Differences between apktool and baksmali
Asked Answered
U

2

11

As far as I know, both apktool and baksmali are able to produce smali code out of .apk (.dex) files, and apktool makes use of the dexlib2. They are both APK packing/unpacking tools

But still I am not clear what are the main differences between apktool and smali/baksmali. in temrs of functionality with .dex files and extended features?

PS: One of the difference that I just found out is that apktool is able to work with multiple dex files inside an apk while baksmali cannot (at least for the time being)

I did try to read the source code but due to the lack of experience, I could not really understand the working flow of both tools. I would really appreciate If anyone could suggest some readings or flow charts, etc.

Thank you!

Uraemia answered 30/3, 2017 at 7:19 Comment(0)
F
13

smali/baksmali are an assembler/disassembler pair for the dex format. Baksmali takes a dex file and produces human readable assembly, and smali takes the human readable assembly and produces a dex file.

Apktool is a more general took for unpacking and repacking an apk. It actually uses smali/baksmali under the hood in order to assemble/disassemble the dex file. It also unpacks the binary resources and binary xml files back into the standard textual format, etc.

Furcula answered 30/3, 2017 at 18:10 Comment(0)
X
7

In short, apktool is for APK files and baksmali is for DEX files.

APK file is a zip archive with specific structure. This represents the Android app. This is what your smart phone or tablet downloads from the market, usually Google Play. The archive consists of the manifest, resources, asserts/data files, native libraries and the DEX file.

DEX file contains the app code. See https://source.android.com/devices/tech/dalvik/dex-format.html for details.

One more thing to say, is that apktool is capable to extract and pack back the resources file. (I believe baksmali doesn't do that, need to check.)

Ximenes answered 30/3, 2017 at 7:59 Comment(3)
Thanks. You are right about the assets and resource, which apktool is able to decode them. About the dex-format, I checked the opcodes before and was a bit lost. In deed, baksmali tool does the decompiling (.dex to smali code) and smali tool does the assembling of smali code into .dex. Both of them work as a pair and they belong to the same project of Jesus Freke github.com/JesusFreke/smali. I'm still figuring a way to understand these projects ...Uraemia
That's correct. Smali and baksmali work in a pair. As for the opcodes, I prefer this non-official reference: pallergabor.uw.hu/androidblog/dalvik_opcodes.htmlXimenes
That unofficial reference is super old, and based on his reverse engineering of the format before android was open source. The official documentation is .. well.. official. And it's much better - source.android.com/devices/tech/dalvik/dalvik-bytecode.htmlFurcula

© 2022 - 2024 — McMap. All rights reserved.