From a12f1aa503fefb6ac2e2570abcfc4e56b473d33d Mon Sep 17 00:00:00 2001 From: Konloch Date: Sun, 27 Jun 2021 14:41:58 -0700 Subject: [PATCH] Plugin Code Cleanup --- plugins/example/ExampleStringDecrypter.gy | 42 +++++++------- .../preinstalled/ZStringArrayDecrypter.java | 55 ++++++++++--------- 2 files changed, 49 insertions(+), 48 deletions(-) diff --git a/plugins/example/ExampleStringDecrypter.gy b/plugins/example/ExampleStringDecrypter.gy index 8862658d..2c260f01 100644 --- a/plugins/example/ExampleStringDecrypter.gy +++ b/plugins/example/ExampleStringDecrypter.gy @@ -1,10 +1,12 @@ -import the.bytecode.club.bytecodeviewer.api.*; +import the.bytecode.club.bytecodeviewer.api.* +import the.bytecode.club.bytecodeviewer.gui.components.MultipleChoiceDialogue; + import java.util.ArrayList; -import org.objectweb.asm.tree.ClassNode; -import javax.swing.JDialog; -import javax.swing.JOptionPane; import java.lang.reflect.Field; -import org.objectweb.asm.tree.FieldNode; +import org.objectweb.asm.tree.ClassNode; +import org.objectweb.asm.tree.FieldNode + +import static the.bytecode.club.bytecodeviewer.Constants.nl; /** * This is an example of a string decrypter plugin @@ -15,27 +17,25 @@ public class ExampleStringDecrypter extends Plugin { public void execute(ArrayList classNodesList) { PluginConsole gui = new PluginConsole("Example String Decrypter"); - JOptionPane pane = new JOptionPane("WARNING: This method of decryption loads the classes into a classloader and executes the init function, this could lead to malicious code executing.\n\r\n\rAre you sure you want to run this plugin?"); - String[] options = ["Yes", "No"]; - pane.setOptions(options); - JDialog dialog = pane.createDialog(the.bytecode.club.bytecodeviewer.BytecodeViewer.viewer, "WARNING"); - dialog.show(); - Object obj = pane.getValue(); - int result = -1; - for (int k = 0; k < options.length; k++) - if (options[k].equals(obj)) - result = k; + MultipleChoiceDialogue dialogue = new MultipleChoiceDialogue("Bytecode Viewer - WARNING", + "WARNING: This will load the classes into the JVM and execute the initialize function" + + nl + "for each class. IF THE FILE YOU'RE LOADING IS MALICIOUS, DO NOT CONTINUE.", + new String[]{"Continue", "Cancel"}); - - if(result == 0) { - for(ClassNode cn : classNodesList) { + if(dialogue.promptChoice() == 0) + { + for(ClassNode cn : classNodesList) + { the.bytecode.club.bytecodeviewer.api.BytecodeViewer.getClassNodeLoader().addClass(cn); - for(Object o : cn.fields.toArray()) { + for(Object o : cn.fields.toArray()) + { FieldNode f = (FieldNode) o; if(f.name.equals("z")) {// && f.desc.equals("([Ljava/lang/String;)V")) { - try { - for(Field f2 : the.bytecode.club.bytecodeviewer.api.BytecodeViewer.getClassNodeLoader().nodeToClass(cn).getFields()) { + try + { + for(Field f2 : the.bytecode.club.bytecodeviewer.api.BytecodeViewer.getClassNodeLoader().nodeToClass(cn).getFields()) + { String s = f2.get(null); if(s != null && !s.empty()) gui.appendText(cn+":"+s); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ZStringArrayDecrypter.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ZStringArrayDecrypter.java index a45b0d6f..228ec3e8 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ZStringArrayDecrypter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ZStringArrayDecrypter.java @@ -10,6 +10,7 @@ import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.api.Plugin; import the.bytecode.club.bytecodeviewer.api.PluginConsole; +import the.bytecode.club.bytecodeviewer.gui.components.MultipleChoiceDialogue; import static the.bytecode.club.bytecodeviewer.Constants.*; @@ -38,54 +39,54 @@ import static the.bytecode.club.bytecodeviewer.Constants.*; * @author Righteous */ -public class ZStringArrayDecrypter extends Plugin { - +public class ZStringArrayDecrypter extends Plugin +{ PluginConsole gui = new PluginConsole("ZStringArray Decrypter"); StringBuilder out = new StringBuilder(); @Override - public void execute(ArrayList classNodeList) { - JOptionPane pane = new JOptionPane( + public void execute(ArrayList classNodeList) + { + MultipleChoiceDialogue dialogue = new MultipleChoiceDialogue("Bytecode Viewer - WARNING", "WARNING: This will load the classes into the JVM and execute the initialize function" - + nl + "for each class. IF THE FILE YOU'RE LOADING IS MALICIOUS, DO NOT CONTINUE." - ); - Object[] options = new String[]{"Continue", "Cancel"}; - pane.setOptions(options); - JDialog dialog = pane.createDialog(BytecodeViewer.viewer, - "Bytecode Viewer - WARNING"); - dialog.setVisible(true); - Object obj = pane.getValue(); - int result = -1; - for (int k = 0; k < options.length; k++) - if (options[k].equals(obj)) - result = k; + + nl + "for each class. IF THE FILE YOU'RE LOADING IS MALICIOUS, DO NOT CONTINUE.", + new String[]{"Continue", "Cancel"}); - if (result == 0) { + if (dialogue.promptChoice() == 0) + { boolean needsWarning = false; for (Class debug : - Objects.requireNonNull(the.bytecode.club.bytecodeviewer.api.BytecodeViewer.loadClassesIntoClassLoader())) { - try { + Objects.requireNonNull(the.bytecode.club.bytecodeviewer.api.BytecodeViewer.loadClassesIntoClassLoader())) + { + try + { Field[] fields = debug.getDeclaredFields(); - for (Field field : fields) { - if (field.getName().equals("z")) { + for (Field field : fields) + { + if (field.getName().equals("z")) + { out.append(debug.getName()).append(":").append(nl); field.setAccessible(true); - if (field.get(null) != null && field.get(null) instanceof String[] && Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) { + if (field.get(null) != null && field.get(null) instanceof String[] + && Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) + { String[] fieldVal = (String[]) field.get(null); - for (int i = 0; i < fieldVal.length; i++) { + for (int i = 0; i < fieldVal.length; i++) out.append(" z[").append(i).append("] = ").append(fieldVal[i]).append(nl); - } } } } - } catch (NoClassDefFoundError | Exception e) { + } + catch (NoClassDefFoundError | Exception e) + { System.err.println("Failed loading class " + debug.getName()); e.printStackTrace(); needsWarning = true; } } - if (needsWarning) { + if (needsWarning) + { BytecodeViewer.showMessage("Some classes failed to decrypt, if you'd like to decrypt all of them" + nl + "makes sure you include ALL the libraries it requires."); } @@ -94,4 +95,4 @@ public class ZStringArrayDecrypter extends Plugin { gui.setVisible(true); } } -} +} \ No newline at end of file