25

I have lost the source code of my flutter application due to drive corruption, but I have my debug.apk in my android phone. How can I decompile the Flutter apk to get source code? I have tried decompiling it using decompilers but it is not giving my source code as the Flutter source code is in Dart language.

MendelG
  • 14,885
  • 4
  • 25
  • 52
Jagraj Singh
  • 4,031
  • 4
  • 15
  • 33

1 Answers1

23

If your debug.apk is in debug mode then you can use apktool in order to extract the components of the apk (I'm using the word extracting since apk is a zip file).

Flutter, in debug mode, keeps the source code (with comments!) in the file kernel_blob.bin. Thus, using the following command should help you extract the code into a file:

strings /path/to/extracted/apk/assets/flutter_assets/kernel_blob.bin > extracted_code.dart

Please, pay attention - You'll need to clean 'extracted_code.dart', from irrelevant/garbage strings.

Try to search strings like "dart", "import", "void" and other keywords in 'extracted_code.dart', it will help you find the code itself.

Here's an example from my Ubuntu:

Example

If the apk is compiled in "release" mode, extracting the code will be much harder, since the code is compiled into isolate_snapshot_instr file, which is not a raw arm assembly, and is only deserialized using the Flutter engine in run-time. You can read more about it here

Hamed
  • 5,867
  • 4
  • 32
  • 56
user3467955
  • 561
  • 5
  • 11
  • Better search for filename, your class names, or some regex like `runApp\(.*\(\)\);` in vscode or using `sed`. Because the file would be very big eg: 25MB and `470850` lines. – Phani Rithvij Dec 06 '19 at 07:44
  • 1
    Please how do i perform this operation on windows. Windows can't seem to find command "strings". Thanks – Brendan Apr 12 '20 at 11:02
  • 1
    Hey, you can [https://learn.microsoft.com/en-us/sysinternals/downloads/strings](download strings) for your Windows machine – user3467955 Apr 14 '20 at 16:02
  • https://medium.com/@rondalal54/reverse-engineering-flutter-apps-5d620bb105c0 – Kamlesh May 26 '21 at 13:11
  • REALLY THANKS!!! It works. Was writing a game with my son, and everything got lost during Git operations. And this helped! There was a lot of byte code, but search by file and variable names worked. – wowkin2 Aug 13 '22 at 14:46