Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter debug Apk decompile to get the source code

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.

like image 310
Jagraj Singh Avatar asked Dec 07 '18 09:12

Jagraj Singh


People also ask

How do you get the source code on Flutter app?

Try to search strings like "dart", "import", "void" and other keywords in 'extracted_code. dart', it will help you find the code itself. Better search for filename, your class names, or some regex like runApp\(. *\(\)\); in vscode or using sed .

How do I get source code from APK file?

May be the easy one to see the source: In Android studio 2.3, Build -> Analyze APK -> Select the apk that you want to decompile . You will see it's source code.


Video Answer


1 Answers

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

like image 90
user3467955 Avatar answered Oct 19 '22 00:10

user3467955