-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwin-find-vtable.py
More file actions
75 lines (59 loc) · 1.77 KB
/
win-find-vtable.py
File metadata and controls
75 lines (59 loc) · 1.77 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
import re
f = open('/Users/vit/vtables.txt', 'w')
doc = Document.getCurrentDocument()
dataseg = doc.getSegmentByName('.data')
rdataseg = doc.getSegmentByName('.rdata')
textseg = doc.getSegmentByName('.text')
datasec = doc.getSectionByName('.data')
rdatasec = doc.getSectionByName('.rdata')
base = 0x140000000
def readAscii(seg,addr,end):
start = seg
ret = ''
started = 0
while addr < end:
b = seg.readByte(addr)
addr = addr + 1
if not b:
if started:
return ret, started
else:
continue
elif b != 0x2e:
if not started:
continue
ret = ret + chr(b)
if not started:
started = addr-1
return '',end
print '============================='
if True:
addr1 = rdatasec.getStartingAddress()
addr2 = rdatasec.getStartingAddress()
end2 = rdatasec.getStartingAddress() + rdatasec.getLength()
while addr2 < end2:
q = doc.readUInt64LE(addr2)
if q > addr1 and q < end2:
rdataseg.setTypeAtAddress(addr2, 8, Segment.TYPE_LONG)
addr2 = addr2 + 4
print 'PREPARE DONE'
addr2 = rdatasec.getStartingAddress()
end2 = rdatasec.getStartingAddress() + rdatasec.getLength()
addr3 = datasec.getStartingAddress()
end3 = datasec.getStartingAddress() + datasec.getLength()
while addr2 < end2:
d = doc.readUInt32LE(addr2) + base
if d > addr3 and d < end3 and doc.readByte(d+16) == 0x2e and doc.readByte(addr2-12) == 0x01:
s,ad = readAscii(dataseg, d, d+0x100)
m = re.match("(..[A-Z]+)([a-z_]+st)", s)
if m and m.group(2) != 'bad_cast':
classname = m.group(2)
refs = rdataseg.getReferencesOfAddress(addr2-12)
if len(refs) == 0:
print 'can not find refs for %s 0x%x' % (classname, addr2-12)
else:
vtable = refs[0] + 8
f.write ("<vtable-address name='%s' value='0x%08x'/>\n" % (classname, vtable))
addr2 = addr2 + 4
f.close()
print 'DONE'