首頁
社區(qū)
課程
招聘
frida hook函數(shù)時怎么獲取當前實例
cyvk 2022-12-14 1455
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函數(shù)的時候怎么拿到這個函數(shù)的對象實例,我想在他調(diào)用這個函數(shù)的時候打印他的參數(shù)返回值,以及他當前實例對象所有屬性的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;
        }
    })

輸出結(jié)果

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

this就是當前的實例
console.log("this: ",this);

回復(fù)
cyvk 2022-12-14

不對啊,這里的this指的是被hook的函數(shù)并不是對象實例

回復(fù)
Furnnace 2022-12-15 2022-12-15編輯

這是java嗎

回復(fù)