notishell / smali

Automatically exported from code.google.com/p/smali
0 stars 0 forks source link

Register args in the v15+ range #68

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What seems to be the problem?
An App seems to be using over v15 (v16, v17, etc..) for register names. The 
Smali code was generated using the latest baksmali version.

What is the exact smali/baksmali command that you ran?
java -jar smali-1.2.6.jar smalidir

What version of smali/baksmali are you using? What rom are you working
from?
1.2.6

What is the airspeed velocity of an unladen swallow?
That depends, African or European?

Please provide any additional information below: error messages, symptoms,
etc.

Offending code:
.method public onCreate(Landroid/os/Bundle;)V
    .locals 20 # pretty high
    .parameter "someParam"

    .prologue
    .line 110

    # error seems to be here, line 1001
    const-string v15, "SomeString1"

    const-string v16, "OnCreate"

    invoke-static/range {v15 .. v16}, Landroid/util/Log;->w(Ljava/lang/String;Ljava/lang/String;)I

Exact error is:
file.smali[1001,4] All register args must fit in 4 bits

Original issue reported on code.google.com by tekpr...@gmail.com on 3 May 2011 at 1:56

GoogleCodeExporter commented 9 years ago
That makes no sense. Neither const-string nor invoke-static/range have 4 bit 
wideregister fields. const-string uses an 8-bit register field, so it is able 
to go up to v255, while invoke-static/range uses a 16bit starting register and 
an 8 bit register count, for a maximum register range of v65535..v65792

Are you positive you're looking at and assembling the correct code?

Original comment by JesusFr...@gmail.com on 3 May 2011 at 4:28

GoogleCodeExporter commented 9 years ago
Ah, sorry about that. I had not included a line out of hand that I was -sure- 
was not causing it, because it's never given me a problem before and the error 
had nothing to do with that line. My mistake.

I added back the line, getApplicationContext. It's called elsewhere in the code 
exactly like that but with no problems.

.class public Lfile;
.super Landroid/app/Activity;
.source "file.java"

.method static constructor <clinit>()V
    # stuff
.end method

.method public onCreate(Landroid/os/Bundle;)V
    .locals 20
    .parameter "someParam"

    .prologue
    .line 110
    invoke-virtual {p0}, Lfile;->getApplicationContext()Landroid/content/Context;

    const-string v15, "SomeString1"

    const-string v16, "OnCreate"

    invoke-static/range {v15 .. v16}, Landroid/util/Log;->w(Ljava/lang/String;Ljava/lang/String;)I

Is onCreate of an Activity special? After your previous comment I thought about 
trying something like this:
    invoke-virtual/range {p0 .. p0}, Lfile;->getBaseContext()Landroid/content/Context;

Which works fine. Is the error saying that p0 is not 4 bits?

Original comment by tekpr...@gmail.com on 3 May 2011 at 12:15

GoogleCodeExporter commented 9 years ago
Yes, that is in fact the offending line. There is some information on the 
Registers wiki page about the difference between the v* and p* registers. In 
short, the p* registers are aliased to the end of the v registers, based on how 
many registers are used and how many parameters are in the method. For this 
method, there are 22 registers total (20 "local" registers, and 2 parameter 
registers), and so p0 is aliased to v19.

Original comment by JesusFr...@gmail.com on 3 May 2011 at 2:27

GoogleCodeExporter commented 9 years ago
Thanks for the explanation and writing up the documentation. I've looked at 
several more apps and they all use invoke-virtual/range to get context when the 
number of local registers is high enough.

Original comment by tekpr...@gmail.com on 3 May 2011 at 2:37