diff --git a/src/com/jpexs/decompiler/flash/action/swf4/ActionIf.java b/src/com/jpexs/decompiler/flash/action/swf4/ActionIf.java index 343002859..11e18d784 100644 --- a/src/com/jpexs/decompiler/flash/action/swf4/ActionIf.java +++ b/src/com/jpexs/decompiler/flash/action/swf4/ActionIf.java @@ -81,7 +81,7 @@ public class ActionIf extends Action { } public ActionIf(FlasmLexer lexer) throws IOException, ParseException { - super(0x9D, -1); + super(0x9D, 2); identifier = lexIdentifier(lexer); } diff --git a/test/com/jpexs/decompiler/flash/ActionScript2ModificationTest.java b/test/com/jpexs/decompiler/flash/ActionScript2ModificationTest.java index ce7cd81a0..c59febbee 100644 --- a/test/com/jpexs/decompiler/flash/ActionScript2ModificationTest.java +++ b/test/com/jpexs/decompiler/flash/ActionScript2ModificationTest.java @@ -66,25 +66,13 @@ public class ActionScript2ModificationTest extends ActionStript2TestBase { return actions; } - @Test - public void testRemoveAction() { - String actionsString = - "ConstantPool\n" + - "DefineFunction \"test\" 1 \"p1\" {\n" + - "Push 1\n" + - "}\n" + - "Push 2\n" + - "Jump label1\n" + - "label1:Push 3"; - String expectedResult = - "ConstantPool\n" + - "DefineFunction \"test\" 1 \"p1\" {\n" + - "Push 1\n" + - "}\n" + - "Push 2 3"; + public void testRemoveAction(String actionsString, String expectedResult, int[] actionsToRemove) { try { ActionList actions = ASMParser.parse(0, true, actionsString, swf.version, false); - actions.removeAction(4); // jump + + for (int i : actionsToRemove) { + actions.removeAction(i); + } DoActionTag doa = getFirstActionTag(); doa.setActionBytes(Action.actionsToBytes(actions, true, swf.version)); @@ -100,4 +88,120 @@ public class ActionScript2ModificationTest extends ActionStript2TestBase { fail(); } } + + @Test + public void testRemoveJumpAction() { + String actionsString = + "ConstantPool\n" + + "DefineFunction \"test\" 1 \"p1\" {\n" + + "Push 1\n" + + "Return\n" + + "}\n" + + "Push 2\n" + + "Jump label_1\n" + // remove this action + "label_1:Push 3"; + String expectedResult = + "ConstantPool\n" + + "DefineFunction \"test\" 1 \"p1\" {\n" + + "Push 1\n" + + "Return\n" + + "}\n" + + "Push 2 3"; + testRemoveAction(actionsString, expectedResult, new int[] {5}); + } + + @Test + public void testRemoveActionFromContainer() { + String actionsString = + "ConstantPool\n" + + "DefineFunction \"test\" 1 \"p1\" {\n" + + "Push 1\n" + // remove this action + "Return\n" + + "}\n" + + "Push 2\n" + + "Jump label_1\n" + + "label_1:Push 3"; + String expectedResult = + "ConstantPool\n" + + "DefineFunction \"test\" 1 \"p1\" {\n" + + "Return\n" + + "}\n" + + "Push 2\n" + + "Jump label_1\n" + + "label_1:Push 3"; + testRemoveAction(actionsString, expectedResult, new int[] {2}); + } + + @Test + public void testRemoveLastActionFromContainer() { + String actionsString = + "ConstantPool\n" + + "DefineFunction \"test\" 1 \"p1\" {\n" + + "Push 1\n" + + "GetVariable\n" + // remove this action + "}\n" + + "Push 2\n" + + "Jump label_1\n" + + "label_1:Push 3"; + String expectedResult = + "ConstantPool\n" + + "DefineFunction \"test\" 1 \"p1\" {\n" + + "Push 1\n" + + "}\n" + + "Push 2\n" + + "Jump label_1\n" + + "label_1:Push 3"; + testRemoveAction(actionsString, expectedResult, new int[] {3}); + } + + @Test + public void testRemoveIfTargetAction() { + String actionsString = + "ConstantPool\n" + + "DefineFunction \"test\" 1 \"p1\" {\n" + + "Push 1\n" + + "GetVariable\n" + + "}\n" + + "Push 2\n" + + "If label_1\n" + + "Push 3\n" + + "label_1:Push 4\n" + // remove this action + "Push 5"; // after removing the previous action the if action should jump here + String expectedResult = + "ConstantPool\n" + + "DefineFunction \"test\" 1 \"p1\" {\n" + + "Push 1\n" + + "GetVariable\n" + + "}\n" + + "Push 2\n" + + "If label_1\n" + + "Push 3\n" + + "label_1:Push 5"; + testRemoveAction(actionsString, expectedResult, new int[] {7}); + } + + @Test + public void testRemoveIfTargetLastAction() { + String actionsString = + "ConstantPool\n" + + "DefineFunction \"test\" 1 \"p1\" {\n" + + "Push 1\n" + + "GetVariable\n" + + "}\n" + + "Push 2\n" + + "If label_1\n" + + "Push 3\n" + + "label_1:Push 4"; // remove this action + String expectedResult = + "ConstantPool\n" + + "DefineFunction \"test\" 1 \"p1\" {\n" + + "Push 1\n" + + "GetVariable\n" + + "}\n" + + "Push 2\n" + + "If label_1\n" + + "Push 3\n" + + "label_1:"; + testRemoveAction(actionsString, expectedResult, new int[] {7}); + } }