问题
.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
This is a smali code which returns a Title and a Link from 'weblink' inside a database file. I want to return a static value (example 'This is the link www.google.com ' ) instead of Title and Link from database file. How can I do that? What code should I change? This is similar to this question here ( How to return a static result in smali function ) and I already tried that solution. But app is force closing. can somebody help?
回答1:
Simply override the content of the string object before it's appended to the 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;
Similarly, you can do the same for the 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;
Actually, you can override the whole string at once before it's put to the intent.
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
I hope you are not doing something bad.
来源:https://stackoverflow.com/questions/36588934/how-to-return-a-static-result-in-this-smali-code