コード例 #1
1
  public static void renameClassNode(final String oldName, final String newName) {
    for (ClassNode c : BytecodeViewer.getLoadedClasses()) {
      for (Object oo : c.innerClasses) {
        InnerClassNode innerClassNode = (InnerClassNode) oo;
        if (innerClassNode.innerName != null && innerClassNode.innerName.equals(oldName)) {
          innerClassNode.innerName = newName;
        }
        if (innerClassNode.name.equals(oldName)) {
          innerClassNode.name = newName;
        }
        if (innerClassNode.outerName != null && innerClassNode.outerName.equals(oldName)) {
          innerClassNode.outerName = newName;
        }
      }

      if (c.signature != null) c.signature = c.signature.replace(oldName, newName);

      if (c.superName.equals(oldName)) {
        c.superName = newName;
      }
      for (Object o : c.fields.toArray()) {
        FieldNode f = (FieldNode) o;
        f.desc = f.desc.replace(oldName, newName);
      }
      for (Object o : c.interfaces.toArray()) {
        String truxerLipton = (String) o;
        truxerLipton = truxerLipton.replace(oldName, newName);
      }
      for (Object o : c.methods.toArray()) {
        MethodNode m = (MethodNode) o;

        if (m.localVariables != null) {
          for (LocalVariableNode node : (List<LocalVariableNode>) m.localVariables) {
            node.desc = node.desc.replace(oldName, newName);
          }
        }

        if (m.signature != null) m.signature = m.signature.replace(oldName, newName);

        for (int i = 0; i < m.exceptions.size(); i++) {
          if (m.exceptions.get(i).equals(oldName)) m.exceptions.set(i, newName);
        }

        for (AbstractInsnNode i : m.instructions.toArray()) {
          if (i instanceof TypeInsnNode) {
            TypeInsnNode t = (TypeInsnNode) i;
            if (t.desc.equals(oldName)) {
              t.desc = newName;
            }
          }
          if (i instanceof MethodInsnNode) {
            MethodInsnNode mi = (MethodInsnNode) i;
            if (mi.owner.equals(oldName)) mi.owner = newName;
            mi.desc = mi.desc.replace(oldName, newName);
          }
          if (i instanceof FieldInsnNode) {
            FieldInsnNode fi = (FieldInsnNode) i;
            if (fi.owner.equals(oldName)) fi.owner = newName;
            fi.desc = fi.desc.replace(oldName, newName);
          }
        }
      }
    }
  }
コード例 #2
0
 protected Object scrubField(ClassNode cnOrig, ClassNode cnRepl, FieldNode fnRepl) {
   if (fnRepl.desc.equals(cnRepl.name)) {
     fnRepl.desc = fnRepl.desc.replace(cnRepl.name, cnOrig.name);
   }
   return fnRepl;
 }
コード例 #3
0
  @Override
  public byte[] transform(String name, String transformedName, byte[] bytes) {
    if (bytes == null) {
      return null;
    }
    boolean makeAllPublic = FMLDeobfuscatingRemapper.INSTANCE.isRemappedClass(name);

    if (DEBUG) {
      FMLRelaunchLog.fine(
          "Considering all methods and fields on %s (%s): %b\n",
          name, transformedName, makeAllPublic);
    }
    if (!makeAllPublic && !modifiers.containsKey(name)) {
      return bytes;
    }

    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(bytes);
    classReader.accept(classNode, 0);

    if (makeAllPublic) {
      // class
      Modifier m = new Modifier();
      m.targetAccess = ACC_PUBLIC;
      m.modifyClassVisibility = true;
      modifiers.put(name, m);
      // fields
      m = new Modifier();
      m.targetAccess = ACC_PUBLIC;
      m.name = "*";
      modifiers.put(name, m);
      // methods
      m = new Modifier();
      m.targetAccess = ACC_PUBLIC;
      m.name = "*";
      m.desc = "<dummy>";
      modifiers.put(name, m);
      if (DEBUG) {
        System.out.printf("Injected all public modifiers for %s (%s)\n", name, transformedName);
      }
    }

    Collection<Modifier> mods = modifiers.get(name);
    for (Modifier m : mods) {
      if (m.modifyClassVisibility) {
        classNode.access = getFixedAccess(classNode.access, m);
        if (DEBUG) {
          System.out.println(
              String.format(
                  "Class: %s %s -> %s", name, toBinary(m.oldAccess), toBinary(m.newAccess)));
        }
        continue;
      }
      if (m.desc.isEmpty()) {
        for (FieldNode n : classNode.fields) {
          if (n.name.equals(m.name) || m.name.equals("*")) {
            n.access = getFixedAccess(n.access, m);
            if (DEBUG) {
              System.out.println(
                  String.format(
                      "Field: %s.%s %s -> %s",
                      name, n.name, toBinary(m.oldAccess), toBinary(m.newAccess)));
            }

            if (!m.name.equals("*")) {
              break;
            }
          }
        }
      } else {
        for (MethodNode n : classNode.methods) {
          if ((n.name.equals(m.name) && n.desc.equals(m.desc)) || m.name.equals("*")) {
            n.access = getFixedAccess(n.access, m);
            if (DEBUG) {
              System.out.println(
                  String.format(
                      "Method: %s.%s%s %s -> %s",
                      name, n.name, n.desc, toBinary(m.oldAccess), toBinary(m.newAccess)));
            }

            if (!m.name.equals("*")) {
              break;
            }
          }
        }
      }
    }

    ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    classNode.accept(writer);
    return writer.toByteArray();
  }
コード例 #4
0
ファイル: AccessTransformer.java プロジェクト: JoeBarley/FML
  @Override
  public byte[] transform(String name, String transformedName, byte[] bytes) {
    if (bytes == null) {
      return null;
    }

    if (DEBUG) {
      FMLRelaunchLog.fine("Considering all methods and fields on %s (%s)\n", name, transformedName);
    }
    if (!modifiers.containsKey(name)) {
      return bytes;
    }

    ClassNode classNode = new ClassNode();
    ClassReader classReader = new ClassReader(bytes);
    classReader.accept(classNode, 0);

    Collection<Modifier> mods = modifiers.get(name);
    for (Modifier m : mods) {
      if (m.modifyClassVisibility) {
        classNode.access = getFixedAccess(classNode.access, m);
        if (DEBUG) {
          System.out.println(
              String.format(
                  "Class: %s %s -> %s", name, toBinary(m.oldAccess), toBinary(m.newAccess)));
        }
        continue;
      }
      if (m.desc.isEmpty()) {
        for (FieldNode n : classNode.fields) {
          if (n.name.equals(m.name) || m.name.equals("*")) {
            n.access = getFixedAccess(n.access, m);
            if (DEBUG) {
              System.out.println(
                  String.format(
                      "Field: %s.%s %s -> %s",
                      name, n.name, toBinary(m.oldAccess), toBinary(m.newAccess)));
            }

            if (!m.name.equals("*")) {
              break;
            }
          }
        }
      } else {
        for (MethodNode n : classNode.methods) {
          if ((n.name.equals(m.name) && n.desc.equals(m.desc)) || m.name.equals("*")) {
            n.access = getFixedAccess(n.access, m);
            if (DEBUG) {
              System.out.println(
                  String.format(
                      "Method: %s.%s%s %s -> %s",
                      name, n.name, n.desc, toBinary(m.oldAccess), toBinary(m.newAccess)));
            }

            if (!m.name.equals("*")) {
              break;
            }
          }
        }
      }
    }

    ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_MAXS);
    classNode.accept(writer);
    return writer.toByteArray();
  }