Exemplo n.º 1
0
  public void addInvoke(
      ArrayList<Instruction> instructions, DebugMethod method, short startReg, CodeItem codeItem) {
    short registerCount = 0;

    if (method.params.length != 0) {
      registerCount = (short) method.params.length;
      for (String param : method.params) {
        if (param.equals("J") || param.equals("D")) {
          registerCount++;
        }
      }
    }

    if (!(method.opcode.name.equals(Opcode.INVOKE_STATIC.name)
        || method.opcode.name.equals(Opcode.INVOKE_STATIC_RANGE.name))) {
      registerCount++;
    }

    instructions.add(
        new Instruction3rc(
                method.opcode, // 65536
                registerCount,
                startReg,
                ic.prepareMethodIdItem(method))
            .setInject());
    if (codeItem.outWords < registerCount) {
      codeItem.outWords = registerCount;
    }
  }
Exemplo n.º 2
0
  /**
   * Inserts hooks into a single code item.
   *
   * @param hooks
   * @param classData
   * @param code
   */
  private void hookReferences(HookMap hooks, ClassDataItem classData, CodeItem code) {
    if (code == null) {
      return;
    }

    Instruction[] instructions = code.getInstructions();
    for (int index = 0; index < instructions.length; index++) {
      Instruction i = instructions[index];

      if (i instanceof InstructionWithReference) {
        InstructionWithReference inst = (InstructionWithReference) i;

        HookItem oldTarget = HookItem.getInstance(inst.getReferencedItem());

        if (!hooks.containsKey(oldTarget)) {
          continue;
        }

        Item newTarget = hooks.get(oldTarget);

        inst.referencedItem = newTarget;

        if (newTarget instanceof MethodIdItem) {
          // Need to update the invoke type if it changed
          updateInvokeType(inst, (MethodIdItem) newTarget);
        }
      }
    }
  }