Skip to content

Commit

Permalink
Add more JNI calls
Browse files Browse the repository at this point in the history
  • Loading branch information
AeonLucid committed Jun 3, 2019
1 parent b574e31 commit 6da5a8e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
34 changes: 30 additions & 4 deletions androidemu/java/jni_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@ def add_global_reference(self, obj):

return self._globals.add(obj)

def get_global_reference(self, idx):
return self._globals.get(idx)

def delete_global_reference(self, obj):
if not isinstance(obj, jobject):
raise ValueError('Expected a jobject.')
Expand Down Expand Up @@ -464,8 +467,17 @@ def new_global_ref(self, mu, env, obj):
return self.add_global_reference(obj)

@native_method
def delete_global_ref(self, mu, env):
raise NotImplementedError()
def delete_global_ref(self, mu, env, idx):
"""
Deletes the global reference pointed to by globalRef.
"""
logger.debug("JNIEnv->DeleteGlobalRef(%d) was called" % idx)

if idx == 0:
return None

obj = self.get_global_reference(idx)
self.delete_global_reference(obj)

@native_method
def delete_local_ref(self, mu, env, idx):
Expand All @@ -487,6 +499,9 @@ def is_same_object(self, mu, env, ref1, ref2):
"""
logger.debug("JNIEnv->IsSameObject(%d, %d) was called" % (ref1, ref2))

if ref1 == 0 and ref2 == 0:
return JNI_TRUE

obj1 = self.get_reference(ref1)
obj2 = self.get_reference(ref2)

Expand All @@ -496,8 +511,19 @@ def is_same_object(self, mu, env, ref1, ref2):
return JNI_FALSE

@native_method
def new_local_ref(self, mu, env):
raise NotImplementedError()
def new_local_ref(self, mu, env, ref):
"""
Creates a new local reference that refers to the same object as ref.
The given ref may be a global or local reference. Returns NULL if ref refers to null.
"""
logger.debug("JNIEnv->NewLocalRef(%d) was called" % ref)

obj = self.get_reference(ref)

if obj is None:
return 0

return self.add_local_reference(obj)

@native_method
def ensure_local_capacity(self, mu, env):
Expand Down
5 changes: 2 additions & 3 deletions samples/debug_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,8 @@ def hook_mem_write(uc, access, address, size, value, user_data):

def hook_mem_read(uc, access, address, size, value, user_data):
pc = uc.reg_read(UC_ARM_REG_PC)
if pc > 0xcbc24cf0 - 8 and pc < 0xcbc24cf0:
data = uc.mem_read(address, size)
logger.debug(">>> Memory READ at 0x%x, data size = %u, pc: %x, data value = 0x%s" % (address, size, pc, data.hex()))
data = uc.mem_read(address, size)
logger.debug(">>> Memory READ at 0x%x, data size = %u, pc: %x, data value = 0x%s" % (address, size, pc, data.hex()))


def hook_interrupt(uc, intno, data):
Expand Down

0 comments on commit 6da5a8e

Please sign in to comment.