Fixed: Try..catch.finally vs loops

This commit is contained in:
Jindra Petřík
2021-02-02 09:42:38 +01:00
parent 28650d40fb
commit e649d08a08
20 changed files with 866 additions and 171 deletions

View File

@@ -431,14 +431,14 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes
+ "{\r\n"
+ "trace(\"A\");\r\n"
+ "}\r\n"
+ "else if(c == 3)\r\n"
+ "{\r\n"
+ "trace(\"B\");\r\n"
+ "}\r\n"
+ "else\r\n"
+ "{\r\n"
+ "if(c != 3)\r\n"
+ "{\r\n"
+ "continue;\r\n"
+ "}\r\n"
+ "trace(\"B\");\r\n"
+ "}\r\n"
+ "trace(\"C\");\r\n"
+ "}\r\n"
+ "trace(\"exit\");\r\n",
@@ -480,14 +480,14 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes
+ "{\r\n"
+ "trace(\"A\");\r\n"
+ "}\r\n"
+ "else if(c == 3)\r\n"
+ "{\r\n"
+ "trace(\"B\");\r\n"
+ "}\r\n"
+ "else\r\n"
+ "{\r\n"
+ "if(c != 3)\r\n"
+ "{\r\n"
+ "continue;\r\n"
+ "}\r\n"
+ "trace(\"B\");\r\n"
+ "}\r\n"
+ "trace(\"C\");\r\n"
+ "}\r\n",
false);
@@ -1303,7 +1303,6 @@ public class ActionScript3ClassicDecompileTest extends ActionScript3DecompileTes
+ "{\r\n"
+ "trace(\"a\");\r\n"
+ "}\r\n"
+ "continue;\r\n"
+ "}\r\n"
+ "catch(e:EOFError)\r\n"
+ "{\r\n"

View File

