Permalink
Browse files

all renamers fixed. beginning of control flow obfuscation. added obfu…

…scation level enum and some controls. gui coming soon, more bugs to fix as always
  • Loading branch information...
1 parent 9c30766 commit 0dc106dadfa4253d609c7b91c926a41a1e2270f1 @contra committed Feb 8, 2011
Showing with 255 additions and 244 deletions.
  1. +3 −0 .idea/uiDesigner.xml
  2. +78 −194 .idea/workspace.xml
  3. 0 JMO.iml → JMOT.iml
  4. BIN out/production/ContraObfuscator/net/contra/obfuscator/Application.class
  5. BIN out/production/ContraObfuscator/net/contra/obfuscator/Constants.class
  6. BIN out/production/ContraObfuscator/net/contra/obfuscator/trans/AbstractTransformer.class
  7. BIN out/production/ContraObfuscator/net/contra/obfuscator/trans/Obfuscator.class
  8. BIN out/production/ContraObfuscator/net/contra/obfuscator/util/IO.class
  9. BIN out/production/ContraObfuscator/net/contra/obfuscator/util/JarLoader.class
  10. BIN out/production/ContraObfuscator/net/contra/obfuscator/util/LogHandler.class
  11. BIN out/production/JMO/net/contra/obfuscator/Settings.class
  12. BIN out/production/JMO/net/contra/obfuscator/trans/AttributeObfuscator.class
  13. BIN out/production/JMO/net/contra/obfuscator/trans/ClassNameObfuscator.class
  14. BIN out/production/JMO/net/contra/obfuscator/trans/FieldNameObfuscator.class
  15. BIN out/production/JMO/net/contra/obfuscator/trans/MethodNameObfuscator.class
  16. BIN out/production/JMO/net/contra/obfuscator/util/BCELMethods.class
  17. BIN out/production/JMO/net/contra/obfuscator/util/JarLoader.class
  18. BIN out/production/JMO/net/contra/obfuscator/util/Misc.class
  19. 0 out/production/JMOT/FILE LOCATION HERE
  20. BIN out/production/{JMO → JMOT}/net/contra/obfuscator/Application.class
  21. BIN out/production/JMOT/net/contra/obfuscator/Settings.class
  22. BIN out/production/JMOT/net/contra/obfuscator/trans/AttributeObfuscator.class
  23. BIN out/production/JMOT/net/contra/obfuscator/trans/ClassNameObfuscator.class
  24. BIN out/production/JMOT/net/contra/obfuscator/trans/FieldNameObfuscator.class
  25. BIN out/production/{JMO → JMOT}/net/contra/obfuscator/trans/ITransformer.class
  26. BIN out/production/JMOT/net/contra/obfuscator/trans/IntegerComplicator.class
  27. BIN out/production/JMOT/net/contra/obfuscator/trans/MethodNameObfuscator.class
  28. BIN out/production/JMOT/net/contra/obfuscator/trans/ObfuscationType.class
  29. BIN out/production/{JMO → JMOT}/net/contra/obfuscator/trans/StringObfuscator.class
  30. BIN out/production/JMOT/net/contra/obfuscator/util/BCELMethods.class
  31. BIN out/production/{JMO → JMOT}/net/contra/obfuscator/util/IO.class
  32. BIN out/production/JMOT/net/contra/obfuscator/util/JarLoader.class
  33. BIN out/production/{JMO → JMOT}/net/contra/obfuscator/util/LogHandler.class
  34. BIN out/production/JMOT/net/contra/obfuscator/util/Misc$1.class
  35. BIN out/production/JMOT/net/contra/obfuscator/util/Misc.class
  36. BIN .../net/contra/obfuscator/util/RenamePair.class → JMOT/net/contra/obfuscator/util/RenamedPair.class}
  37. +6 −0 run.bat
  38. +4 −4 src/net/contra/obfuscator/Settings.java
  39. +8 −4 src/net/contra/obfuscator/trans/AttributeObfuscator.java
  40. +26 −12 src/net/contra/obfuscator/trans/ClassNameObfuscator.java
  41. +6 −7 src/net/contra/obfuscator/trans/FieldNameObfuscator.java
  42. +56 −0 src/net/contra/obfuscator/trans/IntegerComplicator.java
  43. +6 −7 src/net/contra/obfuscator/trans/MethodNameObfuscator.java
  44. +6 −0 src/net/contra/obfuscator/trans/ObfuscationType.java
  45. +10 −1 src/net/contra/obfuscator/util/BCELMethods.java
  46. +5 −5 src/net/contra/obfuscator/util/JarLoader.java
  47. +33 −4 src/net/contra/obfuscator/util/Misc.java
  48. +8 −6 src/net/contra/obfuscator/util/{RenamePair.java → RenamedPair.java}
