From 800caa77c071157824f066578020b42eaaf3f5cb Mon Sep 17 00:00:00 2001 From: Vitali Deatlov Date: Fri, 27 May 2016 23:16:08 +0300 Subject: [PATCH] improved deobfuscation of ternary operator --- .../AVM2DeobfuscatorSimpleOld.java | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) 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 472aa6bdd..5fadb3a3d 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 @@ -155,6 +155,16 @@ public class AVM2DeobfuscatorSimpleOld extends SWFDecompilerAdapter { return false; } + // find jump targets + List jumpTargets = new ArrayList(); + for (int i = 0; i < code.code.size(); i++) { + AVM2Instruction ins = code.code.get(i); + if (ins.definition instanceof JumpIns) { + long address = ins.getTargetAddress(); + jumpTargets.add( code.adr2pos(address) ); + } + } + AVM2LocalData localData = newLocalData(scriptIndex, abc, abc.constants, body, isStatic, classIndex); int localReservedCount = body.getLocalReservedCount(); for (int i = 0; i < code.code.size(); i++) { @@ -168,7 +178,7 @@ public class AVM2DeobfuscatorSimpleOld extends SWFDecompilerAdapter { localData.localRegs.clear(); initLocalRegs(localData, localReservedCount, body.max_regs); - executeInstructions(staticRegs, body, abc, code, localData, i, code.code.size() - 1, null, inlineIns); + executeInstructions(staticRegs, body, abc, code, localData, i, code.code.size() - 1, null, inlineIns, jumpTargets); } return false; @@ -218,7 +228,7 @@ public class AVM2DeobfuscatorSimpleOld extends SWFDecompilerAdapter { } } - private void executeInstructions(Map staticRegs, MethodBody body, ABC abc, AVM2Code code, AVM2LocalData localData, int idx, int endIdx, ExecutionResult result, List inlineIns) throws InterruptedException { + private void executeInstructions(Map staticRegs, MethodBody body, ABC abc, AVM2Code code, AVM2LocalData localData, int idx, int endIdx, ExecutionResult result, List inlineIns, List jumpTargets) throws InterruptedException { List output = new ArrayList<>(); FixItemCounterTranslateStack stack = new FixItemCounterTranslateStack(""); @@ -284,9 +294,13 @@ public class AVM2DeobfuscatorSimpleOld extends SWFDecompilerAdapter { if (inlineIns.contains(ins)) { if (def instanceof SetLocalTypeIns) { - int regId = ((SetLocalTypeIns) def).getRegisterId(ins); - staticRegs.put(regId, localData.localRegs.get(regId).getNotCoerced()); - code.replaceInstruction(idx, new AVM2Instruction(0, DeobfuscatePopIns.getInstance(), null), body); + InstructionDefinition prevDef = code.code.get(idx-1).definition; + if ((prevDef instanceof DupIns && !jumpTargets.contains(idx-2)) || !jumpTargets.contains(idx-1)) + { + int regId = ((SetLocalTypeIns) def).getRegisterId(ins); + staticRegs.put(regId, localData.localRegs.get(regId).getNotCoerced()); + code.replaceInstruction(idx, new AVM2Instruction(0, DeobfuscatePopIns.getInstance(), null), body); + } } } if (def instanceof GetLocalTypeIns) {