Created
October 12, 2016 09:37
-
-
Save haxelion/6372a1f775a453a2541a7eab48ed37af to your computer and use it in GitHub Desktop.
Hopper v3 script to resolve relocation using readelf and c++filt. Put it in Hopper script directory to use it (under linux ~/GNUstep/Library/ApplicationSupport/Hopper/Scripts)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import subprocess | |
import re | |
doc = Document.getCurrentDocument() | |
segment = doc.getCurrentSegment() | |
binary = doc.getExecutableFilePath() | |
mangled = subprocess.check_output(['readelf', '-rW', binary]) | |
filt = subprocess.Popen(['c++filt'], stdin=subprocess.PIPE, stdout=subprocess.PIPE) | |
output = filt.communicate(mangled) | |
demangled = output[0].split('\n') | |
parser = re.compile('^([0-9a-f]+)\s+([0-9a-f]+)\s+(\w+)\s+([0-9a-f]+)\s+(.*)$') | |
for line in demangled: | |
m = parser.match(line) | |
if m != None: | |
# Markup .got entry | |
address = int(m.group(1), 16) | |
name = m.group(5) | |
segment.setInlineCommentAtAddress(address, name) | |
# Markup .plt jump function | |
ref = segment.getReferencesOfAddress(address) | |
if len(ref) > 0: | |
pltseg = doc.getSegmentAtAddress(ref[0]) | |
proc = pltseg.getProcedureAtAddress(ref[0]) | |
if proc != None: | |
entry = proc.getEntryPoint() | |
pltseg.setNameAtAddress(entry, name[:name.find(' +')]) | |
else: | |
print('No procedure found for {:x}!'.format(ref[0])) | |
else: | |
print('No reference to {} .got entry'.format(name)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment