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

The following examples show how to use org.jf.dexlib2.iface.reference.FieldReference. These examples are extracted from open source projects. 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 Project: atlas   Author: alibaba   File: ReferenceFormatter.java    License: 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 #2
Source Project: zjdroid   Author: Miracle963   File: ClassProto.java    License: 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 #3
Source Project: JAADAS   Author: flankerhqd   File: FieldInstruction.java    License: 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 #4
Source Project: ZjDroid   Author: KB5201314   File: BaseFieldReference.java    License: 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 #5
Source Project: ZjDroid   Author: halfkiss   File: FieldPool.java    License: 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 Project: ZjDroid   Author: KB5201314   File: FieldPool.java    License: 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 #7
Source Project: ZjDroid   Author: KB5201314   File: BuilderFieldPool.java    License: 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 #8
Source Project: ZjDroid   Author: KB5201314   File: ClassProto.java    License: 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 #9
Source Project: ZjDroid   Author: halfkiss   File: InstructionRewriter.java    License: 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 #10
Source Project: ZjDroid   Author: KB5201314   File: MethodAnalyzer.java    License: 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 #11
Source Project: ZjDroid   Author: halfkiss   File: ArrayProto.java    License: 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 #12
Source Project: HeyGirl   Author: mikusjelly   File: InstructionWriter.java    License: 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 #13
Source Project: ZjDroid   Author: halfkiss   File: MethodAnalyzer.java    License: 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 #14
Source Project: HeyGirl   Author: mikusjelly   File: BaseFieldReference.java    License: 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 #15
Source Project: HeyGirl   Author: mikusjelly   File: FieldPool.java    License: 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 #16
Source Project: zjdroid   Author: Miracle963   File: ImmutableFieldReference.java    License: 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 #17
Source Project: zjdroid   Author: Miracle963   File: BaseFieldReference.java    License: 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 #18
Source Project: HeyGirl   Author: mikusjelly   File: BaseFieldReference.java    License: 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 Project: zjdroid   Author: Miracle963   File: InstructionWriter.java    License: 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 #20
Source Project: zjdroid   Author: Miracle963   File: FieldPool.java    License: 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 #21
Source Project: zjdroid   Author: Miracle963   File: BuilderFieldPool.java    License: 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 #22
Source Project: zjdroid   Author: Miracle963   File: InstructionRewriter.java    License: 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 #23
Source Project: ZjDroid   Author: halfkiss   File: InstructionWriter.java    License: 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 #24
Source Project: zjdroid   Author: Miracle963   File: ArrayProto.java    License: 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 #25
Source Project: ZjDroid   Author: halfkiss   File: BuilderFieldPool.java    License: 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 #26
Source Project: JAADAS   Author: flankerhqd   File: DexPrinter.java    License: 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 #27
Source Project: JAADAS   Author: flankerhqd   File: SgetInstruction.java    License: 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 #28
Source Project: JAADAS   Author: flankerhqd   File: FieldInstruction.java    License: 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 Project: ZjDroid   Author: KB5201314   File: ImmutableFieldEncodedValue.java    License: Apache License 2.0 4 votes vote down vote up
public ImmutableFieldEncodedValue(@Nonnull FieldReference value) {
    this.value = value;
}
 
Example #30
Source Project: HeyGirl   Author: mikusjelly   File: EncodedValueRewriter.java    License: Apache License 2.0 4 votes vote down vote up
@Override @Nonnull public FieldReference getValue() {
    return rewriters.getFieldReferenceRewriter().rewrite(fieldEncodedValue.getValue());
}