diff --git a/dexlib/src/main/java/org/jf/dexlib/Code/Opcode.java b/dexlib/src/main/java/org/jf/dexlib/Code/Opcode.java index 5679feb6..2355bd17 100644 --- a/dexlib/src/main/java/org/jf/dexlib/Code/Opcode.java +++ b/dexlib/src/main/java/org/jf/dexlib/Code/Opcode.java @@ -288,6 +288,20 @@ public enum Opcode NEW_INSTANCE_JUMBO((short)0xff03, "new-instance/jumbo", ReferenceType.type, Format.Format41c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_REGISTER), NEW_ARRAY_JUMBO((short)0xff04, "new-array/jumbo", ReferenceType.type, Format.Format52c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_REGISTER), + IGET_JUMBO((short)0xff06, "iget/jumbo", ReferenceType.field, Format.Format52c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_REGISTER), + IGET_WIDE_JUMBO((short)0xff07, "iget-wide/jumbo", ReferenceType.field, Format.Format52c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_REGISTER | Opcode.SETS_WIDE_REGISTER), + IGET_OBJECT_JUMBO((short)0xff08, "iget-object/jumbo", ReferenceType.field, Format.Format52c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_REGISTER), + IGET_BOOLEAN_JUMBO((short)0xff09, "iget-boolean/jumbo", ReferenceType.field, Format.Format52c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_REGISTER), + IGET_BYTE_JUMBO((short)0xff0a, "iget-byte/jumbo", ReferenceType.field, Format.Format52c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_REGISTER), + IGET_CHAR_JUMBO((short)0xff0b, "iget-char/jumbo", ReferenceType.field, Format.Format52c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_REGISTER), + IGET_SHORT_JUMBO((short)0xff0c, "iget-short/jumbo", ReferenceType.field, Format.Format52c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_REGISTER), + IPUT_JUMBO((short)0xff0d, "iput/jumbo", ReferenceType.field, Format.Format52c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE), + IPUT_WIDE_JUMBO((short)0xff0e, "iput-wide/jumbo", ReferenceType.field, Format.Format52c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE), + IPUT_OBJECT_JUMBO((short)0xff0f, "iput-object/jumbo", ReferenceType.field, Format.Format52c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE), + IPUT_BOOLEAN_JUMBO((short)0xff10, "iput-boolean/jumbo", ReferenceType.field, Format.Format52c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE), + IPUT_BYTE_JUMBO((short)0xff11, "iput-byte/jumbo", ReferenceType.field, Format.Format52c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE), + IPUT_CHAR_JUMBO((short)0xff12, "iput-char/jumbo", ReferenceType.field, Format.Format52c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE), + IPUT_SHORT_JUMBO((short)0xff13, "iput-short/jumbo", ReferenceType.field, Format.Format52c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE), SGET_JUMBO((short)0xff14, "sget/jumbo", ReferenceType.field, Format.Format41c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_REGISTER), SGET_WIDE_JUMBO((short)0xff15, "sget-wide/jumbo", ReferenceType.field, Format.Format41c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_REGISTER | Opcode.SETS_WIDE_REGISTER), SGET_OBJECT_JUMBO((short)0xff16, "sget-object/jumbo", ReferenceType.field, Format.Format41c, Opcode.CAN_THROW | Opcode.CAN_CONTINUE | Opcode.SETS_REGISTER), diff --git a/smali-integration-tests/src/test/smali/jumbo-field-tests/Format52c.smali b/smali-integration-tests/src/test/smali/jumbo-field-tests/Format52c.smali new file mode 100644 index 00000000..ea2004e5 --- /dev/null +++ b/smali-integration-tests/src/test/smali/jumbo-field-tests/Format52c.smali @@ -0,0 +1,199 @@ +#Copyright 2011, Google Inc. +#All rights reserved. +# +#Redistribution and use in source and binary forms, with or without +#modification, are permitted provided that the following conditions are +#met: +# +# * Redistributions of source code must retain the above copyright +#notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +#copyright notice, this list of conditions and the following disclaimer +#in the documentation and/or other materials provided with the +#distribution. +# * Neither the name of Google Inc. nor the names of its +#contributors may be used to endorse or promote products derived from +#this software without specific prior written permission. +# +#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +#A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +#OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +#SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +#LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +#DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +#THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +#(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +.class public LFormat52c; +.super Ljava/lang/Object; +.source "Format52c.smali" + +.method public constructor ()V + .registers 1 + invoke-direct {p0}, Ljava/lang/Object;->()V + return-void +.end method + +.method public test-iput-iget-jumbo()V + .registers 259 + .annotation runtime Lorg/junit/Test; + .end annotation + + new-instance v0, LzzzInstanceFields; + invoke-direct/range {v0}, LzzzInstanceFields;->()V + move-object/16 v258, v0 + + const v0, 23 + move/16 v256, v0 + iput/jumbo v256, v258, LzzzInstanceFields;->field99999:I + + iget/jumbo v257, v258, LzzzInstanceFields;->field99999:I + + invoke-static/range {v256 .. v257}, LAssert;->assertEquals(II)V + return-void +.end method + +.method public test-iput-object-iget-object-jumbo()V + .registers 259 + .annotation runtime Lorg/junit/Test; + .end annotation + + new-instance v0, LzzzInstanceFields; + invoke-direct/range {v0}, LzzzInstanceFields;->()V + move-object/16 v258, v0 + + new-instance v0, Ljava/lang/Object; + invoke-direct {v0}, Ljava/lang/Object;->()V + + move-object/16 v256, v0 + + iput-object/jumbo v256, v258, LzzzInstanceFields;->field99999Object:Ljava/lang/Object; + + iget-object/jumbo v257, v258, LzzzInstanceFields;->field99999Object:Ljava/lang/Object; + + invoke-static/range {v256 .. v257}, Lorg/junit/Assert;->assertEquals(Ljava/lang/Object;Ljava/lang/Object;)V + return-void +.end method + +.method public test-iput-wide-iget-wide-jumbo()V + .registers 261 + .annotation runtime Lorg/junit/Test; + .end annotation + + new-instance v0, LzzzInstanceFields; + invoke-direct/range {v0}, LzzzInstanceFields;->()V + move-object/16 v260, v0 + + const-wide v0, 0x200000000L + move-wide/16 v256, v0 + + iput-wide/jumbo v256, v260, LzzzInstanceFields;->field99999Wide:J + + iget-wide/jumbo v258, v260, LzzzInstanceFields;->field99999Wide:J + + invoke-static/range {v256 .. v259}, Lorg/junit/Assert;->assertEquals(JJ)V + return-void +.end method + +.method public test-iput-boolean-iget-boolean-true-jumbo()V + .registers 259 + .annotation runtime Lorg/junit/Test; + .end annotation + + new-instance v0, LzzzInstanceFields; + invoke-direct/range {v0}, LzzzInstanceFields;->()V + move-object/16 v258, v0 + + const v0, 1 + move/16 v256, v0 + + iput-boolean/jumbo v256, v258, LzzzInstanceFields;->field99999Boolean:Z + + iget-boolean/jumbo v257, v258, LzzzInstanceFields;->field99999Boolean:Z + + invoke-static/range {v257}, Lorg/junit/Assert;->assertTrue(Z)V + return-void +.end method + +.method public test-iput-boolean-iget-boolean-false-jumbo()V + .registers 259 + .annotation runtime Lorg/junit/Test; + .end annotation + + new-instance v0, LzzzInstanceFields; + invoke-direct/range {v0}, LzzzInstanceFields;->()V + move-object/16 v258, v0 + + const v0, 0 + move/16 v256, v0 + + iput-boolean/jumbo v256, v258, LzzzInstanceFields;->field99999Boolean:Z + + iget-boolean/jumbo v257, v258, LzzzInstanceFields;->field99999Boolean:Z + + invoke-static/range {v257}, Lorg/junit/Assert;->assertFalse(Z)V + return-void +.end method + +.method public test-iput-byte-iget-byte-jumbo()V + .registers 259 + .annotation runtime Lorg/junit/Test; + .end annotation + + new-instance v0, LzzzInstanceFields; + invoke-direct/range {v0}, LzzzInstanceFields;->()V + move-object/16 v258, v0 + + const v0, 120T + move/16 v256, v0 + + iput-byte/jumbo v256, v258, LzzzInstanceFields;->field99999Byte:B + + iget-byte/jumbo v257, v258, LzzzInstanceFields;->field99999Byte:B + + invoke-static/range {v256 .. v257}, LAssert;->assertEquals(II)V + return-void +.end method + +.method public test-iput-char-iget-char-jumbo()V + .registers 259 + .annotation runtime Lorg/junit/Test; + .end annotation + + new-instance v0, LzzzInstanceFields; + invoke-direct/range {v0}, LzzzInstanceFields;->()V + move-object/16 v258, v0 + + const v0, 'a' + move/16 v256, v0 + + iput-char/jumbo v256, v258, LzzzInstanceFields;->field99999Char:C + + iget-char/jumbo v257, v258, LzzzInstanceFields;->field99999Char:C + + invoke-static/range {v256 .. v257}, LAssert;->assertEquals(II)V + return-void +.end method + +.method public test-iput-short-iget-short-jumbo()V + .registers 259 + .annotation runtime Lorg/junit/Test; + .end annotation + + new-instance v0, LzzzInstanceFields; + invoke-direct/range {v0}, LzzzInstanceFields;->()V + move-object/16 v258, v0 + + const v0, 1234S + move/16 v256, v0 + + iput-short/jumbo v256, v258, LzzzInstanceFields;->field99999Short:S + + iget-short/jumbo v257, v258, LzzzInstanceFields;->field99999Short:S + + invoke-static/range {v256 .. v257}, LAssert;->assertEquals(II)V + return-void +.end method \ No newline at end of file diff --git a/smali-integration-tests/src/test/smali/jumbo-field-tests/TestSuite.smali b/smali-integration-tests/src/test/smali/jumbo-field-tests/TestSuite.smali index c6e53500..001e18f6 100644 --- a/smali-integration-tests/src/test/smali/jumbo-field-tests/TestSuite.smali +++ b/smali-integration-tests/src/test/smali/jumbo-field-tests/TestSuite.smali @@ -35,5 +35,7 @@ .end annotation .annotation runtime Lorg/junit/runners/Suite$SuiteClasses; - value = { LFormat41c; } + value = { LFormat41c;, + LFormat52c; + } .end annotation \ No newline at end of file diff --git a/smali-integration-tests/src/test/smali/jumbo-field-tests/zzzInstanceFields.smali b/smali-integration-tests/src/test/smali/jumbo-field-tests/zzzInstanceFields.smali new file mode 100644 index 00000000..ef4c444f --- /dev/null +++ b/smali-integration-tests/src/test/smali/jumbo-field-tests/zzzInstanceFields.smali @@ -0,0 +1,45 @@ +#Copyright 2011, Google Inc. +#All rights reserved. +# +#Redistribution and use in source and binary forms, with or without +#modification, are permitted provided that the following conditions are +#met: +# +# * Redistributions of source code must retain the above copyright +#notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +#copyright notice, this list of conditions and the following disclaimer +#in the documentation and/or other materials provided with the +#distribution. +# * Neither the name of Google Inc. nor the names of its +#contributors may be used to endorse or promote products derived from +#this software without specific prior written permission. +# +#THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +#"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +#LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +#A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +#OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +#SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +#LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +#DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +#THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +#(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +#OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +.class public LzzzInstanceFields; +.super Ljava/lang/Object; + +.method public constructor ()V + .registers 1 + invoke-direct {v0}, Ljava/lang/Object;->()V + return-void +.end method + +.field public field99999:I +.field public field99999Wide:J +.field public field99999Object:Ljava/lang/Object; +.field public field99999Boolean:Z +.field public field99999Byte:B +.field public field99999Char:C +.field public field99999Short:S \ No newline at end of file diff --git a/smali/src/main/antlr3/org/jf/smali/smaliLexer.g b/smali/src/main/antlr3/org/jf/smali/smaliLexer.g index ce1a6237..8320efb8 100644 --- a/smali/src/main/antlr3/org/jf/smali/smaliLexer.g +++ b/smali/src/main/antlr3/org/jf/smali/smaliLexer.g @@ -718,6 +718,22 @@ INSTRUCTION_FORMAT52c_TYPE : 'instance-of/jumbo' | 'new-array/jumbo'; +INSTRUCTION_FORMAT52c_FIELD + : 'iget/jumbo' + | 'iget-wide/jumbo' + | 'iget-object/jumbo' + | 'iget-boolean/jumbo' + | 'iget-byte/jumbo' + | 'iget-char/jumbo' + | 'iget-short/jumbo' + | 'iput/jumbo' + | 'iput-wide/jumbo' + | 'iput-object/jumbo' + | 'iput-boolean/jumbo' + | 'iput-byte/jumbo' + | 'iput-char/jumbo' + | 'iput-short/jumbo'; + /********************************************************** * Types diff --git a/smali/src/main/antlr3/org/jf/smali/smaliParser.g b/smali/src/main/antlr3/org/jf/smali/smaliParser.g index 8b22556f..19d4ff73 100644 --- a/smali/src/main/antlr3/org/jf/smali/smaliParser.g +++ b/smali/src/main/antlr3/org/jf/smali/smaliParser.g @@ -121,6 +121,7 @@ tokens { I_STATEMENT_FORMAT41c_FIELD; I_STATEMENT_FORMAT51l; I_STATEMENT_FORMAT52c_TYPE; + I_STATEMENT_FORMAT52c_FIELD; I_STATEMENT_ARRAY_DATA; I_STATEMENT_PACKED_SWITCH; I_STATEMENT_SPARSE_SWITCH; @@ -849,6 +850,9 @@ instruction returns [int size] | //e.g. instance-of/jumbo v0, v1, Ljava/lang/String; INSTRUCTION_FORMAT52c_TYPE REGISTER COMMA REGISTER COMMA nonvoid_type_descriptor {$size = Format.Format52c.size;} -> ^(I_STATEMENT_FORMAT52c_TYPE[$start, "I_STATEMENT_FORMAT52c_TYPE"] INSTRUCTION_FORMAT52c_TYPE REGISTER REGISTER nonvoid_type_descriptor) + | //e.g. iput-object/jumbo v1, v0 Lorg/jf/HelloWorld2/HelloWorld2;->helloWorld:Ljava/lang/String; + INSTRUCTION_FORMAT52c_FIELD REGISTER COMMA REGISTER COMMA fully_qualified_field {$size = Format.Format52c.size;} + -> ^(I_STATEMENT_FORMAT52c_FIELD[$start, "I_STATEMENT_FORMAT52c_FIELD"] INSTRUCTION_FORMAT52c_FIELD REGISTER REGISTER fully_qualified_field) | ARRAY_DATA_DIRECTIVE { diff --git a/smali/src/main/antlr3/org/jf/smali/smaliTreeWalker.g b/smali/src/main/antlr3/org/jf/smali/smaliTreeWalker.g index f4ffefa0..54aeccb7 100644 --- a/smali/src/main/antlr3/org/jf/smali/smaliTreeWalker.g +++ b/smali/src/main/antlr3/org/jf/smali/smaliTreeWalker.g @@ -1290,6 +1290,17 @@ instruction[int totalMethodRegisters, int methodParameterRegisters, ListhelloWorld:Ljava/lang/String; + ^(I_STATEMENT_FORMAT52c_FIELD INSTRUCTION_FORMAT52c_FIELD registerA=REGISTER registerB=REGISTER fully_qualified_field) + { + Opcode opcode = Opcode.getOpcodeByName($INSTRUCTION_FORMAT52c_FIELD.text); + int regA = parseRegister_short($registerA.text, $totalMethodRegisters, $methodParameterRegisters); + int regB = parseRegister_short($registerB.text, $totalMethodRegisters, $methodParameterRegisters); + + FieldIdItem fieldIdItem = $fully_qualified_field.fieldIdItem; + + $instructions.add(new Instruction52c(opcode, regA, regB, fieldIdItem)); + } | //e.g. .array-data 4 1000000 .end array-data ^(I_STATEMENT_ARRAY_DATA ^(I_ARRAY_ELEMENT_SIZE short_integral_literal) array_elements) { diff --git a/smali/src/main/jflex/smaliLexer.flex b/smali/src/main/jflex/smaliLexer.flex index 5bd13d35..8562e714 100644 --- a/smali/src/main/jflex/smaliLexer.flex +++ b/smali/src/main/jflex/smaliLexer.flex @@ -579,6 +579,12 @@ Type = {PrimitiveType} | {ClassDescriptor} | {ArrayDescriptor} "instance-of/jumbo" | "new-array/jumbo" { return newToken(INSTRUCTION_FORMAT52c_TYPE); } + + "iget/jumbo" | "iget-wide/jumbo" | "iget-object/jumbo" | "iget-boolean/jumbo" | "iget-byte/jumbo" | + "iget-char/jumbo" | "iget-short/jumbo" | "iput/jumbo" | "iput-wide/jumbo" | "iput-object/jumbo" | + "iput-boolean/jumbo" | "iput-byte/jumbo" | "iput-char/jumbo" | "iput-short/jumbo" { + return newToken(INSTRUCTION_FORMAT52c_FIELD); + } } /*Types*/ diff --git a/smali/src/test/resources/LexerTest/InstructionTest.smali b/smali/src/test/resources/LexerTest/InstructionTest.smali index c747c601..d43c2c87 100644 --- a/smali/src/test/resources/LexerTest/InstructionTest.smali +++ b/smali/src/test/resources/LexerTest/InstructionTest.smali @@ -241,4 +241,18 @@ sput-char/jumbo sput-short/jumbo const-wide instance-of/jumbo -new-array/jumbo \ No newline at end of file +new-array/jumbo +iget/jumbo +iget-wide/jumbo +iget-object/jumbo +iget-boolean/jumbo +iget-byte/jumbo +iget-char/jumbo +iget-short/jumbo +iput/jumbo +iput-wide/jumbo +iput-object/jumbo +iput-boolean/jumbo +iput-byte/jumbo +iput-char/jumbo +iput-short/jumbo \ No newline at end of file diff --git a/smali/src/test/resources/LexerTest/InstructionTest.tokens b/smali/src/test/resources/LexerTest/InstructionTest.tokens index 86d2981e..7f896add 100644 --- a/smali/src/test/resources/LexerTest/InstructionTest.tokens +++ b/smali/src/test/resources/LexerTest/InstructionTest.tokens @@ -241,4 +241,18 @@ INSTRUCTION_FORMAT41c_FIELD("sput-char/jumbo") INSTRUCTION_FORMAT41c_FIELD("sput-short/jumbo") INSTRUCTION_FORMAT51l("const-wide") INSTRUCTION_FORMAT52c_TYPE("instance-of/jumbo") -INSTRUCTION_FORMAT52c_TYPE("new-array/jumbo") \ No newline at end of file +INSTRUCTION_FORMAT52c_TYPE("new-array/jumbo") +INSTRUCTION_FORMAT52c_FIELD("iget/jumbo") +INSTRUCTION_FORMAT52c_FIELD("iget-wide/jumbo") +INSTRUCTION_FORMAT52c_FIELD("iget-object/jumbo") +INSTRUCTION_FORMAT52c_FIELD("iget-boolean/jumbo") +INSTRUCTION_FORMAT52c_FIELD("iget-byte/jumbo") +INSTRUCTION_FORMAT52c_FIELD("iget-char/jumbo") +INSTRUCTION_FORMAT52c_FIELD("iget-short/jumbo") +INSTRUCTION_FORMAT52c_FIELD("iput/jumbo") +INSTRUCTION_FORMAT52c_FIELD("iput-wide/jumbo") +INSTRUCTION_FORMAT52c_FIELD("iput-object/jumbo") +INSTRUCTION_FORMAT52c_FIELD("iput-boolean/jumbo") +INSTRUCTION_FORMAT52c_FIELD("iput-byte/jumbo") +INSTRUCTION_FORMAT52c_FIELD("iput-char/jumbo") +INSTRUCTION_FORMAT52c_FIELD("iput-short/jumbo") \ No newline at end of file