public void setupLoadOnly(String deobfFileName, boolean loadAll) { try { File mapData = new File(deobfFileName); LZMAInputSupplier zis = new LZMAInputSupplier(new FileInputStream(mapData)); InputSupplier<InputStreamReader> srgSupplier = CharStreams.newReaderSupplier(zis, Charsets.UTF_8); List<String> srgList = CharStreams.readLines(srgSupplier); rawMethodMaps = Maps.newHashMap(); rawFieldMaps = Maps.newHashMap(); Builder<String, String> builder = ImmutableBiMap.<String, String>builder(); Builder<String, String> mcpBuilder = ImmutableBiMap.<String, String>builder(); Splitter splitter = Splitter.on(CharMatcher.anyOf(": ")).omitEmptyStrings().trimResults(); for (String line : srgList) { String[] parts = Iterables.toArray(splitter.split(line), String.class); String typ = parts[0]; if ("CL".equals(typ)) { parseClass(builder, parts); parseMCPClass(mcpBuilder, parts); } else if ("MD".equals(typ) && loadAll) { parseMethod(parts); } else if ("FD".equals(typ) && loadAll) { parseField(parts); } } classNameBiMap = builder.build(); mcpNameBiMap = mcpBuilder.build(); } catch (IOException ioe) { FMLRelaunchLog.log(Level.ERROR, "An error occurred loading the deobfuscation map data", ioe); } methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size()); fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size()); }
private String getFieldType(String owner, String name) { if (fieldDescriptions.containsKey(owner)) { return fieldDescriptions.get(owner).get(name); } synchronized (fieldDescriptions) { try { byte[] classBytes = ClassPatchManager.INSTANCE.getPatchedResource( owner, map(owner).replace('/', '.'), classLoader); if (classBytes == null) { return null; } ClassReader cr = new ClassReader(classBytes); ClassNode classNode = new ClassNode(); cr.accept( classNode, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES); Map<String, String> resMap = Maps.newHashMap(); for (FieldNode fieldNode : (List<FieldNode>) classNode.fields) { resMap.put(fieldNode.name, fieldNode.desc); } fieldDescriptions.put(owner, resMap); return resMap.get(name); } catch (IOException e) { FMLRelaunchLog.log( Level.ERROR, e, "A critical exception occured reading a class file %s", owner); } return null; } }
private Map<String, String> getMethodMap(String className) { if (!methodNameMaps.containsKey(className) && !negativeCacheMethods.contains(className)) { findAndMergeSuperMaps(className); if (!methodNameMaps.containsKey(className)) { negativeCacheMethods.add(className); } if (DUMP_METHOD_MAPS) { FMLRelaunchLog.finer("Method map for %s : %s", className, methodNameMaps.get(className)); } } return methodNameMaps.get(className); }
private Map<String, String> getFieldMap(String className) { if (!fieldNameMaps.containsKey(className) && !negativeCacheFields.contains(className)) { findAndMergeSuperMaps(className); if (!fieldNameMaps.containsKey(className)) { negativeCacheFields.add(className); } if (DUMP_FIELD_MAPS) { FMLRelaunchLog.finer("Field map for %s : %s", className, fieldNameMaps.get(className)); } } return fieldNameMaps.get(className); }
public void setup(File mcDir, LaunchClassLoader classLoader, String deobfFileName) { this.classLoader = classLoader; try { InputStream classData = getClass().getResourceAsStream(deobfFileName); LZMAInputSupplier zis = new LZMAInputSupplier(classData); InputSupplier<InputStreamReader> srgSupplier = CharStreams.newReaderSupplier(zis, Charsets.UTF_8); List<String> srgList = CharStreams.readLines(srgSupplier); rawMethodMaps = Maps.newHashMap(); rawFieldMaps = Maps.newHashMap(); Builder<String, String> builder = ImmutableBiMap.<String, String>builder(); Builder<String, String> mcpBuilder = ImmutableBiMap.<String, String>builder(); Splitter splitter = Splitter.on(CharMatcher.anyOf(": ")).omitEmptyStrings().trimResults(); for (String line : srgList) { String[] parts = Iterables.toArray(splitter.split(line), String.class); String typ = parts[0]; if ("CL".equals(typ)) { parseClass(builder, parts); parseMCPClass(mcpBuilder, parts); } else if ("MD".equals(typ)) { parseMethod(parts); } else if ("FD".equals(typ)) { parseField(parts); } } classNameBiMap = builder.build(); // Special case some mappings for modloader mods mcpBuilder.put("BaseMod", "net/minecraft/src/BaseMod"); mcpBuilder.put("ModLoader", "net/minecraft/src/ModLoader"); mcpBuilder.put("EntityRendererProxy", "net/minecraft/src/EntityRendererProxy"); mcpBuilder.put("MLProp", "net/minecraft/src/MLProp"); mcpBuilder.put("TradeEntry", "net/minecraft/src/TradeEntry"); mcpNameBiMap = mcpBuilder.build(); } catch (IOException ioe) { FMLRelaunchLog.log(Level.ERROR, ioe, "An error occurred loading the deobfuscation map data"); } methodNameMaps = Maps.newHashMapWithExpectedSize(rawMethodMaps.size()); fieldNameMaps = Maps.newHashMapWithExpectedSize(rawFieldMaps.size()); }
@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(); }
@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(); }