org.jf.dexlib2.iface.reference.FieldReference Java Examples

The following examples show how to use org.jf.dexlib2.iface.reference.FieldReference. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClassProto.java    From zjdroid with Apache License 2.0 6 votes vote down vote up
private int getNextFieldOffset() {
    SparseArray<FieldReference> instanceFields = getInstanceFields();
    if (instanceFields.size() == 0) {
        return 8;
    }

    int lastItemIndex = instanceFields.size()-1;
    int fieldOffset = instanceFields.keyAt(lastItemIndex);
    FieldReference lastField = instanceFields.valueAt(lastItemIndex);

    switch (lastField.getType().charAt(0)) {
        case 'J':
        case 'D':
            return fieldOffset + 8;
        default:
            return fieldOffset + 4;
    }
}
 
Example #2
Source File: ReferenceFormatter.java    From atlas with Apache License 2.0 6 votes vote down vote up
public static void writeReference(IndentingWriter writer, int referenceType,
                                  Reference reference) throws IOException {
    switch (referenceType) {
        case ReferenceType.STRING:
            writeStringReference(writer, ((StringReference)reference).getString());
            return;
        case ReferenceType.TYPE:
            writer.write(((TypeReference)reference).getType());
            return;
        case ReferenceType.METHOD:
            ReferenceUtil.writeMethodDescriptor(writer, (MethodReference) reference);
            return;
        case ReferenceType.FIELD:
            ReferenceUtil.writeFieldDescriptor(writer, (FieldReference)reference);
            return;
        default:
            throw new IllegalStateException("Unknown reference type");
    }
}
 
Example #3
Source File: SgetInstruction.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public void jimplify (DexBody body) {
      int dest = ((OneRegisterInstruction)instruction).getRegisterA();
      FieldReference f = (FieldReference)((ReferenceInstruction)instruction).getReference();
      StaticFieldRef r = Jimple.v().newStaticFieldRef(getStaticSootFieldRef(f));
      assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), r);
      setUnit(assign);
      addTags(assign);
      body.add(assign);
      
if (IDalvikTyper.ENABLE_DVKTYPER) {
	Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ assign);
        int op = (int)instruction.getOpcode().value;
        DalvikTyper.v().setType(assign.getLeftOpBox(), r.getType(), false);
      }
  }
 
Example #4
Source File: FieldPool.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public void intern(@Nonnull FieldReference field) {
    Integer prev = internedItems.put(field, 0);
    if (prev == null) {
        typePool.intern(field.getDefiningClass());
        stringPool.intern(field.getName());
        typePool.intern(field.getType());
    }
}
 
Example #5
Source File: FieldPool.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public void intern(@Nonnull FieldReference field) {
    Integer prev = internedItems.put(field, 0);
    if (prev == null) {
        typePool.intern(field.getDefiningClass());
        stringPool.intern(field.getName());
        typePool.intern(field.getType());
    }
}
 
Example #6
Source File: BaseFieldReference.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(@Nonnull FieldReference o) {
    int res = getDefiningClass().compareTo(o.getDefiningClass());
    if (res != 0) return res;
    res = getName().compareTo(o.getName());
    if (res != 0) return res;
    return getType().compareTo(o.getType());
}
 
Example #7
Source File: FieldInstruction.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Set<Type> introducedTypes() {
    Set<Type> types = new HashSet<Type>();
    // Aput instructions don't have references
    if (!(instruction instanceof ReferenceInstruction))
        return types;

    ReferenceInstruction i = (ReferenceInstruction) instruction;

    FieldReference field = (FieldReference) i.getReference();

    types.add(DexType.toSoot(field.getType()));
    types.add(DexType.toSoot(field.getDefiningClass()));
    return types;
}
 
Example #8
Source File: BuilderFieldPool.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Nonnull public BuilderFieldReference internField(@Nonnull FieldReference fieldReference) {
    BuilderFieldReference ret = internedItems.get(fieldReference);
    if (ret != null) {
        return ret;
    }

    BuilderFieldReference dexPoolFieldReference = new BuilderFieldReference(
            context.typePool.internType(fieldReference.getDefiningClass()),
            context.stringPool.internString(fieldReference.getName()),
            context.typePool.internType(fieldReference.getType()));
    ret = internedItems.putIfAbsent(dexPoolFieldReference, dexPoolFieldReference);
    return ret==null?dexPoolFieldReference:ret;
}
 
Example #9
Source File: ClassProto.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public FieldReference getFieldByOffset(int fieldOffset) {
    if (getInstanceFields().size() == 0) {
        return null;
    }
    return getInstanceFields().get(fieldOffset);
}
 
Example #10
Source File: InstructionRewriter.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Override @Nonnull public Reference getReference() {
    switch (getReferenceType()) {
        case ReferenceType.TYPE:
            return RewriterUtils.rewriteTypeReference(rewriters.getTypeRewriter(),
                    (TypeReference)instruction.getReference());
        case ReferenceType.FIELD:
            return rewriters.getFieldReferenceRewriter().rewrite((FieldReference)instruction.getReference());
        case ReferenceType.METHOD:
            return rewriters.getMethodReferenceRewriter().rewrite((MethodReference)instruction.getReference());
        case ReferenceType.STRING:
            return instruction.getReference();
        default:
            throw new IllegalArgumentException();
    }
}
 
