Frida SharedPreferences 挂钩问题 - 我怎样才能得到文件名和路径

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

我想用 Frida 分析一个应用程序。该应用程序有 20 多个不同的共享首选项 XML 文件。我正在挂钩共享首选项的 put 方法,就像在这个代码片段中一样:

var sp = Java.use("android.app.SharedPreferencesImpl$EditorImpl");
sp.putString.implementation = function(var0, var1) {
console.log(var0 + " " + var1 + "\n");
return this.putString(var0, var1);
}

这个类没有像 getPath() 或类似的方法。如何将代码添加到这个挂钩方法中,以接收正确的 xml 文件?当我使用 android.content.ContextWrapper 中的 getSharedPreferences 时,它不起作用,因为该应用程序使用了太多我无法分辨的 xml 文件,书面信息属于哪里。

我尝试从 SharedPreferencesImpl 挂钩变量和方法。我试图获取作为 java.io.File 对象的 mfile,但无法从文件对象调用 getPath() 方法。我还尝试挂钩 SharedPreferencesImpl 中的几种方法,但它不起作用。我也不确定这是否是正确的方法。

javascript android hook frida dynamic-analysis
1个回答
0
投票

您可以通过这种方式简单地获取写入字符串的文件名:

var sp = Java.use("android.app.SharedPreferencesImpl$EditorImpl");
sp.putString.implementation = function (key, value) {
    console.log(`putString("${key}", "${value}")`);

    let outer = this.this$0.value; // SharedPreferencesImpl 
    console.log("pref file: " + outer.mFile.value);

    return this.putString(key, value);
}

如何构建此代码

android.app.SharedPreferencesImpl$EditorImpl
android.app.SharedPreferencesImpl
的非静态内部类。这意味着每个
$EditorImpl
实例都有一个对其外部类
SharedPreferencesImpl
的引用。

你不会在这些类的源代码中看到这个字段,因为它是由编译器生成的隐式引用。所以Java代码在编译时,编译器会在内部类的所有构造函数中添加一个参数,并生成将这个值保存在内部类的一个特殊字段中。

可以在frida控制台执行以下两条命令获取

EditorImpl
的所有字段列表:

var sp = Java.use("android.app.SharedPreferencesImpl$EditorImpl");
sp.class.getDeclaredFields().forEach(f => console.log(f))

你会得到一个字段列表,包括这个:

final android.app.SharedPreferencesImpl android.app.SharedPreferencesImpl$EditorImpl.this$0

所以我们现在知道外部类的字段名称是

this$0
- 如果我们在
putString
的Frida hooking代码中,我们可以通过读取
this.this$0.value
来获取外部类。

从这里到

mFile
的值,
File
存放在我们感兴趣的地方,只是一小步:

this.this$0.value.mFile.value;
© www.soinside.com 2019 - 2024. All rights reserved.