From d4611106cb33fb5bec8430224dce0286f53d899a Mon Sep 17 00:00:00 2001 From: im-frizzy Date: Sat, 28 Feb 2015 22:10:45 -0600 Subject: [PATCH] Print the re-mapping of classes/methods/fields --- .../bytecodeviewer/gui/MainViewerGUI.java | 6 +++- .../obfuscators/JavaObfuscator.java | 3 ++ .../obfuscators/mapping/RefactorMapper.java | 33 +++++++++++++++++-- .../obfuscators/mapping/Refactorer.java | 1 + .../obfuscators/rename/RenameClasses.java | 2 +- 5 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java b/src/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java index f35a73ab..301c918c 100644 --- a/src/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java +++ b/src/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java @@ -340,6 +340,8 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { private final JSeparator separator_6 = new JSeparator(); public final JCheckBoxMenuItem refreshOnChange = new JCheckBoxMenuItem("Refresh On View Change"); + public FileNavigationPane cn = new FileNavigationPane(this); + public boolean isMaximized = false; public void removed(boolean busy) { @@ -1434,6 +1436,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { } new RenameFields().start(); workPane.refreshClass.doClick(); + cn.tree.updateUI(); } }); @@ -1455,6 +1458,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { } new RenameMethods().start(); workPane.refreshClass.doClick(); + cn.tree.updateUI(); } }); @@ -1467,6 +1471,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { } new RenameClasses().start(); workPane.refreshClass.doClick(); + cn.tree.updateUI(); } }); @@ -1575,7 +1580,6 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier { new BoxLayout(getContentPane(), BoxLayout.X_AXIS)); // scrollPane.setViewportView(tree); - FileNavigationPane cn = new FileNavigationPane(this); cn.setMinimumSize(new Dimension(200, 50)); // panel.add(cn); SearchingPane s = new SearchingPane(this); diff --git a/src/the/bytecode/club/bytecodeviewer/obfuscators/JavaObfuscator.java b/src/the/bytecode/club/bytecodeviewer/obfuscators/JavaObfuscator.java index 9aa3e3a1..c7431232 100644 --- a/src/the/bytecode/club/bytecodeviewer/obfuscators/JavaObfuscator.java +++ b/src/the/bytecode/club/bytecodeviewer/obfuscators/JavaObfuscator.java @@ -43,6 +43,9 @@ public abstract class JavaObfuscator extends Thread { String name = ""; while (!found) { String nameTry = MiscUtils.randomString(1) + MiscUtils.randomStringNum(length - 1); + if (!Character.isJavaIdentifierStart(nameTry.toCharArray()[0])) + continue; + if (!names.contains(nameTry)) { names.add(nameTry); name = nameTry; diff --git a/src/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RefactorMapper.java b/src/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RefactorMapper.java index 43505fad..6e160ae3 100644 --- a/src/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RefactorMapper.java +++ b/src/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RefactorMapper.java @@ -1,6 +1,8 @@ package the.bytecode.club.bytecodeviewer.obfuscators.mapping; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.objectweb.asm.commons.Remapper; @@ -17,11 +19,16 @@ public class RefactorMapper extends Remapper { protected final Map sortedClasses; protected final Map sortedMethods; protected final Map sortedFields; + protected final List mappingList; + private StringBuilder builder; + public RefactorMapper(HookMap hookMap) { sortedClasses = new HashMap<>(); sortedMethods = new HashMap<>(); sortedFields = new HashMap<>(); + mappingList = new ArrayList<>(); + builder = new StringBuilder(); for(MappingData hook : hookMap.getClasses()){ if(hook.getObfuscatedName().contains("$")) continue; @@ -46,24 +53,44 @@ public class RefactorMapper extends Remapper { @Override public String map(String type) { - if (sortedClasses.containsKey(type)) + if (sortedClasses.containsKey(type)) { + String map = new String(type + " --> " + sortedClasses.get(type).getRefactoredName() + "\n"); + if (!mappingList.contains(map)) + mappingList.add(map); + return sortedClasses.get(type).getRefactoredName(); + } return type; } @Override public String mapFieldName(String owner, String name, String desc) { String obfKey = owner + "$$$$" + name + "$$$$" + desc; - if (sortedFields.containsKey(obfKey)) + if (sortedFields.containsKey(obfKey)) { + String map = new String(owner + "." + name + " --> " + owner + sortedFields.get(obfKey).getName().getRefactoredName() + "\n"); + if (!mappingList.contains(map)) + mappingList.add(map); name = sortedFields.get(obfKey).getName().getRefactoredName(); + } return name; } @Override public String mapMethodName(String owner, String name, String desc) { String obfKey = owner + "$$$$" + name + "$$$$" + desc; - if (sortedMethods.containsKey(obfKey)) + if (sortedMethods.containsKey(obfKey)) { + String map = new String(owner + "." + name + " --> " + owner + sortedMethods.get(obfKey).getMethodName().getRefactoredName() + "\n"); + if (!mappingList.contains(map)) + mappingList.add(map); name = sortedMethods.get(obfKey).getMethodName().getRefactoredName(); + } return name; } + + public void printMap() { + for (String map : mappingList) { + builder.append(map); + } + System.out.println(builder.toString()); + } } diff --git a/src/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Refactorer.java b/src/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Refactorer.java index 70c9aca1..cf2fb2ac 100644 --- a/src/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Refactorer.java +++ b/src/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Refactorer.java @@ -45,6 +45,7 @@ public class Refactorer { for (Map.Entry factor : refactored.entrySet()) { BytecodeViewer.relocate(factor.getKey(), factor.getValue()); } + mapper.printMap(); } private byte[] getClassNodeBytes(ClassNode cn) { diff --git a/src/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameClasses.java b/src/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameClasses.java index 79765a48..1e17f6e7 100644 --- a/src/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameClasses.java +++ b/src/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameClasses.java @@ -22,7 +22,7 @@ public class RenameClasses extends JavaObfuscator { @Override public void obfuscate() { - int stringLength = getStringLength(); + int stringLength = 5;//getStringLength(); System.out.println("Obfuscating class names..."); classLoop: for (ClassNode c : BytecodeViewer.getLoadedClasses()) {