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

The following examples show how to use org.jf.dexlib2.iface.reference.TypeReference. 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: ZjDroid   Author: KB5201314   File: BuilderExceptionHandler.java    License: 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 #2
Source Project: HeyGirl   Author: mikusjelly   File: MethodAnalyzer.java    License: 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 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 #4
Source Project: zjdroid   Author: Miracle963   File: MethodAnalyzer.java    License: 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 Project: ZjDroid   Author: halfkiss   File: MethodAnalyzer.java    License: 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 Project: HeyGirl   Author: mikusjelly   File: BuilderExceptionHandler.java    License: 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 #7
Source Project: JAADAS   Author: flankerhqd   File: InstanceOfInstruction.java    License: 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 #8
Source Project: JAADAS   Author: flankerhqd   File: NewInstanceInstruction.java    License: 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 #9
Source Project: JAADAS   Author: flankerhqd   File: CheckCastInstruction.java    License: 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 #10
Source Project: HeyGirl   Author: mikusjelly   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 #11
Source Project: ZjDroid   Author: KB5201314   File: ImmutableTypeReference.java    License: 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 #12
Source Project: ZjDroid   Author: KB5201314   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: RewriterUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static TypeReference rewriteTypeReference(@Nonnull final Rewriter<String> typeRewriter,
                                                 @Nonnull final TypeReference typeReference) {
    return new BaseTypeReference() {
        @Nonnull @Override public String getType() {
            return typeRewriter.rewrite(typeReference.getType());
        }
    };
}
 
Example #14
Source Project: HeyGirl   Author: mikusjelly   File: BuilderClassPool.java    License: Apache License 2.0 5 votes vote down vote up
@Nullable private BuilderTypeReference checkTypeReference(@Nullable TypeReference typeReference) {
    if (typeReference == null) {
        return null;
    }
    try {
        return (BuilderTypeReference)typeReference;
    } catch (ClassCastException ex) {
        throw new IllegalStateException("Only TypeReference instances returned by " +
                "DexBuilder.internTypeReference or DexBuilder.internNullableTypeReference may be used.");
    }
}
 
Example #15
Source Project: HeyGirl   Author: mikusjelly   File: MethodAnalyzer.java    License: 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 #16
Source Project: ZjDroid   Author: KB5201314   File: RewriterUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static TypeReference rewriteTypeReference(@Nonnull final Rewriter<String> typeRewriter,
                                                 @Nonnull final TypeReference typeReference) {
    return new BaseTypeReference() {
        @Nonnull @Override public String getType() {
            return typeRewriter.rewrite(typeReference.getType());
        }
    };
}
 
Example #17
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 #18
Source Project: HeyGirl   Author: mikusjelly   File: RewriterUtils.java    License: Apache License 2.0 5 votes vote down vote up
public static TypeReference rewriteTypeReference(@Nonnull final Rewriter<String> typeRewriter,
                                                 @Nonnull final TypeReference typeReference) {
    return new BaseTypeReference() {
        @Nonnull @Override public String getType() {
            return typeRewriter.rewrite(typeReference.getType());
        }
    };
}
 
Example #19
Source Project: zjdroid   Author: Miracle963   File: ImmutableStartLocal.java    License: 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 #20
Source Project: zjdroid   Author: Miracle963   File: ImmutableTypeReference.java    License: 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 #21
Source Project: zjdroid   Author: Miracle963   File: BaseExceptionHandler.java    License: 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 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 #23
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 #24
Source Project: ZjDroid   Author: halfkiss   File: BaseTypeReference.java    License: 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;
}
 
Example #25
Source Project: ZjDroid   Author: halfkiss   File: ImmutableStartLocal.java    License: 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 #26
Source Project: zjdroid   Author: Miracle963   File: MethodAnalyzer.java    License: 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 #27
Source Project: ZjDroid   Author: halfkiss   File: ImmutableTypeReference.java    License: 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 #28
Source Project: HeyGirl   Author: mikusjelly   File: BuilderStartLocal.java    License: 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 #29
Source Project: ZjDroid   Author: halfkiss   File: BuilderStartLocal.java    License: 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 #30
Source Project: JAADAS   Author: flankerhqd   File: InstanceOfInstruction.java    License: 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;
}