Class SimplifyVisitor

java.lang.Object
jadx.core.dex.visitors.AbstractVisitor
jadx.core.dex.visitors.SimplifyVisitor
All Implemented Interfaces:
IDexTreeVisitor

public class SimplifyVisitor extends AbstractVisitor
  • Field Details

    • LOG

      private static final org.slf4j.Logger LOG
    • stringGetBytesMth

      private MethodInfo stringGetBytesMth
  • Constructor Details

    • SimplifyVisitor

      public SimplifyVisitor()
  • Method Details

    • init

      public void init(RootNode root)
      Description copied from interface: IDexTreeVisitor
      Called after loading dex tree, but before visitor traversal.
      Specified by:
      init in interface IDexTreeVisitor
      Overrides:
      init in class AbstractVisitor
    • visit

      public void visit(MethodNode mth)
      Description copied from interface: IDexTreeVisitor
      Visit method
      Specified by:
      visit in interface IDexTreeVisitor
      Overrides:
      visit in class AbstractVisitor
    • simplifyBlock

      private boolean simplifyBlock(MethodNode mth, BlockNode block)
    • simplifyArgs

      private void simplifyArgs(MethodNode mth, InsnNode insn)
    • simplifyInsn

      private InsnNode simplifyInsn(MethodNode mth, InsnNode insn, @Nullable @Nullable InsnNode parentInsn)
    • simplifyStringConstructor

      private InsnNode simplifyStringConstructor(MethodNode mth, ConstructorInsn insn)
    • processCast

      private static InsnNode processCast(MethodNode mth, IndexInsnNode castInsn, @Nullable @Nullable InsnNode parentInsn)
    • isArithWideUpCast

      private static boolean isArithWideUpCast(@Nullable @Nullable InsnNode parentInsn, ArgType argType, ArgType castToType)
      Keep cast to wide types in arith instructions, because arguments type determine instruction used in result bytecode. Example: (long) i invalid input: '<'invalid input: '<' 32 - without 'long' cast will be used 'int shift' instruction and result will be incorrect
    • isCastDuplicate

      private static boolean isCastDuplicate(IndexInsnNode castInsn)
    • shadowedByOuterCast

      private static boolean shadowedByOuterCast(RootNode root, ArgType castType, @Nullable @Nullable InsnNode parentInsn)
    • simplifyIf

      private static void simplifyIf(MethodNode mth, IfNode insn)
      Simplify 'cmp' instruction in if condition
    • simplifyTernary

      private static void simplifyTernary(MethodNode mth, TernaryInsn insn)
      Simplify condition in ternary operation
    • convertInvoke

      private static InsnNode convertInvoke(MethodNode mth, InvokeNode insn)
      Simplify chains of calls to StringBuilder#append() plus constructor of StringBuilder. Those chains are usually automatically generated by the Java compiler when you create String concatenations like "text " + 1 + " text".
    • collectUseChain

      private static List<InsnNode> collectUseChain(MethodNode mth, InvokeNode insn, RegisterArg instanceArg)
    • convertStringBuilderChain

      private static InsnNode convertStringBuilderChain(MethodNode mth, InvokeNode toStrInsn, List<InsnNode> chain)
    • isConstConcatNeeded

      private static boolean isConstConcatNeeded(List<InsnArg> args)
    • concatConstArgs

      private static List<InsnArg> concatConstArgs(List<InsnArg> args)
    • getConcatArg

      private static InsnArg getConcatArg(List<String> concatList, List<InsnArg> args, int idx)
    • getConstString

      @Nullable private static @Nullable String getConstString(InsnArg arg)
    • removeStringBuilderInsns

      private static void removeStringBuilderInsns(MethodNode mth, InvokeNode toStrInsn, List<InsnNode> chain)
      Remove and unbind all instructions with StringBuilder
    • flattenInsnChainUntil

      private static List<InsnNode> flattenInsnChainUntil(InsnNode insn, InsnType insnType)
    • getArgFromAppend

      private static InsnArg getArgFromAppend(InsnNode chainInsn)
    • simplifyArith

      private static InsnNode simplifyArith(ArithNode arith)
    • convertFieldArith

      private static ArithNode convertFieldArith(MethodNode mth, InsnNode insn)
      Convert field arith operation to arith instruction (IPUT (ARITH (IGET, lit)) -> ARITH ((IGET)) = lit))