Skip to content

Commit

Permalink
Add system properties support
Browse files Browse the repository at this point in the history
  • Loading branch information
AeonLucid committed May 31, 2019
1 parent 25bd2d6 commit 78f5d6b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
5 changes: 4 additions & 1 deletion androidemu/emulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def __init__(self, vfs_root=None, vfp_inst_set=False):
if vfp_inst_set:
self._enable_vfp()

# Android
self.system_properties = {}

# Stack.
self.mu.mem_map(config.STACK_ADDR, config.STACK_SIZE)
self.mu.reg_write(UC_ARM_REG_SP, config.STACK_ADDR + config.STACK_SIZE)
Expand Down Expand Up @@ -68,7 +71,7 @@ def __init__(self, vfs_root=None, vfp_inst_set=False):

# Native
self.native_memory = NativeMemory(self.mu, config.HEAP_BASE, config.HEAP_SIZE, self.syscall_handler)
self.native_hooks = NativeHooks(self.native_memory, self.modules, self.hooker)
self.native_hooks = NativeHooks(self, self.native_memory, self.modules, self.hooker)

# https://github.com/unicorn-engine/unicorn/blob/8c6cbe3f3cabed57b23b721c29f937dd5baafc90/tests/regress/arm_fp_vfp_disabled.py#L15
def _enable_vfp(self):
Expand Down
4 changes: 2 additions & 2 deletions androidemu/java/jni_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,6 @@ def new_object(self, mu, env):

@native_method
def new_object_v(self, mu, env, clazz_idx, method_id, args):
logger.debug("JNIEnv->NewObjectV(%u, %u, 0x%x) was called" % (clazz_idx, method_id, args))

# Get class reference.
clazz = self.get_reference(clazz_idx)
if not isinstance(clazz, jclass):
Expand All @@ -484,6 +482,8 @@ def new_object_v(self, mu, env, clazz_idx, method_id, args):
if method.name != '<init>' or not method.signature.endswith('V'):
raise ValueError('Class constructor has the wrong name or does not return void.')

logger.debug("JNIEnv->NewObjectV(%s, %s, 0x%x) was called" % (clazz.value.jvm_name, method.name, args))

# Parse arguments.
constructor_args = self.read_args_v(mu, args, method.args_list)

Expand Down
26 changes: 21 additions & 5 deletions androidemu/native/hooks.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import logging

from androidemu.hooker import Hooker
from androidemu.native.memory import NativeMemory

from androidemu.java.helpers.native_method import native_method
from androidemu.native.memory import NativeMemory
from androidemu.utils import memory_helpers

logger = logging.getLogger(__name__)

Expand All @@ -15,8 +15,24 @@ class NativeHooks:
:type modules Modules
:type hooker Hooker
"""
def __init__(self, memory, modules, hooker):
def __init__(self, emu, memory, modules, hooker):
self._emu = emu
self._memory = memory

# modules.add_symbol_hook('malloc', hooker.write_function(self.malloc) + 1)
# modules.add_symbol_hook('memcpy', hooker.write_function(self.memcpy) + 1)
modules.add_symbol_hook('__system_property_get', hooker.write_function(self.system_property_get) + 1)

@native_method
def system_property_get(self, uc, name_ptr, buf_ptr):
name = memory_helpers.read_utf8(uc, name_ptr)
logger.debug("Called __system_property_get(%s, 0x%x) was called" % (name, buf_ptr))

if name in self._emu.system_properties:
memory_helpers.write_utf8(uc, buf_ptr, self._emu.system_properties[name])
else:
raise ValueError('%s was not found in system_properties dictionary.' % name)

return None

@native_method
def nop(self, emu):
raise NotImplementedError()

0 comments on commit 78f5d6b

Please sign in to comment.