Java InsnArg Example

Introduction

The java insnarg example is extracted from the most popular open source projects, you can refer to the following example for usage.

Programming language: Java

Namespace/package name: jadx.core.dex.instructions.args

Example#1
File: SSATransform.javaProject: gitter-badger/jadx

 private static void renameVar(MethodNode mth, SSAVar[] vars, int[] vers, BlockNode block) {
   SSAVar[] inputVars = Arrays.copyOf(vars, vars.length);
   for (InsnNode insn : block.getInstructions()) {
     if (insn.getType() != InsnType.PHI) {
       for (InsnArg arg : insn.getArguments()) {
         if (!arg.isRegister()) {
           continue;
         }
         RegisterArg reg = (RegisterArg) arg;
         int regNum = reg.getRegNum();
         SSAVar var = vars[regNum];
         if (var == null) {
           throw new JadxRuntimeException(
               "Not initialized variable reg: "
                   + regNum
                   + ", insn: "
                   + insn
                   + ", block:"
                   + block
                   + ", method: "
                   + mth);
         }
         var.use(reg);
       }
     }
     RegisterArg result = insn.getResult();
     if (result != null) {
       int regNum = result.getRegNum();
       vars[regNum] = mth.makeNewSVar(regNum, vers, result);
     }
   }
   for (BlockNode s : block.getSuccessors()) {
     PhiListAttr phiList = s.get(AType.PHI_LIST);
     if (phiList == null) {
       continue;
     }
     int j = s.getPredecessors().indexOf(block);
     if (j == -1) {
       throw new JadxRuntimeException("Can't find predecessor for " + block + " " + s);
     }
     for (PhiInsn phiInsn : phiList.getList()) {
       if (j >= phiInsn.getArgsCount()) {
         continue;
       }
       int regNum = phiInsn.getResult().getRegNum();
       SSAVar var = vars[regNum];
       if (var == null) {
         continue;
       }
       var.use(phiInsn.getArg(j));
       var.setUsedInPhi(phiInsn);
     }
   }
   for (BlockNode domOn : block.getDominatesOn()) {
     renameVar(mth, vars, vers, domOn);
   }
   System.arraycopy(inputVars, 0, vars, 0, vars.length);
 }

Example#2
File: DebugInfoParser.javaProject: kennychou0529/jadx

 private static void merge(InsnArg arg, LocalVar var) {
   if (arg != null && arg.isRegister()) {
     RegisterArg reg = (RegisterArg) arg;
     if (var.getRegNum() == reg.getRegNum()) {
       reg.mergeDebugInfo(var.getType(), var.getName());
     }
   }
 }

Example#3
File: DebugInfoParser.javaProject: kennychou0529/jadx

 private int addrChange(int addr, int addrInc, int line) {
   int newAddr = addr + addrInc;
   for (int i = addr + 1; i <= newAddr; i++) {
     InsnNode insn = insnByOffset[i];
     if (insn == null) {
       continue;
     }
     for (InsnArg arg : insn.getArguments()) {
       if (arg.isRegister()) {
         activeRegisters[((RegisterArg) arg).getRegNum()] = arg;
       }
     }
     RegisterArg res = insn.getResult();
     if (res != null) {
       activeRegisters[res.getRegNum()] = res;
     }
   }
   setSourceLines(addr, newAddr, line);
   return newAddr;
 }