Skip to content

Commit a12f1aa

Browse files
committed
Plugin Code Cleanup
1 parent 6031154 commit a12f1aa

2 files changed

Lines changed: 49 additions & 48 deletions

File tree

plugins/example/ExampleStringDecrypter.gy

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import the.bytecode.club.bytecodeviewer.api.*;
1+
import the.bytecode.club.bytecodeviewer.api.*
2+
import the.bytecode.club.bytecodeviewer.gui.components.MultipleChoiceDialogue;
3+
24
import java.util.ArrayList;
3-
import org.objectweb.asm.tree.ClassNode;
4-
import javax.swing.JDialog;
5-
import javax.swing.JOptionPane;
65
import java.lang.reflect.Field;
7-
import org.objectweb.asm.tree.FieldNode;
6+
import org.objectweb.asm.tree.ClassNode;
7+
import org.objectweb.asm.tree.FieldNode
8+
9+
import static the.bytecode.club.bytecodeviewer.Constants.nl;
810

911
/**
1012
* This is an example of a string decrypter plugin
@@ -15,27 +17,25 @@ public class ExampleStringDecrypter extends Plugin {
1517
public void execute(ArrayList<ClassNode> classNodesList) {
1618
PluginConsole gui = new PluginConsole("Example String Decrypter");
1719

18-
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?");
19-
String[] options = ["Yes", "No"];
20-
pane.setOptions(options);
21-
JDialog dialog = pane.createDialog(the.bytecode.club.bytecodeviewer.BytecodeViewer.viewer, "WARNING");
22-
dialog.show();
23-
Object obj = pane.getValue();
24-
int result = -1;
25-
for (int k = 0; k < options.length; k++)
26-
if (options[k].equals(obj))
27-
result = k;
28-
20+
MultipleChoiceDialogue dialogue = new MultipleChoiceDialogue("Bytecode Viewer - WARNING",
21+
"WARNING: This will load the classes into the JVM and execute the initialize function"
22+
+ nl + "for each class. IF THE FILE YOU'RE LOADING IS MALICIOUS, DO NOT CONTINUE.",
23+
new String[]{"Continue", "Cancel"});
2924

30-
if(result == 0) {
31-
for(ClassNode cn : classNodesList) {
25+
if(dialogue.promptChoice() == 0)
26+
{
27+
for(ClassNode cn : classNodesList)
28+
{
3229
the.bytecode.club.bytecodeviewer.api.BytecodeViewer.getClassNodeLoader().addClass(cn);
3330

34-
for(Object o : cn.fields.toArray()) {
31+
for(Object o : cn.fields.toArray())
32+
{
3533
FieldNode f = (FieldNode) o;
3634
if(f.name.equals("z")) {// && f.desc.equals("([Ljava/lang/String;)V")) {
37-
try {
38-
for(Field f2 : the.bytecode.club.bytecodeviewer.api.BytecodeViewer.getClassNodeLoader().nodeToClass(cn).getFields()) {
35+
try
36+
{
37+
for(Field f2 : the.bytecode.club.bytecodeviewer.api.BytecodeViewer.getClassNodeLoader().nodeToClass(cn).getFields())
38+
{
3939
String s = f2.get(null);
4040
if(s != null && !s.empty())
4141
gui.appendText(cn+":"+s);

src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ZStringArrayDecrypter.java

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
1111
import the.bytecode.club.bytecodeviewer.api.Plugin;
1212
import the.bytecode.club.bytecodeviewer.api.PluginConsole;
13+
import the.bytecode.club.bytecodeviewer.gui.components.MultipleChoiceDialogue;
1314

1415
import static the.bytecode.club.bytecodeviewer.Constants.*;
1516

@@ -38,54 +39,54 @@
3839
* @author Righteous
3940
*/
4041

41-
public class ZStringArrayDecrypter extends Plugin {
42-
42+
public class ZStringArrayDecrypter extends Plugin
43+
{
4344
PluginConsole gui = new PluginConsole("ZStringArray Decrypter");
4445
StringBuilder out = new StringBuilder();
4546

4647
@Override
47-
public void execute(ArrayList<ClassNode> classNodeList) {
48-
JOptionPane pane = new JOptionPane(
48+
public void execute(ArrayList<ClassNode> classNodeList)
49+
{
50+
MultipleChoiceDialogue dialogue = new MultipleChoiceDialogue("Bytecode Viewer - WARNING",
4951
"WARNING: This will load the classes into the JVM and execute the initialize function"
50-
+ nl + "for each class. IF THE FILE YOU'RE LOADING IS MALICIOUS, DO NOT CONTINUE."
51-
);
52-
Object[] options = new String[]{"Continue", "Cancel"};
53-
pane.setOptions(options);
54-
JDialog dialog = pane.createDialog(BytecodeViewer.viewer,
55-
"Bytecode Viewer - WARNING");
56-
dialog.setVisible(true);
57-
Object obj = pane.getValue();
58-
int result = -1;
59-
for (int k = 0; k < options.length; k++)
60-
if (options[k].equals(obj))
61-
result = k;
52+
+ nl + "for each class. IF THE FILE YOU'RE LOADING IS MALICIOUS, DO NOT CONTINUE.",
53+
new String[]{"Continue", "Cancel"});
6254

63-
if (result == 0) {
55+
if (dialogue.promptChoice() == 0)
56+
{
6457
boolean needsWarning = false;
6558
for (Class<?> debug :
66-
Objects.requireNonNull(the.bytecode.club.bytecodeviewer.api.BytecodeViewer.loadClassesIntoClassLoader())) {
67-
try {
59+
Objects.requireNonNull(the.bytecode.club.bytecodeviewer.api.BytecodeViewer.loadClassesIntoClassLoader()))
60+
{
61+
try
62+
{
6863
Field[] fields = debug.getDeclaredFields();
69-
for (Field field : fields) {
70-
if (field.getName().equals("z")) {
64+
for (Field field : fields)
65+
{
66+
if (field.getName().equals("z"))
67+
{
7168
out.append(debug.getName()).append(":").append(nl);
7269
field.setAccessible(true);
73-
if (field.get(null) != null && field.get(null) instanceof String[] && Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers())) {
70+
if (field.get(null) != null && field.get(null) instanceof String[]
71+
&& Modifier.isStatic(field.getModifiers()) && Modifier.isFinal(field.getModifiers()))
72+
{
7473
String[] fieldVal = (String[]) field.get(null);
75-
for (int i = 0; i < fieldVal.length; i++) {
74+
for (int i = 0; i < fieldVal.length; i++)
7675
out.append(" z[").append(i).append("] = ").append(fieldVal[i]).append(nl);
77-
}
7876
}
7977
}
8078
}
81-
} catch (NoClassDefFoundError | Exception e) {
79+
}
80+
catch (NoClassDefFoundError | Exception e)
81+
{
8282
System.err.println("Failed loading class " + debug.getName());
8383
e.printStackTrace();
8484
needsWarning = true;
8585
}
8686
}
8787

88-
if (needsWarning) {
88+
if (needsWarning)
89+
{
8990
BytecodeViewer.showMessage("Some classes failed to decrypt, if you'd like to decrypt all of them"
9091
+ nl + "makes sure you include ALL the libraries it requires.");
9192
}
@@ -94,4 +95,4 @@ public void execute(ArrayList<ClassNode> classNodeList) {
9495
gui.setVisible(true);
9596
}
9697
}
97-
}
98+
}

0 commit comments

Comments
 (0)