@@ -76,6 +76,68 @@ public class ActionScript3CrossCompileDecompileTest extends ActionScript3Decompi
false);
}
@Test(dataProvider = "swfNamesProvider")
public void testTryCatchInWhile(String swfUsed) {
decompileMethod(swfUsed, "testTryCatchInWhile", "trace(\"before loop\");\r\n"
+ "while(true)\r\n"
+ "{\r\n"
+ "try\r\n"
+ "{\r\n"
+ "trace(\"in try\");\r\n"
+ "while(true)\r\n"
+ "{\r\n"
+ "trace(\"a\");\r\n"
+ "}\r\n"
+ "}\r\n"
+ "catch(e:EOFError)\r\n"
+ "{\r\n"
+ "continue;\r\n"
+ "}\r\n"
+ "catch(e:Error)\r\n"
+ "{\r\n"
+ "continue;\r\n"
+ "}\r\n"
+ "}\r\n",
false);
}
@Test(dataProvider = "swfNamesProvider")
public void testTryCatchInWhile2(String swfUsed) {
decompileMethod(swfUsed, "testTryCatchInWhile2", "var a:int = 0;\r\n"
+ "a = 0;\r\n"
+ "trace(\"before loop\");\r\n"
+ "while(a > 5)\r\n"
+ "{\r\n"
+ "try\r\n"
+ "{\r\n"
+ "trace(\"in try\");\r\n"
+ "if(a == 6)\r\n"
+ "{\r\n"
+ "continue;\r\n"
+ "}\r\n"
+ "if(a == 7)\r\n"
+ "{\r\n"
+ "break;\r\n"
+ "}\r\n"
+ "trace(\"after inner while\");\r\n"
+ "}\r\n"
+ "catch(e:EOFError)\r\n"
+ "{\r\n"
+ "continue;\r\n"
+ "}\r\n"
+ "catch(e:Error)\r\n"
+ "{\r\n"
+ "if(a == 8)\r\n"
+ "{\r\n"
+ "break;\r\n"
+ "}\r\n"
+ "continue;\r\n"
+ "}\r\n"
+ "a++;\r\n"
+ "}\r\n",
false);
}
@Test(dataProvider = "swfNamesProvider")
public void testTryCatchLoop(String swfUsed) {
decompileMethod(swfUsed, "testTryCatchLoop", "var j:int = 0;\r\n"

View File

@@ -0,0 +1,463 @@
package com.jpexs.decompiler.flash;
import java.io.IOException;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
/**
*
* @author JPEXS
*/
public class ActionScript3CrossCompileSwfToolsDecompileTest extends ActionScript3DecompileTestBase {
@BeforeClass
public void init() throws IOException, InterruptedException {
addSwf("swftools", "testdata/cross_compile/bin/Main.swftools.swf");
}
@Test
public void testTryCatch() {
decompileMethod("swftools", "testTryCatch", "trace(\"before try\");\r\n"
+ "try\r\n"
+ "{\r\n"
+ "trace(\"in try\");\r\n"
+ "}\r\n"
+ "catch(e:Error)\r\n"
+ "{\r\n"
+ "trace(\"in catch\");\r\n"
+ "}\r\n"
+ "trace(\"after\");\r\n",
false);
}
@Test
public void testTryCatchExceptionUsage() {
decompileMethod("swftools", "testTryCatchExceptionUsage", "trace(\"before try\");\r\n"
+ "try\r\n"
+ "{\r\n"
+ "trace(\"in try\");\r\n"
+ "}\r\n"
+ "catch(e:Error)\r\n"
+ "{\r\n"
+ "var _loc1_:* = e;\r\n"
+ "trace(\"catched exception: \" + _loc1_.message);\r\n"
+ "}\r\n"
+ "trace(\"after\");\r\n",
false);
}
@Test
public void testTryCatchIfInTry() {
decompileMethod("swftools", "testTryCatchIfInTry", "var _loc1_:Boolean = true;\r\n"
+ "trace(\"before\");\r\n"
+ "try\r\n"
+ "{\r\n"
+ "if(_loc1_)\r\n"
+ "{\r\n"
+ "trace(\"ret\");\r\n"
+ "return;\r\n"
+ "}\r\n"
+ "trace(\"in try\");\r\n"
+ "}\r\n"
+ "catch(e:Error)\r\n"
+ "{\r\n"
+ "trace(\"in catch\");\r\n"
+ "}\r\n"
+ "trace(\"after\");\r\n",
false);
}
@Test
public void testTryCatchInWhile() {
decompileMethod("swftools", "testTryCatchInWhile", "trace(\"before loop\");\r\n"
+ "while(true)\r\n"
+ "{\r\n"
+ "try\r\n"
+ "{\r\n"
+ "trace(\"in try\");\r\n"
+ "while(true)\r\n"
+ "{\r\n"
+ "trace(\"a\");\r\n"
+ "}\r\n"
+ "}\r\n"
+ "catch(e:EOFError)\r\n"
+ "{\r\n"
+ "continue;\r\n"
+ "}\r\n"
+ "catch(e:Error)\r\n"
+ "{\r\n"
+ "continue;\r\n"
+ "}\r\n"
+ "}\r\n",
false);
}
@Test
public void testTryCatchInWhile2() {
decompileMethod("swftools", "testTryCatchInWhile2", "var _loc1_:int = 0;\r\n"
+ "_loc1_ = 0;\r\n"
+ "trace(\"before loop\");\r\n"
+ "while(_loc1_ > 5)\r\n"
+ "{\r\n"
+ "try\r\n"
+ "{\r\n"
+ "trace(\"in try\");\r\n"
+ "if(_loc1_ == 6)\r\n"
+ "{\r\n"
+ "continue;\r\n"
+ "}\r\n"
+ "if(_loc1_ == 7)\r\n"
+ "{\r\n"
+ "break;\r\n"
+ "}\r\n"
+ "trace(\"after inner while\");\r\n"
+ "}\r\n"
+ "catch(e:EOFError)\r\n"
+ "{\r\n"
+ "continue;\r\n"
+ "}\r\n"
+ "catch(e:Error)\r\n"
+ "{\r\n"
+ "if(_loc1_ == 8)\r\n"
+ "{\r\n"
+ "break;\r\n"
+ "}\r\n"
+ "continue;\r\n"
+ "}\r\n"
+ "_loc1_++;\r\n"
+ "}\r\n",
false);
}
@Test
public void testTryCatchLoop() {
decompileMethod("swftools", "testTryCatchLoop", "var _loc1_:int = 0;\r\n"
+ "while(_loc1_ < 100)\r\n"
+ "{\r\n"
+ "try\r\n"
+ "{\r\n"
+ "var _loc2_:int = 0;\r\n"
+ "while(_loc2_ < 20)\r\n"
+ "{\r\n"
+ "trace(\"a\");\r\n"
+ "_loc2_++;\r\n"
+ "}\r\n"
+ "}\r\n"
+ "catch(e:EOFError)\r\n"
+ "{\r\n"
+ "continue;\r\n"
+ "}\r\n"
+ "catch(e:Error)\r\n"
+ "{\r\n"
+ "continue;\r\n"
+ "}\r\n"
+ "trace(\"after_try\");\r\n"
+ "_loc1_++;\r\n"
+ "}\r\n"
+ "trace(\"end\");\r\n",
false);
}
@Test
public void testTryFinally() {
decompileMethod("swftools", "testTryFinally", "trace(\"before try\");\r\n"
+ "try\r\n"
+ "{\r\n"
+ "try\r\n"
+ "{\r\n"
+ "trace(\"in try\");\r\n"
+ "}\r\n"
+ "catch(e:Error)\r\n"
+ "{\r\n"
+ "trace(\"in catch\");\r\n"
+ "}\r\n"
+ "}\r\n"
+ "catch(_loc_e_:*)\r\n"
+ "{\r\n"
+ "trace(\"in finally\");\r\n"
+ "throw _loc_e_;\r\n"
+ "}\r\n"
+ "trace(\"in finally\");\r\n"
+ "trace(\"after\");\r\n",
false);
}
@Test
public void testTryFinallyDirectReturnInFinally() {
decompileMethod("swftools", "testTryFinallyDirectReturnInFinally", "var _loc1_:String = \"xxx\";\r\n"
+ "try\r\n"
+ "{\r\n"
+ "}\r\n"
+ "catch(e:Error)\r\n"
+ "{\r\n"
+ "trace(\"error\");\r\n"
+ "}\r\n"
+ "finally\r\n"
+ "{\r\n"
+ "trace(\"hi \");\r\n"
+ "if(_loc1_ == \"check\")\r\n"
+ "{\r\n"
+ "return _loc1_;\r\n"
+ "}\r\n"
+ "return \"hu\" + _loc1_;\r\n"
+ "}\r\n",
false);
}
@Test
public void testTryFinallyLoop() {
decompileMethod("swftools", "testTryFinallyLoop", "var _loc1_:* = 0;\r\n"
+ "while(_loc1_ < 10)\r\n"
+ "{\r\n"
+ "trace(\"before try\");\r\n"
+ "try\r\n"
+ "{\r\n"
+ "try\r\n"
+ "{\r\n"
+ "trace(\"in try\");\r\n"
+ "if(_loc1_ == 5)\r\n"
+ "{\r\n"
+ "_loc1_ = _loc1_ + 5;\r\n"
+ "trace(\"continue while\");\r\n"
+ "trace(\"in finally\");\r\n"
+ "continue;\r\n"
+ "}\r\n"
+ "}\r\n"
+ "catch(e:Error)\r\n"
+ "{\r\n"
+ "trace(\"in catch\");\r\n"
+ "}\r\n"
+ "}\r\n"
+ "catch(_loc_e_:*)\r\n"
+ "{\r\n"
+ "trace(\"in finally\");\r\n"
+ "throw _loc_e_;\r\n"
+ "}\r\n"
+ "trace(\"in finally\");\r\n"
+ "trace(\"after\");\r\n"
+ "_loc1_++;\r\n"
+ "}\r\n",
false);
}
@Test
public void testTryFinallyLoopInFinally() {
decompileMethod("swftools", "testTryFinallyLoopInFinally", "var _loc1_:* = 0;\r\n"
+ "while(_loc1_ < 10)\r\n"
+ "{\r\n"
+ "trace(\"before try\");\r\n"
+ "try\r\n"
+ "{\r\n"
+ "trace(\"in try\");\r\n"
+ "}\r\n"
+ "catch(e:Error)\r\n"
+ "{\r\n"
+ "trace(\"in catch\");\r\n"
+ "}\r\n"
+ "finally\r\n"
+ "{\r\n"
+ "if(_loc1_ == 5)\r\n"
+ "{\r\n"
+ "_loc1_ = _loc1_ + 7;\r\n"
+ "trace(\"continue while\");\r\n"
+ "continue;\r\n"
+ "}\r\n"
+ "trace(\"in finally\");\r\n"
+ "}\r\n"
+ "trace(\"after\");\r\n"
+ "_loc1_++;\r\n"
+ "}\r\n",
false);
}
@Test
public void testTryFinallyMultipleCatch() {
decompileMethod("swftools", "testTryFinallyMultipleCatch", "trace(\"before try\");\r\n"
+ "try\r\n"
+ "{\r\n"
+ "try\r\n"
+ "{\r\n"
+ "trace(\"in try\");\r\n"
+ "}\r\n"
+ "catch(e:Error)\r\n"
+ "{\r\n"
+ "trace(\"in catch Error\");\r\n"
+ "}\r\n"
+ "catch(e:EOFError)\r\n"
+ "{\r\n"
+ "trace(\"in catch EOFError\");\r\n"
+ "}\r\n"
+ "}\r\n"
+ "catch(_loc_e_:*)\r\n"
+ "{\r\n"
+ "trace(\"in finally\");\r\n"
+ "throw _loc_e_;\r\n"
+ "}\r\n"
+ "trace(\"in finally\");\r\n"
+ "trace(\"after\");\r\n",
false);
}
@Test
public void testTryFinallyNoCatch() {
decompileMethod("swftools", "testTryFinallyNoCatch", "trace(\"before try\");\r\n"
+ "try\r\n"
+ "{\r\n"
+ "trace(\"in try\");\r\n"
+ "trace(\"in finally\");\r\n"
+ "trace(\"after\");\r\n"
+ "return;\r\n"
+ "}\r\n"
+ "catch(_loc_e_:*)\r\n"
+ "{\r\n"
+ "trace(\"in finally\");\r\n"
+ "throw _loc_e_;\r\n"
+ "}\r\n",
false);
}
@Test
public void testTryFinallyReturn() {
decompileMethod("swftools", "testTryFinallyReturn", "trace(\"before try\");\r\n"
+ "try\r\n"
+ "{\r\n"
+ "try\r\n"
+ "{\r\n"
+ "trace(\"in try\");\r\n"
+ "var _loc1_:int = 5;\r\n"
+ "if(_loc1_ > 4)\r\n"
+ "{\r\n"
+ "trace(\"in finally\");\r\n"
+ "return \"RET\";\r\n"
+ "}\r\n"
+ "trace(\"between\");\r\n"
+ "if(_loc1_ < 3)\r\n"
+ "{\r\n"
+ "trace(\"in finally\");\r\n"
+ "return \"RE2\";\r\n"
+ "}\r\n"
+ "trace(\"in try2\");\r\n"
+ "}\r\n"
+ "catch(e:Error)\r\n"
+ "{\r\n"
+ "trace(\"in catch\");\r\n"
+ "}\r\n"
+ "}\r\n"
+ "catch(_loc_e_:*)\r\n"
+ "{\r\n"
+ "trace(\"in finally\");\r\n"
+ "throw _loc_e_;\r\n"
+ "}\r\n"
+ "trace(\"in finally\");\r\n"
+ "trace(\"after\");\r\n"
+ "return \"RETFINAL\";\r\n",
false);
}
@Test
public void testTryFinallyReturnInFinally() {
decompileMethod("swftools", "testTryFinallyReturnInFinally", "trace(\"before try\");\r\n"
+ "try\r\n"
+ "{\r\n"
+ "trace(\"in try\");\r\n"
+ "var _loc1_:int = 5;\r\n"
+ "if(_loc1_ > 4)\r\n"
+ "{\r\n"
+ "return \"RET\";\r\n"
+ "}\r\n"
+ "}\r\n"
+ "catch(e:Error)\r\n"
+ "{\r\n"
+ "trace(\"in catch\");\r\n"
+ "}\r\n"
+ "finally\r\n"
+ "{\r\n"
+ "trace(\"in finally\");\r\n"
+ "if(_loc1_ > 6)\r\n"
+ "{\r\n"
+ "return \"FINRET1\";\r\n"
+ "}\r\n"
+ "trace(\"xx\");\r\n"
+ "if(_loc1_ > 5)\r\n"
+ "{\r\n"
+ "return \"FINRET2\";\r\n"
+ "}\r\n"
+ "trace(\"nofinret\");\r\n"
+ "}\r\n"
+ "trace(\"after\");\r\n"
+ "return \"RETEXIT\";\r\n",
false);
}
@Test
public void testTryFinallyReturnNested() {
decompileMethod("swftools", "testTryFinallyReturnNested", "var _loc1_:int = Math.random() * 5;\r\n"
+ "try\r\n"
+ "{\r\n"
+ "trace(\"before try2\");\r\n"
+ "try\r\n"
+ "{\r\n"
+ "try\r\n"
+ "{\r\n"
+ "trace(\"in try2\");\r\n"
+ "if(_loc1_ > 4)\r\n"
+ "{\r\n"
+ "trace(\"in finally2\");\r\n"
+ "trace(\"in finally1\");\r\n"
+ "return \"RET\";\r\n"
+ "}\r\n"
+ "}\r\n"
+ "catch(e:Error)\r\n"
+ "{\r\n"
+ "trace(\"in catch\");\r\n"
+ "}\r\n"
+ "}\r\n"
+ "catch(_loc_e_:*)\r\n"
+ "{\r\n"
+ "trace(\"in finally2\");\r\n"
+ "throw _loc_e_;\r\n"
+ "}\r\n"
+ "trace(\"in finally2\");\r\n"
+ "trace(\"after\");\r\n"
+ "trace(\"in finally1\");\r\n"
+ "return \"RETFINAL\";\r\n"
+ "}\r\n"
+ "catch(_loc_e_:*)\r\n"
+ "{\r\n"
+ "trace(\"in finally1\");\r\n"
+ "throw _loc_e_;\r\n"
+ "}\r\n",
false);
}
@Test
public void testTryFinallyReturnVoid() {
decompileMethod("swftools", "testTryFinallyReturnVoid", "var _loc1_:int = Math.random() * 5;\r\n"
+ "trace(\"before try\");\r\n"
+ "try\r\n"
+ "{\r\n"
+ "try\r\n"
+ "{\r\n"
+ "trace(\"in try\");\r\n"
+ "if(_loc1_ > 4)\r\n"
+ "{\r\n"
+ "trace(\"in finally\");\r\n"
+ "return;\r\n"
+ "}\r\n"
+ "trace(\"in try2\");\r\n"
+ "}\r\n"
+ "catch(e:Error)\r\n"
+ "{\r\n"
+ "trace(\"in catch\");\r\n"
+ "}\r\n"
+ "}\r\n"
+ "catch(_loc_e_:*)\r\n"
+ "{\r\n"
+ "trace(\"in finally\");\r\n"
+ "throw _loc_e_;\r\n"
+ "}\r\n"
+ "trace(\"in finally\");\r\n"
+ "trace(\"after\");\r\n",
false);
}
}

View File

@@ -175,6 +175,8 @@ public class AS3Generator {
{"testdata/cross_compile/bin/Main.flex.swf", "flex"},
{"testdata/cross_compile/bin/Main.air.swf", "air"}
}, true);
useFile("ActionScript3CrossCompileSwfToolsDecompileTest", new String[][]{
{"testdata/cross_compile/bin/Main.swftools.swf", "swftools"},}, false);
useFile("ActionScript3AssembledDecompileTest", new String[][]{{"testdata/custom/bin/custom.swf", "assembled"}}, false);
System.exit(0);