将 .dart.snapshot 反编译为 Dart 源代码

Rez*_*edi 3 reverse-engineering decompiler apk dart flutter

根据dart-lang/sdk

从 1.21 开始,Dart VM 还支持应用程序快照,其中包括程序训练运行期间生成的所有解析类和编译代码。

    $ dart --snapshot=hello.dart.snapshot --snapshot-kind=app-jit hello.dart arguments-for-training
    Hello, world!
    $ dart hello.dart.snapshot arguments-for-use
    Hello, world!
Run Code Online (Sandbox Code Playgroud)

现在,我如何将这个 hello.dart.snapshot 文件反编译为 hello.dart?

在java语言编写的android Apk中,我们可以使用dex2jar工具反编译apk并从class.dex中获取jar文件,但是当使用flutter框架(用dart编写)开发应用程序时,如何反编译该应用程序并获取应用程序dart类?

此图像显示在 apk 资产文件中生成的快照文件。

Apk结构

use*_*955 9

在发布模式下,Flutter 将 Dart 代码编译为机器码,目前只有 ARMv7(此过程称为 AOT - Ahead-Of-Time 编译)。与原生 Android 应用程序不同,其中 Java 被编译为名为 Smali 的字节码,可以(非常容易地)再次反编译为 Java。

大部分机器码被编译成以特殊格式编写的“isolate_snapshot_instr”文件,并且flutter引擎(flutterlib.so,也可以在应用程序内部找到)在运行时将其加载到应用程序内存中。因此,您有两个合理的选择:

  1. 在运行时读取应用程序代码(.text 段)。您可以为此使用 frida dump,并提取您需要的已编译的 Dart 代码
  2. 修补/使用 Flutter 引擎来反序列化机器代码

如果您有 ipa(IOS 应用程序),那可能会更容易,因为所有代码都可以在 App.Framework 中找到。