1616
1717package com .javadeobfuscator .deobfuscator ;
1818
19+ import com .javadeobfuscator .deobfuscator .asm .ConstantPool ;
1920import com .javadeobfuscator .deobfuscator .config .Configuration ;
2021import com .javadeobfuscator .deobfuscator .config .TransformerConfig ;
2122import com .javadeobfuscator .deobfuscator .exceptions .NoClassInPathException ;
2223import com .javadeobfuscator .deobfuscator .transformers .Transformer ;
2324import com .javadeobfuscator .deobfuscator .utils .ClassTree ;
2425import com .javadeobfuscator .deobfuscator .utils .Utils ;
25- import com .javadeobfuscator .deobfuscator .utils .WrappedClassNode ;
2626import org .apache .commons .io .IOUtils ;
2727import org .objectweb .asm .ClassReader ;
2828import org .objectweb .asm .ClassWriter ;
5252import java .util .zip .ZipOutputStream ;
5353
5454public class Deobfuscator {
55- private Map <String , WrappedClassNode > classpath = new HashMap <>();
56- private Map <String , WrappedClassNode > classes = new HashMap <>();
55+ private Map <String , ClassNode > classpath = new HashMap <>();
56+ private Map <String , ClassNode > classes = new HashMap <>();
5757 private Map <String , ClassTree > hierachy = new HashMap <>();
5858 private Set <ClassNode > libraryClassnodes = new HashSet <>();
5959
6060 // Entries from the input jar that will be passed through to the output
6161 private Map <String , byte []> inputPassthrough = new HashMap <>();
6262
63+ // Constant pool data since ClassNodes don't support custom data
64+ private Map <ClassNode , ConstantPool > constantPools = new HashMap <>();
65+
6366 private final Configuration configuration ;
6467 private final Logger logger = LoggerFactory .getLogger (Deobfuscator .class );
6568
@@ -74,8 +77,20 @@ public Deobfuscator(Configuration configuration) {
7477 */
7578 private static final boolean DELETE_USELESS_CLASSES = false ;
7679
77- private Map <String , WrappedClassNode > loadClasspathFile (File file ) throws IOException {
78- Map <String , WrappedClassNode > map = new HashMap <>();
80+ public ConstantPool getConstantPool (ClassNode classNode ) {
81+ return this .constantPools .get (classNode );
82+ }
83+
84+ public void setConstantPool (ClassNode owner , ConstantPool pool ) {
85+ this .constantPools .put (owner , pool );
86+ }
87+
88+ public Map <ClassNode , ConstantPool > getConstantPools () {
89+ return this .constantPools ;
90+ }
91+
92+ private Map <String , ClassNode > loadClasspathFile (File file ) throws IOException {
93+ Map <String , ClassNode > map = new HashMap <>();
7994
8095 ZipFile zipIn = new ZipFile (file );
8196 Enumeration <? extends ZipEntry > entries = zipIn .entries ();
@@ -85,8 +100,9 @@ private Map<String, WrappedClassNode> loadClasspathFile(File file) throws IOExce
85100 ClassReader reader = new ClassReader (zipIn .getInputStream (ent ));
86101 ClassNode node = new ClassNode ();
87102 reader .accept (node , ClassReader .SKIP_CODE | ClassReader .SKIP_DEBUG | ClassReader .SKIP_FRAMES );
88- WrappedClassNode wrappedClassNode = new WrappedClassNode (node , reader .getItemCount ());
89- map .put (node .name , wrappedClassNode );
103+ map .put (node .name , node );
104+
105+ setConstantPool (node , new ConstantPool (reader ));
90106 }
91107 }
92108 zipIn .close ();
@@ -108,7 +124,7 @@ private void loadClasspath() throws IOException {
108124 }
109125 }
110126 }
111- libraryClassnodes .addAll (classpath .values (). stream (). map ( WrappedClassNode :: getClassNode ). collect ( Collectors . toList ()) );
127+ libraryClassnodes .addAll (classpath .values ());
112128 }
113129 }
114130
@@ -152,6 +168,8 @@ private void loadInput() throws IOException {
152168 ClassNode node = new ClassNode ();
153169 reader .accept (node , ClassReader .SKIP_FRAMES );
154170
171+ setConstantPool (node , new ConstantPool (reader ));
172+
155173 if (!isClassIgnored (node )) {
156174 for (int i = 0 ; i < node .methods .size (); i ++) {
157175 MethodNode methodNode = node .methods .get (i );
@@ -160,11 +178,10 @@ private void loadInput() throws IOException {
160178 node .methods .set (i , adapter );
161179 }
162180
163- WrappedClassNode wr = new WrappedClassNode (node , reader .getItemCount ());
164- classes .put (node .name , wr );
181+ classes .put (node .name , node );
165182 passthrough = false ;
166183 } else {
167- classpath .put (node .name , new WrappedClassNode ( node , reader . getItemCount ()) );
184+ classpath .put (node .name , node );
168185 }
169186 } catch (IllegalArgumentException x ) {
170187 logger .error ("Could not parse {} (is it a class file?)" , next .getName (), x );
@@ -185,18 +202,18 @@ private void loadInput() throws IOException {
185202 */
186203 @ Deprecated
187204 private void computeCallers () {
188- Map <MethodNode , List <Entry <WrappedClassNode , MethodNode >>> callers = new HashMap <>();
189- classes .values ().forEach (wrappedClassNode -> {
190- wrappedClassNode . classNode .methods .forEach (methodNode -> {
205+ Map <MethodNode , List <Entry <ClassNode , MethodNode >>> callers = new HashMap <>();
206+ classes .values ().forEach (classNode -> {
207+ classNode .methods .forEach (methodNode -> {
191208 for (int i = 0 ; i < methodNode .instructions .size (); i ++) {
192209 AbstractInsnNode node = methodNode .instructions .get (i );
193210 if (node instanceof MethodInsnNode ) {
194211 MethodInsnNode mn = (MethodInsnNode ) node ;
195- WrappedClassNode targetNode = classes .get (mn .owner );
212+ ClassNode targetNode = classes .get (mn .owner );
196213 if (targetNode != null ) {
197- MethodNode targetMethod = targetNode .classNode . methods .stream ().filter (m -> m .name .equals (mn .name ) && m .desc .equals (mn .desc )).findFirst ().orElse (null );
214+ MethodNode targetMethod = targetNode .methods .stream ().filter (m -> m .name .equals (mn .name ) && m .desc .equals (mn .desc )).findFirst ().orElse (null );
198215 if (targetMethod != null ) {
199- callers .computeIfAbsent (targetMethod , k -> new ArrayList <>()).add (new SimpleEntry <>(wrappedClassNode , methodNode ));
216+ callers .computeIfAbsent (targetMethod , k -> new ArrayList <>()).add (new SimpleEntry <>(classNode , methodNode ));
200217 }
201218 }
202219 }
@@ -229,7 +246,7 @@ public void start() throws Throwable {
229246
230247 logger .info ("Writing" );
231248 if (DEBUG ) {
232- classes .values ().stream (). map ( wrappedClassNode -> wrappedClassNode . classNode ). forEach (Utils ::printClass );
249+ classes .values ().forEach (Utils ::printClass );
233250 }
234251
235252 ZipOutputStream zipOut = new ZipOutputStream (new FileOutputStream (configuration .getOutput ()));
@@ -244,7 +261,7 @@ public void start() throws Throwable {
244261 }
245262 });
246263
247- classes .values ().stream (). map ( wrappedClassNode -> wrappedClassNode . classNode ). forEach (classNode -> {
264+ classes .values ().forEach (classNode -> {
248265 try {
249266 byte [] b = toByteArray (classNode );
250267 if (b != null ) {
@@ -267,27 +284,27 @@ public boolean runFromConfig(TransformerConfig config) throws Throwable {
267284 }
268285
269286 public ClassNode assureLoaded (String ref ) {
270- WrappedClassNode clazz = classpath .get (ref );
287+ ClassNode clazz = classpath .get (ref );
271288 if (clazz == null ) {
272289 throw new NoClassInPathException (ref );
273290 }
274- return clazz . classNode ;
291+ return clazz ;
275292 }
276293
277294 public ClassNode assureLoadedElseRemove (String referencer , String ref ) {
278- WrappedClassNode clazz = classpath .get (ref );
295+ ClassNode clazz = classpath .get (ref );
279296 if (clazz == null ) {
280297 classes .remove (referencer );
281298 classpath .remove (referencer );
282299 return null ;
283300 }
284- return clazz . classNode ;
301+ return clazz ;
285302 }
286303
287304 public void loadHierachy () {
288305 Set <String > processed = new HashSet <>();
289306 LinkedList <ClassNode > toLoad = new LinkedList <>();
290- toLoad .addAll (this .classes .values (). stream (). map ( wrappedClassNode -> wrappedClassNode . classNode ). collect ( Collectors . toList ()) );
307+ toLoad .addAll (this .classes .values ());
291308 while (!toLoad .isEmpty ()) {
292309 for (ClassNode toProcess : loadHierachy (toLoad .poll ())) {
293310 if (processed .add (toProcess .name )) {
0 commit comments