Fix some of the dup stuff, works a little better?

This commit is contained in:
Adam
2015-09-30 20:39:35 -04:00
parent d43dc04519
commit d61d006b34
3 changed files with 45 additions and 12 deletions

View File

@@ -65,6 +65,7 @@ public class Dup extends Instruction implements DupInstruction
// ctx = stack pushed by this instruction, return stack popped by this instruction
InstructionContext ctx = sctx.getPushed();
assert ctx.getInstruction() == this;
assert ctx.getPushes().contains(sctx);
return ctx.getPops().get(0);
}

View File

@@ -120,7 +120,7 @@ public class MultiplicationDeobfuscator implements Deobfuscator
}
else if (i.getInstruction() instanceof DupInstruction)
{
if(true) throw new IllegalStateException();
//if(true) throw new IllegalStateException();
DupInstruction dup = (DupInstruction) i.getInstruction();
//if (dup instanceof Dup || dup instanceof Dup_X1)
@@ -144,7 +144,12 @@ public class MultiplicationDeobfuscator implements Deobfuscator
try
{
MultiplicationExpression other = parseExpression(orig.getPushed());
me.subexpressions.add(other);
// this expression is used elsewhere like 'pushConstant' so any changes
// done to it affect that, too. so multiply it by existing values?
me.instructions.addAll(other.instructions);
me.dupedInstructions.addAll(other.instructions);
me.subexpressions.addAll(other.subexpressions);
//me.subexpressions.add(other);
}
catch (IllegalStateException ex)
{

View File

@@ -8,7 +8,8 @@ import net.runelite.deob.execution.InstructionContext;
public class MultiplicationExpression
{
List<InstructionContext> instructions = new ArrayList<>(); // push constant instructions that are being multiplied
List<InstructionContext> instructions = new ArrayList<>(), // push constant instructions that are being multiplied
dupedInstructions = new ArrayList<>();
List<MultiplicationExpression> subexpressions = new ArrayList<>(); // for distributing, each subexpr is * by this
InstructionContext dupmagic; // inverse of what is distributed to subexpressions gets set here
static boolean replace;
@@ -27,23 +28,49 @@ public class MultiplicationExpression
result *= value;
}
// assert (dupmagic != null) == !dupedInstructions.isEmpty();
if (dupmagic != null)
{
// mul dupmagic by result of dup ins?
PushConstantInstruction pci = (PushConstantInstruction) dupmagic.getInstruction();
int value = (int) pci.getConstant().getObject();
for (InstructionContext ic : dupedInstructions)
{
PushConstantInstruction pci2 = (PushConstantInstruction) ic.getInstruction();
int value2 = (int) pci2.getConstant().getObject();
value *= value2;
}
Instruction newIns = pci.setConstant(new net.runelite.deob.pool.Integer(value));
System.out.println("dupmagic");
assert newIns == (Instruction) pci;
}
// multiply subexpressions by result
if (!subexpressions.isEmpty())
{
for (MultiplicationExpression me : subexpressions)
{
// if (me.instructions.isEmpty() && this.dupmagic != null)
// {
// assert me.dupmagic == null;
// me.dupmagic = this.dupmagic;
// }
count += me.simplify(result);
}
if (dupmagic != null)
{
PushConstantInstruction pci = (PushConstantInstruction) dupmagic.getInstruction();
int value = (int) pci.getConstant().getObject();
value *= DMath.modInverse(result);
pci.setConstant(new net.runelite.deob.pool.Integer(value));
}
// if (dupmagic != null)
// {
// PushConstantInstruction pci = (PushConstantInstruction) dupmagic.getInstruction();
// int value = (int) pci.getConstant().getObject();
//
// value *= DMath.modInverse(result);
//
// pci.setConstant(new net.runelite.deob.pool.Integer(value));
// }
result = 1; // constant has been distributed, outer numbers all go to 1
}