11package me .coley .recaf .workspace ;
22
3+ import me .coley .cafedude .InvalidClassException ;
4+ import me .coley .cafedude .io .ClassFileReader ;
35import me .coley .recaf .plugin .PluginsManager ;
46import me .coley .recaf .plugin .api .LoadInterceptorPlugin ;
57import me .coley .recaf .util .ClassUtil ;
@@ -24,6 +26,7 @@ public class EntryLoader {
2426 private final Map <String , byte []> classes = new HashMap <>();
2527 private final Map <String , byte []> files = new HashMap <>();
2628 private final Map <String , byte []> invalidClasses = new HashMap <>();
29+ private final Map <String , byte []> invalidJunkClasses = new HashMap <>();
2730
2831 /**
2932 * @return New archive entry loader instance.
@@ -52,14 +55,32 @@ public static EntryLoader create() {
5255 public boolean onClass (String entryName , byte [] value ) {
5356 // Check if class is valid. If it is not it will be stored for later.
5457 if (!ClassUtil .isValidClass (value )) {
55- if (invalidClasses .containsKey (entryName )) {
56- debug ("Skipping duplicate invalid class '{}'" , entryName );
58+ try {
59+ // If the data can be read, overwrite whatever entry we have previously seen
60+ new ClassFileReader ().read (value );
61+ invalidClasses .put (entryName , value );
62+ if (invalidJunkClasses .remove (entryName ) != null ) {
63+ debug ("Replacing class '{}' previously associated with non-class junk with" +
64+ " newly discovered class data" , entryName );
65+ }
66+ return false ;
67+ } catch (InvalidClassException e ) {
68+ // Skip if we think this is junk data that is masking an invalid class we already recovered
69+ if (invalidClasses .containsKey (entryName )) {
70+ debug ("Skipping masking junk data for class '{}'" , entryName );
71+ return false ;
72+ }
73+ // Doesnt look like the CAFEDOOD backup parser can read it either.
74+ if (invalidJunkClasses .containsKey (entryName )) {
75+ // Already seen it. Probably dupe junk data.
76+ debug ("Skipping duplicate invalid class '{}'" , entryName );
77+ return false ;
78+ } else {
79+ debug ("Invalid class detected, not parsable by backup reader \" {}\" " , entryName );
80+ }
81+ invalidJunkClasses .put (entryName , value );
5782 return false ;
58- } else {
59- debug ("Invalid class detected \" {}\" " , entryName );
6083 }
61- invalidClasses .put (entryName , value );
62- return false ;
6384 }
6485 // Check if we've already seen this class
6586 String clsName = new ClassReader (value ).getClassName ();
0 commit comments