Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathDelphiHelper.py
More file actions
Latest commit
194 lines (154 loc) · 6.94 KB
/
Copy pathDelphiHelper.py
File metadata and controls
194 lines (154 loc) · 6.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#
# IDA plugin definition
#
# Copyright (c) 2020-2026 ESET
# Author: Juraj Horňák <juraj.hornak@eset.com>
# See LICENSE file for redistribution.
importida_auto
importida_idaapi
importida_kernwin
importida_segment
importidautils
fromDelphiHelper.core.ClassResolverimportResolveClass, ResolveApplicationClass
fromDelphiHelper.core.ClassStructimportUpdateClassStructures
fromDelphiHelper.core.DFMParserimportParseDFMs
fromDelphiHelper.core.DelphiClass_TypeInfoimportParseTypeInfo
fromDelphiHelper.core.EPFinderimportEPFinder
fromDelphiHelper.core.FormViewerimportFormViewer
fromDelphiHelper.core.IDRKBLoaderimportKBLoader
fromDelphiHelper.core.IDRKBParserimportGetDelphiVersion
fromDelphiHelper.util.delphiimportLoadDelphiFLIRTSignatures
fromDelphiHelper.util.exceptionimportDelphiHelperError
PLUGIN_NAME="DelphiHelper"
PLUGIN_VERSION="1.24"
PLUGIN_AUTHOR="Juraj Hornak (juraj.hornak@eset.com)"
classDelphiHelperPlugin(ida_idaapi.plugin_t):
flags=ida_idaapi.PLUGIN_MOD|ida_idaapi.PLUGIN_MULTI
comment=PLUGIN_NAME+" - IDA plugin simplifying the analysis of Delphi x86/x64 binaries"
help="IDA plugin simplifying the analysis of Delphi binaries"
wanted_name=PLUGIN_NAME
wanted_hotkey="Alt+Shift+H"
definit(self):
addon=ida_kernwin.addon_info_t()
addon.id="delphi_helper"
addon.name=PLUGIN_NAME
addon.producer=PLUGIN_AUTHOR
addon.url="juraj.hornak@eset.com"
addon.version=PLUGIN_VERSION
ida_kernwin.register_addon(addon)
LoadDelphiFLIRTSignatures()
returnDelphiHelperPluginMain()
classDelphiHelperPluginMain(ida_idaapi.plugmod_t):
def__init__(self) ->None:
ida_idaapi.plugmod_t.__init__(self)
self.__delphiFormList=list()
self.__packageinfo=None
self.__parseFlag=True
self.__delphiVersion=0
self.hotkeys= []
self.hotkeys.append(ida_kernwin.add_hotkey("Alt+Shift+R", self.resolveClass))
self.hotkeys.append(ida_kernwin.add_hotkey("Alt+Shift+E", self.findEntryPointFunc))
self.hotkeys.append(ida_kernwin.add_hotkey("Alt+Shift+F", self.formViewer))
self.hotkeys.append(ida_kernwin.add_hotkey("Alt+Shift+S", self.loadIDRKBSignatures_main))
self.hotkeys.append(ida_kernwin.add_hotkey("Alt+Shift+A", self.loadIDRKBSignatures_custom))
defrun(self, arg):
self.printHelp()
defprintHelp(self) ->None:
print("-"*100)
print(f"{PLUGIN_NAME} ({PLUGIN_VERSION}) by {PLUGIN_AUTHOR}")
print("Copyright (c) 2020-2026 ESET\n")
print("IDA plugin simplifying the analysis of Delphi x86/x64 binaries")
print("\nHotkeys:")
print(" \"Alt + Shift + R\" - run VMT Parser in order to parse selected VMT structure")
print(" Usage: Press it in disassembly window when the cursor is on the starting address of a VMT structure")
print(" e.g. mov edx, VMT_offset --> starting address of the VMT structure")
print(" call CreateForm\n")
print(" \"Alt + Shift + F\" - run DFM Finder (show Delphi Form Viewer)")
print(" Usage: Press it anywhere in the disassembly window")
print(" Note: The resource section of Delphi file must be loaded by IDA\n")
print(" \"Alt + Shift + E\" - run Entry Point Function Finder (searching for \"CreateForm\", \"InitExe\" and \"InitLib\" references)")
print(" Usage: Press it anywhere in the disassembly window\n")
print(" \"Alt + Shift + S\" - run IDR Knowledge Base Loader for \"SysInit\" and \"System\" unit")
print(" Usage: Press it anywhere in the disassembly window")
print(" Note: read the README.md for KB file location.\n")
print(" \"Alt + Shift + A\" - run IDR Knowledge Base Loader for selected units")
print(" Usage: Press it anywhere in the disassembly window")
print(" Note: read the README.md for KB file location.")
print("-"*100)
defterm(self) ->None:
forhotkeyinself.hotkeys:
ida_kernwin.del_hotkey(hotkey)
deffindEntryPointFunc(self) ->None:
msg="NODELAY\nHIDECANCEL\nSearching for EP function..."
ida_kernwin.show_wait_box(msg)
try:
self.getDelphiVersion()
EPFinder(self.__delphiVersion).FindEPFunction()
exceptDelphiHelperErrorase:
e.print()
finally:
ida_kernwin.hide_wait_box()
defresolveClass(self) ->None:
msg="NODELAY\nHIDECANCEL\nProcessing selected VMT structure..."
ida_kernwin.show_wait_box(msg)
try:
self.getDelphiVersion()
LoadDelphiFLIRTSignatures()
ida_auto.auto_wait()
ResolveClass(ida_kernwin.get_screen_ea(), self.__delphiVersion)
exceptDelphiHelperErrorase:
e.print()
finally:
ida_kernwin.hide_wait_box()
defformViewer(self) ->None:
msg="NODELAY\nHIDECANCEL\nProcessing Delphi file's DFMs..."
ida_kernwin.show_wait_box(msg)
try:
self.getDelphiVersion()
LoadDelphiFLIRTSignatures()
ida_auto.auto_wait()
ResolveApplicationClass(self.__delphiVersion)
ifself.__parseFlag:
self.__delphiFormList=ParseDFMs(self.__delphiVersion)
self.__parseFlag=False
self.processTypeInfoStructures()
UpdateClassStructures()
ifself.__delphiFormList:
FormViewer(self.__delphiFormList)
else:
print("[INFO] The Delphi binary seems to not contain any Delphi Form")
exceptDelphiHelperErrorase:
e.print()
finally:
ida_kernwin.hide_wait_box()
defloadIDRKBSignatures_custom(self) ->None:
try:
KBLoader(True)
exceptDelphiHelperErrorase:
e.print()
defloadIDRKBSignatures_main(self) ->None:
try:
KBLoader(False)
exceptDelphiHelperErrorase:
e.print()
defgetDelphiVersion(self) ->None:
ifself.__delphiVersion==0:
self.__delphiVersion=GetDelphiVersion()
defprocessTypeInfoStructures(self) ->None:
msg="NODELAY\nHIDECANCEL\nProcessing TypeInfo structures..."
ida_kernwin.show_wait_box(msg)
try:
self.getDelphiVersion()
forea_seg_startinidautils.Segments():
addr=ea_seg_start+5
seg=ida_segment.getseg(ea_seg_start)
whileaddr!=ida_idaapi.BADADDRandaddr<seg.end_ea:
addr=ParseTypeInfo(addr, self.__delphiVersion)
exceptDelphiHelperErrorase:
e.print()
finally:
ida_kernwin.hide_wait_box()
defPLUGIN_ENTRY():
"""Required plugin entry point for IDAPython Plugins.
"""
returnDelphiHelperPlugin()