gpt4 book ai didi

android - 编辑smali文件

转载 作者:行者123 更新时间:2023-11-29 00:53:48 24 4
gpt4 key购买 nike

我有一个要添加日志的 smali 代码。由于我对smali一无所知,所以我需要你的帮助。

原始Java代码是:

    static HttpURLConnection createHttpURLConnection(String linkURL) {
try {
HttpURLConnection urlConnection = (HttpURLConnection) new URL(linkURL).openConnection();
urlConnection.setRequestProperty("Accept-Encoding", HTTP.IDENTITY_CODING);
urlConnection.setDoInput(true);
return urlConnection;
} catch (Exception e) {
Log.e("URLConnection exception", e.toString());
return null;
}
}

我的 smali 代码看起来像这样:

.method static createHttpURLConnection(Ljava/lang/String;)Ljava/net/HttpURLConnection;
.locals 5
.param p0, "linkURL" # Ljava/lang/String;

.prologue
.line 64
:try_start_0
new-instance v1, Ljava/net/URL;

invoke-direct {v1, p0}, Ljava/net/URL;-><init>(Ljava/lang/String;)V

.line 65
.local v1, "url":Ljava/net/URL;
invoke-virtual {v1}, Ljava/net/URL;->openConnection()Ljava/net/URLConnection;

move-result-object v2

check-cast v2, Ljava/net/HttpURLConnection;

.line 67
.local v2, "urlConnection":Ljava/net/HttpURLConnection;
const-string/jumbo v3, "Accept-Encoding"

const-string/jumbo v4, "identity"

invoke-virtual {v2, v3, v4}, Ljava/net/HttpURLConnection;->setRequestProperty(Ljava/lang/String;Ljava/lang/String;)V

.line 68
const/4 v3, 0x1

invoke-virtual {v2, v3}, Ljava/net/HttpURLConnection;->setDoInput(Z)V
:try_end_0
.catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

.line 74
.end local v1 # "url":Ljava/net/URL;
.end local v2 # "urlConnection":Ljava/net/HttpURLConnection;
:goto_0
return-object v2

.line 69
:catch_0
move-exception v0

.line 70
.local v0, "e":Ljava/lang/Exception;
const-string/jumbo v3, "URLConnection exception"

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

move-result-object v4

invoke-static {v3, v4}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

.line 71
const/4 v2, 0x0

goto :goto_0
.end method

我想添加这一行(在 Java 中显示):

Log.e("creating new connection to", linkURL);

作为函数中的第一行,在 try

在 smali 代码中会是什么样子?

谢谢!

最佳答案

这是在 try block 的第一行添加了您的日志的 smali 代码。您也可以使用 java2smali将 java 代码转换为 smali 的在线工具。

.method static createHttpURLConnection(Ljava/lang/String;)Ljava/net/HttpURLConnection;
.locals 5
.param p0, "linkURL" # Ljava/lang/String;

.prologue
.line 64
:try_start_0
const-string v0, "creating new connection to"

invoke-static {v0, p0}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

new-instance v1, Ljava/net/URL;

invoke-direct {v1, p0}, Ljava/net/URL;-><init>(Ljava/lang/String;)V

.line 65
.local v1, "url":Ljava/net/URL;
invoke-virtual {v1}, Ljava/net/URL;->openConnection()Ljava/net/URLConnection;

move-result-object v2

check-cast v2, Ljava/net/HttpURLConnection;

.line 67
.local v2, "urlConnection":Ljava/net/HttpURLConnection;
const-string/jumbo v3, "Accept-Encoding"

const-string/jumbo v4, "identity"

invoke-virtual {v2, v3, v4}, Ljava/net/HttpURLConnection;->setRequestProperty(Ljava/lang/String;Ljava/lang/String;)V

.line 68
const/4 v3, 0x1

invoke-virtual {v2, v3}, Ljava/net/HttpURLConnection;->setDoInput(Z)V
:try_end_0
.catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

.line 74
.end local v1 # "url":Ljava/net/URL;
.end local v2 # "urlConnection":Ljava/net/HttpURLConnection;
:goto_0
return-object v2

.line 69
:catch_0
move-exception v0

.line 70
.local v0, "e":Ljava/lang/Exception;
const-string/jumbo v3, "URLConnection exception"

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

move-result-object v4

invoke-static {v3, v4}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

.line 71
const/4 v2, 0x0

goto :goto_0
.end method

关于android - 编辑smali文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56831198/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com