Clean up of the striping code
This commit is contained in:
parent
5b06a20351
commit
f81c5c4f8d
3 changed files with 36 additions and 78 deletions
|
@ -1,9 +1,7 @@
|
|||
package techreborn.asm;
|
||||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.ModAPIManager;
|
||||
import cpw.mods.fml.common.ModContainer;
|
||||
import cpw.mods.fml.common.discovery.ASMDataTable;
|
||||
import cpw.mods.fml.common.versioning.InvalidVersionSpecificationException;
|
||||
import cpw.mods.fml.common.versioning.VersionRange;
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
|
@ -14,6 +12,7 @@ import org.objectweb.asm.tree.AnnotationNode;
|
|||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.objectweb.asm.tree.FieldNode;
|
||||
import org.objectweb.asm.tree.MethodNode;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
@ -21,47 +20,17 @@ import java.util.Map;
|
|||
|
||||
public class ClassTransformation implements IClassTransformer {
|
||||
|
||||
private static boolean scrappedData = false;
|
||||
static String strippableDesc;
|
||||
private static final String[] emptyList = {};
|
||||
static String strippableDesc;
|
||||
private static Map<String, ModContainer> mods;
|
||||
|
||||
|
||||
public ClassTransformation() {
|
||||
strippableDesc = Type.getDescriptor(Strippable.class);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public byte[] transform(String name, String transformedName, byte[] bytes) {
|
||||
|
||||
if (bytes == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ClassReader cr = new ClassReader(bytes);
|
||||
ClassNode cn = new ClassNode();
|
||||
cr.accept(cn, 0);
|
||||
if (strip(cn)) {
|
||||
ClassWriter cw = new ClassWriter(0);
|
||||
cn.accept(cw);
|
||||
bytes = cw.toByteArray();
|
||||
System.out.println("Striped " + name);
|
||||
} else {
|
||||
//LogHelper.trace("Nothing stripped from " + transformedName);
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
static boolean strip(ClassNode cn) {
|
||||
boolean altered = false;
|
||||
if (cn.visibleAnnotations != null) {
|
||||
for (AnnotationNode n : cn.visibleAnnotations) {
|
||||
AnnotationInfo node = parseAnnotation(n, strippableDesc);
|
||||
if(node != null){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
if (cn.methods != null) {
|
||||
Iterator<MethodNode> iter = cn.methods.iterator();
|
||||
while (iter.hasNext()) {
|
||||
|
@ -95,7 +64,6 @@ public class ClassTransformation implements IClassTransformer {
|
|||
|
||||
|
||||
static AnnotationInfo parseAnnotation(AnnotationNode node, String desc) {
|
||||
|
||||
AnnotationInfo info = null;
|
||||
if (node.desc.equals(desc)) {
|
||||
info = new AnnotationInfo();
|
||||
|
@ -109,11 +77,6 @@ public class ClassTransformation implements IClassTransformer {
|
|||
continue;
|
||||
}
|
||||
info.values = ((List<?>) v).toArray(emptyList);
|
||||
} else if ("side".equals(k) && v instanceof String[]) {
|
||||
String t = ((String[]) v)[1];
|
||||
if (t != null) {
|
||||
info.side = t.toUpperCase().intern();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -159,15 +122,7 @@ public class ClassTransformation implements IClassTransformer {
|
|||
return false;
|
||||
}
|
||||
|
||||
static class AnnotationInfo {
|
||||
|
||||
public String side = "NONE";
|
||||
public String[] values = emptyList;
|
||||
}
|
||||
|
||||
private static Map<String, ModContainer> mods;
|
||||
static Map<String, ModContainer> getLoadedMods() {
|
||||
|
||||
if (mods == null) {
|
||||
mods = new HashMap<String, ModContainer>();
|
||||
for (ModContainer m : Loader.instance().getModList()) {
|
||||
|
@ -176,4 +131,27 @@ public class ClassTransformation implements IClassTransformer {
|
|||
}
|
||||
return mods;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] transform(String name, String transformedName, byte[] bytes) {
|
||||
if (bytes == null) {
|
||||
return null;
|
||||
}
|
||||
ClassReader cr = new ClassReader(bytes);
|
||||
ClassNode cn = new ClassNode();
|
||||
cr.accept(cn, 0);
|
||||
if (strip(cn)) {
|
||||
ClassWriter cw = new ClassWriter(0);
|
||||
cn.accept(cw);
|
||||
bytes = cw.toByteArray();
|
||||
LoadingPlugin.stripedClases++;
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
static class AnnotationInfo {
|
||||
|
||||
public String side = "NONE";
|
||||
public String[] values = emptyList;
|
||||
}
|
||||
}
|
|
@ -1,23 +1,18 @@
|
|||
package techreborn.asm;
|
||||
|
||||
import com.google.common.eventbus.EventBus;
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
import cpw.mods.fml.common.DummyModContainer;
|
||||
import cpw.mods.fml.common.LoadController;
|
||||
import cpw.mods.fml.common.ModMetadata;
|
||||
import cpw.mods.fml.common.discovery.ASMDataTable;
|
||||
import cpw.mods.fml.common.event.FMLConstructionEvent;
|
||||
import cpw.mods.fml.relauncher.IFMLCallHook;
|
||||
import cpw.mods.fml.relauncher.IFMLLoadingPlugin;
|
||||
import techreborn.lib.ModInfo;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@IFMLLoadingPlugin.MCVersion( "1.7.10" )
|
||||
@IFMLLoadingPlugin.MCVersion("1.7.10")
|
||||
public class LoadingPlugin implements IFMLLoadingPlugin {
|
||||
|
||||
public static ASMDataTable ASM_DATA = null;
|
||||
public static boolean runtimeDeobfEnabled = false;
|
||||
public static int stripedClases = 0;
|
||||
|
||||
@Override
|
||||
public String[] getASMTransformerClass() {
|
||||
|
@ -45,38 +40,24 @@ public class LoadingPlugin implements IFMLLoadingPlugin {
|
|||
}
|
||||
|
||||
public static class DummyMod extends DummyModContainer implements IFMLCallHook {
|
||||
|
||||
public DummyMod() {
|
||||
|
||||
super(new ModMetadata());
|
||||
ModMetadata md = getMetadata();
|
||||
md.autogenerated = true;
|
||||
md.modId = ModInfo.MOD_ID + "asm";
|
||||
md.name = md.description = "Techreborn-Stripper";
|
||||
md.name = md.description = "Techreborn-ASM";
|
||||
md.parent = ModInfo.MOD_ID;
|
||||
md.version = "000";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean registerBus(EventBus bus, LoadController controller) {
|
||||
|
||||
bus.register(this);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void construction(FMLConstructionEvent evt) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void injectData(Map<String, Object> data) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void call() throws Exception {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,8 +10,7 @@ import java.lang.annotation.Target;
|
|||
* When used on a class, methods from referenced interfaces will not be removed <br>
|
||||
* When using this annotation on methods, ensure you do not switch on an enum inside that method. JavaC implementation details means this will cause crashes.
|
||||
* <p/>
|
||||
* Can also strip on modid using "mod:CoFHCore" as a value <br>
|
||||
* Can also strip on API using "api:CoFHAPI|energy" as a value
|
||||
* Can also strip on modid using "mod:<MODID>" as a value <br>
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
|
|
Loading…
Add table
Reference in a new issue