|
1 | 1 | package org.devinprogress.YAIF.Transformer;
|
2 | 2 |
|
| 3 | +import cpw.mods.fml.common.asm.transformers.deobf.FMLDeobfuscatingRemapper; |
3 | 4 | import org.devinprogress.YAIF.YetAnotherInputFix;
|
4 | 5 | import org.objectweb.asm.ClassReader;
|
5 | 6 | import org.objectweb.asm.ClassWriter;
|
|
14 | 15 | */
|
15 | 16 | public class ASMHelper {
|
16 | 17 | private Object obj;
|
17 |
| - //private Map<String,List<String[]>> map; |
18 |
| - //public static Boolean DEOBF_ENV; |
19 |
| - //Map<DeobfuscatedClassName,[DeobfMethodName,ObfedMethodName,Description,ProcessMethod]> |
20 |
| - private List<MethodRecord> map=null; |
21 |
| - private Set<String> classMap=null; |
| 18 | + //Map<DeobfuscatedClassName,Map<methodName+Desc,processMethod>> |
| 19 | + private Map<String,Map<String,Method>> map; |
| 20 | + |
22 | 21 | public ASMHelper(Object o){
|
23 | 22 | obj=o;
|
24 |
| - map=new ArrayList<MethodRecord>(); |
25 |
| - classMap=new HashSet<String>(); |
| 23 | + map=new HashMap<String, Map<String,Method>>(); |
26 | 24 | }
|
27 | 25 |
|
28 |
| - public void add(String className,String methodName,String methodNameDeobf,String Descripton,String DescriptionDeobf,String targetTransformer){ |
29 |
| - map.add(new MethodRecord( |
30 |
| - className, |
31 |
| - methodName, |
32 |
| - methodNameDeobf, |
33 |
| - Descripton, |
34 |
| - DescriptionDeobf, |
35 |
| - targetTransformer |
36 |
| - )); |
37 |
| - classMap.add(className); |
| 26 | + public void hookMethod(String className,String srgName,String mcpName,String desc,String targetTransformer){ |
| 27 | + if(!map.containsKey(className)) |
| 28 | + map.put(className,new HashMap<String, Method>()); |
| 29 | + Method m=null; |
| 30 | + try{ |
| 31 | + m= obj.getClass().getDeclaredMethod(targetTransformer,MethodNode.class); |
| 32 | + }catch(Exception e){ |
| 33 | + e.printStackTrace(); |
| 34 | + } |
| 35 | + map.get(className).put(srgName + desc, m); |
| 36 | + map.get(className).put(mcpName + desc, m); |
38 | 37 | }
|
39 | 38 |
|
40 |
| - public byte[] transform(String className,byte[] bytes){ |
| 39 | + public byte[] transform(String obfClassName,String className,byte[] bytes){ |
| 40 | + if(!map.containsKey(className))return bytes; |
| 41 | + Map<String,Method> transMap=map.get(className); |
41 | 42 |
|
42 |
| - if(!classMap.contains(className))return bytes; |
43 |
| - //System.out.println("Examing Class:"+className); |
44 | 43 | ClassReader cr=new ClassReader(bytes);
|
45 | 44 | ClassNode cn=new ClassNode();
|
46 | 45 | cr.accept(cn, 0);
|
47 | 46 |
|
48 | 47 | for(MethodNode mn:cn.methods){
|
49 | 48 | //System.out.println(String.format("Examing Method: %s%s",mn.name,mn.desc));
|
50 |
| - for(MethodRecord r:map){ |
51 |
| - r.preProcess(!YetAnotherInputFix.ObfuscatedEnv,obj); |
52 |
| - if(mn.name.equals(r.MethodName)&&mn.desc.equals(r.Desc)&&className.equals(r.ClassName)){ |
53 |
| - try{ |
54 |
| - //System.out.println(String.format("Invoking Method: %s%s",mn.name,mn.desc)); |
55 |
| - r.ProcessMethod.invoke(obj,mn); |
56 |
| - }catch(Exception e){ |
57 |
| - e.printStackTrace(); |
58 |
| - return bytes; |
59 |
| - } |
60 |
| - break; |
| 49 | + String methodName=FMLDeobfuscatingRemapper.INSTANCE.mapMethodName(obfClassName,mn.name,mn.desc); |
| 50 | + String methodDesc=FMLDeobfuscatingRemapper.INSTANCE.mapMethodDesc(mn.desc); |
| 51 | + if(transMap.containsKey(methodName+methodDesc)){ |
| 52 | + try{ |
| 53 | + //System.out.println(String.format("Invoking Method: %s%s",mn.name,mn.desc)); |
| 54 | + transMap.get(methodName+methodDesc).invoke(obj,mn); |
| 55 | + }catch(Exception e){ |
| 56 | + e.printStackTrace(); |
| 57 | + return bytes; |
61 | 58 | }
|
62 | 59 | }
|
63 | 60 | }
|
|
0 commit comments