How to return a static result in smali function

泄露秘密 提交于 2019-12-14 03:58:48

问题


.method public c()Ljava/lang/String;
.locals 3

const/4 v1, 0x0

const-string v0, "wifi"

invoke-virtual {p0, v0}, Lcom/genwen/looltv/start/Appstart;->getSystemService(Ljava/lang/String;)Ljava/lang/Object;

move-result-object v0

check-cast v0, Landroid/net/wifi/WifiManager;

if-nez v0, :cond_1

move-object v0, v1

:goto_0
if-eqz v0, :cond_2

invoke-virtual {v0}, Landroid/net/wifi/WifiInfo;->getMacAddress()Ljava/lang/String;

move-result-object v0

if-eqz v0, :cond_0

const-string v1, ":"

const-string v2, ""

invoke-virtual {v0, v1, v2}, Ljava/lang/String;->replaceAll(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;

move-result-object v0

new-instance v1, Ljava/lang/StringBuilder;

const-string v2, "8c0f"

invoke-direct {v1, v2}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

invoke-virtual {v1, v0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

move-result-object v0

invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

move-result-object v0

:cond_0
:goto_1
return-object v0

:cond_1
invoke-virtual {v0}, Landroid/net/wifi/WifiManager;->getConnectionInfo()Landroid/net/wifi/WifiInfo;

move-result-object v0

goto :goto_0

:cond_2
move-object v0, v1

goto :goto_1
.end method

this is a simple smali function that returns the mac address of the device with '8c0f' at the beginning after stripping the : from the mac address.

i want it to return a static mac address like '8c0f0f0f0f0f0f0f' not the real mac address. how can i do that?


回答1:


just before the return-object v0 do the following

const-string v0, "8c0f0f0f0f0f0f0f"

so your full code will read

const-string v0, "8c0f0f0f0f0f0f0f"
return-object v0

you can also comment out the other code which uses the StringBuilder if you want.




回答2:


Here I use apktool to convert java to smali.

Java Code:

private static final String TAG = "Loop";

public static String getTag()
{
    return TAG;
}

smali code:

# static fields
.field private static final TAG:Ljava/lang/String; = "Loop"

.method public static getTag()Ljava/lang/String;
    .locals 1

    .prologue
  .line 35
    const-string v0, "Loop"

  .line 38
    return-object v0
.end method


来源:https://stackoverflow.com/questions/21889983/how-to-return-a-static-result-in-smali-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!