frida17踩坑

frida17 踩坑

踩坑 1

平常都可以用全局对象比如 Module 这类的去调用 api 获取导出表,符号表之类的

但中 frida17 直接调用会直接提示:TypeError: not a function

1
Module.enumerateExports("libfrida0x8.so")

后面试了其他的 api 发现一个都没有,问了 AI 也无果,但鉴于应该不会只有我这样,差了一下 github 的 issue 发现,现在要模块对象来调用 API

1
2
3
4
5
6
7
8
9
10
var moduleName = "libfrida0x8.so";
var module = Process.findModuleByName(moduleName);
if (module) {
console.log("[*] Found module: " + module.name + " at " + module.base);
var a = module.enumerateExports();
for (var i = 0; i < a.length; i++) {
var e = a[i];
console.log("[*] " + e.name + ": " + e.address);
}
}

踩坑 2

如果 frida17 的 python 库来注入脚本,必然会报错:Java’ is not defined

这是为什么呢,查了官网的 frida17 更新公告:https://frida.re/news/2025/05/17/frida-17-0-0-released/

frida17 相比于之前的版本改了很多东西,官网有一一列举

比如之前的 api 调用方式的问题

之所以不能用 python 调用 frida,是因为 frida17 不再将**Bridges Frida 的 GumJS 运行时捆绑在一起,但Frida REPL(命令行执行)**还能继续用

所以我们需要手动绑定 frida-java-bridge

初始化项目

1
2
3
frida-create -t agent
npm install frida-java-bridge
npm install @tyeps/frida-gum

将脚本写到 agent/index.ts 中,要引入 frida-java-bridge 依赖

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import Java from "frida-java-bridge"

Java.perform(function () {
setTimeout(function() {
var MainActivity = Java.use("com.ad2001.frida0x1.MainActivity");

MainActivity.check.overload('int', 'int').implementation = function (a, b) {
console.log("[*] 拦截到 check(),原始参数为: " + a + ", " + b);
var result = this.check(4, 12);
};

var TextView = Java.use("android.widget.TextView");

TextView.setText.overload('java.lang.CharSequence').implementation = function (text) {
var content = text.toString();
console.log("[*] TextView 显示的内容是: " + content);

return this.setText(text);
};
}, 2000);
});

手动编译成 js 执行

1
frida-compile index.ts -o index.js

但还是会提示报错,这因为 ts 是一种强类型语言,但作为函数的两个参数 a,b 和下面 text 没有声明类型,也没有任何标识符修复

所以需要手动给这些参数添加上类型

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import Java from "frida-java-bridge"

Java.perform(function () {
setTimeout(function() {
var MainActivity = Java.use("com.ad2001.frida0x1.MainActivity");

MainActivity.check.overload('int', 'int').implementation = function (**a: number, b: number**) {
console.log("[*] 拦截到 check(),原始参数为: " + a + ", " + b);
var result = this.check(_4_, _12_);
return result;
};

var TextView = Java.use("android.widget.TextView");

TextView.setText.overload('java.lang.CharSequence').implementation = function (**text: any**) {
var content = text.toString();
console.log("[*] TextView 显示的内容是: " + content);

return this.setText(text);
};
}, _2000_);
});

编译成功后会输出一个 index.js

执行脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import frida
import sys

def on_message(message, data):
if message['type'] == 'send':
print("[*] {0}".format(message['payload']))
else:
print(message)

device = frida.get_usb_device()

with open("agent/index.js", encoding="utf-8") as f:
script_code = f.read()

package_name = "com.ad2001.frida0x1"
print(f"[*] 尝试启动应用: {package_name}")

pid = device.spawn([package_name])
print(f"[*] 应用已启动,PID: {pid}")

process = device.attach(pid)

script = process.create_script(script_code)
script.on('message', on_message)
script.load()

device.resume(pid)

print("[*] 脚本已注入,正在监听...")
print("[*] 按Ctrl+C退出")
sys.stdin.read()

参考:

https://bbs.kanxue.com/thread-287941.htm

https://frida.re/news/2025/05/17/frida-17-0-0-released/


frida17踩坑
http://example.com/2025/09/07/frida17踩坑/
作者
Gilgamesh
发布于
2025年9月7日
许可协议