Issue #50 AS1/2 function body deobfuscation bug

This commit is contained in:
Jindra Pet��k
2013-03-31 19:26:37 +02:00
parent be106cc34b
commit 3472cc79d2
30 changed files with 474 additions and 821 deletions
@@ -16,6 +16,7 @@
*/
package com.jpexs.decompiler.flash.action.swf5;
import com.jpexs.decompiler.flash.ReReadableInputStream;
import com.jpexs.decompiler.flash.SWFInputStream;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.action.Action;
@@ -30,7 +31,6 @@ import com.jpexs.decompiler.flash.action.swf7.ActionDefineFunction2;
import com.jpexs.decompiler.flash.action.treemodel.FunctionTreeItem;
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
import com.jpexs.decompiler.flash.helpers.Helper;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.ArrayList;
@@ -48,6 +48,7 @@ public class ActionDefineFunction extends Action implements ActionContainer {
public int codeSize;
private int version;
public List<String> constantPool;
private long hdrSize;
@Override
public List<Action> getActions() {
@@ -69,22 +70,27 @@ public class ActionDefineFunction extends Action implements ActionContainer {
}
}
public ActionDefineFunction(int actionLength, SWFInputStream sis, int version) throws IOException {
public ActionDefineFunction(int actionLength, SWFInputStream sis, ReReadableInputStream rri, int version) throws IOException {
super(0x9B, actionLength);
this.version = version;
//byte data[]=sis.readBytes(actionLength);
//sis=new SWFInputStream(new ByteArrayInputStream(data),version);
long startPos = sis.getPos();
functionName = sis.readString();
int numParams = sis.readUI16();
for (int i = 0; i < numParams; i++) {
paramNames.add(sis.readString());
}
codeSize = sis.readUI16();
long endPos = sis.getPos();
//code = new ArrayList<Action>();
code = (new SWFInputStream(new ByteArrayInputStream(sis.readBytes(codeSize)), version)).readActionList();
hdrSize = endPos - startPos;
int posBef2 = rri.getPos();
code = sis.readActionList(rri.getPos(), getFileAddress() + hdrSize, rri, codeSize);
rri.setPos(posBef2 + codeSize);
}
public ActionDefineFunction(boolean ignoreNops, List<Label> labels, long address, FlasmLexer lexer, List<String> constantPool, int version) throws IOException, ParseException {
public ActionDefineFunction(long containerSWFPos, boolean ignoreNops, List<Label> labels, long address, FlasmLexer lexer, List<String> constantPool, int version) throws IOException, ParseException {
super(0x9B, -1);
functionName = lexString(lexer);
int numParams = (int) lexLong(lexer);
@@ -92,7 +98,27 @@ public class ActionDefineFunction extends Action implements ActionContainer {
paramNames.add(lexString(lexer));
}
lexBlockOpen(lexer);
code = ASMParser.parse(ignoreNops, labels, address + getPreLen(version), lexer, constantPool, version);
code = ASMParser.parse(containerSWFPos + getHeaderLength(), ignoreNops, labels, address + getPreLen(version), lexer, constantPool, version);
}
public long getHeaderLength() {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
SWFOutputStream sos = new SWFOutputStream(baos, version);
ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
try {
sos.writeString(functionName);
sos.writeUI16(paramNames.size());
for (String s : paramNames) {
sos.writeString(s);
}
sos.writeUI16(0);
sos.close();
baos2.write(surroundWithAction(baos.toByteArray(), version));
} catch (IOException e) {
}
return baos2.toByteArray().length;
}
@Override
@@ -158,9 +184,11 @@ public class ActionDefineFunction extends Action implements ActionContainer {
}
@Override
public void setAddress(long address, int version) {
super.setAddress(address, version);
Action.setActionsAddresses(code, address + getPreLen(version), version);
public void setAddress(long address, int version, boolean recursive) {
super.setAddress(address, version, recursive);
if (recursive) {
Action.setActionsAddresses(code, address + getPreLen(version), version);
}
}
@Override
@@ -170,7 +198,7 @@ public class ActionDefineFunction extends Action implements ActionContainer {
paramStr += "\"" + Helper.escapeString(paramNames.get(i)) + "\"";
paramStr += " ";
}
return "DefineFunction \"" + Helper.escapeString(functionName) + "\" " + paramNames.size() + " " + paramStr + " {\r\n" + Action.actionsToString(code, knownAddreses, constantPool, version, hex) + "}";
return "DefineFunction \"" + Helper.escapeString(functionName) + "\" " + paramNames.size() + " " + paramStr + " {\r\n" + Action.actionsToString(getAddress() + getHeaderLength(), code, knownAddreses, constantPool, version, hex, getFileAddress() + hdrSize) + "}";
}
@Override
@@ -211,4 +239,9 @@ public class ActionDefineFunction extends Action implements ActionContainer {
public String toString() {
return "DefineFunction";
}
@Override
public int getDataLength() {
return codeSize;
}
}