最近在翻unicorn showcase的时候发现了一套不错的代码,能够非常好的模拟Android Native调用。 于是就瞎改了其代码,使其可以支持跑测试so(x音),并翻译了一份README。
初始化有点慢,log有点慢,大黑阔们们别把初始化搞到任务循环里了~~
https://github.com/Chenyuxin/AndroidNativeEmu/
fork from : https://github.com/AeonLucid/AndroidNativeEmu
AndroidNativeEmu 让你能够跨平台模拟Android Native库函数,比如JNI_OnLoad、Java_XXX_XX等函数。
fork from : https://github.com/AeonLucid/AndroidNativeEmu
JNI_OnLoad
can be called properly.小弟不才,修改了一些代码,使其能够运行libcms的leviathan.
运行环境:python 3.7 必须!
pip install -r requirements.txt
python example.py
Windows上可以跑,自行尝试。
# Initialize emulator emulator = Emulator( vfp_inst_set=True, vfs_root=posixpath.join(posixpath.dirname(__file__), "vfs") )
注意看看各项参数的定义
class java_lang_System(metaclass=JavaClassDef, jvm_name='java/lang/System'): def __init__(self): pass @java_method_def(name='getProperty', args_list=["jstring"] ,signature='(Ljava/lang/String;)Ljava/lang/String;', native=False) def getProperty(self, *args, **kwargs): print (args[0].value) return "2.1.0"
class XGorgen(metaclass=JavaClassDef, jvm_name='com/ss/sys/ces/a'): def __init__(self): pass @java_method_def(name='leviathan', signature='(I[B)[B', native=True) def leviathan(self, mu): pass def test(self): pass
class java_lang_Thread(metaclass=JavaClassDef, jvm_name='java/lang/Thread'): def __init__(self): pass @java_method_def(name="currentThread", signature='()Ljava/lang/Thread;', native=False) def currentThread(self, *args, **kwargs): return java_lang_Thread() @java_method_def(name="getStackTrace", signature='()[Ljava/lang/StackTraceElement;', native=False) def getStackTrace(self, *args, **kwargs): return [java_lang_StackTraceElement("dalvik.system.VMStack"), java_lang_StackTraceElement("java.lang.Thread"), java_lang_StackTraceElement("com.ss.sys.ces.a"), java_lang_StackTraceElement("com.yf.douyintool.MainActivity"), java_lang_StackTraceElement("java.lang.reflect.Method"), java_lang_StackTraceElement("java.lang.reflect.Method"), java_lang_StackTraceElement("android.support.v7.app.AppCompatViewInflater$DeclaredOnClickListener"), java_lang_StackTraceElement("android.view.View"), java_lang_StackTraceElement("android.os.Handler"), java_lang_StackTraceElement("android.os.Handler"), java_lang_StackTraceElement("android.os.Looper"), java_lang_StackTraceElement("android.app.ActivityThread"), java_lang_StackTraceElement("java.lang.reflect.Method"), java_lang_StackTraceElement("java.lang.reflect.Method"), java_lang_StackTraceElement("com.android.internal.os.ZygoteInit$MethodAndArgsCaller"), java_lang_StackTraceElement("com.android.internal.os.ZygoteInit"), java_lang_StackTraceElement("dalvik.system.NativeStart") ]
更多的类请见example
emulator.java_classloader.add_class(XGorgen) emulator.java_classloader.add_class(java_lang_System) emulator.java_classloader.add_class(java_lang_Thread) emulator.java_classloader.add_class(java_lang_StackTraceElement)
init array 已经自动调用了,SO如果有加密也没关系。
# 添加依赖库 emulator.load_library("samples/example_binaries/libdl.so") emulator.load_library("samples/example_binaries/libc.so") emulator.load_library("samples/example_binaries/libstdc++.so") emulator.load_library("samples/example_binaries/libm.so") lib_module = emulator.load_library("samples/example_binaries/libcms.so") # JNI_OnLoad will call 'RegisterNatives'. emulator.call_symbol(lib_module, 'JNI_OnLoad', emulator.java_vm.address_ptr, 0x00)
x = XGorgen() data = 'acde74a94e6b493a3399fac83c7c08b35D58B21D9582AF77647FC9902E36AE70f9c001e9334e6e94916682224fbe4e5f00000000000000000000000000000000' data = bytearray(bytes.fromhex(data)) result = x.leviathan(emulator, 1562848170, data)
[公告]LV6级以上的看雪会员可以免费获得《2019安全开发者峰会》门票一张!!
最后于 6天前 被无名侠编辑 ,原因: