diff options
Diffstat (limited to '')
| -rw-r--r-- | src/main/java/cuchaz/enigma/mapping/EntryFactory.java | 101 |
1 files changed, 7 insertions, 94 deletions
diff --git a/src/main/java/cuchaz/enigma/mapping/EntryFactory.java b/src/main/java/cuchaz/enigma/mapping/EntryFactory.java index 993bb64b..c20f6f5f 100644 --- a/src/main/java/cuchaz/enigma/mapping/EntryFactory.java +++ b/src/main/java/cuchaz/enigma/mapping/EntryFactory.java | |||
| @@ -12,19 +12,8 @@ | |||
| 12 | package cuchaz.enigma.mapping; | 12 | package cuchaz.enigma.mapping; |
| 13 | 13 | ||
| 14 | import cuchaz.enigma.analysis.JarIndex; | 14 | import cuchaz.enigma.analysis.JarIndex; |
| 15 | import javassist.*; | ||
| 16 | import javassist.bytecode.Descriptor; | ||
| 17 | import javassist.expr.ConstructorCall; | ||
| 18 | import javassist.expr.FieldAccess; | ||
| 19 | import javassist.expr.MethodCall; | ||
| 20 | import javassist.expr.NewExpr; | ||
| 21 | 15 | ||
| 22 | public class EntryFactory { | 16 | public class EntryFactory { |
| 23 | |||
| 24 | public static ClassEntry getClassEntry(CtClass c) { | ||
| 25 | return new ClassEntry(Descriptor.toJvmName(c.getName())); | ||
| 26 | } | ||
| 27 | |||
| 28 | public static ClassEntry getObfClassEntry(JarIndex jarIndex, ClassMapping classMapping) { | 17 | public static ClassEntry getObfClassEntry(JarIndex jarIndex, ClassMapping classMapping) { |
| 29 | ClassEntry obfClassEntry = new ClassEntry(classMapping.getObfFullName()); | 18 | ClassEntry obfClassEntry = new ClassEntry(classMapping.getObfFullName()); |
| 30 | return obfClassEntry.buildClassEntry(jarIndex.getObfClassChain(obfClassEntry)); | 19 | return obfClassEntry.buildClassEntry(jarIndex.getObfClassChain(obfClassEntry)); |
| @@ -38,95 +27,19 @@ public class EntryFactory { | |||
| 38 | return new ClassEntry(classMapping.getDeobfName()); | 27 | return new ClassEntry(classMapping.getDeobfName()); |
| 39 | } | 28 | } |
| 40 | 29 | ||
| 41 | public static ClassEntry getSuperclassEntry(CtClass c) { | ||
| 42 | return new ClassEntry(Descriptor.toJvmName(c.getClassFile().getSuperclass())); | ||
| 43 | } | ||
| 44 | |||
| 45 | public static FieldEntry getFieldEntry(CtField field) { | ||
| 46 | return new FieldEntry(getClassEntry(field.getDeclaringClass()), field.getName(), new Type(field.getFieldInfo().getDescriptor())); | ||
| 47 | } | ||
| 48 | |||
| 49 | public static FieldEntry getFieldEntry(FieldAccess call) { | ||
| 50 | return new FieldEntry(new ClassEntry(Descriptor.toJvmName(call.getClassName())), call.getFieldName(), new Type(call.getSignature())); | ||
| 51 | } | ||
| 52 | |||
| 53 | public static FieldEntry getFieldEntry(String className, String name, String type) { | ||
| 54 | return new FieldEntry(new ClassEntry(className), name, new Type(type)); | ||
| 55 | } | ||
| 56 | |||
| 57 | public static FieldEntry getObfFieldEntry(ClassMapping classMapping, FieldMapping fieldMapping) { | 30 | public static FieldEntry getObfFieldEntry(ClassMapping classMapping, FieldMapping fieldMapping) { |
| 58 | return new FieldEntry(getObfClassEntry(classMapping), fieldMapping.getObfName(), fieldMapping.getObfType()); | 31 | return new FieldEntry(getObfClassEntry(classMapping), fieldMapping.getObfName(), fieldMapping.getObfDesc()); |
| 59 | } | ||
| 60 | |||
| 61 | public static MethodEntry getMethodEntry(CtMethod method) { | ||
| 62 | return new MethodEntry(getClassEntry(method.getDeclaringClass()), method.getName(), new Signature(method.getMethodInfo().getDescriptor())); | ||
| 63 | } | ||
| 64 | |||
| 65 | public static MethodEntry getMethodEntry(MethodCall call) { | ||
| 66 | return new MethodEntry(new ClassEntry(Descriptor.toJvmName(call.getClassName())), call.getMethodName(), new Signature(call.getSignature())); | ||
| 67 | } | ||
| 68 | |||
| 69 | public static ConstructorEntry getConstructorEntry(CtConstructor constructor) { | ||
| 70 | if (constructor.isClassInitializer()) { | ||
| 71 | return new ConstructorEntry(getClassEntry(constructor.getDeclaringClass())); | ||
| 72 | } else { | ||
| 73 | return new ConstructorEntry(getClassEntry(constructor.getDeclaringClass()), new Signature(constructor.getMethodInfo().getDescriptor())); | ||
| 74 | } | ||
| 75 | } | ||
| 76 | |||
| 77 | public static ConstructorEntry getConstructorEntry(ConstructorCall call) { | ||
| 78 | return new ConstructorEntry(new ClassEntry(Descriptor.toJvmName(call.getClassName())), new Signature(call.getSignature())); | ||
| 79 | } | ||
| 80 | |||
| 81 | public static ConstructorEntry getConstructorEntry(NewExpr call) { | ||
| 82 | return new ConstructorEntry(new ClassEntry(Descriptor.toJvmName(call.getClassName())), new Signature(call.getSignature())); | ||
| 83 | } | ||
| 84 | |||
| 85 | public static BehaviorEntry getBehaviorEntry(CtBehavior behavior) { | ||
| 86 | if (behavior instanceof CtMethod) { | ||
| 87 | return getMethodEntry((CtMethod) behavior); | ||
| 88 | } else if (behavior instanceof CtConstructor) { | ||
| 89 | return getConstructorEntry((CtConstructor) behavior); | ||
| 90 | } | ||
| 91 | throw new Error("behavior is neither Method nor Constructor!"); | ||
| 92 | } | ||
| 93 | |||
| 94 | public static BehaviorEntry getBehaviorEntry(String className, String behaviorName, String behaviorSignature) { | ||
| 95 | return getBehaviorEntry(new ClassEntry(className), behaviorName, new Signature(behaviorSignature)); | ||
| 96 | } | ||
| 97 | |||
| 98 | public static BehaviorEntry getBehaviorEntry(String className, String behaviorName) { | ||
| 99 | return getBehaviorEntry(new ClassEntry(className), behaviorName); | ||
| 100 | } | ||
| 101 | |||
| 102 | public static BehaviorEntry getBehaviorEntry(String className) { | ||
| 103 | return new ConstructorEntry(new ClassEntry(className)); | ||
| 104 | } | ||
| 105 | |||
| 106 | public static BehaviorEntry getBehaviorEntry(ClassEntry classEntry, String behaviorName, Signature behaviorSignature) { | ||
| 107 | switch (behaviorName) { | ||
| 108 | case "<init>": | ||
| 109 | return new ConstructorEntry(classEntry, behaviorSignature); | ||
| 110 | case "<clinit>": | ||
| 111 | return new ConstructorEntry(classEntry); | ||
| 112 | default: | ||
| 113 | return new MethodEntry(classEntry, behaviorName, behaviorSignature); | ||
| 114 | } | ||
| 115 | } | 32 | } |
| 116 | 33 | ||
| 117 | public static BehaviorEntry getBehaviorEntry(ClassEntry classEntry, String behaviorName) { | 34 | public static MethodEntry getMethodEntry(ClassEntry classEntry, String name, MethodDescriptor desc) { |
| 118 | if (behaviorName.equals("<clinit>")) { | 35 | return new MethodEntry(classEntry, name, desc); |
| 119 | return new ConstructorEntry(classEntry); | ||
| 120 | } else { | ||
| 121 | throw new IllegalArgumentException("Only class initializers don't have signatures"); | ||
| 122 | } | ||
| 123 | } | 36 | } |
| 124 | 37 | ||
| 125 | public static BehaviorEntry getObfBehaviorEntry(ClassEntry classEntry, MethodMapping methodMapping) { | 38 | public static MethodEntry getObfMethodEntry(ClassEntry classEntry, MethodMapping methodMapping) { |
| 126 | return getBehaviorEntry(classEntry, methodMapping.getObfName(), methodMapping.getObfSignature()); | 39 | return getMethodEntry(classEntry, methodMapping.getObfName(), methodMapping.getObfDesc()); |
| 127 | } | 40 | } |
| 128 | 41 | ||
| 129 | public static BehaviorEntry getObfBehaviorEntry(ClassMapping classMapping, MethodMapping methodMapping) { | 42 | public static MethodEntry getObfMethodEntry(ClassMapping classMapping, MethodMapping methodMapping) { |
| 130 | return getObfBehaviorEntry(getObfClassEntry(classMapping), methodMapping); | 43 | return getObfMethodEntry(getObfClassEntry(classMapping), methodMapping); |
| 131 | } | 44 | } |
| 132 | } | 45 | } |