Question

Is there any grammar specification available for smali code ? I am trying to play around with the smali code and one of the things that is missing me is the fact that some methods in smali have the .prologue section and some don't. Unfortunately the wiki doesn't seem to have information about smali grammar. Has anyone found yourself in this situation before ? Any suggestions/solutions would be much appreciated.

EDIT1: My objective is to add log messages to the beginning of onResume method of all activities of an app.

EDIT2: I am using ANTLRv4.1 parser to parse my smali files and I get a CommonTree (the parse tree) and a TokenStream from the smaliLexer. Now is creating the Token for the log instruction and altering the parse tree and thereafter generating the classes.dex file the right way to go ? So far I havent found a way to alter the TokenStream and I am not able to generate dex files from the altered ParseTree.

Was it helpful?

Solution

Almost everything in the smali language has a direct analogue in dalvik bytecode/dex format. In this case, the .prologue directive corresponds to the DBG_SET_PROLOGUE_END debug opcode that is part of the debug_info_item.

From http://s.android.com/tech/dalvik/dex-format.html:

sets the prologue_end state machine register, indicating that the next position entry that is added should be considered the end of a method prologue (an appropriate place for a method breakpoint). The prologue_end register is cleared by any special (>= 0x0a) opcode.

OTHER TIPS

You could look at the smali lexer description itself, it is built from a jflex grammar. Skip the preamble code to the line #177 where the tokens specifications begin.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top