Skip to content

Commit

Permalink
added allatori deobfuscator. lets get evil
Browse files Browse the repository at this point in the history
  • Loading branch information
Contra committed Apr 13, 2011
1 parent 71b8c11 commit 0debcb7
Show file tree
Hide file tree
Showing 27 changed files with 489 additions and 237 deletions.
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

446 changes: 282 additions & 164 deletions .idea/workspace.xml

Large diffs are not rendered by default.

Binary file modified out/artifacts/JMOT_jar/JMOT.jar
Binary file not shown.
Binary file modified out/production/JMOT/net/contra/obfuscator/Application$1.class
Binary file not shown.
Binary file modified out/production/JMOT/net/contra/obfuscator/Application.class
Binary file not shown.
Binary file modified out/production/JMOT/net/contra/obfuscator/Settings.class
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified out/production/JMOT/net/contra/obfuscator/util/misc/Misc.class
Binary file not shown.
60 changes: 25 additions & 35 deletions src/net/contra/obfuscator/Application.java
Original file line number Diff line number Diff line change
@@ -1,47 +1,29 @@
package net.contra.obfuscator;

import net.contra.obfuscator.trans.*;
import net.contra.obfuscator.trans.deob.AllatoriDeobfuscator;
import net.contra.obfuscator.trans.ob.*;
import net.contra.obfuscator.util.misc.LogHandler;

