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

The following examples show how to use org.jf.dexlib2.iface.reference.TypeReference. 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: 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 #2
Source File: MethodAnalyzer.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
private void analyzeMoveResult(@Nonnull AnalyzedInstruction analyzedInstruction) {
    AnalyzedInstruction previousInstruction = analyzedInstructions.valueAt(analyzedInstruction.instructionIndex-1);
    if (!previousInstruction.instruction.getOpcode().setsResult()) {
        throw new AnalysisException(analyzedInstruction.instruction.getOpcode().name + " must occur after an " +
                "invoke-*/fill-new-array instruction");
    }

    RegisterType resultRegisterType;
    ReferenceInstruction invokeInstruction = (ReferenceInstruction)previousInstruction.instruction;
    Reference reference = invokeInstruction.getReference();

    if (reference instanceof MethodReference) {
        resultRegisterType = RegisterType.getRegisterType(classPath, ((MethodReference)reference).getReturnType());
    } else {
        resultRegisterType = RegisterType.getRegisterType(classPath, (TypeReference)reference);
    }

    setDestinationRegisterTypeAndPropagateChanges(analyzedInstruction, resultRegisterType);
}
 
Example #3
Source File: BuilderExceptionHandler.java    From HeyGirl with Apache License 2.0 6 votes vote down vote up
static BuilderExceptionHandler newExceptionHandler(@Nullable final TypeReference exceptionType,
                                            @Nonnull Label handler) {
    if (exceptionType == null) {
        return newExceptionHandler(handler);
    }
    return new BuilderExceptionHandler(handler) {
        @Nullable @Override public String getExceptionType() {
            return exceptionType.getType();
        }

        @Override public int getHandlerCodeAddress() {
            return handler.getCodeAddress();
        }

        @Nullable @Override public TypeReference getExceptionTypeReference() {
            return exceptionType;
        }
    };
}
 
Example #4
Source File: MethodAnalyzer.java    From zjdroid with Apache License 2.0 6 votes vote down vote up
private void analyzeMoveResult(@Nonnull AnalyzedInstruction analyzedInstruction) {
    AnalyzedInstruction previousInstruction = analyzedInstructions.valueAt(analyzedInstruction.instructionIndex-1);
    if (!previousInstruction.instruction.getOpcode().setsResult()) {
        throw new AnalysisException(analyzedInstruction.instruction.getOpcode().name + " must occur after an " +
                "invoke-*/fill-new-array instruction");
    }

    RegisterType resultRegisterType;
    ReferenceInstruction invokeInstruction = (ReferenceInstruction)previousInstruction.instruction;
    Reference reference = invokeInstruction.getReference();

    if (reference instanceof MethodReference) {
        resultRegisterType = RegisterType.getRegisterType(classPath, ((MethodReference)reference).getReturnType());
    } else {
        resultRegisterType = RegisterType.getRegisterType(classPath, (TypeReference)reference);
    }

    setDestinationRegisterTypeAndPropagateChanges(analyzedInstruction, resultRegisterType);
}
 
Example #5
Source File: MethodAnalyzer.java    From HeyGirl with Apache License 2.0 6 votes vote down vote up
private void analyzeMoveResult(@Nonnull AnalyzedInstruction analyzedInstruction) {
    AnalyzedInstruction previousInstruction = analyzedInstructions.valueAt(analyzedInstruction.instructionIndex-1);
    if (!previousInstruction.instruction.getOpcode().setsResult()) {
        throw new AnalysisException(analyzedInstruction.instruction.getOpcode().name + " must occur after an " +
                "invoke-*/fill-new-array instruction");
    }

    RegisterType resultRegisterType;
    ReferenceInstruction invokeInstruction = (ReferenceInstruction)previousInstruction.instruction;
    Reference reference = invokeInstruction.getReference();

    if (reference instanceof MethodReference) {
        resultRegisterType = RegisterType.getRegisterType(classPath, ((MethodReference)reference).getReturnType());
    } else {
        resultRegisterType = RegisterType.getRegisterType(classPath, (TypeReference)reference);
    }

    setDestinationRegisterTypeAndPropagateChanges(analyzedInstruction, resultRegisterType);
}
 
Example #6
Source File: CheckCastInstruction.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public void jimplify (DexBody body) {
      if(!(instruction instanceof Instruction21c))
          throw new IllegalArgumentException("Expected Instruction21c but got: "+instruction.getClass());

      Instruction21c checkCastInstr = (Instruction21c)instruction;

      Local castValue = body.getRegisterLocal(checkCastInstr.getRegisterA());
      Type checkCastType = DexType.toSoot((TypeReference) checkCastInstr.getReference());

      CastExpr castExpr =  Jimple.v().newCastExpr(castValue, checkCastType);

      //generate "x = (Type) x"
      //splitter will take care of the rest
      assign = Jimple.v().newAssignStmt(castValue, castExpr);

      setUnit(assign);
      addTags(assign);
      body.add(assign);
      

      if (IDalvikTyper.ENABLE_DVKTYPER) {
	Debug.printDbg(IDalvikTyper.DEBUG, "constraint: "+ assign);
          DalvikTyper.v().setType(assign.getLeftOpBox(), checkCastType, false);
}

  }
 
