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

adding check on .init_array section if present #51

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
49 changes: 25 additions & 24 deletions librw_x64/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,31 @@ def load_functions(self, fnlist):
self.container.add_function(function)

section = self.elffile.get_section_by_name(".init_array")
data = section.data()
# section = self.elffile.get_section_by_name(".fini_array")
# data += section.data()
for e,i in enumerate(range(0, len(data), 8)):
address = data[i:i+8]
addr_int = struct.unpack("<Q", address)[0]
func = self.container.functions.get(addr_int, None)
if func == None:
print(f"ERROR: missed .init_array function symbol at {hex(addr_int)}")
# TODO
# We need to add them to the function list
# we need to "add_function" like right above
min_next_func = 0xffffffffffffffff
for func in self.container.functions:
if func > addr_int:
min_next_func = min(min_next_func, func)
if min_next_func != 0xffffffffffffffff:
sz = min_next_func - addr_int
func_bytes = text_data[addr_int - text_base:addr_int - text_base + sz]
if e == 0:
# skip first initial array and just do ret (problems with _ITM_registerTMClone... begin unlinkable)
self.container.add_function(Function(f"entry_{hex(addr_int)}", addr_int, sz, b"\xc3"))
else:
self.container.add_function(Function(f"entry_{hex(addr_int)}", addr_int, sz, func_bytes))
if hasattr(section, "data"):
data = section.data()
# section = self.elffile.get_section_by_name(".fini_array")
# data += section.data()
for e,i in enumerate(range(0, len(data), 8)):
address = data[i:i+8]
addr_int = struct.unpack("<Q", address)[0]
func = self.container.functions.get(addr_int, None)
if func == None:
print(f"ERROR: missed .init_array function symbol at {hex(addr_int)}")
# TODO
# We need to add them to the function list
# we need to "add_function" like right above
min_next_func = 0xffffffffffffffff
for func in self.container.functions:
if func > addr_int:
min_next_func = min(min_next_func, func)
if min_next_func != 0xffffffffffffffff:
sz = min_next_func - addr_int
func_bytes = text_data[addr_int - text_base:addr_int - text_base + sz]
if e == 0:
# skip first initial array and just do ret (problems with _ITM_registerTMClone... begin unlinkable)
self.container.add_function(Function(f"entry_{hex(addr_int)}", addr_int, sz, b"\xc3"))
else:
self.container.add_function(Function(f"entry_{hex(addr_int)}", addr_int, sz, func_bytes))

# fill gaps
# functions = list(sorted(self.container.functions.items()))
Expand Down