diff --git a/androidemu/java/jni_env.py b/androidemu/java/jni_env.py index 3f9dfa6..4d593f7 100644 --- a/androidemu/java/jni_env.py +++ b/androidemu/java/jni_env.py @@ -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.') @@ -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): @@ -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) @@ -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): diff --git a/samples/debug_utils.py b/samples/debug_utils.py index 0fa6ab3..23bfd74 100644 --- a/samples/debug_utils.py +++ b/samples/debug_utils.py @@ -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):