使用Frida迭代函数的方法

huangapple go评论83阅读模式
英文:

How to Iterate Functions using Frida

问题

我有以下 Java 代码:

public class Class1 {

    public boolean Function1() {
    }

    public boolean Function2() {
    }
    
    public boolean Function3() {
    }
    ...
    public boolean FunctionX() {
    }
}

我希望使用 Frida 钩取所有这些函数。例如:

Java.perform(function(){
    var classVar = Java.use("Class1");
    
    classVar.Function1.implementation = function(){
        // 在这里添加代码
    };
    
    classVar.Function2.implementation = function(){
        // 在这里添加代码
    };
    
    classVar.Function2.implementation = function(){
        // 在这里添加代码
    };
    
    ...
    
    classVar.FunctionX.implementation = function(){
        // 在这里添加代码
    };
});

由于这些函数都属于同一个类,我想知道是否可以将它们放入一个数组中并通过循环来钩取它们?这样我的代码会更短。

英文:

I have the ff Java code:

public class Class1 {

    public boolean Function1() {
    }

    public boolean Function2() {
    }
    
    public boolean Function3() {
    }
    ...
    public boolean FunctionX() {
    }
}

And I wanted to hook all these functions with Frida. For example:

Java.perform(function(){
    var classVar = Java.use("Class1");
    
    classVar.Function1.implementation = function(){
        // code here
    };
    
    classVar.Function2.implementation = function(){
        // code here
    };
    
    classVar.Function2.implementation = function(){
        // code here
    };
    
    ...
    
    classVar.FunctionX.implementation = function(){
        // code here
    };
});

Since these functions belong to the same class, I wonder if I could hook all these functions by putting them in an array and loop through them? That way my code will be shorter.

答案1

得分: 2

你可以使用 Java.use("com.Class1").class.getDeclaredMethods() 来迭代类方法。

完整示例可以在 https://github.com/iddoeldor/frida-snippets#trace-class 找到。

英文:

You can iterate class methods with Java.use("com.Class1").class.getDeclaredMethods()

Full example can be found at https://github.com/iddoeldor/frida-snippets#trace-class

huangapple
  • 本文由 发表于 2020年4月7日 21:27:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/61081134.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定