如何在此 smali 代码中 return 静态结果

How to return a static result in this smali code

.method private a()Landroid/content/Intent;
.locals 5

.prologue
.line 297
:try_start_0
iget-object v0, p0, Lcom/myapp/c/f;->b:Lcom/myapp/context/ApplicationContext;

iget-object v0, v0, Lcom/myapp/context/ApplicationContext;->o:Lcom/myapp/context/b;

iget-object v0, v0, Lcom/myapp/context/b;->b:Ljava/util/List;

iget v1, p0, Lcom/myapp/c/f;->c:I

.line 298
invoke-interface {v0, v1}, Ljava/util/List;->get(I)Ljava/lang/Object;

move-result-object v0

check-cast v0, Lcom/myapp/data/weblink;

.line 299
new-instance v1, Landroid/content/Intent;

const-string v2, "android.intent.action.SEND"

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

.line 300
const-string v2, "text/plain"

invoke-virtual {v1, v2}, Landroid/content/Intent;->setType(Ljava/lang/String;)Landroid/content/Intent;

.line 301
const-string v2, "android.intent.extra.SUBJECT"

.line 302
invoke-virtual {v0}, Lcom/myapp/data/weblink;->getTitle()Ljava/lang/String;

move-result-object v3

.line 301
invoke-virtual {v1, v2, v3}, Landroid/content/Intent;->putExtra(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;

.line 303
const-string v2, "android.intent.extra.TEXT"

new-instance v3, Ljava/lang/StringBuilder;

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

.line 304
invoke-virtual {v0}, Lcom/myapp/data/weblink;->getTitle()Ljava/lang/String;

move-result-object v4

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

move-result-object v3

const-string v4, " "

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

move-result-object v3

invoke-virtual {v0}, Lcom/myapp/data/weblink;->getLink()Ljava/lang/String;

move-result-object v0

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

move-result-object v0

invoke-virtual {v3, 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

.line 303
invoke-virtual {v1, v2, v0}, Landroid/content/Intent;->putExtra(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;
:try_end_0
.catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

move-object v0, v1

.line 309
:goto_0
return-object v0

.line 307
:catch_0
move-exception v0

invoke-static {v0}, Lcom/myapp/d/e;->a(Ljava/lang/Exception;)V

.line 309
const/4 v0, 0x0

goto :goto_0
.end method

.method static synthetic a(Lcom/myapp/c/f;)Lcom/myapp/context/ApplicationContext;
.locals 1

.prologue
.line 51
iget-object v0, p0, Lcom/myapp/c/f;->b:Lcom/myapp/context/ApplicationContext;
return-object v0
.end method

这是一个 smali 代码,其中 return 是数据库文件中 'weblink' 的标题和 Link。我想 return 一个静态值(例如 'This is the link www.google.com ' )而不是数据库文件中的标题和 Link 。我怎样才能做到这一点?我应该更改什么代码?这类似于此处的问题 ( How to return a static result in smali function ),我已经尝试过该解决方案。但是应用程序强制关闭。有人可以帮忙吗?

在将字符串对象附加到 StringBuilder 之前简单地覆盖它的内容。

.line 304
invoke-virtual {v0}, Lcom/myapp/data/weblink;->getTitle()Ljava/lang/String;

move-result-object v4

# Add following line to override v4 before it's appended to the StringBuilder
const-string v4, "This is the link"

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

同样,您可以对 link

invoke-virtual {v0}, Lcom/myapp/data/weblink;->getLink()Ljava/lang/String;

move-result-object v0

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

move-result-object v0

# Add following line to override v0 before it's appended to the StringBuilder
const-string v0, "www.google.com"

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

实际上,您可以在将其放入意图之前立即覆盖整个字符串。

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

move-result-object v0

# Add this line
const-string v0, "The whole text you want, including the title and link"

.line 303
invoke-virtual {v1, v2, v0}, Landroid/content/Intent;->putExtra(Ljava/lang/String;Ljava/lang/String;)Landroid/content/Intent;
:try_end_0
.catch Ljava/lang/Exception; {:try_start_0 .. :try_end_0} :catch_0

希望你没有做坏事。