From af42bb3f7d9e2d5e43c357769e1bcf8fdceec2d8 Mon Sep 17 00:00:00 2001 From: honfika Date: Sat, 28 Jun 2014 08:08:37 +0200 Subject: [PATCH] test fixed --- .../flash/ActionScript2AssemblerTest.java | 158 +++++++-------- .../flash/ActionScript2DeobfuscatorTest.java | 184 +++++++++--------- 2 files changed, 171 insertions(+), 171 deletions(-) diff --git a/test/com/jpexs/decompiler/flash/ActionScript2AssemblerTest.java b/test/com/jpexs/decompiler/flash/ActionScript2AssemblerTest.java index 687bd0892..842c7bc98 100644 --- a/test/com/jpexs/decompiler/flash/ActionScript2AssemblerTest.java +++ b/test/com/jpexs/decompiler/flash/ActionScript2AssemblerTest.java @@ -1,79 +1,79 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash; - -import com.jpexs.decompiler.flash.action.Action; -import com.jpexs.decompiler.flash.action.parser.ParseException; -import com.jpexs.decompiler.flash.action.parser.pcode.ASMParser; -import com.jpexs.decompiler.flash.configuration.Configuration; -import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; -import com.jpexs.decompiler.flash.gui.Main; -import com.jpexs.decompiler.flash.helpers.CodeFormatting; -import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; -import com.jpexs.decompiler.flash.tags.DoActionTag; -import java.io.BufferedInputStream; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.List; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -/** - * - * @author JPEXS - */ -public class ActionScript2AssemblerTest extends ActionStript2TestBase { - - @BeforeClass - public void init() throws IOException, InterruptedException { - Main.initLogging(false); - Configuration.autoDeobfuscate.set(false); - swf = new SWF(new BufferedInputStream(new FileInputStream("testdata/as2/as2.swf")), false); - } - - @Test - public void testModifiedConstantPools() { - String actionsString = "ConstantPool \"ok\"\n" - + "Jump loc001f\n" - + "loc000d:Push \"ok\" false\n" - + "SetVariable\n" - + "Jump loc002f\n" - + "loc001f:ConstantPool \"wrong\"\n" - + "Jump loc000d\n" - + "loc002f:"; - try { - List actions = ASMParser.parse(0, 0, true, actionsString, swf.version, false); - - DoActionTag doa = getFirstActionTag(); - doa.setActionBytes(Action.actionsToBytes(actions, true, swf.version)); - HilightedTextWriter writer = new HilightedTextWriter(new CodeFormatting(), false); - Action.actionsToSource(doa, doa.getActions(), "", writer); - String actualResult = writer.toString(); - writer = new HilightedTextWriter(new CodeFormatting(), false); - doa.getASMSource(ScriptExportMode.PCODE, writer, null); - String decompiled = writer.toString(); - - assertEquals(actualResult.trim(), "ok = false;"); - assertTrue(decompiled.contains("Push \"ok\" false") || decompiled.contains("Push constant0 false")); - } catch (IOException | ParseException | InterruptedException ex) { - fail(); - } - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash; + +import com.jpexs.decompiler.flash.action.Action; +import com.jpexs.decompiler.flash.action.parser.ParseException; +import com.jpexs.decompiler.flash.action.parser.pcode.ASMParser; +import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode; +import com.jpexs.decompiler.flash.gui.Main; +import com.jpexs.decompiler.flash.helpers.CodeFormatting; +import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; +import com.jpexs.decompiler.flash.tags.DoActionTag; +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.List; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * + * @author JPEXS + */ +public class ActionScript2AssemblerTest extends ActionStript2TestBase { + + @BeforeClass + public void init() throws IOException, InterruptedException { + Main.initLogging(false); + Configuration.autoDeobfuscate.set(false); + swf = new SWF(new BufferedInputStream(new FileInputStream("testdata/as2/as2.swf")), false); + } + + @Test + public void testModifiedConstantPools() { + String actionsString = "ConstantPool \"ok\"\n" + + "Jump loc001f\n" + + "loc000d:Push \"ok\" false\n" + + "SetVariable\n" + + "Jump loc002f\n" + + "loc001f:ConstantPool \"wrong\"\n" + + "Jump loc000d\n" + + "loc002f:"; + try { + List actions = ASMParser.parse(0, true, actionsString, swf.version, false); + + DoActionTag doa = getFirstActionTag(); + doa.setActionBytes(Action.actionsToBytes(actions, true, swf.version)); + HilightedTextWriter writer = new HilightedTextWriter(new CodeFormatting(), false); + Action.actionsToSource(doa, doa.getActions(), "", writer); + String actualResult = writer.toString(); + writer = new HilightedTextWriter(new CodeFormatting(), false); + doa.getASMSource(ScriptExportMode.PCODE, writer, null); + String decompiled = writer.toString(); + + assertEquals(actualResult.trim(), "ok = false;"); + assertTrue(decompiled.contains("Push \"ok\" false") || decompiled.contains("Push constant0 false")); + } catch (IOException | ParseException | InterruptedException ex) { + fail(); + } + } +} diff --git a/test/com/jpexs/decompiler/flash/ActionScript2DeobfuscatorTest.java b/test/com/jpexs/decompiler/flash/ActionScript2DeobfuscatorTest.java index a214eabd9..83c699329 100644 --- a/test/com/jpexs/decompiler/flash/ActionScript2DeobfuscatorTest.java +++ b/test/com/jpexs/decompiler/flash/ActionScript2DeobfuscatorTest.java @@ -1,92 +1,92 @@ -/* - * Copyright (C) 2010-2014 JPEXS - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package com.jpexs.decompiler.flash; - -import com.jpexs.decompiler.flash.action.Action; -import com.jpexs.decompiler.flash.action.parser.ParseException; -import com.jpexs.decompiler.flash.action.parser.pcode.ASMParser; -import com.jpexs.decompiler.flash.configuration.Configuration; -import com.jpexs.decompiler.flash.gui.Main; -import com.jpexs.decompiler.flash.helpers.CodeFormatting; -import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; -import com.jpexs.decompiler.flash.tags.DoActionTag; -import java.io.BufferedInputStream; -import java.io.FileInputStream; -import java.io.IOException; -import java.util.List; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -/** - * - * @author JPEXS - */ -public class ActionScript2DeobfuscatorTest extends ActionStript2TestBase { - - @BeforeClass - public void init() throws IOException, InterruptedException { - Main.initLogging(false); - Configuration.autoDeobfuscate.set(true); - swf = new SWF(new BufferedInputStream(new FileInputStream("testdata/as2/as2.swf")), false); - } - - @Test - public void testRemoveJumpsToTheNextAction() { - String actionsString = "ConstantPool \"a\" \"b\" \"c\"\n" - + "Push false register1\n" - + "StoreRegister 2\n" - + "Pop\n" - + "Push register2\n" - + "StoreRegister 0\n" - + "Push \"a\"\n" - + "StrictEquals\n" - + "If loc005a\n" - + "Push register0 \"b\"\n" - + "StrictEquals\n" - + "If loc0068\n" - + "Jump loc0048;\n" - + "loc0048:Push register0 \"c\"\n" - + "StrictEquals\n" - + "If loc0076\n" - + "Jump loc0084\n" - + "loc005a:Push 1\n" - + "Trace\n" - + "Jump loc0084\n" - + "loc0068:Push 2\n" - + "Trace\n" - + "Jump loc0084\n" - + "loc0076:Push 3\n" - + "Trace\n" - + "Jump loc0084\n" - + "loc0084:"; - try { - List actions = ASMParser.parse(0, 0, true, actionsString, swf.version, false); - - DoActionTag doa = getFirstActionTag(); - doa.setActionBytes(Action.actionsToBytes(actions, true, swf.version)); - HilightedTextWriter writer = new HilightedTextWriter(new CodeFormatting(), false); - Action.actionsToSource(doa, doa.getActions(), "", writer); - String actualResult = writer.toString(); - - assertTrue(actualResult.contains("case \"c\":")); - } catch (IOException | ParseException | InterruptedException ex) { - fail(); - } - } -} +/* + * Copyright (C) 2010-2014 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash; + +import com.jpexs.decompiler.flash.action.Action; +import com.jpexs.decompiler.flash.action.parser.ParseException; +import com.jpexs.decompiler.flash.action.parser.pcode.ASMParser; +import com.jpexs.decompiler.flash.configuration.Configuration; +import com.jpexs.decompiler.flash.gui.Main; +import com.jpexs.decompiler.flash.helpers.CodeFormatting; +import com.jpexs.decompiler.flash.helpers.HilightedTextWriter; +import com.jpexs.decompiler.flash.tags.DoActionTag; +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.List; +import static org.testng.Assert.assertTrue; +import static org.testng.Assert.fail; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +/** + * + * @author JPEXS + */ +public class ActionScript2DeobfuscatorTest extends ActionStript2TestBase { + + @BeforeClass + public void init() throws IOException, InterruptedException { + Main.initLogging(false); + Configuration.autoDeobfuscate.set(true); + swf = new SWF(new BufferedInputStream(new FileInputStream("testdata/as2/as2.swf")), false); + } + + @Test + public void testRemoveJumpsToTheNextAction() { + String actionsString = "ConstantPool \"a\" \"b\" \"c\"\n" + + "Push false register1\n" + + "StoreRegister 2\n" + + "Pop\n" + + "Push register2\n" + + "StoreRegister 0\n" + + "Push \"a\"\n" + + "StrictEquals\n" + + "If loc005a\n" + + "Push register0 \"b\"\n" + + "StrictEquals\n" + + "If loc0068\n" + + "Jump loc0048;\n" + + "loc0048:Push register0 \"c\"\n" + + "StrictEquals\n" + + "If loc0076\n" + + "Jump loc0084\n" + + "loc005a:Push 1\n" + + "Trace\n" + + "Jump loc0084\n" + + "loc0068:Push 2\n" + + "Trace\n" + + "Jump loc0084\n" + + "loc0076:Push 3\n" + + "Trace\n" + + "Jump loc0084\n" + + "loc0084:"; + try { + List actions = ASMParser.parse(0, true, actionsString, swf.version, false); + + DoActionTag doa = getFirstActionTag(); + doa.setActionBytes(Action.actionsToBytes(actions, true, swf.version)); + HilightedTextWriter writer = new HilightedTextWriter(new CodeFormatting(), false); + Action.actionsToSource(doa, doa.getActions(), "", writer); + String actualResult = writer.toString(); + + assertTrue(actualResult.contains("case \"c\":")); + } catch (IOException | ParseException | InterruptedException ex) { + fail(); + } + } +}