Added support for Format21h

git-svn-id: https://smali.googlecode.com/svn/trunk@23 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
JesusFreke@JesusFreke.com 2009-04-27 01:26:46 +00:00
parent 68d72351ba
commit 7a0895de9b
5 changed files with 147 additions and 1 deletions

View File

@ -284,6 +284,13 @@ INSTRUCTION_FORMAT21c_TYPE_PHRASE
WS? ',' WS? WS? ',' WS?
CLASS_OR_ARRAY_TYPE_DESCRIPTOR_EMITCHILD; CLASS_OR_ARRAY_TYPE_DESCRIPTOR_EMITCHILD;
INSTRUCTION_FORMAT21h_PHRASE
: INSTRUCTION_FORMAT21h_EMIT
WS
REGISTER_EMIT
WS? ',' WS?
INTEGER_LITERAL_EMIT;
INSTRUCTION_FORMAT21s_PHRASE INSTRUCTION_FORMAT21s_PHRASE
: INSTRUCTION_FORMAT21s_EMIT : INSTRUCTION_FORMAT21s_EMIT
WS WS
@ -758,6 +765,13 @@ fragment INSTRUCTION_FORMAT21c_TYPE
| 'const-class' | 'const-class'
; ;
fragment INSTRUCTION_FORMAT21h_EMIT
: INSTRUCTION_FORMAT21h {emit($INSTRUCTION_FORMAT21h, INSTRUCTION_FORMAT21h);};
fragment INSTRUCTION_FORMAT21h
: 'const/high16'
| 'const-wide/high16'
;
fragment INSTRUCTION_FORMAT21s_EMIT fragment INSTRUCTION_FORMAT21s_EMIT
: INSTRUCTION_FORMAT21s {emit($INSTRUCTION_FORMAT21s, INSTRUCTION_FORMAT21s);}; : INSTRUCTION_FORMAT21s {emit($INSTRUCTION_FORMAT21s, INSTRUCTION_FORMAT21s);};
fragment INSTRUCTION_FORMAT21s fragment INSTRUCTION_FORMAT21s

View File

