0

I need to make some simple tweaks to Android APP that keeps crashing. Viewing the code and seeing possible problems is pretty simple.

I can either:

  • Use Apktool (eg. apktool d name_of_apk.apk -o my_folder) and then view .smali files that will be created from classes.dex
  • Use dex2jar, then view or decompile the jar file using JD-Gui
  • Just use https://bytecodeviewer.com/ which allows me to view the .dex file

As you noticed, all above was about viewing the code. I need to submit changes to it though. One way to do this would be to simply re-create the original project from decompiled sources, presumably using Android Studio. That seems like boring and tedious process.

Since changes I need to perform are miniscule, such as changing debug to true, I would appreciate simpler solution... Is it possible to just edit bytecode of the .dex file?

2

Use apktool to disassemble it into smali, edit the smali, then reassemble with apktool. I've done it tons of times, and it's easy.

You could also manually edit the dex file in simple cases, but this is a HUGE pain. I generally only resort to it in cases where smali itself can't handle something properly.

Note that dex files are much harder to manually edit than java classfiles due to all the extra constraints. First off, you have to update the checksums at the top of the file each time. Additionally, all the string tables must be sorted, which means that even simple renamings can change the entire file if it changes the order of any strings. There's also a lot of things that give offsets into the file. You pretty much need an assembler for dex.

  • How can I edit the smali files? I tried to put them into bytecode editor but it didn't understand the format... – Tomáš Zato Jun 27 '16 at 14:28
  • Smali files are text files, comparable to assembly code. Change them using your favourite text editor. apktool uses baksmali and smali internally to "disassemble" and "assemble" them. – Guntram Blohm supports Monica Jun 27 '16 at 16:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.