1313import java .util .ArrayList ;
1414import java .util .Collection ;
1515import java .util .HashSet ;
16+ import java .util .Iterator ;
1617import java .util .Map ;
1718import java .util .Set ;
19+ import java .util .zip .ZipFile ;
1820
1921import net .md_5 .specialsource .AccessMap ;
2022import net .md_5 .specialsource .Jar ;
@@ -291,6 +293,10 @@ public Object getResult()
291293 }
292294 });
293295 }
296+
297+ // Remove unknown classes from configuration
298+ removeUnknownClasses (inJar , struct );
299+
294300 File jsonTmp = new File (this .getTemporaryDir (), "transformed.json" );
295301 json = jsonTmp .getCanonicalPath ();
296302 Files .write (JsonFactory .GSON .toJson (struct ).getBytes (), jsonTmp );
@@ -314,6 +320,49 @@ public Object getResult()
314320 true );
315321 }
316322
323+ private void removeUnknownClasses (File inJar , Map <String , MCInjectorStruct > config ) throws IOException
324+ {
325+ ZipFile zip = new ZipFile (inJar );
326+ try
327+ {
328+ Iterator <Map .Entry <String , MCInjectorStruct >> entries = config .entrySet ().iterator ();
329+ while (entries .hasNext ())
330+ {
331+ Map .Entry <String , MCInjectorStruct > entry = entries .next ();
332+ String className = entry .getKey ();
333+
334+ // Verify the configuration contains only classes we actually have
335+ if (zip .getEntry (className + ".class" ) == null )
336+ {
337+ getLogger ().info ("Removing unknown class {}" , className );
338+ entries .remove ();
339+ continue ;
340+ }
341+
342+ MCInjectorStruct struct = entry .getValue ();
343+
344+ // Verify the inner classes in the configuration actually exist in our deobfuscated JAR file
345+ if (struct .innerClasses != null )
346+ {
347+ Iterator <InnerClass > innerClasses = struct .innerClasses .iterator ();
348+ while (innerClasses .hasNext ())
349+ {
350+ InnerClass innerClass = innerClasses .next ();
351+ if (zip .getEntry (innerClass .inner_class + ".class" ) == null )
352+ {
353+ getLogger ().info ("Removing unknown inner class {} from {}" , innerClass .inner_class , className );
354+ innerClasses .remove ();
355+ }
356+ }
357+ }
358+ }
359+ }
360+ finally
361+ {
362+ zip .close ();
363+ }
364+ }
365+
317366 public File getExceptorCfg ()
318367 {
319368 return getProject ().file (exceptorCfg );
0 commit comments