From 18c295010abfe2864b0d86ee9fae52938ab58ef8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=C5=99=C3=ADk?= Date: Sun, 21 Jun 2015 07:31:36 +0200 Subject: [PATCH] AS3: insert instruction fix for try --- .../decompiler/flash/abc/avm2/AVM2Code.java | 20 +++++++++++++++---- .../abc/avm2/AVM2DeobfuscatorSimple.java | 4 ++-- 2 files changed, 18 insertions(+), 6 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 81324e6c7..ec330c9cc 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 @@ -1847,16 +1847,16 @@ public class AVM2Code implements Cloneable { * @param pos * @param instruction */ - public void insertInstruction(int pos, AVM2Instruction instruction) { - insertInstruction(pos, instruction, true, false); + public void insertInstruction(int pos, AVM2Instruction instruction, MethodBody body) { + insertInstruction(pos, instruction, true, false, body); } public void replaceInstruction(int idx, AVM2Instruction ins, MethodBody body) { - insertInstruction(idx, ins, true, true); + insertInstruction(idx, ins, true, true, body); removeInstruction(idx + 1, body); } - public void insertInstruction(int pos, AVM2Instruction instruction, boolean preRefsToThis, boolean postRefsToThis) { + public void insertInstruction(int pos, AVM2Instruction instruction, boolean preRefsToThis, boolean postRefsToThis, MethodBody body) { if (pos < 0) { pos = 0; } @@ -1870,6 +1870,18 @@ public class AVM2Code implements Cloneable { instruction.offset = code.get(pos).offset; } + for (ABCException ex : body.exceptions) { + if (ex.start > instruction.offset) { + ex.start += byteCount; + } + if (ex.end > instruction.offset) { + ex.end += byteCount; + } + if (ex.target > instruction.offset) { + ex.target += byteCount; + } + } + { for (int i = 0; i < pos; i++) { if (code.get(i).definition instanceof LookupSwitchIns) { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2DeobfuscatorSimple.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2DeobfuscatorSimple.java index bfeabfa67..9927570c4 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2DeobfuscatorSimple.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/AVM2DeobfuscatorSimple.java @@ -178,7 +178,7 @@ public class AVM2DeobfuscatorSimple implements SWFDecompilerListener { } AVM2Instruction ins = makePush(graphTargetItem.getResult(), cpool); if (ins != null) { - code.insertInstruction(i + (idelta++), ins); + code.insertInstruction(i + (idelta++), ins, body); //prevAction = ins; } else { throw new TranslateException("Cannot push: " + graphTargetItem); @@ -188,7 +188,7 @@ public class AVM2DeobfuscatorSimple implements SWFDecompilerListener { } AVM2Instruction jump = new AVM2Instruction(0, new JumpIns(), new int[]{0}); - code.insertInstruction(i + (idelta++), jump); + code.insertInstruction(i + (idelta++), jump, body); jump.operands[0] = ((int) (target.offset - jump.offset - jump.getBytes().length));