Merge pull request #23 from im-frizzy/master

Obfuscation - Renaming
This commit is contained in:
Kalen (Konloch) Kinloch 2015-02-28 20:30:15 -08:00
commit 1799890f7a
13 changed files with 3449 additions and 2947 deletions

View file

@ -14,6 +14,7 @@ import java.net.URI;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry; import java.util.Map.Entry;
import javax.swing.JDialog; import javax.swing.JDialog;
@ -36,6 +37,7 @@ import the.bytecode.club.bytecodeviewer.gui.MainViewerGUI;
import the.bytecode.club.bytecodeviewer.gui.SearchingPane; import the.bytecode.club.bytecodeviewer.gui.SearchingPane;
import the.bytecode.club.bytecodeviewer.gui.SystemErrConsole; import the.bytecode.club.bytecodeviewer.gui.SystemErrConsole;
import the.bytecode.club.bytecodeviewer.gui.WorkPane; import the.bytecode.club.bytecodeviewer.gui.WorkPane;
import the.bytecode.club.bytecodeviewer.obfuscators.mapping.Refactorer;
/** /**
* A lightweight Java Reverse Engineering suite, developed by Konloch - * A lightweight Java Reverse Engineering suite, developed by Konloch -
@ -117,6 +119,11 @@ public class BytecodeViewer {
public static String lastDirectory = ""; public static String lastDirectory = "";
public static ArrayList<Process> krakatau = new ArrayList<Process>(); public static ArrayList<Process> krakatau = new ArrayList<Process>();
/* ASM Re-mapping Constants */
public static Refactorer refactorer = new Refactorer();
public static List<String> main_classes = new ArrayList<>();
/* ASM Re-mapping Constants */
/** /**
* The version checker thread * The version checker thread
*/ */
@ -383,6 +390,18 @@ public class BytecodeViewer {
BytecodeViewer.loadedClasses.put(oldNode.name, newNode); BytecodeViewer.loadedClasses.put(oldNode.name, newNode);
} }
/**
* Replaces an old node with a new instance
* @param oldNode the old instance
* @param newNode the new instance
*/
public static void relocate(String name, ClassNode node) {
if (BytecodeViewer.loadedClasses.containsKey(name))
BytecodeViewer.loadedClasses.remove(name);
BytecodeViewer.loadedClasses.put(node.name, node);
}
/** /**
* Gets all of the loaded classes as an array list * Gets all of the loaded classes as an array list
* @return the loaded classes as an array list * @return the loaded classes as an array list

View file

@ -39,9 +39,9 @@ import the.bytecode.club.bytecodeviewer.decompilers.FernFlowerDecompiler;
import the.bytecode.club.bytecodeviewer.decompilers.Decompiler; import the.bytecode.club.bytecodeviewer.decompilers.Decompiler;
import the.bytecode.club.bytecodeviewer.decompilers.KrakatauDecompiler; import the.bytecode.club.bytecodeviewer.decompilers.KrakatauDecompiler;
import the.bytecode.club.bytecodeviewer.decompilers.ProcyonDecompiler; import the.bytecode.club.bytecodeviewer.decompilers.ProcyonDecompiler;
import the.bytecode.club.bytecodeviewer.obfuscators.RenameClasses; import the.bytecode.club.bytecodeviewer.obfuscators.rename.RenameClasses;
import the.bytecode.club.bytecodeviewer.obfuscators.RenameFields; import the.bytecode.club.bytecodeviewer.obfuscators.rename.RenameFields;
import the.bytecode.club.bytecodeviewer.obfuscators.RenameMethods; import the.bytecode.club.bytecodeviewer.obfuscators.rename.RenameMethods;
import the.bytecode.club.bytecodeviewer.plugins.*; import the.bytecode.club.bytecodeviewer.plugins.*;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
@ -340,6 +340,8 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier {
private final JSeparator separator_6 = new JSeparator(); private final JSeparator separator_6 = new JSeparator();
public final JCheckBoxMenuItem refreshOnChange = new JCheckBoxMenuItem("Refresh On View Change"); public final JCheckBoxMenuItem refreshOnChange = new JCheckBoxMenuItem("Refresh On View Change");
public FileNavigationPane cn = new FileNavigationPane(this);
public boolean isMaximized = false; public boolean isMaximized = false;
public void removed(boolean busy) { public void removed(boolean busy) {
@ -474,7 +476,7 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier {
public MainViewerGUI() { public MainViewerGUI() {
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new Test()); KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new Test());
mnNewMenu_5.setVisible(false); mnNewMenu_5.setVisible(true);
this.addWindowStateListener(new WindowAdapter() { this.addWindowStateListener(new WindowAdapter() {
public void windowStateChanged(WindowEvent evt) { public void windowStateChanged(WindowEvent evt) {
int oldState = evt.getOldState(); int oldState = evt.getOldState();
@ -1433,6 +1435,8 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier {
return; return;
} }
new RenameFields().start(); new RenameFields().start();
workPane.refreshClass.doClick();
cn.tree.updateUI();
} }
}); });
@ -1453,6 +1457,8 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier {
return; return;
} }
new RenameMethods().start(); new RenameMethods().start();
workPane.refreshClass.doClick();
cn.tree.updateUI();
} }
}); });
@ -1464,6 +1470,8 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier {
return; return;
} }
new RenameClasses().start(); new RenameClasses().start();
workPane.refreshClass.doClick();
cn.tree.updateUI();
} }
}); });
@ -1572,7 +1580,6 @@ public class MainViewerGUI extends JFrame implements FileChangeNotifier {
new BoxLayout(getContentPane(), BoxLayout.X_AXIS)); new BoxLayout(getContentPane(), BoxLayout.X_AXIS));
// scrollPane.setViewportView(tree); // scrollPane.setViewportView(tree);
FileNavigationPane cn = new FileNavigationPane(this);
cn.setMinimumSize(new Dimension(200, 50)); cn.setMinimumSize(new Dimension(200, 50));
// panel.add(cn); // panel.add(cn);
SearchingPane s = new SearchingPane(this); SearchingPane s = new SearchingPane(this);

View file

@ -16,10 +16,10 @@ public abstract class JavaObfuscator extends Thread {
@Override @Override
public void run() { public void run() {
System.out.println("mibbzz is gay");
BytecodeViewer.viewer.setIcon(true); BytecodeViewer.viewer.setIcon(true);
BytecodeViewer.runningObfuscation = true; BytecodeViewer.runningObfuscation = true;
obfuscate(); obfuscate();
BytecodeViewer.refactorer.run();
BytecodeViewer.runningObfuscation = false; BytecodeViewer.runningObfuscation = false;
BytecodeViewer.viewer.setIcon(false); BytecodeViewer.viewer.setIcon(false);
} }
@ -34,8 +34,8 @@ public abstract class JavaObfuscator extends Thread {
} }
} }
public static int MAX_STRING_LENGTH = 250; public static int MAX_STRING_LENGTH = 25;
public static int MIN_STRING_LENGTH = 20; public static int MIN_STRING_LENGTH = 5;
private ArrayList<String> names = new ArrayList<String>(); private ArrayList<String> names = new ArrayList<String>();
protected String generateUniqueName(int length) { protected String generateUniqueName(int length) {
@ -43,6 +43,9 @@ public abstract class JavaObfuscator extends Thread {
String name = ""; String name = "";
while (!found) { while (!found) {
String nameTry = MiscUtils.randomString(1) + MiscUtils.randomStringNum(length - 1); String nameTry = MiscUtils.randomString(1) + MiscUtils.randomStringNum(length - 1);
if (!Character.isJavaIdentifierStart(nameTry.toCharArray()[0]))
continue;
if (!names.contains(nameTry)) { if (!names.contains(nameTry)) {
names.add(nameTry); names.add(nameTry);
name = nameTry; name = nameTry;

View file

@ -1,31 +0,0 @@
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;
/**
* 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);
ASMUtil_OLD.renameClassNode(c.name, newName);
c.name = newName;
}
System.out.println("Obfuscated class names.");
}
}

View file

@ -0,0 +1,46 @@
package the.bytecode.club.bytecodeviewer.obfuscators.mapping;
import java.util.ArrayList;
import java.util.List;
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;
public class HookMap {
protected List<MappingData> classes;
protected List<FieldMappingData> fields;
protected List<MethodMappingData> methods;
public HookMap() {
classes = new ArrayList<MappingData>();
fields = new ArrayList<FieldMappingData>();
methods = new ArrayList<MethodMappingData>();
}
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<MappingData> getClasses() {
return classes;
}
public List<FieldMappingData> getFields() {
return fields;
}
public List<MethodMappingData> getMethods() {
return methods;
}
}

View file

@ -0,0 +1,96 @@
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;
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;
/**
* @author sc4re
*/
public class RefactorMapper extends Remapper {
protected final Map<String, MappingData> sortedClasses;
protected final Map<String, MethodMappingData> sortedMethods;
protected final Map<String, FieldMappingData> sortedFields;
protected final List<String> 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;
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 = 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)) {
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)) {
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());
}
}

