是否可以创建抽象类的实例并仅为该实例重写函数?
public abstract class AbstractClass {
public void OverrideCallback() {
}
}
我想模拟这个:
new AbstractClass() {
@Override
public final OverrideCallback() {
// ...
}
};
我尝试了以下操作,但正如我所期望的,它覆盖了所有实例的 AbstractClass 函数。
const ac = Java.use('AbstractClass');
const acInstance = ac.$new();
acInstance.OverrideCallback.implementation = function () {
console.log('intercepted');
}
acInstance.OverrideCallback(); // prints intercepted
const acAnotherInstance = ac.$new();
acAnotherInstance.OverrideCallback(); // also prints intercepted
当我第一次阅读 frida 文档 时,我没有听懂
Java.registerClass
。这个挺强大的,还可以实现接口。
const DerivedClass = Java.registerClass({
name: 'DerivedClass',
superClass: [Java.use('AbstractClass')],
methods: {
OverrideCallback() {
console.log('intercepted');
},
}
});
const instance = DerivedClass.$new();
instance.OverrideCallback();