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