From 67dec09957db1999fcd71a5aed955377d2211146 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jindra=20Pet=F8=EDk?= Date: Sun, 24 Mar 2013 07:42:51 +0100 Subject: [PATCH] AS1/2 better identifiers renaming (deobfuscation) --- trunk/src/com/jpexs/decompiler/flash/SWF.java | 13 ++++++++++++- .../com/jpexs/decompiler/flash/SWFInputStream.java | 6 +++++- .../flash/action/special/ActionContainer.java | 5 +++++ .../flash/action/swf5/ActionDefineFunction.java | 5 +++++ .../decompiler/flash/action/swf5/ActionWith.java | 5 +++++ .../flash/action/swf7/ActionDefineFunction2.java | 5 +++++ 6 files changed, 37 insertions(+), 2 deletions(-) diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index 4a2d91a17..9a6b80fa9 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash; import SevenZip.Compression.LZMA.Encoder; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.ActionGraphSource; +import com.jpexs.decompiler.flash.action.special.ActionContainer; import com.jpexs.decompiler.flash.action.swf4.ActionEquals; import com.jpexs.decompiler.flash.action.swf4.ActionGetVariable; import com.jpexs.decompiler.flash.action.swf4.ActionIf; @@ -891,9 +892,15 @@ public class SWF { name = stack.peek(); } + if ((ins instanceof ActionDefineFunction) || (ins instanceof ActionDefineFunction2)) { functions.add(ins); } + + if (ins instanceof ActionContainer) { + getVariables(variables, functions, new ActionGraphSource(((ActionContainer) ins).getActions(), code.version, new HashMap(), new HashMap(), new HashMap()), 0); + } + if ((ins instanceof ActionSetVariable) || (ins instanceof ActionSetMember) || (ins instanceof ActionDefineLocal)) { name = stack.get(stack.size() - 2); } @@ -910,7 +917,11 @@ public class SWF { constantPool = new ConstantPool(((ActionConstantPool) ins).constantPool); } - ins.translate(localData, stack, output); + try { + ins.translate(localData, stack, output); + } catch (Exception ex) { + //ignore + } if (ins.isExit()) { break; } diff --git a/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java b/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java index ed0c72fc0..18c7b053a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java @@ -542,7 +542,11 @@ public class SWFInputStream extends InputStream { if (((ins instanceof ActionEquals) || (ins instanceof ActionEquals2)) && (stack.size() == 1) && (stack.peek() instanceof DirectValueTreeItem)) { stack.push(new DirectValueTreeItem(null, 0, new Null(), new ArrayList())); } - ins.translate(localData, stack, output); + try { + ins.translate(localData, stack, output); + } catch (Exception ex) { + //ignore + } if (ins.isExit()) { break; } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/special/ActionContainer.java b/trunk/src/com/jpexs/decompiler/flash/action/special/ActionContainer.java index 10ec9bf77..ad79bb588 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/special/ActionContainer.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/special/ActionContainer.java @@ -1,5 +1,8 @@ package com.jpexs.decompiler.flash.action.special; +import com.jpexs.decompiler.flash.action.Action; +import java.util.List; + /** * * @author JPEXS @@ -7,4 +10,6 @@ package com.jpexs.decompiler.flash.action.special; public interface ActionContainer { public byte[] getHeaderBytes(); + + public List getActions(); } diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionDefineFunction.java b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionDefineFunction.java index 3e557afaa..56ff9cade 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionDefineFunction.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionDefineFunction.java @@ -49,6 +49,11 @@ public class ActionDefineFunction extends Action implements ActionContainer { private int version; public List constantPool; + @Override + public List getActions() { + return code; + } + public void setConstantPool(List constantPool) { this.constantPool = constantPool; for (Action a : code) { diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionWith.java b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionWith.java index 72dd78257..574f76d31 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionWith.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf5/ActionWith.java @@ -35,6 +35,11 @@ public class ActionWith extends Action implements ActionContainer { public int size; public int version; + @Override + public List getActions() { + return actions; + } + public ActionWith(SWFInputStream sis, int version) throws IOException { super(0x94, 2); size = sis.readUI16(); diff --git a/trunk/src/com/jpexs/decompiler/flash/action/swf7/ActionDefineFunction2.java b/trunk/src/com/jpexs/decompiler/flash/action/swf7/ActionDefineFunction2.java index 3832b1b29..1eb55d4c6 100644 --- a/trunk/src/com/jpexs/decompiler/flash/action/swf7/ActionDefineFunction2.java +++ b/trunk/src/com/jpexs/decompiler/flash/action/swf7/ActionDefineFunction2.java @@ -60,6 +60,11 @@ public class ActionDefineFunction2 extends Action implements ActionContainer { private int version; public List constantPool; + @Override + public List getActions() { + return code; + } + public void setConstantPool(List constantPool) { this.constantPool = constantPool; for (Action a : code) {