|
6 | 6 | import java.util.ArrayList; |
7 | 7 | import java.util.Enumeration; |
8 | 8 | import java.util.List; |
| 9 | +import java.util.Objects; |
9 | 10 | import java.util.jar.JarEntry; |
10 | 11 | import java.util.jar.JarFile; |
11 | 12 | import javax.swing.JFrame; |
| 13 | + |
| 14 | +import org.objectweb.asm.ClassWriter; |
12 | 15 | import org.objectweb.asm.tree.ClassNode; |
| 16 | +import the.bytecode.club.bytecodeviewer.BytecodeViewer; |
13 | 17 | import the.bytecode.club.bytecodeviewer.compilers.Compiler; |
14 | 18 | import the.bytecode.club.bytecodeviewer.compilers.InternalCompiler; |
15 | 19 | import the.bytecode.club.bytecodeviewer.decompilers.Decompiler; |
@@ -176,6 +180,41 @@ public static void openFiles(File[] files, boolean recentFiles) { |
176 | 180 | public static ClassNode getCurrentlyOpenedClassNode() { |
177 | 181 | return the.bytecode.club.bytecodeviewer.BytecodeViewer.getCurrentlyOpenedClassNode(); |
178 | 182 | } |
| 183 | + |
| 184 | + /** |
| 185 | + * Returns the currently opened class nodes ClassFile bytes |
| 186 | + * |
| 187 | + * @return The ClassFile bytes for the actively opened resource |
| 188 | + */ |
| 189 | + public static byte[] getCurrentlyOpenedClassNodeBytes() |
| 190 | + { |
| 191 | + final ClassNode cn = BytecodeViewer.getCurrentlyOpenedClassNode(); |
| 192 | + final ClassWriter cw = new ClassWriter(0); |
| 193 | + |
| 194 | + try { |
| 195 | + Objects.requireNonNull(cn).accept(cw); |
| 196 | + } catch (Exception e) { |
| 197 | + e.printStackTrace(); |
| 198 | + try { |
| 199 | + Thread.sleep(200); |
| 200 | + Objects.requireNonNull(cn).accept(cw); |
| 201 | + } catch (InterruptedException ignored) { |
| 202 | + } |
| 203 | + } |
| 204 | + |
| 205 | + return cw.toByteArray(); |
| 206 | + } |
| 207 | + |
| 208 | + /** |
| 209 | + * This decompiles the actively opened ClassFile inside of BCV. |
| 210 | + * |
| 211 | + * @param decompiler The decompiler you would like to use |
| 212 | + * @return The Ascii/text representation of the class node from the decompiler provided |
| 213 | + */ |
| 214 | + public static String decompileCurrentlyOpenedClassNode(Decompiler decompiler) |
| 215 | + { |
| 216 | + return decompiler.getDecompiler().decompileClassNode(BCV.getCurrentlyOpenedClassNode(), BCV.getCurrentlyOpenedClassNodeBytes()); |
| 217 | + } |
179 | 218 |
|
180 | 219 | /** |
181 | 220 | * Used to load a ClassNode. |
|
0 commit comments