From 2fdf2b47bc72d2fb67f8e3ae9d34299fb67a6c29 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 24 Mar 2016 10:13:18 -0400 Subject: [PATCH] ise tests/cleanup. needs more optimizations. --- .../deobfuscators/IllegalStateExceptions.java | 35 ++++++++-------- .../IllegalStateExceptionsTest.java | 40 +++++++++++++++++++ 2 files changed, 56 insertions(+), 19 deletions(-) create mode 100644 src/test/java/net/runelite/deob/deobfuscators/IllegalStateExceptionsTest.java diff --git a/src/main/java/net/runelite/deob/deobfuscators/IllegalStateExceptions.java b/src/main/java/net/runelite/deob/deobfuscators/IllegalStateExceptions.java index 9240ffb322..fb99889f5f 100644 --- a/src/main/java/net/runelite/deob/deobfuscators/IllegalStateExceptions.java +++ b/src/main/java/net/runelite/deob/deobfuscators/IllegalStateExceptions.java @@ -1,5 +1,6 @@ package net.runelite.deob.deobfuscators; +import java.util.Collection; import java.util.List; import net.runelite.asm.ClassFile; @@ -14,10 +15,8 @@ import net.runelite.asm.attributes.code.instruction.types.JumpingInstruction; import net.runelite.asm.attributes.code.instructions.AThrow; import net.runelite.asm.attributes.code.instructions.Goto; import net.runelite.asm.attributes.code.instructions.If; -import net.runelite.asm.attributes.code.instructions.If0; import net.runelite.asm.attributes.code.instructions.New; import net.runelite.asm.execution.Execution; -import net.runelite.asm.execution.Frame; import net.runelite.asm.execution.InstructionContext; public class IllegalStateExceptions implements Deobfuscator @@ -35,7 +34,7 @@ public class IllegalStateExceptions implements Deobfuscator if (c == null) continue; - assert execution.methods.contains(m); + //assert execution.methods.contains(m); Instructions instructions = c.getInstructions(); instructions.buildJumpGraph(); @@ -45,7 +44,7 @@ public class IllegalStateExceptions implements Deobfuscator { Instruction ins = ilist.get(i); - if (!(ins instanceof ComparisonInstruction)) + if (!(ins instanceof ComparisonInstruction)) // the if continue; Instruction ins2 = ilist.get(i + 1); @@ -62,22 +61,20 @@ public class IllegalStateExceptions implements Deobfuscator Instruction to = jumpIns.getJumps().get(0); // remove stack of if. + Collection ics = execution.getInstructonContexts(ins); + if (ics == null) + continue; // never executed + boolean found = false; - outer: - for (Frame f : execution.processedFrames) - if (f.getMethod() == m) - { - for (InstructionContext ic : f.getInstructions()) - if (ic.getInstruction() == ins) // this is the if - { - found = true; - - if (ins instanceof If) - ic.removeStack(1); - ic.removeStack(0); - break outer; - } - } + for (InstructionContext ic : ics) + { + found = true; + + if (ins instanceof If) + ic.removeStack(1); + ic.removeStack(0); + break; + } if (!found) { System.out.println("Unable to locate instruction ctx to remove stack for illegalstateexception " + ins.getType().getName() + " in method " + m.getName() + " class " + m.getMethods().getClassFile().getName()); diff --git a/src/test/java/net/runelite/deob/deobfuscators/IllegalStateExceptionsTest.java b/src/test/java/net/runelite/deob/deobfuscators/IllegalStateExceptionsTest.java new file mode 100644 index 0000000000..e1e4309fc2 --- /dev/null +++ b/src/test/java/net/runelite/deob/deobfuscators/IllegalStateExceptionsTest.java @@ -0,0 +1,40 @@ +package net.runelite.deob.deobfuscators; + +import java.io.File; +import java.io.IOException; +import net.runelite.asm.ClassGroup; +import net.runelite.deob.util.JarUtil; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +public class IllegalStateExceptionsTest +{ + private static final File GAMEPACK = new File(RenameUniqueTest.class.getResource("/gamepack_v16.jar").getFile()); + + @Rule + public TemporaryFolder folder = new TemporaryFolder(); + + private ClassGroup group; + + @Before + public void before() throws IOException + { + group = JarUtil.loadJar(GAMEPACK); + } + + @After + public void after() throws IOException + { + JarUtil.saveJar(group, folder.newFile()); + } + + @Test + public void testRun() + { + IllegalStateExceptions ise = new IllegalStateExceptions(); + ise.run(group); + } +}