function checkLibraryLoaded() {
const baseAddr
=
Module.findBaseAddress(
'libmyapplication.so'
);
if
(baseAddr) {
console.log(
'loaded at address:'
, baseAddr);
const libnative_name
=
"libmyapplication.so"
;
/
/
替换为你的.so库的名称
const func_name
=
"Java_com_example_myapplication_MainActivity_stringFromJNI"
;
/
/
检查是否附加到应用程序
if
(Java.available) {
Java.perform(()
=
> {
/
/
获取模块基址
const libnative_base
=
Process.findModuleByName(libnative_name).base;
/
/
获取native方法地址
const func_addr
=
Module.findExportByName(libnative_name, func_name);
/
/
创建用于native方法调用的NativeFunction
const nativeFunc
=
new NativeFunction(func_addr,
'pointer'
, [
'pointer'
,
'pointer'
,
'pointer'
]);
/
/
获取MainActivity类
const MainActivity
=
Java.use(
'com.example.myapplication.MainActivity'
);
/
/
在主线程上执行操作
Java.scheduleOnMainThread(()
=
> {
/
/
获取JNIEnv指针
const env
=
Java.vm.getEnv();
/
/
创建MainActivity实例
const mainActivityInstance
=
MainActivity.$new();
if
(mainActivityInstance !
=
=
null) {
console.log(
"MainActivity instance created successfully."
);
/
/
创建输入字符串
const inputStr
=
"Hello from Frida!"
;
/
/
将Java字符串转换为JNI jstring
const jniString
=
env.newStringUtf(inputStr);
/
/
转换为jobject
const jobjectInstance
=
Java.cast(mainActivityInstance, Java.use(
"java.lang.Object"
));
/
/
调用native方法
const result
=
nativeFunc(env.handle, jobjectInstance.handle, jniString.handle);
/
/
将JNI jstring转换回Java字符串
const resultStr
=
env.stringFromJni(result);
console.log(
"Result: "
+
resultStr);
}
else
{
console.error(
"Failed to create MainActivity instance."
);
}
});
});
}
else
{
console.error(
"Java not available"
);
}
}
}
/
/
clearInterval(checkLibraryLoadedInterval);
const checkLibraryLoadedInterval
=
setInterval(checkLibraryLoaded,
2000
);