Package org.jf.dexlib2.analysis
Class MethodAnalyzer
java.lang.Object
org.jf.dexlib2.analysis.MethodAnalyzer
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
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AnalysisExceptionprivate final SparseArray<AnalyzedInstruction> private final BitSetprivate static final BitSetprivate final ClassPathprivate final InlineMethodResolverprivate final Methodprivate final MethodImplementationprivate final booleanprivate final intprivate static final BitSetprivate static final BitSetprivate final AnalyzedInstructionprivate static final BitSetprivate static final BitSet -
Constructor Summary
ConstructorsConstructorDescriptionMethodAnalyzer(ClassPath classPath, Method method, InlineMethodResolver inlineResolver, boolean normalizeVirtualMethods) -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddPredecessorSuccessor(AnalyzedInstruction predecessor, AnalyzedInstruction successor, AnalyzedInstruction[][] exceptionHandlers, BitSet instructionsToProcess) private voidaddPredecessorSuccessor(AnalyzedInstruction predecessor, AnalyzedInstruction successor, AnalyzedInstruction[][] exceptionHandlers, BitSet instructionsToProcess, boolean allowMoveException) private voidanalyze()private voidanalyze32BitPrimitiveAget(AnalyzedInstruction analyzedInstruction, RegisterType registerType) private voidanalyze32BitPrimitiveIgetSget(AnalyzedInstruction analyzedInstruction, RegisterType registerType) private voidanalyzeAgetObject(AnalyzedInstruction analyzedInstruction) private voidanalyzeAgetWide(AnalyzedInstruction analyzedInstruction) private voidanalyzeArrayLength(AnalyzedInstruction analyzedInstruction) private voidanalyzeBinary2AddrOp(AnalyzedInstruction analyzedInstruction, RegisterType destRegisterType, boolean checkForBoolean) private voidanalyzeBinaryOp(AnalyzedInstruction analyzedInstruction, RegisterType destRegisterType, boolean checkForBoolean) private voidanalyzeCheckCast(AnalyzedInstruction analyzedInstruction) private voidanalyzeConst(AnalyzedInstruction analyzedInstruction) private voidanalyzeConstClass(AnalyzedInstruction analyzedInstruction) private voidanalyzeConstString(AnalyzedInstruction analyzedInstruction) private voidanalyzeExecuteInline(AnalyzedInstruction analyzedInstruction) private voidanalyzeExecuteInlineRange(AnalyzedInstruction analyzedInstruction) private voidanalyzeFloatWideCmp(AnalyzedInstruction analyzedInstruction) private voidanalyzeIfEqzNez(AnalyzedInstruction analyzedInstruction) Art uses a peephole optimization for an if-eqz or if-nez that occur immediately after an instance-of.private voidanalyzeIgetSgetWideObject(AnalyzedInstruction analyzedInstruction) private voidanalyzeInstanceOf(AnalyzedInstruction analyzedInstruction) private booleananalyzeInstruction(AnalyzedInstruction analyzedInstruction) private voidanalyzeInvokeDirect(AnalyzedInstruction analyzedInstruction) private voidanalyzeInvokeDirectCommon(AnalyzedInstruction analyzedInstruction, int objectRegister) private voidanalyzeInvokeDirectEmpty(AnalyzedInstruction analyzedInstruction) private voidanalyzeInvokeDirectEmpty(AnalyzedInstruction analyzedInstruction, boolean analyzeResult) private voidanalyzeInvokeDirectRange(AnalyzedInstruction analyzedInstruction) private voidanalyzeInvokeObjectInitRange(AnalyzedInstruction analyzedInstruction) private voidanalyzeInvokeObjectInitRange(AnalyzedInstruction analyzedInstruction, boolean analyzeResult) private booleananalyzeInvokeVirtual(AnalyzedInstruction analyzedInstruction, boolean isRange) private booleananalyzeInvokeVirtualQuick(AnalyzedInstruction analyzedInstruction, boolean isSuper, boolean isRange) private booleananalyzeIputIgetQuick(AnalyzedInstruction analyzedInstruction) private voidanalyzeLiteralBinaryOp(AnalyzedInstruction analyzedInstruction, RegisterType destRegisterType, boolean checkForBoolean) private voidanalyzeMove(AnalyzedInstruction analyzedInstruction) private voidanalyzeMoveException(AnalyzedInstruction analyzedInstruction) private voidanalyzeMoveResult(AnalyzedInstruction analyzedInstruction) private voidanalyzeNewArray(AnalyzedInstruction analyzedInstruction) private voidanalyzeNewInstance(AnalyzedInstruction analyzedInstruction) private voidanalyzeOdexReturnVoid(AnalyzedInstruction analyzedInstruction) private voidanalyzeOdexReturnVoid(AnalyzedInstruction analyzedInstruction, boolean analyzeResult) private booleananalyzePutGetVolatile(AnalyzedInstruction analyzedInstruction) private booleananalyzePutGetVolatile(AnalyzedInstruction analyzedInstruction, boolean analyzeResult) private voidanalyzeUnaryOp(AnalyzedInstruction analyzedInstruction, RegisterType destRegisterType) private voidanalyzeWideConst(AnalyzedInstruction analyzedInstruction) private AnalyzedInstruction[]buildExceptionHandlerArray(TryBlock<? extends ExceptionHandler> tryBlock) private void(package private) static booleancanPropagateTypeAfterInstanceOf(AnalyzedInstruction analyzedInstanceOfInstruction, AnalyzedInstruction analyzedIfInstruction, ClassPath classPath) private static voidcheckRegister(RegisterType registerType, int registerNumber, BitSet validCategories) private static voidcheckWidePair(int registerNumber, AnalyzedInstruction analyzedInstruction) private static RegisterTypegetAndCheckSourceRegister(AnalyzedInstruction analyzedInstruction, int registerNumber, BitSet validCategories) private RegisterTypegetDestTypeForLiteralShiftRight(AnalyzedInstruction analyzedInstruction, boolean signedShift) intgetInstructionAddress(AnalyzedInstruction instruction) intprivate voidinitializeRefAndPropagateChanges(AnalyzedInstruction analyzedInstruction, int registerNumber, RegisterType registerType) static booleanisNotWideningConversion(RegisterType originalType, RegisterType newType) private MethodReferencenormalizeMethodReference(MethodReference methodRef) private voidoverridePredecessorRegisterTypeAndPropagateChanges(AnalyzedInstruction analyzedInstruction, AnalyzedInstruction predecessor, int registerNumber, RegisterType registerType) private voidpropagateChanges(BitSet changedInstructions, int registerNumber, boolean override) private voidpropagateParameterTypes(int parameterStartRegister) private voidpropagateRegisterToSuccessors(AnalyzedInstruction instruction, int registerNumber, BitSet changedInstructions, boolean override) private voidsetDestinationRegisterTypeAndPropagateChanges(AnalyzedInstruction analyzedInstruction, RegisterType registerType) private voidsetPostRegisterTypeAndPropagateChanges(AnalyzedInstruction analyzedInstruction, int registerNumber, RegisterType registerType)
-
Field Details
-
method
-
methodImpl
-
normalizeVirtualMethods
private final boolean normalizeVirtualMethods -
paramRegisterCount
private final int paramRegisterCount -
classPath
-
inlineResolver
-
analyzedInstructions
-
analyzedState
-
analysisException
-
startOfMethod
-
Primitive32BitCategories
-
WideLowCategories
-
WideHighCategories
-
ReferenceOrUninitCategories
-
BooleanCategories
-
-
Constructor Details
-
MethodAnalyzer
public MethodAnalyzer(@Nonnull ClassPath classPath, @Nonnull Method method, @Nullable InlineMethodResolver inlineResolver, boolean normalizeVirtualMethods)
-
-
Method Details
-
getClassPath
-
analyze
private void analyze() -
propagateParameterTypes
private void propagateParameterTypes(int parameterStartRegister) -
getAnalyzedInstructions
-
getInstructions
-
getAnalysisException
-
getParamRegisterCount
public int getParamRegisterCount() -
getInstructionAddress
-
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
- Returns:
- false if analyzedInstruction is an odex instruction that couldn't be deodexed, due to its object register being null
-
analyzeMove
-
analyzeMoveResult
-
analyzeMoveException
-
analyzeOdexReturnVoid
-
analyzeOdexReturnVoid
private void analyzeOdexReturnVoid(@Nonnull AnalyzedInstruction analyzedInstruction, boolean analyzeResult) -
analyzeConst
-
analyzeWideConst
-
analyzeConstString
-
analyzeConstClass
-
analyzeCheckCast
-
isNotWideningConversion
-
canPropagateTypeAfterInstanceOf
static boolean canPropagateTypeAfterInstanceOf(AnalyzedInstruction analyzedInstanceOfInstruction, AnalyzedInstruction analyzedIfInstruction, ClassPath classPath) -
analyzeIfEqzNez
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
-
analyzeArrayLength
-
analyzeNewInstance
-
analyzeNewArray
-
analyzeFloatWideCmp
-
analyze32BitPrimitiveAget
private void analyze32BitPrimitiveAget(@Nonnull AnalyzedInstruction analyzedInstruction, @Nonnull RegisterType registerType) -
analyzeAgetWide
-
analyzeAgetObject
-
analyze32BitPrimitiveIgetSget
private void analyze32BitPrimitiveIgetSget(@Nonnull AnalyzedInstruction analyzedInstruction, @Nonnull RegisterType registerType) -
analyzeIgetSgetWideObject
-
analyzeInvokeDirect
-
analyzeInvokeDirectRange
-
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
-
analyzeExecuteInlineRange
-
analyzeInvokeDirectEmpty
-
analyzeInvokeDirectEmpty
private void analyzeInvokeDirectEmpty(@Nonnull AnalyzedInstruction analyzedInstruction, boolean analyzeResult) -
analyzeInvokeObjectInitRange
-
analyzeInvokeObjectInitRange
private void analyzeInvokeObjectInitRange(@Nonnull AnalyzedInstruction analyzedInstruction, boolean analyzeResult) -
analyzeIputIgetQuick
-
analyzeInvokeVirtual
private boolean analyzeInvokeVirtual(@Nonnull AnalyzedInstruction analyzedInstruction, boolean isRange) -
analyzeInvokeVirtualQuick
private boolean analyzeInvokeVirtualQuick(@Nonnull AnalyzedInstruction analyzedInstruction, boolean isSuper, boolean isRange) -
analyzePutGetVolatile
-
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
-
normalizeMethodReference
-