Example #7
Source File: BuilderExceptionHandler.java    From ZjDroid with Apache License 2.0 6 votes vote down vote up
static BuilderExceptionHandler newExceptionHandler(@Nullable final TypeReference exceptionType,
                                            @Nonnull Label handler) {
    if (exceptionType == null) {
        return newExceptionHandler(handler);
    }
    return new BuilderExceptionHandler(handler) {
        @Nullable @Override public String getExceptionType() {
            return exceptionType.getType();
        }

        @Override public int getHandlerCodeAddress() {
            return handler.getCodeAddress();
        }

        @Nullable @Override public TypeReference getExceptionTypeReference() {
            return exceptionType;
        }
    };
}
 
Example #8
Source File: InstanceOfInstruction.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public void jimplify (DexBody body) {
      Instruction22c i = (Instruction22c)instruction;
      int dest = i.getRegisterA();
      int source = i.getRegisterB();

      Type t = DexType.toSoot((TypeReference)(i.getReference()));

      InstanceOfExpr e = Jimple.v().newInstanceOfExpr(body.getRegisterLocal(source), t);
      assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), e);
      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().?
      }
  }
 
Example #9
Source File: NewInstanceInstruction.java    From JAADAS with GNU General Public License v3.0 6 votes vote down vote up
public void jimplify (DexBody body) {
      Instruction21c i = (Instruction21c)instruction;
      int dest = i.getRegisterA();
      String className = dottedClassName(((TypeReference)(i.getReference())).toString());
      RefType type = RefType.v(className);
      NewExpr n = Jimple.v().newNewExpr(type);
      assign = Jimple.v().newAssignStmt(body.getRegisterLocal(dest), n);
      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().captureAssign((JAssignStmt)assign, op); // TODO: ref. type may be null!
        DalvikTyper.v().setType(assign.getLeftOpBox(), type, false);
      }
  }
 
Example #10
Source File: BaseExceptionHandler.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
@Nullable @Override public TypeReference getExceptionTypeReference() {
    final String exceptionType = getExceptionType();
    if (exceptionType == null) {
        return null;
    }

    return new BaseTypeReference() {
        @Nonnull @Override public String getType() {
            return exceptionType;
        }
    };
}
 
Example #11
Source File: NewArrayInstruction.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
public void jimplify (DexBody body) {

        if(!(instruction instanceof Instruction22c))
            throw new IllegalArgumentException("Expected Instruction22c but got: "+instruction.getClass());

        Instruction22c newArray = (Instruction22c)instruction;
        int dest = newArray.getRegisterA();

        Value size = body.getRegisterLocal(newArray.getRegisterB());

        Type t = DexType.toSoot((TypeReference) newArray.getReference());
        // NewArrayExpr needs the ElementType as it increases the array dimension by 1
        Type arrayType = ((ArrayType) t).getElementType();
        Debug.printDbg("new array element type: ", arrayType);
        
        NewArrayExpr newArrayExpr = Jimple.v().newNewArrayExpr(arrayType, size);

        Local l = body.getRegisterLocal(dest);
        assign = Jimple.v().newAssignStmt(l, newArrayExpr);

        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(newArrayExpr.getSizeBox(), IntType.v(), true);
          DalvikTyper.v().setType(assign.getLeftOpBox(), newArrayExpr.getType(), false);
        }
    }
 
Example #12
Source File: ImmutableTypeReference.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static ImmutableTypeReference of(@Nonnull TypeReference typeReference) {
    if (typeReference instanceof ImmutableTypeReference) {
        return (ImmutableTypeReference)typeReference;
    }
    return new ImmutableTypeReference(typeReference.getType());
}
 
Example #13
Source File: MethodAnalyzer.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
private void analyzeNewArray(@Nonnull AnalyzedInstruction analyzedInstruction) {
    ReferenceInstruction instruction = (ReferenceInstruction)analyzedInstruction.instruction;

    TypeReference type = (TypeReference)instruction.getReference();
    if (type.getType().charAt(0) != '[') {
        throw new AnalysisException("new-array used with non-array type");
    }

    RegisterType arrayType = RegisterType.getRegisterType(classPath, type);

    setDestinationRegisterTypeAndPropagateChanges(analyzedInstruction, arrayType);
}
 
