From 0cf0df67ea399466bc65dade2e113f7a7bf2ffdf Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Mon, 30 Nov 2015 09:16:51 +0100 Subject: [PATCH] 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));