Implemented field and method encoded values, and redid how string and type encoded values are handled

git-svn-id: https://smali.googlecode.com/svn/trunk@162 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
JesusFreke@JesusFreke.com 2009-06-18 02:31:38 +00:00
parent 5f50a1a8b3
commit 5e28c634e7
5 changed files with 31 additions and 62 deletions

View File

@ -28,20 +28,21 @@
package org.jf.baksmali.Adaptors.EncodedValue; package org.jf.baksmali.Adaptors.EncodedValue;
import org.jf.dexlib.TypeIdItem; import org.jf.dexlib.IndexedItem;
import org.jf.baksmali.Adaptors.Reference.Reference;
public class TypeEncodedValueAdaptor extends EncodedValueAdaptor { public class EncodedIndexedItemAdaptor extends EncodedValueAdaptor {
private TypeIdItem typeIdItem; private Reference reference;
public TypeEncodedValueAdaptor(TypeIdItem typeIdItem) { public EncodedIndexedItemAdaptor(Reference reference) {
this.typeIdItem = typeIdItem; this.reference = reference;
} }
public String getFormat() { public String getFormat() {
return "SimpleEncodedValue"; return "EncodedIndexedItemReference";
} }
public Object getValue() { public Object getValue() {
return typeIdItem.getTypeDescriptor(); return reference;
} }
} }

View File

@ -31,6 +31,9 @@ package org.jf.baksmali.Adaptors.EncodedValue;
import org.jf.dexlib.EncodedValue.*; import org.jf.dexlib.EncodedValue.*;
import org.jf.dexlib.StringIdItem; import org.jf.dexlib.StringIdItem;
import org.jf.dexlib.TypeIdItem; import org.jf.dexlib.TypeIdItem;
import org.jf.dexlib.MethodIdItem;
import org.jf.dexlib.FieldIdItem;
import org.jf.baksmali.Adaptors.Reference.*;
public abstract class EncodedValueAdaptor { public abstract class EncodedValueAdaptor {
public static EncodedValueAdaptor make(EncodedValue encodedValue) { public static EncodedValueAdaptor make(EncodedValue encodedValue) {
@ -50,23 +53,27 @@ public abstract class EncodedValueAdaptor {
case VALUE_ENUM: case VALUE_ENUM:
return null; return null;
case VALUE_FIELD: case VALUE_FIELD:
return null; EncodedIndexedItemReference fieldEncodedReference = (EncodedIndexedItemReference)encodedValue.getValue();
return new EncodedIndexedItemAdaptor(new FieldReference((FieldIdItem)fieldEncodedReference.getValue()));
case VALUE_FLOAT: case VALUE_FLOAT:
return new SimpleEncodedValueAdaptor(((FloatEncodedValueSubField)encodedValue.getValue()).getValue()); return new SimpleEncodedValueAdaptor(((FloatEncodedValueSubField)encodedValue.getValue()).getValue());
case VALUE_INT: case VALUE_INT:
return new SimpleEncodedValueAdaptor(((IntEncodedValueSubField)encodedValue.getValue()).getValue()); return new SimpleEncodedValueAdaptor(((IntEncodedValueSubField)encodedValue.getValue()).getValue());
case VALUE_LONG: case VALUE_LONG:
return new SimpleEncodedValueAdaptor(((LongEncodedValueSubField)encodedValue.getValue()).getValue()); return new SimpleEncodedValueAdaptor(((LongEncodedValueSubField)encodedValue.getValue()).getValue());
case VALUE_METHOD: case VALUE_METHOD:
return null; EncodedIndexedItemReference methodEncodedReference = (EncodedIndexedItemReference)encodedValue.getValue();
return new EncodedIndexedItemAdaptor(new MethodReference((MethodIdItem)methodEncodedReference.getValue()));
case VALUE_NULL: case VALUE_NULL:
return null; return null;
case VALUE_SHORT: case VALUE_SHORT:
return new SimpleEncodedValueAdaptor(((ShortEncodedValueSubField)encodedValue.getValue()).getValue()); return new SimpleEncodedValueAdaptor(((ShortEncodedValueSubField)encodedValue.getValue()).getValue());
case VALUE_STRING: case VALUE_STRING:
return new StringEncodedValueAdaptor(((EncodedIndexedItemReference<StringIdItem>)encodedValue.getValue()).getValue()); EncodedIndexedItemReference stringEncodedReference = (EncodedIndexedItemReference)encodedValue.getValue();
return new EncodedIndexedItemAdaptor(new StringReference((StringIdItem)stringEncodedReference.getValue()));
case VALUE_TYPE: case VALUE_TYPE:
return new TypeEncodedValueAdaptor(((EncodedIndexedItemReference<TypeIdItem>)encodedValue.getValue()).getValue()); EncodedIndexedItemReference typeEncodedReference = (EncodedIndexedItemReference)encodedValue.getValue();
return new EncodedIndexedItemAdaptor(new TypeReference((TypeIdItem)typeEncodedReference.getValue()));
} }
return null; return null;
} }

View File

@ -1,48 +0,0 @@
/*
* [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.jf.baksmali.Adaptors.EncodedValue;
import org.jf.dexlib.StringIdItem;
import org.jf.dexlib.util.Utf8Utils;
public class StringEncodedValueAdaptor extends EncodedValueAdaptor {
private StringIdItem stringIdItem;
public StringEncodedValueAdaptor(StringIdItem stringIdItem) {
this.stringIdItem = stringIdItem;
}
public String getFormat() {
return "StringEncodedValue";
}
public Object getValue() {
return Utf8Utils.escapeString(stringIdItem.getStringValue());
}
}

View File

@ -255,6 +255,11 @@ MethodReference(MethodReference) ::=
<MethodReference.ContainingClass>-><MethodReference.MethodName><MethodReference.Prototype> <MethodReference.ContainingClass>-><MethodReference.MethodName><MethodReference.Prototype>
>> >>
TypeReference(TypeReference) ::=
<<
<TypeReference.TypeDescriptor>
>>
EncodedValue(EncodedValue) ::= EncodedValue(EncodedValue) ::=
@ -267,7 +272,7 @@ SimpleEncodedValue(EncodedValue) ::=
<EncodedValue.Value> <EncodedValue.Value>
>> >>
StringEncodedValue(EncodedValue) ::= EncodedIndexedItemReference(EncodedValue) ::=
<< <<
"<EncodedValue.Value>" <Reference(EncodedValue.Value)>
>> >>

View File

@ -34,6 +34,10 @@
.field public static stringStaticField:Ljava/lang/String; = "test" .field public static stringStaticField:Ljava/lang/String; = "test"
.field public static stringEscapedStaticField:Ljava/lang/String; = "test\ntest" .field public static stringEscapedStaticField:Ljava/lang/String; = "test\ntest"
.field public static fieldStaticField:Ljava/lang/reflect/Field; = Lbaksmali/test/class;->fieldStaticField:Ljava/lang/reflect/Field;
.field public static methodStaticField:Ljava/lang/reflect/Method; = Lbaksmali/test/class;->teshMethod(ILjava/lang/String;)Ljava/lang/String;
.field public instanceField:Ljava/lang/String; .field public instanceField:Ljava/lang/String;
.method public constructor <init>()V .method public constructor <init>()V