首页
社区
课程
招聘
frida hook函数时怎么获取当前实例
cyvk 2022-12-14 1305
1
2
3
4
5
6
7
8
9
10
Java.use("com.cyvk.hooktest.MyClass")["fun"].overloads.forEach(overload => {
    overload.implementation = function () {
        let ret = overload.apply(this, arguments);
        for (let i of arguments) {
            console.log("p ==> " + i)
        }
        console.log("r ==> " + ret)
        return ret;
    }
})

我想问一下在hook函数的时候怎么拿到这个函数的对象实例,我想在他调用这个函数的时候打印他的参数返回值,以及他当前实例对象所有属性的toString()

收藏
4条回答
Melanthe 2022-12-15

Java

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
/**
 * @author XiaoKoZi
 * @Create 2022-12-15-5:17
 */
public class Person {
    private String name;
    private int age;
 
    public Person(String name, int age) {
        this.name = name;
        this.age = age;
    }
 
    public int add(int i,int j){
        return i+j;
    }
 
 
    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }
}

Frida

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Java.perform(function () {
        Java.use("com.xiaokozi.libcdemo.Person").add.implementation = function(i,j){
            let ret = this.add(i,j);
            let obj = this;
            console.log()
            console.log("obj: ",obj)
            console.log("this: ",JSON.stringify(this))
            console.log("name: ",this.name.value.toString())
            console.log("age: ",this.age.value)
            console.log("ret: ",ret)
 
            return ret;
        }
    })

输出结果

1
2
3
4
5
obj:  Person{name='Melanthe', age=19}
this:  "<instance: com.xiaokozi.libcdemo.Person>"
name:  Melanthe
age:  19
ret:  5
回复 已采纳
Melanthe 2022-12-14

this就是当前的实例
console.log("this: ",this);

回复
cyvk 2022-12-14

不对啊,这里的this指的是被hook的函数并不是对象实例

回复
Furnnace 2022-12-15 2022-12-15编辑

这是java吗

回复