08
May
nexusae0_image_thumb79

If you're in the modding and theming community, your work is about to get a bit faster, because Smali v2.0 is now in beta and firing on all cylinders. The new version brings multithreaded processing and a few tweaks to the language that should result in cleaner-looking code.

Smali and baksmali are tools for assembling and disassembling the dex format used in Android apks. It's true that tools like this can be used for less than honorable endeavors, but they are also incredibly important to activities like deodexing apps for custom themes, tweaking functionality (like forcing portrait or landscape mode), and even digging around to learn more about various apps.


Multithreading

The biggest change to come with this update is multithreading, which splits processing of classes across as many as 6 cores. The developers recommend increasing available memory via a command line option to account for running several threads simultaneously. Concurrent processing is enabled by default, but the maximum number of cores can also be adjusted. The speed increase should be pretty noticeable, especially on larger and very complicated apps.

Command line call with option to boost memory usage:

smali -JXmx512m out -o classes.dex

Language Changes

The developer also took the opportunity to make a few changes to Smali code syntax to improve readability and function. A very welcome modification comes to the .parameter directive, which is now called .param and no longer requires ordered sequential lines for each parameter slot.

.method parameters(IILjava/lang/String;)V
 .parameter
 .parameter
 .parameter stringParameter

/** Becomes **/

.method parameters(IILjava/lang/String;)V
 .param p3, "stringParameter"

Similarly, .array-data has been tweaked so that numbers can be written in simple little-endian order without breaking them into a series bytes.

.array-data 0x4
 0x0t 0x0t 0x80t 0x0t
 0x0t 0x0t 0x40t 0x0t
 0x0t 0x0t 0x20t 0x0t
 0x0t 0x0t 0x10t 0x0t
.end array-data

/** Becomes **/

.array-data 4
 0x800000
 0x400000
 0x200000
 0x100000
.end array-data

Rounding out the list of changes, const/high16 and const-wide/high16 no longer accept just 16 bits for the instruction, but require the full value to be loaded into the register.

const/high16 v0, 0x1234
const-wide/high16 v0, 0x1234

/** Becomes **/

const/high16 v0, 0x12340000
const-wide/high16 v0, 0x1234000000000000

If you can't wait to give all of your processor cores a workout, hurry over to the Smali repository to pick up the latest version. Remember, this is still in beta, so check back frequently as updates and bug fixes will probably be uploaded often.

Source: Smali 2.0 on Google Code

Cody Toombs
Cody is a Software Engineer and Writer with a mildly overwhelming obsession with smartphones and the mobile world. If he’s been pulled away from the computer for any length of time, you might find him talking about cocktails and movies, sometimes resulting in the consumption of both.

  • ft

    Were you going to mention that smali is JesusFreke's project? Android old-timers may know JesusFreke as the creator of the modified G1 ROM that lead to CyanogenMod.

    • http://twitter.com/TeamAndIRC Justin Case

      Anyone interested in smali, or any Android old timer already knows smali is JesusFreke's baby.

  • Jeffrey Smith

    Hm... that const/high16 means I'll have to tweak my program that finds all the 0x7f references in smali code and adds a comment about the associated resource name.

    • Ben Gruver

      Hopefully it should let you simplify the script, so that you don't have to have a special case for the high16 instructions.

    • Ben Gruver

      Hopefully it should let you simplify the script, removing the special cases for the /high16 instructions :)