something is wrong somewhere but I don't see anything

This commit is contained in:
Adam
2015-09-27 21:26:05 -04:00
parent 812975d7dc
commit d43dc04519
8 changed files with 51 additions and 12 deletions

View File

@@ -4,7 +4,7 @@ import net.runelite.deob.execution.StackContext;
public interface DupInstruction public interface DupInstruction
{ {
public StackContext resolve(StackContext sctx); public StackContext getOriginal(StackContext sctx);
public StackContext getOtherBranch(StackContext sctx); public StackContext getOtherBranch(StackContext sctx);
} }

View File

@@ -60,7 +60,7 @@ public class Dup extends Instruction implements DupInstruction
} }
@Override @Override
public StackContext resolve(StackContext sctx) public StackContext getOriginal(StackContext sctx)
{ {
// ctx = stack pushed by this instruction, return stack popped by this instruction // ctx = stack pushed by this instruction, return stack popped by this instruction
InstructionContext ctx = sctx.getPushed(); InstructionContext ctx = sctx.getPushed();

View File

@@ -73,7 +73,7 @@ public class Dup2 extends Instruction implements DupInstruction
} }
@Override @Override
public StackContext resolve(StackContext ctx) public StackContext getOriginal(StackContext ctx)
{ {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
} }

View File

@@ -81,7 +81,7 @@ public class Dup2_X1 extends Instruction implements DupInstruction
} }
@Override @Override
public StackContext resolve(StackContext ctx) public StackContext getOriginal(StackContext ctx)
{ {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
} }

View File

@@ -95,7 +95,7 @@ public class Dup2_X2 extends Instruction implements DupInstruction
} }
@Override @Override
public StackContext resolve(StackContext ctx) public StackContext getOriginal(StackContext ctx)
{ {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
} }

View File

@@ -56,7 +56,7 @@ public class Dup_X1 extends Instruction implements DupInstruction
} }
@Override @Override
public StackContext resolve(StackContext sctx) public StackContext getOriginal(StackContext sctx)
{ {
// ctx = stack pushed by this instruction, return stack popped by this instruction // ctx = stack pushed by this instruction, return stack popped by this instruction
InstructionContext ctx = sctx.getPushed(); InstructionContext ctx = sctx.getPushed();

View File

@@ -71,14 +71,51 @@ public class Dup_X2 extends Instruction implements DupInstruction
} }
@Override @Override
public StackContext resolve(StackContext ctx) public StackContext getOriginal(StackContext sctx)
{ {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. // 3 2 1 -> 1 3 2 1
InstructionContext ctx = sctx.getPushed();
assert ctx.getInstruction() == this;
assert ctx.getPushes().contains(sctx);
int pushedIndex = ctx.getPushes().indexOf(sctx);
int poppedIndex;
switch (pushedIndex)
{
case 0:
case 3:
poppedIndex = 0;
break;
case 1:
poppedIndex = 2;
break;
case 2:
poppedIndex = 1;
default:
throw new IllegalStateException();
}
return ctx.getPops().get(poppedIndex);
} }
@Override @Override
public StackContext getOtherBranch(StackContext sctx) public StackContext getOtherBranch(StackContext sctx)
{ {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. // sctx = stack pushed by this instruction, return the other branch
InstructionContext ctx = sctx.getPushed();
assert ctx.getInstruction() == this;
assert ctx.getPushes().contains(sctx);
int pushedIndex = ctx.getPushes().indexOf(sctx);
// 3 2 1 -> 1 3 2 1
if (pushedIndex == 0)
return ctx.getPushes().get(3);
else if (pushedIndex == 3)
return ctx.getPushes().get(0);
return null;
} }
} }

View File

@@ -120,9 +120,10 @@ public class MultiplicationDeobfuscator implements Deobfuscator
} }
else if (i.getInstruction() instanceof DupInstruction) else if (i.getInstruction() instanceof DupInstruction)
{ {
if(true) throw new IllegalStateException();
DupInstruction dup = (DupInstruction) i.getInstruction(); DupInstruction dup = (DupInstruction) i.getInstruction();
if (dup instanceof Dup || dup instanceof Dup_X1) //if (dup instanceof Dup || dup instanceof Dup_X1)
{ {
// find other branch of the dup instruction // find other branch of the dup instruction
@@ -139,7 +140,7 @@ public class MultiplicationDeobfuscator implements Deobfuscator
me.dupmagic = pushConstant; me.dupmagic = pushConstant;
StackContext orig = dup.resolve(sctx); // original StackContext orig = dup.getOriginal(sctx); // original
try try
{ {
MultiplicationExpression other = parseExpression(orig.getPushed()); MultiplicationExpression other = parseExpression(orig.getPushed());
@@ -152,7 +153,8 @@ public class MultiplicationDeobfuscator implements Deobfuscator
} }
else else
{ {
System.out.println("dup ins " + i); System.out.println("dup ins " + otherCtxI.getInstruction());
throw new IllegalStateException();
} }
} }
} }