View file

@ -0,0 +1,57 @@
package the.bytecode.club.bytecodeviewer.obfuscators.mapping;
import java.util.HashMap;
import java.util.Map;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.commons.RemappingClassAdapter;
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<String, ClassNode> 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<String, ClassNode> factor : refactored.entrySet()) {
BytecodeViewer.relocate(factor.getKey(), factor.getValue());
}
mapper.printMap();
}
private byte[] getClassNodeBytes(ClassNode cn) {
ClassWriter cw = new ClassWriter(0);
cn.accept(cw);
byte[] b = cw.toByteArray();
return b;
}
}

View file

@ -0,0 +1,83 @@
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) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
return true;
}
}

View file

@ -0,0 +1,65 @@
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) {
if (other.refactoredName != null)
return false;
} else if (!refactoredName.equals(other.refactoredName))
return false;
return true;
}
}

View file

@ -0,0 +1,83 @@
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) {
if (other.methodOwner != null)
return false;
} else if (!methodOwner.equals(other.methodOwner))
return false;
return true;
}
}

View file

@ -0,0 +1,55 @@
package the.bytecode.club.bytecodeviewer.obfuscators.rename;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodNode;
import com.sun.xml.internal.ws.org.objectweb.asm.Opcodes;
import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.api.ASMUtil_OLD;
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 {
@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 the user specified as main-classes */
for (String name : BytecodeViewer.main_classes) {
if (name.equals(c.name))
continue classLoop;
}
/** As we dont want to rename classes that contain native dll methods */
for (Object o : c.methods) {
MethodNode m = (MethodNode) o;
/* As we dont want to rename native dll methods */
if ((m.access & Opcodes.ACC_NATIVE) != 0)
continue classLoop;
}
String newName = generateUniqueName(stringLength);
BytecodeViewer.refactorer.getHooks().addClass(new MappingData(c.name, newName));
/*ASMUtil_OLD.renameClassNode(c.name, newName);
c.name = newName;*/
}
System.out.println("Obfuscated class names.");
}
}

