removed some unnecessary parameters + small fixes

This commit is contained in:
honfika@gmail.com
2015-10-21 08:54:25 +02:00
parent a093b2580e
commit 099bffdf68
70 changed files with 270 additions and 158 deletions

View File

@@ -58,6 +58,10 @@ public class IdentifiersDeobfuscation {
private static final Pattern IDENTIFIER_PATTERN = Pattern.compile("^[" + VALID_FIRST_CHARACTERS + "][" + VALID_NEXT_CHARACTERS + "]*$");
private static final Pattern VALID_NAME_PATTERN_DOT = Pattern.compile("^[a-zA-Z_\\$][a-zA-Z0-9_.\\$]*$");
private static final Pattern IDENTIFIER_PATTERN_DOT = Pattern.compile("^[" + VALID_FIRST_CHARACTERS + "][" + VALID_NEXT_CHARACTERS + ".]*$");
public static final String FOO_CHARACTERS = "bcdfghjklmnpqrstvwz";
public static final String FOO_JOIN_CHARACTERS = "aeiouy";
@@ -228,6 +232,28 @@ public class IdentifiersDeobfuscation {
return null;
}
public static boolean isValidNameWithDot(boolean as3, String s, String... exceptions) {
for (String e : exceptions) {
if (e.equals(s)) {
return true;
}
}
if (isReservedWord(s, as3)) {
return false;
}
// simple fast test
if (VALID_NAME_PATTERN_DOT.matcher(s).matches()) {
return true;
}
// unicode test
if (IDENTIFIER_PATTERN_DOT.matcher(s).matches()) {
return true;
}
return false;
}
public static boolean isValidName(boolean as3, String s, String... exceptions) {
for (String e : exceptions) {
if (e.equals(s)) {

View File

@@ -20,8 +20,10 @@ import com.jpexs.decompiler.flash.BaseLocalData;
import com.jpexs.decompiler.flash.abc.avm2.AVM2Code;
import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
import com.jpexs.decompiler.flash.abc.types.ABCException;
import com.jpexs.decompiler.flash.abc.types.InstanceInfo;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.flash.abc.types.ScriptInfo;
import com.jpexs.decompiler.graph.DottedChain;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.ScopeStack;
@@ -44,10 +46,6 @@ public class AVM2LocalData extends BaseLocalData {
public ScopeStack scopeStack;
public AVM2ConstantPool constants;
public List<MethodInfo> methodInfo;
public MethodBody methodBody;
public ABC abc;
@@ -83,8 +81,6 @@ public class AVM2LocalData extends BaseLocalData {
classIndex = localData.classIndex;
localRegs = localData.localRegs;
scopeStack = localData.scopeStack;
constants = localData.constants;
methodInfo = localData.methodInfo;
methodBody = localData.methodBody;
abc = localData.abc;
localRegNames = localData.localRegNames;
@@ -99,4 +95,20 @@ public class AVM2LocalData extends BaseLocalData {
refs = localData.refs;
code = localData.code;
}
public AVM2ConstantPool getConstants() {
return abc.constants;
}
public List<MethodInfo> getMethodInfo() {
return abc.method_info;
}
public List<InstanceInfo> getInstanceInfo() {
return abc.instance_info;
}
public List<ScriptInfo> getScriptInfo() {
return abc.script_info;
}
}

View File

@@ -68,6 +68,7 @@ public class ScriptPack extends AS3ClassTreeItem {
private final ClassPath path;
public boolean isSimple = false;
public boolean scriptInitializerIsEmpty = false;
@Override
@@ -162,7 +163,7 @@ public class ScriptPack extends AS3ClassTreeItem {
}
writer.mark();
abc.bodies.get(bodyIndex).convert(path +/*packageName +*/ "/.scriptinitializer", exportMode, true, script_init, scriptIndex, -1, abc, null, abc.constants, abc.method_info, new ScopeStack(), GraphTextWriter.TRAIT_SCRIPT_INITIALIZER, writer, new ArrayList<DottedChain>(), ts, true);
abc.bodies.get(bodyIndex).convert(path +/*packageName +*/ "/.scriptinitializer", exportMode, true, script_init, scriptIndex, -1, abc, null, new ScopeStack(), GraphTextWriter.TRAIT_SCRIPT_INITIALIZER, writer, new ArrayList<DottedChain>(), ts, true);
scriptInitializerIsEmpty = !writer.getMark();
}
@@ -190,7 +191,7 @@ public class ScriptPack extends AS3ClassTreeItem {
writer.startMethod(script_init);
if (!scriptInitializerIsEmpty) {
writer.startBlock();
abc.bodies.get(bodyIndex).toString(path +/*packageName +*/ "/.scriptinitializer", exportMode, abc, null, abc.constants, abc.method_info, writer, new ArrayList<DottedChain>());
abc.bodies.get(bodyIndex).toString(path +/*packageName +*/ "/.scriptinitializer", exportMode, abc, null, writer, new ArrayList<>());
writer.endBlock();
} else {
writer.append(" ");

View File

@@ -275,6 +275,7 @@ import com.jpexs.decompiler.flash.ecma.EcmaScript;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
import com.jpexs.decompiler.flash.helpers.SWFDecompilerPlugin;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightSpecialType;
import com.jpexs.decompiler.graph.Block;
import com.jpexs.decompiler.graph.DottedChain;
@@ -1463,7 +1464,7 @@ public class AVM2Code implements Cloneable {
return pos2adr(fixIPAfterDebugLine(adr2pos(addr, true)));
}
public ConvertOutput toSourceOutput(String path, GraphPart part, boolean processJumps, boolean isStatic, int scriptIndex, int classIndex, HashMap<Integer, GraphTargetItem> localRegs, TranslateStack stack, ScopeStack scopeStack, ABC abc, AVM2ConstantPool constants, List<MethodInfo> method_info, MethodBody body, int start, int end, HashMap<Integer, String> localRegNames, List<DottedChain> fullyQualifiedNames, boolean[] visited, HashMap<Integer, Integer> localRegAssigmentIps, HashMap<Integer, List<Integer>> refs) throws ConvertException, InterruptedException {
public ConvertOutput toSourceOutput(String path, GraphPart part, boolean processJumps, boolean isStatic, int scriptIndex, int classIndex, HashMap<Integer, GraphTargetItem> localRegs, TranslateStack stack, ScopeStack scopeStack, ABC abc, MethodBody body, int start, int end, HashMap<Integer, String> localRegNames, List<DottedChain> fullyQualifiedNames, boolean[] visited, HashMap<Integer, Integer> localRegAssigmentIps, HashMap<Integer, List<Integer>> refs) throws ConvertException, InterruptedException {
calcKilledStats(body);
boolean debugMode = DEBUG_MODE;
if (debugMode) {
@@ -1570,12 +1571,12 @@ public class AVM2Code implements Cloneable {
AVM2Instruction insAfter = code.get(ip + 1);
if ((insAfter.definition instanceof GetLocalTypeIns) && (((GetLocalTypeIns) insAfter.definition).getRegisterId(insAfter) == ((SetLocalTypeIns) ins.definition).getRegisterId(ins))) {
GraphTargetItem before = stack.peek();
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, ins, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
stack.push(before);
ip += 2;
continue iploop;
} else {
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, ins, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
ip++;
continue iploop;
}
@@ -1584,7 +1585,7 @@ public class AVM2Code implements Cloneable {
do {
AVM2Instruction insAfter = ip + 1 < code.size() ? code.get(ip + 1) : null;
if (insAfter == null) {
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, ins, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
ip++;
break;
}
@@ -1618,7 +1619,7 @@ public class AVM2Code implements Cloneable {
if (((GetLocalTypeIns) code.get(t).definition).getRegisterId(code.get(t)) == reg) {
if (code.get(t + 1).definition instanceof KillIns) {
if (code.get(t + 1).operands[0] == reg) {
ConvertOutput assignment = toSourceOutput(path, part, processJumps, isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, abc, constants, method_info, body, ip + 2, t - 1, localRegNames, fullyQualifiedNames, visited, localRegAssigmentIps, refs);
ConvertOutput assignment = toSourceOutput(path, part, processJumps, isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, abc, body, ip + 2, t - 1, localRegNames, fullyQualifiedNames, visited, localRegAssigmentIps, refs);
if (!assignment.output.isEmpty()) {
GraphTargetItem tar = assignment.output.remove(assignment.output.size() - 1);
tar.firstPart = part;
@@ -1652,21 +1653,21 @@ public class AVM2Code implements Cloneable {
}
stack.push(vx);
} else {
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, ins, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
}
ip++;
break;
//}
} else {
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, ins, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
ip++;
break;
//throw new ConvertException("Unknown pattern after DUP:" + insComparsion.toString());
}
} while (ins.definition instanceof DupIns);
} else if ((ins.definition instanceof ReturnValueIns) || (ins.definition instanceof ReturnVoidIns) || (ins.definition instanceof ThrowIns)) {
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, ins, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
//ip = end + 1;
break;
} else if (ins.definition instanceof NewFunctionIns) {
@@ -1688,7 +1689,7 @@ public class AVM2Code implements Cloneable {
if (code.get(ip + plus + 2).definition instanceof SwapIns) {
if (code.get(ip + plus + 4).definition instanceof PopScopeIns) {
if (code.get(ip + plus + 3).definition instanceof SetPropertyIns) {
functionName = abc.constants.getMultiname(code.get(ip + plus + 3).operands[0]).getName(constants, fullyQualifiedNames, true);
functionName = abc.constants.getMultiname(code.get(ip + plus + 3).operands[0]).getName(abc.constants, fullyQualifiedNames, true);
scopeStack.pop();// with
output.remove(output.size() - 1); // with
ip = ip + plus + 4; // +1 below
@@ -1702,13 +1703,13 @@ public class AVM2Code implements Cloneable {
}
}
// What to do when hasDup is false?
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, ins, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
NewFunctionAVM2Item nft = (NewFunctionAVM2Item) stack.peek();
nft.functionName = functionName;
ip++;
} else {
try {
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, constants, ins, method_info, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
ins.definition.translate(isStatic, scriptIndex, classIndex, localRegs, stack, scopeStack, ins, output, body, abc, localRegNames, fullyQualifiedNames, path, localRegAssigmentIps, ip, refs, this);
} catch (RuntimeException re) {
/*String last="";
int len=5;
@@ -1879,7 +1880,7 @@ public class AVM2Code implements Cloneable {
}*/
}
public List<GraphTargetItem> toGraphTargetItems(String path, int methodIndex, boolean isStatic, int scriptIndex, int classIndex, ABC abc, AVM2ConstantPool constants, List<MethodInfo> method_info, MethodBody body, HashMap<Integer, String> localRegNames, ScopeStack scopeStack, int initializerType, List<DottedChain> fullyQualifiedNames, List<Traits> initTraits, int staticOperation, HashMap<Integer, Integer> localRegAssigmentIps, HashMap<Integer, List<Integer>> refs) throws InterruptedException {
public List<GraphTargetItem> toGraphTargetItems(String path, int methodIndex, boolean isStatic, int scriptIndex, int classIndex, ABC abc, MethodBody body, HashMap<Integer, String> localRegNames, ScopeStack scopeStack, int initializerType, List<DottedChain> fullyQualifiedNames, List<Traits> initTraits, int staticOperation, HashMap<Integer, Integer> localRegAssigmentIps, HashMap<Integer, List<Integer>> refs) throws InterruptedException {
initToSource();
List<GraphTargetItem> list;
HashMap<Integer, GraphTargetItem> localRegs = new HashMap<>();
@@ -2217,8 +2218,6 @@ public class AVM2Code implements Cloneable {
ret.classIndex = localData.classIndex;
ret.localRegs = new HashMap<>(localData.localRegs);
ret.scopeStack = (ScopeStack) (localData.scopeStack).clone();
ret.constants = localData.constants;
ret.methodInfo = localData.methodInfo;
ret.methodBody = localData.methodBody;
ret.abc = localData.abc;
ret.localRegNames = localData.localRegNames;
@@ -2235,15 +2234,13 @@ public class AVM2Code implements Cloneable {
return ret;
}
private int removeTrapsOld(AVM2ConstantPool constants, Trait trait, MethodInfo info, MethodBody body, ABC abc, int scriptIndex, int classIndex, boolean isStatic, String path) throws InterruptedException {
private int removeTrapsOld(Trait trait, int methodInfo, MethodBody body, ABC abc, int scriptIndex, int classIndex, boolean isStatic, String path) throws InterruptedException {
removeDeadCode(body);
AVM2LocalData localData = new AVM2LocalData();
localData.isStatic = isStatic;
localData.classIndex = classIndex;
localData.localRegs = new HashMap<>();
localData.scopeStack = new ScopeStack();
localData.constants = abc.constants;
localData.methodInfo = abc.method_info;
localData.methodBody = body;
localData.abc = abc;
localData.localRegNames = body.getLocalRegNames(abc);
@@ -2253,25 +2250,26 @@ public class AVM2Code implements Cloneable {
localData.refs = refs;
localData.code = this;
int ret = 0;
ret += removeTrapsOld(constants, trait, info, body, localData, new AVM2GraphSource(this, false, -1, -1, new HashMap<>(), new ScopeStack(), abc, body, new HashMap<>(), new ArrayList<>(), new HashMap<>(), refs), 0, path, refs);
ret += removeTrapsOld(trait, methodInfo, body, localData, new AVM2GraphSource(this, false, -1, -1, new HashMap<>(), new ScopeStack(), abc, body, new HashMap<>(), new ArrayList<>(), new HashMap<>(), refs), 0, path, refs);
removeIgnored(body);
removeDeadCode(body);
return ret;
}
public int removeTraps(AVM2ConstantPool constants, Trait trait, MethodInfo info, MethodBody body, ABC abc, int scriptIndex, int classIndex, boolean isStatic, String path) throws InterruptedException {
public int removeTraps(Trait trait, int methodInfo, MethodBody body, ABC abc, int scriptIndex, int classIndex, boolean isStatic, String path) throws InterruptedException {
if (Configuration.deobfuscationOldMode.get()) {
return removeTrapsOld(constants, trait, info, body, abc, scriptIndex, classIndex, isStatic, path);
return removeTrapsOld(trait, methodInfo, body, abc, scriptIndex, classIndex, isStatic, path);
} else {
SWFDecompilerPlugin.fireAvm2CodeRemoveTraps(path, classIndex, isStatic, scriptIndex, abc, trait, methodInfo, body);
try (Statistics s = new Statistics("AVM2DeobfuscatorSimple")) {
new AVM2DeobfuscatorSimple().deobfuscate(path, classIndex, isStatic, scriptIndex, abc, constants, trait, info, body);
new AVM2DeobfuscatorSimple().avm2CodeRemoveTraps(path, classIndex, isStatic, scriptIndex, abc, trait, methodInfo, body);
}
try (Statistics s = new Statistics("AVM2DeobfuscatorRegisters")) {
new AVM2DeobfuscatorRegisters().deobfuscate(path, classIndex, isStatic, scriptIndex, abc, constants, trait, info, body);
new AVM2DeobfuscatorRegisters().avm2CodeRemoveTraps(path, classIndex, isStatic, scriptIndex, abc, trait, methodInfo, body);
}
try (Statistics s = new Statistics("AVM2DeobfuscatorJumps")) {
new AVM2DeobfuscatorJumps().deobfuscate(path, classIndex, isStatic, scriptIndex, abc, constants, trait, info, body);
new AVM2DeobfuscatorJumps().avm2CodeRemoveTraps(path, classIndex, isStatic, scriptIndex, abc, trait, methodInfo, body);
}
return 1;
}
@@ -3310,7 +3308,7 @@ public class AVM2Code implements Cloneable {
return ret;
}
public static int removeTrapsOld(AVM2ConstantPool constants, Trait trait, MethodInfo info, MethodBody body, AVM2LocalData localData, AVM2GraphSource code, int addr, String path, HashMap<Integer, List<Integer>> refs) throws InterruptedException {
public static int removeTrapsOld(Trait trait, int methodInfo, MethodBody body, AVM2LocalData localData, AVM2GraphSource code, int addr, String path, HashMap<Integer, List<Integer>> refs) throws InterruptedException {
HashMap<AVM2Instruction, AVM2Code.Decision> decisions = new HashMap<>();
removeTrapsOld(refs, false, false, localData, new TranslateStack(path), new ArrayList<>(), code, code.adr2pos(addr), new HashMap<>(), new HashMap<>(), decisions, path, 0);
int cnt = 0;

View File

@@ -19,12 +19,10 @@ 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.AVM2ConstantPool;
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
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.MethodInfo;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.action.ActionList;
import java.util.List;
@@ -47,7 +45,7 @@ public class AVM2DeobfuscatorJumps extends AVM2DeobfuscatorSimple {
}
@Override
public void deobfuscate(String path, int classIndex, boolean isStatic, int scriptIndex, ABC abc, AVM2ConstantPool cpool, Trait trait, MethodInfo minfo, MethodBody body) throws InterruptedException {
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);
@@ -81,7 +79,7 @@ public class AVM2DeobfuscatorJumps extends AVM2DeobfuscatorSimple {
}
}
}
removeUnreachableInstructions(body.getCode(), cpool, trait, minfo, body);
removeUnreachableInstructions(body.getCode(), body);
} while (found);
}
}

View File

@@ -92,11 +92,11 @@ public class AVM2DeobfuscatorRegisters extends AVM2DeobfuscatorSimple {
}
@Override
public void deobfuscate(String path, int classIndex, boolean isStatic, int scriptIndex, ABC abc, AVM2ConstantPool cpool, Trait trait, MethodInfo minfo, MethodBody body) throws InterruptedException {
public void avm2CodeRemoveTraps(String path, int classIndex, boolean isStatic, int scriptIndex, ABC abc, Trait trait, int methodInfo, MethodBody body) throws InterruptedException {
//System.err.println("regdeo:" + path);
MethodBody originalBody = body;
removeUnreachableInstructions(body.getCode(), cpool, trait, minfo, body);
removeUnreachableInstructions(body.getCode(), body);
Set<Integer> ignoredRegs = new HashSet<>();
int localReservedCount = body.getLocalReservedCount();
@@ -141,7 +141,7 @@ public class AVM2DeobfuscatorRegisters extends AVM2DeobfuscatorSimple {
AVM2Instruction assignment = assignmentRef.getVal();
InstructionDefinition def = assignment.definition;
if ((def instanceof SetLocalTypeIns) || (def instanceof GetLocalTypeIns /*First usage -> value undefined*/)) {
super.removeObfuscationIfs(classIndex, isStatic, scriptIndex, abc, cpool, trait, minfo, body, Arrays.asList(assignment));
super.removeObfuscationIfs(classIndex, isStatic, scriptIndex, abc, body, Arrays.asList(assignment));
}
if (def instanceof GetLocalTypeIns) {
@@ -154,7 +154,7 @@ public class AVM2DeobfuscatorRegisters extends AVM2DeobfuscatorSimple {
originalBody.exceptions = body.exceptions;
originalBody.setCode(body.getCode());
removeUnreachableInstructions(body.getCode(), cpool, trait, minfo, body);
removeUnreachableInstructions(body.getCode(), body);
//System.err.println("/deo");
}

View File

@@ -77,7 +77,6 @@ import com.jpexs.decompiler.flash.abc.avm2.model.NullAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.StringAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.UndefinedAVM2Item;
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.flash.ecma.EcmaScript;
@@ -170,7 +169,7 @@ public class AVM2DeobfuscatorSimple implements SWFDecompilerListener {
}
}
protected boolean removeObfuscationIfs(int classIndex, boolean isStatic, int scriptIndex, ABC abc, AVM2ConstantPool cpool, Trait trait, MethodInfo minfo, MethodBody body, List<AVM2Instruction> inlineIns) throws InterruptedException {
protected boolean removeObfuscationIfs(int classIndex, boolean isStatic, int scriptIndex, ABC abc, MethodBody body, List<AVM2Instruction> inlineIns) throws InterruptedException {
AVM2Code code = body.getCode();
if (code.code.isEmpty()) {
return false;
@@ -206,7 +205,7 @@ public class AVM2DeobfuscatorSimple implements SWFDecompilerListener {
return false;
}
protected void removeUnreachableInstructions(AVM2Code code, AVM2ConstantPool cpool, Trait trait, MethodInfo minfo, MethodBody body) throws InterruptedException {
protected void removeUnreachableInstructions(AVM2Code code, MethodBody body) throws InterruptedException {
code.removeDeadCode(body);
}
@@ -236,8 +235,6 @@ public class AVM2DeobfuscatorSimple implements SWFDecompilerListener {
localData.localRegs = new HashMap<>(body.max_regs);
localData.localRegAssignmentIps = new HashMap<>();
localData.scopeStack = new ScopeStack(true);
localData.constants = cpool;
localData.methodInfo = abc.method_info;
localData.methodBody = body;
localData.abc = abc;
localData.localRegNames = new HashMap<>();
@@ -472,10 +469,11 @@ public class AVM2DeobfuscatorSimple implements SWFDecompilerListener {
}
public void deobfuscate(String path, int classIndex, boolean isStatic, int scriptIndex, ABC abc, AVM2ConstantPool cpool, Trait trait, MethodInfo minfo, MethodBody body) throws InterruptedException {
@Override
public void avm2CodeRemoveTraps(String path, int classIndex, boolean isStatic, int scriptIndex, ABC abc, Trait trait, int methodInfo, MethodBody body) throws InterruptedException {
AVM2Code code = body.getCode();
removeUnreachableInstructions(code, cpool, trait, minfo, body);
removeObfuscationIfs(classIndex, isStatic, scriptIndex, abc, cpool, trait, minfo, body, new ArrayList<>());
removeUnreachableInstructions(code, body);
removeObfuscationIfs(classIndex, isStatic, scriptIndex, abc, body, new ArrayList<>());
removeZeroJumps(code, body);
}

View File

@@ -122,8 +122,6 @@ public class AVM2Graph extends Graph {
localData.classIndex = classIndex;
localData.localRegs = localRegs;
localData.scopeStack = scopeStack;
localData.constants = abc.constants;
localData.methodInfo = abc.method_info;
localData.methodBody = body;
localData.abc = abc;
localData.localRegNames = localRegNames;

View File

@@ -102,7 +102,7 @@ public class AVM2GraphSource extends GraphSource {
public List<GraphTargetItem> translatePart(GraphPart part, BaseLocalData localData, TranslateStack stack, int start, int end, int staticOperation, String path) throws InterruptedException {
List<GraphTargetItem> ret = new ArrayList<>();
ScopeStack newstack = ((AVM2LocalData) localData).scopeStack;
ConvertOutput co = code.toSourceOutput(path, part, false, isStatic, scriptIndex, classIndex, localRegs, stack, newstack, abc, abc.constants, abc.method_info, body, start, end, localRegNames, fullyQualifiedNames, new boolean[size()], localRegAssigmentIps, refs);
ConvertOutput co = code.toSourceOutput(path, part, false, isStatic, scriptIndex, classIndex, localRegs, stack, newstack, abc, body, start, end, localRegNames, fullyQualifiedNames, new boolean[size()], localRegAssigmentIps, refs);
ret.addAll(co.output);
return ret;
}

View File

@@ -29,7 +29,6 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.localregs.SetLocalTypeIn
import com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.FullMultinameAVM2Item;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.DottedChain;
import com.jpexs.decompiler.graph.GraphTargetItem;
@@ -92,15 +91,13 @@ public abstract class InstructionDefinition implements Serializable {
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) throws InterruptedException {
}
public void translate(boolean isStatic, int scriptIndex, int classIndex, HashMap<Integer, GraphTargetItem> localRegs, TranslateStack stack, ScopeStack scopeStack, AVM2ConstantPool constants, AVM2Instruction ins, List<MethodInfo> method_info, List<GraphTargetItem> output, MethodBody body, ABC abc, HashMap<Integer, String> localRegNames, List<DottedChain> fullyQualifiedNames, String path, HashMap<Integer, Integer> localRegsAssignmentIps, int ip, HashMap<Integer, List<Integer>> refs, AVM2Code code) throws InterruptedException {
public void translate(boolean isStatic, int scriptIndex, int classIndex, HashMap<Integer, GraphTargetItem> localRegs, TranslateStack stack, ScopeStack scopeStack, AVM2Instruction ins, List<GraphTargetItem> output, MethodBody body, ABC abc, HashMap<Integer, String> localRegNames, List<DottedChain> fullyQualifiedNames, String path, HashMap<Integer, Integer> localRegsAssignmentIps, int ip, HashMap<Integer, List<Integer>> refs, AVM2Code code) throws InterruptedException {
AVM2LocalData localData = new AVM2LocalData();
localData.isStatic = isStatic;
localData.scriptIndex = scriptIndex;
localData.classIndex = classIndex;
localData.localRegs = localRegs;
localData.scopeStack = scopeStack;
localData.constants = constants;
localData.methodInfo = method_info;
localData.methodBody = body;
localData.abc = abc;
localData.localRegNames = localRegNames;

View File

@@ -89,13 +89,13 @@ public class ConstructIns extends InstructionDefinition {
FullMultinameAVM2Item fptXmlMult = (FullMultinameAVM2Item) fpt.propertyName;
FullMultinameAVM2Item gptXmlMult = (FullMultinameAVM2Item) gpt.propertyName;
isXML = fptXmlMult.isXML(localData.constants, localData.localRegNames, localData.fullyQualifiedNames)
&& gptXmlMult.isXML(localData.constants, localData.localRegNames, localData.fullyQualifiedNames);
isXML = fptXmlMult.isXML(localData.getConstants(), localData.localRegNames, localData.fullyQualifiedNames)
&& gptXmlMult.isXML(localData.getConstants(), localData.localRegNames, localData.fullyQualifiedNames);
}
}
if (obj instanceof GetLexAVM2Item) {
GetLexAVM2Item glt = (GetLexAVM2Item) obj;
isXML = glt.propertyName.getName(localData.constants, localData.fullyQualifiedNames, true).equals("XML");
isXML = glt.propertyName.getName(localData.getConstants(), localData.fullyQualifiedNames, true).equals("XML");
}
if (isXML) {

View File

@@ -60,10 +60,10 @@ public class ConstructPropIns extends InstructionDefinition {
for (int a = 0; a < argCount; a++) {
args.add(0, stack.pop());
}
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.constants, multinameIndex, ins);
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
GraphTargetItem obj = stack.pop();
if (multiname.isXML(localData.constants, localData.localRegNames, localData.fullyQualifiedNames)) {
if (multiname.isXML(localData.getConstants(), localData.localRegNames, localData.fullyQualifiedNames)) {
if (args.size() == 1) {
GraphTargetItem arg = args.get(0);
List<GraphTargetItem> xmlLines = new ArrayList<>();

View File

@@ -39,10 +39,10 @@ public class NewClassIns extends InstructionDefinition {
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) throws InterruptedException {
int clsIndex = ins.operands[0];
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
stack.pop().toString(writer, LocalData.create(localData.constants, localData.localRegNames, localData.fullyQualifiedNames));
stack.pop().toString(writer, LocalData.create(localData.getConstants(), localData.localRegNames, localData.fullyQualifiedNames));
String baseType = writer.toString();
ABC abc = localData.abc;
stack.push(new UnparsedAVM2Item(ins, "new " + abc.constants.getMultiname(abc.instance_info.get(clsIndex).name_index).getName(localData.constants, localData.fullyQualifiedNames, false) + ".class extends " + baseType));
stack.push(new UnparsedAVM2Item(ins, "new " + abc.constants.getMultiname(abc.instance_info.get(clsIndex).name_index).getName(localData.getConstants(), localData.fullyQualifiedNames, false) + ".class extends " + baseType));
}
@Override

View File

@@ -35,7 +35,7 @@ public class NewFunctionIns extends InstructionDefinition {
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
int methodIndex = ins.operands[0];
NewFunctionAVM2Item function = new NewFunctionAVM2Item(ins, "", path, localData.isStatic, localData.scriptIndex, localData.classIndex, localData.abc, localData.fullyQualifiedNames, localData.constants, localData.methodInfo, methodIndex);
NewFunctionAVM2Item function = new NewFunctionAVM2Item(ins, "", path, localData.isStatic, localData.scriptIndex, localData.classIndex, localData.abc, localData.fullyQualifiedNames, methodIndex);
stack.push(function);
}

View File

@@ -57,7 +57,7 @@ public class CallMethodIns extends InstructionDefinition {
args.add(0, stack.pop());
}
GraphTargetItem receiver = stack.pop();
String methodName = localData.methodInfo.get(methodIndex).getName(localData.constants);
String methodName = localData.getMethodInfo().get(methodIndex).getName(localData.getConstants());
stack.push(new CallMethodAVM2Item(ins, receiver, methodName, args));
}

View File

@@ -42,7 +42,7 @@ public class CallPropLexIns extends CallPropertyIns {
args.add(0, stack.pop());
}
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.constants, multinameIndex, ins);
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
GraphTargetItem receiver = stack.pop();
stack.push(new CallPropertyAVM2Item(ins, false, receiver, multiname, args));

View File

@@ -61,7 +61,7 @@ public class CallPropVoidIns extends InstructionDefinition {
for (int a = 0; a < argCount; a++) {
args.add(0, stack.pop());
}
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.constants, multinameIndex, ins);
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
GraphTargetItem receiver = stack.pop();

View File

@@ -60,7 +60,7 @@ public class CallPropertyIns extends InstructionDefinition {
args.add(0, stack.pop());
}
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.constants, multinameIndex, ins);
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
GraphTargetItem receiver = stack.pop();
stack.push(new CallPropertyAVM2Item(ins, false, receiver, multiname, args));

View File

@@ -57,7 +57,7 @@ public class CallStaticIns extends InstructionDefinition {
args.add(0, stack.pop());
}
GraphTargetItem receiver = stack.pop();
String methodName = localData.methodInfo.get(methodIndex).getName(localData.constants);
String methodName = localData.getMethodInfo().get(methodIndex).getName(localData.getConstants());
stack.push(new CallStaticAVM2Item(ins, receiver, methodName, args));
}

View File

@@ -59,7 +59,7 @@ public class CallSuperIns extends InstructionDefinition {
for (int a = 0; a < argCount; a++) {
args.add(0, stack.pop());
}
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.constants, multinameIndex, ins);
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
GraphTargetItem receiver = stack.pop();
stack.push(new CallSuperAVM2Item(ins, false, receiver, multiname, args));

View File

@@ -59,7 +59,7 @@ public class CallSuperVoidIns extends InstructionDefinition {
for (int a = 0; a < argCount; a++) {
args.add(0, stack.pop());
}
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.constants, multinameIndex, ins);
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
GraphTargetItem receiver = stack.pop();
output.add(new CallSuperAVM2Item(ins, true, receiver, multiname, args));

View File

@@ -41,14 +41,14 @@ public abstract class GetLocalTypeIns extends InstructionDefinition {
int regId = getRegisterId(ins);
if (regId == 0) {
if ((localData.classIndex >= localData.abc.instance_info.size()) || localData.classIndex < 0) {
if ((localData.classIndex >= localData.getInstanceInfo().size()) || localData.classIndex < 0) {
stack.push(new ScriptAVM2Item(localData.scriptIndex));
return;
}
if (localData.isStatic) {
stack.push(new ClassAVM2Item(localData.abc.instance_info.get(localData.classIndex).getName(localData.constants)));
stack.push(new ClassAVM2Item(localData.getInstanceInfo().get(localData.classIndex).getName(localData.getConstants())));
} else {
stack.push(new ThisAVM2Item(ins, localData.abc.instance_info.get(localData.classIndex).getName(localData.constants)));
stack.push(new ThisAVM2Item(ins, localData.getInstanceInfo().get(localData.classIndex).getName(localData.getConstants())));
}
return;
}

View File

@@ -48,7 +48,7 @@ public class DeletePropertyIns extends InstructionDefinition {
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
int multinameIndex = ins.operands[0];
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.constants, multinameIndex, ins);
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
GraphTargetItem obj = stack.pop();
//stack.add(new BooleanAVM2Item(ins, Boolean.TRUE));//property successfully deleted
stack.add(new DeletePropertyAVM2Item(ins, obj, multiname));

View File

@@ -36,7 +36,7 @@ public class FindDefIns extends InstructionDefinition {
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
int multinameIndex = ins.operands[0];
Multiname multiname = localData.constants.getMultiname(multinameIndex);
Multiname multiname = localData.getConstants().getMultiname(multinameIndex);
stack.push(new FindDefAVM2Item(ins, multiname));
}

View File

@@ -47,7 +47,7 @@ public class FindPropertyIns extends InstructionDefinition {
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
int multinameIndex = ins.operands[0];
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.constants, multinameIndex, ins);
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
stack.push(new FindPropertyAVM2Item(ins, multiname)); //resolve right object
}

View File

@@ -46,7 +46,7 @@ public class FindPropertyStrictIns extends InstructionDefinition {
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
int multinameIndex = ins.operands[0];
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.constants, multinameIndex, ins);
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
stack.push(new FindPropertyAVM2Item(ins, multiname));
}

View File

@@ -47,7 +47,7 @@ public class GetDescendantsIns extends InstructionDefinition {
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
int multinameIndex = ins.operands[0];
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.constants, multinameIndex, ins);
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
GraphTargetItem obj = stack.pop();
stack.push(new GetDescendantsAVM2Item(ins, obj, multiname));
}

View File

@@ -45,7 +45,7 @@ public class GetGlobalScopeIns extends InstructionDefinition {
if (localData.classIndex == -1) {
stack.push(new ScriptAVM2Item(localData.scriptIndex));
} else {
stack.push(new ClassAVM2Item(localData.abc.instance_info.get(localData.classIndex).getName(localData.constants)));
stack.push(new ClassAVM2Item(localData.getInstanceInfo().get(localData.classIndex).getName(localData.getConstants())));
}
return;
}

View File

@@ -43,7 +43,7 @@ public class GetGlobalSlotIns extends InstructionDefinition {
GraphTargetItem obj = localData.scopeStack.get(0); //scope
Multiname slotname = null;
if (obj instanceof ExceptionAVM2Item) {
slotname = localData.constants.getMultiname(((ExceptionAVM2Item) obj).exception.name_index);
slotname = localData.getConstants().getMultiname(((ExceptionAVM2Item) obj).exception.name_index);
} else {
MethodBody body = localData.methodBody;
List<Trait> traits = body.traits.traits;

View File

@@ -36,7 +36,7 @@ public class GetLexIns extends InstructionDefinition {
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
int multinameIndex = ins.operands[0];
Multiname multiname = localData.constants.getMultiname(multinameIndex);
Multiname multiname = localData.getConstants().getMultiname(multinameIndex);
stack.push(new GetLexAVM2Item(ins, multiname));
}

View File

@@ -36,7 +36,7 @@ public class GetPropertyIns extends InstructionDefinition {
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
int multinameIndex = ins.operands[0];
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.constants, multinameIndex, ins);
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
GraphTargetItem obj = stack.pop();
stack.push(new GetPropertyAVM2Item(ins, obj, multiname));
}

View File

@@ -48,13 +48,13 @@ public class GetSlotIns extends InstructionDefinition {
obj = obj.getThroughRegister();
Multiname slotname = null;
if (obj instanceof ExceptionAVM2Item) {
slotname = localData.constants.getMultiname(((ExceptionAVM2Item) obj).exception.name_index);
slotname = localData.getConstants().getMultiname(((ExceptionAVM2Item) obj).exception.name_index);
} else if (obj instanceof ClassAVM2Item) {
slotname = ((ClassAVM2Item) obj).className;
} else if (obj instanceof ThisAVM2Item) {
slotname = ((ThisAVM2Item) obj).className;
} else if (obj instanceof ScriptAVM2Item) {
List<Trait> traits = localData.abc.script_info.get(((ScriptAVM2Item) obj).scriptIndex).traits.traits;
List<Trait> traits = localData.getScriptInfo().get(((ScriptAVM2Item) obj).scriptIndex).traits.traits;
for (int t = 0; t < traits.size(); t++) {
Trait tr = traits.get(t);
if (tr instanceof TraitWithSlot) {

View File

@@ -36,7 +36,7 @@ public class GetSuperIns extends InstructionDefinition {
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
int multinameIndex = ins.operands[0];
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.constants, multinameIndex, ins);
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
GraphTargetItem obj = stack.pop();
stack.push(new GetSuperAVM2Item(ins, obj, multiname));
}

View File

@@ -38,7 +38,7 @@ public class InitPropertyIns extends InstructionDefinition {
int multinameIndex = ins.operands[0];
GraphTargetItem val = stack.pop();
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.constants, multinameIndex, ins);
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
GraphTargetItem obj = stack.pop();
output.add(new InitPropertyAVM2Item(ins, obj, multiname, val));
}

View File

@@ -55,7 +55,7 @@ public class SetPropertyIns extends InstructionDefinition implements SetTypeIns
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
int multinameIndex = ins.operands[0];
GraphTargetItem value = stack.pop();
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.constants, multinameIndex, ins);
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
GraphTargetItem obj = stack.pop();
if (value.getThroughDuplicate().getThroughRegister().getThroughDuplicate() instanceof IncrementAVM2Item) {
GraphTargetItem inside = ((IncrementAVM2Item) value.getThroughDuplicate().getThroughRegister().getThroughDuplicate()).value.getThroughRegister().getNotCoerced().getThroughDuplicate();

View File

@@ -68,13 +68,13 @@ public class SetSlotIns extends InstructionDefinition implements SetTypeIns {
}
if (obj instanceof ExceptionAVM2Item) {
slotname = localData.constants.getMultiname(((ExceptionAVM2Item) obj).exception.name_index);
slotname = localData.getConstants().getMultiname(((ExceptionAVM2Item) obj).exception.name_index);
} else if (obj instanceof ClassAVM2Item) {
slotname = ((ClassAVM2Item) obj).className;
} else if (obj instanceof ThisAVM2Item) {
slotname = ((ThisAVM2Item) obj).className;
} else if (obj instanceof ScriptAVM2Item) {
List<Trait> traits = localData.abc.script_info.get(((ScriptAVM2Item) obj).scriptIndex).traits.traits;
List<Trait> traits = localData.getScriptInfo().get(((ScriptAVM2Item) obj).scriptIndex).traits.traits;
for (int t = 0; t < traits.size(); t++) {
Trait tr = traits.get(t);
if (tr instanceof TraitWithSlot) {
@@ -100,7 +100,7 @@ public class SetSlotIns extends InstructionDefinition implements SetTypeIns {
if (slotname != null) {
if (value instanceof LocalRegAVM2Item) {
LocalRegAVM2Item lr = (LocalRegAVM2Item) value;
String slotNameStr = slotname.getName(localData.constants, localData.fullyQualifiedNames, true);
String slotNameStr = slotname.getName(localData.getConstants(), localData.fullyQualifiedNames, true);
if (localData.localRegNames.containsKey(lr.regIndex)) {
if (localData.localRegNames.get(lr.regIndex).equals(slotNameStr)) {
return; //Register with same name to slot

View File

@@ -47,7 +47,7 @@ public class SetSuperIns extends InstructionDefinition implements SetTypeIns {
int multinameIndex = ins.operands[0];
GraphTargetItem value = stack.pop();
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.constants, multinameIndex, ins);
FullMultinameAVM2Item multiname = resolveMultiname(stack, localData.getConstants(), multinameIndex, ins);
GraphTargetItem obj = stack.pop();
output.add(new SetSuperAVM2Item(ins, value, obj, multiname));
}

View File

@@ -41,7 +41,7 @@ public class PushDoubleIns extends InstructionDefinition {
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
stack.push(new FloatValueAVM2Item(ins, localData.constants.getDouble(ins.operands[0])));
stack.push(new FloatValueAVM2Item(ins, localData.getConstants().getDouble(ins.operands[0])));
}
@Override

View File

@@ -41,7 +41,7 @@ public class PushIntIns extends InstructionDefinition implements PushIntegerType
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
stack.push(new IntegerValueAVM2Item(ins, localData.constants.getInt(ins.operands[0])));
stack.push(new IntegerValueAVM2Item(ins, localData.getConstants().getInt(ins.operands[0])));
}
@Override

View File

@@ -41,7 +41,7 @@ public class PushStringIns extends InstructionDefinition {
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
stack.push(new StringAVM2Item(ins, localData.constants.getString(ins.operands[0])));
stack.push(new StringAVM2Item(ins, localData.getConstants().getString(ins.operands[0])));
}
@Override

View File

@@ -41,7 +41,7 @@ public class PushUIntIns extends InstructionDefinition implements PushIntegerTyp
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
stack.push(new IntegerValueAVM2Item(ins, localData.constants.getUInt(ins.operands[0])));
stack.push(new IntegerValueAVM2Item(ins, localData.getConstants().getUInt(ins.operands[0])));
}
@Override

View File

@@ -45,7 +45,7 @@ public class CoerceAIns extends InstructionDefinition implements CoerceOrConvert
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
stack.push(new CoerceAVM2Item(ins, stack.pop(), getTargetType(localData.constants, ins)));
stack.push(new CoerceAVM2Item(ins, stack.pop(), getTargetType(localData.getConstants(), ins)));
}

View File

@@ -44,7 +44,7 @@ public class CoerceIns extends InstructionDefinition implements CoerceOrConvertT
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
int multinameIndex = ins.operands[0];
stack.push(new CoerceAVM2Item(ins, stack.pop(), PropertyAVM2Item.multinameToType(multinameIndex, localData.constants)));
stack.push(new CoerceAVM2Item(ins, stack.pop(), PropertyAVM2Item.multinameToType(multinameIndex, localData.getConstants())));
}
@Override

View File

@@ -43,7 +43,7 @@ public class CoerceSIns extends InstructionDefinition implements CoerceOrConvert
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
stack.push(new CoerceAVM2Item(ins, stack.pop(), getTargetType(localData.constants, ins)));
stack.push(new CoerceAVM2Item(ins, stack.pop(), getTargetType(localData.getConstants(), ins)));
}
@Override

View File

@@ -53,7 +53,7 @@ public class ConvertBIns extends InstructionDefinition implements CoerceOrConver
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
stack.push(new ConvertAVM2Item(ins, stack.pop(), getTargetType(localData.constants, ins)));
stack.push(new ConvertAVM2Item(ins, stack.pop(), getTargetType(localData.getConstants(), ins)));
}
@Override

View File

@@ -61,7 +61,7 @@ public class ConvertDIns extends InstructionDefinition implements CoerceOrConver
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
stack.push(new ConvertAVM2Item(ins, stack.pop(), getTargetType(localData.constants, ins)));
stack.push(new ConvertAVM2Item(ins, stack.pop(), getTargetType(localData.getConstants(), ins)));
}
@Override

View File

@@ -59,7 +59,7 @@ public class ConvertIIns extends InstructionDefinition implements CoerceOrConver
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
stack.push(new ConvertAVM2Item(ins, stack.pop(), getTargetType(localData.constants, ins)));
stack.push(new ConvertAVM2Item(ins, stack.pop(), getTargetType(localData.getConstants(), ins)));
}
@Override

View File

@@ -42,7 +42,7 @@ public class ConvertOIns extends InstructionDefinition implements CoerceOrConver
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
stack.push(new ConvertAVM2Item(ins, stack.pop(), getTargetType(localData.constants, ins)));
stack.push(new ConvertAVM2Item(ins, stack.pop(), getTargetType(localData.getConstants(), ins)));
}
@Override

View File

@@ -43,7 +43,7 @@ public class ConvertSIns extends InstructionDefinition implements CoerceOrConver
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
stack.push(new ConvertAVM2Item(ins, stack.pop(), getTargetType(localData.constants, ins)));
stack.push(new ConvertAVM2Item(ins, stack.pop(), getTargetType(localData.getConstants(), ins)));
}
@Override

View File

@@ -42,7 +42,7 @@ public class ConvertUIns extends InstructionDefinition implements CoerceOrConver
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
stack.push(new ConvertAVM2Item(ins, stack.pop(), getTargetType(localData.constants, ins)));
stack.push(new ConvertAVM2Item(ins, stack.pop(), getTargetType(localData.getConstants(), ins)));
}
@Override

View File

@@ -45,6 +45,6 @@ public class DXNSIns extends InstructionDefinition {
@Override
public void translate(AVM2LocalData localData, TranslateStack stack, AVM2Instruction ins, List<GraphTargetItem> output, String path) {
//FIXME!!! - search namespace
output.add(new DefaultXMLNamespace(ins, new StringAVM2Item(ins, localData.constants.getString(ins.operands[0]))));
output.add(new DefaultXMLNamespace(ins, new StringAVM2Item(ins, localData.getConstants().getString(ins.operands[0]))));
}
}

View File

@@ -17,10 +17,8 @@
package com.jpexs.decompiler.flash.abc.avm2.model;
import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.avm2.AVM2ConstantPool;
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.exporters.modes.ScriptExportMode;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
@@ -48,13 +46,9 @@ public class NewFunctionAVM2Item extends AVM2Item {
public List<DottedChain> fullyQualifiedNames;
public AVM2ConstantPool constants;
public List<MethodInfo> methodInfo;
public int methodIndex;
public NewFunctionAVM2Item(AVM2Instruction instruction, String functionName, String path, boolean isStatic, int scriptIndex, int classIndex, ABC abc, List<DottedChain> fullyQualifiedNames, AVM2ConstantPool constants, List<MethodInfo> methodInfo, int methodIndex) {
public NewFunctionAVM2Item(AVM2Instruction instruction, String functionName, String path, boolean isStatic, int scriptIndex, int classIndex, ABC abc, List<DottedChain> fullyQualifiedNames, int methodIndex) {
super(instruction, PRECEDENCE_PRIMARY);
this.functionName = functionName;
this.path = path;
@@ -63,8 +57,6 @@ public class NewFunctionAVM2Item extends AVM2Item {
this.classIndex = classIndex;
this.abc = abc;
this.fullyQualifiedNames = fullyQualifiedNames;
this.constants = constants;
this.methodInfo = methodInfo;
this.methodIndex = methodIndex;
}
@@ -75,20 +67,20 @@ public class NewFunctionAVM2Item extends AVM2Item {
writer.startMethod(methodIndex);
writer.append((!functionName.isEmpty() ? " " + functionName : ""));
writer.appendNoHilight("(");
methodInfo.get(methodIndex).getParamStr(writer, constants, body, abc, fullyQualifiedNames);
abc.method_info.get(methodIndex).getParamStr(writer, abc.constants, body, abc, fullyQualifiedNames);
writer.appendNoHilight("):");
if (Configuration.showMethodBodyId.get()) {
writer.appendNoHilight("// method body id: ");
writer.appendNoHilight(abc.findBodyIndex(methodIndex));
writer.newLine();
}
methodInfo.get(methodIndex).getReturnTypeStr(writer, constants, fullyQualifiedNames);
abc.method_info.get(methodIndex).getReturnTypeStr(writer, abc.constants, fullyQualifiedNames);
writer.startBlock();
if (body != null) {
if (writer instanceof NulWriter) {
body.convert(path + "/inner", ScriptExportMode.AS, isStatic, methodIndex, scriptIndex, classIndex, abc, null, constants, methodInfo, new ScopeStack(), 0, (NulWriter) writer, fullyQualifiedNames, null, false);
body.convert(path + "/inner", ScriptExportMode.AS, isStatic, methodIndex, scriptIndex, classIndex, abc, null, new ScopeStack(), 0, (NulWriter) writer, fullyQualifiedNames, null, false);
} else {
body.toString(path + "/inner", ScriptExportMode.AS, abc, null, constants, methodInfo, writer, fullyQualifiedNames);
body.toString(path + "/inner", ScriptExportMode.AS, abc, null, writer, fullyQualifiedNames);
}
}
writer.endBlock();

View File

@@ -178,18 +178,18 @@ public final class MethodBody implements Cloneable {
getCode().restoreControlFlow(constants, trait, info, this);
}
public int removeTraps(AVM2ConstantPool constants, ABC abc, Trait trait, int scriptIndex, int classIndex, boolean isStatic, String path) throws InterruptedException {
public int removeTraps(ABC abc, Trait trait, int scriptIndex, int classIndex, boolean isStatic, String path) throws InterruptedException {
return getCode().removeTraps(constants, trait, abc.method_info.get(method_info), this, abc, scriptIndex, classIndex, isStatic, path);
return getCode().removeTraps(trait, method_info, this, abc, scriptIndex, classIndex, isStatic, path);
}
public void deobfuscate(DeobfuscationLevel level, Trait trait, int scriptIndex, int classIndex, boolean isStatic, String path) throws InterruptedException {
if (level == DeobfuscationLevel.LEVEL_REMOVE_DEAD_CODE) {
removeDeadCode(abc.constants, trait, abc.method_info.get(method_info));
} else if (level == DeobfuscationLevel.LEVEL_REMOVE_TRAPS) {
removeTraps(abc.constants, abc, trait, scriptIndex, classIndex, isStatic, path);
removeTraps(abc, trait, scriptIndex, classIndex, isStatic, path);
} else if (level == DeobfuscationLevel.LEVEL_RESTORE_CONTROL_FLOW) {
removeTraps(abc.constants, abc, trait, scriptIndex, classIndex, isStatic, path);
removeTraps(abc, trait, scriptIndex, classIndex, isStatic, path);
restoreControlFlow(abc.constants, trait, abc.method_info.get(method_info));
}
}
@@ -276,12 +276,12 @@ public final class MethodBody implements Cloneable {
return ret;
}
public void convert(final String path, ScriptExportMode exportMode, final boolean isStatic, final int methodIndex, final int scriptIndex, final int classIndex, final ABC abc, final Trait trait, final AVM2ConstantPool constants, final List<MethodInfo> method_info, final ScopeStack scopeStack, final int initializerType, final NulWriter writer, final List<DottedChain> fullyQualifiedNames, final List<Traits> initTraits, boolean firstLevel) throws InterruptedException {
public void convert(final String path, ScriptExportMode exportMode, final boolean isStatic, final int methodIndex, final int scriptIndex, final int classIndex, final ABC abc, final Trait trait, final ScopeStack scopeStack, final int initializerType, final NulWriter writer, final List<DottedChain> fullyQualifiedNames, final List<Traits> initTraits, boolean firstLevel) throws InterruptedException {
if (debugMode) {
System.err.println("Decompiling " + path);
}
if (exportMode != ScriptExportMode.AS) {
getCode().toASMSource(constants, trait, method_info.get(this.method_info), this, exportMode, writer);
getCode().toASMSource(abc.constants, trait, abc.method_info.get(this.method_info), this, exportMode, writer);
} else {
if ((DEBUG_FIXED != null && !path.endsWith(DEBUG_FIXED)) || (!Configuration.decompile.get())) {
writer.appendNoHilight(Helper.getDecompilationSkippedComment()).newLine();
@@ -294,14 +294,14 @@ public final class MethodBody implements Cloneable {
@Override
public Void call() throws InterruptedException {
try (Statistics s1 = new Statistics("MethodBody.convert")) {
MethodBody converted = convertMethodBody(path, isStatic, scriptIndex, classIndex, abc, trait, constants, method_info, scopeStack, initializerType != GraphTextWriter.TRAIT_INSTANCE_INITIALIZER, fullyQualifiedNames, initTraits);
MethodBody converted = convertMethodBody(path, isStatic, scriptIndex, classIndex, abc, trait, scopeStack, initializerType != GraphTextWriter.TRAIT_INSTANCE_INITIALIZER, fullyQualifiedNames, initTraits);
HashMap<Integer, String> localRegNames = getLocalRegNames(abc);
List<GraphTargetItem> convertedItems1;
try (Statistics s = new Statistics("AVM2Code.toGraphTargetItems")) {
convertedItems1 = converted.getCode().toGraphTargetItems(path, methodIndex, isStatic, scriptIndex, classIndex, abc, constants, method_info, converted, localRegNames, scopeStack, initializerType, fullyQualifiedNames, initTraits, Graph.SOP_USE_STATIC, new HashMap<>(), converted.getCode().visitCode(converted));
convertedItems1 = converted.getCode().toGraphTargetItems(path, methodIndex, isStatic, scriptIndex, classIndex, abc, converted, localRegNames, scopeStack, initializerType, fullyQualifiedNames, initTraits, Graph.SOP_USE_STATIC, new HashMap<>(), converted.getCode().visitCode(converted));
}
try (Statistics s = new Statistics("Graph.graphToString")) {
Graph.graphToString(convertedItems1, writer, LocalData.create(constants, localRegNames, fullyQualifiedNames));
Graph.graphToString(convertedItems1, writer, LocalData.create(abc.constants, localRegNames, fullyQualifiedNames));
}
convertedItems = convertedItems1;
}
@@ -330,9 +330,9 @@ public final class MethodBody implements Cloneable {
}
}
public GraphTextWriter toString(final String path, ScriptExportMode exportMode, final ABC abc, final Trait trait, final AVM2ConstantPool constants, final List<MethodInfo> method_info, final GraphTextWriter writer, final List<DottedChain> fullyQualifiedNames) throws InterruptedException {
public GraphTextWriter toString(final String path, ScriptExportMode exportMode, final ABC abc, final Trait trait, final GraphTextWriter writer, final List<DottedChain> fullyQualifiedNames) throws InterruptedException {
if (exportMode != ScriptExportMode.AS) {
getCode().toASMSource(constants, trait, method_info.get(this.method_info), this, exportMode, writer);
getCode().toASMSource(abc.constants, trait, abc.method_info.get(this.method_info), this, exportMode, writer);
} else {
if ((DEBUG_FIXED != null && !path.endsWith(DEBUG_FIXED)) || (!Configuration.decompile.get())) {
//writer.startMethod(this.method_info);
@@ -351,7 +351,7 @@ public final class MethodBody implements Cloneable {
writer.appendNoHilight(abc.findBodyIndex(this.method_info));
writer.newLine();
}
Graph.graphToString(convertedItems, writer, LocalData.create(constants, localRegNames, fullyQualifiedNames));
Graph.graphToString(convertedItems, writer, LocalData.create(abc.constants, localRegNames, fullyQualifiedNames));
//writer.endMethod();
} else if (convertException instanceof TimeoutException) {
// exception was logged in convert method
@@ -365,7 +365,7 @@ public final class MethodBody implements Cloneable {
return writer;
}
public MethodBody convertMethodBody(String path, boolean isStatic, int scriptIndex, int classIndex, ABC abc, Trait trait, AVM2ConstantPool constants, List<MethodInfo> method_info, ScopeStack scopeStack, boolean isStaticInitializer, List<DottedChain> fullyQualifiedNames, List<Traits> initTraits) throws InterruptedException {
public MethodBody convertMethodBody(String path, boolean isStatic, int scriptIndex, int classIndex, ABC abc, Trait trait, ScopeStack scopeStack, boolean isStaticInitializer, List<DottedChain> fullyQualifiedNames, List<Traits> initTraits) throws InterruptedException {
MethodBody body = clone();
AVM2Code code = body.getCode();
code.markMappedOffsets();
@@ -373,7 +373,7 @@ public final class MethodBody implements Cloneable {
if (Configuration.autoDeobfuscate.get()) {
try {
code.removeTraps(constants, trait, method_info.get(this.method_info), body, abc, scriptIndex, classIndex, isStatic, path);
code.removeTraps(trait, method_info, body, abc, scriptIndex, classIndex, isStatic, path);
} catch (ThreadDeath | InterruptedException ex) {
throw ex;
} catch (Throwable ex) {

View File

@@ -470,7 +470,7 @@ public class TraitClass extends Trait implements TraitWithSlot {
writer.startMethod(classInfo.cinit_index);
if (!classInitializerIsEmpty) {
writer.startBlock();
abc.bodies.get(bodyIndex).toString(path +/*packageName +*/ "/" + instanceInfoName + ".staticinitializer", exportMode, abc, this, abc.constants, abc.method_info, writer, fullyQualifiedNames);
abc.bodies.get(bodyIndex).toString(path +/*packageName +*/ "/" + instanceInfoName + ".staticinitializer", exportMode, abc, this, writer, fullyQualifiedNames);
writer.endBlock();
} else {
//Note: There must be trait/method highlight even if the initializer is empty to TraitList in GUI to work correctly
@@ -518,7 +518,7 @@ public class TraitClass extends Trait implements TraitWithSlot {
abc.method_info.get(instanceInfo.iinit_index).getParamStr(writer, abc.constants, body, abc, fullyQualifiedNames);
writer.appendNoHilight(")").startBlock();
if (body != null) {
body.toString(path +/*packageName +*/ "/" + instanceInfoName + ".initializer", exportMode, abc, this, abc.constants, abc.method_info, writer, fullyQualifiedNames);
body.toString(path +/*packageName +*/ "/" + instanceInfoName + ".initializer", exportMode, abc, this, writer, fullyQualifiedNames);
}
writer.endBlock().newLine();
@@ -553,7 +553,7 @@ public class TraitClass extends Trait implements TraitWithSlot {
writer.mark();
List<Traits> ts = new ArrayList<>();
ts.add(classInfo.static_traits);
abc.bodies.get(bodyIndex).convert(path +/*packageName +*/ "/" + instanceInfoName + ".staticinitializer", exportMode, true, classInfo.cinit_index, scriptIndex, class_info, abc, this, abc.constants, abc.method_info, new ScopeStack(), GraphTextWriter.TRAIT_CLASS_INITIALIZER, writer, fullyQualifiedNames, ts, true);
abc.bodies.get(bodyIndex).convert(path +/*packageName +*/ "/" + instanceInfoName + ".staticinitializer", exportMode, true, classInfo.cinit_index, scriptIndex, class_info, abc, this, new ScopeStack(), GraphTextWriter.TRAIT_CLASS_INITIALIZER, writer, fullyQualifiedNames, ts, true);
classInitializerIsEmpty = !writer.getMark();
}
@@ -563,7 +563,7 @@ public class TraitClass extends Trait implements TraitWithSlot {
if (bodyIndex != -1) {
List<Traits> ts = new ArrayList<>();
ts.add(instanceInfo.instance_traits);
abc.bodies.get(bodyIndex).convert(path +/*packageName +*/ "/" + instanceInfoName + ".initializer", exportMode, false, instanceInfo.iinit_index, scriptIndex, class_info, abc, this, abc.constants, abc.method_info, new ScopeStack(), GraphTextWriter.TRAIT_INSTANCE_INITIALIZER, writer, fullyQualifiedNames, ts, true);
abc.bodies.get(bodyIndex).convert(path +/*packageName +*/ "/" + instanceInfoName + ".initializer", exportMode, false, instanceInfo.iinit_index, scriptIndex, class_info, abc, this, new ScopeStack(), GraphTextWriter.TRAIT_INSTANCE_INITIALIZER, writer, fullyQualifiedNames, ts, true);
}
}
@@ -585,11 +585,11 @@ public class TraitClass extends Trait implements TraitWithSlot {
int iInitializer = abc.findBodyIndex(instanceInfo.iinit_index);
int ret = 0;
if (iInitializer != -1) {
ret += abc.bodies.get(iInitializer).removeTraps(abc.constants, abc, this, scriptIndex, class_info, false, path);
ret += abc.bodies.get(iInitializer).removeTraps(abc, this, scriptIndex, class_info, false, path);
}
int sInitializer = abc.findBodyIndex(classInfo.cinit_index);
if (sInitializer != -1) {
ret += abc.bodies.get(sInitializer).removeTraps(abc.constants, abc, this, scriptIndex, class_info, true, path);
ret += abc.bodies.get(sInitializer).removeTraps(abc, this, scriptIndex, class_info, true, path);
}
ret += instanceInfo.instance_traits.removeTraps(scriptIndex, class_info, false, abc, path);
ret += classInfo.static_traits.removeTraps(scriptIndex, class_info, true, abc, path);

View File

@@ -80,7 +80,7 @@ public class TraitFunction extends Trait implements TraitWithSlot {
writer.appendNoHilight(" {").newLine();
int bodyIndex = abc.findBodyIndex(method_info);
if (bodyIndex != -1) {
abc.bodies.get(bodyIndex).toString(path + "." + abc.constants.getMultiname(name_index).getName(abc.constants, fullyQualifiedNames, false), exportMode, abc, this, abc.constants, abc.method_info, writer, fullyQualifiedNames);
abc.bodies.get(bodyIndex).toString(path + "." + abc.constants.getMultiname(name_index).getName(abc.constants, fullyQualifiedNames, false), exportMode, abc, this, writer, fullyQualifiedNames);
}
writer.newLine();
writer.appendNoHilight("}");
@@ -97,7 +97,7 @@ public class TraitFunction extends Trait implements TraitWithSlot {
if (!abc.instance_info.get(classIndex).isInterface()) {
int bodyIndex = abc.findBodyIndex(method_info);
if (bodyIndex != -1) {
abc.bodies.get(bodyIndex).convert(path + "." + abc.constants.getMultiname(name_index).getName(abc.constants, fullyQualifiedNames, false), exportMode, isStatic, method_info, scriptIndex, classIndex, abc, this, abc.constants, abc.method_info, new ScopeStack(), 0, writer, fullyQualifiedNames, null, true);
abc.bodies.get(bodyIndex).convert(path + "." + abc.constants.getMultiname(name_index).getName(abc.constants, fullyQualifiedNames, false), exportMode, isStatic, method_info, scriptIndex, classIndex, abc, this, new ScopeStack(), 0, writer, fullyQualifiedNames, null, true);
}
}
writer.endMethod();
@@ -107,7 +107,7 @@ public class TraitFunction extends Trait implements TraitWithSlot {
public int removeTraps(int scriptIndex, int classIndex, boolean isStatic, ABC abc, String path) throws InterruptedException {
int bodyIndex = abc.findBodyIndex(method_info);
if (bodyIndex != -1) {
return abc.bodies.get(bodyIndex).removeTraps(abc.constants, abc, this, scriptIndex, classIndex, isStatic, path);
return abc.bodies.get(bodyIndex).removeTraps(abc, this, scriptIndex, classIndex, isStatic, path);
}
return 0;
}

View File

@@ -81,7 +81,7 @@ public class TraitMethodGetterSetter extends Trait {
int bodyIndex = abc.findBodyIndex(method_info);
if (!(classIndex != -1 && abc.instance_info.get(classIndex).isInterface() || bodyIndex == -1)) {
if (bodyIndex != -1) {
abc.bodies.get(bodyIndex).convert(path, exportMode, isStatic, method_info, scriptIndex, classIndex, abc, this, abc.constants, abc.method_info, new ScopeStack(), 0, writer, fullyQualifiedNames, null, true);
abc.bodies.get(bodyIndex).convert(path, exportMode, isStatic, method_info, scriptIndex, classIndex, abc, this, new ScopeStack(), 0, writer, fullyQualifiedNames, null, true);
}
}
writer.endMethod();
@@ -99,7 +99,7 @@ public class TraitMethodGetterSetter extends Trait {
} else {
writer.startBlock();
if (bodyIndex != -1) {
abc.bodies.get(bodyIndex).toString(path, exportMode, abc, this, abc.constants, abc.method_info, writer, fullyQualifiedNames);
abc.bodies.get(bodyIndex).toString(path, exportMode, abc, this, writer, fullyQualifiedNames);
}
writer.endBlock();
}
@@ -112,7 +112,7 @@ public class TraitMethodGetterSetter extends Trait {
public int removeTraps(int scriptIndex, int classIndex, boolean isStatic, ABC abc, String path) throws InterruptedException {
int bodyIndex = abc.findBodyIndex(method_info);
if (bodyIndex != -1) {
return abc.bodies.get(bodyIndex).removeTraps(abc.constants, abc, this, scriptIndex, classIndex, isStatic, path);
return abc.bodies.get(bodyIndex).removeTraps(abc, this, scriptIndex, classIndex, isStatic, path);
}
return 0;
}

View File

@@ -21,6 +21,7 @@ import com.jpexs.decompiler.flash.BaseLocalData;
import com.jpexs.decompiler.flash.DisassemblyListener;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.SWFOutputStream;
import com.jpexs.decompiler.flash.action.deobfuscation.ActionDeobfuscatorSimpleFast;
import com.jpexs.decompiler.flash.action.model.ActionItem;
import com.jpexs.decompiler.flash.action.model.ConstantPool;
import com.jpexs.decompiler.flash.action.model.DirectValueActionItem;
@@ -64,6 +65,7 @@ import com.jpexs.decompiler.flash.helpers.CodeFormatting;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
import com.jpexs.decompiler.flash.helpers.NulWriter;
import com.jpexs.decompiler.flash.helpers.SWFDecompilerPlugin;
import com.jpexs.decompiler.flash.helpers.collections.MyEntry;
import com.jpexs.decompiler.flash.tags.base.ASMSource;
import com.jpexs.decompiler.graph.Graph;
@@ -817,13 +819,20 @@ public abstract class Action implements GraphSourceItem {
List<GraphTargetItem> tree = null;
Throwable convertException = null;
int timeout = Configuration.decompilationTimeoutSingleMethod.get();
final int version = asm == null ? SWF.DEFAULT_VERSION : asm.getSwf().version;
final SWF swf = asm == null ? null : asm.getSwf();
final int version = swf == null ? SWF.DEFAULT_VERSION : swf.version;
try {
tree = CancellableWorker.call(new Callable<List<GraphTargetItem>>() {
@Override
public List<GraphTargetItem> call() throws Exception {
int staticOperation = Graph.SOP_USE_STATIC; //(Boolean) Configuration.getConfig("autoDeobfuscate", true) ? Graph.SOP_SKIP_STATIC : Graph.SOP_USE_STATIC;
List<GraphTargetItem> tree = actionsToTree(new HashMap<>(), new HashMap<>(), new HashMap<>(), actions, version, staticOperation, path);
SWFDecompilerPlugin.fireActionTreeCreated(tree, swf);
int deobfuscationMode = Configuration.autoDeobfuscate.get() ? (Configuration.deobfuscationOldMode.get() ? 0 : 1) : -1;
if (deobfuscationMode == 1) {
new ActionDeobfuscatorSimpleFast().actionTreeCreated(tree, swf);
}
Graph.graphToString(tree, new NulWriter(), new LocalData());
return tree;
}

View File

@@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.action.deobfuscation;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.ActionList;
import com.jpexs.decompiler.flash.action.ActionLocalData;
@@ -419,6 +420,10 @@ public class ActionDeobfuscatorSimple implements SWFDecompilerListener {
public void methodBodyParsed(MethodBody body, SWF swf) {
}
@Override
public void avm2CodeRemoveTraps(String path, int classIndex, boolean isStatic, int scriptIndex, ABC abc, Trait trait, int methodInfo, MethodBody body) throws InterruptedException {
}
class ExecutionResult {
public int idx = -1;

View File

@@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.action.deobfuscation;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.traits.Trait;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.ActionList;
import com.jpexs.decompiler.flash.action.ActionListReader;
@@ -652,6 +653,10 @@ public class ActionDeobfuscatorSimpleFast implements SWFDecompilerListener {
public void methodBodyParsed(MethodBody body, SWF swf) {
}
@Override
public void avm2CodeRemoveTraps(String path, int classIndex, boolean isStatic, int scriptIndex, ABC abc, Trait trait, int methodInfo, MethodBody body) throws InterruptedException {
}
class ExecutionResult {
public ActionItem item = null;

View File

@@ -176,8 +176,8 @@ public class DirectValueActionItem extends ActionItem implements SimpleValue {
if (value instanceof RegisterNumber) {
return writer.append(((RegisterNumber) value).translate());
}
return writer.append(value.toString());
//return writer.append(EcmaScript.toString(value, true)); // todo, use this line
//return writer.append(value.toString());
return writer.append(EcmaScript.toString(value, true)); // todo, use this line
}
@Override

View File

@@ -64,7 +64,7 @@ public class GetVariableActionItem extends ActionItem {
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
if (((name instanceof DirectValueActionItem)) && (((DirectValueActionItem) name).isString()) && (!IdentifiersDeobfuscation.isValidName(false, ((DirectValueActionItem) name).toStringNoQuotes(localData), "this", "super"))) {
if (((name instanceof DirectValueActionItem)) && (((DirectValueActionItem) name).isString()) && (!IdentifiersDeobfuscation.isValidNameWithDot(false, ((DirectValueActionItem) name).toStringNoQuotes(localData), "this", "super"))) {
return IdentifiersDeobfuscation.appendObfuscatedIdentifier(((DirectValueActionItem) name).toStringNoQuotes(localData), writer);
} else if ((!(name instanceof DirectValueActionItem)) || (!((DirectValueActionItem) name).isString())) {
writer.append("eval(");

View File

@@ -85,7 +85,7 @@ public class ActionIf extends Action {
@Override
public String getASMSource(ActionList container, Set<Long> knownAddreses, ScriptExportMode exportMode) {
long address = getAddress() + getTotalActionLength() + offset;
long address = getTargetAddress();
String ofsStr = Helper.formatAddress(address);
return "If loc" + ofsStr + (!jumpUsed ? " ;compileTimeIgnore" : (!ignoreUsed ? " ;compileTimeJump" : ""));
}

View File

@@ -85,7 +85,7 @@ public class ActionJump extends Action {
@Override
public String getASMSource(ActionList container, Set<Long> knownAddreses, ScriptExportMode exportMode) {
long address = getAddress() + getTotalActionLength() + offset;
long address = getTargetAddress();
String ofsStr = Helper.formatAddress(address);
return "Jump loc" + ofsStr;
}

View File

@@ -19,6 +19,7 @@ package com.jpexs.decompiler.flash.helpers;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.abc.ABC;
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.graph.GraphTargetItem;
import java.util.List;
@@ -40,4 +41,7 @@ public interface SWFDecompilerListener {
void abcParsed(ABC abc, SWF swf);
void methodBodyParsed(MethodBody body, SWF swf);
// this method is only called when deobfuscation is enabled and new deobfuscation mode is selected
void avm2CodeRemoveTraps(String path, int classIndex, boolean isStatic, int scriptIndex, ABC abc, Trait trait, int methodInfo, MethodBody body) throws InterruptedException;
}

View File

@@ -19,8 +19,11 @@ package com.jpexs.decompiler.flash.helpers;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.abc.ABC;
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.graph.GraphTargetItem;
import com.jpexs.helpers.Helper;
import com.jpexs.helpers.Path;
import com.jpexs.helpers.plugin.CharSequenceJavaFileObject;
import com.jpexs.helpers.plugin.ClassFileManager;
import java.util.ArrayList;
@@ -43,6 +46,18 @@ public class SWFDecompilerPlugin {
private static final List<SWFDecompilerListener> listeners = new ArrayList<>();
public static void loadPlugin(String path) {
if (".class".equals(Path.getExtension(path))) {
loadPluginCompiled(path);
} else {
loadPluginSource(path);
}
}
private static void loadPluginCompiled(String path) {
}
private static void loadPluginSource(String path) {
// Here we specify the source code of the class to be compiled
String src = Helper.readTextFile(path);
@@ -90,6 +105,8 @@ public class SWFDecompilerPlugin {
result = newResult;
data = newResult;
}
} catch (ThreadDeath ex) {
throw ex;
} catch (Throwable e) {
logger.log(Level.SEVERE, "Failed to call plugin method proxyFileCatched.", e);
}
@@ -101,6 +118,8 @@ public class SWFDecompilerPlugin {
for (SWFDecompilerListener listener : listeners) {
try {
listener.swfParsed(swf);
} catch (ThreadDeath ex) {
throw ex;
} catch (Throwable e) {
logger.log(Level.SEVERE, "Failed to call plugin method swfParsed.", e);
}
@@ -108,10 +127,12 @@ public class SWFDecompilerPlugin {
return !listeners.isEmpty();
}
public static boolean fireActionListParsed(ActionList actions, SWF swf) {
public static boolean fireActionListParsed(ActionList actions, SWF swf) throws InterruptedException {
for (SWFDecompilerListener listener : listeners) {
try {
listener.actionListParsed(actions, swf);
} catch (ThreadDeath | InterruptedException ex) {
throw ex;
} catch (Throwable e) {
logger.log(Level.SEVERE, "Failed to call plugin method actionListParsed.", e);
}
@@ -119,10 +140,25 @@ public class SWFDecompilerPlugin {
return !listeners.isEmpty();
}
public static boolean fireActionTreeCreated(List<GraphTargetItem> tree, SWF swf) throws InterruptedException {
for (SWFDecompilerListener listener : listeners) {
try {
listener.actionTreeCreated(tree, swf);
} catch (ThreadDeath | InterruptedException ex) {
throw ex;
} catch (Throwable e) {
logger.log(Level.SEVERE, "Failed to call plugin method actionTreeCreated.", e);
}
}
return !listeners.isEmpty();
}
public static boolean fireAbcParsed(ABC abc, SWF swf) {
for (SWFDecompilerListener listener : listeners) {
try {
listener.abcParsed(abc, swf);
} catch (ThreadDeath ex) {
throw ex;
} catch (Throwable e) {
logger.log(Level.SEVERE, "Failed to call plugin method abcParsed.", e);
}
@@ -134,10 +170,25 @@ public class SWFDecompilerPlugin {
for (SWFDecompilerListener listener : listeners) {
try {
listener.methodBodyParsed(body, swf);
} catch (ThreadDeath ex) {
throw ex;
} catch (Throwable e) {
logger.log(Level.SEVERE, "Failed to call plugin method methodBodyParsed.", e);
}
}
return !listeners.isEmpty();
}
public static boolean fireAvm2CodeRemoveTraps(String path, int classIndex, boolean isStatic, int scriptIndex, ABC abc, Trait trait, int methodInfo, MethodBody body) throws InterruptedException {
for (SWFDecompilerListener listener : listeners) {
try {
listener.avm2CodeRemoveTraps(path, classIndex, isStatic, scriptIndex, abc, trait, methodInfo, body);
} catch (ThreadDeath | InterruptedException ex) {
throw ex;
} catch (Throwable e) {
logger.log(Level.SEVERE, "Failed to call plugin method abcParsed.", e);
}
}
return !listeners.isEmpty();
}
}