Flutter debug Apk decompile to get the source code
Asked Answered
E

1

26

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.

Eucaine answered 7/12, 2018 at 9:17 Comment(11)
Possible duplicate of Is there a way to get the source code from an APK file?Volga
flutter applications source code is in dart language , can java decompilers decompile other language code ?Eucaine
try it and let us knowVolga
sure , btw I recovered my project using easeus and now its running fine. Thanks for your concern .Eucaine
@F-1 I have tried decompiling the apk and I am not getting my dart code .Eucaine
@estn I am new to this community sir , I haven't asked a duplicate question but it is showing this question may have an answer here . can you please tell me sir how to remove that . I already edit my question with more specific info but it is still showing the same.Eucaine
@JagrajSingh have you find a solution?Bothersome
@LuigiSaggese No , not yet . btw I had tried java decompilers but got nothing .Eucaine
@JagrajSingh The same question as Luigi: do you have a solution now?Nervy
Well I tried @user3467955 's answer and I got small code snippets rather full code. You could try that .Eucaine
Better use github/gitlab :)Butyrate
H
25

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

Hienhieracosphinx answered 28/5, 2019 at 16:55 Comment(5)
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.Butyrate
Please how do i perform this operation on windows. Windows can't seem to find command "strings". ThanksHootchykootchy
Hey, you can [learn.microsoft.com/en-us/sysinternals/downloads/… strings) for your Windows machineHienhieracosphinx
medium.com/@rondalal54/…Richart
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.Cooperage

© 2022 - 2024 — McMap. All rights reserved.