4

我的教授问您如何在他提供给我们的 apk 以使用 frida 启动和分析的课程中打印变量的内容:

package com.test_uni_apk.lib.proftest;


 public class ProfApi{


  public static class StateReady
  extends ProfApi.CallState
  {


  public CallStateReady() {}

  public CallStateReady(ProfApi.CallProc paramCallProc, 
    ProfApi.CallConnection[] paramArrayOfCallConnection, String 
     paramString, byte[] paramArrayOfByte, String[] paramArrayOfString)
   {

  this.printthis = paramArrayOfCallConnection;

  }


 }


}

我读到用 frida 你可以挂钩一个类,但我不明白如何打印 printthis 的值。

4

1 回答 1

3

我将假设CallStateReady是一个内部类,com.test_uni_apk.lib.proftest.ProfApi并且您想要挂钩 c'tor 并打印第二个参数#PleaseSubmitElegantCode

function printParamArrayOfCallConnection() {
    var ArrayList = Java.use("java.util.ArrayList");
    var CallConnection = Java.use("com.test_uni_apk.lib.proftest.ProfApi$CallConnection");
    Java.use("com.test_uni_apk.lib.proftest.ProfApi$CallStateReady") // dollar sign for inner class
        .$init // init represent the constructor
        // list of arguments are passed in byte code style, [B represents byte array
        // when you try to hook Frida will provide an informative error with all the possible arguments for overloading
        // copy & paste the right one which will look like this:
        .overload("Lcom..ProfApi.CallProc;", "Lcom...ProfApi.CallConnection;", "java.lang.String", "[B", "Ljava.lang.String;")
        .implementation = function(paramCallProc, paramArrayOfCallConnection, paramString, paramArrayOfByte, paramArrayOfString) {
            // first we cast to list
            var list = Java.cast(paramArrayOfCallConnection, ArrayList);
            // iterating the list
            for (var i = 0, l = list.size(); i < l; i++) {
                // casting each element to the object we created earlier
                var currentElement = Java.cast(list.get(i), CallConnection);
                // printing to terminal
                console.log(i, currentElement);
            }
            // executing original c'tor 
            this.$init(paramCallProc, paramArrayOfCallConnection, paramString, paramArrayOfByte, paramArrayOfString);
        }
}
Java.perform(printParamArrayOfCallConnection);
于 2018-09-26T14:15:31.053 回答