Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modifying existing methods in Smali

I've been looking at a simple method in smali (coming from Android here), and any I was wondering how I'd do something simple to it, such as return false. I've been trying to understand it from comparing with the Java counterparts to some examples and I think I get how most of it works, but any changes I make don't seem to go well.

Currently, in Java the method is:

public static boolean isEnabled(){
    return com.example.test.isEnabled();
}

and in smali it's:

.method public static isEnabled()Z
    .registers 1

    .prologue
    .line 3714
    invoke-static {}, Lcom/example/test;->isEnabled()Z

    move-result v0

    return v0
.end method

In the context above, how would I modify the method to just do the equivalent of Java return false;? From what I've been able to see, 0x0 is false, but just returning that causing issue when compiling the smali (expecting REGISTER?) so I was wondering what exactly I'd need to do.

A solution, as well as an explanation, would be appreciated! It's not for anything in particular, I just like to look at this stuff.

like image 285
whitfin Avatar asked Dec 07 '22 05:12

whitfin


1 Answers

You could answer this yourself fairly easily by writing a quick java program, compiling it, dx'ing it, then disassembling it.

public class EnabledTest {
    public static boolean isEnabled() {
        return false;
    }
}

And then compile/dx/disassemble it

javac EnabledTest.java
dx --dex --output=EnabledTest.dex EnabledTest.class
baksmali EnabledTest.dex

And you'll end up with something like

.method public static isEnabled()Z
    .registers 1
    const v0, 0
    return v0
.end method
like image 56
JesusFreke Avatar answered Dec 20 '22 05:12

JesusFreke