From f354443455acf04cec6204257d98de418b6d2ea0 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Mon, 24 Aug 2015 21:06:08 +0200 Subject: [PATCH] small fixes, impovemnets --- .../decompiler/flash/abc/avm2/AVM2Code.java | 12 ++++++------ .../decompiler/flash/abc/avm2/CodeStats.java | 2 +- .../AVM2DeobfuscatorRegisters.java | 2 +- .../deobfuscation/AVM2DeobfuscatorSimple.java | 18 +++++++++--------- .../instructions/InstructionDefinition.java | 2 +- .../decompiler/flash/abc/types/MethodBody.java | 14 ++++++++------ 6 files changed, 26 insertions(+), 24 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 2746fad13..af6d51444 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 @@ -790,7 +790,7 @@ public class AVM2Code implements Cloneable { List switchAddresses = new ArrayList<>(); int availableBytes = ais.available(); for (int i = 0; i < availableBytes; i++) { - codeMap.put((long) i, new AVM2Instruction(i, new NopIns(), new int[]{})); + codeMap.put((long) i, new AVM2Instruction(i, new NopIns(), null)); } long startPos = ais.getPosition(); @@ -1267,7 +1267,7 @@ public class AVM2Code implements Cloneable { int fixBranch = ins.getFixBranch(); if (fixBranch > -1) { if (ins.definition instanceof IfTypeIns) { - for (int i = 0; i < -ins.definition.getStackDelta2(ins, null/*IfTypeIns do not require ABCs*/); i++) { + for (int i = 0; i < -ins.definition.getStackDelta(ins, null/*IfTypeIns do not require ABCs*/); i++) { writer.appendNoHilight(new DeobfuscatePopIns().instructionName).newLine(); } if (fixBranch == 0) { // jump @@ -2297,7 +2297,7 @@ public class AVM2Code implements Cloneable { stats.instructionStats[pos].stackpos = stack; stats.instructionStats[pos].scopepos = scope; - int stackDelta = ins.definition.getStackDelta2(ins, abc); + int stackDelta = ins.definition.getStackDelta(ins, abc); int scopeDelta = ins.definition.getScopeStackDelta(ins, abc); int oldStack = stack; @@ -2875,11 +2875,11 @@ public class AVM2Code implements Cloneable { if (ins2.isExit()) { code.set(i, new AVM2Instruction(ofs, ins2.definition, ins2.operands)); AVM2Instruction nopIns; - nopIns = new AVM2Instruction(ofs + 1, new NopIns(), new int[]{}); + nopIns = new AVM2Instruction(ofs + 1, new NopIns(), null); code.add(i + 1, nopIns); - nopIns = new AVM2Instruction(ofs + 2, new NopIns(), new int[]{}); + nopIns = new AVM2Instruction(ofs + 2, new NopIns(), null); code.add(i + 2, nopIns); - nopIns = new AVM2Instruction(ofs + 3, new NopIns(), new int[]{}); + nopIns = new AVM2Instruction(ofs + 3, new NopIns(), null); code.add(i + 3, nopIns); i += 3; csize = code.size(); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/CodeStats.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/CodeStats.java index 82990e6a5..0afc0fffb 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/CodeStats.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/avm2/CodeStats.java @@ -47,7 +47,7 @@ public class CodeStats { int i = 0; int ms = 0; for (InstructionStats stats : instructionStats) { - int deltastack = stats.ins.definition.getStackDelta2(stats.ins, abc); + int deltastack = stats.ins.definition.getStackDelta(stats.ins, abc); if (stats.stackpos > ms) { ms = stats.stackpos; } 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 67f9baf7a..6fe54caf3 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 @@ -141,7 +141,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, new DeobfuscatePopIns(), new int[]{}), body); + code.replaceInstruction(i, new AVM2Instruction(ins.offset, new DeobfuscatePopIns(), null), body); } } 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 6fce5fc26..773d953f6 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 @@ -120,15 +120,15 @@ public class AVM2DeobfuscatorSimple implements SWFDecompilerListener { } if (ovalue instanceof Boolean) { if ((Boolean) ovalue) { - return new AVM2Instruction(0, new PushTrueIns(), new int[]{}); + return new AVM2Instruction(0, new PushTrueIns(), null); } - return new AVM2Instruction(0, new PushFalseIns(), new int[]{}); + return new AVM2Instruction(0, new PushFalseIns(), null); } if (ovalue instanceof Null) { - return new AVM2Instruction(0, new PushNullIns(), new int[]{}); + return new AVM2Instruction(0, new PushNullIns(), null); } if (ovalue instanceof Undefined) { - return new AVM2Instruction(0, new PushUndefinedIns(), new int[]{}); + return new AVM2Instruction(0, new PushUndefinedIns(), null); } return null; } @@ -272,7 +272,7 @@ public class AVM2DeobfuscatorSimple implements SWFDecompilerListener { if (def instanceof SetLocalTypeIns) { int regId = ((SetLocalTypeIns) def).getRegisterId(ins); staticRegs.put(regId, localData.localRegs.get(regId).getNotCoerced()); - code.replaceInstruction(idx, new AVM2Instruction(0, new DeobfuscatePopIns(), new int[]{}), body); + code.replaceInstruction(idx, new AVM2Instruction(0, new DeobfuscatePopIns(), null), body); } } if (def instanceof GetLocalTypeIns) { @@ -364,7 +364,7 @@ public class AVM2DeobfuscatorSimple implements SWFDecompilerListener { AVM2Instruction tarIns = code.code.get(nidx); //Some IfType instructions need more than 1 operand, we must pop out all of them - int stackCount = -def.getStackDelta2(ins, abc); + int stackCount = -def.getStackDelta(ins, abc); if (EcmaScript.toBoolean(res)) { //System.err.println("replacing " + ins + " on " + idx + " with jump"); @@ -373,15 +373,15 @@ public class AVM2DeobfuscatorSimple implements SWFDecompilerListener { code.replaceInstruction(idx, jumpIns, body); jumpIns.operands[0] = (int) (tarIns.offset - jumpIns.offset - jumpIns.getBytesLength()); for (int s = 0; s < stackCount; s++) { - code.insertInstruction(idx, new AVM2Instruction(ins.offset, new DeobfuscatePopIns(), new int[]{}), true, body); + code.insertInstruction(idx, new AVM2Instruction(ins.offset, new DeobfuscatePopIns(), null), true, body); } idx = code.adr2pos(jumpIns.offset + jumpIns.getBytesLength() + jumpIns.operands[0]); } else { //System.err.println("replacing " + ins + " on " + idx + " with pop"); - code.replaceInstruction(idx, new AVM2Instruction(ins.offset, new DeobfuscatePopIns(), new int[]{}), body); + code.replaceInstruction(idx, new AVM2Instruction(ins.offset, new DeobfuscatePopIns(), null), body); for (int s = 1 /*first is replaced*/; s < stackCount; s++) { - code.insertInstruction(idx, new AVM2Instruction(ins.offset, new DeobfuscatePopIns(), new int[]{}), true, body); + code.insertInstruction(idx, new AVM2Instruction(ins.offset, new DeobfuscatePopIns(), null), true, body); } //ins.definition = new DeobfuscatePopIns(); idx++; 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 2da4b502a..bd7d84d34 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 @@ -160,7 +160,7 @@ public class InstructionDefinition implements Serializable { return name + ns; } - public int getStackDelta2(AVM2Instruction ins, ABC abc) { + public int getStackDelta(AVM2Instruction ins, ABC abc) { return getStackPushCount(ins, abc) - getStackPopCount(ins, abc); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java index 37a6ea62a..a35dbd288 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/types/MethodBody.java @@ -142,19 +142,21 @@ public final class MethodBody implements Cloneable { public List getExceptionEntries() { List ret = new ArrayList<>(); + AVM2Code code = getCode(); for (ABCException e : exceptions) { - ret.add(getCode().adr2pos(e.start, true)); - ret.add(getCode().adr2pos(e.end, true)); - ret.add(getCode().adr2pos(e.target)); + ret.add(code.adr2pos(e.start, true)); + ret.add(code.adr2pos(e.end, true)); + ret.add(code.adr2pos(e.target)); } return ret; } public void markOffsets() { long offset = 0; - for (int i = 0; i < getCode().code.size(); i++) { - getCode().code.get(i).offset = offset; - offset += getCode().code.get(i).getBytesLength(); + AVM2Code code = getCode(); + for (int i = 0; i < code.code.size(); i++) { + code.code.get(i).offset = offset; + offset += code.code.get(i).getBytesLength(); } }