forked from AeonLucid/AndroidNativeEmu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
314 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import inspect | ||
import itertools | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class JavaClassDef(type): | ||
next_jvm_id = itertools.count(start=1) | ||
|
||
def __init__(cls, name, base, ns, jvm_name=None): | ||
cls.jvm_id = next(JavaClassDef.next_jvm_id) | ||
cls.jvm_name = jvm_name | ||
cls.jvm_methods = list() | ||
|
||
# Register all defined Java methods. | ||
for func in inspect.getmembers(cls, predicate=inspect.isfunction): | ||
if hasattr(func[1], 'jvm_method'): | ||
cls.jvm_methods.append(func[1].jvm_method) | ||
|
||
type.__init__(cls, name, base, ns) | ||
|
||
def __new__(mcs, name, base, ns, **kargs): | ||
return type.__new__(mcs, name, base, ns) | ||
|
||
def register_native(self, name, signature, ptr_func): | ||
found = False | ||
found_method = None | ||
|
||
# Search for a defined jvm method. | ||
for method in self.jvm_methods: | ||
if method.name == name and method.signature == signature: | ||
method.native_addr = ptr_func | ||
found = True | ||
found_method = method | ||
break | ||
|
||
if not found: | ||
raise RuntimeError("Register native ('%s', '%s') failed on class %s." % (name, signature, self.__name__)) | ||
|
||
logger.debug("Registered native function ('%s', '%s') to %s.%s" % (name, signature, | ||
self.__name__, found_method.func_name)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
class JavaMethodDef: | ||
|
||
def __init__(self, func_name, name, signature, native): | ||
self.func_name = func_name | ||
self.name = name | ||
self.signature = signature | ||
self.native = native | ||
self.native_addr = None | ||
|
||
|
||
def java_method_def(name, signature, native=False): | ||
def java_method_def_real(func): | ||
def native_wrapper(self, emulator, *argv): | ||
return emulator.call_native( | ||
native_wrapper.jvm_method.native_addr, | ||
emulator.java_vm.jni_env.address_ptr, # JNIEnv* | ||
0x0, # this, TODO: Implement proper "this", a reference to the Java object inside which this native | ||
# method has been declared in | ||
*argv # Extra args. | ||
) | ||
|
||
def normal_wrapper(*args, **kwargs): | ||
print('Got called wow!') | ||
result = func(*args, **kwargs) | ||
return result | ||
|
||
wrapper = native_wrapper if native else normal_wrapper | ||
wrapper.jvm_method = JavaMethodDef(func.__name__, name, signature, native) | ||
return wrapper | ||
|
||
return java_method_def_real |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
class jobject: | ||
|
||
def __init__(self, value=None): | ||
self.value = value | ||
|
||
|
||
class jclass(jobject): | ||
|
||
def __init__(self, value=None): | ||
super().__init__(value) | ||
|
||
|
||
class jstring(jobject): | ||
|
||
def __init__(self, value=None): | ||
super().__init__(value) | ||
|
||
|
||
class jarray(jobject): | ||
|
||
def __init__(self, value=None): | ||
super().__init__(value) | ||
|
||
|
||
class jobjectArray(jarray): | ||
|
||
def __init__(self, value=None): | ||
super().__init__(value) | ||
|
||
|
||
class jbooleanArray(jarray): | ||
|
||
def __init__(self, value=None): | ||
super().__init__(value) | ||
|
||
|
||
class jbyteArray(jarray): | ||
|
||
def __init__(self, value=None): | ||
super().__init__(value) | ||
|
||
|
||
class jcharArray(jarray): | ||
|
||
def __init__(self, value=None): | ||
super().__init__(value) | ||
|
||
|
||
class jshortArray(jarray): | ||
|
||
def __init__(self, value=None): | ||
super().__init__(value) | ||
|
||
|
||
class jintArray(jarray): | ||
|
||
def __init__(self, value=None): | ||
super().__init__(value) | ||
|
||
|
||
class jlongArray(jarray): | ||
|
||
def __init__(self, value=None): | ||
super().__init__(value) | ||
|
||
|
||
class jfloatArray(jarray): | ||
|
||
def __init__(self, value=None): | ||
super().__init__(value) | ||
|
||
|
||
class jdoubleArray(jarray): | ||
|
||
def __init__(self, value=None): | ||
super().__init__(value) | ||
|
||
|
||
class jthrowable(jobject): | ||
|
||
def __init__(self, value=None): | ||
super().__init__(value) | ||
|
||
|
Oops, something went wrong.