Search code examples
androideditreverse-engineeringsmaliapktool

Editing smali. Issue : Low 16 bits must be zeroed out. Is the hexadecimal id is wrong?


Good morning/afternoon/evening, I am quiet a newbie in smali language and, while compiling, there is an issue I can't solve. I hope this question has not been asked before, but I checked out Google and some threads on stackoverflow and couldn't find any solution, so I assume that it hasn't. So, what happens :

I am trying to modify the C1.smali file of my app, I just want to change the wrong id of an array. So i just replaced the id, I didn't touch anything else.

The smali file after modification :

.line 52
invoke-virtual {p0}, Lcom/one/aplication/C1;->getResources()Landroid/content/res/Resources;

move-result-object v6

const/high16 v7, 0x7f060001
# array "Codes", id was 0x7f050000

invoke-virtual {v6, v7}, Landroid/content/res/Resources;->getStringArray(I)[Ljava/lang/String;

move-result-object v5

Of course, I verified that the id was correct, by checking the public.xml file(in res\values). I let you see by yourself :

 <public type="string" name="name1" id="0x7f05003d" />
<public type="string" name="surname1" id="0x7f05003e" />
<public type="array" name="server" id="0x7f060000" />
<public type="array" name="Codes" id="0x7f060001" />
<public type="menu" name="search" id="0x7f070000" />
<public type="id" name="txt" id="0x7f080000" />
<public type="id" name="button1" id="0x7f080001" />

Now, when i want to recompile, apktool throw an issue that i can't understand : C:\apktool>apktool b CC I: Using Apktool 2.0.0-RC4 I: Checking whether sources has changed... I: Smaling smali folder into classes.dex... CC\smali\com\one\aplication\C1.smali[58,4] Invalid literal value: 2131099649. Low 16 bits must be zeroed out. Exception in thread "main" brut.androlib.AndrolibException: Could not smali file : com/one/aplication/C1.smali at brut.androlib.src.SmaliBuilder.buildFile(SmaliBuilder.java:71) at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:55) at brut.androlib.src.SmaliBuilder.build(SmaliBuilder.java:41) at brut.androlib.Androlib.buildSourcesSmali(Androlib.java:354) at brut.androlib.Androlib.buildSources(Androlib.java:294) at brut.androlib.Androlib.build(Androlib.java:280) at brut.androlib.Androlib.build(Androlib.java:255) at brut.apktool.Main.cmdBuild(Main.java:225) at brut.apktool.Main.main(Main.java:84)

Do someone know something about the cause of this issue? The apktool issue is pointing to the line [58] which is the line I modified. I really don't know what happens! Thanks to anybody who will try to help me, and please excuse my poor English. Have a good day! :)


Solution

  • In the raw bytecode, the const/high16 instruction accepts a 16-bit operand, which is then shifted left 16 bits before being loaded into the register. In smali 2.0 and up, the operand is given in the post-shifted form, which requires, of course, that the least-significant 16 bits are all 0s.

    For example, to load the value 0x12340000 into a register, you could use

    const/high16 0x12340000
    

    And in the raw bytecode, the operand would be represented as the 16 bit value "0x1234".

    The value 0x7f060001 does not meet this requirement, so it can't be used with the const/high16 instruction. You could instead use the const instruction.

    const v7, 0x7f060001