View file

@ -1,10 +1,15 @@
package the.bytecode.club.bytecodeviewer.obfuscators; package the.bytecode.club.bytecodeviewer.obfuscators.rename;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode; import org.objectweb.asm.tree.FieldNode;
import com.sun.xml.internal.ws.org.objectweb.asm.Opcodes;
import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.api.ASMUtil_OLD; import the.bytecode.club.bytecodeviewer.api.ASMUtil_OLD;
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. * Rename fields.
@ -23,10 +28,13 @@ public class RenameFields extends JavaObfuscator {
for (ClassNode c : BytecodeViewer.getLoadedClasses()) { for (ClassNode c : BytecodeViewer.getLoadedClasses()) {
for (Object o : c.fields.toArray()) { for (Object o : c.fields.toArray()) {
FieldNode f = (FieldNode) o; FieldNode f = (FieldNode) o;
String newName = generateUniqueName(stringLength); String newName = generateUniqueName(stringLength);
ASMUtil_OLD.renameFieldNode(c.name, f.name, f.desc, null,
newName, null); BytecodeViewer.refactorer.getHooks().addField(new FieldMappingData(c.name, new MappingData(f.name, newName), f.desc));
f.name = newName;
/*ASMUtil_OLD.renameFieldNode(c.name, f.name, f.desc, null, newName, null);
f.name = newName;*/
} }
} }

View file

@ -1,4 +1,4 @@
package the.bytecode.club.bytecodeviewer.obfuscators; package the.bytecode.club.bytecodeviewer.obfuscators.rename;
import org.objectweb.asm.Opcodes; import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.ClassNode; import org.objectweb.asm.tree.ClassNode;
@ -6,6 +6,9 @@ import org.objectweb.asm.tree.MethodNode;
import the.bytecode.club.bytecodeviewer.BytecodeViewer; import the.bytecode.club.bytecodeviewer.BytecodeViewer;
import the.bytecode.club.bytecodeviewer.api.ASMUtil_OLD; import the.bytecode.club.bytecodeviewer.api.ASMUtil_OLD;
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. * Rename methods.
@ -22,8 +25,13 @@ public class RenameMethods extends JavaObfuscator {
System.out.println("Obfuscating method names..."); System.out.println("Obfuscating method names...");
for (ClassNode c : BytecodeViewer.getLoadedClasses()) { for (ClassNode c : BytecodeViewer.getLoadedClasses()) {
for (Object o : c.methods.toArray()) { methodLoop: for (Object o : c.methods.toArray()) {
MethodNode m = (MethodNode) o; MethodNode m = (MethodNode) o;
/* As we dont want to rename native dll methods */
if ((m.access & Opcodes.ACC_NATIVE) != 0)
continue methodLoop;
if (m.access != Opcodes.ACC_ABSTRACT if (m.access != Opcodes.ACC_ABSTRACT
&& m.access != Opcodes.ACC_ABSTRACT && m.access != Opcodes.ACC_ABSTRACT
+ Opcodes.ACC_STATIC + Opcodes.ACC_STATIC
@ -42,8 +50,11 @@ public class RenameMethods extends JavaObfuscator {
if (!m.name.equals("main") && !m.name.equals("<init>") if (!m.name.equals("main") && !m.name.equals("<init>")
&& !m.name.equals("<clinit>")) { && !m.name.equals("<clinit>")) {
String newName = generateUniqueName(stringLength); String newName = generateUniqueName(stringLength);
ASMUtil_OLD.renameMethodNode(c.name, m.name, m.desc,
null, newName, null); BytecodeViewer.refactorer.getHooks().addMethod(new MethodMappingData(c.name, new MappingData(m.name, newName), m.desc));
/*ASMUtil_OLD.renameMethodNode(c.name, m.name, m.desc,
null, newName, null);*/
} }
} }
} }