Class/Method/Field Renaming
This commit is contained in:
parent
1d32d00d4b
commit
c8337e74fd
13 changed files with 3404 additions and 2947 deletions
|
@ -36,6 +36,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 +118,10 @@ 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();
|
||||||
|
/* ASM Re-mapping Constants */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The version checker thread
|
* The version checker thread
|
||||||
*/
|
*/
|
||||||
|
@ -383,6 +388,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
|
||||||
|
|
|
@ -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;
|
||||||
|
@ -474,7 +474,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();
|
||||||
|
|
|
@ -20,6 +20,7 @@ public abstract class JavaObfuscator extends Thread {
|
||||||
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 +35,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) {
|
||||||
|
|
|
@ -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.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,69 @@
|
||||||
|
package the.bytecode.club.bytecodeviewer.obfuscators.mapping;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
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;
|
||||||
|
|
||||||
|
public RefactorMapper(HookMap hookMap) {
|
||||||
|
sortedClasses = new HashMap<>();
|
||||||
|
sortedMethods = new HashMap<>();
|
||||||
|
sortedFields = new HashMap<>();
|
||||||
|
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))
|
||||||
|
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))
|
||||||
|
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))
|
||||||
|
name = sortedMethods.get(obfKey).getMethodName().getRefactoredName();
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,56 @@
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] getClassNodeBytes(ClassNode cn) {
|
||||||
|
ClassWriter cw = new ClassWriter(0);
|
||||||
|
cn.accept(cw);
|
||||||
|
byte[] b = cw.toByteArray();
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,49 @@
|
||||||
|
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 = 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 (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.");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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;*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue