android - Insert method call in smali code -
i want add following call of method "send()" smali method:
invoke-direct {p0}, x->send()v
send() method of current class. x wildcard current class name. have 2 unresolved problems:
why invoke-direct need register p0? thought parameter.
do have take consideration p0 register? possible additional code makes entire app not compile if keep it? if so, how can find out register must used?
i want add method call arbitrary method. don't know method structure , can't predict register usage. therefore need know if p0 in upper code can change , under conditions.
i provide simple example emphasize intention:
let's assume have method reads contacts saved on smartphone:
.method private getcontacts()ljava/util/arraylist; .locals 12 .annotation system ldalvik/annotation/signature; value = { "()", "ljava/util/arraylist", "<", "ljava/lang/string;", ">;" } .end annotation .prologue const/4 v2, 0x0 .line 43 new-instance v7, ljava/util/arraylist; invoke-direct {v7}, ljava/util/arraylist;-><init>()v .line 44 .local v7, "contacts":ljava/util/arraylist;, "ljava/util/arraylist<ljava/lang/string;>;" invoke-virtual {p0}, lorg/puellen/contacts/mainactivity;->getcontentresolver()landroid/content/contentresolver; move-result-object v0 sget-object v1, landroid/provider/contactscontract$contacts;->content_uri:landroid/net/uri; move-object v3, v2 move-object v4, v2 move-object v5, v2 ...
i wrote parser automatically extracts code .apk file. want extend methods functionality, adding upper method call.
in case can add call @ beginning. difference appears in line 13 (see comment)
.method private getcontacts()ljava/util/arraylist; .locals 12 .annotation system ldalvik/annotation/signature; value = { "()", "ljava/util/arraylist", "<", "ljava/lang/string;", ">;" } .end annotation .prologue invoke-direct {p0}, lorg/my_package/custom_class/mainactivity;->send()v # added method call const/4 v2, 0x0 .line 43 new-instance v7, ljava/util/arraylist; invoke-direct {v7}, ljava/util/arraylist;-><init>()v .line 44 .local v7, "contacts":ljava/util/arraylist;, "ljava/util/arraylist<ljava/lang/string;>;" invoke-virtual {p0}, lorg/puellen/contacts/mainactivity;->getcontentresolver()landroid/content/contentresolver; move-result-object v0 sget-object v1, landroid/provider/contactscontract$contacts;->content_uri:landroid/net/uri; move-object v3, v2 move-object v4, v2 move-object v5, v2
until know add method call after .prologue. sure behaviour not work always. there "perfect" place add call? can use p0 in "invoke-direct" or how find out register can used?
question: can use p0 in "invoke-direct" or how find out register can used?
answer: "the first parameter non-static methods object method being invoked on." (link see blow in first comment). method not static, can use p0
now need know place method call.
Comments
Post a Comment