-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathgeneratePseudoCode.py
37 lines (31 loc) · 949 Bytes
/
generatePseudoCode.py
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
from os.path import exists, expanduser, split
from os import makedirs
doc = Document.getCurrentDocument()
seg = doc.getCurrentSegment()
# get proc count
procCount = seg.getProcedureCount()
homeDir = expanduser("~")
head, appName = split(doc.getExecutableFilePath())
path = homeDir + '/hopperDumps/' + appName + '/'
if not exists(path):
makedirs(path)
# iterate through procs
i = 0
while i < procCount:
# get proc
proc = seg.getProcedureAtIndex(i)
# get proc's name
name = seg.getNameAtAddress(proc.getEntryPoint())
if name:
# clean the name of any unsavoury chars
items = ["[", "]", ":"]
for item in items:
name = name.replace(item, "")
name = name.replace(" ", "__")
# grab the decompilation
output = proc.decompile()
# open up a file handler for the name
with open(path + name +'.pseu', 'w') as outFile:
outFile.write(output + '\n')
i += 1
print "[*] Pseudo code export complete. Export located at: %s" % (path)