remove the "disable interning" functionality in dexlib

- rename the getInterned* methods to intern*
- add a lookup* method to a few item types that performs the same function, except that
it returns null if the item isn't found, instead of interning it

git-svn-id: https://smali.googlecode.com/svn/trunk@632 55b6fa8a-2a1e-11de-a435-ffa8d773f76a
This commit is contained in:
JesusFreke@JesusFreke.com
2010-02-22 00:55:50 +00:00
parent f5defb97c0
commit 928790f293
22 changed files with 218 additions and 97 deletions

View File

@ -41,7 +41,6 @@ public class DeodexUtil {
public DeodexUtil(Deodexerant deodexerant) { public DeodexUtil(Deodexerant deodexerant) {
this.deodexerant = deodexerant; this.deodexerant = deodexerant;
deodexerant.dexFile.disableInterning();
} }
private List<insn> makeInsnList(final CodeItem codeItem) { private List<insn> makeInsnList(final CodeItem codeItem) {

View File

@ -112,7 +112,7 @@ public class Deodexerant {
} }
private TypeIdItem resolveTypeOrSupertype(String type) { private TypeIdItem resolveTypeOrSupertype(String type) {
TypeIdItem typeItem = TypeIdItem.getInternedTypeIdItem(dexFile, type); TypeIdItem typeItem = TypeIdItem.internTypeIdItem(dexFile, type);
while (typeItem == null) { while (typeItem == null) {
type = lookupSuperclass(type); type = lookupSuperclass(type);
@ -120,7 +120,7 @@ public class Deodexerant {
throw new RuntimeException("Could not find the type or a supertype of " + type + " in the dex file"); throw new RuntimeException("Could not find the type or a supertype of " + type + " in the dex file");
} }
typeItem = TypeIdItem.getInternedTypeIdItem(dexFile, type); typeItem = TypeIdItem.internTypeIdItem(dexFile, type);
} }
return typeItem; return typeItem;
} }
@ -249,7 +249,7 @@ public class Deodexerant {
String methodRet) { String methodRet) {
TypeIdItem classTypeItem = resolveTypeOrSupertype(classType); TypeIdItem classTypeItem = resolveTypeOrSupertype(classType);
StringIdItem methodNameItem = StringIdItem.getInternedStringIdItem(dexFile, methodName); StringIdItem methodNameItem = StringIdItem.internStringIdItem(dexFile, methodName);
if (methodNameItem == null) { if (methodNameItem == null) {
return null; return null;
} }
@ -318,7 +318,7 @@ public class Deodexerant {
TypeListItem paramListItem = null; TypeListItem paramListItem = null;
if (paramList.size() > 0) { if (paramList.size() > 0) {
paramListItem = TypeListItem.getInternedTypeListItem(dexFile, paramList); paramListItem = TypeListItem.internTypeListItem(dexFile, paramList);
if (paramListItem == null) { if (paramListItem == null) {
throw new RuntimeException("Could not find type list item in dex file"); throw new RuntimeException("Could not find type list item in dex file");
} }
@ -326,7 +326,7 @@ public class Deodexerant {
TypeIdItem retType = getType(methodRet); TypeIdItem retType = getType(methodRet);
ProtoIdItem protoItem = ProtoIdItem.getInternedProtoIdItem(dexFile, retType, paramListItem); ProtoIdItem protoItem = ProtoIdItem.internProtoIdItem(dexFile, retType, paramListItem);
if (protoItem == null) { if (protoItem == null) {
return null; return null;
} }
@ -334,7 +334,7 @@ public class Deodexerant {
MethodIdItem methodIdItem; MethodIdItem methodIdItem;
do { do {
methodIdItem = MethodIdItem.getInternedMethodIdItem(dexFile, classTypeItem, protoItem, methodNameItem); methodIdItem = MethodIdItem.internMethodIdItem(dexFile, classTypeItem, protoItem, methodNameItem);
if (methodIdItem != null) { if (methodIdItem != null) {
return methodIdItem; return methodIdItem;
} }
@ -343,11 +343,11 @@ public class Deodexerant {
if (superclassDescriptor == null) { if (superclassDescriptor == null) {
return null; return null;
} }
classTypeItem = TypeIdItem.getInternedTypeIdItem(dexFile, superclassDescriptor); classTypeItem = TypeIdItem.internTypeIdItem(dexFile, superclassDescriptor);
while (classTypeItem == null && superclassDescriptor != null) { while (classTypeItem == null && superclassDescriptor != null) {
superclassDescriptor = lookupSuperclass(superclassDescriptor); superclassDescriptor = lookupSuperclass(superclassDescriptor);
classTypeItem = TypeIdItem.getInternedTypeIdItem(dexFile, superclassDescriptor); classTypeItem = TypeIdItem.internTypeIdItem(dexFile, superclassDescriptor);
} }
} while (true); } while (true);
} }
@ -371,12 +371,12 @@ public class Deodexerant {
String fieldName = parts[0]; String fieldName = parts[0];
String fieldType = parts[1]; String fieldType = parts[1];
StringIdItem fieldNameItem = StringIdItem.getInternedStringIdItem(dexFile, fieldName); StringIdItem fieldNameItem = StringIdItem.internStringIdItem(dexFile, fieldName);
if (fieldNameItem == null) { if (fieldNameItem == null) {
return null; return null;
} }
TypeIdItem fieldTypeItem = TypeIdItem.getInternedTypeIdItem(dexFile, fieldType); TypeIdItem fieldTypeItem = TypeIdItem.internTypeIdItem(dexFile, fieldType);
if (fieldTypeItem == null) { if (fieldTypeItem == null) {
return null; return null;
} }
@ -384,17 +384,17 @@ public class Deodexerant {
FieldIdItem fieldIdItem; FieldIdItem fieldIdItem;
do { do {
fieldIdItem = FieldIdItem.getInternedFieldIdItem(dexFile, classTypeItem, fieldTypeItem, fieldNameItem); fieldIdItem = FieldIdItem.internFieldIdItem(dexFile, classTypeItem, fieldTypeItem, fieldNameItem);
if (fieldIdItem != null) { if (fieldIdItem != null) {
return fieldIdItem; return fieldIdItem;
} }
String superclassDescriptor = lookupSuperclass(classTypeItem.getTypeDescriptor()); String superclassDescriptor = lookupSuperclass(classTypeItem.getTypeDescriptor());
classTypeItem = TypeIdItem.getInternedTypeIdItem(dexFile, superclassDescriptor); classTypeItem = TypeIdItem.internTypeIdItem(dexFile, superclassDescriptor);
while (classTypeItem == null && superclassDescriptor != null) { while (classTypeItem == null && superclassDescriptor != null) {
superclassDescriptor = lookupSuperclass(superclassDescriptor); superclassDescriptor = lookupSuperclass(superclassDescriptor);
classTypeItem = TypeIdItem.getInternedTypeIdItem(dexFile, superclassDescriptor); classTypeItem = TypeIdItem.internTypeIdItem(dexFile, superclassDescriptor);
} }
} while (classTypeItem != null); } while (classTypeItem != null);
throw new RuntimeException("Could not find field in dex file"); throw new RuntimeException("Could not find field in dex file");
@ -447,7 +447,7 @@ public class Deodexerant {
} }
private TypeIdItem getType(String typeDescriptor) { private TypeIdItem getType(String typeDescriptor) {
TypeIdItem type = TypeIdItem.getInternedTypeIdItem(dexFile, typeDescriptor); TypeIdItem type = TypeIdItem.internTypeIdItem(dexFile, typeDescriptor);
if (type == null) { if (type == null) {
throw new RuntimeException("Could not find type \"" + typeDescriptor + "\" in dex file"); throw new RuntimeException("Could not find type \"" + typeDescriptor + "\" in dex file");
} }

View File

@ -108,7 +108,7 @@ public class AnnotationDirectoryItem extends Item<AnnotationDirectoryItem> {
* @return an <code>AnnotationItem</code> for the given values, and that has been interned into the given * @return an <code>AnnotationItem</code> for the given values, and that has been interned into the given
* <code>DexFile</code> * <code>DexFile</code>
*/ */
public static AnnotationDirectoryItem getInternedAnnotationDirectoryItem(DexFile dexFile, public static AnnotationDirectoryItem internAnnotationDirectoryItem(DexFile dexFile,
AnnotationSetItem classAnnotations, AnnotationSetItem classAnnotations,
List<FieldAnnotation> fieldAnnotations, List<FieldAnnotation> fieldAnnotations,
List<MethodAnnotation> methodAnnotations, List<MethodAnnotation> methodAnnotations,

View File

@ -68,7 +68,7 @@ public class AnnotationItem extends Item<AnnotationItem> {
* @return an <code>AnnotationItem</code> for the given values, and that has been interned into the given * @return an <code>AnnotationItem</code> for the given values, and that has been interned into the given
* <code>DexFile</code> * <code>DexFile</code>
*/ */
public static AnnotationItem getInternedAnnotationItem(DexFile dexFile, AnnotationVisibility visibility, public static AnnotationItem internAnnotationItem(DexFile dexFile, AnnotationVisibility visibility,
AnnotationEncodedSubValue annotationValue) { AnnotationEncodedSubValue annotationValue) {
AnnotationItem annotationItem = new AnnotationItem(dexFile, visibility, annotationValue); AnnotationItem annotationItem = new AnnotationItem(dexFile, visibility, annotationValue);
return dexFile.AnnotationsSection.intern(annotationItem); return dexFile.AnnotationsSection.intern(annotationItem);

View File

@ -63,7 +63,7 @@ public class AnnotationSetItem extends Item<AnnotationSetItem> {
* @param annotations The annotations for this <code>AnnotationSetItem</code> * @param annotations The annotations for this <code>AnnotationSetItem</code>
* @return an <code>AnnotationSetItem</code> for the given annotations * @return an <code>AnnotationSetItem</code> for the given annotations
*/ */
public static AnnotationSetItem getInternedAnnotationSetItem(DexFile dexFile, List<AnnotationItem> annotations) { public static AnnotationSetItem internAnnotationSetItem(DexFile dexFile, List<AnnotationItem> annotations) {
AnnotationItem[] annotationsArray = new AnnotationItem[annotations.size()]; AnnotationItem[] annotationsArray = new AnnotationItem[annotations.size()];
annotations.toArray(annotationsArray); annotations.toArray(annotationsArray);
AnnotationSetItem annotationSetItem = new AnnotationSetItem(dexFile, annotationsArray); AnnotationSetItem annotationSetItem = new AnnotationSetItem(dexFile, annotationsArray);

View File

@ -63,7 +63,7 @@ public class AnnotationSetRefList extends Item<AnnotationSetRefList> {
* @param annotationSets The annotation sets for this <code>AnnotationSetRefList</code> * @param annotationSets The annotation sets for this <code>AnnotationSetRefList</code>
* @return an <code>AnnotationSetItem</code> for the given annotations * @return an <code>AnnotationSetItem</code> for the given annotations
*/ */
public static AnnotationSetRefList getInternedAnnotationSetRefList(DexFile dexFile, public static AnnotationSetRefList internAnnotationSetRefList(DexFile dexFile,
List<AnnotationSetItem> annotationSets) { List<AnnotationSetItem> annotationSets) {
AnnotationSetItem[] annotationSetsArray = new AnnotationSetItem[annotationSets.size()]; AnnotationSetItem[] annotationSetsArray = new AnnotationSetItem[annotationSets.size()];
annotationSets.toArray(annotationSetsArray); annotationSets.toArray(annotationSetsArray);

View File

@ -75,7 +75,7 @@ public class ClassDataItem extends Item<ClassDataItem> {
* @param virtualMethods The virtual methods for this class * @param virtualMethods The virtual methods for this class
* @return a new <code>ClassDataItem</code> with the given values * @return a new <code>ClassDataItem</code> with the given values
*/ */
public static ClassDataItem getInternedClassDataItem(DexFile dexFile, List<EncodedField> staticFields, public static ClassDataItem internClassDataItem(DexFile dexFile, List<EncodedField> staticFields,
List<EncodedField> instanceFields, List<EncodedField> instanceFields,
List<EncodedMethod> directMethods, List<EncodedMethod> directMethods,
List<EncodedMethod> virtualMethods) { List<EncodedMethod> virtualMethods) {

View File

@ -112,7 +112,7 @@ public class ClassDefItem extends Item<ClassDefItem> {
* @return a <code>ClassDefItem</code> for the given values, and that has been interned into the given * @return a <code>ClassDefItem</code> for the given values, and that has been interned into the given
* <code>DexFile</code> * <code>DexFile</code>
*/ */
public static ClassDefItem getInternedClassDefItem(DexFile dexFile, TypeIdItem classType, int accessFlags, public static ClassDefItem internClassDefItem(DexFile dexFile, TypeIdItem classType, int accessFlags,
TypeIdItem superType, TypeListItem implementedInterfaces, StringIdItem sourceFile, TypeIdItem superType, TypeListItem implementedInterfaces, StringIdItem sourceFile,
AnnotationDirectoryItem annotations, ClassDataItem classData, AnnotationDirectoryItem annotations, ClassDataItem classData,
List<StaticFieldInitializer> staticFieldInitializers) { List<StaticFieldInitializer> staticFieldInitializers) {
@ -128,6 +128,40 @@ public class ClassDefItem extends Item<ClassDefItem> {
return dexFile.ClassDefsSection.intern(classDefItem); return dexFile.ClassDefsSection.intern(classDefItem);
} }
/**
* Looks up a <code>ClassDefItem</code> from the given <code>DexFile</code> for the given
* values
* @param dexFile The <code>DexFile</code> that the <code>ClassDefItem</code> belongs to
* @param classType The type of the class
* @param accessFlags The access flags of the class
* @param superType The superclass of the class, or null if none (only valid for java.lang.Object)
* @param implementedInterfaces A list of the interfaces that the class implements, or null if none
* @param sourceFile The main source file that the class is defined in, or null if not available
* @param annotations The annotations for the class and its fields, methods and method parameters, or null if none
* @param classData The <code>ClassDataItem</code> containing the method and field definitions for the class
* @param staticFieldInitializers The initial values for the class's static fields, or null if none. If it is not
* null, it must contain the same number of items as the number of static fields in the class. The value in the
* <code>StaticFieldInitializer</code> for any field that doesn't have an explicit initial value can either be null
* or be the type-appropriate null/0 value.
* @return a <code>ClassDefItem</code> from the given <code>DexFile</code> for the given
* values, or null if it doesn't exist
*/
public static ClassDefItem lookupClassDefItem(DexFile dexFile, TypeIdItem classType, int accessFlags,
TypeIdItem superType, TypeListItem implementedInterfaces, StringIdItem sourceFile,
AnnotationDirectoryItem annotations, ClassDataItem classData,
List<StaticFieldInitializer> staticFieldInitializers) {
EncodedArrayItem encodedArrayItem = null;
if(!dexFile.getInplace() && staticFieldInitializers != null && staticFieldInitializers.size() > 0) {
assert classData != null;
assert staticFieldInitializers.size() == classData.getStaticFields().length;
encodedArrayItem = makeStaticFieldInitializersItem(dexFile, staticFieldInitializers);
}
ClassDefItem classDefItem = new ClassDefItem(dexFile, classType, accessFlags, superType, implementedInterfaces,
sourceFile, annotations, classData, encodedArrayItem);
return dexFile.ClassDefsSection.getInternedItem(classDefItem);
}
/** {@inheritDoc} */ /** {@inheritDoc} */
protected void readItem(Input in, ReadContext readContext) { protected void readItem(Input in, ReadContext readContext) {
classType = dexFile.TypeIdsSection.getItemByIndex(in.readInt()); classType = dexFile.TypeIdsSection.getItemByIndex(in.readInt());
@ -373,6 +407,6 @@ public class ClassDefItem extends Item<ClassDefItem> {
} }
ArrayEncodedSubValue encodedArrayValue = new ArrayEncodedSubValue(values); ArrayEncodedSubValue encodedArrayValue = new ArrayEncodedSubValue(values);
return EncodedArrayItem.getInternedEncodedArrayItem(dexFile, encodedArrayValue); return EncodedArrayItem.internEncodedArrayItem(dexFile, encodedArrayValue);
} }
} }

View File

@ -105,7 +105,7 @@ public class CodeItem extends Item<CodeItem> {
* @param encodedCatchHandlers a list of the exception handlers defined for this code/method or null if none * @param encodedCatchHandlers a list of the exception handlers defined for this code/method or null if none
* @return a new <code>CodeItem</code> with the given values. * @return a new <code>CodeItem</code> with the given values.
*/ */
public static CodeItem getInternedCodeItem(DexFile dexFile, public static CodeItem internCodeItem(DexFile dexFile,
int registerCount, int registerCount,
int inWords, int inWords,
int outWords, int outWords,

View File

@ -87,7 +87,7 @@ public class DebugInfoItem extends Item<DebugInfoItem> {
* debug info * debug info
* @return a new <code>DebugInfoItem</code> with the given values * @return a new <code>DebugInfoItem</code> with the given values
*/ */
public static DebugInfoItem getInternedDebugInfoItem(DexFile dexFile, public static DebugInfoItem internDebugInfoItem(DexFile dexFile,
int lineStart, int lineStart,
StringIdItem[] parameterNames, StringIdItem[] parameterNames,
byte[] encodedDebugInfo, byte[] encodedDebugInfo,

View File

@ -30,7 +30,7 @@ package org.jf.dexlib;
import org.jf.dexlib.Util.*; import org.jf.dexlib.Util.*;
import org.jf.dexlib.*; import org.jf.dexlib.*;
import org.jf.dexlib.Item; import org.jf.dexlib.Item;
import org.jf.dexlib.StringDataItem; import org.jf.dexlib.StringDataItem;
import java.io.*; import java.io.*;
@ -185,9 +185,6 @@ public class DexFile
private int dataSize; private int dataSize;
private int fileSize; private int fileSize;
private boolean disableInterning = false;
/** /**
* A private constructor containing common code to initialize the section maps and lists * A private constructor containing common code to initialize the section maps and lists
* @param preserveSignedRegisters If true, keep track of any registers in the debug information * @param preserveSignedRegisters If true, keep track of any registers in the debug information
@ -506,23 +503,6 @@ public class DexFile
this.sortAllItems = value; this.sortAllItems = value;
} }
/**
* Disables adding new items to this dex file. The various getInterned*() type
* methods on individual items will return null if there isn't an existing item
* that matches
*/
public void disableInterning() {
this.disableInterning = true;
}
/**
* @return a boolean value indicating whether interning new items has been disabled
* for this dex file
*/
public boolean getInterningDisabled() {
return disableInterning;
}
/** /**
* @return a boolean value indicating whether this dex file was created by reading in an odex file * @return a boolean value indicating whether this dex file was created by reading in an odex file
*/ */

View File

@ -62,7 +62,7 @@ public class EncodedArrayItem extends Item<EncodedArrayItem> {
* @param encodedArray The encoded array value * @param encodedArray The encoded array value
* @return an <code>EncodedArrayItem</code> for the given values, and that has been interned into the given * @return an <code>EncodedArrayItem</code> for the given values, and that has been interned into the given
*/ */
public static EncodedArrayItem getInternedEncodedArrayItem(DexFile dexFile, ArrayEncodedSubValue encodedArray) { public static EncodedArrayItem internEncodedArrayItem(DexFile dexFile, ArrayEncodedSubValue encodedArray) {
EncodedArrayItem encodedArrayItem = new EncodedArrayItem(dexFile, encodedArray); EncodedArrayItem encodedArrayItem = new EncodedArrayItem(dexFile, encodedArray);
return dexFile.EncodedArraysSection.intern(encodedArrayItem); return dexFile.EncodedArraysSection.intern(encodedArrayItem);
} }

View File

@ -75,12 +75,28 @@ public class FieldIdItem extends Item<FieldIdItem> {
* @return a <code>FieldIdItem</code> for the given values, and that has been interned into * @return a <code>FieldIdItem</code> for the given values, and that has been interned into
* the given <code>DexFile</code> * the given <code>DexFile</code>
*/ */
public static FieldIdItem getInternedFieldIdItem(DexFile dexFile, TypeIdItem classType, TypeIdItem fieldType, public static FieldIdItem internFieldIdItem(DexFile dexFile, TypeIdItem classType, TypeIdItem fieldType,
StringIdItem fieldName) { StringIdItem fieldName) {
FieldIdItem fieldIdItem = new FieldIdItem(dexFile, classType, fieldType, fieldName); FieldIdItem fieldIdItem = new FieldIdItem(dexFile, classType, fieldType, fieldName);
return dexFile.FieldIdsSection.intern(fieldIdItem); return dexFile.FieldIdsSection.intern(fieldIdItem);
} }
/**
* Looks up a <code>FieldIdItem</code> from the given <code>DexFile</code> for the given
* values
* @param dexFile The <code>DexFile</code> that this item belongs to
* @param classType the class that the field is a member of
* @param fieldType the type of the field
* @param fieldName the name of the field
* @return a <code>FieldIdItem</code> from the given <code>DexFile</code> for the given
* values, or null if it doesn't exist
*/
public static FieldIdItem lookupFieldIdItem(DexFile dexFile, TypeIdItem classType, TypeIdItem fieldType,
StringIdItem fieldName) {
FieldIdItem fieldIdItem = new FieldIdItem(dexFile, classType, fieldType, fieldName);
return dexFile.FieldIdsSection.getInternedItem(fieldIdItem);
}
/** {@inheritDoc} */ /** {@inheritDoc} */
protected void readItem(Input in, ReadContext readContext) { protected void readItem(Input in, ReadContext readContext) {
classType = dexFile.TypeIdsSection.getItemByIndex(in.readShort()); classType = dexFile.TypeIdsSection.getItemByIndex(in.readShort());

View File

@ -70,12 +70,28 @@ public class MethodIdItem extends Item<MethodIdItem> {
* @return a <code>MethodIdItem</code> for the given values, and that has been interned into * @return a <code>MethodIdItem</code> for the given values, and that has been interned into
* the given <code>DexFile</code> * the given <code>DexFile</code>
*/ */
public static MethodIdItem getInternedMethodIdItem(DexFile dexFile, TypeIdItem classType, public static MethodIdItem internMethodIdItem(DexFile dexFile, TypeIdItem classType,
ProtoIdItem methodPrototype, StringIdItem methodName) { ProtoIdItem methodPrototype, StringIdItem methodName) {
MethodIdItem methodIdItem = new MethodIdItem(dexFile, classType, methodPrototype, methodName); MethodIdItem methodIdItem = new MethodIdItem(dexFile, classType, methodPrototype, methodName);
return dexFile.MethodIdsSection.intern(methodIdItem); return dexFile.MethodIdsSection.intern(methodIdItem);
} }
/**
* Looks up a <code>MethodIdItem</code> from the given <code>DexFile</code> for the given
* values
* @param dexFile The <code>DexFile</code> that this item belongs to
* @param classType the class that the method is a member of
* @param methodPrototype the type of the method
* @param methodName the name of the method
* @return a <code>MethodIdItem</code> from the given <code>DexFile</code> for the given
* values, or null if it doesn't exist
*/
public static MethodIdItem lookupMethodIdItem(DexFile dexFile, TypeIdItem classType,
ProtoIdItem methodPrototype, StringIdItem methodName) {
MethodIdItem methodIdItem = new MethodIdItem(dexFile, classType, methodPrototype, methodName);
return dexFile.MethodIdsSection.getInternedItem(methodIdItem);
}
/** {@inheritDoc} */ /** {@inheritDoc} */
protected void readItem(Input in, ReadContext readContext) { protected void readItem(Input in, ReadContext readContext) {
classType = dexFile.TypeIdsSection.getItemByIndex(in.readShort()); classType = dexFile.TypeIdsSection.getItemByIndex(in.readShort());

View File

@ -59,7 +59,7 @@ public class ProtoIdItem extends Item<ProtoIdItem> {
if (parameters != null) { if (parameters != null) {
shortyString += parameters.getShortyString(); shortyString += parameters.getShortyString();
} }
this.shortyDescriptor = StringIdItem.getInternedStringIdItem(dexFile, shortyString); this.shortyDescriptor = StringIdItem.internStringIdItem(dexFile, shortyString);
this.returnType = returnType; this.returnType = returnType;
this.parameters = parameters; this.parameters = parameters;
} }
@ -73,11 +73,25 @@ public class ProtoIdItem extends Item<ProtoIdItem> {
* @return a <code>ProtoIdItem</code> for the given values, and that has been interned into * @return a <code>ProtoIdItem</code> for the given values, and that has been interned into
* the given <code>DexFile</code> * the given <code>DexFile</code>
*/ */
public static ProtoIdItem getInternedProtoIdItem(DexFile dexFile, TypeIdItem returnType, TypeListItem parameters) { public static ProtoIdItem internProtoIdItem(DexFile dexFile, TypeIdItem returnType, TypeListItem parameters) {
ProtoIdItem protoIdItem = new ProtoIdItem(dexFile, returnType, parameters); ProtoIdItem protoIdItem = new ProtoIdItem(dexFile, returnType, parameters);
return dexFile.ProtoIdsSection.intern(protoIdItem); return dexFile.ProtoIdsSection.intern(protoIdItem);
} }
/**
* Looks up the <code>ProtoIdItem</code> from the given <code>DexFile</code> for the given
* values
* @param dexFile the <code>Dexfile</code> to find the type in
* @param returnType the return type
* @param parameters a <code>TypeListItem</code> containing a list of the parameter types
* @return a <code>ProtoIdItem</code> from the given <code>DexFile</code> for the given
* values, or null if it doesn't exist
*/
public static ProtoIdItem lookupProtoIdItem(DexFile dexFile, TypeIdItem returnType, TypeListItem parameters) {
ProtoIdItem protoIdItem = new ProtoIdItem(dexFile, returnType, parameters);
return dexFile.ProtoIdsSection.getInternedItem(protoIdItem);
}
/** {@inheritDoc} */ /** {@inheritDoc} */
protected void readItem(Input in, ReadContext readContext) { protected void readItem(Input in, ReadContext readContext) {
shortyDescriptor = dexFile.StringIdsSection.getItemByIndex(in.readInt()); shortyDescriptor = dexFile.StringIdsSection.getItemByIndex(in.readInt());

View File

@ -178,7 +178,7 @@ public abstract class Section<T extends Item> {
return null; return null;
} }
T internedItem = getInternedItem(item); T internedItem = getInternedItem(item);
if (internedItem == null && !item.dexFile.getInterningDisabled()) { if (internedItem == null) {
uniqueItems.put(item, item); uniqueItems.put(item, item);
items.add(item); items.add(item);
return item; return item;

View File

@ -62,11 +62,24 @@ public class StringDataItem extends Item<StringDataItem> {
* @return a <code>StringDataItem</code> for the given values, and that has been interned into * @return a <code>StringDataItem</code> for the given values, and that has been interned into
* the given <code>DexFile</code> * the given <code>DexFile</code>
*/ */
public static StringDataItem getInternedStringDataItem(DexFile dexFile, String value) { public static StringDataItem internStringDataItem(DexFile dexFile, String value) {
StringDataItem StringDataItem = new StringDataItem(dexFile, value); StringDataItem StringDataItem = new StringDataItem(dexFile, value);
return dexFile.StringDataSection.intern(StringDataItem); return dexFile.StringDataSection.intern(StringDataItem);
} }
/**
* Looks up the <code>StringDataItem</code> from the given <code>DexFile</code> for the given
* string value
* @param dexFile the <code>Dexfile</code> to find the string value in
* @param value The string value to look up
* @return a <code>StringDataItem</code> from the given <code>DexFile</code> for the given
* string value, or null if it doesn't exist
**/
public static StringDataItem lookupStringDataItem(DexFile dexFile, String value) {
StringDataItem StringDataItem = new StringDataItem(dexFile, value);
return dexFile.StringDataSection.getInternedItem(StringDataItem);
}
/** {@inheritDoc} */ /** {@inheritDoc} */
protected void readItem(Input in, ReadContext readContext) { protected void readItem(Input in, ReadContext readContext) {
in.readUnsignedLeb128(); //string length in.readUnsignedLeb128(); //string length

View File

@ -61,8 +61,8 @@ public class StringIdItem extends Item<StringIdItem> {
* @return a <code>StringIdItem</code> for the given values, and that has been interned into * @return a <code>StringIdItem</code> for the given values, and that has been interned into
* the given <code>DexFile</code> * the given <code>DexFile</code>
*/ */
public static StringIdItem getInternedStringIdItem(DexFile dexFile, String stringValue) { public static StringIdItem internStringIdItem(DexFile dexFile, String stringValue) {
StringDataItem stringDataItem = StringDataItem.getInternedStringDataItem(dexFile, stringValue); StringDataItem stringDataItem = StringDataItem.internStringDataItem(dexFile, stringValue);
if (stringDataItem == null) { if (stringDataItem == null) {
return null; return null;
} }
@ -70,6 +70,23 @@ public class StringIdItem extends Item<StringIdItem> {
return dexFile.StringIdsSection.intern(stringIdItem); return dexFile.StringIdsSection.intern(stringIdItem);
} }
/**
* Looks up the <code>StringIdItem</code> from the given <code>DexFile</code> for the given
* string value
* @param dexFile the <code>Dexfile</code> to find the string value in
* @param stringValue The string value to look up
* @return a <code>StringIdItem</code> from the given <code>DexFile</code> for the given
* string value, or null if it doesn't exist
*/
public static StringIdItem lookupStringIdItem(DexFile dexFile, String stringValue) {
StringDataItem stringDataItem = StringDataItem.lookupStringDataItem(dexFile, stringValue);
if (stringDataItem == null) {
return null;
}
StringIdItem stringIdItem = new StringIdItem(dexFile, stringDataItem);
return dexFile.StringIdsSection.getInternedItem(stringIdItem);
}
/** {@inheritDoc} */ /** {@inheritDoc} */
protected void readItem(Input in, ReadContext readContext) { protected void readItem(Input in, ReadContext readContext) {
int stringDataOffset = in.readInt(); int stringDataOffset = in.readInt();

View File

@ -62,7 +62,7 @@ public class TypeIdItem extends Item<TypeIdItem> {
* @return a <code>TypeIdItem</code> for the given values, and that has been interned into * @return a <code>TypeIdItem</code> for the given values, and that has been interned into
* the given <code>DexFile</code> * the given <code>DexFile</code>
*/ */
public static TypeIdItem getInternedTypeIdItem(DexFile dexFile, StringIdItem typeDescriptor) { public static TypeIdItem internTypeIdItem(DexFile dexFile, StringIdItem typeDescriptor) {
TypeIdItem typeIdItem = new TypeIdItem(dexFile, typeDescriptor); TypeIdItem typeIdItem = new TypeIdItem(dexFile, typeDescriptor);
return dexFile.TypeIdsSection.intern(typeIdItem); return dexFile.TypeIdsSection.intern(typeIdItem);
} }
@ -76,8 +76,8 @@ public class TypeIdItem extends Item<TypeIdItem> {
* @return a <code>TypeIdItem</code> for the given values, and that has been interned into * @return a <code>TypeIdItem</code> for the given values, and that has been interned into
* the given <code>DexFile</code> * the given <code>DexFile</code>
*/ */
public static TypeIdItem getInternedTypeIdItem(DexFile dexFile, String typeDescriptor) { public static TypeIdItem internTypeIdItem(DexFile dexFile, String typeDescriptor) {
StringIdItem stringIdItem = StringIdItem.getInternedStringIdItem(dexFile, typeDescriptor); StringIdItem stringIdItem = StringIdItem.internStringIdItem(dexFile, typeDescriptor);
if (stringIdItem == null) { if (stringIdItem == null) {
return null; return null;
} }
@ -85,6 +85,23 @@ public class TypeIdItem extends Item<TypeIdItem> {
return dexFile.TypeIdsSection.intern(typeIdItem); return dexFile.TypeIdsSection.intern(typeIdItem);
} }
/**
* Looks up the <code>TypeIdItem</code> from the given <code>DexFile</code> for the given
* type descriptor
* @param dexFile the <code>Dexfile</code> to find the type in
* @param typeDescriptor The string containing the type descriptor to look up
* @return a <code>TypeIdItem</code> from the given <code>DexFile</code> for the given
* type descriptor, or null if it doesn't exist
*/
public static TypeIdItem lookupTypeIdItem(DexFile dexFile, String typeDescriptor) {
StringIdItem stringIdItem = StringIdItem.lookupStringIdItem(dexFile, typeDescriptor);
if (stringIdItem == null) {
return null;
}
TypeIdItem typeIdItem = new TypeIdItem(dexFile, stringIdItem);
return dexFile.TypeIdsSection.getInternedItem(typeIdItem);
}
/** {@inheritDoc} */ /** {@inheritDoc} */
protected void readItem(Input in, ReadContext readContext) { protected void readItem(Input in, ReadContext readContext) {
int stringIdIndex = in.readInt(); int stringIdIndex = in.readInt();

View File

@ -66,13 +66,28 @@ public class TypeListItem extends Item<TypeListItem> {
* @return a <code>TypeListItem</code> for the given values, and that has been interned into * @return a <code>TypeListItem</code> for the given values, and that has been interned into
* the given <code>DexFile</code> * the given <code>DexFile</code>
*/ */
public static TypeListItem getInternedTypeListItem(DexFile dexFile, List<TypeIdItem> typeList) { public static TypeListItem internTypeListItem(DexFile dexFile, List<TypeIdItem> typeList) {
TypeIdItem[] typeArray = new TypeIdItem[typeList.size()]; TypeIdItem[] typeArray = new TypeIdItem[typeList.size()];
typeList.toArray(typeArray); typeList.toArray(typeArray);
TypeListItem typeListItem = new TypeListItem(dexFile, typeArray); TypeListItem typeListItem = new TypeListItem(dexFile, typeArray);
return dexFile.TypeListsSection.intern(typeListItem); return dexFile.TypeListsSection.intern(typeListItem);
} }
/**
* Looks up the <code>TypeListItem</code> from the given <code>DexFile</code> for the given
* list of types
* @param dexFile the <code>Dexfile</code> to find the type in
* @param typeList A list of the types that the <code>TypeListItem</code> represents
* @return a <code>TypeListItem</code> from the given <code>DexFile</code> for the given
* list of types, or null if it doesn't exist
*/
public static TypeListItem lookupTypeListItem(DexFile dexFile, List<TypeIdItem> typeList) {
TypeIdItem[] typeArray = new TypeIdItem[typeList.size()];
typeList.toArray(typeArray);
TypeListItem typeListItem = new TypeListItem(dexFile, typeArray);
return dexFile.TypeListsSection.getInternedItem(typeListItem);
}
/** {@inheritDoc} */ /** {@inheritDoc} */
protected void readItem(Input in, ReadContext readContext) { protected void readItem(Input in, ReadContext readContext) {
int size = in.readInt(); int size = in.readInt();

View File

@ -170,13 +170,13 @@ public class DebugInfoBuilder
if (parameterName == null) { if (parameterName == null) {
parameterNamesArray[index++] = null; parameterNamesArray[index++] = null;
} else { } else {
parameterNamesArray[index++] = StringIdItem.getInternedStringIdItem(dexFile, parameterName); parameterNamesArray[index++] = StringIdItem.internStringIdItem(dexFile, parameterName);
} }
} }
Item[] referencedItemsArray = new Item[referencedItems.size()]; Item[] referencedItemsArray = new Item[referencedItems.size()];
referencedItems.toArray(referencedItemsArray); referencedItems.toArray(referencedItemsArray);
return DebugInfoItem.getInternedDebugInfoItem(dexFile, lineStart, parameterNamesArray, out.toByteArray(), return DebugInfoItem.internDebugInfoItem(dexFile, lineStart, parameterNamesArray, out.toByteArray(),
referencedItemsArray); referencedItemsArray);
} }
@ -307,9 +307,9 @@ public class DebugInfoBuilder
public void emit(DexFile dexFile, Output out, List<Item> referencedItems) { public void emit(DexFile dexFile, Output out, List<Item> referencedItems) {
emitAdvancePC(out, address); emitAdvancePC(out, address);
emitStartLocal(out, registerNum); emitStartLocal(out, registerNum);
referencedItems.add(localName==null?null:StringIdItem.getInternedStringIdItem(dexFile, localName)); referencedItems.add(localName==null?null:StringIdItem.internStringIdItem(dexFile, localName));
referencedItems.add(localType==null?null:TypeIdItem.getInternedTypeIdItem(dexFile, referencedItems.add(localType==null?null:TypeIdItem.internTypeIdItem(dexFile,
StringIdItem.getInternedStringIdItem(dexFile, localType))); StringIdItem.internStringIdItem(dexFile, localType)));
} }
} }
@ -338,14 +338,14 @@ public class DebugInfoBuilder
emitAdvancePC(out, address); emitAdvancePC(out, address);
emitStartLocalExtended(out, registerNum); emitStartLocalExtended(out, registerNum);
if (localName != null) { if (localName != null) {
referencedItems.add(StringIdItem.getInternedStringIdItem(dexFile, localName)); referencedItems.add(StringIdItem.internStringIdItem(dexFile, localName));
} }
if (localType != null) { if (localType != null) {
referencedItems.add(TypeIdItem.getInternedTypeIdItem(dexFile, referencedItems.add(TypeIdItem.internTypeIdItem(dexFile,
StringIdItem.getInternedStringIdItem(dexFile, localType))); StringIdItem.internStringIdItem(dexFile, localType)));
} }
if (signature != null) { if (signature != null) {
referencedItems.add(StringIdItem.getInternedStringIdItem(dexFile, signature)); referencedItems.add(StringIdItem.internStringIdItem(dexFile, signature));
} }
} }
} }
@ -444,7 +444,7 @@ public class DebugInfoBuilder
emitAdvancePC(out, address); emitAdvancePC(out, address);
emitSetFile(out); emitSetFile(out);
if (fileName != null) { if (fileName != null) {
referencedItems.add(StringIdItem.getInternedStringIdItem(dexFile, fileName)); referencedItems.add(StringIdItem.internStringIdItem(dexFile, fileName));
} }
} }
} }

View File

@ -158,7 +158,7 @@ smali_file
$methods.parameterAnnotations != null || $methods.parameterAnnotations != null ||
$fields.fieldAnnotations != null || $fields.fieldAnnotations != null ||
$annotations.annotationSetItem != null) { $annotations.annotationSetItem != null) {
annotationDirectoryItem = AnnotationDirectoryItem.getInternedAnnotationDirectoryItem( annotationDirectoryItem = AnnotationDirectoryItem.internAnnotationDirectoryItem(
dexFile, dexFile,
$annotations.annotationSetItem, $annotations.annotationSetItem,
$fields.fieldAnnotations, $fields.fieldAnnotations,
@ -168,11 +168,11 @@ smali_file
if ($fields.staticFields.size() != 0 || $fields.instanceFields.size() != 0 || if ($fields.staticFields.size() != 0 || $fields.instanceFields.size() != 0 ||
$methods.directMethods.size() != 0 || $methods.virtualMethods.size()!= 0) { $methods.directMethods.size() != 0 || $methods.virtualMethods.size()!= 0) {
classDataItem = ClassDataItem.getInternedClassDataItem(dexFile, $fields.staticFields, $fields.instanceFields, classDataItem = ClassDataItem.internClassDataItem(dexFile, $fields.staticFields, $fields.instanceFields,
$methods.directMethods, $methods.virtualMethods); $methods.directMethods, $methods.virtualMethods);
} }
classDefItem = ClassDefItem.getInternedClassDefItem(dexFile, $header.classType, $header.accessFlags, classDefItem = ClassDefItem.internClassDefItem(dexFile, $header.classType, $header.accessFlags,
$header.superType, $header.implementsList, $header.sourceSpec, annotationDirectoryItem, $header.superType, $header.implementsList, $header.sourceSpec, annotationDirectoryItem,
classDataItem, $fields.staticFieldInitialValues); classDataItem, $fields.staticFieldInitialValues);
}; };
@ -220,7 +220,7 @@ implements_list returns[TypeListItem implementsList]
(implements_spec {typeList.add($implements_spec.type);} )* (implements_spec {typeList.add($implements_spec.type);} )*
{ {
if (typeList.size() > 0) { if (typeList.size() > 0) {
$implementsList = TypeListItem.getInternedTypeListItem(dexFile, typeList); $implementsList = TypeListItem.internTypeListItem(dexFile, typeList);
} else { } else {
$implementsList = null; $implementsList = null;
} }
@ -228,7 +228,7 @@ implements_list returns[TypeListItem implementsList]
source_spec returns[StringIdItem source] source_spec returns[StringIdItem source]
: {$source = null;} : {$source = null;}
^(I_SOURCE string_literal {$source = StringIdItem.getInternedStringIdItem(dexFile, $string_literal.value);}) ^(I_SOURCE string_literal {$source = StringIdItem.internStringIdItem(dexFile, $string_literal.value);})
| ; | ;
@ -314,10 +314,10 @@ methods returns[List<ClassDataItem.EncodedMethod> directMethods,
field returns [ClassDataItem.EncodedField encodedField, EncodedValue encodedValue, AnnotationSetItem fieldAnnotationSet] field returns [ClassDataItem.EncodedField encodedField, EncodedValue encodedValue, AnnotationSetItem fieldAnnotationSet]
:^(I_FIELD MEMBER_NAME access_list ^(I_FIELD_TYPE nonvoid_type_descriptor) field_initial_value annotations?) :^(I_FIELD MEMBER_NAME access_list ^(I_FIELD_TYPE nonvoid_type_descriptor) field_initial_value annotations?)
{ {
StringIdItem memberName = StringIdItem.getInternedStringIdItem(dexFile, $MEMBER_NAME.text); StringIdItem memberName = StringIdItem.internStringIdItem(dexFile, $MEMBER_NAME.text);
TypeIdItem fieldType = $nonvoid_type_descriptor.type; TypeIdItem fieldType = $nonvoid_type_descriptor.type;
FieldIdItem fieldIdItem = FieldIdItem.getInternedFieldIdItem(dexFile, classType, fieldType, memberName); FieldIdItem fieldIdItem = FieldIdItem.internFieldIdItem(dexFile, classType, fieldType, memberName);
$encodedField = new ClassDataItem.EncodedField(fieldIdItem, $access_list.value); $encodedField = new ClassDataItem.EncodedField(fieldIdItem, $access_list.value);
if ($field_initial_value.encodedValue != null) { if ($field_initial_value.encodedValue != null) {
@ -348,7 +348,7 @@ literal returns[EncodedValue encodedValue]
| float_literal { $encodedValue = new FloatEncodedValue($float_literal.value); } | float_literal { $encodedValue = new FloatEncodedValue($float_literal.value); }
| double_literal { $encodedValue = new DoubleEncodedValue($double_literal.value); } | double_literal { $encodedValue = new DoubleEncodedValue($double_literal.value); }
| char_literal { $encodedValue = new CharEncodedValue($char_literal.value); } | char_literal { $encodedValue = new CharEncodedValue($char_literal.value); }
| string_literal { $encodedValue = new StringEncodedValue(StringIdItem.getInternedStringIdItem(dexFile, $string_literal.value)); } | string_literal { $encodedValue = new StringEncodedValue(StringIdItem.internStringIdItem(dexFile, $string_literal.value)); }
| bool_literal { $encodedValue = $bool_literal.value?BooleanEncodedValue.TrueValue:BooleanEncodedValue.FalseValue; } | bool_literal { $encodedValue = $bool_literal.value?BooleanEncodedValue.TrueValue:BooleanEncodedValue.FalseValue; }
| NULL_LITERAL { $encodedValue = NullEncodedValue.NullValue; } | NULL_LITERAL { $encodedValue = NullEncodedValue.NullValue; }
| type_descriptor { $encodedValue = new TypeEncodedValue($type_descriptor.type); } | type_descriptor { $encodedValue = new TypeEncodedValue($type_descriptor.type); }
@ -537,7 +537,7 @@ method returns[ ClassDataItem.EncodedMethod encodedMethod,
" parameters."); " parameters.");
} }
codeItem = CodeItem.getInternedCodeItem(dexFile, codeItem = CodeItem.internCodeItem(dexFile,
totalMethodRegisters, totalMethodRegisters,
methodParameterRegisters, methodParameterRegisters,
$statements.maxOutRegisters, $statements.maxOutRegisters,
@ -565,20 +565,20 @@ method_prototype returns[ProtoIdItem protoIdItem]
List<TypeIdItem> parameterTypes = $field_type_list.types; List<TypeIdItem> parameterTypes = $field_type_list.types;
TypeListItem parameterTypeListItem = null; TypeListItem parameterTypeListItem = null;
if (parameterTypes != null && parameterTypes.size() > 0) { if (parameterTypes != null && parameterTypes.size() > 0) {
parameterTypeListItem = TypeListItem.getInternedTypeListItem(dexFile, parameterTypes); parameterTypeListItem = TypeListItem.internTypeListItem(dexFile, parameterTypes);
} }
$protoIdItem = ProtoIdItem.getInternedProtoIdItem(dexFile, returnType, parameterTypeListItem); $protoIdItem = ProtoIdItem.internProtoIdItem(dexFile, returnType, parameterTypeListItem);
}; };
method_name_and_prototype returns[MethodIdItem methodIdItem] method_name_and_prototype returns[MethodIdItem methodIdItem]
: MEMBER_NAME method_prototype : MEMBER_NAME method_prototype
{ {
String methodNameString = $MEMBER_NAME.text; String methodNameString = $MEMBER_NAME.text;
StringIdItem methodName = StringIdItem.getInternedStringIdItem(dexFile, methodNameString); StringIdItem methodName = StringIdItem.internStringIdItem(dexFile, methodNameString);
ProtoIdItem protoIdItem = $method_prototype.protoIdItem; ProtoIdItem protoIdItem = $method_prototype.protoIdItem;
$methodIdItem = MethodIdItem.getInternedMethodIdItem(dexFile, classType, protoIdItem, methodName); $methodIdItem = MethodIdItem.internMethodIdItem(dexFile, classType, protoIdItem, methodName);
}; };
field_type_list returns[List<TypeIdItem> types] field_type_list returns[List<TypeIdItem> types]
@ -598,18 +598,18 @@ fully_qualified_method returns[MethodIdItem methodIdItem]
: reference_type_descriptor MEMBER_NAME method_prototype : reference_type_descriptor MEMBER_NAME method_prototype
{ {
TypeIdItem classType = $reference_type_descriptor.type; TypeIdItem classType = $reference_type_descriptor.type;
StringIdItem methodName = StringIdItem.getInternedStringIdItem(dexFile, $MEMBER_NAME.text); StringIdItem methodName = StringIdItem.internStringIdItem(dexFile, $MEMBER_NAME.text);
ProtoIdItem prototype = $method_prototype.protoIdItem; ProtoIdItem prototype = $method_prototype.protoIdItem;
$methodIdItem = MethodIdItem.getInternedMethodIdItem(dexFile, classType, prototype, methodName); $methodIdItem = MethodIdItem.internMethodIdItem(dexFile, classType, prototype, methodName);
}; };
fully_qualified_field returns[FieldIdItem fieldIdItem] fully_qualified_field returns[FieldIdItem fieldIdItem]
: reference_type_descriptor MEMBER_NAME nonvoid_type_descriptor : reference_type_descriptor MEMBER_NAME nonvoid_type_descriptor
{ {
TypeIdItem classType = $reference_type_descriptor.type; TypeIdItem classType = $reference_type_descriptor.type;
StringIdItem fieldName = StringIdItem.getInternedStringIdItem(dexFile, $MEMBER_NAME.text); StringIdItem fieldName = StringIdItem.internStringIdItem(dexFile, $MEMBER_NAME.text);
TypeIdItem fieldType = $nonvoid_type_descriptor.type; TypeIdItem fieldType = $nonvoid_type_descriptor.type;
$fieldIdItem = FieldIdItem.getInternedFieldIdItem(dexFile, classType, fieldType, fieldName); $fieldIdItem = FieldIdItem.internFieldIdItem(dexFile, classType, fieldType, fieldName);
}; };
registers_directive returns[boolean isLocalsDirective, int registers] registers_directive returns[boolean isLocalsDirective, int registers]
@ -706,7 +706,7 @@ parameters returns[AnnotationSetRefList parameterAnnotations]
{ {
if ($parameter.parameterAnnotationSet != null) { if ($parameter.parameterAnnotationSet != null) {
while (annotationSetItems.size() < parameterCount) { while (annotationSetItems.size() < parameterCount) {
annotationSetItems.add(AnnotationSetItem.getInternedAnnotationSetItem(dexFile, null)); annotationSetItems.add(AnnotationSetItem.internAnnotationSetItem(dexFile, null));
} }
annotationSetItems.add($parameter.parameterAnnotationSet); annotationSetItems.add($parameter.parameterAnnotationSet);
} }
@ -717,9 +717,9 @@ parameters returns[AnnotationSetRefList parameterAnnotations]
{ {
if (annotationSetItems.size() > 0) { if (annotationSetItems.size() > 0) {
while (annotationSetItems.size() < parameterCount) { while (annotationSetItems.size() < parameterCount) {
annotationSetItems.add(AnnotationSetItem.getInternedAnnotationSetItem(dexFile, null)); annotationSetItems.add(AnnotationSetItem.internAnnotationSetItem(dexFile, null));
} }
$parameterAnnotations = AnnotationSetRefList.getInternedAnnotationSetRefList(dexFile, annotationSetItems); $parameterAnnotations = AnnotationSetRefList.internAnnotationSetRefList(dexFile, annotationSetItems);
} }
}; };
@ -941,7 +941,7 @@ instruction[int totalMethodRegisters, int methodParameterRegisters, List<Instruc
Opcode opcode = Opcode.getOpcodeByName($INSTRUCTION_FORMAT21c_STRING.text); Opcode opcode = Opcode.getOpcodeByName($INSTRUCTION_FORMAT21c_STRING.text);
short regA = parseRegister_byte($REGISTER.text, $totalMethodRegisters, $methodParameterRegisters); short regA = parseRegister_byte($REGISTER.text, $totalMethodRegisters, $methodParameterRegisters);
StringIdItem stringIdItem = StringIdItem.getInternedStringIdItem(dexFile, $string_literal.value); StringIdItem stringIdItem = StringIdItem.internStringIdItem(dexFile, $string_literal.value);
instructions.add(new Instruction21c(opcode, regA, stringIdItem)); instructions.add(new Instruction21c(opcode, regA, stringIdItem));
} }
@ -1083,7 +1083,7 @@ instruction[int totalMethodRegisters, int methodParameterRegisters, List<Instruc
Opcode opcode = Opcode.getOpcodeByName($INSTRUCTION_FORMAT31c.text); Opcode opcode = Opcode.getOpcodeByName($INSTRUCTION_FORMAT31c.text);
short regA = parseRegister_byte($REGISTER.text, $totalMethodRegisters, $methodParameterRegisters); short regA = parseRegister_byte($REGISTER.text, $totalMethodRegisters, $methodParameterRegisters);
StringIdItem stringIdItem = StringIdItem.getInternedStringIdItem(dexFile, $string_literal.value); StringIdItem stringIdItem = StringIdItem.internStringIdItem(dexFile, $string_literal.value);
$instructions.add(new Instruction31c(opcode, regA, stringIdItem)); $instructions.add(new Instruction31c(opcode, regA, stringIdItem));
} }
@ -1276,7 +1276,7 @@ nonvoid_type_descriptor returns [TypeIdItem type]
| CLASS_DESCRIPTOR | CLASS_DESCRIPTOR
| ARRAY_DESCRIPTOR) | ARRAY_DESCRIPTOR)
{ {
$type = TypeIdItem.getInternedTypeIdItem(dexFile, $start.getText()); $type = TypeIdItem.internTypeIdItem(dexFile, $start.getText());
}; };
@ -1284,7 +1284,7 @@ reference_type_descriptor returns [TypeIdItem type]
: (CLASS_DESCRIPTOR : (CLASS_DESCRIPTOR
| ARRAY_DESCRIPTOR) | ARRAY_DESCRIPTOR)
{ {
$type = TypeIdItem.getInternedTypeIdItem(dexFile, $start.getText()); $type = TypeIdItem.internTypeIdItem(dexFile, $start.getText());
}; };
@ -1295,11 +1295,11 @@ reference_type_descriptor returns [TypeIdItem type]
class_type_descriptor returns [TypeIdItem type] class_type_descriptor returns [TypeIdItem type]
: CLASS_DESCRIPTOR : CLASS_DESCRIPTOR
{ {
$type = TypeIdItem.getInternedTypeIdItem(dexFile, $CLASS_DESCRIPTOR.text); $type = TypeIdItem.internTypeIdItem(dexFile, $CLASS_DESCRIPTOR.text);
}; };
type_descriptor returns [TypeIdItem type] type_descriptor returns [TypeIdItem type]
: VOID_TYPE {$type = TypeIdItem.getInternedTypeIdItem(dexFile, "V");} : VOID_TYPE {$type = TypeIdItem.internTypeIdItem(dexFile, "V");}
| nonvoid_type_descriptor {$type = $nonvoid_type_descriptor.type;} | nonvoid_type_descriptor {$type = $nonvoid_type_descriptor.type;}
; ;
@ -1374,7 +1374,7 @@ annotations returns[AnnotationSetItem annotationSetItem]
^(I_ANNOTATIONS (annotation {annotationList.add($annotation.annotationItem);} )*) ^(I_ANNOTATIONS (annotation {annotationList.add($annotation.annotationItem);} )*)
{ {
if (annotationList.size() > 0) { if (annotationList.size() > 0) {
$annotationSetItem = AnnotationSetItem.getInternedAnnotationSetItem(dexFile, annotationList); $annotationSetItem = AnnotationSetItem.internAnnotationSetItem(dexFile, annotationList);
} }
}; };
@ -1385,13 +1385,13 @@ annotation returns[AnnotationItem annotationItem]
AnnotationVisibility visibility = AnnotationVisibility.valueOf($ANNOTATION_VISIBILITY.text.toUpperCase()); AnnotationVisibility visibility = AnnotationVisibility.valueOf($ANNOTATION_VISIBILITY.text.toUpperCase());
AnnotationEncodedSubValue encodedAnnotation = new AnnotationEncodedSubValue($subannotation.annotationType, AnnotationEncodedSubValue encodedAnnotation = new AnnotationEncodedSubValue($subannotation.annotationType,
$subannotation.elementNames, $subannotation.elementValues); $subannotation.elementNames, $subannotation.elementValues);
$annotationItem = AnnotationItem.getInternedAnnotationItem(dexFile, visibility, encodedAnnotation); $annotationItem = AnnotationItem.internAnnotationItem(dexFile, visibility, encodedAnnotation);
}; };
annotation_element returns[StringIdItem elementName, EncodedValue elementValue] annotation_element returns[StringIdItem elementName, EncodedValue elementValue]
: ^(I_ANNOTATION_ELEMENT MEMBER_NAME literal) : ^(I_ANNOTATION_ELEMENT MEMBER_NAME literal)
{ {
$elementName = StringIdItem.getInternedStringIdItem(dexFile, $MEMBER_NAME.text); $elementName = StringIdItem.internStringIdItem(dexFile, $MEMBER_NAME.text);
$elementValue = $literal.encodedValue; $elementValue = $literal.encodedValue;
}; };