From 5509a659fb36d2c7e6c9475138e33d5ca43a53d2 Mon Sep 17 00:00:00 2001 From: Konloch Date: Tue, 6 Jul 2021 13:38:45 -0700 Subject: [PATCH] Started Replace Strings Cleanup --- .../plugin/preinstalled/ReplaceStrings.java | 121 ++++++++++-------- 1 file changed, 65 insertions(+), 56 deletions(-) diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ReplaceStrings.java b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ReplaceStrings.java index 06ac4567..03072033 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ReplaceStrings.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/plugin/preinstalled/ReplaceStrings.java @@ -34,16 +34,16 @@ import the.bytecode.club.bytecodeviewer.api.PluginConsole; * @author Konloch */ -public class ReplaceStrings extends Plugin { - +public class ReplaceStrings extends Plugin +{ PluginConsole frame = new PluginConsole("Replace Strings"); String originalLDC; String newLDC; String className; boolean contains; - public ReplaceStrings(String originalLDC, String newLDC, String className, - boolean contains) { + public ReplaceStrings(String originalLDC, String newLDC, String className, boolean contains) + { this.originalLDC = originalLDC; this.newLDC = newLDC; this.className = className; @@ -51,103 +51,112 @@ public class ReplaceStrings extends Plugin { } @Override - public void execute(ArrayList classNodeList) { - if (!className.equals("*")) { - for (ClassNode classNode : classNodeList) { + public void execute(ArrayList classNodeList) + { + if (!className.equals("*")) + { + for (ClassNode classNode : classNodeList) if (classNode.name.equals(className)) scanClassNode(classNode); - } - } else { - for (ClassNode classNode : classNodeList) { - scanClassNode(classNode); - } } + else + { + for (ClassNode classNode : classNodeList) + scanClassNode(classNode); + } + frame.setVisible(true); } - public void scanClassNode(ClassNode classNode) { - for (Object o : classNode.fields.toArray()) { + public void scanClassNode(ClassNode classNode) + { + 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 (contains) { + if (contains) + { if (s.contains(originalLDC)) - f.value = ((String) f.value).replaceAll(originalLDC, - newLDC); - } else { + f.value = ((String) f.value).replaceAll(originalLDC, newLDC); + } + else + { if (s.equals(originalLDC)) f.value = newLDC; } } - 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 (contains) { - if (s.contains(originalLDC)) { - f.value = ((String[]) f.value)[i].replaceAll( - originalLDC, newLDC); + if (contains) + { + if (s.contains(originalLDC)) + { + f.value = ((String[]) f.value)[i].replaceAll(originalLDC, newLDC); String ugh = s.replaceAll("\\n", "\\\\n") .replaceAll("\\r", "\\\\r"); frame.appendText(classNode.name + "." + f.name + "" - + f.desc + " -> \"" + ugh - + "\" replaced with \"" + + f.desc + " -> \"" + ugh + "\" replaced with \"" + s.replaceAll(originalLDC, newLDC) + "\""); } - } else { - if (s.equals(originalLDC)) { + } + else + { + if (s.equals(originalLDC)) + { ((String[]) f.value)[i] = newLDC; String ugh = s.replaceAll("\\n", "\\\\n") .replaceAll("\\r", "\\\\r"); frame.appendText(classNode.name + "." + f.name + "" - + f.desc + " -> \"" + ugh - + "\" replaced with \"" + newLDC + "\""); + + f.desc + " -> \"" + ugh + "\" replaced with \"" + newLDC + "\""); } } } } } - 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 (contains) { - if (s.contains(originalLDC)) { + if (contains) + { + if (s.contains(originalLDC)) + { ((LdcInsnNode) a).cst = ((String) ((LdcInsnNode) a).cst) .replaceAll(originalLDC, newLDC); String ugh = s.replaceAll("\\n", "\\\\n") .replaceAll("\\r", "\\\\r"); - frame.appendText(classNode.name - + "." - + m.name - + "" - + m.desc - + " -> \"" - + ugh - + "\" replaced with \"" + frame.appendText(classNode.name + "." + m.name + "" + m.desc + + " -> \"" + ugh + "\" replaced with \"" + s.replaceAll(originalLDC, newLDC) .replaceAll("\\n", "\\\\n") .replaceAll("\\r", "\\\\r") + "\""); } - } else { - if (s.equals(originalLDC)) { + } + else + { + if (s.equals(originalLDC)) + { ((LdcInsnNode) a).cst = newLDC; String ugh = s.replaceAll("\\n", "\\\\n") .replaceAll("\\r", "\\\\r"); - frame.appendText(classNode.name - + "." - + m.name - + "" - + m.desc - + " -> \"" - + ugh - + "\" replaced with \"" + frame.appendText(classNode.name + "." + m.name + "" + m.desc + + " -> \"" + ugh + "\" replaced with \"" + newLDC.replaceAll("\\n", "\\\\n") .replaceAll("\\r", "\\\\r") + "\"");