diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java index e774a3767..17181440b 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/BytecodeViewer.java @@ -40,7 +40,6 @@ import the.bytecode.club.bytecodeviewer.gui.resourcelist.ResourceListIconRenderer; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ClassViewer; import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ResourceViewer; -import the.bytecode.club.bytecodeviewer.obfuscators.mapping.Refactorer; import the.bytecode.club.bytecodeviewer.plugin.PluginWriter; import the.bytecode.club.bytecodeviewer.resources.ResourceContainer; import the.bytecode.club.bytecodeviewer.resources.importing.ImportResource; @@ -140,9 +139,6 @@ public class BytecodeViewer //Security Manager for dynamic analysis debugging public static SecurityMan sm = new SecurityMan(); - //Refactorer - public static Refactorer refactorer = new Refactorer(); - //GSON Reference public static Gson gson = new GsonBuilder().setPrettyPrinting().create(); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/Configuration.java b/src/main/java/the/bytecode/club/bytecodeviewer/Configuration.java index a71ee9924..6c34dd5b8 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/Configuration.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/Configuration.java @@ -73,7 +73,6 @@ public class Configuration public static boolean currentlyDumping = false; public static boolean needsReDump = true; public static boolean warnForEditing = false; - public static boolean runningObfuscation = false; public static final long BOOT_TIMESTAMP = System.currentTimeMillis(); public static String lastOpenDirectory = "."; public static String lastSaveDirectory = "."; diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java b/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java index 0991cc59f..8a6b84fa7 100644 --- a/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java +++ b/src/main/java/the/bytecode/club/bytecodeviewer/gui/MainViewerGUI.java @@ -33,9 +33,6 @@ import the.bytecode.club.bytecodeviewer.gui.resourceviewer.viewer.ResourceViewer; import the.bytecode.club.bytecodeviewer.gui.theme.LAFTheme; import the.bytecode.club.bytecodeviewer.gui.theme.RSTATheme; -import the.bytecode.club.bytecodeviewer.obfuscators.rename.RenameClasses; -import the.bytecode.club.bytecodeviewer.obfuscators.rename.RenameFields; -import the.bytecode.club.bytecodeviewer.obfuscators.rename.RenameMethods; import the.bytecode.club.bytecodeviewer.plugin.PluginManager; import the.bytecode.club.bytecodeviewer.plugin.PluginTemplate; import the.bytecode.club.bytecodeviewer.plugin.preinstalled.*; @@ -280,17 +277,6 @@ public class MainViewerGUI extends JFrame public final JMenu minSdkVersionMenu = new TranslatedJMenu("Minimum SDK version", TranslatedComponents.MIN_SDK_VERSION); public final JSpinner minSdkVersionSpinner = new JSpinner(); - //obfuscation - public final JMenu obfuscate = new JMenu("Obfuscate"); - public final JMenuItem renameFields = new JMenuItem("Rename Fields"); - public final JMenuItem renameMethods = new JMenuItem("Rename Methods"); - public final JMenuItem moveAllClassesIntoRoot = new JMenuItem("Move All Classes Into Root Package"); - public final JMenuItem controlFlow = new JMenuItem("Control Flow"); - public final JMenuItem junkCode = new JMenuItem("Junk Code"); - public final ButtonGroup obfuscatorGroup = new ButtonGroup(); - public final JRadioButtonMenuItem strongObf = new JRadioButtonMenuItem("Strong Obfuscation"); - public final JRadioButtonMenuItem lightObf = new JRadioButtonMenuItem("Light Obfuscation"); - public final JMenuItem renameClasses = new JMenuItem("Rename Classes"); public MainViewerGUI() { @@ -307,7 +293,6 @@ public MainViewerGUI() buildViewMenu(); buildSettingsMenu(); buildPluginMenu(); - buildObfuscateMenu(); defaultSettings(); setTitle("Bytecode Viewer " + VERSION + " - https://bytecodeviewer.com | https://the.bytecode.club - @Konloch"); @@ -720,31 +705,6 @@ public void buildPluginMenu() changeClassFileVersions.addActionListener(arg0 -> PluginManager.runPlugin(new ChangeClassFileVersions())); } - public void buildObfuscateMenu() - { - //hide obfuscation menu since it's currently not being used - obfuscate.setVisible(false); - - rootMenu.add(obfuscate); - obfuscate.add(strongObf); - obfuscate.add(lightObf); - obfuscate.add(new JSeparator()); - obfuscate.add(moveAllClassesIntoRoot); - obfuscate.add(renameFields); - obfuscate.add(renameMethods); - obfuscate.add(renameClasses); - obfuscate.add(controlFlow); - obfuscate.add(junkCode); - - obfuscatorGroup.add(strongObf); - obfuscatorGroup.add(lightObf); - obfuscatorGroup.setSelected(strongObf.getModel(), true); - - renameFields.addActionListener(arg0 -> RenameFields.open()); - renameClasses.addActionListener(arg0 -> RenameClasses.open()); - renameMethods.addActionListener(arg0 -> RenameMethods.open()); - } - public void defaultSettings() { compileOnSave.setSelected(false); @@ -760,10 +720,6 @@ public void defaultSettings() simplifyNameInTabTitle.setEnabled(true); - moveAllClassesIntoRoot.setEnabled(false); - controlFlow.setEnabled(false); - junkCode.setEnabled(false); - // cfr decodeEnumSwitch.setSelected(true); sugarEnums.setSelected(true); diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/JavaObfuscator.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/JavaObfuscator.java deleted file mode 100644 index f11844ebb..000000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/JavaObfuscator.java +++ /dev/null @@ -1,85 +0,0 @@ -/*************************************************************************** - * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * - * Copyright (C) 2014 Konloch - Konloch.com / BytecodeViewer.com * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - ***************************************************************************/ - -package the.bytecode.club.bytecodeviewer.obfuscators; - -import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.Configuration; -import the.bytecode.club.bytecodeviewer.util.MiscUtils; - -import java.util.ArrayList; -import java.util.List; - -/** - * An unfinished obfuscator. - * - * @author Konloch - */ - -public abstract class JavaObfuscator extends Thread -{ - - public static int MAX_STRING_LENGTH = 25; - public static int MIN_STRING_LENGTH = 5; - private final List names = new ArrayList<>(); - - @Override - public void run() - { - BytecodeViewer.updateBusyStatus(true); - Configuration.runningObfuscation = true; - - obfuscate(); - - BytecodeViewer.refactorer.run(); - Configuration.runningObfuscation = false; - BytecodeViewer.updateBusyStatus(false); - } - - public int getStringLength() - { - if (BytecodeViewer.viewer.obfuscatorGroup.isSelected(BytecodeViewer.viewer.strongObf.getModel())) - return MAX_STRING_LENGTH; - else // if(BytecodeViewer.viewer.obfuscatorGroup.isSelected(BytecodeViewer.viewer.lightObf.getModel())) - return MIN_STRING_LENGTH; - } - - protected String generateUniqueName(int length) - { - boolean found = false; - 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; - found = true; - } - } - - return name; - } - - public abstract void obfuscate(); -} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameClasses.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameClasses.java deleted file mode 100644 index e5e42228a..000000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameClasses.java +++ /dev/null @@ -1,50 +0,0 @@ -/*************************************************************************** - * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * - * Copyright (C) 2014 Konloch - Konloch.com / BytecodeViewer.com * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - ***************************************************************************/ - -package the.bytecode.club.bytecodeviewer.obfuscators; - -import org.objectweb.asm.tree.ClassNode; -import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.api.ASMResourceUtil; - -/** - * Rename classes. - * - * @author Konloch - */ - -public class RenameClasses extends JavaObfuscator -{ - - @Override - public void obfuscate() - { - int stringLength = getStringLength(); - - System.out.println("Obfuscating class names..."); - - for (ClassNode c : BytecodeViewer.getLoadedClasses()) - { - String newName = generateUniqueName(stringLength); - ASMResourceUtil.renameClassNode(c.name, newName); - c.name = newName; - } - - System.out.println("Obfuscated class names."); - } -} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameFields.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameFields.java deleted file mode 100644 index 8fbb48ebb..000000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameFields.java +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************** - * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * - * Copyright (C) 2014 Konloch - Konloch.com / BytecodeViewer.com * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - ***************************************************************************/ - -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.ASMResourceUtil; - -/** - * Rename fields. - * - * @author Konloch - */ - -public class RenameFields extends JavaObfuscator -{ - - @Override - public void obfuscate() - { - int stringLength = getStringLength(); - - System.out.println("Obfuscating fields names..."); - - for (ClassNode c : BytecodeViewer.getLoadedClasses()) - { - for (Object o : c.fields.toArray()) - { - FieldNode f = (FieldNode) o; - String newName = generateUniqueName(stringLength); - ASMResourceUtil.renameFieldNode(c.name, f.name, f.desc, - null, newName, null); - f.name = newName; - } - } - - System.out.println("Obfuscated field names."); - } -} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameMethods.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameMethods.java deleted file mode 100644 index bb73264fb..000000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/RenameMethods.java +++ /dev/null @@ -1,62 +0,0 @@ -/*************************************************************************** - * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * - * Copyright (C) 2014 Konloch - Konloch.com / BytecodeViewer.com * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - ***************************************************************************/ - -package the.bytecode.club.bytecodeviewer.obfuscators; - -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.ASMResourceUtil; - -/** - * Rename methods. - * - * @author Konloch - */ - -public class RenameMethods extends JavaObfuscator -{ - - @Override - public void obfuscate() - { - int stringLength = getStringLength(); - - System.out.println("Obfuscating method names..."); - - for (ClassNode c : BytecodeViewer.getLoadedClasses()) - { - for (Object o : c.methods.toArray()) - { - MethodNode m = (MethodNode) o; - if (m.access != Opcodes.ACC_ABSTRACT && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC + Opcodes.ACC_PRIVATE && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC + Opcodes.ACC_PROTECTED && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_PUBLIC && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_PRIVATE && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_PROTECTED) - { - if (!m.name.equals("main") && !m.name.equals("") && !m.name.equals("")) - { - String newName = generateUniqueName(stringLength); - ASMResourceUtil.renameMethodNode(c.name, m.name, m.desc, - null, newName, null); - } - } - } - } - - System.out.println("Obfuscated method names."); - } -} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/HookMap.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/HookMap.java deleted file mode 100644 index e64736a41..000000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/HookMap.java +++ /dev/null @@ -1,71 +0,0 @@ -/*************************************************************************** - * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * - * Copyright (C) 2014 Konloch - Konloch.com / BytecodeViewer.com * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - ***************************************************************************/ - -package the.bytecode.club.bytecodeviewer.obfuscators.mapping; - -import the.bytecode.club.bytecodeviewer.obfuscators.mapping.data.FieldMappingData; -import the.bytecode.club.bytecodeviewer.obfuscators.mapping.data.MappingData; -import the.bytecode.club.bytecodeviewer.obfuscators.mapping.data.MethodMappingData; - -import java.util.ArrayList; -import java.util.List; - -public class HookMap -{ - - protected List classes; - protected List fields; - protected List methods; - - public HookMap() - { - classes = new ArrayList<>(); - fields = new ArrayList<>(); - methods = new ArrayList<>(); - } - - public void addClass(MappingData clazz) - { - classes.add(clazz); - } - - public void addField(FieldMappingData field) - { - fields.add(field); - } - - public void addMethod(MethodMappingData method) - { - methods.add(method); - } - - public List getClasses() - { - return classes; - } - - public List getFields() - { - return fields; - } - - public List getMethods() - { - return methods; - } -} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RefactorMapper.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RefactorMapper.java deleted file mode 100644 index a6feb712f..000000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RefactorMapper.java +++ /dev/null @@ -1,134 +0,0 @@ -/*************************************************************************** - * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * - * Copyright (C) 2014 Konloch - Konloch.com / BytecodeViewer.com * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - ***************************************************************************/ - -package the.bytecode.club.bytecodeviewer.obfuscators.mapping; - -import the.bytecode.club.bytecodeviewer.obfuscators.mapping.data.FieldMappingData; -import the.bytecode.club.bytecodeviewer.obfuscators.mapping.data.MappingData; -import the.bytecode.club.bytecodeviewer.obfuscators.mapping.data.MethodMappingData; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -/** - * @author sc4re - */ -public class RefactorMapper extends Remapper -{ - - protected final Map sortedClasses; - protected final Map sortedMethods; - protected final Map sortedFields; - protected final List mappingList; - - private final 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; - String obfuscatedName = hook.getObfuscatedName(); - String refactoredName = hook.getRefactoredName(); - sortedClasses.put(obfuscatedName, hook); - sortedClasses.put(refactoredName, hook); - } - - for (MethodMappingData hook : hookMap.getMethods()) - { - String obfuscatedName = hook.getMethodName().getObfuscatedName(); - String obfuscatedDesc = hook.getMethodDesc(); - String obfuscatedCname = hook.getMethodOwner(); - sortedMethods.put(obfuscatedCname + "$$$$" + obfuscatedName + "$$$$" + obfuscatedDesc, hook); - } - - for (FieldMappingData hook : hookMap.getFields()) - { - String obfuscatedName = hook.getName().getObfuscatedName(); - String obfuscatedDesc = hook.getDesc(); - String obfuscatedCname = hook.getFieldOwner(); - sortedFields.put(obfuscatedCname + "$$$$" + obfuscatedName + "$$$$" + obfuscatedDesc, hook); - } - } - - @Override - public String map(String type) - { - if (sortedClasses.containsKey(type)) - { - String map = 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)) - { - String map = 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)) - { - String map = 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/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Refactorer.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Refactorer.java deleted file mode 100644 index 3a4d9b91b..000000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Refactorer.java +++ /dev/null @@ -1,77 +0,0 @@ -/*************************************************************************** - * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * - * Copyright (C) 2014 Konloch - Konloch.com / BytecodeViewer.com * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - ***************************************************************************/ - -package the.bytecode.club.bytecodeviewer.obfuscators.mapping; - -import org.objectweb.asm.ClassReader; -import org.objectweb.asm.ClassWriter; -import org.objectweb.asm.tree.ClassNode; -import the.bytecode.club.bytecodeviewer.BytecodeViewer; - -/** - * @author sc4re - */ -public class Refactorer -{ - - protected HookMap hooks; - - public Refactorer() - { - hooks = new HookMap(); - } - - public HookMap getHooks() - { - return hooks; - } - - public void run() - { - if (getHooks() == null) - return; - - RefactorMapper mapper = new RefactorMapper(getHooks()); - //Map refactored = new HashMap<>(); - for (ClassNode cn : BytecodeViewer.getLoadedClasses()) - { - //String oldName = cn.name; - ClassReader cr = new ClassReader(getClassNodeBytes(cn)); - ClassWriter cw = new ClassWriter(cr, 0); - RemappingClassAdapter rca = new RemappingClassAdapter(cw, mapper); - cr.accept(rca, ClassReader.EXPAND_FRAMES); - cr = new ClassReader(cw.toByteArray()); - cn = new ClassNode(); - cr.accept(cn, 0); - //refactored.put(oldName, cn); - } - - /*for (Map.Entry factor : refactored.entrySet()) { - BytecodeViewer.relocate(factor.getKey(), factor.getValue()); - }*/ - - mapper.printMap(); - } - - private byte[] getClassNodeBytes(ClassNode cn) - { - ClassWriter cw = new ClassWriter(0); - cn.accept(cw); - return cw.toByteArray(); - } -} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Remapper.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Remapper.java deleted file mode 100644 index 650a48c23..000000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/Remapper.java +++ /dev/null @@ -1,267 +0,0 @@ -/*** - * ASM: a very small and fast Java bytecode manipulation framework - * Copyright (c) 2000-2011 INRIA, France Telecom - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -package the.bytecode.club.bytecodeviewer.obfuscators.mapping; - -import org.objectweb.asm.Handle; -import org.objectweb.asm.Opcodes; -import org.objectweb.asm.Type; -import org.objectweb.asm.signature.SignatureReader; -import org.objectweb.asm.signature.SignatureVisitor; -import org.objectweb.asm.signature.SignatureWriter; - -/** - * A class responsible for remapping types and names. Subclasses can override - * the following methods: - *

