@Override
  public void run() {
    ClassGen nodeCG = hookHandler.getClassByNick("Node");
    ClassGen npcCG = hookHandler.getClassByNick("NPC");
    for (ClassGen cG : classes) {
      ConstantPoolGen cpg = cG.getConstantPool();
      if (!cG.getSuperclassName().equals(nodeCG.getClassName())) {
        continue;
      }

      int nonStaticFieldCount = 0;
      int npcFieldCount = 0;
      for (Field field : cG.getFields()) {
        if (field.isStatic()) {
          continue;
        }
        nonStaticFieldCount++;
        if (field.getType().toString().equals(npcCG.getClassName())) {
          npcFieldCount++;
        }
      }
      if (nonStaticFieldCount != 1 || npcFieldCount != 1) {
        continue;
      }

      hookHandler.addClassNick("NPCNode", cG);
      for (Field field : cG.getFields()) {
        if (field.isStatic()) {
          continue;
        }
        if (field.getType().toString().equals(npcCG.getClassName())) {
          hookHandler.addFieldHook("NPCNode", cG, field, "NPC", TypeBuilder.createHookType("NPC"));
        }
      }
    }
    ClassGen npcNodeCG = hookHandler.getClassByNick("NPCNode");
    for (ClassGen cG : classes) {
      for (Field field : cG.getFields()) {
        if (!field.isStatic()) {
          continue;
        }
        if (field.getType().getSignature().equals("[L" + npcNodeCG.getClassName() + ";")) {
          hookHandler.addClientHook(
              cG, field, "NPCNodes", TypeBuilder.createHookArrayType("NPCNode", 1));
        }
      }
    }
    ClassGen nodeCacheCG = hookHandler.getClassByNick("NodeCache");
    FieldHook fieldHook = hookHandler.getFieldHook("NPCNode", "NPC");
    for (ClassGen cG : classes) {
      ConstantPoolGen cpg = cG.getConstantPool();
      if (cpg.lookupClass(nodeCacheCG.getClassName()) == -1) {
        continue;
      }
      if (cpg.lookupFieldref(
              fieldHook.getClassName(),
              fieldHook.getFieldName(),
              fieldHook.getFieldType().getSignature())
          == -1) {
        continue;
      }
      for (Method method : cG.getMethods()) {
        if (!method.isStatic()) {
          continue;
        }
        if (!method.getReturnType().equals(Type.VOID)) {
          continue;
        }
        Type[] args = method.getArgumentTypes();
        if (args.length < 13 || args.length > 14) {
          continue;
        }
        if (TypeCounter.getObjectCount(args) != 0) {
          continue;
        }
        InstructionList iList = new InstructionList(method.getCode().getCode());
        InstructionFinder instructionFinder = new InstructionFinder(iList);
        for (Iterator<InstructionHandle[]> iterator = instructionFinder.search("getstatic");
            iterator.hasNext(); ) {
          InstructionHandle[] ih = iterator.next();
          FieldInstruction fieldInstruction = (FieldInstruction) ih[0].getInstruction();
          if (fieldInstruction.getFieldType(cpg).toString().equals(nodeCacheCG.getClassName())) {
            hookHandler.addClientHook(
                fieldInstruction, cpg, "NPCNodeCache", TypeBuilder.createHookType("NodeCache"));
          }
        }
      }
    }
  }
Exemplo n.º 2
0
 /** Field access. */
 public void visitFieldInstruction(FieldInstruction i) {
   cv.registerFieldAccess(i.getClassName(cp), i.getFieldName(cp));
   cv.registerCoupling(i.getFieldType(cp));
 }