@ -60,6 +60,7 @@ tokens {
I_STATEMENT_FORMAT21c_TYPE; I_STATEMENT_FORMAT21c_TYPE;
I_STATEMENT_FORMAT21c_FIELD; I_STATEMENT_FORMAT21c_FIELD;
I_STATEMENT_FORMAT21c_STRING; I_STATEMENT_FORMAT21c_STRING;
I_STATEMENT_FORMAT21h;
I_STATEMENT_FORMAT21s; I_STATEMENT_FORMAT21s;
I_STATEMENT_FORMAT21t; I_STATEMENT_FORMAT21t;
I_STATEMENT_FORMAT22c_FIELD; I_STATEMENT_FORMAT22c_FIELD;
@ -163,6 +164,9 @@ instruction returns [int size]
| //e.g. const-class v2 org/JesusFreke/HelloWorld2/HelloWorld2 | //e.g. const-class v2 org/JesusFreke/HelloWorld2/HelloWorld2
INSTRUCTION_FORMAT21c_TYPE REGISTER class_or_array_type_descriptor {$size = Format21c.Format.getByteCount();} INSTRUCTION_FORMAT21c_TYPE REGISTER class_or_array_type_descriptor {$size = Format21c.Format.getByteCount();}
-> ^(I_STATEMENT_FORMAT21c_TYPE[$start, "I_STATEMENT_FORMAT21c"] INSTRUCTION_FORMAT21c_TYPE REGISTER class_or_array_type_descriptor) -> ^(I_STATEMENT_FORMAT21c_TYPE[$start, "I_STATEMENT_FORMAT21c"] INSTRUCTION_FORMAT21c_TYPE REGISTER class_or_array_type_descriptor)
| //e.g. const/high16 v1, 1234
INSTRUCTION_FORMAT21h REGISTER INTEGER_LITERAL {$size = Format21h.Format.getByteCount();}
-> ^(I_STATEMENT_FORMAT21h[$start, "I_STATEMENT_FORMAT21h"] INSTRUCTION_FORMAT21h REGISTER INTEGER_LITERAL)
| //e.g. const/16 v1, 1234 | //e.g. const/16 v1, 1234
INSTRUCTION_FORMAT21s REGISTER INTEGER_LITERAL {$size = Format21s.Format.getByteCount();} INSTRUCTION_FORMAT21s REGISTER INTEGER_LITERAL {$size = Format21s.Format.getByteCount();}
-> ^(I_STATEMENT_FORMAT21s[$start, "I_STATEMENT_FORMAT21s"] INSTRUCTION_FORMAT21s REGISTER INTEGER_LITERAL) -> ^(I_STATEMENT_FORMAT21s[$start, "I_STATEMENT_FORMAT21s"] INSTRUCTION_FORMAT21s REGISTER INTEGER_LITERAL)

View File

@ -421,6 +421,16 @@ instruction returns[Instruction instruction]
$instruction = Format21c.Format.make(dexFile, opcode.value, regA, typeIdItem); $instruction = Format21c.Format.make(dexFile, opcode.value, regA, typeIdItem);
} }
| //e.g. const/high16 v1, 1234
^(I_STATEMENT_FORMAT21h INSTRUCTION_FORMAT21h REGISTER INTEGER_LITERAL)
{
Opcode opcode = Opcode.getOpcodeByName($INSTRUCTION_FORMAT21h.text);
short regA = parseRegister_byte($REGISTER.text);
short litB = parseIntLiteral_short($INTEGER_LITERAL.text);
$instruction = Format21h.Format.make(dexFile, opcode.value, regA, litB);
}
| //e.g. const/16 v1, 1234 | //e.g. const/16 v1, 1234
^(I_STATEMENT_FORMAT21s INSTRUCTION_FORMAT21s REGISTER INTEGER_LITERAL) ^(I_STATEMENT_FORMAT21s INSTRUCTION_FORMAT21s REGISTER INTEGER_LITERAL)
{ {

View File

@ -0,0 +1,70 @@
/*
* [The "BSD licence"]
* Copyright (c) 2009 Ben Gruver
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. 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.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
*/
package org.JesusFreke.dexlib.code.Format;
import org.JesusFreke.dexlib.code.Instruction;
import org.JesusFreke.dexlib.code.Opcode;
import org.JesusFreke.dexlib.DexFile;
public class Format21h extends Format
{
public static final Format21h Format = new Format21h();
private Format21h() {
}
public Instruction make(DexFile dexFile, byte opcode, short regA, short litB) {
byte[] bytes = new byte[4];
Opcode op = Opcode.getOpcodeByValue(opcode);
checkOpcodeFormat(op);
if (regA >= 1<<8) {
throw new RuntimeException("The register number must be less than v256");
}
bytes[0] = opcode;
bytes[1] = (byte)regA;
bytes[2] = (byte)litB;
bytes[3] = (byte)(litB >> 8);
return new Instruction(dexFile, bytes, null);
}
public int getByteCount()
{
return 4;
}
public String getFormatName()
{
return "21h";
}
}

View File

@ -24,7 +24,8 @@
;Testing Format22x and Format32x ;Testing Format22x and Format32x
;Testing Format21t ;Testing Format21t
;-32768 ;-32768
;-2147483648
;-9223372036854775808
.method static constructor <clinit>()V ;test .method static constructor <clinit>()V ;test
@ -87,6 +88,29 @@ HERE:
return-object v1 return-object v1
.end method .end method
.method public testFormat21h()Ljava/lang/String;
.registers 2
const/high16 v0, -32768
invoke-static {v0}, java/lang/Integer/toString(I)Ljava/lang/String;
move-result-object v1
return-object v1
.end method
.method public testFormat21h-wide()Ljava/lang/String;
.registers 3
const-wide/high16 v0, -32768
invoke-static {v0, v1}, java/lang/Long/toString(J)Ljava/lang/String;
move-result-object v2
return-object v2
.end method
.method public onCreate(Landroid/os/Bundle;)V .method public onCreate(Landroid/os/Bundle;)V
.registers 6 .registers 6
@ -288,6 +312,30 @@ HERE:
move-result-object v2 move-result-object v2
;test format21h
invoke-virtual {v4}, org/JesusFreke/HelloWorld2/HelloWorld2/testFormat21h()Ljava/lang/String;
move-result-object v1
invoke-virtual {v2, v1}, java/lang/String/concat(Ljava/lang/String;)Ljava/lang/String;
move-result-object v2
invoke-virtual {v2, v3}, java/lang/String/concat(Ljava/lang/String;)Ljava/lang/String;
move-result-object v2
;test format21h
invoke-virtual {v4}, org/JesusFreke/HelloWorld2/HelloWorld2/testFormat21h-wide()Ljava/lang/String;
move-result-object v1
invoke-virtual {v2, v1}, java/lang/String/concat(Ljava/lang/String;)Ljava/lang/String;
move-result-object v2
invoke-virtual {v2, v3}, java/lang/String/concat(Ljava/lang/String;)Ljava/lang/String;
move-result-object v2
check-cast v4, Landroid/app/Activity; check-cast v4, Landroid/app/Activity;
invoke-virtual {v0,v2}, android/widget/TextView/setText(Ljava/lang/CharSequence;)V invoke-virtual {v0,v2}, android/widget/TextView/setText(Ljava/lang/CharSequence;)V