Class MethodAnalyzer

java.lang.Object
org.jf.dexlib2.analysis.MethodAnalyzer

public class MethodAnalyzer extends Object
The MethodAnalyzer performs several functions. It "analyzes" the instructions and infers the register types for each register, it can deodex odexed instructions, and it can verify the bytecode. The analysis and verification are done in two separate passes, because the analysis has to process instructions multiple times in some cases, and there's no need to perform the verification multiple times, so we wait until the method is fully analyzed and then verify it. Before calling the analyze() method, you must have initialized the ClassPath by calling ClassPath.InitializeClassPath
  • Field Details

    • method

      @Nonnull private final Method method
    • methodImpl

      @Nonnull private final MethodImplementation methodImpl
    • normalizeVirtualMethods

      private final boolean normalizeVirtualMethods
    • paramRegisterCount

      private final int paramRegisterCount
    • classPath

      @Nonnull private final ClassPath classPath
    • inlineResolver

      @Nullable private final InlineMethodResolver inlineResolver
    • analyzedInstructions

      @Nonnull private final SparseArray<AnalyzedInstruction> analyzedInstructions
    • analyzedState

      @Nonnull private final BitSet analyzedState
    • analysisException

      @Nullable private AnalysisException analysisException
    • startOfMethod

      private final AnalyzedInstruction startOfMethod
    • Primitive32BitCategories

      private static final BitSet Primitive32BitCategories
    • WideLowCategories

      private static final BitSet WideLowCategories
    • WideHighCategories

      private static final BitSet WideHighCategories
    • ReferenceOrUninitCategories

      private static final BitSet ReferenceOrUninitCategories
    • BooleanCategories

      private static final BitSet BooleanCategories
  • Constructor Details

    • MethodAnalyzer

      public MethodAnalyzer(@Nonnull ClassPath classPath, @Nonnull Method method, @Nullable InlineMethodResolver inlineResolver, boolean normalizeVirtualMethods)
  • Method Details

    • getClassPath

      @Nonnull public ClassPath getClassPath()
    • analyze

      private void analyze()
    • propagateParameterTypes

      private void propagateParameterTypes(int parameterStartRegister)
    • getAnalyzedInstructions

      public List<AnalyzedInstruction> getAnalyzedInstructions()
    • getInstructions

      public List<Instruction> getInstructions()
    • getAnalysisException

      @Nullable public AnalysisException getAnalysisException()
    • getParamRegisterCount

      public int getParamRegisterCount()
    • getInstructionAddress

      public int getInstructionAddress(@Nonnull AnalyzedInstruction instruction)
    • setDestinationRegisterTypeAndPropagateChanges

      private void setDestinationRegisterTypeAndPropagateChanges(@Nonnull AnalyzedInstruction analyzedInstruction, @Nonnull RegisterType registerType)
    • propagateChanges

      private void propagateChanges(@Nonnull BitSet changedInstructions, int registerNumber, boolean override)
    • overridePredecessorRegisterTypeAndPropagateChanges

      private void overridePredecessorRegisterTypeAndPropagateChanges(@Nonnull AnalyzedInstruction analyzedInstruction, @Nonnull AnalyzedInstruction predecessor, int registerNumber, @Nonnull RegisterType registerType)
    • initializeRefAndPropagateChanges

      private void initializeRefAndPropagateChanges(@Nonnull AnalyzedInstruction analyzedInstruction, int registerNumber, @Nonnull RegisterType registerType)
    • setPostRegisterTypeAndPropagateChanges

      private void setPostRegisterTypeAndPropagateChanges(@Nonnull AnalyzedInstruction analyzedInstruction, int registerNumber, @Nonnull RegisterType registerType)
    • propagateRegisterToSuccessors

      private void propagateRegisterToSuccessors(@Nonnull AnalyzedInstruction instruction, int registerNumber, @Nonnull BitSet changedInstructions, boolean override)
    • buildInstructionList

      private void buildInstructionList()
    • addPredecessorSuccessor

      private void addPredecessorSuccessor(@Nonnull AnalyzedInstruction predecessor, @Nonnull AnalyzedInstruction successor, @Nonnull AnalyzedInstruction[][] exceptionHandlers, @Nonnull BitSet instructionsToProcess)
    • addPredecessorSuccessor

      private void addPredecessorSuccessor(@Nonnull AnalyzedInstruction predecessor, @Nonnull AnalyzedInstruction successor, @Nonnull AnalyzedInstruction[][] exceptionHandlers, @Nonnull BitSet instructionsToProcess, boolean allowMoveException)
    • buildExceptionHandlerArray

      @Nonnull private AnalyzedInstruction[] buildExceptionHandlerArray(@Nonnull TryBlock<? extends ExceptionHandler> tryBlock)
    • analyzeInstruction

      private boolean analyzeInstruction(@Nonnull AnalyzedInstruction analyzedInstruction)
      Returns:
      false if analyzedInstruction is an odex instruction that couldn't be deodexed, due to its object register being null
    • analyzeMove

      private void analyzeMove(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyzeMoveResult

      private void analyzeMoveResult(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyzeMoveException

      private void analyzeMoveException(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyzeOdexReturnVoid

      private void analyzeOdexReturnVoid(AnalyzedInstruction analyzedInstruction)
    • analyzeOdexReturnVoid

      private void analyzeOdexReturnVoid(@Nonnull AnalyzedInstruction analyzedInstruction, boolean analyzeResult)
    • analyzeConst

      private void analyzeConst(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyzeWideConst

      private void analyzeWideConst(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyzeConstString

      private void analyzeConstString(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyzeConstClass

      private void analyzeConstClass(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyzeCheckCast

      private void analyzeCheckCast(@Nonnull AnalyzedInstruction analyzedInstruction)
    • isNotWideningConversion

      public static boolean isNotWideningConversion(RegisterType originalType, RegisterType newType)
    • canPropagateTypeAfterInstanceOf

      static boolean canPropagateTypeAfterInstanceOf(AnalyzedInstruction analyzedInstanceOfInstruction, AnalyzedInstruction analyzedIfInstruction, ClassPath classPath)
    • analyzeIfEqzNez

      private void analyzeIfEqzNez(@Nonnull AnalyzedInstruction analyzedInstruction)
      Art uses a peephole optimization for an if-eqz or if-nez that occur immediately after an instance-of. It will narrow the type if possible, and then NOP out any corresponding check-cast instruction later on
    • analyzeInstanceOf

      private void analyzeInstanceOf(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyzeArrayLength

      private void analyzeArrayLength(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyzeNewInstance

      private void analyzeNewInstance(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyzeNewArray

      private void analyzeNewArray(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyzeFloatWideCmp

      private void analyzeFloatWideCmp(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyze32BitPrimitiveAget

      private void analyze32BitPrimitiveAget(@Nonnull AnalyzedInstruction analyzedInstruction, @Nonnull RegisterType registerType)
    • analyzeAgetWide

      private void analyzeAgetWide(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyzeAgetObject

      private void analyzeAgetObject(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyze32BitPrimitiveIgetSget

      private void analyze32BitPrimitiveIgetSget(@Nonnull AnalyzedInstruction analyzedInstruction, @Nonnull RegisterType registerType)
    • analyzeIgetSgetWideObject

      private void analyzeIgetSgetWideObject(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyzeInvokeDirect

      private void analyzeInvokeDirect(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyzeInvokeDirectRange

      private void analyzeInvokeDirectRange(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyzeInvokeDirectCommon

      private void analyzeInvokeDirectCommon(@Nonnull AnalyzedInstruction analyzedInstruction, int objectRegister)
    • analyzeUnaryOp

      private void analyzeUnaryOp(@Nonnull AnalyzedInstruction analyzedInstruction, @Nonnull RegisterType destRegisterType)
    • analyzeBinaryOp

      private void analyzeBinaryOp(@Nonnull AnalyzedInstruction analyzedInstruction, @Nonnull RegisterType destRegisterType, boolean checkForBoolean)
    • analyzeBinary2AddrOp

      private void analyzeBinary2AddrOp(@Nonnull AnalyzedInstruction analyzedInstruction, @Nonnull RegisterType destRegisterType, boolean checkForBoolean)
    • analyzeLiteralBinaryOp

      private void analyzeLiteralBinaryOp(@Nonnull AnalyzedInstruction analyzedInstruction, @Nonnull RegisterType destRegisterType, boolean checkForBoolean)
    • getDestTypeForLiteralShiftRight

      private RegisterType getDestTypeForLiteralShiftRight(@Nonnull AnalyzedInstruction analyzedInstruction, boolean signedShift)
    • analyzeExecuteInline

      private void analyzeExecuteInline(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyzeExecuteInlineRange

      private void analyzeExecuteInlineRange(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyzeInvokeDirectEmpty

      private void analyzeInvokeDirectEmpty(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyzeInvokeDirectEmpty

      private void analyzeInvokeDirectEmpty(@Nonnull AnalyzedInstruction analyzedInstruction, boolean analyzeResult)
    • analyzeInvokeObjectInitRange

      private void analyzeInvokeObjectInitRange(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyzeInvokeObjectInitRange

      private void analyzeInvokeObjectInitRange(@Nonnull AnalyzedInstruction analyzedInstruction, boolean analyzeResult)
    • analyzeIputIgetQuick

      private boolean analyzeIputIgetQuick(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyzeInvokeVirtual

      private boolean analyzeInvokeVirtual(@Nonnull AnalyzedInstruction analyzedInstruction, boolean isRange)
    • analyzeInvokeVirtualQuick

      private boolean analyzeInvokeVirtualQuick(@Nonnull AnalyzedInstruction analyzedInstruction, boolean isSuper, boolean isRange)
    • analyzePutGetVolatile

      private boolean analyzePutGetVolatile(@Nonnull AnalyzedInstruction analyzedInstruction)
    • analyzePutGetVolatile

      private boolean analyzePutGetVolatile(@Nonnull AnalyzedInstruction analyzedInstruction, boolean analyzeResult)
    • getAndCheckSourceRegister

      @Nonnull private static RegisterType getAndCheckSourceRegister(@Nonnull AnalyzedInstruction analyzedInstruction, int registerNumber, BitSet validCategories)
    • checkRegister

      private static void checkRegister(RegisterType registerType, int registerNumber, BitSet validCategories)
    • checkWidePair

      private static void checkWidePair(int registerNumber, AnalyzedInstruction analyzedInstruction)
    • normalizeMethodReference

      @Nullable private MethodReference normalizeMethodReference(@Nonnull MethodReference methodRef)