大家好。 我尝试使用 adb 和 frida 在 android apk 上挂接未加载的类。为此,我尝试以不寻常的方式加载 dex 文件中包含的类。我使用 Java.registerClass() 创建一个新类,以加载具有已实现的目标类的原始类。
但是,当我运行代码时,我应该处理问题:
{'type': 'error', 'description': "TypeError: cannot read property 'replace' of undefined", 'stack': "TypeError: cannot read property 'replace' of undefined
at w (frida/node_modules/frida-java-bridge/lib/types.js:334)
at registerClass (frida/node_modules/frida-java-bridge/lib/class-factory.js:153)
at registerClass (frida/node_modules/frida-java-bridge/index.js:271)
at bend4 (/script1.js:42)
at <eval> (/script1.js:48)", 'fileName': 'frida/node_modules/frida-java-bridge/lib/types.js', 'lineNumber': 334, 'columnNumber': 1}
{'type': 'error', 'description': 'Error: java.io.IOException: Permission denied', 'stack': 'Error: java.io.IOException: Permission denied
at <anonymous> (frida/node_modules/frida-java-bridge/lib/env.js:124)
at value (frida/node_modules/frida-java-bridge/lib/class-factory.js:1058)
at e (frida/node_modules/frida-java-bridge/lib/class-factory.js:580)
at apply (native)
at value (frida/node_modules/frida-java-bridge/lib/class-factory.js:963)
at e (frida/node_modules/frida-java-bridge/lib/class-factory.js:547)
at ue (frida/node_modules/frida-java-bridge/lib/class-factory.js:1190)
at fromBuffer (frida/node_modules/frida-java-bridge/lib/class-factory.js:1168)
at registerClass (frida/node_modules/frida-java-bridge/lib/class-factory.js:216)
at registerClass (frida/node_modules/frida-java-bridge/index.js:271)
at bend4 (/script1.js:42)
at <eval> (/script1.js:48)', 'fileName': 'frida/node_modules/frida-java-bridge/lib/env.js', 'lineNumber': 124, 'columnNumber': 1}
我指定在基于 virtualbox 设备的 Android VM 上以 root 权限运行钩子。
挂钩脚本:
function bend4(){
const p2 = Java.registerClass({
name:"com.example.orl",
// implements: [],
// superClass: targeted_class,
});
const p3 = p2.$new();
send(p3);
};
Java.perform(bend4());
预先感谢您的帮助。
RegisterClass的 Android 实现不会覆盖 JVM 中已存在的类。它添加了新的类,或者在已有类存在时失败 - 可能就是您在这里看到的。您可以使用它来扩展现有的类,ofc,但我不确定这就是您想要的。
要修改现有类的行为,您可以尝试Java.use在生成之前挂钩类行为并生成新实例或挂钩构造函数。还有其他模式,如 Java.choose 来查找和修改内存中的实例、跟踪者、拦截、间谍...
例如:
Java.perform(function () {
var orl_class = Java.use('com.example.orl')
var orl_instance = orl_class.$new();
send(orl_instance.toString());
});