private void loadPublicConfig() { if(ObfMapping.obfuscated) return; makeAllPublic = CodeChickenCoreModContainer.config.getTag("dev.runtimePublic") .setComment("Enabling this setting will make all minecraft classes public at runtime in MCP just as they are in modloader." + "\nYou should ONLY use this when you are testing with a mod that relies on runtime publicity and doesn't include access transformers." + "\nSuch mods are doing the wrong thing and should be fixed.") .getBooleanValue(false); if(!makeAllPublic) return; try { f_classNameBiMap = FMLDeobfuscatingRemapper.class.getDeclaredField("classNameBiMap"); f_classNameBiMap.setAccessible(true); } catch(Exception e) { throw new RuntimeException(e); } }
static Type map(Type type) { if (!HookLibPlugin.getObfuscated()) return type; // void or primitive if (type.getSort() < 9) return type; //array if (type.getSort() == 9) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < type.getDimensions(); i++) { sb.append("["); } boolean isPrimitiveArray = type.getSort() < 9; if (!isPrimitiveArray) sb.append("L"); sb.append(map(type.getElementType()).getInternalName()); if (!isPrimitiveArray) sb.append(";"); return Type.getType(sb.toString()); } else if (type.getSort() == 10) { String unmappedName = FMLDeobfuscatingRemapper.INSTANCE.map(type.getInternalName()); return Type.getType("L" + unmappedName + ";"); } else { throw new IllegalArgumentException("Can not map method type!"); } }
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodVisitor mv= super.visitMethod(access, name, desc, signature, exceptions); String method=FMLDeobfuscatingRemapper.INSTANCE.mapMethodName(this.name,name,desc); if(method.equals("func_147939_a")){ TB tb=new TB(access,name,desc,signature,exceptions); tb.accept(mv); } return mv; }
public boolean match(final @Nonnull String methodName, final @Nonnull String methodDesc) { if (methodName.equals(this.refname.mcpName())) return true; if (!VisitorHelper.useSrgNames()) return false; final String unmappedDesc = FMLDeobfuscatingRemapper.INSTANCE.mapMethodDesc(methodDesc); if (!unmappedDesc.equals(this.description)) return false; final String unmappedName = FMLDeobfuscatingRemapper.INSTANCE.mapMethodName(this.clsName, methodName, methodDesc); return unmappedName.equals(this.refname.srgName()); }
public boolean match(final @Nonnull String fieldName, final @Nonnull String fieldDesc) { if (!fieldDesc.equals(this.description)) return false; if (fieldName.equals(this.refname.mcpName())) return true; if (!VisitorHelper.useSrgNames()) return false; final String unmappedName = FMLDeobfuscatingRemapper.INSTANCE.mapFieldName(this.clsName, fieldName, fieldDesc); return unmappedName.equals(this.refname.srgName()); }
public static String getSuperClass(String name, boolean runtime) { name = toKey(name); SuperCache cache = declareClass(name); if (cache == null) return "java.lang.Object"; cache.flatten(); String s = cache.superclass; if (!runtime) s = FMLDeobfuscatingRemapper.INSTANCE.unmap(s); return s; }
private void restoreClassMap() { try { f_classNameBiMap.set(FMLDeobfuscatingRemapper.INSTANCE, emptyMap); } catch(Exception e) { throw new RuntimeException(e); } }
private void setClassMap(String name) { try { f_classNameBiMap.set(FMLDeobfuscatingRemapper.INSTANCE, ImmutableBiMap.of(name.replace('.', '/'), "")); } catch(Exception e) { throw new RuntimeException(e); } }
@Override public void injectData(Map<String, Object> data) { liveEnv = (Boolean)data.get("runtimeDeobfuscationEnabled"); cl = (LaunchClassLoader) data.get("classLoader"); File mcDir = (File)data.get("mcLocation"); fmlLocation = (File)data.get("coremodLocation"); ClassPatchManager.INSTANCE.setup(FMLLaunchHandler.side()); FMLDeobfuscatingRemapper.INSTANCE.setup(mcDir, cl, (String) data.get("deobfuscationFileName")); }
public static String[] remapFieldNames(String className, String... fieldNames) { String internalClassName = FMLDeobfuscatingRemapper.INSTANCE.unmap(className.replace('.', '/')); String[] mappedNames = new String[fieldNames.length]; int i = 0; for (String fName : fieldNames) { mappedNames[i++] = FMLDeobfuscatingRemapper.INSTANCE.mapFieldName(internalClassName, fName, null); } return mappedNames; }
@Override public void injectData(Map<String, Object> data) { cl = (LaunchClassLoader) data.get("classLoader"); File mcDir = (File)data.get("mcLocation"); fmlLocation = (File)data.get("coremodLocation"); ClassPatchManager.INSTANCE.setup(FMLLaunchHandler.side()); FMLDeobfuscatingRemapper.INSTANCE.setup(mcDir, cl, (String) data.get("deobfuscationFileName")); }
public static String getSuperClass(String name, boolean runtime) { name = toKey(name); SuperCache cache = declareClass(name); if (cache == null) { return "java.lang.Object"; } cache.flatten(); String s = cache.superclass; if (!runtime) { s = FMLDeobfuscatingRemapper.INSTANCE.unmap(s); } return s; }
private boolean tryMatch(String methodName, String methodDesc) { if (!methodDesc.equals(description)) return false; if (methodName.equals(mcpName)) return true; if (!VisitorHelper.useSrgNames()) return false; String mapped = FMLDeobfuscatingRemapper.INSTANCE.mapMethodName(clsName, methodName, methodDesc); return mapped.equals(srgName); }
public BS4MCTransformer() { srgMappings.put("description", "field_71513_a"); srgMappings.put("cause", "field_71511_b"); srgMappings.put("populateEnvironment", "func_71504_g"); srgMappings.put("getCompleteReport", "func_71502_e"); this.mapper = FMLDeobfuscatingRemapper.INSTANCE; }
public static @Nonnull String getMappedName(final @Nonnull String clsName) { return useSrgNames() ? FMLDeobfuscatingRemapper.INSTANCE.unmap(clsName) : clsName; }
public static void performTest() { for (final String s : FMLDeobfuscatingRemapper.INSTANCE.getObfedClasses()) { LogHelper.info(s + FMLDeobfuscatingRemapper.INSTANCE.map(s), new Object[0]); } }
public static String toKey(String name) { if (ObfMapping.obfuscated) name = FMLDeobfuscatingRemapper.INSTANCE.map(name.replace('.', '/')).replace('/', '.'); return name; }
public static String unKey(String name) { if (ObfMapping.obfuscated) name = FMLDeobfuscatingRemapper.INSTANCE.unmap(name.replace('.', '/')).replace('/', '.'); return name; }
@Override public String map(String typeName) { return FMLDeobfuscatingRemapper.INSTANCE.unmap(typeName); }
public String unmap(String typeName) { return FMLDeobfuscatingRemapper.INSTANCE.map(typeName); }
public static void main(String[] args) throws IOException { String sourceJar = args[0]; //Clean Vanilla jar minecraft.jar or minecraft_server.jar String targetDir = args[1]; //Directory containing obfed output classes, typically mcp/reobf/minecraft String deobfData = args[2]; //Path to FML's deobfusication_data.lzma String outputDir = args[3]; //Path to place generated .binpatch String killTarget = args[4]; //"true" if we should destroy the target file if it generated a successful .binpatch LogManager.getLogger("GENDIFF").log(Level.INFO, String.format("Creating patches at %s for %s from %s", outputDir, sourceJar, targetDir)); Delta delta = new Delta(); FMLDeobfuscatingRemapper remapper = FMLDeobfuscatingRemapper.INSTANCE; remapper.setupLoadOnly(deobfData, false); JarFile sourceZip = new JarFile(sourceJar); boolean kill = killTarget.equalsIgnoreCase("true"); File f = new File(outputDir); f.mkdirs(); for (String name : remapper.getObfedClasses()) { // Logger.getLogger("GENDIFF").info(String.format("Evaluating path for data :%s",name)); String fileName = name; String jarName = name; if (RESERVED_NAMES.contains(name.toUpperCase(Locale.ENGLISH))) { fileName = "_"+name; } File targetFile = new File(targetDir, fileName.replace('/', File.separatorChar) + ".class"); jarName = jarName+".class"; if (targetFile.exists()) { String sourceClassName = name.replace('/', '.'); String targetClassName = remapper.map(name).replace('/', '.'); JarEntry entry = sourceZip.getJarEntry(jarName); byte[] vanillaBytes = entry != null ? ByteStreams.toByteArray(sourceZip.getInputStream(entry)) : new byte[0]; byte[] patchedBytes = Files.toByteArray(targetFile); byte[] diff = delta.compute(vanillaBytes, patchedBytes); ByteArrayDataOutput diffOut = ByteStreams.newDataOutput(diff.length + 50); // Original name diffOut.writeUTF(name); // Source name diffOut.writeUTF(sourceClassName); // Target name diffOut.writeUTF(targetClassName); // exists at original diffOut.writeBoolean(entry != null); if (entry != null) { diffOut.writeInt(Hashing.adler32().hashBytes(vanillaBytes).asInt()); } // length of patch diffOut.writeInt(diff.length); // patch diffOut.write(diff); File target = new File(outputDir, targetClassName+".binpatch"); target.getParentFile().mkdirs(); Files.write(diffOut.toByteArray(), target); Logger.getLogger("GENDIFF").info(String.format("Wrote patch for %s (%s) at %s",name, targetClassName, target.getAbsolutePath())); if (kill) { targetFile.delete(); Logger.getLogger("GENDIFF").info(String.format(" Deleted target: %s", targetFile.toString())); } } } sourceZip.close(); }
@Override public String remapClassName(String name) { return FMLDeobfuscatingRemapper.INSTANCE.map(name.replace('.','/')).replace('/', '.'); }
@Override public String unmapClassName(String name) { return FMLDeobfuscatingRemapper.INSTANCE.unmap(name.replace('.', '/')).replace('/','.'); }
private byte[] hookWorldTick(String name, String unTransformedName, byte[] basicClass){ ClassNode classNode = new ClassNode(); ClassReader classReader = new ClassReader(basicClass); classReader.accept(classNode,0); String targetMethodName = "tick"; String targetMethoddesc = "()V"; FMLLog.log(Level.DEBUG,"Class WorldServer was found!"); MethodNode methodNode = null; for (MethodNode currentMethodNode : classNode.methods){ if (targetMethodName.equals(currentMethodNode.name) || targetMethodName.equals(FMLDeobfuscatingRemapper.INSTANCE.mapMethodName(name,targetMethodName,targetMethoddesc)) || targetMethodName.equals(FMLDeobfuscatingRemapper.INSTANCE.mapMethodName(unTransformedName,targetMethodName,targetMethoddesc))){ methodNode = currentMethodNode; break; } } if(methodNode != null){ InsnList overrideList = new InsnList(); //テスト用のログ FMLLog.log(Level.DEBUG,"Method was found!"); //メソッドコールの追加などをここで行う //Modding Wikiのコピペ /* overrideList.add(new VarInsnNode(ALOAD, 1)); overrideList.add(new VarInsnNode(DLOAD, 2)); overrideList.add(new VarInsnNode(DLOAD, 4)); overrideList.add(new VarInsnNode(DLOAD, 6)); overrideList .add(new MethodInsnNode(INVOKESTATIC, "tutorial/test", "passTestRender", "(LEntityLiving;DDD)V")); */ // mnode.instructions.get(1)で、対象のメソッドの先頭を取得 // mnode.instructions.insertで、指定した位置にバイトコードを挿入します。 //mnode.instructions.insert(mnode.instructions.get(1), overrideList); // 改変したクラスファイルをバイト列に書き出します //ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); //classNode.accept(cw); //return cw.toByteArray(); } return basicClass; }