Plugin Cleanup

This commit is contained in:
Konloch 2021-07-06 13:47:34 -07:00
parent 5509a659fb
commit b2d37f6adb
4 changed files with 60 additions and 35 deletions

View file

@ -37,25 +37,34 @@ import static the.bytecode.club.bytecodeviewer.Constants.*;
* @author Konloch * @author Konloch
*/ */
public class ShowAllStrings extends Plugin { public class ShowAllStrings extends Plugin
{
@Override @Override
public void execute(ArrayList<ClassNode> classNodeList) { public void execute(ArrayList<ClassNode> classNodeList)
{
PluginConsole frame = new PluginConsole("Show All Strings"); PluginConsole frame = new PluginConsole("Show All Strings");
StringBuilder sb = new StringBuilder(); 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; FieldNode f = (FieldNode) o;
Object v = f.value; Object v = f.value;
if (v instanceof String) {
if (v instanceof String)
{
String s = (String) v; String s = (String) v;
if (!s.isEmpty()) if (!s.isEmpty())
sb.append(classNode.name).append(".").append(f.name).append(f.desc).append(" -> \"") sb.append(classNode.name).append(".").append(f.name).append(f.desc).append(" -> \"")
.append(s.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r")) .append(s.replaceAll("\\n", "\\\\n").replaceAll("\\r", "\\\\r"))
.append("\"").append(nl); .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]; String s = ((String[]) v)[i];
if (!s.isEmpty()) if (!s.isEmpty())
sb.append(classNode.name).append(".").append(f.name).append(f.desc).append("[").append(i) 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; MethodNode m = (MethodNode) o;
InsnList iList = m.instructions; InsnList iList = m.instructions;
for (AbstractInsnNode a : iList.toArray()) {
if (a instanceof LdcInsnNode) { for (AbstractInsnNode a : iList.toArray())
if (((LdcInsnNode) a).cst instanceof String) { {
if (a instanceof LdcInsnNode)
{
if (((LdcInsnNode) a).cst instanceof String)
{
final String s = (String) ((LdcInsnNode) a).cst; final String s = (String) ((LdcInsnNode) a).cst;
if (!s.isEmpty()) if (!s.isEmpty())
sb.append(classNode.name).append(".").append(m.name).append(m.desc).append(" -> \"") 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.appendText(sb.toString());
frame.setVisible(true); frame.setVisible(true);
} }
} }

View file

@ -32,19 +32,26 @@ import the.bytecode.club.bytecodeviewer.api.PluginConsole;
* @author Sh1ftchg * @author Sh1ftchg
*/ */
public class ShowMainMethods extends Plugin { public class ShowMainMethods extends Plugin
{
private static final int PUBLIC_STATIC = Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC; private static final int PUBLIC_STATIC = Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC;
@Override @Override
public void execute(ArrayList<ClassNode> classNodeList) { public void execute(ArrayList<ClassNode> classNodeList)
{
PluginConsole frame = new PluginConsole("Show Main Methods"); PluginConsole frame = new PluginConsole("Show Main Methods");
StringBuilder sb = new StringBuilder(); 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; MethodNode m = (MethodNode) o;
if ((m.access & (PUBLIC_STATIC)) == PUBLIC_STATIC) { if ((m.access & (PUBLIC_STATIC)) == PUBLIC_STATIC)
if (m.name.equals("main") && m.desc.equals("([Ljava/lang/String;)V")) { {
if (m.name.equals("main") && m.desc.equals("([Ljava/lang/String;)V"))
{
sb.append(classNode.name); sb.append(classNode.name);
sb.append("."); sb.append(".");
sb.append(m.name); 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."); frame.appendText("No main methods found.");
} else { else
frame.appendText(sb.toString()); frame.appendText(sb.toString());
}
frame.setVisible(true); frame.setVisible(true);
} }

View file

@ -9,16 +9,21 @@ import org.objectweb.asm.tree.MethodNode;
import the.bytecode.club.bytecodeviewer.api.Plugin; import the.bytecode.club.bytecodeviewer.api.Plugin;
import the.bytecode.club.bytecodeviewer.api.PluginConsole; import the.bytecode.club.bytecodeviewer.api.PluginConsole;
public class StackFramesRemover extends Plugin { public class StackFramesRemover extends Plugin
{
@Override @Override
public void execute(ArrayList<ClassNode> classNodeList) { public void execute(ArrayList<ClassNode> classNodeList)
{
AtomicInteger counter = new AtomicInteger(); AtomicInteger counter = new AtomicInteger();
PluginConsole frame = new PluginConsole("StackFrames Remover"); PluginConsole frame = new PluginConsole("StackFrames Remover");
for (ClassNode cn : classNodeList) { for (ClassNode cn : classNodeList)
for (MethodNode mn : cn.methods) { {
for (AbstractInsnNode insn : mn.instructions.toArray()) { for (MethodNode mn : cn.methods)
if (insn instanceof FrameNode) { {
for (AbstractInsnNode insn : mn.instructions.toArray())
{
if (insn instanceof FrameNode)
{
mn.instructions.remove(insn); mn.instructions.remove(insn);
counter.incrementAndGet(); counter.incrementAndGet();
} }
@ -29,4 +34,4 @@ public class StackFramesRemover extends Plugin {
frame.appendText(String.format("Removed %s stackframes.", counter)); frame.appendText(String.format("Removed %s stackframes.", counter));
frame.setVisible(true); frame.setVisible(true);
} }
} }

View file

@ -29,10 +29,11 @@ import the.bytecode.club.bytecodeviewer.api.Plugin;
* @author Konloch * @author Konloch
*/ */
public class ZKMStringDecrypter extends Plugin { public class ZKMStringDecrypter extends Plugin
{
@Override @Override
public void execute(ArrayList<ClassNode> classNodeList) { public void execute(ArrayList<ClassNode> classNodeList)
{
BytecodeViewer.showMessage("This is a planned feature."); BytecodeViewer.showMessage("This is a planned feature.");
} }
} }