4

I know how to return a TRUE boolean from a function:

.locals 1
const/4 v0, 0x1
return v0

Now I need to return an integer (10000 value). How?

runs
  • 95
  • 2
  • 7

1 Answers1

6

The following method

public int return1000() {
    int i = 1000;
    return i;
}

Looks like this in smali

.method public return1000()I
    .locals 1

    .prologue
    .line 278
    const/16 v0, 0x3e8

    .line 279
    .local v0, "i":I
    return v0
.end method
pelotasplus
  • 9,852
  • 1
  • 35
  • 37
  • 1
    This is a useful approach for figuring out any sort of "how do I do [x] in smali" question – JesusFreke Aug 13 '15 at 23:28
  • 2
    This is how I always do it. Especially if you are trying to inject a lot of code, writing a static method and compiling in Android Studio will generate 99% of what you need for you, then you just need to add the generated smali method/class and modify a line or two in the target smali to hook it in. – Kane O'Riley Aug 14 '15 at 00:36