forked from phracker/HopperScripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rename PLT.py
executable file
·40 lines (34 loc) · 1.13 KB
/
Rename PLT.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
38
39
40
doc = Document.getCurrentDocument()
doc.log("# PLT funtion rename v1.0")
doc.log("# Author: @pwntester")
segment = doc.getCurrentSegment()
lower = segment.getStartingAddress()
upper = segment.getStartingAddress() + segment.getLength()
plt_address = 0
doc.log("Lower: {0}".format(hex(lower)))
doc.log("Upper: {0}".format(hex(upper)))
for i in xrange(upper-lower):
comment = segment.getCommentAtAddress(lower + i)
if comment is not None:
doc.log(comment)
if "Section .plt" in comment:
plt_address = lower + i
doc.log("PLT at: {0}".format(hex(plt_address)))
break
if plt_address > 0:
doc.log("Renaming in range %s to %s" % (hex(plt_address), hex(upper)))
adr = plt_address
while adr <= upper:
name = segment.getNameAtAddress(adr)
if name is not None:
ins = segment.getInstructionAtAddress(adr)
op = ins.getInstructionString()
arg = ins.getFormattedArgument(0)
if op == "jmp" and "sub_" in name and "@GOT" in arg:
new_name = arg[:arg.index('@GOT')]
if new_name != None:
doc.log("Renaming %s to %s" % (name, new_name))
doc.setNameAtAddress(adr, new_name)
adr = adr + 1
name = ''
doc.refreshView()