Created
December 26, 2014 04:48
-
-
Save Cazzar/9115a119bc056fb2cc5f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.cazzar.corelib.asm.transformers; | |
import net.minecraft.launchwrapper.IClassTransformer; | |
import org.objectweb.asm.ClassReader; | |
import org.objectweb.asm.tree.ClassNode; | |
import org.objectweb.asm.tree.FieldNode; | |
import org.objectweb.asm.tree.MethodNode; | |
import java.io.File; | |
import java.io.FileNotFoundException; | |
import java.io.IOException; | |
import java.io.PrintStream; | |
public class ClassDumpingTransformer implements IClassTransformer { | |
static File[] outputFile = {new File("fields"), new File("methods")}; | |
static { | |
for (File file : outputFile) { | |
if (!file.exists()) try { | |
file.createNewFile(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
PrintStream[] output = new PrintStream[outputFile.length]; | |
public ClassDumpingTransformer() throws FileNotFoundException { | |
for (int i = 0; i < outputFile.length; i++) { | |
output[i] = new PrintStream(outputFile[i]); | |
} | |
} | |
@Override | |
public byte[] transform(String name, String transformedName, byte[] bytes) { | |
if (!transformedName.startsWith("net.minecraft.")) return bytes; | |
ClassNode clazz = new ClassNode(); | |
ClassReader classReader = new ClassReader(bytes); | |
classReader.accept(clazz, 0); | |
for (PrintStream stream : output) { | |
stream.printf("%n#%s%n", transformedName); | |
} | |
for (FieldNode field : clazz.fields) { | |
output[0].printf("%s %s%n", field.name, field.desc); | |
} | |
for (MethodNode method : clazz.methods) { | |
output[1].printf("%s %s%n", method.name, method.desc); | |
} | |
return bytes; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment