From 4fb62ab85dc98c8a8bbe79cafa18a8d42880cc43 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Sun, 29 Nov 2015 08:22:25 +0100 Subject: [PATCH 1/8] add test for FastActionList --- .../action/fastactionlist/FastActionList.java | 5 + .../flash/action/parser/pcode/ASMParser.java | 4 + .../flash/ActionScript2ModificationTest.java | 101 ++++++++++++++++-- 3 files changed, 103 insertions(+), 7 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java index 4f0b3aacd..ab7eaee5a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java @@ -57,6 +57,11 @@ public class FastActionList implements Collection { getJumps(actions, actionItemMap); } + public final ActionItem insertItemBefore(ActionItem item, Action action) { + ActionItem newItem = new ActionItem(action); + return insertItemBefore(item, newItem); + } + public final ActionItem insertItemAfter(ActionItem item, Action action) { ActionItem newItem = new ActionItem(action); return insertItemAfter(item, newItem); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/pcode/ASMParser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/pcode/ASMParser.java index 1dd150a30..6f681cf0b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/pcode/ASMParser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/pcode/ASMParser.java @@ -550,6 +550,10 @@ public class ASMParser { } } + if (ret.size() == 0 || !(ret.get(ret.size() - 1) instanceof ActionEnd)) { + ret.add(new ActionEnd()); + } + return ret; } } diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2ModificationTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2ModificationTest.java index e8e22ac2f..1f90b8ed6 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2ModificationTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript2ModificationTest.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.ActionList; +import com.jpexs.decompiler.flash.action.fastactionlist.FastActionList; import com.jpexs.decompiler.flash.action.parser.ActionParseException; import com.jpexs.decompiler.flash.action.parser.pcode.ASMParser; import com.jpexs.decompiler.flash.action.swf4.ActionJump; @@ -67,7 +68,7 @@ public class ActionScript2ModificationTest extends ActionScript2TestBase { return actions; } - public void testRemoveAction(String actionsString, String expectedResult, int[] actionsToRemove) { + public void testRemoveActionNormal(String actionsString, String expectedResult, int[] actionsToRemove) { try { ActionList actions = ASMParser.parse(0, true, actionsString, swf.version, false); @@ -90,7 +91,38 @@ public class ActionScript2ModificationTest extends ActionScript2TestBase { } } - public void testAddAction(String actionsString, String expectedResult, Action action, int index) { + public void testRemoveActionFast(String actionsString, String expectedResult, int[] actionsToRemove) { + try { + ActionList actions = ASMParser.parse(0, true, actionsString, swf.version, false); + FastActionList fastActions = new FastActionList(actions); + + for (int i : actionsToRemove) { + fastActions.removeItem(i, 1); + } + + actions = fastActions.toActionList(); + + DoActionTag doa = getFirstActionTag(); + doa.setActionBytes(Action.actionsToBytes(actions, true, swf.version)); + HighlightedTextWriter writer = new HighlightedTextWriter(new CodeFormatting(), false); + doa.getASMSource(ScriptExportMode.PCODE, writer, doa.getActions()); + String actualResult = normalizeLabels(writer.toString()); + + actualResult = cleanPCode(actualResult); + expectedResult = cleanPCode(expectedResult); + + Assert.assertEquals(actualResult, expectedResult); + } catch (IOException | ActionParseException | InterruptedException ex) { + fail(); + } + } + + public void testRemoveAction(String actionsString, String expectedResult, int[] actionsToRemove) { + testRemoveActionNormal(actionsString, expectedResult, actionsToRemove); + testRemoveActionFast(actionsString, expectedResult, actionsToRemove); + } + + public void testAddActionNormal(String actionsString, String expectedResult, Action action, int index) { try { ActionList actions = ASMParser.parse(0, true, actionsString, swf.version, false); @@ -111,6 +143,29 @@ public class ActionScript2ModificationTest extends ActionScript2TestBase { } } + public void testAddActionFast(String actionsString, String expectedResult, Action action, int index) { + try { + ActionList actions = ASMParser.parse(0, true, actionsString, swf.version, false); + FastActionList fastActions = new FastActionList(actions); + + fastActions.insertItemBefore(fastActions.get(index), action); + actions = fastActions.toActionList(); + + DoActionTag doa = getFirstActionTag(); + doa.setActionBytes(Action.actionsToBytes(actions, true, swf.version)); + HighlightedTextWriter writer = new HighlightedTextWriter(new CodeFormatting(), false); + doa.getASMSource(ScriptExportMode.PCODE, writer, doa.getActions()); + String actualResult = normalizeLabels(writer.toString()); + + actualResult = cleanPCode(actualResult); + expectedResult = cleanPCode(expectedResult); + + Assert.assertEquals(actualResult, expectedResult); + } catch (IOException | ActionParseException | InterruptedException ex) { + fail(); + } + } + @Test public void testRemoveJumpAction() { String actionsString @@ -227,6 +282,33 @@ public class ActionScript2ModificationTest extends ActionScript2TestBase { testRemoveAction(actionsString, expectedResult, new int[]{7}); } + @Test + public void testAddAtionFirst() { + 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"; + String expectedResult + = "GetMember\n" + + "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"; + testAddActionNormal(actionsString, expectedResult, new ActionGetMember(), 0); + testAddActionFast(actionsString, expectedResult, new ActionGetMember(), 0); + } + @Test public void testAddAtion1() { String actionsString @@ -250,7 +332,8 @@ public class ActionScript2ModificationTest extends ActionScript2TestBase { + "If label_1\n" + "Push 3\n" + "label_1:Push 4"; - testAddAction(actionsString, expectedResult, new ActionGetMember(), 1); + testAddActionNormal(actionsString, expectedResult, new ActionGetMember(), 1); + testAddActionFast(actionsString, expectedResult, new ActionGetMember(), 1); } @Test @@ -276,7 +359,8 @@ public class ActionScript2ModificationTest extends ActionScript2TestBase { + "If label_1\n" + "Push 3\n" + "label_1:Push 4"; - testAddAction(actionsString, expectedResult, new ActionGetMember(), 2); + testAddActionNormal(actionsString, expectedResult, new ActionGetMember(), 2); + testAddActionFast(actionsString, expectedResult, new ActionGetMember(), 2); } @Test @@ -302,7 +386,8 @@ public class ActionScript2ModificationTest extends ActionScript2TestBase { + "Push 3\n" + "GetMember\n" + "label_1:Push 4"; - testAddAction(actionsString, expectedResult, new ActionGetMember(), 7); + testAddActionNormal(actionsString, expectedResult, new ActionGetMember(), 7); + testAddActionFast(actionsString, expectedResult, new ActionGetMember(), 7); } @Test @@ -328,7 +413,8 @@ public class ActionScript2ModificationTest extends ActionScript2TestBase { + "If label_1\n" + "Push 3\n" + "label_1:Push 4"; - testAddAction(actionsString, expectedResult, new ActionGetMember(), 4); + testAddActionNormal(actionsString, expectedResult, new ActionGetMember(), 4); + testAddActionFast(actionsString, expectedResult, new ActionGetMember(), 4); } @Test @@ -353,6 +439,7 @@ public class ActionScript2ModificationTest extends ActionScript2TestBase { ActionJump jump = new ActionJump(0); jump.setAddress(9); jump.setJumpOffset(24 - 9 - 5); - testAddAction(actionsString, expectedResult, jump, 3); + testAddActionNormal(actionsString, expectedResult, jump, 3); + testAddActionFast(actionsString, expectedResult, jump, 3); } } From 2b17094592d62791907c67316e366c9af4ff0452 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Sun, 29 Nov 2015 11:49:12 +0100 Subject: [PATCH 2/8] unused field removed from AVM2Code --- .../src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index 23fb0c645..e4b2ce7de 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -635,8 +635,6 @@ public class AVM2Code implements Cloneable { } } - public boolean hideTemporaryRegisters = true; - public static final String IDENTOPEN = "/*IDENTOPEN*/"; public static final String IDENTCLOSE = "/*IDENTCLOSE*/"; From 0cf0df67ea399466bc65dade2e113f7a7bf2ffdf Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Mon, 30 Nov 2015 09:16:51 +0100 Subject: [PATCH 3/8] using existing getOffset method everywhere, made offset is privete --- .../decompiler/flash/abc/avm2/AVM2Code.java | 56 ++++++---- .../deobfuscation/AVM2DeobfuscatorGetSet.java | 4 +- .../deobfuscation/AVM2DeobfuscatorJumps.java | 4 +- .../AVM2DeobfuscatorRegisters.java | 4 +- .../AVM2DeobfuscatorRegistersOld.java | 6 +- .../deobfuscation/AVM2DeobfuscatorSimple.java | 104 +++++++++--------- .../AVM2DeobfuscatorSimpleOld.java | 14 +-- .../avm2/instructions/AVM2Instruction.java | 6 +- .../instructions/InstructionDefinition.java | 2 +- .../abc/avm2/parser/pcode/ASM3Parser.java | 4 +- .../parser/script/AVM2SourceGenerator.java | 9 +- .../jpexs/decompiler/flash/action/Action.java | 2 + .../action/fastactionlist/FastActionList.java | 2 +- .../flash/ActionScript3ExecuteTest.java | 3 - .../flash/gui/AdobeFlashExecutor.java | 1 - .../decompiler/flash/gui/FlashPlayerTest.java | 3 - 16 files changed, 114 insertions(+), 110 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index e4b2ce7de..b9baa6dce 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -312,7 +312,7 @@ public class AVM2Code implements Cloneable { public static int toSourceLimit = -1; - public List code = new ArrayList<>(); + public List code; public static boolean DEBUG_REWRITE = false; @@ -640,6 +640,15 @@ public class AVM2Code implements Cloneable { public static final String IDENTCLOSE = "/*IDENTCLOSE*/"; public AVM2Code() { + code = new ArrayList<>(); + } + + public AVM2Code(int capacity) { + code = new ArrayList<>(capacity); + } + + public AVM2Code(ArrayList instructions) { + code = instructions; } public Object execute(HashMap arguments, AVM2ConstantPool constants) throws AVM2ExecutionException { @@ -993,6 +1002,7 @@ public class AVM2Code implements Cloneable { diParent.sortChildren(); } + code = new ArrayList<>(codeMap.size()); AVM2Instruction prev = null; for (int i = 0; i < availableBytes; i++) { AVM2Instruction ins = codeMap.get((long) i); @@ -1035,7 +1045,7 @@ public class AVM2Code implements Cloneable { public void markOffsets() { long offset = 0; for (int i = 0; i < code.size(); i++) { - code.get(i).offset = offset; + code.get(i).setOffset(offset); offset += code.get(i).getBytesLength(); } } @@ -1230,7 +1240,7 @@ public class AVM2Code implements Cloneable { Helper.byteArrayToHexWithHeader(writer, getBytes()); } else if (exportMode == ScriptExportMode.PCODE || exportMode == ScriptExportMode.PCODE_HEX) { for (AVM2Instruction ins : code) { - long ofs = ins.offset; + long ofs = ins.getOffset(); if (exportMode == ScriptExportMode.PCODE_HEX) { writer.appendNoHilight("; "); writer.appendNoHilight(Helper.bytesToHexString(ins.getBytes())); @@ -1275,7 +1285,7 @@ public class AVM2Code implements Cloneable { if (body != null) { for (ABCException exception : body.exceptions) { ret.add((long) exception.start); - ret.add((long) exception.end); + // ret.add((long) exception.end); // end is not important ret.add((long) exception.target); } } @@ -1308,7 +1318,7 @@ public class AVM2Code implements Cloneable { while (max >= min) { int mid = (min + max) / 2; - long midValue = code.get(mid).offset; + long midValue = code.get(mid).getOffset(); if (midValue == address) { return mid; } else if (midValue < address) { @@ -1329,7 +1339,7 @@ public class AVM2Code implements Cloneable { if (pos == code.size()) { return getEndOffset(); } - return (int) code.get(pos).offset; + return (int) code.get(pos).getOffset(); } public long getEndOffset() { @@ -1338,7 +1348,7 @@ public class AVM2Code implements Cloneable { } AVM2Instruction ins = code.get(code.size() - 1); - return (int) (ins.offset + ins.getBytesLength()); + return (int) (ins.getOffset() + ins.getBytesLength()); } /** @@ -1954,11 +1964,11 @@ public class AVM2Code implements Cloneable { for (int i = 0; i < code.size(); i++) { AVM2Instruction ins = code.get(i); if (ins.definition instanceof LookupSwitchIns) { - long target = ins.offset + ins.operands[0]; - ins.operands[0] = updater.updateOperandOffset(ins.offset, target, ins.operands[0]); + long target = ins.getOffset() + ins.operands[0]; + ins.operands[0] = updater.updateOperandOffset(ins.getOffset(), target, ins.operands[0]); for (int k = 2; k < ins.operands.length; k++) { - target = ins.offset + ins.operands[k]; - ins.operands[k] = updater.updateOperandOffset(ins.offset, target, ins.operands[k]); + target = ins.getOffset() + ins.operands[k]; + ins.operands[k] = updater.updateOperandOffset(ins.getOffset(), target, ins.operands[k]); } } else { /*for (int j = 0; j < ins.definition.operands.length; j++) { @@ -1969,15 +1979,15 @@ public class AVM2Code implements Cloneable { }*/ //Faster, but not so universal if ((ins.definition instanceof JumpIns) || (ins.definition instanceof IfTypeIns)) { - long target = ins.offset + ins.getBytesLength() + ins.operands[0]; + long target = ins.getOffset() + ins.getBytesLength() + ins.operands[0]; try { - ins.operands[0] = updater.updateOperandOffset(ins.offset, target, ins.operands[0]); + ins.operands[0] = updater.updateOperandOffset(ins.getOffset(), target, ins.operands[0]); } catch (ConvertException cex) { throw new ConvertException("Invalid offset (" + ins + ")", i); } } } - ins.offset = updater.updateInstructionOffset(ins.offset); + ins.setOffset(updater.updateInstructionOffset(ins.getOffset())); } for (ABCException ex : body.exceptions) { @@ -2051,7 +2061,7 @@ public class AVM2Code implements Cloneable { } AVM2Instruction ins = code.get(pos); - final long remOffset = ins.offset; + final long remOffset = ins.getOffset(); int bc = ins.getBytesLength(); final int byteCount = bc; @@ -2116,7 +2126,7 @@ public class AVM2Code implements Cloneable { */ public void replaceInstruction(int pos, AVM2Instruction instruction, MethodBody body) { AVM2Instruction oldInstruction = code.get(pos); - instruction.offset = oldInstruction.offset; + instruction.setOffset(oldInstruction.getOffset()); int oldByteCount = oldInstruction.getBytesLength(); int newByteCount = instruction.getBytesLength(); int byteDelta = newByteCount - oldByteCount; @@ -2126,7 +2136,7 @@ public class AVM2Code implements Cloneable { @Override public long updateInstructionOffset(long address) { - if (address > instruction.offset) { + if (address > instruction.getOffset()) { return address + byteDelta; } return address; @@ -2134,10 +2144,10 @@ public class AVM2Code implements Cloneable { @Override public int updateOperandOffset(long insAddr, long targetAddress, int offset) { - if (targetAddress > instruction.offset && insAddr <= instruction.offset) { + if (targetAddress > instruction.getOffset() && insAddr <= instruction.getOffset()) { return offset + byteDelta; } - if (targetAddress <= instruction.offset && insAddr > instruction.offset) { + if (targetAddress <= instruction.getOffset() && insAddr > instruction.getOffset()) { return offset - byteDelta; } return offset; @@ -2168,11 +2178,11 @@ public class AVM2Code implements Cloneable { } final int byteCount = instruction.getBytesLength(); if (pos == code.size()) { - instruction.offset = code.get(pos - 1).offset + code.get(pos - 1).getBytesLength(); + instruction.setOffset(code.get(pos - 1).getOffset() + code.get(pos - 1).getBytesLength()); } else { - instruction.offset = code.get(pos).offset; + instruction.setOffset(code.get(pos).getOffset()); } - final long x = instruction.offset; + final long x = instruction.getOffset(); updateOffsets(new OffsetUpdater() { @Override @@ -2220,7 +2230,7 @@ public class AVM2Code implements Cloneable { return offset_jt; } }, body); - instruction.offset = x; + instruction.setOffset(x); code.add(pos, instruction); //checkValidOffsets(body); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorGetSet.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorGetSet.java index 03b8bfaba..186571c2d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorGetSet.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorGetSet.java @@ -149,7 +149,7 @@ public class AVM2DeobfuscatorGetSet extends SWFDecompilerAdapter { int regId = ((SetLocalTypeIns) def).getRegisterId(ins); if (!stack.isEmpty() && (stack.peek() instanceof LocalRegAVM2Item) && (((LocalRegAVM2Item) stack.peek()).regIndex == regId)) { stack.pop(); - code.replaceInstruction(idx, new AVM2Instruction(ins.offset, DeobfuscatePopIns.getInstance(), null), body); + code.replaceInstruction(idx, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), body); idx++; continue; } @@ -185,7 +185,7 @@ public class AVM2DeobfuscatorGetSet extends SWFDecompilerAdapter { boolean ifed = false; if (def instanceof JumpIns) { - long address = ins.offset + ins.getBytesLength() + ins.operands[0]; + long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0]; idx = code.adr2pos(address); if (idx == -1) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorJumps.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorJumps.java index c446e0a35..ffc18382b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorJumps.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorJumps.java @@ -50,7 +50,7 @@ public class AVM2DeobfuscatorJumps extends SWFDecompilerAdapter { for (int i = 0; i < code.code.size(); i++) { AVM2Instruction ins = code.code.get(i); if (ins.definition instanceof JumpIns) { - long targetAddr = ins.offset + ins.operands[0] + ins.getBytesLength(); + long targetAddr = ins.getOffset() + ins.operands[0] + ins.getBytesLength(); { for (int r : refs.get(i)) { if (r >= 0) { //Not Exception start/end @@ -58,7 +58,7 @@ public class AVM2DeobfuscatorJumps extends SWFDecompilerAdapter { if ((srcIns.definition instanceof JumpIns) || ((srcIns.definition instanceof IfTypeIns) && (r != i - 1))) { int oldop = srcIns.operands[0]; - srcIns.operands[0] = (int) (targetAddr - (srcIns.offset + srcIns.getBytesLength())); + srcIns.operands[0] = (int) (targetAddr - (srcIns.getOffset() + srcIns.getBytesLength())); if (srcIns.operands[0] != oldop) { found = true; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegisters.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegisters.java index a5a34ea26..15eb875ca 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegisters.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegisters.java @@ -167,7 +167,7 @@ public class AVM2DeobfuscatorRegisters extends AVM2DeobfuscatorSimple { SetLocalTypeIns slt = (SetLocalTypeIns) ins.definition; int regId = slt.getRegisterId(ins); if (singleRegisters.containsKey(regId)) { - code.replaceInstruction(i, new AVM2Instruction(ins.offset, DeobfuscatePopIns.getInstance(), null), body); + code.replaceInstruction(i, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), body); } } @@ -264,7 +264,7 @@ public class AVM2DeobfuscatorRegisters extends AVM2DeobfuscatorSimple { if (ins.definition instanceof JumpIns) { - long address = ins.offset + ins.getBytesLength() + ins.operands[0]; + long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0]; idx = code.adr2pos(address);//code.indexOf(code.getByAddress(address)); if (idx == -1) { throw new TranslateException("Jump target not found: " + address); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegistersOld.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegistersOld.java index 13cdd1bb1..7789dab9f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegistersOld.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegistersOld.java @@ -20,9 +20,7 @@ import com.jpexs.decompiler.flash.BaseLocalData; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.AVM2LocalData; import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; -import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; -import com.jpexs.decompiler.flash.abc.avm2.instructions.DeobfuscatePopIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; import com.jpexs.decompiler.flash.abc.avm2.instructions.debug.DebugIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.jumps.JumpIns; @@ -35,7 +33,6 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.other.ThrowIns; import com.jpexs.decompiler.flash.abc.avm2.model.NullAVM2Item; import com.jpexs.decompiler.flash.abc.avm2.parser.script.Reference; import com.jpexs.decompiler.flash.abc.types.MethodBody; -import com.jpexs.decompiler.flash.abc.types.MethodInfo; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.graph.Graph; import com.jpexs.decompiler.graph.GraphPart; @@ -48,7 +45,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; /** @@ -232,7 +228,7 @@ public class AVM2DeobfuscatorRegistersOld extends AVM2DeobfuscatorSimpleOld { if (ins.definition instanceof JumpIns) { - long address = ins.offset + ins.getBytesLength() + ins.operands[0]; + long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0]; idx = code.adr2pos(address);//code.indexOf(code.getByAddress(address)); if (idx == -1) { throw new TranslateException("Jump target not found: " + address); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimple.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimple.java index 6dd2b2808..8b72b57f6 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimple.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimple.java @@ -170,7 +170,7 @@ public class AVM2DeobfuscatorSimple extends SWFDecompilerAdapter { } AVM2Instruction ins = code.code.get(idx); - if (instructionsProcessed > 0 && refs.contains(ins.offset)) { + if (instructionsProcessed > 0 && refs.contains(ins.getOffset())) { break; } @@ -199,51 +199,13 @@ public class AVM2DeobfuscatorSimple extends SWFDecompilerAdapter { } } - if (def instanceof NewFunctionIns) { - if (idx + 1 < code.code.size()) { - if (code.code.get(idx + 1).definition instanceof PopIns) { - code.removeInstruction(idx + 1, body); - code.removeInstruction(idx, body); - modified = true; - continue; - } - } - } else { - // do not throw EmptyStackException, much faster - int requiredStackSize = def.getStackPopCount(ins, abc); - if (stack.size() < requiredStackSize) { - break; - } - - if (requiredStackSize > 0 && !def.isNotCompileTimeSupported()) { - boolean notCompileTime = false; - for (int i = 0; i < requiredStackSize; i++) { - if (stack.peek(i + 1) == NotCompileTime.INSTANCE) { - notCompileTime = true; - break; - } - } - - if (notCompileTime) { - break; - } - } - - if (localData.scopeStack.size() < -def.getScopeStackDelta(ins, abc)) { - break; - } - - boolean supported; - try { - localData.jump = null; - supported = def.execute(localData, abc.constants, ins); - } catch (AVM2ExecutionException ex) { - supported = false; - } - - if (!supported) { - break; - } + if (def instanceof NewFunctionIns + && idx + 1 < code.code.size() + && code.code.get(idx + 1).definition instanceof PopIns) { + code.removeInstruction(idx + 1, body); + code.removeInstruction(idx, body); + modified = true; + continue; } boolean ok = false; @@ -301,9 +263,47 @@ public class AVM2DeobfuscatorSimple extends SWFDecompilerAdapter { break; } + if (!(def instanceof NewFunctionIns)) { + // do not throw EmptyStackException, much faster + int requiredStackSize = def.getStackPopCount(ins, abc); + if (stack.size() < requiredStackSize) { + break; + } + + if (requiredStackSize > 0 && !def.isNotCompileTimeSupported()) { + boolean notCompileTime = false; + for (int i = 0; i < requiredStackSize; i++) { + if (stack.peek(i + 1) == NotCompileTime.INSTANCE) { + notCompileTime = true; + break; + } + } + + if (notCompileTime) { + break; + } + } + + if (localData.scopeStack.size() < -def.getScopeStackDelta(ins, abc)) { + break; + } + + boolean supported; + try { + localData.jump = null; + supported = def.execute(localData, abc.constants, ins); + } catch (AVM2ExecutionException ex) { + supported = false; + } + + if (!supported) { + break; + } + } + boolean ifed = false; if (def instanceof IfTypeIns && !(def instanceof JumpIns)) { - long address = ins.offset + ins.getBytesLength() + ins.operands[0]; + long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0]; int nidx = code.adr2pos(address); AVM2Instruction tarIns = code.code.get(nidx); @@ -315,17 +315,17 @@ public class AVM2DeobfuscatorSimple extends SWFDecompilerAdapter { AVM2Instruction jumpIns = new AVM2Instruction(0, AVM2Instructions.Jump, new int[]{0}); //jumpIns.operands[0] = ins.operands[0] /*- ins.getBytes().length*/ + jumpIns.getBytes().length; code.replaceInstruction(idx, jumpIns, body); - jumpIns.operands[0] = (int) (tarIns.offset - jumpIns.offset - jumpIns.getBytesLength()); + jumpIns.operands[0] = (int) (tarIns.getOffset() - jumpIns.getOffset() - jumpIns.getBytesLength()); for (int s = 0; s < stackCount; s++) { - code.insertInstruction(idx, new AVM2Instruction(ins.offset, DeobfuscatePopIns.getInstance(), null), true, body); + code.insertInstruction(idx, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), true, body); } - idx = code.adr2pos(jumpIns.offset + jumpIns.getBytesLength() + jumpIns.operands[0]); + idx = code.adr2pos(jumpIns.getOffset() + jumpIns.getBytesLength() + jumpIns.operands[0]); } else { //System.err.println("replacing " + ins + " on " + idx + " with pop"); - code.replaceInstruction(idx, new AVM2Instruction(ins.offset, DeobfuscatePopIns.getInstance(), null), body); + code.replaceInstruction(idx, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), body); for (int s = 1 /*first is replaced*/; s < stackCount; s++) { - code.insertInstruction(idx, new AVM2Instruction(ins.offset, DeobfuscatePopIns.getInstance(), null), true, body); + code.insertInstruction(idx, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), true, body); } //ins.definition = DeobfuscatePopIns.getInstance(); idx++; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimpleOld.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimpleOld.java index ada6efaa4..57db7f911 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimpleOld.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimpleOld.java @@ -342,7 +342,7 @@ public class AVM2DeobfuscatorSimpleOld extends SWFDecompilerAdapter { boolean ifed = false; if (def instanceof JumpIns) { - long address = ins.offset + ins.getBytesLength() + ins.operands[0]; + long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0]; idx = code.adr2pos(address); if (idx == -1) { @@ -355,7 +355,7 @@ public class AVM2DeobfuscatorSimpleOld extends SWFDecompilerAdapter { GraphTargetItem top = stack.pop(); Object res = top.getResult(); - long address = ins.offset + ins.getBytesLength() + ins.operands[0]; + long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0]; int nidx = code.adr2pos(address);//code.indexOf(code.getByAddress(address)); AVM2Instruction tarIns = code.code.get(nidx); @@ -367,17 +367,17 @@ public class AVM2DeobfuscatorSimpleOld extends SWFDecompilerAdapter { AVM2Instruction jumpIns = new AVM2Instruction(0, AVM2Instructions.Jump, new int[]{0}); //jumpIns.operands[0] = ins.operands[0] /*- ins.getBytes().length*/ + jumpIns.getBytes().length; code.replaceInstruction(idx, jumpIns, body); - jumpIns.operands[0] = (int) (tarIns.offset - jumpIns.offset - jumpIns.getBytesLength()); + jumpIns.operands[0] = (int) (tarIns.getOffset() - jumpIns.getOffset() - jumpIns.getBytesLength()); for (int s = 0; s < stackCount; s++) { - code.insertInstruction(idx, new AVM2Instruction(ins.offset, DeobfuscatePopIns.getInstance(), null), true, body); + code.insertInstruction(idx, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), true, body); } - idx = code.adr2pos(jumpIns.offset + jumpIns.getBytesLength() + jumpIns.operands[0]); + idx = code.adr2pos(jumpIns.getOffset() + jumpIns.getBytesLength() + jumpIns.operands[0]); } else { //System.err.println("replacing " + ins + " on " + idx + " with pop"); - code.replaceInstruction(idx, new AVM2Instruction(ins.offset, DeobfuscatePopIns.getInstance(), null), body); + code.replaceInstruction(idx, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), body); for (int s = 1 /*first is replaced*/; s < stackCount; s++) { - code.insertInstruction(idx, new AVM2Instruction(ins.offset, DeobfuscatePopIns.getInstance(), null), true, body); + code.insertInstruction(idx, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), true, body); } //ins.definition = DeobfuscatePopIns.getInstance(); idx++; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java index 1e97aff81..c85124686 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java @@ -47,7 +47,7 @@ public class AVM2Instruction implements Cloneable, GraphSourceItem { public int[] operands; - public long offset; + private long offset; public String comment; @@ -375,6 +375,10 @@ public class AVM2Instruction implements Cloneable, GraphSourceItem { return offset; } + public void setOffset(long offset) { + this.offset = offset; + } + @Override public List getBranches(GraphSource code) { List ret = new ArrayList<>(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/InstructionDefinition.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/InstructionDefinition.java index da8078e18..9a05c478c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/InstructionDefinition.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/InstructionDefinition.java @@ -238,7 +238,7 @@ public abstract class InstructionDefinition implements Serializable { if (constants.getMultiname(multinameIndex).needsName()) { name = stack.get(pos).toString(); } else { - name = GraphTextWriter.hilighOffset(constants.getMultiname(multinameIndex).getName(constants, fullyQualifiedNames, false), ins.offset); + name = GraphTextWriter.hilighOffset(constants.getMultiname(multinameIndex).getName(constants, fullyQualifiedNames, false), ins.getOffset()); } return name + ns; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/pcode/ASM3Parser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/pcode/ASM3Parser.java index 1f95351c5..12f53ed8f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/pcode/ASM3Parser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/pcode/ASM3Parser.java @@ -969,9 +969,9 @@ public class ASM3Parser { AVM2Instruction ins = code.code.get((int) oi.insPosition); int relOffset; if (oi instanceof CaseOffsetItem) { - relOffset = li.offset - (int) ins.offset; + relOffset = li.offset - (int) ins.getOffset(); } else { - relOffset = li.offset - ((int) ins.offset + ins.getBytesLength()); + relOffset = li.offset - ((int) ins.getOffset() + ins.getBytesLength()); } ins.operands[oi.insOperandIndex] = relOffset; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java index d5d2f8992..5b0109695 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/parser/script/AVM2SourceGenerator.java @@ -201,8 +201,8 @@ public class AVM2SourceGenerator implements SourceGenerator { return ret; } - public List toInsList(List items) { - List ret = new ArrayList<>(); + public ArrayList toInsList(List items) { + ArrayList ret = new ArrayList<>(); for (GraphSourceItem s : items) { if (s instanceof AVM2Instruction) { ret.add((AVM2Instruction) s); @@ -1675,9 +1675,8 @@ public class AVM2SourceGenerator implements SourceGenerator { mbody.method_info = abcIndex.getSelectedAbc().addMethodInfo(mi); mi.setBody(mbody); - List mbodyCode = toInsList(src); - mbody.setCode(new AVM2Code()); - mbody.getCode().code = mbodyCode; + ArrayList mbodyCode = toInsList(src); + mbody.setCode(new AVM2Code(mbodyCode)); if (needsActivation) { if (localData.traitUsages.containsKey(mbody)) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java index 4cb80f780..a6a7ecefe 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java @@ -122,6 +122,7 @@ public abstract class Action implements GraphSourceItem { */ public int actionLength; + // todo: honfika: rename to offset to be similar with AS3 private long address; @Override @@ -208,6 +209,7 @@ public abstract class Action implements GraphSourceItem { } public int getTotalActionLength() { + // honfika: todo rename to getBytesLength to match the name with the similar method in AS3 return actionLength + 1 + (actionCode >= 0x80 ? 2 : 0); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java index ab7eaee5a..c3012bfe1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java @@ -672,7 +672,7 @@ public class FastActionList implements Collection { if (o instanceof ActionItem) { item = (ActionItem) o; } else if (o instanceof Action) { - item = actionItemMap.get(o); + item = actionItemMap.get((Action) o); } if (item == null) { diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3ExecuteTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3ExecuteTest.java index 194b2317d..4f91508d2 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3ExecuteTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3ExecuteTest.java @@ -31,7 +31,6 @@ import com.jpexs.decompiler.flash.tags.Tag; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.IOException; -import java.util.ArrayList; import java.util.HashMap; import java.util.List; import static org.testng.Assert.assertEquals; @@ -90,7 +89,6 @@ public class ActionScript3ExecuteTest { runBody.max_stack = 10; AVM2Code ccode = new AVM2Code(); - ccode.code = new ArrayList<>(); List code = ccode.code; code.add(new AVM2Instruction(0, AVM2Instructions.GetLocal0, null)); code.add(new AVM2Instruction(0, AVM2Instructions.PushScope, null)); @@ -98,7 +96,6 @@ public class ActionScript3ExecuteTest { for (int testMethodId = 1; testMethodId < 10; testMethodId++) { AVM2Code ccode2 = new AVM2Code(); - ccode2.code = new ArrayList<>(); List code2 = ccode2.code; code2.add(new AVM2Instruction(0, AVM2Instructions.GetLocal0, null)); code2.add(new AVM2Instruction(0, AVM2Instructions.PushScope, null)); diff --git a/test/com/jpexs/decompiler/flash/gui/AdobeFlashExecutor.java b/test/com/jpexs/decompiler/flash/gui/AdobeFlashExecutor.java index ae47514c0..6f06b9387 100644 --- a/test/com/jpexs/decompiler/flash/gui/AdobeFlashExecutor.java +++ b/test/com/jpexs/decompiler/flash/gui/AdobeFlashExecutor.java @@ -301,7 +301,6 @@ public class AdobeFlashExecutor { int multinameId = abc.constants.getMultinameId(multiname, true); AVM2Code ccode = new AVM2Code(); - ccode.code = new ArrayList<>(); List code = ccode.code; code.add(new AVM2Instruction(0, AVM2Instructions.GetLocal0, null)); code.add(new AVM2Instruction(0, AVM2Instructions.PushScope, null)); diff --git a/test/com/jpexs/decompiler/flash/gui/FlashPlayerTest.java b/test/com/jpexs/decompiler/flash/gui/FlashPlayerTest.java index 16ed58c8a..7e4ccee91 100644 --- a/test/com/jpexs/decompiler/flash/gui/FlashPlayerTest.java +++ b/test/com/jpexs/decompiler/flash/gui/FlashPlayerTest.java @@ -84,7 +84,6 @@ import java.util.Random; import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertTrue; import static org.testng.Assert.fail; -import org.testng.annotations.Test; /** * @@ -109,7 +108,6 @@ public class FlashPlayerTest { List tasks = new ArrayList<>(); for (int p1 = 0; p1 < pushes.length; p1++) { AVM2Code ccode = new AVM2Code(); - ccode.code = new ArrayList<>(); List code = ccode.code; code.add(new AVM2Instruction(0, AVM2Instructions.GetLocal0, null)); code.add(new AVM2Instruction(0, AVM2Instructions.PushScope, null)); @@ -213,7 +211,6 @@ public class FlashPlayerTest { } AVM2Code ccode = new AVM2Code(); - ccode.code = new ArrayList<>(); List code = ccode.code; code.add(new AVM2Instruction(0, AVM2Instructions.GetLocal0, null)); code.add(new AVM2Instruction(0, AVM2Instructions.PushScope, null)); From 15c09a2d21f7c4f349bf666350d7fdfb6bf7df21 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Mon, 30 Nov 2015 09:22:31 +0100 Subject: [PATCH 4/8] test fix --- .../decompiler/flash/ActionScript3AssemblerTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3AssemblerTest.java b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3AssemblerTest.java index 8a13a1020..a50284fc3 100644 --- a/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3AssemblerTest.java +++ b/libsrc/ffdec_lib/test/com/jpexs/decompiler/flash/ActionScript3AssemblerTest.java @@ -164,12 +164,12 @@ public class ActionScript3AssemblerTest extends ActionScriptTestBase { for (int i = 0; i < code.code.size(); i++) { AVM2Instruction ins = code.code.get(i); int length = ins.getBytesLength(); - expected.put(ins.offset, i); - expectedNearest.put(ins.offset, i); - Assert.assertEquals(code.pos2adr(i), ins.offset); + expected.put(ins.getOffset(), i); + expectedNearest.put(ins.getOffset(), i); + Assert.assertEquals(code.pos2adr(i), ins.getOffset()); for (int j = 1; j < length; j++) { - expected.put(ins.offset + j, -1); - expectedNearest.put(ins.offset + j, i + 1); + expected.put(ins.getOffset() + j, -1); + expectedNearest.put(ins.getOffset() + j, i + 1); } } From d0f27866735c948f7402ca047db3e7eca6301f14 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Tue, 1 Dec 2015 09:28:01 +0100 Subject: [PATCH 5/8] removed unused imports --- .../decompiler/flash/gui/DebugPanel.java | 16 ++++++++++------ .../decompiler/flash/gui/DebuggerHandler.java | 19 ++++++++++--------- .../flash/gui/MainFrameClassic.java | 5 ----- .../flash/gui/MainFrameClassicMenu.java | 1 - .../decompiler/flash/gui/MainFrameRibbon.java | 5 ----- .../flash/gui/MainFrameRibbonMenu.java | 4 +--- .../decompiler/flash/gui/MenuBuilder.java | 5 ++++- .../decompiler/flash/gui/abc/ABCPanel.java | 9 ++------- .../flash/gui/debugger/Debugger.java | 4 +++- .../gui/editor/DebuggableEditorPane.java | 11 ++++++++++- .../gui/editor/LineMarkedEditorPane.java | 8 ++++++-- 11 files changed, 46 insertions(+), 41 deletions(-) diff --git a/src/com/jpexs/decompiler/flash/gui/DebugPanel.java b/src/com/jpexs/decompiler/flash/gui/DebugPanel.java index 20f4427cd..ac1866fd6 100644 --- a/src/com/jpexs/decompiler/flash/gui/DebugPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/DebugPanel.java @@ -19,12 +19,7 @@ package com.jpexs.decompiler.flash.gui; import com.jpexs.debugger.flash.Variable; import com.jpexs.debugger.flash.messages.in.InBreakAtExt; import com.jpexs.debugger.flash.messages.in.InFrame; -import com.jpexs.decompiler.flash.gui.AppStrings; -import com.jpexs.decompiler.flash.gui.DebuggerHandler; import com.jpexs.decompiler.flash.gui.DebuggerHandler.BreakListener; -import com.jpexs.decompiler.flash.gui.HeaderLabel; -import com.jpexs.decompiler.flash.gui.Main; -import com.jpexs.decompiler.flash.gui.View; import com.jpexs.decompiler.flash.gui.abc.ABCPanel; import java.awt.BorderLayout; import java.awt.Color; @@ -51,15 +46,25 @@ import javax.swing.table.DefaultTableModel; public class DebugPanel extends JPanel { private JTable debugRegistersTable; + private JTable debugLocalsTable; + private JTable debugScopeTable; + private JTable callStackTable; + private JTable stackTable; + private JTabbedPane varTabs; + private BreakListener listener; + private JTextArea traceLogTextarea; + private int logLength = 0; + private List tabTypes = new ArrayList<>(); + private boolean loading = false; public static enum SelectedTab { @@ -314,5 +319,4 @@ public class DebugPanel extends JPanel { public void dispose() { Main.getDebugHandler().removeBreakListener(listener); } - } diff --git a/src/com/jpexs/decompiler/flash/gui/DebuggerHandler.java b/src/com/jpexs/decompiler/flash/gui/DebuggerHandler.java index afea91060..77239fb96 100644 --- a/src/com/jpexs/decompiler/flash/gui/DebuggerHandler.java +++ b/src/com/jpexs/decompiler/flash/gui/DebuggerHandler.java @@ -21,8 +21,6 @@ import com.jpexs.debugger.flash.DebugMessageListener; import com.jpexs.debugger.flash.Debugger; import com.jpexs.debugger.flash.DebuggerCommands; import com.jpexs.debugger.flash.DebuggerConnection; -import com.jpexs.debugger.flash.SWD; -import com.jpexs.debugger.flash.Variable; import com.jpexs.debugger.flash.messages.in.InAskBreakpoints; import com.jpexs.debugger.flash.messages.in.InBreakAt; import com.jpexs.debugger.flash.messages.in.InBreakAtExt; @@ -42,15 +40,11 @@ import com.jpexs.debugger.flash.messages.out.OutGetBreakReason; import com.jpexs.debugger.flash.messages.out.OutGetSwd; import com.jpexs.debugger.flash.messages.out.OutGetSwf; import com.jpexs.debugger.flash.messages.out.OutProcessedTag; -import com.jpexs.decompiler.flash.abc.ClassPath; -import com.jpexs.decompiler.flash.abc.ScriptPack; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.graph.DottedChain; -import com.jpexs.helpers.CancellableWorker; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -68,18 +62,27 @@ import java.util.regex.Pattern; public class DebuggerHandler implements DebugConnectionListener { private boolean connected = false; + private DebuggerCommands commands = null; + private List swfs = new ArrayList<>(); + private boolean paused = true; + private Map modulePaths = new HashMap<>(); + private Map classToModule = new HashMap<>(); private Map> toAddBPointMap = new HashMap<>(); + private Map> confirmedPointMap = new HashMap<>(); + private Map> invalidBreakPointMap = new HashMap<>(); + private Map> toRemoveBPointMap = new HashMap<>(); private int breakIp = -1; + private String breakScriptName = null; public int getBreakIp() { @@ -221,6 +224,7 @@ public class DebuggerHandler implements DebugConnectionListener { private InFrame frame; private InBreakAtExt breakInfo; + private InBreakReason breakReason; private final List breakListeners = new ArrayList<>(); @@ -255,13 +259,11 @@ public class DebuggerHandler implements DebugConnectionListener { public void connected(); public void disconnected(); - } public static interface TraceListener { public void trace(String... val); - } public static interface BreakListener { @@ -269,7 +271,6 @@ public class DebuggerHandler implements DebugConnectionListener { public void breakAt(String scriptName, int line); public void doContinue(); - } public void addBreakListener(BreakListener l) { diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameClassic.java b/src/com/jpexs/decompiler/flash/gui/MainFrameClassic.java index f0a06af67..e68477e16 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameClassic.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameClassic.java @@ -16,7 +16,6 @@ */ package com.jpexs.decompiler.flash.gui; -import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.gui.player.FlashPlayerPanel; import com.jpexs.helpers.Helper; @@ -29,9 +28,6 @@ import java.awt.event.ComponentEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.event.WindowStateListener; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.JFrame; /** @@ -141,5 +137,4 @@ public final class MainFrameClassic extends AppFrame implements MainFrame { public MainFrameMenu getMenu() { return mainMenu; } - } diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java index 6c41bfd53..be4c9b92d 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameClassicMenu.java @@ -373,5 +373,4 @@ public class MainFrameClassicMenu extends MainFrameMenu { ((JComponent) me).setVisible(val); } } - } diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java index 3a5081837..cc5a2986d 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbon.java @@ -16,7 +16,6 @@ */ package com.jpexs.decompiler.flash.gui; -import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.gui.player.FlashPlayerPanel; import com.jpexs.decompiler.flash.treeitems.SWFList; @@ -33,10 +32,7 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.awt.event.WindowStateListener; import java.io.File; -import java.io.IOException; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.swing.JFrame; import org.pushingpixels.flamingo.api.ribbon.JRibbon; import org.pushingpixels.flamingo.internal.ui.ribbon.appmenu.JRibbonApplicationMenuButton; @@ -199,5 +195,4 @@ public final class MainFrameRibbon extends AppRibbonFrame { public MainFrameMenu getMenu() { return mainMenu; } - } diff --git a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java index cd6c33b07..86fdef902 100644 --- a/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java +++ b/src/com/jpexs/decompiler/flash/gui/MainFrameRibbonMenu.java @@ -37,7 +37,6 @@ import org.pushingpixels.flamingo.api.common.CommandToggleButtonGroup; import org.pushingpixels.flamingo.api.common.JCommandButton; import org.pushingpixels.flamingo.api.common.JCommandButtonPanel; import org.pushingpixels.flamingo.api.common.JCommandToggleButton; -import org.pushingpixels.flamingo.api.common.RichTooltip; import org.pushingpixels.flamingo.api.common.popup.JPopupPanel; import org.pushingpixels.flamingo.api.common.popup.PopupPanelCallback; import org.pushingpixels.flamingo.api.ribbon.AbstractRibbonBand; @@ -291,7 +290,7 @@ public class MainFrameRibbonMenu extends MainFrameMenu { cbut = new JCommandButton(fixCommandTitle(subTitle)); } if (subKey != null) { - //cbut.setActionRichTooltip(new RichTooltip(subTitle, subKey.toString())); + //cbut.setActionRichTooltip(new RichTooltip(subTitle, subKey.toString())); } if (subLoader != null) { cbut.setCommandButtonKind(JCommandButton.CommandButtonKind.ACTION_AND_POPUP_MAIN_ACTION); @@ -639,5 +638,4 @@ public class MainFrameRibbonMenu extends MainFrameMenu { } } - } diff --git a/src/com/jpexs/decompiler/flash/gui/MenuBuilder.java b/src/com/jpexs/decompiler/flash/gui/MenuBuilder.java index 12c4a4c91..764acf620 100644 --- a/src/com/jpexs/decompiler/flash/gui/MenuBuilder.java +++ b/src/com/jpexs/decompiler/flash/gui/MenuBuilder.java @@ -32,6 +32,7 @@ public interface MenuBuilder { public static class HotKey { private static Map keyCodesToNames = new HashMap<>(); + private static Map keyNamesToCodes = new HashMap<>(); { @@ -57,8 +58,11 @@ public interface MenuBuilder { } public int key; + public boolean shiftDown; + public boolean ctrlDown; + public boolean altDown; @Override @@ -163,7 +167,6 @@ public interface MenuBuilder { return s; } - } public static final int PRIORITY_LOW = 1; diff --git a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java index 642500109..40cc70650 100644 --- a/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java +++ b/src/com/jpexs/decompiler/flash/gui/abc/ABCPanel.java @@ -16,11 +16,7 @@ */ package com.jpexs.decompiler.flash.gui.abc; -import com.jpexs.decompiler.flash.gui.DebugPanel; import com.jpexs.debugger.flash.Variable; -import com.jpexs.debugger.flash.messages.in.InBreakAtExt; -import com.jpexs.debugger.flash.messages.in.InBreakReason; -import com.jpexs.debugger.flash.messages.in.InFrame; import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.ClassPath; @@ -45,6 +41,7 @@ import com.jpexs.decompiler.flash.abc.usages.TraitMultinameUsage; import com.jpexs.decompiler.flash.configuration.Configuration; import com.jpexs.decompiler.flash.gui.AppDialog; import com.jpexs.decompiler.flash.gui.AppStrings; +import com.jpexs.decompiler.flash.gui.DebugPanel; import com.jpexs.decompiler.flash.gui.DebuggerHandler; import com.jpexs.decompiler.flash.gui.HeaderLabel; import com.jpexs.decompiler.flash.gui.Main; @@ -87,7 +84,6 @@ import java.awt.event.MouseMotionListener; import java.io.File; import java.util.ArrayList; import java.util.List; -import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; @@ -105,7 +101,6 @@ import javax.swing.JTable; import javax.swing.JToggleButton; import javax.swing.SwingConstants; import javax.swing.border.BevelBorder; -import javax.swing.event.TableModelEvent; import javax.swing.event.TableModelListener; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableModel; @@ -272,6 +267,7 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener tableListeners = new ArrayList<>(); + private List vars; public VariablesTableModel(List vars) { @@ -348,7 +344,6 @@ public class ABCPanel extends JPanel implements ItemListener, SearchListener parameters = new HashMap<>(); public static final int MSG_STRING = 0; + public static final int MSG_LOADER_URL = 1; + public static final int MSG_LOADER_BYTES = 2; public String getParameter(String name, String defValue) { diff --git a/src/com/jpexs/decompiler/flash/gui/editor/DebuggableEditorPane.java b/src/com/jpexs/decompiler/flash/gui/editor/DebuggableEditorPane.java index 15cdecf5e..71964246a 100644 --- a/src/com/jpexs/decompiler/flash/gui/editor/DebuggableEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/editor/DebuggableEditorPane.java @@ -35,25 +35,35 @@ import jsyntaxpane.components.LineNumbersBreakpointsRuler; public class DebuggableEditorPane extends LineMarkedEditorPane implements BreakPointListener, LineMarkerPainter { private static final Color BG_CURRENT_COLOR = new Color(0xd6, 0xe8, 0xe2); + private static final Color BG_RULER_COLOR = new Color(0xe9, 0xe8, 0xe2); private static final Color BG_BREAKPOINT_COLOR = new Color(0xfc, 0x9d, 0x9f); + private static final Color FG_BREAKPOINT_COLOR = null; + private static final int PRIORITY_BREAKPOINT = 20; private static final Color BG_IP_COLOR = new Color(0xbd, 0xe6, 0xaa); + private static final Color FG_IP_COLOR = null; + private static final int PRIORITY_IP = 0; private static final Color BG_INVALID_BREAKPOINT_COLOR = new Color(0xdc, 0xdc, 0xd8); + private static final Color FG_INVALID_BREAKPOINT_COLOR = null; + private static final int PRIORITY_INVALID_BREAKPOINT = 10; public static final LineMarker BREAKPOINT_MARKER = new LineMarker(FG_BREAKPOINT_COLOR, BG_BREAKPOINT_COLOR, PRIORITY_BREAKPOINT); + public static final LineMarker IP_MARKER = new LineMarker(FG_IP_COLOR, BG_IP_COLOR, PRIORITY_IP); + public static final LineMarker INVALID_BREAKPOINT_MARKER = new LineMarker(FG_INVALID_BREAKPOINT_COLOR, BG_INVALID_BREAKPOINT_COLOR, PRIORITY_INVALID_BREAKPOINT); protected String scriptName = null; + private LineNumbersBreakpointsRuler ruler; public synchronized void setScriptName(String scriptName) { @@ -180,5 +190,4 @@ public class DebuggableEditorPane extends LineMarkedEditorPane implements BreakP super.removeColorMarker(line, lm); ruler.repaint(); } - } diff --git a/src/com/jpexs/decompiler/flash/gui/editor/LineMarkedEditorPane.java b/src/com/jpexs/decompiler/flash/gui/editor/LineMarkedEditorPane.java index 062e1dbd5..c5b2d51e3 100644 --- a/src/com/jpexs/decompiler/flash/gui/editor/LineMarkedEditorPane.java +++ b/src/com/jpexs/decompiler/flash/gui/editor/LineMarkedEditorPane.java @@ -65,6 +65,7 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan private static final int truncateLimit = 2 * 1024 * 1024; public static final Color BG_SELECTED_LINE = new Color(0xe9, 0xef, 0xf8); + public static final Color BG_ERROR_LINE = new Color(255, 200, 200); private int lastLine = -1; @@ -80,8 +81,11 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan public static class LineMarker implements Comparable { private Color bgColor; + private Color color; + private FgPainter fgPainter; + //private int line; private int priority; @@ -140,6 +144,7 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan } } //(Map>) + private Map> lineMarkers = Collections.synchronizedMap(new HashMap>()); public void setLineMarkers(Map> colorMarkers) { @@ -415,7 +420,7 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan t = t.substring(0, truncateLimit) + "\r\n" + AppStrings.translate("editorTruncateWarning").replace("%chars%", Integer.toString(truncateLimit)); } super.setText(t); - setCaretPosition(0); //scroll to top + setCaretPosition(0); //scroll to top } public static class FgPainter extends DefaultHighlighter.DefaultHighlightPainter { @@ -613,5 +618,4 @@ public class LineMarkedEditorPane extends UndoFixedEditorPane implements LinkHan } } } - } From 35b917eca12b6869b1a79f45a34ac82c545c5854 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Wed, 2 Dec 2015 14:19:09 +0100 Subject: [PATCH 6/8] using a function which calculates the target address of the IfType instructions --- .../decompiler/flash/abc/avm2/AVM2Code.java | 16 ++++++++-------- .../deobfuscation/AVM2DeobfuscatorGetSet.java | 2 +- .../deobfuscation/AVM2DeobfuscatorJumps.java | 2 +- .../deobfuscation/AVM2DeobfuscatorRegisters.java | 2 +- .../AVM2DeobfuscatorRegistersOld.java | 2 +- .../deobfuscation/AVM2DeobfuscatorSimple.java | 4 ++-- .../deobfuscation/AVM2DeobfuscatorSimpleOld.java | 6 +++--- .../abc/avm2/instructions/AVM2Instruction.java | 6 +++++- .../decompiler/flash/action/swf4/ActionIf.java | 5 +++-- .../decompiler/flash/action/swf4/ActionJump.java | 7 ++++--- 10 files changed, 29 insertions(+), 23 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index b9baa6dce..2b816e015 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -733,14 +733,14 @@ public class AVM2Code implements Cloneable { } if (ins.definition instanceof JumpIns) { try { - pos = adr2pos(pos2adr(pos) + ins.getBytesLength() + ins.operands[0]); + pos = adr2pos(ins.getTargetAddress()); continue; } catch (ConvertException ex) { return false; } } else if (ins.definition instanceof IfTypeIns) { try { - int newpos = adr2pos(pos2adr(pos) + ins.getBytesLength() + ins.operands[0]); + int newpos = adr2pos(ins.getTargetAddress()); calculateDebugFileLine(debugFile, debugLine, newpos, abc, seen); } catch (ConvertException ex) { return false; @@ -1978,8 +1978,8 @@ public class AVM2Code implements Cloneable { } }*/ //Faster, but not so universal - if ((ins.definition instanceof JumpIns) || (ins.definition instanceof IfTypeIns)) { - long target = ins.getOffset() + ins.getBytesLength() + ins.operands[0]; + if (ins.definition instanceof IfTypeIns) { + long target = ins.getTargetAddress(); try { ins.operands[0] = updater.updateOperandOffset(ins.getOffset(), target, ins.operands[0]); } catch (ConvertException cex) { @@ -2322,14 +2322,14 @@ public class AVM2Code implements Cloneable { } if (ins.definition instanceof JumpIns) { try { - pos = adr2pos(pos2adr(pos) + ins.getBytesLength() + ins.operands[0]); + pos = adr2pos(ins.getTargetAddress()); continue; } catch (ConvertException ex) { return false; } } else if (ins.definition instanceof IfTypeIns) { try { - int newpos = adr2pos(pos2adr(pos) + ins.getBytesLength() + ins.operands[0]); + int newpos = adr2pos(ins.getTargetAddress()); walkCode(stats, newpos, stack, scope, abc); } catch (ConvertException ex) { return false; @@ -2459,14 +2459,14 @@ public class AVM2Code implements Cloneable { } if (ins.definition instanceof JumpIns) { try { - ip = adr2pos(pos2adr(ip) + ins.getBytesLength() + ins.operands[0]); + ip = adr2pos(ins.getTargetAddress()); continue; } catch (ConvertException ex) { logger.log(Level.FINE, null, ex); } } else if (ins.definition instanceof IfTypeIns) { try { - toVisit.add(adr2pos(pos2adr(ip) + ins.getBytesLength() + ins.operands[0])); + toVisit.add(adr2pos(ins.getTargetAddress())); toVisitLast.add(ip); } catch (ConvertException ex) { logger.log(Level.FINE, null, ex); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorGetSet.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorGetSet.java index 186571c2d..77570d080 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorGetSet.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorGetSet.java @@ -185,7 +185,7 @@ public class AVM2DeobfuscatorGetSet extends SWFDecompilerAdapter { boolean ifed = false; if (def instanceof JumpIns) { - long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0]; + long address = ins.getTargetAddress(); idx = code.adr2pos(address); if (idx == -1) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorJumps.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorJumps.java index ffc18382b..5cce43766 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorJumps.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorJumps.java @@ -50,7 +50,7 @@ public class AVM2DeobfuscatorJumps extends SWFDecompilerAdapter { for (int i = 0; i < code.code.size(); i++) { AVM2Instruction ins = code.code.get(i); if (ins.definition instanceof JumpIns) { - long targetAddr = ins.getOffset() + ins.operands[0] + ins.getBytesLength(); + long targetAddr = ins.getTargetAddress(); { for (int r : refs.get(i)) { if (r >= 0) { //Not Exception start/end diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegisters.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegisters.java index 15eb875ca..c46c6170d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegisters.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegisters.java @@ -264,7 +264,7 @@ public class AVM2DeobfuscatorRegisters extends AVM2DeobfuscatorSimple { if (ins.definition instanceof JumpIns) { - long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0]; + long address = ins.getTargetAddress(); idx = code.adr2pos(address);//code.indexOf(code.getByAddress(address)); if (idx == -1) { throw new TranslateException("Jump target not found: " + address); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegistersOld.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegistersOld.java index 7789dab9f..ed8747779 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegistersOld.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegistersOld.java @@ -228,7 +228,7 @@ public class AVM2DeobfuscatorRegistersOld extends AVM2DeobfuscatorSimpleOld { if (ins.definition instanceof JumpIns) { - long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0]; + long address = ins.getTargetAddress(); idx = code.adr2pos(address);//code.indexOf(code.getByAddress(address)); if (idx == -1) { throw new TranslateException("Jump target not found: " + address); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimple.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimple.java index 8b72b57f6..a94a84efd 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimple.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimple.java @@ -303,7 +303,7 @@ public class AVM2DeobfuscatorSimple extends SWFDecompilerAdapter { boolean ifed = false; if (def instanceof IfTypeIns && !(def instanceof JumpIns)) { - long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0]; + long address = ins.getTargetAddress(); int nidx = code.adr2pos(address); AVM2Instruction tarIns = code.code.get(nidx); @@ -320,7 +320,7 @@ public class AVM2DeobfuscatorSimple extends SWFDecompilerAdapter { code.insertInstruction(idx, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), true, body); } - idx = code.adr2pos(jumpIns.getOffset() + jumpIns.getBytesLength() + jumpIns.operands[0]); + idx = code.adr2pos(jumpIns.getTargetAddress()); } else { //System.err.println("replacing " + ins + " on " + idx + " with pop"); code.replaceInstruction(idx, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), body); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimpleOld.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimpleOld.java index 57db7f911..92ddf22cd 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimpleOld.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorSimpleOld.java @@ -342,7 +342,7 @@ public class AVM2DeobfuscatorSimpleOld extends SWFDecompilerAdapter { boolean ifed = false; if (def instanceof JumpIns) { - long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0]; + long address = ins.getTargetAddress(); idx = code.adr2pos(address); if (idx == -1) { @@ -355,7 +355,7 @@ public class AVM2DeobfuscatorSimpleOld extends SWFDecompilerAdapter { GraphTargetItem top = stack.pop(); Object res = top.getResult(); - long address = ins.getOffset() + ins.getBytesLength() + ins.operands[0]; + long address = ins.getTargetAddress(); int nidx = code.adr2pos(address);//code.indexOf(code.getByAddress(address)); AVM2Instruction tarIns = code.code.get(nidx); @@ -372,7 +372,7 @@ public class AVM2DeobfuscatorSimpleOld extends SWFDecompilerAdapter { code.insertInstruction(idx, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), true, body); } - idx = code.adr2pos(jumpIns.getOffset() + jumpIns.getBytesLength() + jumpIns.operands[0]); + idx = code.adr2pos(jumpIns.getTargetAddress()); } else { //System.err.println("replacing " + ins + " on " + idx + " with pop"); code.replaceInstruction(idx, new AVM2Instruction(ins.getOffset(), DeobfuscatePopIns.getInstance(), null), body); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java index c85124686..7f2177a88 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java @@ -379,12 +379,16 @@ public class AVM2Instruction implements Cloneable, GraphSourceItem { this.offset = offset; } + public long getTargetAddress() { + return offset + 4 /*getBytesLength()*/ + operands[0]; + } + @Override public List getBranches(GraphSource code) { List ret = new ArrayList<>(); if (definition instanceof IfTypeIns) { - ret.add(code.adr2pos(offset + getBytesLength() + operands[0])); + ret.add(code.adr2pos(getTargetAddress())); if (!(definition instanceof JumpIns)) { ret.add(code.adr2pos(offset + getBytesLength())); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionIf.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionIf.java index 4039f867b..7ee3b9fdb 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionIf.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionIf.java @@ -126,10 +126,11 @@ public class ActionIf extends Action { public List getBranches(GraphSource code) { List ret = super.getBranches(code); int length = getTotalActionLength(); - int jmp = code.adr2pos(getAddress() + length + offset); + long targetAddress = getTargetAddress(); + int jmp = code.adr2pos(targetAddress); int after = code.adr2pos(getAddress() + length); if (jmp == -1) { - Logger.getLogger(ActionIf.class.getName()).log(Level.SEVERE, "Invalid IF jump to ofs" + Helper.formatAddress(getAddress() + length + offset)); + Logger.getLogger(ActionIf.class.getName()).log(Level.SEVERE, "Invalid IF jump to ofs" + Helper.formatAddress(targetAddress)); ret.add(after); } else { ret.add(jmp); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionJump.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionJump.java index 6079808f6..216b2903b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionJump.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/swf4/ActionJump.java @@ -117,11 +117,12 @@ public class ActionJump extends Action { @Override public List getBranches(GraphSource code) { List ret = super.getBranches(code); - int length = getBytesLength(); - int ofs = code.adr2pos(getAddress() + length + offset); + long targetAddress = getTargetAddress(); + int ofs = code.adr2pos(targetAddress); if (ofs == -1) { + int length = getBytesLength(); ofs = code.adr2pos(getAddress() + length); - Logger.getLogger(ActionJump.class.getName()).log(Level.SEVERE, "Invalid jump to ofs" + Helper.formatAddress(getAddress() + length + offset) + " from ofs" + Helper.formatAddress(getAddress())); + Logger.getLogger(ActionJump.class.getName()).log(Level.SEVERE, "Invalid jump to ofs" + Helper.formatAddress(targetAddress) + " from ofs" + Helper.formatAddress(getAddress())); } ret.add(ofs); return ret; From 507cc4c29b3924e0f20f18641aefc6db8f2628ef Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Thu, 3 Dec 2015 09:40:26 +0100 Subject: [PATCH 7/8] #1070 Incorrect decompilation of switch statement fixed --- .../jpexs/decompiler/flash/abc/avm2/AVM2Code.java | 10 ++++++++++ .../deobfuscation/AVM2DeobfuscatorRegistersOld.java | 1 - .../abc/avm2/instructions/AVM2Instruction.java | 4 ++++ .../src/com/jpexs/decompiler/graph/Graph.java | 13 +++++++++---- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java index 2b816e015..01416c5df 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2Code.java @@ -1297,6 +1297,16 @@ public class AVM2Code implements Cloneable { return ret; } + public AVM2Instruction adr2ins(long address) throws ConvertException { + int pos = adr2pos(address, false); + if (pos == code.size()) { + // end + return null; + } + + return code.get(pos); + } + public int adr2pos(long address) throws ConvertException { return adr2pos(address, false); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegistersOld.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegistersOld.java index ed8747779..173b93b09 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegistersOld.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/deobfuscation/AVM2DeobfuscatorRegistersOld.java @@ -146,7 +146,6 @@ public class AVM2DeobfuscatorRegistersOld extends AVM2DeobfuscatorSimpleOld { originalBody.exceptions = body.exceptions; originalBody.setCode(body.getCode()); - } private int getFirstRegisterSetter(Reference assignment, int classIndex, boolean isStatic, int scriptIndex, ABC abc, MethodBody body, Set ignoredRegisters, Set ignoredGets) throws InterruptedException { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java index 7f2177a88..667714a6a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/instructions/AVM2Instruction.java @@ -383,6 +383,10 @@ public class AVM2Instruction implements Cloneable, GraphSourceItem { return offset + 4 /*getBytesLength()*/ + operands[0]; } + public void setTargetOffset(int offset) { + operands[0] = offset; + } + @Override public List getBranches(GraphSource code) { List ret = new ArrayList<>(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java index 1a9e633eb..2250d8e53 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/graph/Graph.java @@ -1793,22 +1793,27 @@ public class Graph { hasExpr = true; } } - } + first = true; pos = 0; //This is tied to AS3 switch implementation which has nextparts switched from index 1. TODO: Make more universal GraphPart defaultPart = hasExpr ? part.nextParts.get(1 + defaultBranch) : part.nextParts.get(0); - for (GraphPart p : part.nextParts) { - if (p != defaultPart) { + for (int i = 1; i < part.nextParts.size(); i++) { + if (hasExpr && i == 1 + defaultBranch) { + continue; + } + + if (part.nextParts.get(i) != defaultPart) { if (caseExpressions.containsKey(pos)) { caseValues.add(caseExpressions.get(pos)); } else { caseValues.add(new IntegerValueItem(null, localData.lineStartInstruction, pos)); } - pos++; } + + pos++; } first = true; From 2f75a7b4ed08da8db1021be6a3e1ef122b41b67d Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Thu, 3 Dec 2015 11:07:07 +0100 Subject: [PATCH 8/8] #1098 Importing SWF XML fails fixed --- .../decompiler/flash/abc/avm2/AVM2ConstantPool.java | 9 +++++++++ .../jpexs/decompiler/flash/importers/SwfXmlImporter.java | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2ConstantPool.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2ConstantPool.java index 0600d21c1..d377887f5 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2ConstantPool.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2ConstantPool.java @@ -25,6 +25,7 @@ import com.jpexs.decompiler.flash.abc.types.NamespaceSet; import com.jpexs.decompiler.flash.ecma.Null; import com.jpexs.decompiler.flash.ecma.Undefined; import com.jpexs.decompiler.flash.types.annotations.Internal; +import com.jpexs.decompiler.flash.types.annotations.SWFField; import com.jpexs.decompiler.graph.DottedChain; import com.jpexs.helpers.HashArrayList; import com.jpexs.helpers.utf8.Utf8PrintWriter; @@ -39,21 +40,29 @@ public class AVM2ConstantPool implements Cloneable { private static final Logger logger = Logger.getLogger(AVM2ConstantPool.class.getName()); + @SWFField private HashArrayList constant_int = new HashArrayList<>(); + @SWFField private HashArrayList constant_uint = new HashArrayList<>(); + @SWFField private HashArrayList constant_double = new HashArrayList<>(); /* Only for some minor versions */ + @SWFField private HashArrayList constant_decimal = new HashArrayList<>(); + @SWFField private HashArrayList constant_string = new HashArrayList<>(); + @SWFField private HashArrayList constant_namespace = new HashArrayList<>(); + @SWFField private HashArrayList constant_namespace_set = new HashArrayList<>(); + @SWFField private HashArrayList constant_multiname = new HashArrayList<>(); public AVM2ConstantPool() { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SwfXmlImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SwfXmlImporter.java index 7cc28ea68..ef0a0f561 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SwfXmlImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SwfXmlImporter.java @@ -96,6 +96,7 @@ import com.jpexs.decompiler.flash.types.shaperecords.EndShapeRecord; import com.jpexs.decompiler.flash.types.shaperecords.StraightEdgeRecord; import com.jpexs.decompiler.flash.types.shaperecords.StyleChangeRecord; import com.jpexs.helpers.ByteArrayRange; +import com.jpexs.helpers.HashArrayList; import com.jpexs.helpers.ReflectionTools; import java.io.IOException; import java.io.StringReader; @@ -205,7 +206,7 @@ public class SwfXmlImporter { Field field = getField(cls, name); Class childCls = field.getType(); if (List.class.isAssignableFrom(childCls)) { - List list = new ArrayList(); + List list = HashArrayList.class.isAssignableFrom(childCls) ? new HashArrayList() : new ArrayList(); for (int j = 0; j < child.getChildNodes().getLength(); j++) { Node childChildNode = child.getChildNodes().item(j); if (childChildNode instanceof Element) {