Retrieving the original Dart code from a compiled Flutter application (libapp.so) is challenging because Flutter compiles Dart code into native machine code (AOT compilation) for release builds, making the original source code non-recoverable in its exact form. However, you can attempt to extract some information, such as strings, symbols, or decompiled pseudo-code, using reverse engineering tools. Here’s how you can approach it:
1. Extract libapp.so from the APK/IPA
- For Android:
- Unzip the APK file (e.g.,
unzip app-release.apk -d extracted_apk).
- Locate
libapp.so in extracted_apk/lib/<abi>/ (e.g., armeabi-v7a, arm64-v8a).
- For iOS:
- Extract the IPA (rename to
.zip and unzip).
- The binary is in
Payload/<app>.app/Frameworks/App.framework/App.
2. Analyze libapp.so
Option A: Extract Strings
Use strings to find human-readable text (e.g., debug strings, hardcoded values):
strings libapp.so | less
Option B: Use a Disassembler/Decompiler
Tools like Ghidra, IDA Pro, or radare2 can analyze the binary:
- Open
libapp.so in Ghidra/IDA.
- Look for Dart-related symbols (e.g.,
kDartIsolateSnapshotData, kDartVmSnapshotData).
- The decompiled code will be low-level (ARM/x86 assembly or C-like pseudocode), not the original Dart.
Option C: Extract Snapshot Data (Advanced)
Flutter apps embed Dart snapshots in libapp.so. You can try extracting them:
- Find snapshot offsets:
- Use a hex editor (e.g.,
xxd or 010 Editor) to locate snapshot sections.
- Look for magic bytes (e.g.,
kDartVmSnapshotData or kDartIsolateSnapshotData).
- Extract snapshots:
- Use tools like
darter or reFlutter (for older Flutter versions).
- Note: Newer Flutter versions (3.0+) use obfuscated snapshots, making this harder.
Option D: Use ReFlutter (for Older Flutter Versions)
reFlutter is a tool to partially recover Dart code from Flutter apps (works best for apps built with Flutter ≤2.8):
python3 reFlutter.py path/to/libapp.so
3. Limitations
- No perfect recovery: You won’t get the original Dart code. At best, you’ll see decompiled logic or strings.
- Obfuscation: Flutter 3.0+ uses snapshot obfuscation (via
--obfuscate), making recovery nearly impossible.
- Stripped symbols: Release builds remove debug symbols, further reducing readability.
4. Prevention (For Developers)
If you’re a developer wanting to protect your code:
- Use obfuscation (
flutter build --obfuscate --split-debug-info).
- Avoid hardcoding sensitive strings.
- Use native code for critical logic (via platform channels).
Conclusion
While you can’t fully recover Dart code from libapp.so, you can extract strings and analyze the binary structure. For meaningful reverse engineering, focus on understanding the app’s behavior rather than recovering exact source code. For newer Flutter apps, obfuscation makes this extremely difficult.