开发demo
新建native项目,实现log打印字符串。
下载地址:https://download.csdn.net/download/u013170888/89698015
#include <android/log.h>
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, "JNI_LOG", __VA_ARGS__)
extern "C" JNIEXPORT jstring JNICALL
Java_com_android_nativedemo3_MainActivity_stringFromJNI(
JNIEnv* env,
jobject /* this */) {
std::string hexHello = StrToHex("Hello from C++");
std::string hello = HexToStr(hexHello);
LOGI("hexHello: %s",hexHello.c_str());
LOGI("hello: %s",hello.c_str());
return env->NewStringUTF(hello.c_str());
}
运行一下看输出日志:
Hook log打印内容
frida hook 脚本:
注意参数数量
下载地址:https://download.csdn.net/download/u013170888/89698021
function hook_native() {
var addr = Module.getExportByName("liblog.so", "__android_log_print")
Interceptor.attach(addr, {
onEnter: function (args) {
console.log("args 0 = ", args[0])
console.log("args 1 = ", args[1].readCString())
console.log("args 2 = ", args[2].readCString())
console.log("args 3 = ", args[3].readCString())
}, onLeave: function (retval) {
console.log("retval = ", retval)
}
})
}
setImmediate(hook_native)
运行打印结果: