Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Jump Table Symbolization Algorithm #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion librw_x64/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def __init__(self, name, start, sz, bytes, bind="STB_LOCAL"):

def set_instrumented(self):
self.instrumented = True

@property
def true_name(self):
if self.is_mangled and not self._true_name:
Expand All @@ -189,6 +189,17 @@ def is_valid_instruction(self, address):

return False

def is_located_at_the_end_of_function(self, address):
assert self.cache, "Function not disassembled!"

for instruction in self.cache:
if instruction.address + instruction.sz == address:
if ".LLC%x:"%(address) not in instruction.after:
instruction.after.append(".LLC%x:"%(address))
return True

return False

def instruction_of_address(self, address):
assert self.cache, "Function not disassembled!"

Expand Down
11 changes: 9 additions & 2 deletions librw_x64/rw.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,10 +627,17 @@ def symbolize_switch_tables(self, container, context):
break

value = (value + swbase) & 0xFFFFFFFF
if not fn.is_valid_instruction(value):

if fn.is_valid_instruction(value):
swlbl = ".LC%x-.LC%x" % (value, swbase)
# Switch table entry might refer to the end of function boundary
# Thus, we check whether the value refers to the end of function
elif fn.is_located_at_the_end_of_function(value):
# is_located_at_the_end_of_function() have created .LLCXXX label
swlbl = ".LLC%x-.LC%x" % (value, swbase)
else:
break

swlbl = ".LC%x-.LC%x" % (value, swbase)
rodata.replace(slot, 4, swlbl)

def _adjust_target(self, container, target):
Expand Down