Frida-访问具有所需类型的类属性

问题描述 投票:1回答:2

我有一个被混淆的android程序。并且在该程序中,类具有相同名称的属性。像这样反编译的代码

public class d implements c
{
    public int a;
    public Cache$Entry a;
    public Cache a;
    public volatile a a;
    public e a;
    public ByteArrayOutputStream a;
    public volatile AtomicBoolean a;

或类似的smali代码

# interfaces
.implements Le/a/x/c;
# instance fields
.field public a:I
.field public a:Lanetwork/channel/cache/Cache$Entry;
.field public a:Lanetwork/channel/cache/Cache;
.field public volatile a:Ld/a/w/a;
.field public a:Le/a/x/e;
.field public a:Ljava/io/ByteArrayOutputStream;
.field public volatile a:Ljava/util/concurrent/atomic/AtomicBoolean;  

我创建了一个方法asd()的钩子,我需要访问此类的属性“ a”。但我需要类型为“ e.a.x.e”的属性“ a”]

Java.perform(function () {
   var var_ddd = Java.use("e.a.x.d");
    var_ddd.asd.implementation = function() {
       this.asd();
       console.log("e.a.x.d.asd()",Java.cast(this.a.value,Java.use("e.a.x.e")));
    };
});

[当我尝试编写this.a.value时-我得到了错误的属性。当我编写Java.cast(this.a.value,Java.use(“ e.a.x.e”))时我收到消息

TypeError: cannot read property 'hasOwnProperty' of undefined

请告诉我如何使用正确的类型获取正确的属性

javascript java android security frida
2个回答
0
投票

如果方法和同名字段之间存在冲突,则Frida内置了解决方法:在字段名前加下划线:_a

如果发生名称冲突,则方法和成员具有相同的名称,下划线将添加到成员。

但是我不确定此信息是否仍然有效。当前的Frida Java桥代码不喜欢使用冲突的字段名称重命名字段:https://github.com/frida/frida-java-bridge/blob/master/lib/class-factory.js#L301

我也看不到一种以不基于其名称的方式访问Frida中的字段的方法。

我看到的唯一机会是通过Java反射访问该字段:

const eaxe = Java.use("e.a.x.e");
for (f of eaxe.class.getDeclaredFields()) {
    if (f.getType().getName() == "e.a.x.e") {
        f.setAccessible(true);
        var fieldValue = f.get(this);
        console.log("Field of type e.a.x.e has value: " + fieldValue);
    }
}

注意:上面的代码尚未在Frida中进行测试,因此在实际工作之前可能需要进一步完善。


0
投票

感谢Robert,找到了一个解决方案。代码进行了一些小的更正

var lo_fld_eaxe;
var lv_found = false;
var lt_fields = this.getClass().getDeclaredFields();
for (var i = 0; i < lt_fields.length && lv_found == false; i++) {
    if(lt_fields[i].getName().toString() == 'a' &&  lt_fields[i].getType().getName().toString() == 'e.a.x.e' ){
       lo_fld_eaxe = lt_fields[i];
       lv_found = true; 
  }
}
if(lv_found == true) {
   lo_fld_eaxe.setAccessible(true);
   try{ 
          var       lv_e_a_x_e = lo_fld_eaxe.get(this);   
   }
   catch(err){
          console.log("Error:"+err);
   }
 }
© www.soinside.com 2019 - 2024. All rights reserved.