Skip to content

Refactor load_module to support 64-bit ELF loading #85

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

Open
wants to merge 4 commits 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
9 changes: 7 additions & 2 deletions src/androidemu/emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,14 @@ def load_library(self, filename, do_init=True):
libmod = self.modules.load_module(filename)
if do_init:
logger.debug("Calling init for: %s " % filename)
# DT_INIT should be called before DT_INIT_ARRAY if both are present.
if libmod.init is not None and libmod.init != 0:
logger.debug("Calling DT_INIT: %x " % libmod.init)
self.call_native(libmod.init, 0, 0, 0)
for fun_ptr in libmod.init_array:
logger.debug("Calling init function: %x " % fun_ptr)
self.call_native(fun_ptr, 0, 0, 0)
logger.debug("Calling DT_INIT_ARRAY function: %x " % fun_ptr)
if fun_ptr != 0: # Some binaries have null pointers in the init array.
self.call_native(fun_ptr, 0, 0, 0)
return libmod

def call_symbol(self, module, symbol_name, *argv, is_return_jobject=True):
Expand Down
6 changes: 6 additions & 0 deletions src/androidemu/internal/arm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
R_ARM_JUMP_SLOT = 22
R_ARM_RELATIVE = 23

R_AARCH64_NONE = 0
R_AARCH64_ABS64 = 257
R_AARCH64_GLOB_DAT = 1025
R_AARCH64_JUMP_SLOT = 1026
R_AARCH64_RELATIVE = 1027
R_AARCH64_TLSDESC = 1031
R_AARCH64_IRELATIVE = 1032
R_AARCH64_TLS_DTPREL = 1028
R_AARCH64_TLS_TPREL = 1029
3 changes: 2 additions & 1 deletion src/androidemu/internal/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ class Module:
:type base int
:type size int
"""
def __init__(self, filename, address, size, symbols_resolved, init_array=[]):
def __init__(self, filename, address, size, symbols_resolved, init_array=[], init=None):
self.filename = filename
self.base = address
self.size = size
self.symbols = symbols_resolved
self.symbol_lookup = dict()
self.init_array = list(init_array)
self.init = init

# Create fast lookup.
for symbol_name, symbol in self.symbols.items():
Expand Down
Loading
Loading