From db089ab628939268139c42a96d753060151b4379 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 10 Oct 2015 15:21:45 -0400 Subject: [PATCH] Small fixups i guess --- .../deobfuscators/arithmetic/ModArith.java | 140 +++++++++--------- .../MultiplicationDeobfuscator.java | 35 +++-- 2 files changed, 94 insertions(+), 81 deletions(-) diff --git a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/ModArith.java b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/ModArith.java index 1f3f53f9e5..7cfc6f9622 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/ModArith.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/ModArith.java @@ -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 constants = null; - try - { - constants = findAssocConstants(field, ctx); - for (int i : constants) - if (i != 1 && i != 0) - constantSetters.put(field, i); - } - catch (OtherFieldException ex) { } +// List 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 values, boolean getter) - { - Map 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 values, boolean getter) +// { +// Map 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 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 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 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; } diff --git a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscator.java b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscator.java index f85a9f15a0..0c8fe514a3 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscator.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscator.java @@ -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 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 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;