From b2d37f6adb9f3ec17999690176b9e3704d3a94bd Mon Sep 17 00:00:00 2001 From: Konloch Date: Tue, 6 Jul 2021 13:47:34 -0700 Subject: [PATCH] Plugin Cleanup --- .../plugin/preinstalled/ShowAllStrings.java | 41 ++++++++++++------- .../plugin/preinstalled/ShowMainMethods.java | 24 +++++++---- .../preinstalled/StackFramesRemover.java | 21 ++++++---- .../preinstalled/ZKMStringDecrypter.java | 9 ++-- 4 files changed, 60 insertions(+), 35 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ShowAllStrings.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ShowAllStrings.java index 0ce0eab1..700a351c 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ShowAllStrings.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ShowAllStrings.java @@ -37,25 +37,34 @@ import static the.bytecode.club.bytecodeviewer.Constants.*; * @author Konloch */ -public class ShowAllStrings extends Plugin { - +public class ShowAllStrings extends Plugin +{ @Override - public void execute(ArrayList classNodeList) { + public void execute(ArrayList classNodeList) + { PluginConsole frame = new PluginConsole("Show All Strings"); StringBuilder sb = new StringBuilder(); - for (ClassNode classNode : classNodeList) { - for (Object o : classNode.fields.toArray()) { + + for (ClassNode classNode : classNodeList) + { + for (Object o : classNode.fields.toArray()) + { FieldNode f = (FieldNode) o; Object v = f.value; - if (v instanceof String) { + + if (v instanceof String) + { String s = (String) v; if (!s.isEmpty()) sb.append(classNode.name).append(".").append(f.name).append(f.desc).append(" -> \"") .append(s.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r")) .append("\"").append(nl); } - if (v instanceof String[]) { - for (int i = 0; i < ((String[]) v).length; i++) { + + if (v instanceof String[]) + { + for (int i = 0; i < ((String[]) v).length; i++) + { String s = ((String[]) v)[i]; if (!s.isEmpty()) sb.append(classNode.name).append(".").append(f.name).append(f.desc).append("[").append(i) @@ -65,13 +74,17 @@ public class ShowAllStrings extends Plugin { } } - for (Object o : classNode.methods.toArray()) { + for (Object o : classNode.methods.toArray()) + { MethodNode m = (MethodNode) o; - InsnList iList = m.instructions; - for (AbstractInsnNode a : iList.toArray()) { - if (a instanceof LdcInsnNode) { - if (((LdcInsnNode) a).cst instanceof String) { + + for (AbstractInsnNode a : iList.toArray()) + { + if (a instanceof LdcInsnNode) + { + if (((LdcInsnNode) a).cst instanceof String) + { final String s = (String) ((LdcInsnNode) a).cst; if (!s.isEmpty()) sb.append(classNode.name).append(".").append(m.name).append(m.desc).append(" -> \"") @@ -86,4 +99,4 @@ public class ShowAllStrings extends Plugin { frame.appendText(sb.toString()); frame.setVisible(true); } -} +} \ No newline at end of file diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ShowMainMethods.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ShowMainMethods.java index 2aa09a58..e8f2c327 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ShowMainMethods.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ShowMainMethods.java @@ -32,19 +32,26 @@ import the.bytecode.club.bytecodeviewer.api.PluginConsole; * @author Sh1ftchg */ -public class ShowMainMethods extends Plugin { +public class ShowMainMethods extends Plugin +{ private static final int PUBLIC_STATIC = Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC; @Override - public void execute(ArrayList classNodeList) { + public void execute(ArrayList classNodeList) + { PluginConsole frame = new PluginConsole("Show Main Methods"); StringBuilder sb = new StringBuilder(); - for (ClassNode classNode : classNodeList) { - for (Object o : classNode.methods.toArray()) { + + for (ClassNode classNode : classNodeList) + { + for (Object o : classNode.methods.toArray()) + { MethodNode m = (MethodNode) o; - if ((m.access & (PUBLIC_STATIC)) == PUBLIC_STATIC) { - if (m.name.equals("main") && m.desc.equals("([Ljava/lang/String;)V")) { + if ((m.access & (PUBLIC_STATIC)) == PUBLIC_STATIC) + { + if (m.name.equals("main") && m.desc.equals("([Ljava/lang/String;)V")) + { sb.append(classNode.name); sb.append("."); sb.append(m.name); @@ -55,11 +62,10 @@ public class ShowMainMethods extends Plugin { } } - if (sb.length() == 0) { + if (sb.length() == 0) frame.appendText("No main methods found."); - } else { + else frame.appendText(sb.toString()); - } frame.setVisible(true); } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/StackFramesRemover.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/StackFramesRemover.java index 5b1d1219..4fb807ef 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/StackFramesRemover.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/StackFramesRemover.java @@ -9,16 +9,21 @@ import org.objectweb.asm.tree.MethodNode; import the.bytecode.club.bytecodeviewer.api.Plugin; import the.bytecode.club.bytecodeviewer.api.PluginConsole; -public class StackFramesRemover extends Plugin { - +public class StackFramesRemover extends Plugin +{ @Override - public void execute(ArrayList classNodeList) { + public void execute(ArrayList classNodeList) + { AtomicInteger counter = new AtomicInteger(); PluginConsole frame = new PluginConsole("StackFrames Remover"); - for (ClassNode cn : classNodeList) { - for (MethodNode mn : cn.methods) { - for (AbstractInsnNode insn : mn.instructions.toArray()) { - if (insn instanceof FrameNode) { + for (ClassNode cn : classNodeList) + { + for (MethodNode mn : cn.methods) + { + for (AbstractInsnNode insn : mn.instructions.toArray()) + { + if (insn instanceof FrameNode) + { mn.instructions.remove(insn); counter.incrementAndGet(); } @@ -29,4 +34,4 @@ public class StackFramesRemover extends Plugin { frame.appendText(String.format("Removed %s stackframes.", counter)); frame.setVisible(true); } -} +} \ No newline at end of file diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ZKMStringDecrypter.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ZKMStringDecrypter.java index 05c0113a..59f320ce 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ZKMStringDecrypter.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ZKMStringDecrypter.java @@ -29,10 +29,11 @@ import the.bytecode.club.bytecodeviewer.api.Plugin; * @author Konloch */ -public class ZKMStringDecrypter extends Plugin { - +public class ZKMStringDecrypter extends Plugin +{ @Override - public void execute(ArrayList classNodeList) { + public void execute(ArrayList classNodeList) + { BytecodeViewer.showMessage("This is a planned feature."); } -} +} \ No newline at end of file