1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
package cuchaz.enigma.mapping;
import javassist.CtBehavior;
import javassist.CtClass;
import javassist.CtConstructor;
import javassist.CtField;
import javassist.CtMethod;
import javassist.bytecode.Descriptor;
import javassist.expr.ConstructorCall;
import javassist.expr.FieldAccess;
import javassist.expr.MethodCall;
import javassist.expr.NewExpr;
import com.strobel.assembler.metadata.FieldDefinition;
import com.strobel.assembler.metadata.MethodDefinition;
import cuchaz.enigma.analysis.JarIndex;
public class EntryFactory {
public static ClassEntry getClassEntry(CtClass c) {
return new ClassEntry(Descriptor.toJvmName(c.getName()));
}
public static ClassEntry getObfClassEntry(JarIndex jarIndex, ClassMapping classMapping) {
ClassEntry obfClassEntry = new ClassEntry(classMapping.getObfFullName());
return obfClassEntry.buildClassEntry(jarIndex.getObfClassChain(obfClassEntry));
}
private static ClassEntry getObfClassEntry(ClassMapping classMapping) {
return new ClassEntry(classMapping.getObfFullName());
}
public static ClassEntry getDeobfClassEntry(ClassMapping classMapping) {
return new ClassEntry(classMapping.getDeobfName());
}
public static ClassEntry getSuperclassEntry(CtClass c) {
return new ClassEntry(Descriptor.toJvmName(c.getClassFile().getSuperclass()));
}
public static FieldEntry getFieldEntry(CtField field) {
return new FieldEntry(
getClassEntry(field.getDeclaringClass()),
field.getName(),
new Type(field.getFieldInfo().getDescriptor())
);
}
public static FieldEntry getFieldEntry(FieldAccess call) {
return new FieldEntry(
new ClassEntry(Descriptor.toJvmName(call.getClassName())),
call.getFieldName(),
new Type(call.getSignature())
);
}
public static FieldEntry getFieldEntry(FieldDefinition def) {
return new FieldEntry(
new ClassEntry(def.getDeclaringType().getInternalName()),
def.getName(),
new Type(def.getErasedSignature())
);
}
public static FieldEntry getFieldEntry(String className, String name, String type) {
return new FieldEntry(new ClassEntry(className), name, new Type(type));
}
public static FieldEntry getObfFieldEntry(ClassMapping classMapping, FieldMapping fieldMapping) {
return new FieldEntry(
getObfClassEntry(classMapping),
fieldMapping.getObfName(),
fieldMapping.getObfType()
);
}
public static MethodEntry getMethodEntry(CtMethod method) {
return new MethodEntry(
getClassEntry(method.getDeclaringClass()),
method.getName(),
new Signature(method.getMethodInfo().getDescriptor())
);
}
public static MethodEntry getMethodEntry(MethodCall call) {
return new MethodEntry(
new ClassEntry(Descriptor.toJvmName(call.getClassName())),
call.getMethodName(),
new Signature(call.getSignature())
);
}
public static MethodEntry getMethodEntry(MethodDefinition def) {
return new MethodEntry(
new ClassEntry(def.getDeclaringType().getInternalName()),
def.getName(),
new Signature(def.getErasedSignature())
);
}
public static ConstructorEntry getConstructorEntry(CtConstructor constructor) {
if (constructor.isClassInitializer()) {
return new ConstructorEntry(
getClassEntry(constructor.getDeclaringClass())
);
} else {
return new ConstructorEntry(
getClassEntry(constructor.getDeclaringClass()),
new Signature(constructor.getMethodInfo().getDescriptor())
);
}
}
public static ConstructorEntry getConstructorEntry(ConstructorCall call) {
return new ConstructorEntry(
new ClassEntry(Descriptor.toJvmName(call.getClassName())),
new Signature(call.getSignature())
);
}
public static ConstructorEntry getConstructorEntry(NewExpr call) {
return new ConstructorEntry(
new ClassEntry(Descriptor.toJvmName(call.getClassName())),
new Signature(call.getSignature())
);
}
public static ConstructorEntry getConstructorEntry(MethodDefinition def) {
if (def.isTypeInitializer()) {
return new ConstructorEntry(
new ClassEntry(def.getDeclaringType().getInternalName())
);
} else {
return new ConstructorEntry(
new ClassEntry(def.getDeclaringType().getInternalName()),
new Signature(def.getErasedSignature())
);
}
}
public static BehaviorEntry getBehaviorEntry(CtBehavior behavior) {
if (behavior instanceof CtMethod) {
return getMethodEntry((CtMethod)behavior);
} else if (behavior instanceof CtConstructor) {
return getConstructorEntry((CtConstructor)behavior);
}
throw new Error("behavior is neither Method nor Constructor!");
}
public static BehaviorEntry getBehaviorEntry(String className, String behaviorName, String behaviorSignature) {
return getBehaviorEntry(new ClassEntry(className), behaviorName, new Signature(behaviorSignature));
}
public static BehaviorEntry getBehaviorEntry(String className, String behaviorName) {
return getBehaviorEntry(new ClassEntry(className), behaviorName);
}
public static BehaviorEntry getBehaviorEntry(String className) {
return new ConstructorEntry(new ClassEntry(className));
}
public static BehaviorEntry getBehaviorEntry(ClassEntry classEntry, String behaviorName, Signature behaviorSignature) {
if (behaviorName.equals("<init>")) {
return new ConstructorEntry(classEntry, behaviorSignature);
} else if(behaviorName.equals("<clinit>")) {
return new ConstructorEntry(classEntry);
} else {
return new MethodEntry(classEntry, behaviorName, behaviorSignature);
}
}
public static BehaviorEntry getBehaviorEntry(ClassEntry classEntry, String behaviorName) {
if(behaviorName.equals("<clinit>")) {
return new ConstructorEntry(classEntry);
} else {
throw new IllegalArgumentException("Only class initializers don't have signatures");
}
}
public static BehaviorEntry getBehaviorEntry(MethodDefinition def) {
if (def.isConstructor() || def.isTypeInitializer()) {
return getConstructorEntry(def);
} else {
return getMethodEntry(def);
}
}
public static BehaviorEntry getObfBehaviorEntry(ClassEntry classEntry, MethodMapping methodMapping) {
return getBehaviorEntry(classEntry, methodMapping.getObfName(), methodMapping.getObfSignature());
}
public static BehaviorEntry getObfBehaviorEntry(ClassMapping classMapping, MethodMapping methodMapping) {
return getObfBehaviorEntry(getObfClassEntry(classMapping), methodMapping);
}
}
|