2222import org .apache .commons .lang3 .ArrayUtils ;
2323import org .jetbrains .java .decompiler .main .decompiler .ConsoleDecompiler ;
2424import org .objectweb .asm .tree .ClassNode ;
25+ import org .objectweb .asm .tree .InnerClassNode ;
2526import the .bytecode .club .bytecodeviewer .BytecodeViewer ;
2627import the .bytecode .club .bytecodeviewer .Constants ;
28+ import the .bytecode .club .bytecodeviewer .api .ASMUtil ;
2729import the .bytecode .club .bytecodeviewer .api .ExceptionUI ;
2830import the .bytecode .club .bytecodeviewer .decompilers .AbstractDecompiler ;
2931import the .bytecode .club .bytecodeviewer .resources .ExternalResources ;
32+ import the .bytecode .club .bytecodeviewer .resources .ResourceContainer ;
3033import the .bytecode .club .bytecodeviewer .translation .TranslatedStrings ;
3134import the .bytecode .club .bytecodeviewer .util .ExceptionUtils ;
3235import the .bytecode .club .bytecodeviewer .util .ProcessUtils ;
3336import the .bytecode .club .bytecodeviewer .util .TempFile ;
3437
3538import java .io .*;
39+ import java .util .ArrayList ;
40+ import java .util .List ;
41+ import java .util .concurrent .atomic .AtomicReference ;
3642
3743import static the .bytecode .club .bytecodeviewer .Constants .*;
3844import static the .bytecode .club .bytecodeviewer .translation .TranslatedStrings .*;
@@ -51,12 +57,61 @@ public FernFlowerDecompiler()
5157 super ("FernFlower Decompiler" , "fernflower" );
5258 }
5359
60+ private String [] inners ;
61+ private final List <File > innerFiles = new ArrayList <>();
5462 @ Override
5563 public String decompileClassNode (ClassNode cn , byte [] bytes )
5664 {
5765 TempFile tempFile = null ;
5866 String exception ;
5967
68+ List <InnerClassNode > innerClasses = cn .innerClasses ;
69+ List <TempFile > innerTempFiles = new ArrayList <>();
70+ AtomicReference <TempFile > innerTempFile = new AtomicReference <>();
71+ if (BytecodeViewer .viewer .din .isSelected ())
72+ {
73+ inners = new String [innerClasses .size ()];
74+ for (int i = 0 ; i < innerClasses .size (); i ++)
75+ {
76+ if (innerClasses .get (i ).outerName != null && innerClasses .get (i ).outerName .equals (cn .name ))
77+ {
78+ inners [i ] = innerClasses .get (i ).name ;
79+ }
80+ else if (innerClasses .get (i ).outerName == null )
81+ {
82+ String name = innerClasses .get (i ).name ;
83+ name = name .substring (name .lastIndexOf ('/' ) + 1 );
84+ if (name .contains (cn .name .substring (cn .name .lastIndexOf ('/' ) + 1 )))
85+ {
86+ inners [i ] = innerClasses .get (i ).name ;
87+ }
88+ }
89+ }
90+
91+ for (ResourceContainer container :BytecodeViewer .resourceContainers .values ()) {
92+ container .resourceClasses .forEach ((s , classNode ) -> {
93+ for (String innerClassName : inners ) {
94+ if (s .equals (innerClassName )) {
95+ innerTempFile .set (TempFile .createTemporaryFile (true , ".class" ));
96+ File tempInputClassFile2 = innerTempFile .get ().getFile ();
97+ try (FileOutputStream fos = new FileOutputStream (tempInputClassFile2 )) {
98+ fos .write (ASMUtil .nodeToBytes (classNode ));
99+ }
100+ catch (IOException e )
101+ {
102+ throw new RuntimeException (e );
103+ } finally
104+ {
105+ innerFiles .add (tempInputClassFile2 );
106+ innerTempFile .get ().markAsCreatedFile (tempInputClassFile2 );
107+ innerTempFiles .add (innerTempFile .get ());
108+ }
109+ }
110+ }
111+ });
112+ }
113+ }
114+
60115 try
61116 {
62117 //create the temporary files
@@ -80,12 +135,17 @@ public String decompileClassNode(ClassNode cn, byte[] bytes)
80135 {
81136 ExternalResources .getSingleton ().getJavaCommand (true ),
82137 "-jar" , ExternalResources .getSingleton ().findLibrary ("fernflower" )
83- }, generateMainMethod (tempInputClassFile .getAbsolutePath (), tempFile .getParent ().getAbsolutePath ())
138+ }, generateMainMethod (tempInputClassFile .getAbsolutePath (), "" , tempFile .getParent ().getAbsolutePath ())
84139 ), false );
85140 }
86141 else
87142 {
88- org .jetbrains .java .decompiler .main .decompiler .ConsoleDecompiler .main (generateMainMethod (tempInputClassFile .getAbsolutePath (), new File (TEMP_DIRECTORY ).getAbsolutePath ()));
143+ List <String > strings = generate (tempInputClassFile .getAbsolutePath (),
144+ new File (TEMP_DIRECTORY ).getAbsolutePath ());
145+
146+ String [] args = strings .toArray (new String [0 ]);
147+
148+ org .jetbrains .java .decompiler .main .decompiler .ConsoleDecompiler .main (args );
89149 }
90150
91151 //if rename is enabled the file name will be the actual class name
@@ -112,6 +172,21 @@ public String decompileClassNode(ClassNode cn, byte[] bytes)
112172 //cleanup temp files
113173 if (tempFile != null )
114174 tempFile .cleanup ();
175+
176+ if (innerTempFile .get () != null )
177+ innerTempFile .get ().cleanup ();
178+
179+ for (TempFile file : innerTempFiles )
180+ {
181+ file .cleanup ();
182+ File file1 = new File (TEMP_DIRECTORY + file .getUniqueName () + ".java" );
183+ if (file1 .exists ())
184+ {
185+ file1 .delete ();
186+ }
187+ }
188+
189+ innerFiles .clear ();
115190 }
116191
117192 return FERNFLOWER + " " + ERROR + "! " + ExceptionUI .SEND_STACKTRACE_TO + NL + NL
@@ -127,7 +202,7 @@ public void decompileToZip(String sourceJar, String zipName)
127202
128203 try
129204 {
130- ConsoleDecompiler .main (generateMainMethod (tempInputJarFile .getAbsolutePath (), TEMP_DIRECTORY + "./temp/" ));
205+ ConsoleDecompiler .main (generateMainMethod (tempInputJarFile .getAbsolutePath (), "" , TEMP_DIRECTORY + "./temp/" ));
131206 }
132207 catch (StackOverflowError | Exception ignored )
133208 {
@@ -140,7 +215,40 @@ public void decompileToZip(String sourceJar, String zipName)
140215
141216 }
142217
143- private String [] generateMainMethod (String className , String folder )
218+ private List <String > generate (String className , String folder )
219+ {
220+ List <String > strings = new ArrayList <>();
221+ strings .add ("-rbr=" + ffOnValue (BytecodeViewer .viewer .rbr .isSelected ()));
222+ strings .add ("-rsy=" + ffOnValue (BytecodeViewer .viewer .rsy .isSelected ()));
223+ strings .add ("-din=" + ffOnValue (BytecodeViewer .viewer .din .isSelected ()));
224+ strings .add ("-dc4=" + ffOnValue (BytecodeViewer .viewer .dc4 .isSelected ()));
225+ strings .add ("-das=" + ffOnValue (BytecodeViewer .viewer .das .isSelected ()));
226+ strings .add ("-hes=" + ffOnValue (BytecodeViewer .viewer .hes .isSelected ()));
227+ strings .add ("-hdc=" + ffOnValue (BytecodeViewer .viewer .hdc .isSelected ()));
228+ strings .add ("-dgs=" + ffOnValue (BytecodeViewer .viewer .dgs .isSelected ()));
229+ strings .add ("-ner=" + ffOnValue (BytecodeViewer .viewer .ner .isSelected ()));
230+ strings .add ("-den=" + ffOnValue (BytecodeViewer .viewer .den .isSelected ()));
231+ strings .add ("-rgn=" + ffOnValue (BytecodeViewer .viewer .rgn .isSelected ()));
232+ strings .add ("-bto=" + ffOnValue (BytecodeViewer .viewer .bto .isSelected ()));
233+ strings .add ("-nns=" + ffOnValue (BytecodeViewer .viewer .nns .isSelected ()));
234+ strings .add ("-uto=" + ffOnValue (BytecodeViewer .viewer .uto .isSelected ()));
235+ strings .add ("-udv=" + ffOnValue (BytecodeViewer .viewer .udv .isSelected ()));
236+ strings .add ("-rer=" + ffOnValue (BytecodeViewer .viewer .rer .isSelected ()));
237+ strings .add ("-fdi=" + ffOnValue (BytecodeViewer .viewer .fdi .isSelected ()));
238+ strings .add ("-asc=" + ffOnValue (BytecodeViewer .viewer .asc .isSelected ()));
239+ strings .add ("-ren=" + ffOnValue (BytecodeViewer .viewer .ren .isSelected ()));
240+ strings .add (className );
241+ if (BytecodeViewer .viewer .din .isSelected ())
242+ {
243+ for (File file : innerFiles )
244+ strings .add (file .getAbsolutePath ());
245+ }
246+
247+ strings .add (folder );
248+ return strings ;
249+ }
250+
251+ private String [] generateMainMethod (String className , String test , String folder )
144252 {
145253 return new String []
146254 {
@@ -163,7 +271,7 @@ private String[] generateMainMethod(String className, String folder)
163271 "-fdi=" + ffOnValue (BytecodeViewer .viewer .fdi .isSelected ()),
164272 "-asc=" + ffOnValue (BytecodeViewer .viewer .asc .isSelected ()),
165273 "-ren=" + ffOnValue (BytecodeViewer .viewer .ren .isSelected ()),
166- className , folder
274+ className , test , folder
167275 };
168276 }
169277
0 commit comments