Example #11
Source File: MethodAnalyzer.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
private void analyzeIgetSgetWideObject(@Nonnull AnalyzedInstruction analyzedInstruction) {
    ReferenceInstruction referenceInstruction = (ReferenceInstruction)analyzedInstruction.instruction;

    FieldReference fieldReference = (FieldReference)referenceInstruction.getReference();

    RegisterType fieldType = RegisterType.getRegisterType(classPath, fieldReference.getType());
    setDestinationRegisterTypeAndPropagateChanges(analyzedInstruction, fieldType);
}
 
Example #12
Source File: ArrayProto.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public FieldReference getFieldByOffset(int fieldOffset) {
    if (fieldOffset==8) {
        return new ImmutableFieldReference(getType(), "length", "int");
    }
    return null;
}
 
Example #13
Source File: InstructionWriter.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
@Nonnull static <StringRef extends StringReference, TypeRef extends TypeReference, FieldRefKey extends FieldReference, MethodRefKey extends MethodReference>
        InstructionWriter<StringRef, TypeRef, FieldRefKey, MethodRefKey>
        makeInstructionWriter(
            @Nonnull DexDataWriter writer,
            @Nonnull StringSection<?, StringRef> stringSection,
            @Nonnull TypeSection<?, ?, TypeRef> typeSection,
            @Nonnull FieldSection<?, ?, FieldRefKey, ?> fieldSection,
            @Nonnull MethodSection<?, ?, ?, MethodRefKey, ?> methodSection) {
    return new InstructionWriter<StringRef, TypeRef, FieldRefKey, MethodRefKey>(
            writer, stringSection, typeSection, fieldSection, methodSection);
}
 
Example #14
Source File: MethodAnalyzer.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
private void analyzeIgetSgetWideObject(@Nonnull AnalyzedInstruction analyzedInstruction) {
    ReferenceInstruction referenceInstruction = (ReferenceInstruction)analyzedInstruction.instruction;

    FieldReference fieldReference = (FieldReference)referenceInstruction.getReference();

    RegisterType fieldType = RegisterType.getRegisterType(classPath, fieldReference.getType());
    setDestinationRegisterTypeAndPropagateChanges(analyzedInstruction, fieldType);
}
 
Example #15
Source File: BaseFieldReference.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(@Nullable Object o) {
    if (o instanceof FieldReference) {
        FieldReference other = (FieldReference)o;
        return getDefiningClass().equals(other.getDefiningClass()) &&
               getName().equals(other.getName()) &&
               getType().equals(other.getType());

    }
    return false;
}
 
Example #16
Source File: FieldPool.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
public void intern(@Nonnull FieldReference field) {
    Integer prev = internedItems.put(field, 0);
    if (prev == null) {
        typePool.intern(field.getDefiningClass());
        stringPool.intern(field.getName());
        typePool.intern(field.getType());
    }
}
 
Example #17
Source File: ImmutableFieldReference.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static ImmutableFieldReference of(@Nonnull FieldReference fieldReference) {
    if (fieldReference instanceof ImmutableFieldReference) {
        return (ImmutableFieldReference)fieldReference;
    }
    return new ImmutableFieldReference(
            fieldReference.getDefiningClass(),
            fieldReference.getName(),
            fieldReference.getType());
}
 
Example #18
Source File: BaseFieldReference.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(@Nonnull FieldReference o) {
    int res = getDefiningClass().compareTo(o.getDefiningClass());
    if (res != 0) return res;
    res = getName().compareTo(o.getName());
    if (res != 0) return res;
    return getType().compareTo(o.getType());
}
 
Example #19
Source File: BaseFieldReference.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(@Nonnull FieldReference o) {
    int res = getDefiningClass().compareTo(o.getDefiningClass());
    if (res != 0) return res;
    res = getName().compareTo(o.getName());
    if (res != 0) return res;
    return getType().compareTo(o.getType());
}
 
Example #20
Source File: InstructionWriter.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
@Nonnull static <StringRef extends StringReference, TypeRef extends TypeReference, FieldRefKey extends FieldReference, MethodRefKey extends MethodReference>
        InstructionWriter<StringRef, TypeRef, FieldRefKey, MethodRefKey>
        makeInstructionWriter(
            @Nonnull DexDataWriter writer,
            @Nonnull StringSection<?, StringRef> stringSection,
            @Nonnull TypeSection<?, ?, TypeRef> typeSection,
            @Nonnull FieldSection<?, ?, FieldRefKey, ?> fieldSection,
            @Nonnull MethodSection<?, ?, ?, MethodRefKey, ?> methodSection) {
    return new InstructionWriter<StringRef, TypeRef, FieldRefKey, MethodRefKey>(
            writer, stringSection, typeSection, fieldSection, methodSection);
}
 
