Joseph
Joseph

Reputation: 1080

How to extract java files from .apk file

Unfortunately I deleted my Android source code. Tried to get jar using dex2jar and baksmali and used jd-gui to get java source files using my .apk file. Yes I got the files but the problem I have is, in more places in the java file, the code is in byte format. Need to get that to readable format to get myself to move forward.

Upvotes: 1

Views: 2619

Answers (2)

Antimony
Antimony

Reputation: 39441

Generally if your goal is to get readable source back, then something like JD-Gui is your best bet. But for cases where it fails, you could try Krakatau, a decompiler I've written.

Krakatau is designed to be able to decompile classfiles, even if they're obfuscated or not compiled from Java. However, the result is less readable then something like JD-Gui because it doesn't take advantage of the patterns left by the Java compiler. It's not perfect, but I think it's definitely worth a try.

P.S. Krakatau only supports JVM bytecode. You'll need a way to convert it from Android back into Java bytecode before you can decompile it.

Upvotes: 0

Raghav Sood
Raghav Sood

Reputation: 82533

Decompiling is not a perfect science, and you rarely get back the exact Java code you typed.

When you compile your code, a bunch of optimizations are done on it, which make decompiling more difficult if you're aiming to get the original code.

At best, you'll get a lot of decently decompiled code, along with some byte code. You should be able to figure out what Java code to substitue for that byte code based on where in the program it is, seeing as you wrote the original code.

For most simple apps, it is easier to rewrite from scratch than it is to decompile and try to fix that decompiled code.

tl;dr: Don't forget to backup your code. Ever.

Upvotes: 2

Related Questions