mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-26 08:40:47 +00:00
Better AS1/2 deobfuscation
This commit is contained in:
@@ -21,14 +21,16 @@ import com.jpexs.decompiler.flash.SWFInputStream;
|
||||
import com.jpexs.decompiler.flash.SWFOutputStream;
|
||||
import com.jpexs.decompiler.flash.action.Action;
|
||||
import com.jpexs.decompiler.flash.action.ActionGraph;
|
||||
import com.jpexs.decompiler.flash.action.ActionGraphSource;
|
||||
import com.jpexs.decompiler.flash.action.parser.ASMParser;
|
||||
import com.jpexs.decompiler.flash.action.parser.FlasmLexer;
|
||||
import com.jpexs.decompiler.flash.action.parser.Label;
|
||||
import com.jpexs.decompiler.flash.action.parser.ParseException;
|
||||
import com.jpexs.decompiler.flash.action.special.ActionContainer;
|
||||
import com.jpexs.decompiler.flash.graph.GraphSourceItemContainer;
|
||||
import com.jpexs.decompiler.flash.action.swf4.ActionPush;
|
||||
import com.jpexs.decompiler.flash.action.swf7.ActionDefineFunction2;
|
||||
import com.jpexs.decompiler.flash.action.treemodel.FunctionTreeItem;
|
||||
import com.jpexs.decompiler.flash.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.flash.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.flash.helpers.Helper;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -38,38 +40,41 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
public class ActionDefineFunction extends Action implements ActionContainer {
|
||||
public class ActionDefineFunction extends Action implements GraphSourceItemContainer {
|
||||
|
||||
public String functionName;
|
||||
public String replacedFunctionName;
|
||||
public List<String> paramNames = new ArrayList<String>();
|
||||
public List<String> replacedParamNames;
|
||||
public List<Action> code;
|
||||
//public List<Action> code;
|
||||
public int codeSize;
|
||||
private int version;
|
||||
public List<String> constantPool;
|
||||
private long hdrSize;
|
||||
|
||||
@Override
|
||||
public List<Action> getActions() {
|
||||
return code;
|
||||
public long getEndAddress() {
|
||||
return getAddress()+getHeaderLength()+codeSize;
|
||||
}
|
||||
|
||||
public void setConstantPool(List<String> constantPool) {
|
||||
this.constantPool = constantPool;
|
||||
for (Action a : code) {
|
||||
if (a instanceof ActionPush) {
|
||||
((ActionPush) a).constantPool = constantPool;
|
||||
}
|
||||
if (a instanceof ActionDefineFunction2) {
|
||||
((ActionDefineFunction2) a).setConstantPool(constantPool);
|
||||
}
|
||||
if (a instanceof ActionDefineFunction) {
|
||||
((ActionDefineFunction) a).setConstantPool(constantPool);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void setEndAddress(long address) {
|
||||
codeSize = (int)(address-getAddress()-getHeaderLength());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public List<GraphSourceItem> getItems(List<GraphSourceItem> parent) {
|
||||
if(parent.isEmpty()){
|
||||
return parent;
|
||||
}
|
||||
ActionGraphSource src=new ActionGraphSource(parent, version, new HashMap<Integer, String>(), new HashMap<String, GraphTargetItem>(), new HashMap<String, GraphTargetItem>());
|
||||
return parent.subList(src.adr2pos(getAddress()+getHeaderLength()),src.adr2pos(getAddress()+getHeaderLength()+codeSize));
|
||||
}
|
||||
|
||||
|
||||
public ActionDefineFunction(int actionLength, SWFInputStream sis, ReReadableInputStream rri, int version) throws IOException {
|
||||
super(0x9B, actionLength);
|
||||
this.version = version;
|
||||
@@ -86,8 +91,8 @@ public class ActionDefineFunction extends Action implements ActionContainer {
|
||||
//code = new ArrayList<Action>();
|
||||
hdrSize = endPos - startPos;
|
||||
int posBef2 = rri.getPos();
|
||||
code = sis.readActionList(rri.getPos(), getFileAddress() + hdrSize, rri, codeSize);
|
||||
rri.setPos(posBef2 + codeSize);
|
||||
//code = sis.readActionList(rri.getPos(), getFileAddress() + hdrSize, rri, codeSize);
|
||||
//rri.setPos(posBef2 + codeSize);
|
||||
}
|
||||
|
||||
public ActionDefineFunction(long containerSWFPos, boolean ignoreNops, List<Label> labels, long address, FlasmLexer lexer, List<String> constantPool, int version) throws IOException, ParseException {
|
||||
@@ -98,7 +103,7 @@ public class ActionDefineFunction extends Action implements ActionContainer {
|
||||
paramNames.add(lexString(lexer));
|
||||
}
|
||||
lexBlockOpen(lexer);
|
||||
code = ASMParser.parse(containerSWFPos + getHeaderLength(), ignoreNops, labels, address + getPreLen(version), lexer, constantPool, version);
|
||||
//code = ASMParser.parse(containerSWFPos + getHeaderLength(), ignoreNops, labels, address + getPreLen(version), lexer, constantPool, version);
|
||||
}
|
||||
|
||||
public long getHeaderLength() {
|
||||
@@ -132,8 +137,8 @@ public class ActionDefineFunction extends Action implements ActionContainer {
|
||||
for (String s : paramNames) {
|
||||
sos.writeString(s);
|
||||
}
|
||||
byte codeBytes[] = Action.actionsToBytes(code, false, version);
|
||||
sos.writeUI16(codeBytes.length);
|
||||
//byte codeBytes[] = Action.actionsToBytes(getActions(null), false, version);
|
||||
sos.writeUI16(codeSize);//codeBytes.length);
|
||||
sos.close();
|
||||
|
||||
|
||||
@@ -154,13 +159,13 @@ public class ActionDefineFunction extends Action implements ActionContainer {
|
||||
for (String s : paramNames) {
|
||||
sos.writeString(s);
|
||||
}
|
||||
byte codeBytes[] = Action.actionsToBytes(code, false, version);
|
||||
sos.writeUI16(codeBytes.length);
|
||||
//byte codeBytes[] = Action.actionsToBytes(code, false, version);
|
||||
sos.writeUI16(codeSize); //codeBytes.length);
|
||||
sos.close();
|
||||
|
||||
|
||||
baos2.write(surroundWithAction(baos.toByteArray(), version));
|
||||
baos2.write(codeBytes);
|
||||
//baos2.write(codeBytes);
|
||||
} catch (IOException e) {
|
||||
}
|
||||
return baos2.toByteArray();
|
||||
@@ -187,22 +192,23 @@ public class ActionDefineFunction extends Action implements ActionContainer {
|
||||
public void setAddress(long address, int version, boolean recursive) {
|
||||
super.setAddress(address, version, recursive);
|
||||
if (recursive) {
|
||||
Action.setActionsAddresses(code, address + getPreLen(version), version);
|
||||
//Action.setActionsAddresses(, address + getPreLen(version), version);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getASMSource(List<Long> knownAddreses, List<String> constantPool, int version, boolean hex) {
|
||||
public String getASMSource(List<GraphSourceItem> container, List<Long> knownAddreses, List<String> constantPool, int version, boolean hex) {
|
||||
String paramStr = "";
|
||||
for (int i = 0; i < paramNames.size(); i++) {
|
||||
paramStr += "\"" + Helper.escapeString(paramNames.get(i)) + "\"";
|
||||
paramStr += " ";
|
||||
}
|
||||
return "DefineFunction \"" + Helper.escapeString(functionName) + "\" " + paramNames.size() + " " + paramStr + " {\r\n" + Action.actionsToString(getAddress() + getHeaderLength(), code, knownAddreses, constantPool, version, hex, getFileAddress() + hdrSize) + "}";
|
||||
|
||||
return "DefineFunction \"" + Helper.escapeString(functionName) + "\" " + paramNames.size() + " " + paramStr + " {";// + "\r\n" +Action.actionsToString(getAddress() + getHeaderLength(),getItems(container) , knownAddreses, constantPool, version, hex, getFileAddress() + hdrSize) + "}";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getASMSourceReplaced(List<Long> knownAddreses, List<String> constantPool, int version, boolean hex) {
|
||||
public String getASMSourceReplaced(List<GraphSourceItem> container, List<Long> knownAddreses, List<String> constantPool, int version, boolean hex) {
|
||||
List<String> oldParamNames = paramNames;
|
||||
if (replacedParamNames != null) {
|
||||
paramNames = replacedParamNames;
|
||||
@@ -211,7 +217,7 @@ public class ActionDefineFunction extends Action implements ActionContainer {
|
||||
if (replacedFunctionName != null) {
|
||||
functionName = replacedFunctionName;
|
||||
}
|
||||
String ret = getASMSource(knownAddreses, constantPool, version, hex);
|
||||
String ret = getASMSource(container,knownAddreses, constantPool, version, hex);
|
||||
paramNames = oldParamNames;
|
||||
functionName = oldFunctionName;
|
||||
return ret;
|
||||
@@ -220,21 +226,28 @@ public class ActionDefineFunction extends Action implements ActionContainer {
|
||||
|
||||
@Override
|
||||
public List<Long> getAllRefs(int version) {
|
||||
return Action.getActionsAllRefs(code, version);
|
||||
return super.getAllRefs(version);//Action.getActionsAllRefs(getActions(null), version);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Action> getAllIfsOrJumps() {
|
||||
return Action.getActionsAllIfsOrJumps(code);
|
||||
return super.getAllIfsOrJumps(); //Action.getActionsAllIfsOrJumps(code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translate(Stack<GraphTargetItem> stack, List<GraphTargetItem> output, HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions) {
|
||||
FunctionTreeItem fti = new FunctionTreeItem(this, functionName, paramNames, ActionGraph.translateViaGraph(regNames, variables, functions, code, version), constantPool, 1);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translateContainer(List<GraphTargetItem> content, Stack<GraphTargetItem> stack, List<GraphTargetItem> output, HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions) {
|
||||
FunctionTreeItem fti = new FunctionTreeItem(this, functionName, paramNames, content, constantPool, 1);
|
||||
//ActionGraph.translateViaGraph(regNames, variables, functions, code, version)
|
||||
stack.push(fti);
|
||||
functions.put(functionName, fti);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "DefineFunction";
|
||||
|
||||
Reference in New Issue
Block a user