From 695f7de686f72a3a6d453c37de3bd32cf544dd0d Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 1 Nov 2015 17:47:49 -0500 Subject: [PATCH] Various Long work. this is making the int tests fail though --- .../attributes/code/instructions/Dup2_X1.java | 108 +++++++++++++++++- .../code/instructions/LConst_0.java | 8 +- .../code/instructions/LConst_1.java | 8 +- .../attributes/code/instructions/LDC2_W.java | 14 +++ .../attributes/code/instructions/LDC_W.java | 6 + .../deob/deobfuscators/arithmetic/DMath.java | 11 ++ .../deobfuscators/arithmetic/ModArith.java | 12 +- .../MultiplicationDeobfuscator.java | 45 +++++--- .../arithmetic/MultiplicationExpression.java | 38 +++--- .../arithmetic/MultiplyOneDeobfuscator.java | 8 +- .../arithmetic/MultiplyZeroDeobfuscator.java | 19 ++- 11 files changed, 226 insertions(+), 51 deletions(-) diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2_X1.java b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2_X1.java index 0f0f13afc7..2a4965a8f1 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2_X1.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/Dup2_X1.java @@ -76,14 +76,116 @@ public class Dup2_X1 extends Instruction implements DupInstruction } @Override - public StackContext getOriginal(StackContext ctx) + public StackContext getOriginal(StackContext sctx) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + InstructionContext ctx = sctx.getPushed(); + + assert ctx.getInstruction() == this; + assert ctx.getPushes().contains(sctx); + int idx = ctx.getPushes().indexOf(sctx); + + // 2 1 0 -> 1 0 2 1 0 OR 1 0 -> 0 1 0 + + assert ctx.getPushes().size() == 5 || ctx.getPushes().size() == 3; + + int orig; + + if (ctx.getPushes().size() == 5) + { + switch (idx) + { + case 0: + orig = 1; + break; + case 1: + orig = 0; + break; + case 2: + orig = 2; + break; + case 3: + orig = 1; + break; + case 4: + orig = 0; + break; + default: + throw new IllegalStateException(); + } + } + else if (ctx.getPushes().size() == 3) + { + switch (idx) + { + case 0: + orig = 0; + break; + case 1: + orig = 1; + break; + case 2: + orig = 0; + break; + default: + throw new IllegalStateException(); + } + } + else + throw new IllegalStateException(); + + return ctx.getPushes().get(orig); } @Override public StackContext getOtherBranch(StackContext sctx) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + InstructionContext ctx = sctx.getPushed(); + assert ctx.getInstruction() == this; + + assert ctx.getPushes().contains(sctx); + int idx = ctx.getPushes().indexOf(sctx); + + // 2 1 0 -> 1 0 2 1 0 OR 1 0 -> 0 1 0 + + int other; + + if (ctx.getPushes().size() == 5) + { + switch (idx) + { + case 0: + other = 3; + break; + case 1: + other = 4; + break; + case 3: + other = 0; + break; + case 4: + other = 1; + break; + default: + return null; + } + } + else if (ctx.getPushes().size() == 3) + { + switch (idx) + { + case 0: + other = 2; + break; + case 2: + other = 0; + break; + default: + return null; + } + } + else + throw new IllegalStateException(); + + return ctx.getPushes().get(other); } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LConst_0.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LConst_0.java index 2838b7690c..06c339d661 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LConst_0.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LConst_0.java @@ -42,6 +42,12 @@ public class LConst_0 extends Instruction implements PushConstantInstruction @Override public Instruction setConstant(PoolEntry entry) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return new LDC2_W(this.getInstructions(), entry); + } + + @Override + public Instruction makeGeneric() + { + return new LDC2_W(this.getInstructions(), getConstant()); } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LConst_1.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LConst_1.java index 96823a9350..e6b085fcef 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LConst_1.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LConst_1.java @@ -42,6 +42,12 @@ public class LConst_1 extends Instruction implements PushConstantInstruction @Override public Instruction setConstant(PoolEntry entry) { - throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + return new LDC2_W(this.getInstructions(), entry); + } + + @Override + public Instruction makeGeneric() + { + return new LDC2_W(this.getInstructions(), getConstant()); } } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LDC2_W.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LDC2_W.java index 094a86ae97..fd46585360 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LDC2_W.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LDC2_W.java @@ -13,6 +13,7 @@ import net.runelite.deob.pool.PoolEntry; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import net.runelite.deob.pool.ConstantType; public class LDC2_W extends Instruction implements PushConstantInstruction { @@ -27,12 +28,24 @@ public class LDC2_W extends Instruction implements PushConstantInstruction { super(instructions, InstructionType.LDC2_W, -1); this.value = new net.runelite.deob.pool.Long(value); + length += 2; + } + + public LDC2_W(Instructions instructions, PoolEntry value) + { + super(instructions, InstructionType.LDC2_W, -1); + + assert value.getType() == ConstantType.LONG || value.getType() == ConstantType.DOUBLE; + + this.value = value; + length += 2; } @Override public void load(DataInputStream is) throws IOException { value = this.getPool().getEntry(is.readUnsignedShort()); + assert value.getType() == ConstantType.LONG || value.getType() == ConstantType.DOUBLE; length += 2; } @@ -66,6 +79,7 @@ public class LDC2_W extends Instruction implements PushConstantInstruction @Override public Instruction setConstant(PoolEntry entry) { + assert entry.getType() == ConstantType.LONG || entry.getType() == ConstantType.DOUBLE; value = entry; return this; } diff --git a/src/main/java/net/runelite/deob/attributes/code/instructions/LDC_W.java b/src/main/java/net/runelite/deob/attributes/code/instructions/LDC_W.java index 6ab1acbce3..78dd3a39b5 100644 --- a/src/main/java/net/runelite/deob/attributes/code/instructions/LDC_W.java +++ b/src/main/java/net/runelite/deob/attributes/code/instructions/LDC_W.java @@ -13,6 +13,7 @@ import net.runelite.deob.pool.PoolEntry; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.IOException; +import net.runelite.deob.pool.ConstantType; public class LDC_W extends Instruction implements PushConstantInstruction { @@ -29,6 +30,8 @@ public class LDC_W extends Instruction implements PushConstantInstruction { super(instructions, InstructionType.LDC_W, 0); + assert value.getType() != ConstantType.LONG; + this.value = value; length += 2; } @@ -55,6 +58,8 @@ public class LDC_W extends Instruction implements PushConstantInstruction value = this.getPool().getEntry(is.readUnsignedByte()); length += 1; } + + assert value.getType() != ConstantType.LONG; } @Override @@ -120,6 +125,7 @@ public class LDC_W extends Instruction implements PushConstantInstruction public Instruction setConstant(PoolEntry entry) { value = entry; + assert value.getType() != ConstantType.LONG; return this; } diff --git a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/DMath.java b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/DMath.java index bc451c8cee..f2d403b2a8 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/DMath.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/DMath.java @@ -1,6 +1,7 @@ package net.runelite.deob.deobfuscators.arithmetic; import java.math.BigInteger; +import net.runelite.deob.pool.PoolEntry; public class DMath { @@ -117,4 +118,14 @@ public class DMath return equals(one, (int) one); return one.longValue() == two; } + + public static PoolEntry toPool(Number value) + { + if (value instanceof Integer) + return new net.runelite.deob.pool.Integer((int) value); + else if (value instanceof Long) + return new net.runelite.deob.pool.Long((long) value); + else + throw new IllegalArgumentException(); + } } 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 c4714ad1f5..5de05ed88e 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/ModArith.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/ModArith.java @@ -158,7 +158,7 @@ public class ModArith implements Deobfuscator try { - MultiplicationExpression expr = MultiplicationDeobfuscator.parseExpression(e, ctx); + MultiplicationExpression expr = MultiplicationDeobfuscator.parseExpression(e, ctx, ctx.getInstruction().getClass()); if (expr.hasFieldOtherThan(field)) continue; } @@ -515,8 +515,16 @@ public class ModArith implements Deobfuscator if (col == null) continue; + String typeStr = f.getType().getType(); + assert typeStr.equals("I") || typeStr.equals("J"); + + Class typeOfField = f.getType().getType().equals("I") ? Integer.class : Long.class; + // filter out non big ones - Collection col2 = col.stream().filter(i -> DMath.isBig(i.value)).collect(Collectors.toList()); + Collection col2 = col.stream() + .filter(i -> DMath.isBig(i.value)) + .filter(i -> i.value.getClass() == typeOfField) + .collect(Collectors.toList()); // filer out ones that have another field in the expression Collection noOther = col2.stream().filter(i -> !i.other).map(i -> i.value).collect(Collectors.toList()); 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 7b64dac6c4..5a3ba4ca2b 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscator.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationDeobfuscator.java @@ -16,7 +16,9 @@ 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.LDC2_W; import net.runelite.deob.attributes.code.instructions.LDC_W; +import net.runelite.deob.attributes.code.instructions.LMul; import net.runelite.deob.attributes.code.instructions.SiPush; import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Frame; @@ -44,11 +46,11 @@ public class MultiplicationDeobfuscator implements Deobfuscator System.out.println("Total changed " + count); } - public static MultiplicationExpression parseExpression(Execution e, InstructionContext ctx) + public static MultiplicationExpression parseExpression(Execution e, InstructionContext ctx, Class want) { MultiplicationExpression me = new MultiplicationExpression(); - assert !(ctx.getInstruction() instanceof DupInstruction); +// assert !(ctx.getInstruction() instanceof DupInstruction); if (ctx.getInstruction() instanceof LVTInstruction) { @@ -74,7 +76,7 @@ public class MultiplicationDeobfuscator implements Deobfuscator assert storelvt.store(); InstructionContext pushed = storeCtx.getPops().get(0).getPushed(); - return parseExpression(e, pushed); + return parseExpression(e, pushed, want); } } } @@ -94,7 +96,7 @@ public class MultiplicationDeobfuscator implements Deobfuscator for (StackContext sctx : ctx.getPops()) { - if (ctx.getInstruction() instanceof IMul) + if (ctx.getInstruction().getClass() == want) { if (!isOnlyPath(e, ctx, sctx)) continue; @@ -103,7 +105,7 @@ public class MultiplicationDeobfuscator implements Deobfuscator InstructionContext i = sctx.getPushed(); // if this instruction is imul, look at pops - if (ctx.getInstruction() instanceof IMul) + if (ctx.getInstruction().getClass() == want) { if (i.getInstruction() instanceof PushConstantInstruction) { @@ -113,12 +115,12 @@ public class MultiplicationDeobfuscator implements Deobfuscator // a constant of imul me.instructions.add(i); } - else if (i.getInstruction() instanceof IMul) + else if (i.getInstruction().getClass() == want) { // chained imul, append to me try { - MultiplicationExpression other = parseExpression(e, i); + MultiplicationExpression other = parseExpression(e, i, want); me.instructions.addAll(other.instructions); me.subexpressions.addAll(other.subexpressions); @@ -128,12 +130,12 @@ public class MultiplicationDeobfuscator implements Deobfuscator // this is ok? just don't include it? } } - else if (i.getInstruction() instanceof IAdd || i.getInstruction() instanceof ISub) + else if (i.getInstruction().getClass() == want) { // imul using result of iadd or isub. evaluate expression try { - MultiplicationExpression other = parseExpression(e, i); + MultiplicationExpression other = parseExpression(e, i, want); // subexpr me.subexpressions.add(other); @@ -153,19 +155,19 @@ public class MultiplicationDeobfuscator implements Deobfuscator StackContext otherCtx = dup.getOtherBranch(sctx); // other side of dup InstructionContext otherCtxI = otherCtx.getPopped().get(0); // is this irght? - if (otherCtxI.getInstruction() instanceof IMul) + if (otherCtxI.getInstruction().getClass() == want) { //assert otherCtxI.getInstruction() instanceof IMul; InstructionContext pushConstant = otherCtxI.getPops().get(0).getPushed(); - assert pushConstant.getInstruction() instanceof LDC_W; + assert pushConstant.getInstruction() instanceof LDC_W || pushConstant.getInstruction() instanceof LDC2_W; me.dupmagic = pushConstant; StackContext orig = dup.getOriginal(sctx); // original try { - MultiplicationExpression other = parseExpression(e, orig.getPushed()); + MultiplicationExpression other = parseExpression(e, orig.getPushed(), want); // this expression is used elsewhere like 'pushConstant' so any changes // done to it affect that, too. so multiply it by existing values? if (orig.getPushed().getInstruction() instanceof IAdd || orig.getPushed().getInstruction() instanceof ISub) @@ -202,7 +204,7 @@ public class MultiplicationDeobfuscator implements Deobfuscator // this is an iadd/sub else if (ctx.getInstruction() instanceof IAdd || ctx.getInstruction() instanceof ISub) { - MultiplicationExpression other = parseExpression(e, i); // parse this side of the add/sub + MultiplicationExpression other = parseExpression(e, i, want); // parse this side of the add/sub me.subexpressions.add(other); } @@ -220,7 +222,8 @@ public class MultiplicationDeobfuscator implements Deobfuscator public static boolean isOnlyPath(Execution execution, InstructionContext ctx) { - assert ctx.getInstruction() instanceof IMul; + assert ctx.getInstruction() instanceof IMul || ctx.getInstruction() instanceof LMul; + Collection ins = execution.getInstructonContexts(ctx.getInstruction()); for (InstructionContext i : ins) { @@ -254,7 +257,7 @@ public class MultiplicationDeobfuscator implements Deobfuscator public static boolean isOnlyPath(Execution execution, InstructionContext ctx, StackContext sctx) { - assert ctx.getInstruction() instanceof IMul; + assert ctx.getInstruction() instanceof IMul || ctx.getInstruction() instanceof LMul; Collection ins = execution.getInstructonContexts(ctx.getInstruction()); for (InstructionContext i : ins) @@ -294,13 +297,13 @@ public class MultiplicationDeobfuscator implements Deobfuscator { Instruction instruction = ictx.getInstruction(); - if (!(instruction instanceof IMul)) + if (!(instruction instanceof IMul) && !(instruction instanceof LMul)) continue; MultiplicationExpression expression; try { - expression = parseExpression(e, ictx); + expression = parseExpression(e, ictx, instruction.getClass()); } catch (IllegalStateException ex) { @@ -314,7 +317,13 @@ public class MultiplicationDeobfuscator implements Deobfuscator continue; done.add(instruction); - count += expression.simplify(1); + assert instruction instanceof IMul || instruction instanceof LMul; + if (instruction instanceof IMul) + count += expression.simplify(1); + else if (instruction instanceof LMul) + count += expression.simplify(1L); + else + throw new IllegalStateException(); } return count; diff --git a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationExpression.java b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationExpression.java index fcc72ee557..3887d9766f 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationExpression.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplicationExpression.java @@ -16,38 +16,36 @@ public class MultiplicationExpression List subexpressions = new ArrayList<>(); // for distributing, each subexpr is * by this InstructionContext dupmagic; // inverse of what is distributed to subexpressions gets set here - int simplify(int start) + int simplify(Number start) { int count = 0; - int result = start; + Number result = start; // calculate result for (InstructionContext i : instructions) { PushConstantInstruction pci = (PushConstantInstruction) i.getInstruction(); - int value = (int) pci.getConstant().getObject(); + Number value = (Number) pci.getConstant().getObject(); - result *= value; + result = DMath.multiply(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(); + Number value = (Number) pci.getConstant().getObject(); for (InstructionContext ic : dupedInstructions) { PushConstantInstruction pci2 = (PushConstantInstruction) ic.getInstruction(); - int value2 = (int) pci2.getConstant().getObject(); + Number value2 = (Number) pci2.getConstant().getObject(); - value *= value2; + value = DMath.multiply(value, value2); } - Instruction newIns = pci.setConstant(new net.runelite.deob.pool.Integer(value)); - System.out.println("dupmagic"); + Instruction newIns = pci.setConstant(DMath.toPool(value)); assert newIns == (Instruction) pci; } @@ -62,24 +60,32 @@ public class MultiplicationExpression if (dupmagic != null) { PushConstantInstruction pci = (PushConstantInstruction) dupmagic.getInstruction(); - int value = (int) pci.getConstant().getObject(); + Number value = (Number) pci.getConstant().getObject(); - value *= DMath.modInverse(result); + value = DMath.multiply(value, DMath.modInverse(result)); - pci.setConstant(new net.runelite.deob.pool.Integer(value)); + pci.setConstant(DMath.toPool(value)); } - result = 1; // constant has been distributed, outer numbers all go to 1 + // constant has been distributed, outer numbers all go to 1 + if (result instanceof Long) + result = 1L; + else + result = 1; } // set result on ins for (InstructionContext i : instructions) { PushConstantInstruction pci = (PushConstantInstruction) i.getInstruction(); - Instruction newIns = pci.setConstant(new net.runelite.deob.pool.Integer(result)); + Instruction newIns = pci.setConstant(DMath.toPool(result)); ++count; assert newIns == pci; - result = 1; // rest of the results go to 1 + // rest of the results go to 1 + if (result instanceof Long) + result = 1L; + else + result = 1; } return count; diff --git a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscator.java b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscator.java index bddd7d65c3..bc89e794b0 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscator.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyOneDeobfuscator.java @@ -10,6 +10,7 @@ import net.runelite.deob.attributes.code.Instruction; import net.runelite.deob.attributes.code.Instructions; import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction; import net.runelite.deob.attributes.code.instructions.IMul; +import net.runelite.deob.attributes.code.instructions.LMul; import net.runelite.deob.attributes.code.instructions.NOP; import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Frame; @@ -34,7 +35,7 @@ public class MultiplyOneDeobfuscator implements Deobfuscator { Instruction instruction = ictx.getInstruction(); - if (!(instruction instanceof IMul)) + if (!(instruction instanceof IMul) && !(instruction instanceof LMul)) continue; Instructions ins = ictx.getInstruction().getInstructions(); @@ -51,12 +52,12 @@ public class MultiplyOneDeobfuscator implements Deobfuscator int removeIdx = -1; if (one.getPushed().getInstruction() instanceof PushConstantInstruction - && (int) ((PushConstantInstruction) one.getPushed().getInstruction()).getConstant().getObject() == 1) + && DMath.equals((Number) ((PushConstantInstruction) one.getPushed().getInstruction()).getConstant().getObject(), 1)) { removeIdx = 0; } else if (two.getPushed().getInstruction() instanceof PushConstantInstruction - && (int) ((PushConstantInstruction) two.getPushed().getInstruction()).getConstant().getObject() == 1) + && DMath.equals((Number) ((PushConstantInstruction) two.getPushed().getInstruction()).getConstant().getObject(), 1)) { removeIdx = 1; } @@ -69,7 +70,6 @@ public class MultiplyOneDeobfuscator implements Deobfuscator ictx.removeStack(removeIdx); ins.replace(ictx.getInstruction(), new NOP(ins)); - //ins.remove(ictx.getInstruction()); ++count; } diff --git a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyZeroDeobfuscator.java b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyZeroDeobfuscator.java index 29f8b784ed..583f84acff 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyZeroDeobfuscator.java +++ b/src/main/java/net/runelite/deob/deobfuscators/arithmetic/MultiplyZeroDeobfuscator.java @@ -7,7 +7,9 @@ import net.runelite.deob.attributes.code.Instruction; import net.runelite.deob.attributes.code.Instructions; import net.runelite.deob.attributes.code.instruction.types.PushConstantInstruction; import net.runelite.deob.attributes.code.instructions.IMul; +import net.runelite.deob.attributes.code.instructions.LDC2_W; import net.runelite.deob.attributes.code.instructions.LDC_W; +import net.runelite.deob.attributes.code.instructions.LMul; import net.runelite.deob.execution.Execution; import net.runelite.deob.execution.Frame; import net.runelite.deob.execution.InstructionContext; @@ -34,7 +36,7 @@ public class MultiplyZeroDeobfuscator implements Deobfuscator if (ins == null) continue; - if (!(instruction instanceof IMul)) + if (!(instruction instanceof IMul) && !(instruction instanceof LMul)) continue; List ilist = ins.getInstructions(); @@ -49,17 +51,17 @@ public class MultiplyZeroDeobfuscator implements Deobfuscator if (ione instanceof PushConstantInstruction) { PushConstantInstruction pci = (PushConstantInstruction) ione; - int value = (int) pci.getConstant().getObject(); + Number value = (Number) pci.getConstant().getObject(); - if (value == 0) + if (DMath.equals(value, 0)) remove = true; } if (itwo instanceof PushConstantInstruction) { PushConstantInstruction pci = (PushConstantInstruction) itwo; - int value = (int) pci.getConstant().getObject(); + Number value = (Number) pci.getConstant().getObject(); - if (value == 0) + if (DMath.equals(value, 0)) remove = true; } @@ -79,7 +81,12 @@ public class MultiplyZeroDeobfuscator implements Deobfuscator ictx.removeStack(1); ictx.removeStack(0); - ins.replace(instruction, new LDC_W(ins, new net.runelite.deob.pool.Integer(0))); + if (instruction instanceof IMul) + ins.replace(instruction, new LDC_W(ins, new net.runelite.deob.pool.Integer(0))); + else if (instruction instanceof LMul) + ins.replace(instruction, new LDC2_W(ins, 0L)); + else + throw new IllegalStateException(); ++count; }