From 00cc8f449966b58a8bb1e266f5da439fa06c5b21 Mon Sep 17 00:00:00 2001 From: "honfika@gmail.com" Date: Fri, 20 Nov 2015 15:42:12 +0100 Subject: [PATCH] common makePush moved to AVM2Constants --- .../deobfuscation/AVM2DeobfuscatorGetSet.java | 35 ------------- .../deobfuscation/AVM2DeobfuscatorJumps.java | 20 ++------ .../AVM2DeobfuscatorRegisters.java | 9 +--- .../deobfuscation/AVM2DeobfuscatorSimple.java | 51 ++++--------------- 4 files changed, 14 insertions(+), 101 deletions(-) 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 e2ee238fa..d0b85e414 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 @@ -23,7 +23,6 @@ import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool; import com.jpexs.decompiler.flash.abc.avm2.FixItemCounterTranslateStack; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; -import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instructions; import com.jpexs.decompiler.flash.abc.avm2.instructions.DeobfuscatePopIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.IfTypeIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition; @@ -38,8 +37,6 @@ import com.jpexs.decompiler.flash.abc.avm2.model.UndefinedAVM2Item; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.traits.Trait; import com.jpexs.decompiler.flash.action.ActionList; -import com.jpexs.decompiler.flash.ecma.Null; -import com.jpexs.decompiler.flash.ecma.Undefined; import com.jpexs.decompiler.flash.helpers.SWFDecompilerListener; import com.jpexs.decompiler.graph.Graph; import com.jpexs.decompiler.graph.GraphTargetItem; @@ -72,38 +69,6 @@ public class AVM2DeobfuscatorGetSet implements SWFDecompilerListener { } - protected AVM2Instruction makePush(Object ovalue, AVM2ConstantPool cpool) { - if (ovalue instanceof Long) { - long value = (Long) ovalue; - if (value >= -128 && value <= 127) { - return new AVM2Instruction(0, AVM2Instructions.PushByte, new int[]{(int) (long) value}); - } else if (value >= -32768 && value <= 32767) { - return new AVM2Instruction(0, AVM2Instructions.PushShort, new int[]{((int) (long) value) & 0xffff}); - } else { - return new AVM2Instruction(0, AVM2Instructions.PushInt, new int[]{cpool.getIntId(value, true)}); - } - } - if (ovalue instanceof Double) { - return new AVM2Instruction(0, AVM2Instructions.PushDouble, new int[]{cpool.getDoubleId((Double) ovalue, true)}); - } - if (ovalue instanceof String) { - return new AVM2Instruction(0, AVM2Instructions.PushString, new int[]{cpool.getStringId((String) ovalue, true)}); - } - if (ovalue instanceof Boolean) { - if ((Boolean) ovalue) { - return new AVM2Instruction(0, AVM2Instructions.PushTrue, null); - } - return new AVM2Instruction(0, AVM2Instructions.PushFalse, null); - } - if (ovalue == Null.INSTANCE) { - return new AVM2Instruction(0, AVM2Instructions.PushNull, null); - } - if (ovalue == Undefined.INSTANCE) { - return new AVM2Instruction(0, AVM2Instructions.PushUndefined, null); - } - return null; - } - protected boolean removeObfuscationGetSets(int classIndex, boolean isStatic, int scriptIndex, ABC abc, MethodBody body, List inlineIns) throws InterruptedException { AVM2Code code = body.getCode(); if (code.code.isEmpty()) { 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 a8567db80..9e5c71f5c 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 @@ -16,7 +16,6 @@ */ package com.jpexs.decompiler.flash.abc.avm2.deobfuscation; -import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction; @@ -24,7 +23,6 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.IfTypeIns; import com.jpexs.decompiler.flash.abc.avm2.instructions.jumps.JumpIns; import com.jpexs.decompiler.flash.abc.types.MethodBody; import com.jpexs.decompiler.flash.abc.types.traits.Trait; -import com.jpexs.decompiler.flash.action.ActionList; import java.util.List; import java.util.Map; @@ -38,17 +36,9 @@ import java.util.Map; */ public class AVM2DeobfuscatorJumps extends AVM2DeobfuscatorSimple { - //private final int executionLimit = 30000; - @Override - public void actionListParsed(ActionList actions, SWF swf) { - - } - @Override public void avm2CodeRemoveTraps(String path, int classIndex, boolean isStatic, int scriptIndex, ABC abc, Trait trait, int methodInfo, MethodBody body) throws InterruptedException { - //body.getCode().markMappedOffsets(); - //removeUnreachableInstructions(body.getCode(), cpool, trait, minfo, body); AVM2Code code = body.getCode(); boolean found; @@ -66,12 +56,10 @@ public class AVM2DeobfuscatorJumps extends AVM2DeobfuscatorSimple { AVM2Instruction srcIns = code.code.get(r); 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())); - if (srcIns.operands[0] != oldop) { - found = true; - } + int oldop = srcIns.operands[0]; + srcIns.operands[0] = (int) (targetAddr - (srcIns.offset + 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 2c470babd..0fa1c5a76 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 @@ -17,7 +17,6 @@ package com.jpexs.decompiler.flash.abc.avm2.deobfuscation; import com.jpexs.decompiler.flash.BaseLocalData; -import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.AVM2LocalData; import com.jpexs.decompiler.flash.abc.avm2.AVM2Code; @@ -36,7 +35,6 @@ 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.flash.action.ActionList; import com.jpexs.decompiler.graph.Graph; import com.jpexs.decompiler.graph.GraphPart; import com.jpexs.decompiler.graph.GraphSource; @@ -61,11 +59,6 @@ import java.util.Set; */ public class AVM2DeobfuscatorRegisters extends AVM2DeobfuscatorSimple { - @Override - public void actionListParsed(ActionList actions, SWF swf) { - - } - private Set getRegisters(AVM2Code code) { Set regs = new HashSet<>(); for (AVM2Instruction ins : code.code) { @@ -178,7 +171,7 @@ public class AVM2DeobfuscatorRegisters extends AVM2DeobfuscatorSimple { GetLocalTypeIns glt = (GetLocalTypeIns) ins.definition; int regId = glt.getRegisterId(ins); if (singleRegisters.containsKey(regId)) { - code.replaceInstruction(i, makePush(singleRegisters.get(regId).getResult(), cpool), body); + code.replaceInstruction(i, cpool.makePush(singleRegisters.get(regId).getResult()), 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 aa0f37e5d..c2bb2afa7 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 @@ -113,60 +113,27 @@ public class AVM2DeobfuscatorSimple implements SWFDecompilerListener { } - protected AVM2Instruction makePush(Object ovalue, AVM2ConstantPool cpool) { - if (ovalue instanceof Long) { - long value = (Long) ovalue; - if (value >= -128 && value <= 127) { - return new AVM2Instruction(0, AVM2Instructions.PushByte, new int[]{(int) (long) value}); - } else if (value >= -32768 && value <= 32767) { - return new AVM2Instruction(0, AVM2Instructions.PushShort, new int[]{((int) (long) value) & 0xffff}); - } else { - return new AVM2Instruction(0, AVM2Instructions.PushInt, new int[]{cpool.getIntId(value, true)}); - } - } - if (ovalue instanceof Double) { - return new AVM2Instruction(0, AVM2Instructions.PushDouble, new int[]{cpool.getDoubleId((Double) ovalue, true)}); - } - if (ovalue instanceof String) { - return new AVM2Instruction(0, AVM2Instructions.PushString, new int[]{cpool.getStringId((String) ovalue, true)}); - } - if (ovalue instanceof Boolean) { - if ((Boolean) ovalue) { - return new AVM2Instruction(0, AVM2Instructions.PushTrue, null); - } - return new AVM2Instruction(0, AVM2Instructions.PushFalse, null); - } - if (ovalue instanceof Null) { - return new AVM2Instruction(0, AVM2Instructions.PushNull, null); - } - if (ovalue instanceof Undefined) { - return new AVM2Instruction(0, AVM2Instructions.PushUndefined, null); - } - return null; - } - protected AVM2Instruction makePush(AVM2ConstantPool cpool, GraphTargetItem graphTargetItem) { - AVM2Instruction ins = null; if (graphTargetItem instanceof IntegerValueAVM2Item) { IntegerValueAVM2Item iv = (IntegerValueAVM2Item) graphTargetItem; - return makePush(iv.value, cpool); + return cpool.makePush(iv.value); } else if (graphTargetItem instanceof FloatValueAVM2Item) { FloatValueAVM2Item fv = (FloatValueAVM2Item) graphTargetItem; - return makePush(fv.value, cpool); + return cpool.makePush(fv.value); } else if (graphTargetItem instanceof StringAVM2Item) { StringAVM2Item fv = (StringAVM2Item) graphTargetItem; - return makePush(fv.getValue(), cpool); + return cpool.makePush(fv.getValue()); } else if (graphTargetItem instanceof TrueItem) { - return makePush(Boolean.TRUE, cpool); + return cpool.makePush(Boolean.TRUE); } else if (graphTargetItem instanceof FalseItem) { - return makePush(Boolean.FALSE, cpool); + return cpool.makePush(Boolean.FALSE); } else if (graphTargetItem instanceof NullAVM2Item) { - return makePush(Null.INSTANCE, cpool); + return cpool.makePush(Null.INSTANCE); } else if (graphTargetItem instanceof UndefinedAVM2Item) { - return makePush(Undefined.INSTANCE, cpool); - } else { - return null; + return cpool.makePush(Undefined.INSTANCE); } + + return null; } protected boolean removeObfuscationIfs(int classIndex, boolean isStatic, int scriptIndex, ABC abc, MethodBody body, List inlineIns) throws InterruptedException {