Example #21
Source File: FieldPool.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
public void intern(@Nonnull FieldReference field) {
    Integer prev = internedItems.put(field, 0);
    if (prev == null) {
        typePool.intern(field.getDefiningClass());
        stringPool.intern(field.getName());
        typePool.intern(field.getType());
    }
}
 
Example #22
Source File: BuilderFieldPool.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
@Nonnull public BuilderFieldReference internField(@Nonnull FieldReference fieldReference) {
    BuilderFieldReference ret = internedItems.get(fieldReference);
    if (ret != null) {
        return ret;
    }

    BuilderFieldReference dexPoolFieldReference = new BuilderFieldReference(
            context.typePool.internType(fieldReference.getDefiningClass()),
            context.stringPool.internString(fieldReference.getName()),
            context.typePool.internType(fieldReference.getType()));
    ret = internedItems.putIfAbsent(dexPoolFieldReference, dexPoolFieldReference);
    return ret==null?dexPoolFieldReference:ret;
}
 
Example #23
Source File: InstructionRewriter.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
@Override @Nonnull public Reference getReference() {
    switch (getReferenceType()) {
        case ReferenceType.TYPE:
            return RewriterUtils.rewriteTypeReference(rewriters.getTypeRewriter(),
                    (TypeReference)instruction.getReference());
        case ReferenceType.FIELD:
            return rewriters.getFieldReferenceRewriter().rewrite((FieldReference)instruction.getReference());
        case ReferenceType.METHOD:
            return rewriters.getMethodReferenceRewriter().rewrite((MethodReference)instruction.getReference());
        case ReferenceType.STRING:
            return instruction.getReference();
        default:
            throw new IllegalArgumentException();
    }
}
 
Example #24
Source File: InstructionWriter.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Nonnull static <StringRef extends StringReference, TypeRef extends TypeReference, FieldRefKey extends FieldReference, MethodRefKey extends MethodReference>
        InstructionWriter<StringRef, TypeRef, FieldRefKey, MethodRefKey>
        makeInstructionWriter(
            @Nonnull DexDataWriter writer,
            @Nonnull StringSection<?, StringRef> stringSection,
            @Nonnull TypeSection<?, ?, TypeRef> typeSection,
            @Nonnull FieldSection<?, ?, FieldRefKey, ?> fieldSection,
            @Nonnull MethodSection<?, ?, ?, MethodRefKey, ?> methodSection) {
    return new InstructionWriter<StringRef, TypeRef, FieldRefKey, MethodRefKey>(
            writer, stringSection, typeSection, fieldSection, methodSection);
}
 
Example #25
Source File: ArrayProto.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public FieldReference getFieldByOffset(int fieldOffset) {
    if (fieldOffset==8) {
        return new ImmutableFieldReference(getType(), "length", "int");
    }
    return null;
}
 
Example #26
Source File: BuilderFieldPool.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Nonnull public BuilderFieldReference internField(@Nonnull FieldReference fieldReference) {
    BuilderFieldReference ret = internedItems.get(fieldReference);
    if (ret != null) {
        return ret;
    }

    BuilderFieldReference dexPoolFieldReference = new BuilderFieldReference(
            context.typePool.internType(fieldReference.getDefiningClass()),
            context.stringPool.internString(fieldReference.getName()),
            context.typePool.internType(fieldReference.getType()));
    ret = internedItems.putIfAbsent(dexPoolFieldReference, dexPoolFieldReference);
    return ret==null?dexPoolFieldReference:ret;
}
 
Example #27
Source File: DexPrinter.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
protected static BuilderFieldReference toFieldReference
   		(SootField f, DexBuilder belongingDexFile) {
   	FieldReference fieldRef = new ImmutableFieldReference
   			(SootToDexUtils.getDexClassName(f.getDeclaringClass().getName()),
   			f.getName(),
   			SootToDexUtils.getDexTypeDescriptor(f.getType()));
   	return belongingDexFile.internFieldReference(fieldRef);
}
 
Example #28
Source File: FieldInstruction.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Return a SootFieldRef for a dexlib FieldReference.
 *
 * @param item the dexlib FieldReference.
 * @param isStatic if the FieldRef should be static
 */
private SootFieldRef getSootFieldRef(FieldReference fref, boolean isStatic) {
    String className = dottedClassName(fref.getDefiningClass());
    SootClass sc = SootResolver.v().makeClassRef(className);
    return Scene.v().makeFieldRef(sc,
                                  fref.getName(),
                                  DexType.toSoot(fref.getType()),
                                  isStatic);
}
 
Example #29
Source File: FieldReferenceRewriter.java    From HeyGirl with Apache License 2.0 4 votes vote down vote up
public RewrittenFieldReference(@Nonnull FieldReference fieldReference) {
    this.fieldReference = fieldReference;
}
 
Example #30
Source File: FieldReferenceRewriter.java    From zjdroid with Apache License 2.0 4 votes vote down vote up
public RewrittenFieldReference(@Nonnull FieldReference fieldReference) {
    this.fieldReference = fieldReference;
}