-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdisasm.py
More file actions
executable file
·59 lines (51 loc) · 1.97 KB
/
disasm.py
File metadata and controls
executable file
·59 lines (51 loc) · 1.97 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
#! /usr/bin/python
# -*- coding: utf-8 -*-
from lib.pyew.pyew_core import CPyew
import os
import sys
import hashlib
def printData(pyew, path, msg = "default message"):
buf = pyew.getBuffer()
print "File :", path
print "Format :", pyew.format
print "File Size: ", pyew.maxfilesize
print "EP offset: ", pyew.ep
print "Offset: ", pyew.offset
print "MD5 :", hashlib.md5(buf).hexdigest()
print "SHA1 :", hashlib.sha1(buf).hexdigest()
print "SHA256:", hashlib.sha256(buf).hexdigest()
print "Found :", msg
if __name__ == '__main__':
if 2 != len(sys.argv):
print "Usage: %s filename\n" % (sys.argv[0])
sys.exit(0)
fileName = os.path.abspath(sys.argv[1])
pyew = CPyew(batch = True)
pyew.codeanalysis = True
try:
pyew.loadFile(fileName)
except:
_, value, _ = sys.exc_info()
print "Error in opening file: ", value
printData(pyew, fileName, "loaded the file!")
fileName = fileName.replace(".exe", "")
with open(fileName + "_disasm", "wb") as f:
for inst in pyew.disasm(pyew.ep, processor = pyew.processor, lines = -1, bsize = pyew.maxfilesize):
f.write(str(inst) + "\n")
with open(fileName + "_disasm_bb", 'wb') as f:
for idx, bb in pyew.basic_blocks.items():
f.write("---------------- bb: %d ----------------\n" % (idx))
for inst in bb.instructions:
f.write(str(inst) + "\n")
f.write ("---------- Connections: ----------\n")
for afrom, ato in bb.connections:
f.write(str(afrom) + ", " + str(ato) + "\n")
f.write ("---------- inrefs : ----------\n")
for ir in bb.inrefs:
f.write(str(type(ir)) + ": " + str(ir) + "\n")
try:
f.write ("Name: %s\n" % (bb.name))
except:
pass
f.write("Offset: %d\n" % (bb.offset))
f.write("----------------------------------------\n")