View
@@ -121,5 +121,8 @@
</item>
</group>
</component>
+ <component name="uidesigner-configuration">
+ <option name="DEFAULT_LAYOUT_MANAGER" value="FormLayout" />
+ </component>
</project>
View
Oops, something went wrong.
View
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
No changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
@@ -0,0 +1,6 @@
+@echo off
+cd out
+cd production
+cd jmot
+java net.contra.obfuscator.Application "FILE LOCATION HERE" string
+pause
@@ -1,15 +1,15 @@
package net.contra.obfuscator;
+import net.contra.obfuscator.trans.ObfuscationType;
+
public class Settings {
//Application Settings
- public static final double Version = 0.12;
+ public static final double Version = 0.13;
public static final boolean Debug = true;
+ public static ObfuscationType ObfuscationLevel = ObfuscationType.Heavy;
//String Obfuscation Settings
public static final String CipherName = "hax";
public static final String CipherArg = "s";
public static final int CipherKey = 127;
-
- //Name Obfuscation Settings
- public static boolean UseInvalid = true;
}
@@ -1,5 +1,6 @@
package net.contra.obfuscator.trans;
+import com.sun.org.apache.bcel.internal.classfile.Attribute;
import com.sun.org.apache.bcel.internal.classfile.Method;
import com.sun.org.apache.bcel.internal.generic.ClassGen;
import com.sun.org.apache.bcel.internal.generic.LocalVariableGen;
@@ -29,11 +30,14 @@ public void Transform() {
mg.removeCodeAttributes();
mg.removeAttributes();
mg.removeLineNumbers();
- for(LocalVariableGen g : mg.getLocalVariables()){
- g.setName(Misc.getRandomString(5));
+ for (LocalVariableGen g : mg.getLocalVariables()) {
+ g.setName(Misc.getRandomName());
}
- for(int i = 0; i < mg.getArgumentNames().length; i++){
- mg.setArgumentName(i, Misc.getRandomString(7));
+ for (int i = 0; i < mg.getArgumentNames().length; i++) {
+ mg.setArgumentName(i, Misc.getRandomName());
+ }
+ for (Attribute at : cg.getAttributes()) {
+ cg.removeAttribute(at);
}
cg.replaceMethod(method, mg.getMethod());
Logger.Log("Removed Attributes/Line Numbers -> Class: " + cg.getClassName() + " Method: " + method.getName());
@@ -1,10 +1,8 @@
package net.contra.obfuscator.trans;
+import com.sun.org.apache.bcel.internal.classfile.Constant;
import com.sun.org.apache.bcel.internal.classfile.Method;
-import com.sun.org.apache.bcel.internal.generic.ClassGen;
-import com.sun.org.apache.bcel.internal.generic.InstructionHandle;
-import com.sun.org.apache.bcel.internal.generic.InstructionList;
-import com.sun.org.apache.bcel.internal.generic.MethodGen;
+import com.sun.org.apache.bcel.internal.generic.*;
import net.contra.obfuscator.util.BCELMethods;
import net.contra.obfuscator.util.JarLoader;
import net.contra.obfuscator.util.LogHandler;
@@ -31,9 +29,17 @@ public void Load() {
public void Transform() {
//We rename methods
for (ClassGen cg : LoadedJar.ClassEntries.values()) {
- Map<String, String> NewClassMethods = new HashMap<String, String>();
if (cg.isAbstract()) continue; //TODO: Probably more shit we shouldn't rename
- String newName = Misc.getRandomString(20);
+ String newName = Misc.getRandomClassName();
+ byte[] manifest = LoadedJar.NonClassEntries.get("META-INF/MANIFEST.MF");
+ if (manifest != null) {
+ String man = new String(manifest);
+ if(man.contains("Main-Class: " + cg.getClassName())){
+ Logger.Debug("Updating Manifest -> Class: " + cg.getClassName());
+ man = man.replace("Main-Class: " + cg.getClassName(), "Main-Class: " + newName);
+ LoadedJar.NonClassEntries.put("META-INF/MANIFEST.MF", man.getBytes());
+ }
+ }
String oldName = cg.getClassName();
cg.setClassName(newName);
Logger.Log("Obfuscating Method Names -> Class: " + oldName + " - " + cg.getClassName());
@@ -53,26 +59,34 @@ public void Transform() {
String methname = BCELMethods.getInvokeMethodName(handle.getInstruction(), cg.getConstantPool());
String methsig = BCELMethods.getInvokeSignature(handle.getInstruction(), cg.getConstantPool());
if (!ChangedClasses.containsKey(clazz)) continue;
- Logger.Debug("Class: " + clazz + " Name: " + methname + " Sig: " + methsig);
+ Logger.Debug("Swapping Call -> Class: " + clazz + " Name: " + methname + " Sig: " + methsig);
String newname = ChangedClasses.get(clazz);
- int index = cg.getConstantPool().addMethodref(clazz, newname, methsig);
+ int index = cg.getConstantPool().addMethodref(newname, methname, methsig);
handle.setInstruction(BCELMethods.getNewInvoke(handle.getInstruction(), index));
} else if (BCELMethods.isFieldInvoke(handle.getInstruction())) {
- String clazz = BCELMethods.getInvokeClassName(handle.getInstruction(), cg.getConstantPool());
+ String clazz = BCELMethods.getFieldInvokeClassName(handle.getInstruction(), cg.getConstantPool());
String fieldname = BCELMethods.getFieldInvokeName(handle.getInstruction(), cg.getConstantPool());
String fieldsig = BCELMethods.getFieldInvokeSignature(handle.getInstruction(), cg.getConstantPool());
if (!ChangedClasses.containsKey(clazz)) continue;
- Logger.Debug("Class: " + clazz + " Name: " + fieldname + " Sig: " + fieldsig);
+ Logger.Debug("Swapping Call -> Class: " + clazz + " Name: " + fieldname + " Sig: " + fieldsig);
String newname = ChangedClasses.get(clazz);
- int index = cg.getConstantPool().addFieldref(clazz, newname, fieldsig);
+ int index = cg.getConstantPool().addFieldref(newname, fieldname, fieldsig);
handle.setInstruction(BCELMethods.getNewFieldInvoke(handle.getInstruction(), index));
+ } else if (handle.getInstruction() instanceof NEW){
+ NEW in = ((NEW) handle.getInstruction());
+ String clazz = in.getLoadClassType(cg.getConstantPool()).getClassName();
+ if (!ChangedClasses.containsKey(clazz)) continue;
+ String newname = ChangedClasses.get(clazz);
+ int index = cg.getConstantPool().addClass(newname);
+ NEW out = new NEW(index);
+ handle.setInstruction(out);
}
}
list.setPositions();
mg.setInstructionList(list);
+ mg.removeLocalVariables();
mg.setMaxLocals();
mg.setMaxStack();
- mg.removeLineNumbers();
cg.replaceMethod(method, mg.getMethod());
}
}
@@ -12,7 +12,7 @@
public class FieldNameObfuscator implements ITransformer {
private final LogHandler Logger = new LogHandler("FieldNameObfuscator");
//ClassName, <OldSig, NewSig>
- private final Map<String, ArrayList<RenamePair>> ChangedFields = new HashMap<String, ArrayList<RenamePair>>();
+ private final Map<String, ArrayList<RenamedPair>> ChangedFields = new HashMap<String, ArrayList<RenamedPair>>();
private String Location = "";
private JarLoader LoadedJar;
@@ -27,16 +27,16 @@ public void Load() {
public void Transform() {
//We rename methods
for (ClassGen cg : LoadedJar.ClassEntries.values()) {
- ArrayList<RenamePair> NewFields = new ArrayList<RenamePair>();
+ ArrayList<RenamedPair> NewFields = new ArrayList<RenamedPair>();
if (cg.isAbstract()) continue;
for (Field field : cg.getFields()) {
if (field.isInterface() || field.isAbstract())
continue;
FieldGen fg = new FieldGen(field, cg.getConstantPool());
- String newName = Misc.getRandomString(4);
+ String newName = Misc.getRandomName();
fg.setName(newName);
cg.replaceField(field, fg.getField());
- RenamePair newPair = new RenamePair(field.getName(), field.getSignature(), fg.getName());
+ RenamedPair newPair = new RenamedPair(field.getName(), field.getSignature(), fg.getName());
NewFields.add(newPair);
Logger.Log("Obfuscating Field Names -> Class: " + cg.getClassName() + " Field: " + field.getName());
}
@@ -57,8 +57,8 @@ public void Transform() {
String fsig = BCELMethods.getFieldInvokeSignature(handle.getInstruction(), cg.getConstantPool()).trim().replace(" ", "");
if (!ChangedFields.containsKey(clazz)) continue;
- for(RenamePair pair : ChangedFields.get(clazz)){
- if(pair.OldName.equals(fname) && pair.OldSignature.equals(fsig)){
+ for (RenamedPair pair : ChangedFields.get(clazz)) {
+ if (pair.OldName.equals(fname) && pair.OldSignature.equals(fsig)) {
int index = cg.getConstantPool().addFieldref(clazz, pair.NewName, fsig);
handle.setInstruction(BCELMethods.getNewFieldInvoke(handle.getInstruction(), index));
}
@@ -69,7 +69,6 @@ public void Transform() {
mg.setInstructionList(list);
mg.setMaxLocals();
mg.setMaxStack();
- mg.removeLineNumbers();
cg.replaceMethod(method, mg.getMethod());
}
}
@@ -0,0 +1,56 @@
+package net.contra.obfuscator.trans;
+
+import com.sun.org.apache.bcel.internal.classfile.Method;
+import com.sun.org.apache.bcel.internal.generic.*;
+import net.contra.obfuscator.util.JarLoader;
+import net.contra.obfuscator.util.LogHandler;
+
+
+public class IntegerComplicator implements ITransformer {
+ LogHandler Logger = new LogHandler("AttributeObfuscator");
+ private String Location = "";
+ private JarLoader LoadedJar;
+
+ public IntegerComplicator(String loc) {
+ Location = loc;
+ }
+
+ public void Load() {
+ LoadedJar = new JarLoader(Location);
+ }
+
+ public void Transform() {
+ for (ClassGen cg : LoadedJar.ClassEntries.values()) {
+ for (Method method : cg.getMethods()) {
+ MethodGen mg = new MethodGen(method, cg.getClassName(), cg.getConstantPool());
+ InstructionList list = mg.getInstructionList();
+ if (list == null) continue;
+ Logger.Log("Complicating Constant Integers -> Class: " + cg.getClassName() + " Method: " + method.getName());
+ InstructionHandle[] handles = list.getInstructionHandles();
+ for (InstructionHandle handle : handles) {
+ if (handle.getInstruction() instanceof ICONST
+ && (handle.getNext().getInstruction() instanceof PUTSTATIC
+ || handle.getNext().getInstruction() instanceof PUTFIELD
+ || handle.getNext().getInstruction() instanceof ISTORE)
+ && handle.getPrev().getInstruction() instanceof ALOAD) {
+ ICONST con = (ICONST) handle.getInstruction();
+ InstructionList nlist = new InstructionList();
+ nlist.append(new ICONST(1));
+ nlist.append(new IMUL());
+ list.append(handle, nlist);
+ }
+ }
+ list.setPositions();
+ mg.setInstructionList(list);
+ mg.setMaxLocals();
+ mg.setMaxStack();
+ cg.replaceMethod(method, mg.getMethod());
+ }
+ }
+ }
+
+ public void Dump() {
+ LoadedJar.Save(Location.replace(".jar", "-new.jar"));
+ }
+}
+
@@ -14,7 +14,7 @@
public class MethodNameObfuscator implements ITransformer {
private final LogHandler Logger = new LogHandler("MethodNameObfuscator");
//ClassName, <OldSig, NewSig>
- private final Map<String, ArrayList<RenamePair>> ChangedMethods = new HashMap<String, ArrayList<RenamePair>>();
+ private final Map<String, ArrayList<RenamedPair>> ChangedMethods = new HashMap<String, ArrayList<RenamedPair>>();
private String Location = "";
private JarLoader LoadedJar;
@@ -29,16 +29,16 @@ public void Load() {
public void Transform() {
//We rename methods
for (ClassGen cg : LoadedJar.ClassEntries.values()) {
- ArrayList<RenamePair> NewClassMethods = new ArrayList<RenamePair>();
+ ArrayList<RenamedPair> NewClassMethods = new ArrayList<RenamedPair>();
if (cg.isAbstract()) continue; //TODO: Probably more shit we shouldn't rename
for (Method method : cg.getMethods()) {
if (method.isInterface() || method.isAbstract() || method.getName().endsWith("init>") || method.getName().equals("main"))
continue; //TODO: Probably more shit we shouldn't rename
MethodGen mg = new MethodGen(method, cg.getClassName(), cg.getConstantPool());
- String newName = Misc.getRandomString(200);
+ String newName = Misc.getRandomName();
mg.setName(newName);
cg.replaceMethod(method, mg.getMethod());
- RenamePair pair = new RenamePair(method.getName(), method.getSignature(), mg.getName());
+ RenamedPair pair = new RenamedPair(method.getName(), method.getSignature(), mg.getName());
NewClassMethods.add(pair);
Logger.Log("Obfuscating Method Names -> Class: " + cg.getClassName() + " Method: " + method.getName());
}
@@ -59,8 +59,8 @@ public void Transform() {
String methsig = BCELMethods.getInvokeSignature(handle.getInstruction(), cg.getConstantPool()).trim();
if (!ChangedMethods.containsKey(clazz)) continue;
- for(RenamePair pair : ChangedMethods.get(clazz)){
- if(pair.OldName.equals(methname) && pair.OldSignature.equals(methsig)){
+ for (RenamedPair pair : ChangedMethods.get(clazz)) {
+ if (pair.OldName.equals(methname) && pair.OldSignature.equals(methsig)) {
int index = cg.getConstantPool().addMethodref(clazz, pair.NewName, pair.OldSignature);
handle.setInstruction(BCELMethods.getNewInvoke(handle.getInstruction(), index));
}
@@ -71,7 +71,6 @@ public void Transform() {
mg.setInstructionList(list);
mg.setMaxLocals();
mg.setMaxStack();
- mg.removeLineNumbers();
cg.replaceMethod(method, mg.getMethod());
}
}
@@ -0,0 +1,6 @@
+package net.contra.obfuscator.trans;
+
+
+public enum ObfuscationType {
+ Light, Normal, Heavy, Insane
+}
@@ -18,6 +18,7 @@ public static boolean isFieldInvoke(Instruction ins) {
return false;
}
}
+
public static String getFieldInvokeName(Instruction ins, ConstantPoolGen cp) {
if (ins instanceof GETSTATIC) {
return (((GETSTATIC) ins).getFieldName(cp));
@@ -31,6 +32,7 @@ public static String getFieldInvokeName(Instruction ins, ConstantPoolGen cp) {
return null;
}
}
+
public static String getFieldInvokeClassName(Instruction ins, ConstantPoolGen cp) {
if (ins instanceof GETSTATIC) {
return (((GETSTATIC) ins).getClassName(cp));
@@ -44,6 +46,7 @@ public static String getFieldInvokeClassName(Instruction ins, ConstantPoolGen cp
return null;
}
}
+
public static String getFieldInvokeSignature(Instruction ins, ConstantPoolGen cp) {
if (ins instanceof GETSTATIC) {
return (((GETSTATIC) ins).getSignature(cp));
@@ -57,6 +60,7 @@ public static String getFieldInvokeSignature(Instruction ins, ConstantPoolGen cp
return null;
}
}
+
public static Instruction getNewFieldInvoke(Instruction ins, int index) {
if (ins instanceof GETSTATIC) {
return new GETSTATIC(index);
@@ -65,11 +69,12 @@ public static Instruction getNewFieldInvoke(Instruction ins, int index) {
} else if (ins instanceof GETFIELD) {
return new GETFIELD(index);
} else if (ins instanceof PUTFIELD) {
- return new PUTSTATIC(index);
+ return new PUTFIELD(index);
} else {
return null;
}
}
+
public static boolean isInvoke(Instruction ins) {
if (ins instanceof INVOKESTATIC) {
return true;
@@ -83,6 +88,7 @@ public static boolean isInvoke(Instruction ins) {
return false;
}
}
+
public static String getInvokeMethodName(Instruction ins, ConstantPoolGen cp) {
if (ins instanceof INVOKESTATIC) {
INVOKESTATIC invst = (INVOKESTATIC) ins;
@@ -100,6 +106,7 @@ public static String getInvokeMethodName(Instruction ins, ConstantPoolGen cp) {
return null;
}
}
+
public static Instruction getNewInvoke(Instruction ins, int index) {
if (ins instanceof INVOKESTATIC) {
return new INVOKESTATIC(index);
@@ -115,6 +122,7 @@ public static Instruction getNewInvoke(Instruction ins, int index) {
return null;
}
}
+
public static String getInvokeSignature(Instruction ins, ConstantPoolGen cp) {
if (ins instanceof INVOKESTATIC) {
INVOKESTATIC invst = (INVOKESTATIC) ins;
@@ -132,6 +140,7 @@ public static String getInvokeSignature(Instruction ins, ConstantPoolGen cp) {
return null;
}
}
+
public static String getInvokeClassName(Instruction ins, ConstantPoolGen cp) {
if (ins instanceof INVOKESTATIC) {
INVOKESTATIC invst = (INVOKESTATIC) ins;
Oops, something went wrong.

0 comments on commit 0dc106d

Please sign in to comment.