1

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.

Joseph
  • 1,060
  • 3
  • 22
  • 53

2 Answers2

2

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.

Raghav Sood
  • 81,899
  • 22
  • 187
  • 195
  • But my most important operations and business logics were in byte format. You mean there is no way to get that back ? Should I go from scratch ? – Joseph Apr 13 '13 at 03:51
  • 2
    @Joseph There are byte tables available online, and if you really spent time on it you might be able to manually convert from byte code to corresponding Java, but it would take ages. I would suggest that you start from scratch. – Raghav Sood Apr 13 '13 at 03:53
  • A lot of optimizations? `Javac` doesn't really do optimization. The Android toolchain might though. – Antimony Apr 13 '13 at 04:01
  • 1
    @Antimony The Android tool chain does a fair bit of optimization, as they want to be able to run the code on even low end devices (at least uptil Android 2.2). There's an SO answer listing them out by a Google Employee, but I can't seem to find it atm. – Raghav Sood Apr 13 '13 at 04:03
  • @Raghunandan Obfuscation just makes decompiled code harder to read. It does not change the actual functioning and logic. – Raghav Sood Apr 13 '13 at 05:38
  • in that case even if he gets the original code it will be hard for him to read. So you are suggestion to start from scratch is good. +1 – Raghunandan Apr 13 '13 at 05:40
0

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.

Antimony
  • 37,781
  • 10
  • 100
  • 107