public class Application {
private static final LogHandler Logger = new LogHandler("Application");

public static void main(String[] args) {
Logger.Log(String.format("JMOT v%s by Contra", Settings.Version));
Logger.Log(String.format("JMOT v%s by Contra", Settings.VERSION));
Logger.Log("Visit RECoders.org for Info");
Logger.Log("Please read LICENSE.txt for licensing information.");
if (args.length < 2) {
Logger.Error("Please provide at least two arguments!");
return;
}
Logger.Log("Running with Obfuscation Level: " + Settings.ObfuscationLevel.getName());
Logger.Log("Running with Obfuscation Level: " + Settings.OBFUSCATION_LEVEL.getName());
SetParameters();
Logger.Log("Beginning Obfuscation");
Logger.Log("Beginning Process");
try {
String cmd = args[1];
ITransformer obber;
//Obfuscation Stuff
if (cmd.equalsIgnoreCase("all")) {
//TODO: UNGHETTO THIS, THIS IS AWFUL
obber = new StringObfuscator(args[0]);
obber.load();
obber.transform();
obber = new AttributeObfuscator(obber.save());
Settings.FileTag = "";
obber.load();
obber.transform();
obber = new MethodNameObfuscator(obber.save());
obber.load();
obber.transform();
obber = new FieldNameObfuscator(obber.save());
obber.load();
obber.transform();
obber = new IntegerComplicator(obber.save());
obber.load();
obber.transform();
obber = new IntegerBoxer(obber.save());
obber.load();
obber.transform();
obber.save();
return;
} else if (cmd.equalsIgnoreCase("string")) {
obber = new StringObfuscator(args[0]);
Expand All @@ -57,6 +39,9 @@ public static void main(String[] args) {
obber = new IntegerComplicator(args[0]);
} else if (cmd.equalsIgnoreCase("int-boxer")) {
obber = new IntegerBoxer(args[0]);
//Deobfuscation stuff
} else if (cmd.equalsIgnoreCase("allatori")) {
obber = new AllatoriDeobfuscator(args[0]);
} else {
Logger.Error("Please provide a proper transformer identifier!");
return;
Expand All @@ -76,27 +61,32 @@ public static void main(String[] args) {
}

public static void SetParameters() {
switch (Settings.ObfuscationLevel) {
switch (Settings.OBFUSCATION_LEVEL) {
case Light:
Settings.CipherKeys = new int[]{127};
Settings.Iterations = 0;
Settings.CIPHER_KEYS = new int[]{127};
Settings.ITERATIONS = 0;
break;
case Normal:
Settings.CipherKeys = new int[]{81, 127};
Settings.Iterations = 1;
Settings.CIPHER_KEYS = new int[]{81, 127};
Settings.ITERATIONS = 1;
break;
case Heavy:
Settings.CipherKeys = new int[]{85, 127, 200};
Settings.Iterations = 3;
Settings.CIPHER_KEYS = new int[]{85, 127, 200};
Settings.ITERATIONS = 3;
break;
case Insane:
Settings.CipherKeys = new int[]{11, 22, 33, 44, 55, 66, 77, 88};
Settings.Iterations = 15;
Settings.CIPHER_KEYS = new int[]{11, 22, 33, 44, 55, 66, 77, 88};
Settings.ITERATIONS = 15;
break;
default:
Settings.CipherKeys = new int[]{127};
Settings.Iterations = 0;
Settings.CIPHER_KEYS = new int[]{127};
Settings.ITERATIONS = 0;
break;
}
}

public static void Close(){
System.out.println("Application is closing...");
System.exit(1337);
}
}
20 changes: 10 additions & 10 deletions src/net/contra/obfuscator/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

public class Settings {
//Application Settings
public static final double Version = 0.15; //Don't Touch
public static final boolean Debug = true;
public static final ObfuscationType ObfuscationLevel = ObfuscationType.Normal;
public static String FileTag = "-new";
public static final double VERSION = 0.15; //Don't Touch
public static final boolean DEBUG = true;
public static final ObfuscationType OBFUSCATION_LEVEL = ObfuscationType.Insane;
public static String FILE_TAG = "-new";

//Integer Boxer Settings
public static final String BoxerName = "box";
public static final String BoxerArg = "s";
public static final String BOXER_NAME = "box";
public static final String BOXER_ARG = "s";

//String Obfuscation Settings
public static final String CipherName = "hax";
public static final String CipherArg = "s";
public static int[] CipherKeys = {}; //Don't Touch
public static final String CIPHER_NAME = "hax";
public static final String CIPHER_ARG = "s";
public static int[] CIPHER_KEYS = {}; //Don't Touch

//Integer Complicator Settings
public static int Iterations = 0; //Don't Touch
public static int ITERATIONS = 0; //Don't Touch
}
141 changes: 141 additions & 0 deletions src/net/contra/obfuscator/trans/deob/AllatoriDeobfuscator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package net.contra.obfuscator.trans.deob;


import com.sun.org.apache.bcel.internal.classfile.Method;
import com.sun.org.apache.bcel.internal.generic.*;
import net.contra.obfuscator.Application;
import net.contra.obfuscator.ITransformer;
import net.contra.obfuscator.Settings;
import net.contra.obfuscator.util.bcel.BCELMethods;
import net.contra.obfuscator.util.bcel.JarLoader;
import net.contra.obfuscator.util.misc.LogHandler;

public class AllatoriDeobfuscator implements ITransformer {
private final LogHandler Logger = new LogHandler("AllatoriDeobfuscator");
private String Location = "";
private JarLoader LoadedJar;
private boolean isHeavy = false;
private boolean isLight = false;

public AllatoriDeobfuscator(String loc) {
Location = loc;
}

public void load() {
LoadedJar = new JarLoader(Location);
}

private String cipher(String string) {
int i = 85;
char[] cs = new char[string.length()];
int pos = cs.length - 1;
int index = pos;
int xor = i;
while (pos >= 0) {
char c = (char) (string.charAt(index) ^ xor);
int c1_index = index;
xor = (char) ((char) (c1_index ^ xor) & '?');
cs[c1_index] = c;
if (--index < 0) {
break;
}
char c2 = (char) (string.charAt(index) ^ xor);
int c2_index = index;
xor = (char) ((char) (c2_index ^ xor) & '?');
cs[c2_index] = c2;
pos = --index;
}

return new String(cs);
}

private String cipherContext(String encrypted, String callingClass, String callingMethod) {
String keyString = callingClass + callingMethod;
int lastKeyIndex = keyString.length() - 1;
int xor = 85;
int keyIndex = lastKeyIndex;
int length = encrypted.length();
char[] cs = new char[length];
for (int i = length - 1; i >= 0; i--) {
if (keyIndex < 0) {
keyIndex = lastKeyIndex;
}
char keyChar = keyString.charAt(keyIndex--);
cs[i] = (char) (keyChar ^ (encrypted.charAt(i) ^ xor));
xor = (char) (63 & (xor ^ (i ^ keyChar)));
}
return new String(cs);
}

private ClassGen getAllatoriClassGen(JarLoader jr) {
for (ClassGen cg : jr.ClassEntries.values()) {
if (cg.getMethods().length == 2 && cg.getMethods()[0].isStatic() && cg.getMethods()[1].isStatic()) {
if (cg.getMethods()[0].getReturnType().toString().equals("java.lang.String")
&& cg.getMethods()[1].getReturnType().toString().equals("java.lang.String")) {
return cg;
}
}
}
return null;
}

public void transform() {
ClassGen hashClass = getAllatoriClassGen(LoadedJar);
if (hashClass == null) {
Logger.Error("Could not locate Allatori cipher class.");
Logger.Error("This is not obfuscated with Allatori.");
Application.Close();
} else {
Logger.Debug("Allatori Class ID: " + hashClass.getClassName());
}
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.Debug("Stripping Allatori Calls -> Class: " + cg.getClassName() + " Method: " + method.getName());
InstructionHandle[] handles = list.getInstructionHandles();
for (InstructionHandle handle : handles) {
if (handle.getNext() == null) continue;
if (handle.getInstruction() instanceof LDC &&
handle.getNext().getInstruction() instanceof INVOKESTATIC) {
INVOKESTATIC invs = (INVOKESTATIC) handle.getNext().getInstruction();
if (!BCELMethods.getInvokeClassName(invs, cg.getConstantPool()).equals(hashClass.getClassName()))
continue;
if (!isLight && !isHeavy) {
if (!BCELMethods.getInvokeSignature(invs, cg.getConstantPool()).equals(hashClass.getMethods()[0].getSignature())) {
isLight = true;
Logger.Log("Light string obfuscation detected!");
} else {
isHeavy = true;
Logger.Log("Heavy string obfuscation detected!");
}
}
String original = (String) ((LDC) handle.getInstruction()).getValue(cg.getConstantPool());
String deciphered;
if (isHeavy) {
deciphered = cipherContext(original, cg.getClassName(), mg.getName());
} else {
deciphered = cipher(original);
}
int idx = cg.getConstantPool().addString(deciphered); //Add our new string
handle.getNext().setInstruction(new NOP()); //Get rid of the invoke
handle.setInstruction(new LDC(idx)); //Replace old LDC with new LDC
Logger.Debug("\"" + original + "\" -> \"" + deciphered + "\"");
}
}
list.setPositions();
mg.setInstructionList(list);
mg.setMaxLocals();
mg.setMaxStack();
cg.replaceMethod(method, mg.getMethod());
}
}
}

public String save() {
String loc = Location.replace(".jar", Settings.FILE_TAG + ".jar");
LoadedJar.saveJar(loc);
return loc;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.contra.obfuscator.trans;
package net.contra.obfuscator.trans.ob;

import com.sun.org.apache.bcel.internal.classfile.Attribute;
import com.sun.org.apache.bcel.internal.classfile.Method;
Expand Down Expand Up @@ -48,7 +48,7 @@ public void transform() {
}

public String save() {
String loc = Location.replace(".jar", Settings.FileTag + ".jar");
String loc = Location.replace(".jar", Settings.FILE_TAG + ".jar");
LoadedJar.saveJar(loc);
return loc;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.contra.obfuscator.trans;
package net.contra.obfuscator.trans.ob;

import com.sun.org.apache.bcel.internal.classfile.Method;
import com.sun.org.apache.bcel.internal.generic.*;
Expand Down Expand Up @@ -94,7 +94,7 @@ public void transform() {
}

public String save() {
String loc = Location.replace(".jar", Settings.FileTag + ".jar");
String loc = Location.replace(".jar", Settings.FILE_TAG + ".jar");
LoadedJar.saveJar(loc);
return loc;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.contra.obfuscator.trans;
package net.contra.obfuscator.trans.ob;

import com.sun.org.apache.bcel.internal.classfile.Field;
import com.sun.org.apache.bcel.internal.classfile.Method;
Expand Down Expand Up @@ -81,7 +81,7 @@ public void transform() {
}

public String save() {
String loc = Location.replace(".jar", Settings.FileTag + ".jar");
String loc = Location.replace(".jar", Settings.FILE_TAG + ".jar");
LoadedJar.saveJar(loc);
return loc;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.contra.obfuscator.trans;
package net.contra.obfuscator.trans.ob;

import com.sun.org.apache.bcel.internal.Constants;
import com.sun.org.apache.bcel.internal.classfile.Method;
Expand Down Expand Up @@ -45,7 +45,7 @@ public void transform() {
//If it is an even int, it gets replaced with half it's value and appends
//an int of the key
if (curValue != -9001 && (curValue % 2 == 0)
&& Settings.ObfuscationLevel.getLevel() > ObfuscationType.Normal.getLevel()) { //check if it's even.
&& Settings.OBFUSCATION_LEVEL.getLevel() > ObfuscationType.Normal.getLevel()) { //check if it's even.
int tempkey = curValue / 2;
Logger.Debug("Value: " + curValue + " Key: " + tempkey);
Instruction newIns = BCELMethods.getIntegerLoad(handle.getInstruction(), tempkey);
Expand Down Expand Up @@ -80,7 +80,7 @@ public void transform() {
MethodGen getBoxer(ClassGen cg) {
InstructionList il = new InstructionList();
MethodGen method = new MethodGen(Constants.ACC_PUBLIC | Constants.ACC_STATIC, Type.INT, new Type[]{Type.INT, Type.INT},
new String[]{Settings.BoxerArg, Settings.BoxerArg + "i"}, Settings.BoxerName, cg.getClassName(), il, cg.getConstantPool());
new String[]{Settings.BOXER_ARG, Settings.BOXER_ARG + "i"}, Settings.BOXER_NAME, cg.getClassName(), il, cg.getConstantPool());
il.append(InstructionFactory.createLoad(Type.INT, 0));
il.append(InstructionFactory.createLoad(Type.INT, 1));
il.append(new IADD());
Expand All @@ -91,7 +91,7 @@ MethodGen getBoxer(ClassGen cg) {
}

public String save() {
String loc = Location.replace(".jar", Settings.FileTag + ".jar");
String loc = Location.replace(".jar", Settings.FILE_TAG + ".jar");
LoadedJar.saveJar(loc);
return loc;
}
Expand Down
Loading

0 comments on commit 0debcb7

Please sign in to comment.