This commit is contained in:
Adam
2015-11-20 11:14:50 -05:00
parent 919d2d68b3
commit 0da5258c17
2 changed files with 68 additions and 46 deletions

View File

@@ -2,21 +2,30 @@ package net.runelite.deob;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import net.runelite.deob.deobfuscators.ConstantParameter;
import net.runelite.deob.deobfuscators.FieldInliner;
import net.runelite.deob.deobfuscators.IllegalStateExceptions;
import net.runelite.deob.deobfuscators.MethodInliner; import net.runelite.deob.deobfuscators.MethodInliner;
import net.runelite.deob.deobfuscators.RenameUnique;
import net.runelite.deob.deobfuscators.RuntimeExceptions;
import net.runelite.deob.deobfuscators.UnreachedCode;
import net.runelite.deob.deobfuscators.UnusedClass;
import net.runelite.deob.deobfuscators.UnusedFields;
import net.runelite.deob.deobfuscators.UnusedMethods; import net.runelite.deob.deobfuscators.UnusedMethods;
import net.runelite.deob.deobfuscators.UnusedParameters;
import net.runelite.deob.deobfuscators.arithmetic.ModArith;
import net.runelite.deob.deobfuscators.arithmetic.MultiplicationDeobfuscator;
import net.runelite.deob.deobfuscators.arithmetic.MultiplyOneDeobfuscator;
import net.runelite.deob.deobfuscators.arithmetic.MultiplyZeroDeobfuscator;
import net.runelite.deob.deobfuscators.rename.Rename2; import net.runelite.deob.deobfuscators.rename.Rename2;
import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Execution;
import net.runelite.deob.util.JarUtil; import net.runelite.deob.util.JarUtil;
// XXX something to detect final fields and evaluate them
// the problem is static functions which dup,
// graph of method/field (not include static) relationships
public class Deob public class Deob
{ {
public static void main(String[] args) throws IOException public static void main(String[] args) throws IOException
{ {
merge(); if(true) return; //merge(); if(true) return;
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
@@ -28,9 +37,8 @@ public class Deob
// run(group, new RuntimeExceptions()); // run(group, new RuntimeExceptions());
// //
// // remove unused methods // // remove unused methods
// run(group, new UnusedMethods());
//
// run(group, new UnreachedCode()); // run(group, new UnreachedCode());
// run(group, new UnusedMethods());
// //
// // remove illegal state exceptions, frees up some parameters // // remove illegal state exceptions, frees up some parameters
// run(group, new IllegalStateExceptions()); // run(group, new IllegalStateExceptions());
@@ -45,50 +53,43 @@ public class Deob
// // remove unused parameters // // remove unused parameters
// run(group, new UnusedParameters()); // run(group, new UnusedParameters());
// //
// // remove jump obfuscation
// //new Jumps().run(group);
//
// // remove unused fields // // remove unused fields
// run(group, new UnusedFields()); // run(group, new UnusedFields());
// //
// // remove unused methods, again? // // remove unused methods, again?
// run(group, new UnusedMethods()); // run(group, new UnusedMethods());
//
run(group, new MethodInliner()); //// run(group, new MethodInliner());
run(group, new UnusedMethods()); // inliner might leave unused methods //// run(group, new UnusedMethods()); // inliner might leave unused methods
//
// // broken because rename was removed //// // broken because rename was removed
// //run(group, new MethodMover()); //// //run(group, new MethodMover());
// //
// run(group, new FieldInliner()); // run(group, new FieldInliner());
// //
// // XXX this is broken because when moving clinit around, some fields can depend on other fields //// // XXX this is broken because when moving clinit around, some fields can depend on other fields
// // (like multianewarray) //// // (like multianewarray)
// //new FieldMover().run(group); //// //new FieldMover().run(group);
// //
// run(group, new UnusedClass()); // run(group, new UnusedClass());
//
// ModArith mod = new ModArith(); ModArith mod = new ModArith();
// mod.run(group); mod.run(group);
//
// int last = -1, cur; int last = -1, cur;
// while ((cur = mod.runOnce()) > 0) while ((cur = mod.runOnce()) > 0)
// { {
// new MultiplicationDeobfuscator().run(group); new MultiplicationDeobfuscator().run(group);
//
// new MultiplyOneDeobfuscator().run(group); new MultiplyOneDeobfuscator().run(group);
//
// new MultiplyZeroDeobfuscator().run(group); new MultiplyZeroDeobfuscator().run(group);
//
// if (last == cur) if (last == cur)
// { break;
// System.out.println("break");
// break; last = cur;
// } }
//
// last = cur;
// //break;
// }
// eval constant fields (only set once to a constant in ctor) maybe just inline them // eval constant fields (only set once to a constant in ctor) maybe just inline them

View File

@@ -1,5 +1,7 @@
package net.runelite.deob.deobfuscators.rename; package net.runelite.deob.deobfuscators.rename;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
@@ -7,12 +9,15 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import net.runelite.deob.ClassFile; import net.runelite.deob.ClassFile;
import net.runelite.deob.ClassGroup; import net.runelite.deob.ClassGroup;
import net.runelite.deob.Field; import net.runelite.deob.Field;
import net.runelite.deob.Method; import net.runelite.deob.Method;
import net.runelite.deob.attributes.code.instruction.types.SetFieldInstruction; import net.runelite.deob.attributes.code.instruction.types.SetFieldInstruction;
import net.runelite.deob.deobfuscators.Renamer;
import net.runelite.deob.deobfuscators.rename.graph.Graph; import net.runelite.deob.deobfuscators.rename.graph.Graph;
import net.runelite.deob.deobfuscators.rename.graph.Vertex; import net.runelite.deob.deobfuscators.rename.graph.Vertex;
import net.runelite.deob.deobfuscators.rename.graph.VertexType; import net.runelite.deob.deobfuscators.rename.graph.VertexType;
@@ -20,6 +25,7 @@ import net.runelite.deob.execution.Execution;
import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.Frame;
import net.runelite.deob.execution.InstructionContext; import net.runelite.deob.execution.InstructionContext;
import net.runelite.deob.signature.Signature; import net.runelite.deob.signature.Signature;
import net.runelite.deob.util.JarUtil;
import net.runelite.deob.util.NameMappings; import net.runelite.deob.util.NameMappings;
public class Rename2 public class Rename2
@@ -144,13 +150,11 @@ public class Rename2
{ {
Execution eone = new Execution(one); Execution eone = new Execution(one);
eone.setBuildGraph(true); eone.setBuildGraph(true);
//eone.setFollowInvokes(false);
eone.populateInitialMethods(); eone.populateInitialMethods();
eone.run(); eone.run();
Execution etwo = new Execution(two); Execution etwo = new Execution(two);
etwo.setBuildGraph(true); etwo.setBuildGraph(true);
//etwo.setFollowInvokes(false);
etwo.populateInitialMethods(); etwo.populateInitialMethods();
etwo.run(); etwo.run();
@@ -203,9 +207,20 @@ public class Rename2
System.out.println("methods " +g1.solved(VertexType.METHOD)); System.out.println("methods " +g1.solved(VertexType.METHOD));
System.out.println("f " +g1.solved(VertexType.FIELD)); System.out.println("f " +g1.solved(VertexType.FIELD));
NameMappings mappings = rename(one, two); // two -> one NameMappings mappings = buildMappings(one, two); // two -> one
// show(mappings); show(mappings);
rename(mappings, two);
try
{
JarUtil.saveJar(two, new File("d:/rs/07/adamout.jar"));
}
catch (IOException ex)
{
Logger.getLogger(Rename2.class.getName()).log(Level.SEVERE, null, ex);
}
} }
private void show(NameMappings mappings) private void show(NameMappings mappings)
@@ -228,7 +243,7 @@ public class Rename2
} }
} }
private NameMappings rename(ClassGroup one, ClassGroup two) private NameMappings buildMappings(ClassGroup one, ClassGroup two)
{ {
NameMappings mappings = new NameMappings(); NameMappings mappings = new NameMappings();
@@ -261,4 +276,10 @@ public class Rename2
return mappings; return mappings;
} }
private void rename(NameMappings mappings, ClassGroup group)
{
Renamer renamer = new Renamer(mappings);
renamer.run(group);
}
} }