示例#1
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();
  }
示例#2
0
  @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();
  }