Small fixups i guess

This commit is contained in:
Adam
2015-10-10 15:21:45 -04:00
parent bd427975ae
commit db089ab628
2 changed files with 94 additions and 81 deletions

View File

@@ -97,6 +97,11 @@ public class ModArith implements Deobfuscator
if (field == null)
continue;
if (field.getName().equals("field2201"))
{
int k=7;
}
int value = (int) pc.getConstant().getObject();
if (value == 1 || value == 0)
@@ -112,17 +117,17 @@ public class ModArith implements Deobfuscator
if (field == null)
continue;
List<Integer> constants = null;
try
{
constants = findAssocConstants(field, ctx);
for (int i : constants)
if (i != 1 && i != 0)
constantSetters.put(field, i);
}
catch (OtherFieldException ex) { }
// List<Integer> constants = null;
// try
// {
// constants = findAssocConstants(field, ctx);
// for (int i : constants)
// if (i != 1 && i != 0)
// constantSetters.put(field, i);
// }
// catch (OtherFieldException ex) { }
StackContext value = ctx.getPops().get(0); // the first thing poppe from both putfield and putstatic is the value
StackContext value = ctx.getPops().get(0); // the first thing popped from both putfield and putstatic is the value
if (!(value.getPushed().getInstruction() instanceof IMul))
continue;
@@ -150,6 +155,11 @@ public class ModArith implements Deobfuscator
if (value2 == 1 || value2 == 0)
continue;
if (field.getName().equals("field2201"))
{
int k=7;
}
constantSetters.put(field, value2);
}
}
@@ -214,60 +224,60 @@ public class ModArith implements Deobfuscator
return p;
}
private Pair guess(Field field, Collection<Integer> values, boolean getter)
{
Map<Integer, Integer> map = CollectionUtils.getCardinalityMap(values); // value -> how many times it occurs
int max = Collections.max(map.values()); // largest occurance #
int size = values.size();
// if (max == size)
// {
// // all getters are the same value
// int constant = getters.iterator().next();
// Pair pair = new Pair();
// pair.getter = constant;
// System.out.println("Guessing " + field.getName() + " getter " + constant + " setter ");
// pair.setter = DMath.modInverse(constant);
// return pair;
// private Pair guess(Field field, Collection<Integer> values, boolean getter)
// {
// Map<Integer, Integer> map = CollectionUtils.getCardinalityMap(values); // value -> how many times it occurs
// int max = Collections.max(map.values()); // largest occurance #
// int size = values.size();
//
//// if (max == size)
//// {
//// // all getters are the same value
//// int constant = getters.iterator().next();
//// Pair pair = new Pair();
//// pair.getter = constant;
//// System.out.println("Guessing " + field.getName() + " getter " + constant + " setter ");
//// pair.setter = DMath.modInverse(constant);
//// return pair;
//// }
////
//// if (size < 50)
//// return null;
//
//// if (((float) max / (float) size) < 0.9)
//// return null;
//
// for (final Map.Entry<Integer, Integer> entry : map.entrySet()) {
// if (max == entry.getValue()) {
// int constant = entry.getKey();
// int inverse;
// try
// {
// inverse = DMath.modInverse(constant);
// }
// catch (ArithmeticException ex)
// {
// break;
// }
//
// Pair pair = new Pair();
// if (getter)
// {
// pair.getter = constant;
// pair.setter = inverse;
// }
// else
// {
// pair.getter = inverse;
// pair.setter = constant;
// }
//
// return pair;
// }
// }
//
// if (size < 50)
// return null;
// if (((float) max / (float) size) < 0.9)
// return null;
for (final Map.Entry<Integer, Integer> entry : map.entrySet()) {
if (max == entry.getValue()) {
int constant = entry.getKey();
int inverse;
try
{
inverse = DMath.modInverse(constant);
}
catch (ArithmeticException ex)
{
break;
}
Pair pair = new Pair();
if (getter)
{
pair.getter = constant;
pair.setter = inverse;
}
else
{
pair.getter = inverse;
pair.setter = constant;
}
return pair;
}
}
return null;
}
// return null;
// }
private void reduce()
{
@@ -277,11 +287,6 @@ public class ModArith implements Deobfuscator
Collection<Integer> getters = constantGetters.getCollection(f),
setters = constantSetters.getCollection(f);
if (f.getName().equals("field542"))
{
int i =5;
}
if (getters == null || setters == null)
continue;
@@ -421,6 +426,7 @@ public class ModArith implements Deobfuscator
//if (!field.getName().equals("field3014") && !field.getName().equals("field2960"))
if (!field.getName().equals("field2201"))
{
int j =5;
// continue;
}

View File

@@ -13,6 +13,7 @@ import net.runelite.deob.attributes.code.instruction.types.GetFieldInstruction;
import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction;
import net.runelite.deob.attributes.code.instructions.BiPush;
import net.runelite.deob.attributes.code.instructions.IAdd;
import net.runelite.deob.attributes.code.instructions.IConst_M1;
import net.runelite.deob.attributes.code.instructions.IMul;
import net.runelite.deob.attributes.code.instructions.ISub;
import net.runelite.deob.attributes.code.instructions.LDC_W;
@@ -49,7 +50,8 @@ public class MultiplicationDeobfuscator implements Deobfuscator
if (ctx.getInstruction() instanceof PushConstantInstruction)
{
if (ctx.getInstruction() instanceof BiPush || ctx.getInstruction() instanceof SiPush)
if (ctx.getInstruction() instanceof BiPush || ctx.getInstruction() instanceof SiPush
|| ctx.getInstruction() instanceof IConst_M1)
{
throw new IllegalStateException();
}
@@ -92,7 +94,8 @@ public class MultiplicationDeobfuscator implements Deobfuscator
{
if (i.getInstruction() instanceof PushConstantInstruction)
{
if (i.getInstruction() instanceof BiPush || i.getInstruction() instanceof SiPush)
if (i.getInstruction() instanceof BiPush || i.getInstruction() instanceof SiPush
|| i.getInstruction() instanceof IConst_M1)
throw new IllegalStateException();
// a constant of imul
@@ -271,19 +274,23 @@ public class MultiplicationDeobfuscator implements Deobfuscator
if (one.getInstruction() != two.getInstruction())
return false;
// check if stack at time of execution is equal
List<StackContext> ours = one.getStack().getStack(), theirs = two.getStack().getStack();
//Stack ours = new Stack(one.getStack()), // copy stacks since we destroy them
// theirs = new Stack(two.getStack());
if (ours.size() != theirs.size()) // is this possible?
return false;
assert ours.contains(sctx);
int i = ours.indexOf(sctx);
StackContext theirsctx = theirs.get(i);
assert one.getPops().contains(sctx);
int i = one.getPops().indexOf(sctx);
StackContext theirsctx = two.getPops().get(i);
// // check if stack at time of execution is equal
// List<StackContext> ours = one.getStack().getStack(), theirs = two.getStack().getStack();
// //Stack ours = new Stack(one.getStack()), // copy stacks since we destroy them
//// theirs = new Stack(two.getStack());
//
// if (ours.size() != theirs.size()) // is this possible?
// return false;
//
// assert ours.contains(sctx);
// int i = ours.indexOf(sctx);
//
// StackContext theirsctx = theirs.get(i);
//
if (sctx.getPushed().getInstruction() != theirsctx.getPushed().getInstruction())
return false;