Example #14
Source File: ConstClassInstruction.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Set<Type> introducedTypes() {
    ReferenceInstruction i = (ReferenceInstruction) instruction;

    Set<Type> types = new HashSet<Type>();
    types.add(DexType.toSoot((TypeReference) i.getReference()));
    return types;
}
 
Example #15
Source File: FilledArrayInstruction.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Set<Type> introducedTypes() {
    ReferenceInstruction i = (ReferenceInstruction) instruction;

    Set<Type> types = new HashSet<Type>();
    types.add(DexType.toSoot((TypeReference) i.getReference()));
    return types;
}
 
Example #16
Source File: InstanceOfInstruction.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Set<Type> introducedTypes() {
    ReferenceInstruction i = (ReferenceInstruction) instruction;

    Set<Type> types = new HashSet<Type>();
    types.add(DexType.toSoot((TypeReference) i.getReference()));
    return types;
}
 
Example #17
Source File: NewInstanceInstruction.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Set<Type> introducedTypes() {
    ReferenceInstruction i = (ReferenceInstruction) instruction;

    Set<Type> types = new HashSet<Type>();
    types.add(DexType.toSoot((TypeReference) i.getReference()));
    return types;
}
 
Example #18
Source File: BuilderStartLocal.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
public BuilderStartLocal(int register,
                         @Nullable StringReference name,
                         @Nullable TypeReference type,
                         @Nullable StringReference signature) {
    this.register = register;
    this.name = name;
    this.type = type;
    this.signature = signature;
}
 
Example #19
Source File: CheckCastInstruction.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Set<Type> introducedTypes() {
    ReferenceInstruction i = (ReferenceInstruction) instruction;

    Set<Type> types = new HashSet<Type>();
    types.add(DexType.toSoot((TypeReference) i.getReference()));
    return types;
}
 
Example #20
Source File: BaseExceptionHandler.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
@Nullable @Override public TypeReference getExceptionTypeReference() {
    final String exceptionType = getExceptionType();
    if (exceptionType == null) {
        return null;
    }

    return new BaseTypeReference() {
        @Nonnull @Override public String getType() {
            return exceptionType;
        }
    };
}
 
Example #21
Source File: BaseExceptionHandler.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Nullable @Override public TypeReference getExceptionTypeReference() {
    final String exceptionType = getExceptionType();
    if (exceptionType == null) {
        return null;
    }

    return new BaseTypeReference() {
        @Nonnull @Override public String getType() {
            return exceptionType;
        }
    };
}
 
Example #22
Source File: NewArrayInstruction.java    From JAADAS with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Set<Type> introducedTypes() {
    ReferenceInstruction i = (ReferenceInstruction) instruction;

    Set<Type> types = new HashSet<Type>();
    types.add(DexType.toSoot((TypeReference) i.getReference()));
    return types;
}
 
Example #23
Source File: BuilderStartLocal.java    From HeyGirl with Apache License 2.0 5 votes vote down vote up
public BuilderStartLocal(int register,
                         @Nullable StringReference name,
                         @Nullable TypeReference type,
                         @Nullable StringReference signature) {
    this.register = register;
    this.name = name;
    this.type = type;
    this.signature = signature;
}
 
Example #24
Source File: ImmutableTypeReference.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static ImmutableTypeReference of(@Nonnull TypeReference typeReference) {
    if (typeReference instanceof ImmutableTypeReference) {
        return (ImmutableTypeReference)typeReference;
    }
    return new ImmutableTypeReference(typeReference.getType());
}
 
Example #25
Source File: MethodAnalyzer.java    From zjdroid with Apache License 2.0 5 votes vote down vote up
private void analyzeNewArray(@Nonnull AnalyzedInstruction analyzedInstruction) {
    ReferenceInstruction instruction = (ReferenceInstruction)analyzedInstruction.instruction;

    TypeReference type = (TypeReference)instruction.getReference();
    if (type.getType().charAt(0) != '[') {
        throw new AnalysisException("new-array used with non-array type");
    }

    RegisterType arrayType = RegisterType.getRegisterType(classPath, type);

    setDestinationRegisterTypeAndPropagateChanges(analyzedInstruction, arrayType);
}
 
Example #26
Source File: ImmutableStartLocal.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Nullable @Override public TypeReference getTypeReference() {
    return type==null?null:new BaseTypeReference() {
        @Nonnull @Override public String getType() {
            return type;
        }
    };
}
 
Example #27
Source File: InstructionRewriter.java    From HeyGirl 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 #28
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 #29
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 #30
Source File: BaseTypeReference.java    From ZjDroid with Apache License 2.0 5 votes vote down vote up
@Override
public boolean equals(Object o) {
    if (o != null) {
        if (o instanceof TypeReference) {
            return getType().equals(((TypeReference)o).getType());
        }
        if (o instanceof CharSequence) {
            return getType().equals(o.toString());
        }
    }
    return false;
}