1+ #pragma once
2+ #include " resource.h"
3+ #include " HexEdit.h"
4+ #include " ApiReader.h"
5+
6+ enum DisasmAddressType {
7+ ADDRESS_TYPE_MODULE,
8+ ADDRESS_TYPE_API,
9+ ADDRESS_TYPE_SPECIAL
10+ };
11+
12+ class DisasmAddressComment {
13+ public:
14+ DWORD_PTR _address;
15+ WCHAR _comment[512 ];
16+ DisasmAddressType _type;
17+ DWORD _moduleSize;
18+
19+ bool operator <(const DisasmAddressComment& rhs) {
20+ return _address < rhs._address ;
21+ }
22+ };
23+
24+ class CDisasmDlg :public CDialogImpl <CDisasmDlg>,
25+ public CWinDataExchange<CDisasmDlg>, public CDialogResize<CDisasmDlg> {
26+ public:
27+ enum {IDD = IDD_DISASSEMBLER};
28+
29+ CDisasmDlg (DWORD_PTR startAddress, ApiReader* _pApiReader);
30+
31+ protected:
32+ static const size_t DISASM_SIZE = 0x1000 ;
33+ WCHAR _temp[512 ];
34+ int _addressHistoryIndex = 0 ;
35+
36+ std::vector<DWORD_PTR> _addressHistories;
37+ std::vector<DisasmAddressComment> _addressComments;
38+
39+ CListViewCtrl _ListDisassembler;
40+ CHexEdit _address;
41+
42+ enum DisasmColumns {
43+ Address = 0 ,
44+ InstructionSize,
45+ Opcodes,
46+ Instruction,
47+ Comment
48+ };
49+
50+ CMenu _hMenuDisasm;
51+
52+ BOOL OnInitDialog (CWindow wndFocus, LPARAM lInitParam);
53+ void OnContextMenu (CWindow wnd, CPoint point);
54+ void OnExit (UINT uNotifyCode, int nID, CWindow wndCtl);
55+ LRESULT OnNMCustomdraw (NMHDR* pnmh);
56+ void OnDisassemble (UINT uNotifyCode, int nID, CWindow wndCtl);
57+ void OnDisassembleBack (UINT uNotifyCode, int nID, CWindow wndCtl);
58+ void OnDisassembleForward (UINT uNotifyCode, int nID, CWindow wndCtl);
59+
60+ void AddColumnsToDisassembler (CListViewCtrl& list);
61+ bool DisplayDisassembly ();
62+
63+ void CopyToClipboard (const WCHAR* pText);
64+
65+ private:
66+ ApiReader* _pApiReader = nullptr ;
67+ BYTE _data[DISASM_SIZE];
68+
69+ void ToUpperCase (WCHAR* pLowercase);
70+ void DoColorInstruction (LPNMLVCUSTOMDRAW lpLVCustomDraw, DWORD_PTR itemIndex);
71+ void FollowInstruction (int index);
72+ bool GetDisassemblyComment (unsigned int index);
73+
74+ void DisassembleNewAddress (DWORD_PTR address);
75+ void InitAddressCommentList ();
76+ void AddModuleAddressCommentEntry (DWORD_PTR address, DWORD moduleSize, const WCHAR* pModulePath);
77+ void AnalyzeAddress (DWORD_PTR address, WCHAR* pComment);
78+
79+ public:
80+ BEGIN_DDX_MAP (CDisasmDlg)
81+ DDX_CONTROL_HANDLE (IDC_LIST_DISASSEMBLER,_ListDisassembler)
82+ DDX_CONTROL (IDC_DISASM_ADDRESS,_address)
83+ END_DDX_MAP ()
84+
85+ BEGIN_MSG_MAP (CDisasmDlg)
86+ MSG_WM_INITDIALOG (OnInitDialog)
87+ MSG_WM_CONTEXTMENU (OnContextMenu)
88+
89+ NOTIFY_HANDLER_EX (IDC_LIST_DISASSEMBLER,NM_CUSTOMDRAW,OnNMCustomdraw)
90+
91+ COMMAND_ID_HANDLER_EX (IDC_DISASM,OnDisassemble)
92+ COMMAND_ID_HANDLER_EX (IDC_DISASM_BACK,OnDisassembleBack)
93+ COMMAND_ID_HANDLER_EX (IDC_DISASM_FORWARD,OnDisassembleForward)
94+ COMMAND_ID_HANDLER_EX (IDCANCEL,OnExit)
95+ COMMAND_ID_HANDLER_EX (IDOK,OnExit)
96+ CHAIN_MSG_MAP (CDialogResize<CDisasmDlg>)
97+ END_MSG_MAP ()
98+
99+ BEGIN_DLGRESIZE_MAP (CDisasmDlg)
100+ DLGRESIZE_CONTROL (IDC_LIST_DISASSEMBLER, DLSZ_SIZE_X | DLSZ_SIZE_Y)
101+ DLGRESIZE_CONTROL (IDC_DISASM, DLSZ_MOVE_X | DLSZ_MOVE_Y)
102+ DLGRESIZE_CONTROL (IDC_DISASM_BACK, DLSZ_MOVE_X | DLSZ_MOVE_Y)
103+ DLGRESIZE_CONTROL (IDC_DISASM_FORWARD, DLSZ_MOVE_X | DLSZ_MOVE_Y)
104+ DLGRESIZE_CONTROL (IDC_DISASM_ADDRESS, DLSZ_MOVE_Y)
105+ DLGRESIZE_CONTROL (IDC_DISASSEMBLE_ADDRESS, DLSZ_MOVE_Y)
106+ END_DLGRESIZE_MAP ()
107+ };
0 commit comments