SymbolView.cpp
上传用户:ch83438830
上传日期:2007-01-01
资源大小:104k
文件大小:6k
源码类别:

文件操作

开发平台:

Visual C++

  1. // winpeView.cpp : implementation of the CSymbolView class
  2. //
  3. #include "stdafx.h"
  4. #include "winpe.h"
  5. //#include "pefile.h"
  6. #include "winpeDoc.h"
  7. #include "SymbolView.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. /////////////////////////////////////////////////////////////////////////////
  14. // CSymbolView
  15. IMPLEMENT_DYNCREATE(CSymbolView, CScrollView)
  16. BEGIN_MESSAGE_MAP(CSymbolView, CScrollView)
  17. //{{AFX_MSG_MAP(CSymbolView)
  18. ON_WM_CREATE()
  19. //}}AFX_MSG_MAP
  20. // Standard printing commands
  21. ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
  22. ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
  23. ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
  24. END_MESSAGE_MAP()
  25. /////////////////////////////////////////////////////////////////////////////
  26. // CSymbolView construction/destruction
  27. CSymbolView::CSymbolView()
  28. {
  29. // TODO: add construction code here
  30. }
  31. CSymbolView::~CSymbolView()
  32. {
  33. }
  34. BOOL CSymbolView::PreCreateWindow(CREATESTRUCT& cs)
  35. {
  36. // TODO: Modify the Window class or styles here by modifying
  37. //  the CREATESTRUCT cs
  38. return CScrollView::PreCreateWindow(cs);
  39. }
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CSymbolView drawing
  42. void CSymbolView::OnDraw(CDC* pDC)
  43. {
  44. CWinpeDoc* pDoc = GetDocument();
  45. ASSERT_VALID(pDoc);
  46. if (m_nLinesTotal != 0)
  47. {
  48. CRect rect;
  49. pDC->GetClipBox(&rect);
  50. UINT nStart = rect.top / m_cyScreen;
  51. UINT nEnd = min(m_nLinesTotal - 1,
  52.  (rect.bottom + m_cyScreen - 1) /
  53.  m_cyScreen);
  54. CFont * pOldFont = pDC->SelectObject(&m_screenFont);
  55. for (UINT i = nStart; i <= nEnd; i++)
  56. {
  57. pDC->TextOut(2,(i * m_cyScreen) +2,m_DisplayData[i]);
  58. }
  59. pDC->SelectObject(pOldFont);
  60. }
  61. }
  62. /////////////////////////////////////////////////////////////////////////////
  63. // CSymbolView printing
  64. BOOL CSymbolView::OnPreparePrinting(CPrintInfo* pInfo)
  65. {
  66. // default preparation
  67. return DoPreparePrinting(pInfo);
  68. }
  69. void CSymbolView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  70. {
  71. // TODO: add extra initialization before printing
  72. }
  73. void CSymbolView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  74. {
  75. // TODO: add cleanup after printing
  76. }
  77. /////////////////////////////////////////////////////////////////////////////
  78. // CSymbolView diagnostics
  79. #ifdef _DEBUG
  80. void CSymbolView::AssertValid() const
  81. {
  82. CScrollView::AssertValid();
  83. }
  84. void CSymbolView::Dump(CDumpContext& dc) const
  85. {
  86. CScrollView::Dump(dc);
  87. }
  88. CWinpeDoc* CSymbolView::GetDocument() // non-debug version is inline
  89. {
  90. ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CWinpeDoc)));
  91. return (CWinpeDoc*)m_pDocument;
  92. }
  93. #endif //_DEBUG
  94. /////////////////////////////////////////////////////////////////////////////
  95. // CSymbolView message handlers
  96. int CSymbolView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
  97. {
  98. if (CScrollView::OnCreate(lpCreateStruct) == -1)
  99. return -1;
  100. // TODO: Add your specialized creation code here
  101. CClientDC dc (this);
  102. int nHeight = -((dc.GetDeviceCaps (LOGPIXELSY) * 10 ) / 72);
  103. m_screenFont.CreateFont(nHeight,
  104. 0,0,0,
  105. FW_NORMAL,
  106. 0,0,0,
  107. DEFAULT_CHARSET,
  108. OUT_CHARACTER_PRECIS,
  109. CLIP_CHARACTER_PRECIS,
  110. DEFAULT_QUALITY,
  111. DEFAULT_PITCH | FF_DONTCARE,
  112. "Courier New");
  113. TEXTMETRIC tm;
  114. CFont * pOldFont = dc.SelectObject(&m_screenFont);
  115. dc.GetTextMetrics (&tm);
  116. m_cyScreen = tm.tmHeight + tm.tmExternalLeading;
  117. dc.SelectObject(pOldFont);
  118. return 0;
  119. }
  120. void CSymbolView::OnInitialUpdate() 
  121. {
  122. DWORD nDocLength = GetDocument()->GetDocumentLength();
  123. if (nDocLength == 0)
  124. {
  125. m_nLinesTotal = 0;
  126. }
  127. else
  128. {
  129. m_nLinesTotal = GetSymbols();
  130. }
  131. SetScrollSizes (MM_TEXT,
  132. CSize(0,m_nLinesTotal * m_cyScreen), //tot size
  133. CSize(0,m_cyScreen * 10),  //screen size 
  134. CSize (0,m_cyScreen)); //line size
  135. ScrollToPosition(CPoint (0,0));
  136. CScrollView::OnInitialUpdate();
  137. // TODO: Add your specialized code here and/or call the base class
  138. }
  139. INT CSymbolView::GetSymbols()
  140. {
  141. PIMAGE_EXPORT_DIRECTORY exportDir;
  142. PIMAGE_SECTION_HEADER header;
  143. PIMAGE_NT_HEADERS pNTHeader;
  144. PIMAGE_DOS_HEADER pDosHdr;
  145. INT delta;
  146. LPSTR filename;
  147. DWORD i;
  148. PDWORD functions;
  149. PWORD  ordinals;
  150. LPSTR *name;
  151. DWORD exportsStartRVA, exportsEndRVA;
  152. DWORD base;
  153. BYTE * pfile;
  154. CString string;
  155. CString stringapnd;
  156. CHAR line[128];
  157. CHAR *pLine;
  158. CWinpeDoc* pDoc;
  159. PIMAGE_SYMBOL PCOFFSymbolTable;
  160.     DWORD COFFSymbolCount;
  161.     PIMAGE_COFF_SYMBOLS_HEADER PCOFFDebugInfo;
  162. pDoc = GetDocument();
  163. pfile = pDoc->GetDocumentDataP();
  164. pDosHdr = (PIMAGE_DOS_HEADER)pfile;
  165. base = (DWORD)pfile;
  166. pNTHeader = MakePtr(PIMAGE_NT_HEADERS,
  167. pfile,pDosHdr->e_lfanew);
  168. if (pNTHeader->FileHeader.PointerToSymbolTable == 0)
  169. {
  170. string = "No Symbol Table:";
  171. m_DisplayData.Add(string);
  172. return m_DisplayData.GetSize(); 
  173. }
  174.     PCOFFSymbolTable = MakePtr(PIMAGE_SYMBOL, base,
  175.                         pNTHeader->FileHeader.PointerToSymbolTable);
  176.     COFFSymbolCount = pNTHeader->FileHeader.NumberOfSymbols;
  177.     
  178.     DumpCOFFHeader( PCOFFDebugInfo );
  179.    
  180.     
  181.     
  182.     DumpLineNumbers( MakePtr(PIMAGE_LINENUMBER, PCOFFDebugInfo,
  183.                         PCOFFDebugInfo->LvaToFirstLinenumber),
  184.                         PCOFFDebugInfo->NumberOfLinenumbers);
  185.    
  186.     
  187.     
  188.     if ( pNTHeader->FileHeader.NumberOfSymbols) 
  189.       
  190.     {
  191.         DumpSymbolTable(PCOFFSymbolTable, COFFSymbolCount);
  192.        
  193.     }
  194.     string = "  ";
  195. m_DisplayData.Add(string);
  196. return m_DisplayData.GetSize(); 
  197. }
  198. void CSymbolView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
  199. {
  200. // TODO: Add your specialized code here and/or call the base class
  201. CWinpeDoc* pDoc = GetDocument();
  202. ASSERT_VALID(pDoc);
  203. CClientDC dc(this);
  204. TEXTMETRIC tm;
  205. CFont* pOldFont = dc.SelectObject(pDoc->m_screenFont);
  206. dc.GetTextMetrics (&tm);
  207. m_cyScreen = tm.tmHeight + tm.tmExternalLeading;
  208. dc.SelectObject(pOldFont);
  209. //
  210. SetScrollSizes (MM_TEXT,
  211. CSize(0,m_nLinesTotal * m_cyScreen),
  212. CSize(0,m_cyScreen * 100),
  213. CSize (0,m_cyScreen));
  214. ScrollToPosition(CPoint (0,0));
  215. CRect rect;
  216. dc.GetClipBox(&rect);
  217. InvalidateRect(&rect);
  218. }