diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/api/ASMUtil_OLD.java b/src/main/java/the/bytecode/club/bytecodeviewer/api/ASMRenameUtil.java similarity index 76% rename from src/main/java/the/bytecode/club/bytecodeviewer/api/ASMUtil_OLD.java rename to src/main/java/the/bytecode/club/bytecodeviewer/api/ASMRenameUtil.java index 8272c201..096aecf6 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/api/ASMUtil_OLD.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/api/ASMRenameUtil.java @@ -30,25 +30,33 @@ import the.bytecode.club.bytecodeviewer.BytecodeViewer; ***************************************************************************/ /** - * Used to rename/replace methods/classes/fields + * Used to rename/replace methods/classes/fields loaded as a BCV resource * * @author Konloch */ -public final class ASMUtil_OLD { + +public final class ASMRenameUtil +{ public static void renameFieldNode(String originalParentName, String originalFieldName, String originalFieldDesc, - String newFieldParent, String newFieldName, String newFieldDesc) { - for (ClassNode c : BytecodeViewer.getLoadedClasses()) { - for (Object o : c.methods.toArray()) { + String newFieldParent, String newFieldName, String newFieldDesc) + { + for (ClassNode c : BytecodeViewer.getLoadedClasses()) + { + for (Object o : c.methods.toArray()) + { MethodNode m = (MethodNode) o; - for (AbstractInsnNode i : m.instructions.toArray()) { - if (i instanceof FieldInsnNode) { + for (AbstractInsnNode i : m.instructions.toArray()) + { + if (i instanceof FieldInsnNode) + { FieldInsnNode field = (FieldInsnNode) i; if (field.owner.equals(originalParentName) && field.name.equals(originalFieldName) - && field.desc.equals(originalFieldDesc)) { + && field.desc.equals(originalFieldDesc)) + { if (newFieldParent != null) field.owner = newFieldParent; if (newFieldName != null) @@ -64,16 +72,22 @@ public final class ASMUtil_OLD { public static void renameMethodNode(String originalParentName, String originalMethodName, String originalMethodDesc, - String newParent, String newName, String newDesc) { - for (ClassNode c : BytecodeViewer.getLoadedClasses()) { - for (Object o : c.methods.toArray()) { + String newParent, String newName, String newDesc) + { + for (ClassNode c : BytecodeViewer.getLoadedClasses()) + { + for (Object o : c.methods.toArray()) + { MethodNode m = (MethodNode) o; - for (AbstractInsnNode i : m.instructions.toArray()) { - if (i instanceof MethodInsnNode) { + for (AbstractInsnNode i : m.instructions.toArray()) + { + if (i instanceof MethodInsnNode) + { MethodInsnNode mi = (MethodInsnNode) i; if (mi.owner.equals(originalParentName) && mi.name.equals(originalMethodName) - && mi.desc.equals(originalMethodDesc)) { + && mi.desc.equals(originalMethodDesc)) + { if (newParent != null) mi.owner = newParent; if (newName != null) @@ -86,7 +100,8 @@ public final class ASMUtil_OLD { }*/ } - if (m.signature != null) { + if (m.signature != null) + { if (newName != null) m.signature = m.signature.replace(originalMethodName, newName); @@ -97,7 +112,8 @@ public final class ASMUtil_OLD { if (m.name.equals(originalMethodName) && m.desc.equals(originalMethodDesc) - && c.name.equals(originalParentName)) { + && c.name.equals(originalParentName)) + { if (newName != null) m.name = newName; if (newDesc != null) @@ -108,63 +124,67 @@ public final class ASMUtil_OLD { } public static void renameClassNode(final String oldName, - final String newName) { - for (ClassNode c : BytecodeViewer.getLoadedClasses()) { - for (InnerClassNode oo : c.innerClasses) { - if (oo.innerName != null - && oo.innerName.equals(oldName)) { + final String newName) + { + for (ClassNode c : BytecodeViewer.getLoadedClasses()) + { + for (InnerClassNode oo : c.innerClasses) + { + if (oo.innerName != null && oo.innerName.equals(oldName)) oo.innerName = newName; - } - if (oo.name.equals(oldName)) { + + if (oo.name.equals(oldName)) oo.name = newName; - } - if (oo.outerName != null - && oo.outerName.equals(oldName)) { + + if (oo.outerName != null && oo.outerName.equals(oldName)) oo.outerName = newName; - } } if (c.signature != null) c.signature = c.signature.replace(oldName, newName); - if (c.superName.equals(oldName)) { + if (c.superName.equals(oldName)) c.superName = newName; - } - for (Object o : c.fields.toArray()) { + + for (Object o : c.fields.toArray()) + { FieldNode f = (FieldNode) o; f.desc = f.desc.replace(oldName, newName); } - for (Object o : c.methods.toArray()) { + + for (Object o : c.methods.toArray()) + { MethodNode m = (MethodNode) o; - if (m.localVariables != null) { - for (LocalVariableNode node : m.localVariables) { + if (m.localVariables != null) + for (LocalVariableNode node : m.localVariables) node.desc = node.desc.replace(oldName, newName); - } - } if (m.signature != null) m.signature = m.signature.replace(oldName, newName); - for (int i = 0; i < m.exceptions.size(); i++) { + for (int i = 0; i < m.exceptions.size(); i++) if (m.exceptions.get(i).equals(oldName)) m.exceptions.set(i, newName); - } - for (AbstractInsnNode i : m.instructions.toArray()) { - if (i instanceof TypeInsnNode) { + for (AbstractInsnNode i : m.instructions.toArray()) + { + if (i instanceof TypeInsnNode) + { TypeInsnNode t = (TypeInsnNode) i; - if (t.desc.equals(oldName)) { + if (t.desc.equals(oldName)) t.desc = newName; - } } - if (i instanceof MethodInsnNode) { + + if (i instanceof MethodInsnNode) + { MethodInsnNode mi = (MethodInsnNode) i; if (mi.owner.equals(oldName)) mi.owner = newName; mi.desc = mi.desc.replace(oldName, newName); } - if (i instanceof FieldInsnNode) { + if (i instanceof FieldInsnNode) + { FieldInsnNode fi = (FieldInsnNode) i; if (fi.owner.equals(oldName)) fi.owner = newName; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameClasses.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameClasses.java index a0b94527..9f70cceb 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameClasses.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameClasses.java @@ -2,7 +2,7 @@ package the.bytecode.club.bytecodeviewer.obfuscators; import org.objectweb.asm.tree.ClassNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.api.ASMUtil_OLD; +import the.bytecode.club.bytecodeviewer.api.ASMRenameUtil; /*************************************************************************** * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * @@ -37,7 +37,7 @@ public class RenameClasses extends JavaObfuscator { System.out.println("Obfuscating class names..."); for (ClassNode c : BytecodeViewer.getLoadedClasses()) { String newName = generateUniqueName(stringLength); - ASMUtil_OLD.renameClassNode(c.name, newName); + ASMRenameUtil.renameClassNode(c.name, newName); c.name = newName; } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameFields.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameFields.java index 69399bda..4e205776 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameFields.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameFields.java @@ -3,7 +3,7 @@ package the.bytecode.club.bytecodeviewer.obfuscators; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.FieldNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.api.ASMUtil_OLD; +import the.bytecode.club.bytecodeviewer.api.ASMRenameUtil; /*************************************************************************** * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * @@ -40,7 +40,7 @@ public class RenameFields extends JavaObfuscator { for (Object o : c.fields.toArray()) { FieldNode f = (FieldNode) o; String newName = generateUniqueName(stringLength); - ASMUtil_OLD.renameFieldNode(c.name, f.name, f.desc, null, + ASMRenameUtil.renameFieldNode(c.name, f.name, f.desc, null, newName, null); f.name = newName; } diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameMethods.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameMethods.java index fd0d59e5..a3b6fe07 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameMethods.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameMethods.java @@ -4,7 +4,7 @@ import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.MethodNode; import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.api.ASMUtil_OLD; +import the.bytecode.club.bytecodeviewer.api.ASMRenameUtil; /*************************************************************************** * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * @@ -58,7 +58,7 @@ public class RenameMethods extends JavaObfuscator { if (!m.name.equals("main") && !m.name.equals("") && !m.name.equals("")) { String newName = generateUniqueName(stringLength); - ASMUtil_OLD.renameMethodNode(c.name, m.name, m.desc, + ASMRenameUtil.renameMethodNode(c.name, m.name, m.desc, null, newName, null); } }