Added support for string and type encoded values

git-svn-id: https://smali.googlecode.com/svn/trunk@159 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
JesusFreke@JesusFreke.com 2009-06-18 01:50:18 +00:00
parent 6ef13753e7
commit 2c5df648d0
5 changed files with 109 additions and 3 deletions

View File

@ -29,6 +29,8 @@
package org.jf.baksmali.Adaptors.EncodedValue;
import org.jf.dexlib.EncodedValue.*;
import org.jf.dexlib.TypeIdItem;
import org.jf.dexlib.StringIdItem;
public abstract class EncodedValueAdaptor {
public static EncodedValueAdaptor make(EncodedValue encodedValue) {
@ -62,9 +64,9 @@ public abstract class EncodedValueAdaptor {
case VALUE_SHORT:
return new SimpleEncodedValueAdaptor(((ShortEncodedValueSubField)encodedValue.getValue()).getValue());
case VALUE_STRING:
return null;
return new StringEncodedValueAdaptor(((EncodedIndexedItemReference<StringIdItem>)encodedValue.getValue()).getValue());
case VALUE_TYPE:
return null;
return new TypeEncodedValueAdaptor(((EncodedIndexedItemReference<TypeIdItem>)encodedValue.getValue()).getValue());
}
return null;
}

View File

@ -0,0 +1,48 @@
/*
* [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

@ -0,0 +1,49 @@
/*
* [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.TypeIdItem;
import org.jf.dexlib.util.Utf8Utils;
public class TypeEncodedValueAdaptor extends EncodedValueAdaptor {
private TypeIdItem typeIdItem;
public TypeEncodedValueAdaptor(TypeIdItem typeIdItem) {
this.typeIdItem = typeIdItem;
}
public String getFormat() {
return "SimpleEncodedValue";
}
public Object getValue() {
return typeIdItem.getTypeDescriptor();
}
}

View File

@ -265,4 +265,9 @@ EncodedValue(EncodedValue) ::=
SimpleEncodedValue(EncodedValue) ::=
<<
<EncodedValue.Value>
>>
StringEncodedValue(EncodedValue) ::=
<<
"<EncodedValue.Value>"
>>

View File

@ -29,8 +29,10 @@
.field public static boolTrueStaticField:Z = true
.field public static boolFalseStaticField:Z = false
.field public static typeStaticField:Ljava/lang/Class; = Lbaksmali/test/class;
.field public static stringStaticField:Ljava/lang/String; = "test"
.field public static stringEscapedStaticField:Ljava/lang/String; = "test\ntest"
.field public instanceField:Ljava/lang/String;