- *

    - *
  • {@link #map(String)} - map type
  • - *
  • {@link #mapFieldName(String, String, String)} - map field name
  • - *
  • {@link #mapMethodName(String, String, String)} - map method name
  • - *
- * - * @author Eugene Kuleshov - */ -public abstract class Remapper extends org.objectweb.asm.commons.Remapper -{ - - @Override - public String mapDesc(String desc) - { - Type t = Type.getType(desc); - - switch (t.getSort()) - { - case Type.ARRAY: - StringBuilder s = new StringBuilder(mapDesc(t.getElementType().getDescriptor())); - - for (int i = 0; i < t.getDimensions(); ++i) - { - s.insert(0, '['); - } - - return s.toString(); - - case Type.OBJECT: - String newType = map(t.getInternalName()); - - if (newType != null) - return 'L' + newType + ';'; - } - - return desc; - } - - private Type mapType(Type t) - { - switch (t.getSort()) - { - case Type.ARRAY: - StringBuilder s = new StringBuilder(mapDesc(t.getElementType().getDescriptor())); - - for (int i = 0; i < t.getDimensions(); ++i) - { - s.insert(0, '['); - } - - return Type.getType(s.toString()); - - case Type.OBJECT: - s = new StringBuilder(map(t.getInternalName())); - return Type.getObjectType(s.toString()); - - case Type.METHOD: - return Type.getMethodType(mapMethodDesc(t.getDescriptor())); - } - - return t; - } - - @Override - public String mapType(String type) - { - if (type == null) - return null; - - return mapType(Type.getObjectType(type)).getInternalName(); - } - - @Override - public String[] mapTypes(String[] types) - { - String[] newTypes = null; - boolean needMapping = false; - - for (int i = 0; i < types.length; i++) - { - String type = types[i]; - String newType = map(type); - - if (newType != null && newTypes == null) - { - newTypes = new String[types.length]; - - if (i > 0) - System.arraycopy(types, 0, newTypes, 0, i); - - needMapping = true; - } - - if (needMapping) - newTypes[i] = newType == null ? type : newType; - } - - return needMapping ? newTypes : types; - } - - @Override - public String mapMethodDesc(String desc) - { - if ("()V".equals(desc)) - return desc; - - Type[] args = Type.getArgumentTypes(desc); - StringBuilder sb = new StringBuilder("("); - - for (Type arg : args) - { - sb.append(mapDesc(arg.getDescriptor())); - } - - Type returnType = Type.getReturnType(desc); - - if (returnType == Type.VOID_TYPE) - { - sb.append(")V"); - return sb.toString(); - } - - sb.append(')').append(mapDesc(returnType.getDescriptor())); - return sb.toString(); - } - - @Override - public Object mapValue(Object value) - { - if (value instanceof Type) - return mapType((Type) value); - - if (value instanceof Handle) - { - Handle h = (Handle) value; - return new Handle(h.getTag(), - mapType(h.getOwner()), - mapMethodName(h.getOwner(), h.getName(), h.getDesc()), - mapMethodDesc(h.getDesc()), - h.getTag() == Opcodes.H_INVOKEINTERFACE); - } - - return value; - } - - /** - * @param typeSignature true if signature is a FieldTypeSignature, such as the - * signature parameter of the ClassVisitor.visitField or - * MethodVisitor.visitLocalVariable methods - */ - @Override - public String mapSignature(String signature, boolean typeSignature) - { - if (signature == null) - return null; - - SignatureReader r = new SignatureReader(signature); - SignatureWriter w = new SignatureWriter(); - SignatureVisitor a = createSignatureRemapper(w); - - if (typeSignature) - r.acceptType(a); - else - r.accept(a); - - return w.toString(); - } - - @Override - protected SignatureVisitor createSignatureRemapper(SignatureVisitor v) - { - return new RemappingSignatureAdapter(v, this); - } - - /** - * Map method name to the new name. Subclasses can override. - * - * @param owner owner of the method. - * @param name name of the method. - * @param desc descriptor of the method. - * @return new name of the method - */ - @Override - public String mapMethodName(String owner, String name, String desc) - { - return name; - } - - /** - * Map invokedynamic method name to the new name. Subclasses can override. - * - * @param name name of the invokedynamic. - * @param desc descriptor of the invokedynamic. - * @return new invokdynamic name. - */ - @Override - public String mapInvokeDynamicMethodName(String name, String desc) - { - return name; - } - - /** - * Map field name to the new name. Subclasses can override. - * - * @param owner owner of the field. - * @param name name of the field - * @param desc descriptor of the field - * @return new name of the field. - */ - @Override - public String mapFieldName(String owner, String name, String desc) - { - return name; - } - - /** - * Map type name to the new name. Subclasses can override. - */ - @Override - public String map(String typeName) - { - return typeName; - } -} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RemappingAnnotationAdapter.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RemappingAnnotationAdapter.java deleted file mode 100644 index f89ecd9e7..000000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RemappingAnnotationAdapter.java +++ /dev/null @@ -1,83 +0,0 @@ -/*** - * ASM: a very small and fast Java bytecode manipulation framework - * Copyright (c) 2000-2011 INRIA, France Telecom - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -package the.bytecode.club.bytecodeviewer.obfuscators.mapping; - -import org.objectweb.asm.AnnotationVisitor; -import org.objectweb.asm.commons.Remapper; -import the.bytecode.club.bytecodeviewer.Constants; - -/** - * An {@link AnnotationVisitor} adapter for type remapping. - * - * @author Eugene Kuleshov - */ -public class RemappingAnnotationAdapter extends AnnotationVisitor -{ - - protected final Remapper remapper; - - public RemappingAnnotationAdapter(AnnotationVisitor av, Remapper remapper) - { - this(Constants.ASM_VERSION, av, remapper); - } - - protected RemappingAnnotationAdapter(int api, AnnotationVisitor av, Remapper remapper) - { - super(api, av); - this.remapper = remapper; - } - - @Override - public void visit(String name, Object value) - { - av.visit(name, remapper.mapValue(value)); - } - - @Override - public void visitEnum(String name, String desc, String value) - { - av.visitEnum(name, remapper.mapDesc(desc), value); - } - - @Override - public AnnotationVisitor visitAnnotation(String name, String desc) - { - AnnotationVisitor v = av.visitAnnotation(name, remapper.mapDesc(desc)); - return v == null ? null : (v == av ? this : new RemappingAnnotationAdapter(v, remapper)); - } - - @Override - public AnnotationVisitor visitArray(String name) - { - AnnotationVisitor v = av.visitArray(name); - return v == null ? null : (v == av ? this : new RemappingAnnotationAdapter(v, remapper)); - } -} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RemappingClassAdapter.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RemappingClassAdapter.java deleted file mode 100644 index bd5ef9838..000000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RemappingClassAdapter.java +++ /dev/null @@ -1,123 +0,0 @@ -/*** - * ASM: a very small and fast Java bytecode manipulation framework - * Copyright (c) 2000-2011 INRIA, France Telecom - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -package the.bytecode.club.bytecodeviewer.obfuscators.mapping; - -import org.objectweb.asm.*; -import the.bytecode.club.bytecodeviewer.Constants; - -/** - * A {@link ClassVisitor} for type remapping. - * - * @author Eugene Kuleshov - */ -public class RemappingClassAdapter extends ClassVisitor -{ - - protected final Remapper remapper; - - protected String className; - - public RemappingClassAdapter(ClassVisitor cv, Remapper remapper) - { - this(Constants.ASM_VERSION, cv, remapper); - } - - protected RemappingClassAdapter(int api, ClassVisitor cv, Remapper remapper) - { - super(api, cv); - this.remapper = remapper; - } - - @Override - public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) - { - this.className = name; - super.visit(version, access, remapper.mapType(name), remapper.mapSignature(signature, false), remapper.mapType(superName), interfaces == null ? null : remapper.mapTypes(interfaces)); - } - - @Override - public AnnotationVisitor visitAnnotation(String desc, boolean visible) - { - AnnotationVisitor av = super.visitAnnotation(remapper.mapDesc(desc), visible); - return av == null ? null : createRemappingAnnotationAdapter(av); - } - - @Override - public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) - { - AnnotationVisitor av = super.visitTypeAnnotation(typeRef, typePath, remapper.mapDesc(desc), visible); - return av == null ? null : createRemappingAnnotationAdapter(av); - } - - @Override - public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) - { - FieldVisitor fv = super.visitField(access, remapper.mapFieldName(className, name, desc), remapper.mapDesc(desc), remapper.mapSignature(signature, true), remapper.mapValue(value)); - return fv == null ? null : createRemappingFieldAdapter(fv); - } - - @Override - public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) - { - String newDesc = remapper.mapMethodDesc(desc); - MethodVisitor mv = super.visitMethod(access, remapper.mapMethodName(className, name, desc), newDesc, remapper.mapSignature(signature, false), exceptions == null ? null : remapper.mapTypes(exceptions)); - return mv == null ? null : createRemappingMethodAdapter(access, newDesc, mv); - } - - @Override - public void visitInnerClass(String name, String outerName, String innerName, int access) - { - // TODO should innerName be changed? - super.visitInnerClass(remapper.mapType(name), outerName == null ? null : remapper.mapType(outerName), innerName, access); - } - - @Override - public void visitOuterClass(String owner, String name, String desc) - { - super.visitOuterClass(remapper.mapType(owner), name == null ? null : remapper.mapMethodName(owner, name, desc), desc == null ? null : remapper.mapMethodDesc(desc)); - } - - protected FieldVisitor createRemappingFieldAdapter(FieldVisitor fv) - { - return new RemappingFieldAdapter(fv, remapper); - } - - protected MethodVisitor createRemappingMethodAdapter(int access, String newDesc, MethodVisitor mv) - { - return new RemappingMethodAdapter(access, newDesc, mv, remapper); - } - - protected AnnotationVisitor createRemappingAnnotationAdapter(AnnotationVisitor av) - { - return new RemappingAnnotationAdapter(av, remapper); - } -} - diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RemappingFieldAdapter.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RemappingFieldAdapter.java deleted file mode 100644 index f3f6c7e69..000000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RemappingFieldAdapter.java +++ /dev/null @@ -1,73 +0,0 @@ -/*** - * ASM: a very small and fast Java bytecode manipulation framework - * Copyright (c) 2000-2011 INRIA, France Telecom - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -package the.bytecode.club.bytecodeviewer.obfuscators.mapping; - -import org.objectweb.asm.AnnotationVisitor; -import org.objectweb.asm.FieldVisitor; -import org.objectweb.asm.TypePath; -import org.objectweb.asm.commons.Remapper; -import the.bytecode.club.bytecodeviewer.Constants; - -/** - * A {@link FieldVisitor} adapter for type remapping. - * - * @author Eugene Kuleshov - */ -public class RemappingFieldAdapter extends FieldVisitor -{ - - private final org.objectweb.asm.commons.Remapper remapper; - - public RemappingFieldAdapter(FieldVisitor fv, org.objectweb.asm.commons.Remapper remapper) - { - this(Constants.ASM_VERSION, fv, remapper); - } - - protected RemappingFieldAdapter(int api, FieldVisitor fv, Remapper remapper) - { - super(api, fv); - this.remapper = remapper; - } - - @Override - public AnnotationVisitor visitAnnotation(String desc, boolean visible) - { - AnnotationVisitor av = fv.visitAnnotation(remapper.mapDesc(desc), visible); - return av == null ? null : new RemappingAnnotationAdapter(av, remapper); - } - - @Override - public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) - { - AnnotationVisitor av = super.visitTypeAnnotation(typeRef, typePath, remapper.mapDesc(desc), visible); - return av == null ? null : new RemappingAnnotationAdapter(av, remapper); - } -} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RemappingMethodAdapter.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RemappingMethodAdapter.java deleted file mode 100644 index f08ea1231..000000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RemappingMethodAdapter.java +++ /dev/null @@ -1,221 +0,0 @@ -/*** - * ASM: a very small and fast Java bytecode manipulation framework - * Copyright (c) 2000-2011 INRIA, France Telecom - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -package the.bytecode.club.bytecodeviewer.obfuscators.mapping; - -import org.objectweb.asm.*; -import org.objectweb.asm.commons.LocalVariablesSorter; -import org.objectweb.asm.commons.Remapper; -import the.bytecode.club.bytecodeviewer.Constants; - -/** - * A {@link LocalVariablesSorter} for type mapping. - * - * @author Eugene Kuleshov - */ -public class RemappingMethodAdapter extends LocalVariablesSorter -{ - - protected final org.objectweb.asm.commons.Remapper remapper; - - public RemappingMethodAdapter(int access, String desc, MethodVisitor mv, org.objectweb.asm.commons.Remapper remapper) - { - this(Constants.ASM_VERSION, access, desc, mv, remapper); - } - - protected RemappingMethodAdapter(int api, int access, String desc, MethodVisitor mv, Remapper remapper) - { - super(api, access, desc, mv); - this.remapper = remapper; - } - - @Override - public AnnotationVisitor visitAnnotationDefault() - { - AnnotationVisitor av = super.visitAnnotationDefault(); - return av == null ? null : new RemappingAnnotationAdapter(av, remapper); - } - - @Override - public AnnotationVisitor visitAnnotation(String desc, boolean visible) - { - AnnotationVisitor av = super.visitAnnotation(remapper.mapDesc(desc), visible); - return av == null ? null : new RemappingAnnotationAdapter(av, remapper); - } - - @Override - public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) - { - AnnotationVisitor av = super.visitTypeAnnotation(typeRef, typePath, remapper.mapDesc(desc), visible); - return av == null ? null : new RemappingAnnotationAdapter(av, remapper); - } - - @Override - public AnnotationVisitor visitParameterAnnotation(int parameter, String desc, boolean visible) - { - AnnotationVisitor av = super.visitParameterAnnotation(parameter, remapper.mapDesc(desc), visible); - return av == null ? null : new RemappingAnnotationAdapter(av, remapper); - } - - @Override - public void visitFrame(int type, int nLocal, Object[] local, int nStack, Object[] stack) - { - super.visitFrame(type, nLocal, remapEntries(nLocal, local), nStack, remapEntries(nStack, stack)); - } - - private Object[] remapEntries(int n, Object[] entries) - { - for (int i = 0; i < n; i++) - { - if (entries[i] instanceof String) - { - Object[] newEntries = new Object[n]; - if (i > 0) - { - System.arraycopy(entries, 0, newEntries, 0, i); - } - do - { - Object t = entries[i]; - newEntries[i++] = t instanceof String ? remapper.mapType((String) t) : t; - } while (i < n); - - return newEntries; - } - } - - return entries; - } - - @Override - public void visitFieldInsn(int opcode, String owner, String name, String desc) - { - super.visitFieldInsn(opcode, remapper.mapType(owner), remapper.mapFieldName(owner, name, desc), remapper.mapDesc(desc)); - } - - @Deprecated - @Override - public void visitMethodInsn(int opcode, String owner, String name, String desc) - { - if (api >= Constants.ASM_VERSION) - { - super.visitMethodInsn(opcode, owner, name, desc); - return; - } - - doVisitMethodInsn(opcode, owner, name, desc, opcode == Opcodes.INVOKEINTERFACE); - } - - @Override - public void visitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) - { - if (api < Constants.ASM_VERSION) - { - super.visitMethodInsn(opcode, owner, name, desc, itf); - return; - } - - doVisitMethodInsn(opcode, owner, name, desc, itf); - } - - private void doVisitMethodInsn(int opcode, String owner, String name, String desc, boolean itf) - { - // Calling super.visitMethodInsn requires to call the correct version - // depending on this.api (otherwise infinite loops can occur). To - // simplify and to make it easier to automatically remove the backward - // compatibility code, we inline the code of the overridden method here. - // IMPORTANT: THIS ASSUMES THAT visitMethodInsn IS NOT OVERRIDDEN IN - // LocalVariableSorter. - if (mv != null) - mv.visitMethodInsn(opcode, remapper.mapType(owner), remapper.mapMethodName(owner, name, desc), remapper.mapMethodDesc(desc), itf); - } - - @Override - public void visitInvokeDynamicInsn(String name, String desc, Handle bsm, Object... bsmArgs) - { - for (int i = 0; i < bsmArgs.length; i++) - { - bsmArgs[i] = remapper.mapValue(bsmArgs[i]); - } - - super.visitInvokeDynamicInsn(remapper.mapInvokeDynamicMethodName(name, desc), remapper.mapMethodDesc(desc), (Handle) remapper.mapValue(bsm), bsmArgs); - } - - @Override - public void visitTypeInsn(int opcode, String type) - { - super.visitTypeInsn(opcode, remapper.mapType(type)); - } - - @Override - public void visitLdcInsn(Object cst) - { - super.visitLdcInsn(remapper.mapValue(cst)); - } - - @Override - public void visitMultiANewArrayInsn(String desc, int dims) - { - super.visitMultiANewArrayInsn(remapper.mapDesc(desc), dims); - } - - @Override - public AnnotationVisitor visitInsnAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) - { - AnnotationVisitor av = super.visitInsnAnnotation(typeRef, typePath, remapper.mapDesc(desc), visible); - return av == null ? null : new RemappingAnnotationAdapter(av, remapper); - } - - @Override - public void visitTryCatchBlock(Label start, Label end, Label handler, String type) - { - super.visitTryCatchBlock(start, end, handler, type == null ? null : remapper.mapType(type)); - } - - @Override - public AnnotationVisitor visitTryCatchAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) - { - AnnotationVisitor av = super.visitTryCatchAnnotation(typeRef, typePath, remapper.mapDesc(desc), visible); - return av == null ? null : new RemappingAnnotationAdapter(av, remapper); - } - - @Override - public void visitLocalVariable(String name, String desc, String signature, Label start, Label end, int index) - { - super.visitLocalVariable(name, remapper.mapDesc(desc), remapper.mapSignature(signature, true), start, end, index); - } - - @Override - public AnnotationVisitor visitLocalVariableAnnotation(int typeRef, TypePath typePath, Label[] start, Label[] end, int[] index, String desc, boolean visible) - { - AnnotationVisitor av = super.visitLocalVariableAnnotation(typeRef, typePath, start, end, index, remapper.mapDesc(desc), visible); - return av == null ? null : new RemappingAnnotationAdapter(av, remapper); - } -} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RemappingSignatureAdapter.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RemappingSignatureAdapter.java deleted file mode 100644 index f9fe40e2f..000000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/RemappingSignatureAdapter.java +++ /dev/null @@ -1,172 +0,0 @@ -/*** - * ASM: a very small and fast Java bytecode manipulation framework - * Copyright (c) 2000-2011 INRIA, France Telecom - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the copyright holders nor the names of its - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - * THE POSSIBILITY OF SUCH DAMAGE. - */ - -package the.bytecode.club.bytecodeviewer.obfuscators.mapping; - -import org.objectweb.asm.commons.Remapper; -import org.objectweb.asm.signature.SignatureVisitor; -import the.bytecode.club.bytecodeviewer.Constants; - -/** - * A {@link SignatureVisitor} adapter for type mapping. - * - * @author Eugene Kuleshov - */ -public class RemappingSignatureAdapter extends SignatureVisitor -{ - - private final SignatureVisitor v; - - private final org.objectweb.asm.commons.Remapper remapper; - - private String className; - - public RemappingSignatureAdapter(SignatureVisitor v, Remapper remapper) - { - this(Constants.ASM_VERSION, v, remapper); - } - - protected RemappingSignatureAdapter(int api, SignatureVisitor v, Remapper remapper) - { - super(api); - this.v = v; - this.remapper = remapper; - } - - @Override - public void visitClassType(String name) - { - className = name; - v.visitClassType(remapper.mapType(name)); - } - - @Override - public void visitInnerClassType(String name) - { - String remappedOuter = remapper.mapType(className) + '$'; - className += '$' + name; - String remappedName = remapper.mapType(className); - int index = remappedName.startsWith(remappedOuter) ? remappedOuter.length() : remappedName.lastIndexOf('$') + 1; - v.visitInnerClassType(remappedName.substring(index)); - } - - @Override - public void visitFormalTypeParameter(String name) - { - v.visitFormalTypeParameter(name); - } - - @Override - public void visitTypeVariable(String name) - { - v.visitTypeVariable(name); - } - - @Override - public SignatureVisitor visitArrayType() - { - v.visitArrayType(); - return this; - } - - @Override - public void visitBaseType(char descriptor) - { - v.visitBaseType(descriptor); - } - - @Override - public SignatureVisitor visitClassBound() - { - v.visitClassBound(); - return this; - } - - @Override - public SignatureVisitor visitExceptionType() - { - v.visitExceptionType(); - return this; - } - - @Override - public SignatureVisitor visitInterface() - { - v.visitInterface(); - return this; - } - - @Override - public SignatureVisitor visitInterfaceBound() - { - v.visitInterfaceBound(); - return this; - } - - @Override - public SignatureVisitor visitParameterType() - { - v.visitParameterType(); - return this; - } - - @Override - public SignatureVisitor visitReturnType() - { - v.visitReturnType(); - return this; - } - - @Override - public SignatureVisitor visitSuperclass() - { - v.visitSuperclass(); - return this; - } - - @Override - public void visitTypeArgument() - { - v.visitTypeArgument(); - } - - @Override - public SignatureVisitor visitTypeArgument(char wildcard) - { - v.visitTypeArgument(wildcard); - return this; - } - - @Override - public void visitEnd() - { - v.visitEnd(); - } -} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/data/FieldMappingData.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/data/FieldMappingData.java deleted file mode 100644 index 717218684..000000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/data/FieldMappingData.java +++ /dev/null @@ -1,117 +0,0 @@ -/*************************************************************************** - * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * - * Copyright (C) 2014 Konloch - Konloch.com / BytecodeViewer.com * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - ***************************************************************************/ - -package the.bytecode.club.bytecodeviewer.obfuscators.mapping.data; - -public class FieldMappingData -{ - - protected String fieldOwner; - protected MappingData name; - protected String desc; - - public FieldMappingData(MappingData name, String desc) - { - this("", name, desc); - } - - public FieldMappingData(String fieldOwner, MappingData name, String desc) - { - this.fieldOwner = fieldOwner; - this.name = name; - this.desc = desc; - } - - public String getFieldOwner() - { - return fieldOwner; - } - - public FieldMappingData setFieldOwner(String fieldOwner) - { - this.fieldOwner = fieldOwner; - return this; - } - - public MappingData getName() - { - return name; - } - - public FieldMappingData setName(MappingData name) - { - this.name = name; - return this; - } - - public String getDesc() - { - return desc; - } - - public FieldMappingData setDesc(String desc) - { - this.desc = desc; - return this; - } - - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = (prime * result) + ((desc == null) ? 0 : desc.hashCode()); - result = (prime * result) + ((fieldOwner == null) ? 0 : fieldOwner.hashCode()); - result = (prime * result) + ((name == null) ? 0 : name.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) - { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - - FieldMappingData other = (FieldMappingData) obj; - - if (desc == null) - { - if (other.desc != null) - return false; - } - else if (!desc.equals(other.desc)) - return false; - - if (fieldOwner == null) - { - if (other.fieldOwner != null) - return false; - } - else if (!fieldOwner.equals(other.fieldOwner)) - return false; - - if (name == null) - return other.name == null; - else - return name.equals(other.name); - } -} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/data/MappingData.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/data/MappingData.java deleted file mode 100644 index cd3487012..000000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/data/MappingData.java +++ /dev/null @@ -1,95 +0,0 @@ -/*************************************************************************** - * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * - * Copyright (C) 2014 Konloch - Konloch.com / BytecodeViewer.com * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - ***************************************************************************/ - -package the.bytecode.club.bytecodeviewer.obfuscators.mapping.data; - -public class MappingData -{ - - protected String obfuscatedName; - protected String refactoredName; - - public MappingData(String refactoredName) - { - this("", refactoredName); - } - - public MappingData(String obfuscatedName, String refactoredName) - { - this.obfuscatedName = obfuscatedName; - this.refactoredName = refactoredName; - } - - public String getObfuscatedName() - { - return obfuscatedName; - } - - public MappingData setObfuscatedName(String obfuscatedName) - { - this.obfuscatedName = obfuscatedName; - return this; - } - - public String getRefactoredName() - { - return refactoredName; - } - - public MappingData setRefactoredName(String refactoredName) - { - this.refactoredName = refactoredName; - return this; - } - - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = (prime * result) + ((obfuscatedName == null) ? 0 : obfuscatedName.hashCode()); - result = (prime * result) + ((refactoredName == null) ? 0 : refactoredName.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) - { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - - MappingData other = (MappingData) obj; - - if (obfuscatedName == null) - { - if (other.obfuscatedName != null) - return false; - } - else if (!obfuscatedName.equals(other.obfuscatedName)) - return false; - - if (refactoredName == null) - return other.refactoredName == null; - else - return refactoredName.equals(other.refactoredName); - } -} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/data/MethodMappingData.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/data/MethodMappingData.java deleted file mode 100644 index 1e3cb37b5..000000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/mapping/data/MethodMappingData.java +++ /dev/null @@ -1,117 +0,0 @@ -/*************************************************************************** - * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * - * Copyright (C) 2014 Konloch - Konloch.com / BytecodeViewer.com * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - ***************************************************************************/ - -package the.bytecode.club.bytecodeviewer.obfuscators.mapping.data; - -public class MethodMappingData -{ - - protected String methodOwner; - protected MappingData methodName; - protected String methodDesc; - - public MethodMappingData(MappingData methodName, String methodDesc) - { - this("", methodName, methodDesc); - } - - public MethodMappingData(String methodOwner, MappingData methodName, String methodDesc) - { - this.methodOwner = methodOwner; - this.methodName = methodName; - this.methodDesc = methodDesc; - } - - public String getMethodOwner() - { - return methodOwner; - } - - public MethodMappingData setMethodOwner(String methodOwner) - { - this.methodOwner = methodOwner; - return this; - } - - public MappingData getMethodName() - { - return methodName; - } - - public MethodMappingData setMethodName(MappingData methodName) - { - this.methodName = methodName; - return this; - } - - public String getMethodDesc() - { - return methodDesc; - } - - public MethodMappingData setMethodDesc(String methodDesc) - { - this.methodDesc = methodDesc; - return this; - } - - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = (prime * result) + ((methodDesc == null) ? 0 : methodDesc.hashCode()); - result = (prime * result) + ((methodName == null) ? 0 : methodName.hashCode()); - result = (prime * result) + ((methodOwner == null) ? 0 : methodOwner.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) - { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - - MethodMappingData other = (MethodMappingData) obj; - - if (methodDesc == null) - { - if (other.methodDesc != null) - return false; - } - else if (!methodDesc.equals(other.methodDesc)) - return false; - - if (methodName == null) - { - if (other.methodName != null) - return false; - } - else if (!methodName.equals(other.methodName)) - return false; - - if (methodOwner == null) - return other.methodOwner == null; - else - return methodOwner.equals(other.methodOwner); - } -} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameClasses.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameClasses.java deleted file mode 100644 index d4d406dd3..000000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameClasses.java +++ /dev/null @@ -1,82 +0,0 @@ -/*************************************************************************** - * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * - * Copyright (C) 2014 Konloch - Konloch.com / BytecodeViewer.com * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - ***************************************************************************/ - -package the.bytecode.club.bytecodeviewer.obfuscators.rename; - -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.Configuration; -import the.bytecode.club.bytecodeviewer.obfuscators.JavaObfuscator; -import the.bytecode.club.bytecodeviewer.obfuscators.mapping.data.MappingData; - -/** - * Rename classes. - * - * @author Konloch - */ - -public class RenameClasses extends JavaObfuscator -{ - - public static void open() - { - if (Configuration.runningObfuscation) - { - BytecodeViewer.showMessage("You're currently running an obfuscation task, wait for this to finish."); - return; - } - - new RenameClasses().start(); - - BytecodeViewer.viewer.workPane.refreshClass.doClick(); - BytecodeViewer.viewer.resourcePane.tree.updateUI(); - } - - @Override - public void obfuscate() - { - int stringLength = 5;//getStringLength(); - - System.out.println("Obfuscating class names..."); - classLoop: - for (ClassNode c : BytecodeViewer.getLoadedClasses()) - { - - /* As we dont want to rename classes that contain native dll methods */ - for (MethodNode o : c.methods) - { - /* As we dont want to rename any main-classes */ - if (o.name.equals("main") && o.desc.equals("([Ljava/lang/String;)V") - || o.name.equals("init") && c.superName.equals("java/applet/Applet")) - continue classLoop; - - /* As we dont want to rename native dll methods */ - if ((o.access & Opcodes.ACC_NATIVE) != 0) - continue classLoop; - } - - String newName = generateUniqueName(stringLength); - - BytecodeViewer.refactorer.getHooks().addClass(new MappingData(c.name, newName)); - } - - System.out.println("Obfuscated class names."); - } -} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameFields.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameFields.java deleted file mode 100644 index c7434bd63..000000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameFields.java +++ /dev/null @@ -1,72 +0,0 @@ -/*************************************************************************** - * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * - * Copyright (C) 2014 Konloch - Konloch.com / BytecodeViewer.com * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - ***************************************************************************/ - -package the.bytecode.club.bytecodeviewer.obfuscators.rename; - -import org.objectweb.asm.tree.ClassNode; -import org.objectweb.asm.tree.FieldNode; -import the.bytecode.club.bytecodeviewer.BytecodeViewer; -import the.bytecode.club.bytecodeviewer.Configuration; -import the.bytecode.club.bytecodeviewer.obfuscators.JavaObfuscator; -import the.bytecode.club.bytecodeviewer.obfuscators.mapping.data.FieldMappingData; -import the.bytecode.club.bytecodeviewer.obfuscators.mapping.data.MappingData; - -/** - * Rename fields. - * - * @author Konloch - */ - -public class RenameFields extends JavaObfuscator -{ - - public static void open() - { - if (Configuration.runningObfuscation) - { - BytecodeViewer.showMessage("You're currently running an obfuscation task, wait for this to finish."); - return; - } - - new RenameFields().start(); - - BytecodeViewer.viewer.workPane.refreshClass.doClick(); - BytecodeViewer.viewer.resourcePane.tree.updateUI(); - } - - @Override - public void obfuscate() - { - int stringLength = getStringLength(); - - System.out.println("Obfuscating fields names..."); - for (ClassNode c : BytecodeViewer.getLoadedClasses()) - { - for (Object o : c.fields.toArray()) - { - FieldNode f = (FieldNode) o; - - String newName = generateUniqueName(stringLength); - - BytecodeViewer.refactorer.getHooks().addField(new FieldMappingData(c.name, new MappingData(f.name, newName), f.desc)); - } - } - - System.out.println("Obfuscated field names."); - } -} diff --git a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameMethods.java b/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameMethods.java deleted file mode 100644 index 9a3765e5b..000000000 --- a/src/main/java/the/bytecode/club/bytecodeviewer/obfuscators/rename/RenameMethods.java +++ /dev/null @@ -1,90 +0,0 @@ -/*************************************************************************** - * Bytecode Viewer (BCV) - Java & Android Reverse Engineering Suite * - * Copyright (C) 2014 Konloch - Konloch.com / BytecodeViewer.com * - * * - * This program is free software: you can redistribute it and/or modify * - * it under the terms of the GNU General Public License as published by * - * the Free Software Foundation, either version 3 of the License, or * - * (at your option) any later version. * - * * - * This program is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU General Public License for more details. * - * * - * You should have received a copy of the GNU General Public License * - * along with this program. If not, see . * - ***************************************************************************/ - -package the.bytecode.club.bytecodeviewer.obfuscators.rename; - -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.Configuration; -import the.bytecode.club.bytecodeviewer.obfuscators.JavaObfuscator; -import the.bytecode.club.bytecodeviewer.obfuscators.mapping.data.MappingData; -import the.bytecode.club.bytecodeviewer.obfuscators.mapping.data.MethodMappingData; - -/** - * Rename methods. - * - * @author Konloch - */ - -public class RenameMethods extends JavaObfuscator -{ - - public static void open() - { - if (Configuration.runningObfuscation) - { - BytecodeViewer.showMessage("You're currently running an obfuscation task, wait for this to finish."); - return; - } - - new RenameMethods().start(); - - BytecodeViewer.viewer.workPane.refreshClass.doClick(); - BytecodeViewer.viewer.resourcePane.tree.updateUI(); - } - - @Override - public void obfuscate() - { - int stringLength = getStringLength(); - - System.out.println("Obfuscating method names..."); - for (ClassNode c : BytecodeViewer.getLoadedClasses()) - { - for (Object o : c.methods.toArray()) - { - MethodNode m = (MethodNode) o; - - /* As we dont want to rename native dll methods */ - if ((m.access & Opcodes.ACC_NATIVE) != 0) - continue; - - if (m.access != Opcodes.ACC_ABSTRACT - && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC - && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC + Opcodes.ACC_PUBLIC - && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC + Opcodes.ACC_PRIVATE - && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_STATIC + Opcodes.ACC_PROTECTED - && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_PUBLIC - && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_PRIVATE - && m.access != Opcodes.ACC_ABSTRACT + Opcodes.ACC_PROTECTED) - { - if (!m.name.equals("main") && !m.name.equals("") && !m.name.equals("")) - { - String newName = generateUniqueName(stringLength); - - BytecodeViewer.refactorer.getHooks().addMethod(new MethodMappingData(c.name, new MappingData(m.name, newName), m.desc)); - } - } - } - } - - System.out.println("Obfuscated method names."); - } -}