Stack handling improved - no more StackEmptyException

And/Or handling improved
Preprocessor instructions introduced - §§pop,§§push...
This commit is contained in:
Jindra Petřík
2015-06-03 10:10:44 +02:00
parent 8e770dad9f
commit cac19d6cb9
84 changed files with 11171 additions and 11238 deletions

View File

@@ -1736,7 +1736,7 @@ public final class SWF implements SWFContainerItem, Timelined {
private static void getVariables(List<MyEntry<DirectValueActionItem, ConstantPool>> variables, List<GraphSourceItem> functions, HashMap<DirectValueActionItem, ConstantPool> strings, HashMap<DirectValueActionItem, String> usageTypes, ActionGraphSource code, int addr, String path) throws InterruptedException {
ActionLocalData localData = new ActionLocalData();
getVariables(null, localData, new TranslateStack(), new ArrayList<GraphTargetItem>(), code, code.adr2pos(addr), variables, functions, strings, new ArrayList<Integer>(), usageTypes, path);
getVariables(null, localData, new TranslateStack(path), new ArrayList<GraphTargetItem>(), code, code.adr2pos(addr), variables, functions, strings, new ArrayList<Integer>(), usageTypes, path);
}
private List<MyEntry<DirectValueActionItem, ConstantPool>> getVariables(List<MyEntry<DirectValueActionItem, ConstantPool>> variables, HashMap<ASMSource, ActionList> actionsMap, List<GraphSourceItem> functions, HashMap<DirectValueActionItem, ConstantPool> strings, HashMap<DirectValueActionItem, String> usageTypes, ASMSource src, String path) throws InterruptedException {

View File

@@ -27,6 +27,7 @@ import com.jpexs.decompiler.graph.ScopeStack;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
@@ -56,9 +57,10 @@ public class AVM2LocalData extends BaseLocalData {
public ArrayList<ABCException> parsedExceptions;
public ArrayList<Integer> finallyJumps;
public Map<Integer, List<Integer>> finallyJumps;
public ArrayList<Integer> ignoredSwitches;
public Map<Integer, Integer> ignoredSwitches;
public List<Integer> ignoredSwitches2;
public Integer scriptIndex;
@@ -88,6 +90,7 @@ public class AVM2LocalData extends BaseLocalData {
parsedExceptions = localData.parsedExceptions;
finallyJumps = localData.finallyJumps;
ignoredSwitches = localData.ignoredSwitches;
ignoredSwitches2 = localData.ignoredSwitches2;
scriptIndex = localData.scriptIndex;
localRegAssignmentIps = localData.localRegAssignmentIps;
ip = localData.ip;

View File

@@ -282,6 +282,7 @@ import com.jpexs.decompiler.graph.ScopeStack;
import com.jpexs.decompiler.graph.TranslateException;
import com.jpexs.decompiler.graph.TranslateStack;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.decompiler.graph.model.ExitItem;
import com.jpexs.decompiler.graph.model.ScriptEndItem;
import com.jpexs.helpers.Helper;
import java.io.ByteArrayInputStream;
@@ -1243,8 +1244,8 @@ public class AVM2Code implements Cloneable {
if (isKilled(((SetLocalAVM2Item) output.get(i)).regIndex, 0, code.size() - 1)) {
SetLocalAVM2Item lsi = (SetLocalAVM2Item) output.get(i);
if (i + 1 < output.size()) {
if (output.get(i + 1) instanceof ReturnValueAVM2Item) {
ReturnValueAVM2Item rv = (ReturnValueAVM2Item) output.get(i + 1);
if (output.get(i + 1) instanceof ExitItem) {
GraphTargetItem rv = output.get(i + 1);
if (rv.value instanceof LocalRegAVM2Item) {
LocalRegAVM2Item lr = (LocalRegAVM2Item) rv.value;
if (lr.regIndex == lsi.regIndex) {
@@ -1442,7 +1443,7 @@ public class AVM2Code implements Cloneable {
}
}
if (!isKilled(reg, 0, end)) {
GraphTargetItem vx = stack.pop();
GraphTargetItem vx = stack.pop().getThroughDuplicate();
int dupCnt = 1;
for (int i = ip - 1; i >= start; i--) {
if (code.get(i).definition instanceof DupIns) {
@@ -1899,6 +1900,7 @@ public class AVM2Code implements Cloneable {
ret.parsedExceptions = localData.parsedExceptions;
ret.finallyJumps = localData.finallyJumps;
ret.ignoredSwitches = localData.ignoredSwitches;
ret.ignoredSwitches2 = localData.ignoredSwitches2;
ret.scriptIndex = localData.scriptIndex;
ret.localRegAssignmentIps = localData.localRegAssignmentIps;
ret.ip = localData.ip;
@@ -1921,8 +1923,9 @@ public class AVM2Code implements Cloneable {
localData.localRegNames = body.getLocalRegNames(abc);
localData.fullyQualifiedNames = new ArrayList<>();
localData.parsedExceptions = new ArrayList<>();
localData.finallyJumps = new ArrayList<>();
localData.ignoredSwitches = new ArrayList<>();
localData.finallyJumps = new HashMap<>();
localData.ignoredSwitches = new HashMap<>();
localData.ignoredSwitches2 = new ArrayList<>();
localData.scriptIndex = scriptIndex;
localData.localRegAssignmentIps = new HashMap<>();
localData.ip = 0;
@@ -2958,7 +2961,7 @@ public class AVM2Code implements Cloneable {
public static int removeTraps(AVM2ConstantPool constants, Trait trait, MethodInfo info, MethodBody body, AVM2LocalData localData, AVM2GraphSource code, int addr, String path, HashMap<Integer, List<Integer>> refs) throws InterruptedException {
HashMap<AVM2Instruction, AVM2Code.Decision> decisions = new HashMap<>();
removeTraps(refs, false, false, localData, new TranslateStack(), new ArrayList<GraphTargetItem>(), code, code.adr2pos(addr), new HashMap<Integer, Integer>(), new HashMap<Integer, HashMap<Integer, GraphTargetItem>>(), decisions, path, 0);
removeTraps(refs, false, false, localData, new TranslateStack(path), new ArrayList<GraphTargetItem>(), code, code.adr2pos(addr), new HashMap<Integer, Integer>(), new HashMap<Integer, HashMap<Integer, GraphTargetItem>>(), decisions, path, 0);
int cnt = 0;
for (AVM2Instruction src : decisions.keySet()) {
Decision dec = decisions.get(src);

View File

@@ -36,6 +36,7 @@ import com.jpexs.decompiler.flash.abc.avm2.model.HasNextAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.InAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.IntegerValueAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.LocalRegAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.NewActivationAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.NextNameAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.NextValueAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.NullAVM2Item;
@@ -69,6 +70,8 @@ import com.jpexs.decompiler.graph.model.ExitItem;
import com.jpexs.decompiler.graph.model.IfItem;
import com.jpexs.decompiler.graph.model.LoopItem;
import com.jpexs.decompiler.graph.model.NotItem;
import com.jpexs.decompiler.graph.model.PopItem;
import com.jpexs.decompiler.graph.model.PushItem;
import com.jpexs.decompiler.graph.model.SwitchItem;
import com.jpexs.decompiler.graph.model.WhileItem;
import java.util.ArrayList;
@@ -76,6 +79,7 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
*
@@ -124,8 +128,9 @@ public class AVM2Graph extends Graph {
localData.localRegNames = localRegNames;
localData.fullyQualifiedNames = fullyQualifiedNames;
localData.parsedExceptions = new ArrayList<>();
localData.finallyJumps = new ArrayList<>();
localData.ignoredSwitches = new ArrayList<>();
localData.finallyJumps = new HashMap<>();
localData.ignoredSwitches = new HashMap<>();
localData.ignoredSwitches2 = new ArrayList<>();
localData.scriptIndex = scriptIndex;
localData.localRegAssignmentIps = new HashMap<>();
localData.ip = 0;
@@ -159,26 +164,6 @@ public class AVM2Graph extends Graph {
}
}
}
/*for(ABCException ex:body.exceptions){
for(GraphPart p:allBlocks){
boolean next_is_ex_start=false;
for(GraphPart n:p.nextParts){
if(n.start==code.adr2pos(ex.start)){
next_is_ex_start = true;
break;
}
}
if(next_is_ex_start){
for(GraphPart q:allBlocks){ //find target part
if(q.start==code.adr2pos(ex.target)){
p.nextParts.add(q);
break;
}
}
}
}
}*/
}
@Override
@@ -187,11 +172,13 @@ public class AVM2Graph extends Graph {
AVM2LocalData aLocalData = (AVM2LocalData) localData;
List<ABCException> parsedExceptions = aLocalData.parsedExceptions;
List<Integer> finallyJumps = aLocalData.finallyJumps;
List<Integer> ignoredSwitches = aLocalData.ignoredSwitches;
Map<Integer, List<Integer>> finallyJumps = aLocalData.finallyJumps;
Map<Integer, Integer> ignoredSwitches = aLocalData.ignoredSwitches;
List<Integer> ignoredSwitches2 = aLocalData.ignoredSwitches2;
int ip = part.start;
int addr = this.avm2code.fixAddrAfterDebugLine(this.avm2code.pos2adr(part.start));
int maxend = -1;
List<Integer> catchedFinallys = new ArrayList<>();
List<ABCException> catchedExceptions = new ArrayList<>();
for (int e = 0; e < body.exceptions.length; e++) {
if (addr == this.avm2code.fixAddrAfterDebugLine(body.exceptions[e].start)) {
@@ -200,11 +187,13 @@ public class AVM2Graph extends Graph {
if (!parsedExceptions.contains(body.exceptions[e])) {
if (((body.exceptions[e].end) > maxend)) {
catchedExceptions.clear();
catchedFinallys.clear();
maxend = this.avm2code.fixAddrAfterDebugLine(body.exceptions[e].end);
catchedExceptions.add(body.exceptions[e]);
} else if (this.avm2code.fixAddrAfterDebugLine(body.exceptions[e].end) == maxend) {
catchedExceptions.add(body.exceptions[e]);
}
catchedFinallys.add(e);
}
} else if (body.exceptions[e].isFinally()) {
@@ -233,14 +222,16 @@ public class AVM2Graph extends Graph {
List<GraphTargetItem> finallyCommands = new ArrayList<>();
boolean hasFinally = false;
int returnPos = afterCatchPos;
int finStart = -1;
for (int e = 0; e < body.exceptions.length; e++) {
if (body.exceptions[e].isFinally()) {
if (addr == this.avm2code.fixAddrAfterDebugLine(body.exceptions[e].start)) {
if (afterCatchPos + 1 == code.adr2pos(this.avm2code.fixAddrAfterDebugLine(body.exceptions[e].end))) {
catchedFinallys.add(e);
AVM2Instruction jmpIns = this.avm2code.code.get(code.adr2pos(this.avm2code.fixAddrAfterDebugLine(body.exceptions[e].end)));
if (jmpIns.definition instanceof JumpIns) {
int finStart = code.adr2pos(this.avm2code.fixAddrAfterDebugLine(body.exceptions[e].end) + jmpIns.getBytes().length + jmpIns.operands[0]);
finStart = code.adr2pos(this.avm2code.fixAddrAfterDebugLine(body.exceptions[e].end) + jmpIns.getBytes().length + jmpIns.operands[0]);
GraphPart fpart = null;
for (GraphPart p : allParts) {
@@ -249,6 +240,8 @@ public class AVM2Graph extends Graph {
break;
}
}
TranslateStack st = (TranslateStack) stack.clone();
st.clear();
int swPos = -1;
for (int f = finStart; f < this.avm2code.code.size(); f++) {
if (this.avm2code.code.get(f).definition instanceof LookupSwitchIns) {
@@ -256,7 +249,7 @@ public class AVM2Graph extends Graph {
if (swins.operands.length >= 3) {
if (swins.operands[0] == swins.getBytes().length) {
if (code.adr2pos(code.pos2adr(f) + swins.operands[2]) < finStart) {
stack.push(new ExceptionAVM2Item(body.exceptions[e]));
//st.push(new ExceptionAVM2Item(body.exceptions[e]));
GraphPart fepart = null;
for (GraphPart p : allParts) {
if (p.start == f + 1) {
@@ -280,13 +273,17 @@ public class AVM2Graph extends Graph {
}
//ignoredSwitches.add(-1);
//int igs_size=ignoredSwitches.size();
List<Integer> oldFinallyJumps = new ArrayList<>(finallyJumps);
Map<Integer, List<Integer>> oldFinallyJumps = new HashMap<>(finallyJumps);
finallyJumps.clear();
ignoredSwitches.add(swPos);
finallyCommands = printGraph(localData, stack, allParts, parent, fpart, null, loops, staticOperation, path);
ignoredSwitches.put(e, swPos);
st.push(new PopItem(null));
finallyCommands = printGraph(localData, st, allParts, parent, fpart, null, loops, staticOperation, path);
//ignoredSwitches.remove(igs_size-1);
finallyJumps.addAll(oldFinallyJumps);
finallyJumps.add(finStart);
finallyJumps.putAll(oldFinallyJumps);
if (!finallyJumps.containsKey(e)) {
finallyJumps.put(e, new ArrayList<>());
}
finallyJumps.get(e).add(finStart);
hasFinally = true;
break;
}
@@ -328,7 +325,9 @@ public class AVM2Graph extends Graph {
break;
}
}
stack.add(new ExceptionAVM2Item(catchedExceptions.get(e)));
TranslateStack st2 = (TranslateStack) stack.clone();
st2.clear();
st2.add(new ExceptionAVM2Item(catchedExceptions.get(e)));
AVM2LocalData localData2 = new AVM2LocalData(aLocalData);
localData2.scopeStack = new ScopeStack();
List<GraphPart> stopPart2 = new ArrayList<>(stopPart);
@@ -336,16 +335,18 @@ public class AVM2Graph extends Graph {
if (retPart != null) {
stopPart2.add(retPart);
}
List<GraphTargetItem> ncatchedCommands = printGraph(localData2, stack, allParts, parent, npart, stopPart2, loops, staticOperation, path);
List<GraphTargetItem> ncatchedCommands = printGraph(localData2, st2, allParts, parent, npart, stopPart2, loops, staticOperation, path);
if (catchedExceptions.get(e).isFinally() && (catchedExceptions.size() > 1 || hasFinally)) {
catchedExceptions.remove(e);
e--;
} else {
catchedCommands.add(ncatchedCommands);
if (retPart != null && avm2code.code.get(retPart.start).isExit() && !(!ncatchedCommands.isEmpty() && (ncatchedCommands.get(ncatchedCommands.size() - 1) instanceof ExitItem))) {
avm2code.code.get(retPart.start).translate(localData, stack, ncatchedCommands, staticOperation, path);
avm2code.code.get(retPart.start).translate(localData, st2, ncatchedCommands, staticOperation, path);
}
if (catchedExceptions.get(e).isFinally()) {
//endposStartBlock = -1;
if (!ncatchedCommands.isEmpty() && (ncatchedCommands.get(0) instanceof SetLocalAVM2Item)) {
SetLocalAVM2Item sl = (SetLocalAVM2Item) ncatchedCommands.get(0);
if (sl.value.getNotCoerced() instanceof ExceptionAVM2Item) {
@@ -364,19 +365,31 @@ public class AVM2Graph extends Graph {
break;
}
}
List<GraphPart> stopPart2 = new ArrayList<>(stopPart);
stopPart2.add(nepart);
List<GraphPart> stopPart2 = new ArrayList<>();//stopPart);
if (nepart != null) {
stopPart2.add(nepart);
}
stopPart2.addAll(catchParts);
if (retPart != null) {
stopPart2.add(retPart);
}
List<GraphTargetItem> tryCommands = printGraph(localData, stack, allParts, parent, part, stopPart2, loops, staticOperation, path);
TranslateStack st = (TranslateStack) stack.clone();
st.clear();
List<GraphTargetItem> tryCommands = printGraph(localData, st, allParts, parent, part, stopPart2, loops, staticOperation, path);
if (retPart != null && avm2code.code.get(retPart.start).isExit() && !(!tryCommands.isEmpty() && (tryCommands.get(tryCommands.size() - 1) instanceof ExitItem))) {
avm2code.code.get(retPart.start).translate(localData, stack, tryCommands, staticOperation, path);
avm2code.code.get(retPart.start).translate(localData, st, tryCommands, staticOperation, path);
}
output.clear();
stack.clear();
output.add(new TryAVM2Item(tryCommands, catchedExceptions, catchedCommands, finallyCommands, finCatchName));
finallyJumps = ((AVM2LocalData) localData).finallyJumps;
for (int fin_e : catchedFinallys) {
if (finallyJumps.containsKey(fin_e)) {
finallyJumps.get(fin_e).clear();
}
//.remove((Integer) finStart);
}
ip = returnPos;
}
@@ -397,7 +410,10 @@ public class AVM2Graph extends Graph {
ret.addAll(output);
GraphTargetItem lop = checkLoop(part, stopPart, loops);
if (lop == null) {
ret.addAll(printGraph(localData, stack, allParts, null, part, stopPart, loops, staticOperation, path));
TranslateStack st = (TranslateStack) stack.clone();
st.clear();
ret.addAll(printGraph(localData, st, allParts, null, part, stopPart, loops, staticOperation, path));
} else {
ret.add(lop);
}
@@ -423,7 +439,7 @@ public class AVM2Graph extends Graph {
}
}
}
if ((this.avm2code.code.get(part.end).definition instanceof LookupSwitchIns) && ignoredSwitches.contains(part.end)) {
if ((this.avm2code.code.get(part.end).definition instanceof LookupSwitchIns) && (ignoredSwitches.containsValue(part.end) || ignoredSwitches2.contains(part.end))) {
ret = new ArrayList<>();
ret.addAll(output);
return ret;
@@ -444,9 +460,9 @@ public class AVM2Graph extends Graph {
&& (this.avm2code.code.get(part.nextParts.get(1).nextParts.get(0).end).definition instanceof LookupSwitchIns))) {
if (stack.peek() instanceof StrictEqAVM2Item) {
ignoredSwitches.add(part.nextParts.get(0).nextParts.get(0).end);
ignoredSwitches2.add(part.nextParts.get(0).nextParts.get(0).end);
} else {
ignoredSwitches.add(part.nextParts.get(1).nextParts.get(0).end);
ignoredSwitches2.add(part.nextParts.get(1).nextParts.get(0).end);
}
ret = new ArrayList<>();
ret.addAll(output);
@@ -494,7 +510,7 @@ public class AVM2Graph extends Graph {
}
GraphPart numPart = part.nextParts.get(reversed ? 0 : 1);
AVM2Instruction ins = null;
TranslateStack sstack = new TranslateStack();
TranslateStack sstack = new TranslateStack(path);
do {
for (int n = 0; n < numPart.getHeight(); n++) {
ins = this.avm2code.code.get(numPart.getPosAt(n));
@@ -535,7 +551,7 @@ public class AVM2Graph extends Graph {
GraphPart numPart = dp;
AVM2Instruction ins = null;
TranslateStack sstack = new TranslateStack();
TranslateStack sstack = new TranslateStack(path);
do {
for (int n = 0; n < numPart.getHeight(); n++) {
ins = this.avm2code.code.get(numPart.getPosAt(n));
@@ -636,33 +652,34 @@ public class AVM2Graph extends Graph {
@Override
protected GraphPart checkPart(TranslateStack stack, BaseLocalData localData, GraphPart next, List<GraphPart> allParts) {
AVM2LocalData aLocalData = (AVM2LocalData) localData;
List<Integer> finallyJumps = aLocalData.finallyJumps;
List<Integer> ignoredSwitches = aLocalData.ignoredSwitches;
Map<Integer, List<Integer>> finallyJumps = aLocalData.finallyJumps;
Map<Integer, Integer> ignoredSwitches = aLocalData.ignoredSwitches;
GraphPart ret = next;
for (int f = 0; f < finallyJumps.size(); f++) {
int fip = finallyJumps.get(f);
for (int f : finallyJumps.keySet()) {//int f = 0; f < finallyJumps.size(); f++) {
int swip = ignoredSwitches.get(f);
if (next.start == fip) {
if (stack != null && swip != -1) {
AVM2Instruction swIns = avm2code.code.get(swip);
GraphTargetItem t = stack.pop();
Double dval = EcmaScript.toNumber(t.getResult());
int val = (int) (double) dval;
if (swIns.definition instanceof LookupSwitchIns) {
List<Integer> branches = swIns.getBranches(code);
int nip = branches.get(0);
if (val >= 0 && val < branches.size() - 1) {
nip = branches.get(1 + val);
}
for (GraphPart p : allParts) {
if (avm2code.fixIPAfterDebugLine(p.start) == avm2code.fixIPAfterDebugLine(nip)) {
return p;
for (int fip : finallyJumps.get(f)) {
if (next.start == fip) {
if (stack != null && swip != -1) {
AVM2Instruction swIns = avm2code.code.get(swip);
GraphTargetItem t = stack.pop();
Double dval = EcmaScript.toNumber(t.getResult());
int val = (int) (double) dval;
if (swIns.definition instanceof LookupSwitchIns) {
List<Integer> branches = swIns.getBranches(code);
int nip = branches.get(0);
if (val >= 0 && val < branches.size() - 1) {
nip = branches.get(1 + val);
}
for (GraphPart p : allParts) {
if (avm2code.fixIPAfterDebugLine(p.start) == avm2code.fixIPAfterDebugLine(nip)) {
return p;
}
}
ret = null;
}
ret = null;
}
ret = null;
}
ret = null;
}
}
if (ret != next) {
@@ -678,8 +695,14 @@ public class AVM2Graph extends Graph {
AVM2Instruction jmpIns = this.avm2code.code.get(avm2code.adr2pos(this.avm2code.fixAddrAfterDebugLine(body.exceptions[e].end)));
if (jmpIns.definition instanceof JumpIns) {
int finStart = avm2code.adr2pos(this.avm2code.fixAddrAfterDebugLine(body.exceptions[e].end) + jmpIns.getBytes().length + jmpIns.operands[0]);
finallyJumps.add(finStart);
ignoredSwitches.add(-1);
if (!finallyJumps.containsKey(e)) {
finallyJumps.put(e, new ArrayList<>());
}
finallyJumps.get(e).add(finStart);
if (!ignoredSwitches.containsKey(e)) {
ignoredSwitches.put(e, -1);
}
//ignoredSwitches.put(e, -1);
break;
}
}
@@ -707,7 +730,11 @@ public class AVM2Graph extends Graph {
}
GraphTargetItem ft = w.commands.get(pos);
if (ft instanceof WithAVM2Item) {
ft = w.commands.get(pos + 1);
pos++;
while (w.commands.get(pos) instanceof SetTypeAVM2Item) {
pos++;
}
ft = w.commands.get(pos);
if (ft instanceof IfItem) {
IfItem ift = (IfItem) ft;
if (ift.onTrue.size() > 0) {
@@ -759,7 +786,7 @@ public class AVM2Graph extends Graph {
@Override
protected void finalProcess(List<GraphTargetItem> list, int level, FinalProcessLocalData localData) {
super.finalProcess(list, level, localData);
if (level == 0) {
if (!list.isEmpty()) {
if (list.get(list.size() - 1) instanceof ReturnVoidAVM2Item) {
@@ -864,6 +891,8 @@ public class AVM2Graph extends Graph {
}
}
}
//Handle for loops at the end:
super.finalProcess(list, level, localData);
}
@Override

View File

@@ -1,49 +1,49 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.instructions.arithmetic;
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.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.ScopeStack;
import com.jpexs.decompiler.graph.TranslateStack;
import com.jpexs.decompiler.graph.model.NotItem;
import java.util.HashMap;
import java.util.List;
public class NotIns extends InstructionDefinition {
public NotIns() {
super(0x96, "not", new int[]{}, false);
}
@Override
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<String> fullyQualifiedNames, String path, HashMap<Integer, Integer> localRegsAssignmentIps, int ip, HashMap<Integer, List<Integer>> refs, AVM2Code code) {
GraphTargetItem v = stack.pop();
stack.push(new NotItem(ins, v));
}
@Override
public int getStackDelta(AVM2Instruction ins, ABC abc) {
return -1 + 1;
}
}
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.instructions.arithmetic;
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.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.ScopeStack;
import com.jpexs.decompiler.graph.TranslateStack;
import com.jpexs.decompiler.graph.model.NotItem;
import java.util.HashMap;
import java.util.List;
public class NotIns extends InstructionDefinition {
public NotIns() {
super(0x96, "not", new int[]{}, false);
}
@Override
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<String> fullyQualifiedNames, String path, HashMap<Integer, Integer> localRegsAssignmentIps, int ip, HashMap<Integer, List<Integer>> refs, AVM2Code code) {
GraphTargetItem v = stack.pop();
stack.push(v.invert(ins));
}
@Override
public int getStackDelta(AVM2Instruction ins, ABC abc) {
return -1 + 1;
}
}

View File

@@ -1,56 +1,57 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.instructions.jumps;
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.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.ScopeStack;
import com.jpexs.decompiler.graph.TranslateStack;
import com.jpexs.decompiler.graph.model.NotItem;
import java.util.HashMap;
import java.util.List;
public class IfFalseIns extends InstructionDefinition implements IfTypeIns {
public IfFalseIns() {
super(0x12, "iffalse", new int[]{AVM2Code.DAT_OFFSET}, false);
}
@Override
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<String> fullyQualifiedNames, String path, HashMap<Integer, Integer> localRegsAssignmentIps, int ip, HashMap<Integer, List<Integer>> refs, AVM2Code code) {
GraphTargetItem v1 = stack.pop();
stack.push(new NotItem(ins, v1));
}
@Override
public void translateInverted(HashMap<Integer, GraphTargetItem> localRegs, TranslateStack stack, AVM2Instruction ins) {
//String v1 = stack.pop().toString();
//stack.push("(" + v1 + ")");
}
@Override
public int getStackDelta(AVM2Instruction ins, ABC abc) {
return -1;
}
}
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.instructions.jumps;
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.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.ScopeStack;
import com.jpexs.decompiler.graph.TranslateStack;
import com.jpexs.decompiler.graph.model.NotItem;
import java.util.HashMap;
import java.util.List;
public class IfFalseIns extends InstructionDefinition implements IfTypeIns {
public IfFalseIns() {
super(0x12, "iffalse", new int[]{AVM2Code.DAT_OFFSET}, false);
}
@Override
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<String> fullyQualifiedNames, String path, HashMap<Integer, Integer> localRegsAssignmentIps, int ip, HashMap<Integer, List<Integer>> refs, AVM2Code code) {
GraphTargetItem v1 = stack.pop();
//stack.push(new NotItem(ins, v1));
stack.push(v1.invert(ins));
}
@Override
public void translateInverted(HashMap<Integer, GraphTargetItem> localRegs, TranslateStack stack, AVM2Instruction ins) {
//String v1 = stack.pop().toString();
//stack.push("(" + v1 + ")");
}
@Override
public int getStackDelta(AVM2Instruction ins, ABC abc) {
return -1;
}
}

View File

@@ -1,56 +1,56 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.instructions.jumps;
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.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.ScopeStack;
import com.jpexs.decompiler.graph.TranslateStack;
import com.jpexs.decompiler.graph.model.NotItem;
import java.util.HashMap;
import java.util.List;
public class IfTrueIns extends InstructionDefinition implements IfTypeIns {
public IfTrueIns() {
super(0x11, "iftrue", new int[]{AVM2Code.DAT_OFFSET}, false);
}
@Override
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<String> fullyQualifiedNames, String path, HashMap<Integer, Integer> localRegsAssignmentIps, int ip, HashMap<Integer, List<Integer>> refs, AVM2Code code) {
//String v1 = stack.pop().toString();
//stack.push("(" + v1 + ")");
}
@Override
public void translateInverted(HashMap<Integer, GraphTargetItem> localRegs, TranslateStack stack, AVM2Instruction ins) {
GraphTargetItem v1 = stack.pop();
stack.push(new NotItem(ins, v1));
}
@Override
public int getStackDelta(AVM2Instruction ins, ABC abc) {
return -1;
}
}
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.instructions.jumps;
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.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.ScopeStack;
import com.jpexs.decompiler.graph.TranslateStack;
import com.jpexs.decompiler.graph.model.NotItem;
import java.util.HashMap;
import java.util.List;
public class IfTrueIns extends InstructionDefinition implements IfTypeIns {
public IfTrueIns() {
super(0x11, "iftrue", new int[]{AVM2Code.DAT_OFFSET}, false);
}
@Override
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<String> fullyQualifiedNames, String path, HashMap<Integer, Integer> localRegsAssignmentIps, int ip, HashMap<Integer, List<Integer>> refs, AVM2Code code) {
//String v1 = stack.pop().toString();
//stack.push("(" + v1 + ")");
}
@Override
public void translateInverted(HashMap<Integer, GraphTargetItem> localRegs, TranslateStack stack, AVM2Instruction ins) {
GraphTargetItem v1 = stack.pop();
stack.push(v1.invert(null));
}
@Override
public int getStackDelta(AVM2Instruction ins, ABC abc) {
return -1;
}
}

View File

@@ -1,134 +1,134 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.instructions.localregs;
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.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.avm2.instructions.SetTypeIns;
import com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.DecrementAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.FindPropertyAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.IncrementAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.LocalRegAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.NewActivationAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.PostDecrementAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.PostIncrementAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.SetLocalAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.operations.PreDecrementAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.operations.PreIncrementAVM2Item;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.ScopeStack;
import com.jpexs.decompiler.graph.TranslateStack;
import java.util.HashMap;
import java.util.List;
import java.util.Stack;
public abstract class SetLocalTypeIns extends InstructionDefinition implements SetTypeIns {
public SetLocalTypeIns(int instructionCode, String instructionName, int[] operands, boolean canThrow) {
super(instructionCode, instructionName, operands, canThrow);
}
@Override
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<String> fullyQualifiedNames, String path, HashMap<Integer, Integer> regAssignCount, int ip, HashMap<Integer, List<Integer>> refs, AVM2Code code) {
int regId = getRegisterId(ins);
GraphTargetItem value = stack.pop();
/*if (localRegs.containsKey(regId)) {
localRegs.put(regId, new NotCompileTimeAVM2Item(ins, value));
} else {
localRegs.put(regId, value);
}*/
localRegs.put(regId, value);
if (!regAssignCount.containsKey(regId)) {
regAssignCount.put(regId, 0);
}
regAssignCount.put(regId, regAssignCount.get(regId) + 1);
//localRegsAssignmentIps.put(regId, ip);
if (value instanceof NewActivationAVM2Item) {
return;
}
if (value instanceof FindPropertyAVM2Item) {
return;
}
if (value.getNotCoerced() instanceof IncrementAVM2Item) {
GraphTargetItem inside = ((IncrementAVM2Item) value.getNotCoerced()).value.getNotCoerced().getThroughDuplicate();
if (inside instanceof LocalRegAVM2Item) {
if (((LocalRegAVM2Item) inside).regIndex == regId) {
if (stack.size() > 0) {
GraphTargetItem top = stack.peek().getNotCoerced().getThroughDuplicate();
if (top == inside) {
stack.pop();
stack.push(new PostIncrementAVM2Item(ins, inside));
} else if ((top instanceof IncrementAVM2Item) && (((IncrementAVM2Item) top).value == inside)) {
stack.pop();
stack.push(new PreIncrementAVM2Item(ins, inside));
} else {
output.add(new PostIncrementAVM2Item(ins, inside));
}
} else {
output.add(new PostIncrementAVM2Item(ins, inside));
}
return;
}
}
}
if (value.getNotCoerced() instanceof DecrementAVM2Item) {
GraphTargetItem inside = ((DecrementAVM2Item) value.getNotCoerced()).value.getNotCoerced().getThroughDuplicate();
if (inside instanceof LocalRegAVM2Item) {
if (((LocalRegAVM2Item) inside).regIndex == regId) {
if (stack.size() > 0) {
GraphTargetItem top = stack.peek().getNotCoerced().getThroughDuplicate();
if (top == inside) {
stack.pop();
stack.push(new PostDecrementAVM2Item(ins, inside));
} else if ((top instanceof DecrementAVM2Item) && (((DecrementAVM2Item) top).value == inside)) {
stack.pop();
stack.push(new PreDecrementAVM2Item(ins, inside));
} else {
output.add(new PostDecrementAVM2Item(ins, inside));
}
} else {
output.add(new PostDecrementAVM2Item(ins, inside));
}
return;
}
}
}
//if(val.startsWith("catchscope ")) return;
//if(val.startsWith("newactivation()")) return;
output.add(new SetLocalAVM2Item(ins, regId, value));
}
@Override
public String getObject(Stack<AVM2Item> stack, ABC abc, AVM2Instruction ins, List<AVM2Item> output, MethodBody body, HashMap<Integer, String> localRegNames, List<String> fullyQualifiedNames) {
return AVM2Item.localRegName(localRegNames, getRegisterId(ins));
}
@Override
public int getStackDelta(AVM2Instruction ins, ABC abc) {
return -1;
}
public abstract int getRegisterId(AVM2Instruction ins);
}
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.instructions.localregs;
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.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.avm2.instructions.SetTypeIns;
import com.jpexs.decompiler.flash.abc.avm2.model.AVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.DecrementAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.FindPropertyAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.IncrementAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.LocalRegAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.NewActivationAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.PostDecrementAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.PostIncrementAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.SetLocalAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.operations.PreDecrementAVM2Item;
import com.jpexs.decompiler.flash.abc.avm2.model.operations.PreIncrementAVM2Item;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.ScopeStack;
import com.jpexs.decompiler.graph.TranslateStack;
import java.util.HashMap;
import java.util.List;
import java.util.Stack;
public abstract class SetLocalTypeIns extends InstructionDefinition implements SetTypeIns {
public SetLocalTypeIns(int instructionCode, String instructionName, int[] operands, boolean canThrow) {
super(instructionCode, instructionName, operands, canThrow);
}
@Override
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<String> fullyQualifiedNames, String path, HashMap<Integer, Integer> regAssignCount, int ip, HashMap<Integer, List<Integer>> refs, AVM2Code code) {
int regId = getRegisterId(ins);
GraphTargetItem value = stack.pop();
/*if (localRegs.containsKey(regId)) {
localRegs.put(regId, new NotCompileTimeAVM2Item(ins, value));
} else {
localRegs.put(regId, value);
}*/
localRegs.put(regId, value);
if (!regAssignCount.containsKey(regId)) {
regAssignCount.put(regId, 0);
}
regAssignCount.put(regId, regAssignCount.get(regId) + 1);
//localRegsAssignmentIps.put(regId, ip);
if (value.getThroughDuplicate() instanceof NewActivationAVM2Item) {
return;
}
if (value instanceof FindPropertyAVM2Item) {
return;
}
if (value.getNotCoerced() instanceof IncrementAVM2Item) {
GraphTargetItem inside = ((IncrementAVM2Item) value.getNotCoerced()).value.getNotCoerced().getThroughDuplicate();
if (inside instanceof LocalRegAVM2Item) {
if (((LocalRegAVM2Item) inside).regIndex == regId) {
if (stack.size() > 0) {
GraphTargetItem top = stack.peek().getNotCoerced().getThroughDuplicate();
if (top == inside) {
stack.pop();
stack.push(new PostIncrementAVM2Item(ins, inside));
} else if ((top instanceof IncrementAVM2Item) && (((IncrementAVM2Item) top).value == inside)) {
stack.pop();
stack.push(new PreIncrementAVM2Item(ins, inside));
} else {
output.add(new PostIncrementAVM2Item(ins, inside));
}
} else {
output.add(new PostIncrementAVM2Item(ins, inside));
}
return;
}
}
}
if (value.getNotCoerced() instanceof DecrementAVM2Item) {
GraphTargetItem inside = ((DecrementAVM2Item) value.getNotCoerced()).value.getNotCoerced().getThroughDuplicate();
if (inside instanceof LocalRegAVM2Item) {
if (((LocalRegAVM2Item) inside).regIndex == regId) {
if (stack.size() > 0) {
GraphTargetItem top = stack.peek().getNotCoerced().getThroughDuplicate();
if (top == inside) {
stack.pop();
stack.push(new PostDecrementAVM2Item(ins, inside));
} else if ((top instanceof DecrementAVM2Item) && (((DecrementAVM2Item) top).value == inside)) {
stack.pop();
stack.push(new PreDecrementAVM2Item(ins, inside));
} else {
output.add(new PostDecrementAVM2Item(ins, inside));
}
} else {
output.add(new PostDecrementAVM2Item(ins, inside));
}
return;
}
}
}
//if(val.startsWith("catchscope ")) return;
//if(val.startsWith("newactivation()")) return;
output.add(new SetLocalAVM2Item(ins, regId, value));
}
@Override
public String getObject(Stack<AVM2Item> stack, ABC abc, AVM2Instruction ins, List<AVM2Item> output, MethodBody body, HashMap<Integer, String> localRegNames, List<String> fullyQualifiedNames) {
return AVM2Item.localRegName(localRegNames, getRegisterId(ins));
}
@Override
public int getStackDelta(AVM2Instruction ins, ABC abc) {
return -1;
}
public abstract int getRegisterId(AVM2Instruction ins);
}

View File

@@ -156,9 +156,7 @@ public class SetSlotIns extends InstructionDefinition implements SetTypeIns {
}
}
}
if (slotname == null) {
System.err.println("SLOT NOT FOUND");
}
output.add(new SetSlotAVM2Item(ins, obj, slotname, value));
}

View File

@@ -45,13 +45,9 @@ public class PopIns extends InstructionDefinition {
@Override
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<String> fullyQualifiedNames, String path, HashMap<Integer, Integer> localRegsAssignmentIps, int ip, HashMap<Integer, List<Integer>> refs, AVM2Code code) {
if (stack.size() > 0) {
GraphTargetItem top = stack.pop();
//Note: Commands like "5;" - numbers are unsupported as it collide with try..finally block decompilation. TODO: allow this somehow
if (/*!(top instanceof IntegerValueAVM2Item) &&*/(!(top instanceof MarkItem))) {
output.add(top);
}
GraphTargetItem top = stack.pop();
if ((!(top instanceof MarkItem))) {
output.add(top);
}
}

View File

@@ -1,54 +1,55 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.instructions.stack;
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.LocalDataArea;
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.avm2.model.BooleanAVM2Item;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.ScopeStack;
import com.jpexs.decompiler.graph.TranslateStack;
import java.util.HashMap;
import java.util.List;
public class PushFalseIns extends InstructionDefinition {
public PushFalseIns() {
super(0x27, "pushfalse", new int[]{}, false);
}
@Override
public void execute(LocalDataArea lda, AVM2ConstantPool constants, List<Object> arguments) {
lda.operandStack.push(Boolean.FALSE);
}
@Override
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<String> fullyQualifiedNames, String path, HashMap<Integer, Integer> localRegsAssignmentIps, int ip, HashMap<Integer, List<Integer>> refs, AVM2Code code) {
stack.push(new BooleanAVM2Item(ins, Boolean.FALSE));
}
@Override
public int getStackDelta(AVM2Instruction ins, ABC abc) {
return 1;
}
}
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.instructions.stack;
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.LocalDataArea;
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.avm2.model.BooleanAVM2Item;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.ScopeStack;
import com.jpexs.decompiler.graph.TranslateStack;
import com.jpexs.decompiler.graph.model.FalseItem;
import java.util.HashMap;
import java.util.List;
public class PushFalseIns extends InstructionDefinition {
public PushFalseIns() {
super(0x27, "pushfalse", new int[]{}, false);
}
@Override
public void execute(LocalDataArea lda, AVM2ConstantPool constants, List<Object> arguments) {
lda.operandStack.push(Boolean.FALSE);
}
@Override
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<String> fullyQualifiedNames, String path, HashMap<Integer, Integer> localRegsAssignmentIps, int ip, HashMap<Integer, List<Integer>> refs, AVM2Code code) {
stack.push(new FalseItem(ins));
}
@Override
public int getStackDelta(AVM2Instruction ins, ABC abc) {
return 1;
}
}

View File

@@ -1,54 +1,55 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.instructions.stack;
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.LocalDataArea;
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.avm2.model.BooleanAVM2Item;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.ScopeStack;
import com.jpexs.decompiler.graph.TranslateStack;
import java.util.HashMap;
import java.util.List;
public class PushTrueIns extends InstructionDefinition {
public PushTrueIns() {
super(0x26, "pushtrue", new int[]{}, false);
}
@Override
public void execute(LocalDataArea lda, AVM2ConstantPool constants, List<Object> arguments) {
lda.operandStack.push(Boolean.TRUE);
}
@Override
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<String> fullyQualifiedNames, String path, HashMap<Integer, Integer> localRegsAssignmentIps, int ip, HashMap<Integer, List<Integer>> refs, AVM2Code code) {
stack.push(new BooleanAVM2Item(ins, Boolean.TRUE));
}
@Override
public int getStackDelta(AVM2Instruction ins, ABC abc) {
return 1;
}
}
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.instructions.stack;
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.LocalDataArea;
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.InstructionDefinition;
import com.jpexs.decompiler.flash.abc.avm2.model.BooleanAVM2Item;
import com.jpexs.decompiler.flash.abc.types.MethodBody;
import com.jpexs.decompiler.flash.abc.types.MethodInfo;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.ScopeStack;
import com.jpexs.decompiler.graph.TranslateStack;
import com.jpexs.decompiler.graph.model.TrueItem;
import java.util.HashMap;
import java.util.List;
public class PushTrueIns extends InstructionDefinition {
public PushTrueIns() {
super(0x26, "pushtrue", new int[]{}, false);
}
@Override
public void execute(LocalDataArea lda, AVM2ConstantPool constants, List<Object> arguments) {
lda.operandStack.push(Boolean.TRUE);
}
@Override
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<String> fullyQualifiedNames, String path, HashMap<Integer, Integer> localRegsAssignmentIps, int ip, HashMap<Integer, List<Integer>> refs, AVM2Code code) {
stack.push(new TrueItem(ins));
}
@Override
public int getStackDelta(AVM2Instruction ins, ABC abc) {
return 1;
}
}

View File

@@ -40,9 +40,9 @@ public class HasNextAVM2Item extends AVM2Item {
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
collection.toString(writer, localData);
collection.appendTo(writer, localData);
writer.append(" hasNext ");
return object.toString(writer, localData);
return object.appendTo(writer, localData);
}
@Override

View File

@@ -1,18 +1,19 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -25,6 +26,7 @@ import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SimpleValue;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.decompiler.graph.model.LocalData;
@@ -78,4 +80,5 @@ public class IntegerValueAVM2Item extends NumberValueAVM2Item {
public boolean hasReturnValue() {
return true;
}
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.model;
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
@@ -32,7 +33,7 @@ public class NewActivationAVM2Item extends AVM2Item {
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
return writer.append("§§activation");
}
@Override

View File

@@ -1,25 +1,32 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.model;
import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.graph.SimpleValue;
public abstract class NumberValueAVM2Item extends AVM2Item implements SimpleValue {
public NumberValueAVM2Item(AVM2Instruction instruction) {
super(instruction, PRECEDENCE_PRIMARY);
}
@Override
public boolean isSimpleValue() {
return true;
}
}

View File

@@ -46,14 +46,14 @@ public class SetSlotAVM2Item extends AVM2Item implements SetTypeAVM2Item, Assign
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
srcData.localName = slotName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false);
srcData.localName = slotName == null ? "/*UnknownSlot*/" : slotName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false);
getName(writer, localData);
writer.append(" = ");
return value.toString(writer, localData);
}
public String getNameAsStr(LocalData localData) {
return slotName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false);
return slotName == null ? "/*UnknownSlot*/" : slotName.getName(localData.constantsAvm2, localData.fullyQualifiedNames, false);
}
public GraphTextWriter getName(GraphTextWriter writer, LocalData localData) {

View File

@@ -24,6 +24,7 @@ import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SimpleValue;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import com.jpexs.decompiler.graph.model.LocalData;
@@ -31,7 +32,7 @@ import com.jpexs.helpers.Helper;
import java.util.List;
import java.util.Set;
public class StringAVM2Item extends AVM2Item {
public class StringAVM2Item extends AVM2Item implements SimpleValue {
public String value;
@@ -71,4 +72,9 @@ public class StringAVM2Item extends AVM2Item {
public boolean hasReturnValue() {
return true;
}
@Override
public boolean isSimpleValue() {
return true;
}
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -53,7 +54,7 @@ public class EqAVM2Item extends BinaryOpItem implements LogicalOpItem, IfConditi
}
@Override
@Override
public GraphTargetItem invert(GraphSourceItem neqSrc) {
return new NeqAVM2Item(src, leftSide, rightSide);
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -48,7 +49,7 @@ public class GeAVM2Item extends BinaryOpItem implements LogicalOpItem, IfConditi
}
@Override
@Override
public GraphTargetItem invert(GraphSourceItem neqSrc) {
return new LtAVM2Item(src, leftSide, rightSide);
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -48,7 +49,7 @@ public class GtAVM2Item extends BinaryOpItem implements LogicalOpItem, IfConditi
}
@Override
@Override
public GraphTargetItem invert(GraphSourceItem neqSrc) {
return new LeAVM2Item(src, leftSide, rightSide);
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -48,7 +49,7 @@ public class LeAVM2Item extends BinaryOpItem implements LogicalOpItem, IfConditi
}
@Override
@Override
public GraphTargetItem invert(GraphSourceItem neqSrc) {
return new GtAVM2Item(src, leftSide, rightSide);
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -48,7 +49,7 @@ public class LtAVM2Item extends BinaryOpItem implements LogicalOpItem, IfConditi
}
@Override
@Override
public GraphTargetItem invert(GraphSourceItem neqSrc) {
return new GeAVM2Item(src, leftSide, rightSide);
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -54,7 +55,7 @@ public class NeqAVM2Item extends BinaryOpItem implements LogicalOpItem, IfCondit
}
@Override
@Override
public GraphTargetItem invert(GraphSourceItem neqSrc) {
return new EqAVM2Item(src, leftSide, rightSide);
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -56,7 +57,7 @@ public class StrictEqAVM2Item extends BinaryOpItem implements LogicalOpItem, IfC
}
@Override
@Override
public GraphTargetItem invert(GraphSourceItem neqSrc) {
return new StrictNeqAVM2Item(src, leftSide, rightSide);
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -49,7 +50,7 @@ public class StrictNeqAVM2Item extends BinaryOpItem implements LogicalOpItem, If
}
@Override
@Override
public GraphTargetItem invert(GraphSourceItem neqSrc) {
return new StrictEqAVM2Item(src, leftSide, rightSide);
}

View File

@@ -57,9 +57,11 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.DupIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PopIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PopScopeIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PushByteIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PushFalseIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PushNullIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PushScopeIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PushStringIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PushTrueIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PushUndefinedIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PushWithIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.SwapIns;
@@ -103,7 +105,6 @@ import com.jpexs.decompiler.flash.abc.types.traits.TraitFunction;
import com.jpexs.decompiler.flash.abc.types.traits.TraitMethodGetterSetter;
import com.jpexs.decompiler.flash.abc.types.traits.TraitSlotConst;
import com.jpexs.decompiler.flash.abc.types.traits.Traits;
import com.jpexs.decompiler.flash.action.model.DirectValueActionItem;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
@@ -118,6 +119,7 @@ import com.jpexs.decompiler.graph.model.CommaExpressionItem;
import com.jpexs.decompiler.graph.model.ContinueItem;
import com.jpexs.decompiler.graph.model.DoWhileItem;
import com.jpexs.decompiler.graph.model.DuplicateItem;
import com.jpexs.decompiler.graph.model.FalseItem;
import com.jpexs.decompiler.graph.model.ForItem;
import com.jpexs.decompiler.graph.model.IfItem;
import com.jpexs.decompiler.graph.model.LocalData;
@@ -125,6 +127,7 @@ import com.jpexs.decompiler.graph.model.NotItem;
import com.jpexs.decompiler.graph.model.OrItem;
import com.jpexs.decompiler.graph.model.SwitchItem;
import com.jpexs.decompiler.graph.model.TernarOpItem;
import com.jpexs.decompiler.graph.model.TrueItem;
import com.jpexs.decompiler.graph.model.UnboundedTypeItem;
import com.jpexs.decompiler.graph.model.WhileItem;
import java.io.ByteArrayOutputStream;
@@ -161,6 +164,16 @@ public class AVM2SourceGenerator implements SourceGenerator {
return new AVM2Instruction(0, def, operands);
}
@Override
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, FalseItem item) throws CompilationException {
return GraphTargetItem.toSourceMerge(localData, this, ins(new PushFalseIns()));
}
@Override
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, TrueItem item) throws CompilationException {
return GraphTargetItem.toSourceMerge(localData, this, ins(new PushTrueIns()));
}
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, GetDescendantsAVM2Item item) throws CompilationException {
int[] nssa = new int[item.openedNamespaces.size()];
for (int i = 0; i < item.openedNamespaces.size(); i++) {

View File

@@ -1,18 +1,19 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.parser.script;
/**
@@ -32,5 +33,6 @@ public enum SymbolGroup {
TYPENAME,
EOF,
//GLOBALFUNC,
//GLOBALFUNC,
GLOBALCONST,
PREPROCESSOR
}

View File

@@ -1,242 +1,243 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.parser.script;
import com.jpexs.decompiler.graph.GraphTargetItem;
/**
*
* @author JPEXS
*/
public enum SymbolType {
//Keywords
BREAK,
CASE,
CONTINUE,
DEFAULT,
DO,
WHILE,
ELSE,
FOR,
EACH,
IN(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
IF,
RETURN,
SUPER(GraphTargetItem.PRECEDENCE_PRIMARY, false),
SWITCH,
THROW,
TRY,
CATCH,
FINALLY,
WITH,
DYNAMIC,
INTERNAL,
OVERRIDE,
PRIVATE,
PROTECTED,
PUBLIC,
STATIC,
CLASS,
CONST,
EXTENDS,
FUNCTION(GraphTargetItem.PRECEDENCE_PRIMARY, false),
GET,
IMPLEMENTS,
INTERFACE,
NAMESPACE,
PACKAGE,
SET,
VAR,
IMPORT,
USE,
FALSE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
NULL(GraphTargetItem.PRECEDENCE_PRIMARY, false),
THIS(GraphTargetItem.PRECEDENCE_PRIMARY, false),
TRUE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
//Operators
PARENT_OPEN(GraphTargetItem.PRECEDENCE_PRIMARY, false),
PARENT_CLOSE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
CURLY_OPEN(GraphTargetItem.PRECEDENCE_PRIMARY, false),
CURLY_CLOSE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
BRACKET_OPEN(GraphTargetItem.PRECEDENCE_PRIMARY, false),
BRACKET_CLOSE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
SEMICOLON,
COMMA(GraphTargetItem.PRECEDENCE_COMMA, false),
REST,
DOT(GraphTargetItem.PRECEDENCE_PRIMARY, false),
ASSIGN(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
GREATER_THAN(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
LOWER_THAN(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
NOT(GraphTargetItem.PRECEDENCE_UNARY, false),
NEGATE(GraphTargetItem.PRECEDENCE_UNARY, false),
TERNAR(GraphTargetItem.PRECEDENCE_CONDITIONAL, true, true), /*!! ternar !!!*/
COLON(GraphTargetItem.PRECEDENCE_CONDITIONAL, false),/*!! ternar !!!*/
EQUALS(GraphTargetItem.PRECEDENCE_EQUALITY, true),
STRICT_EQUALS(GraphTargetItem.PRECEDENCE_EQUALITY, true),
LOWER_EQUAL(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
GREATER_EQUAL(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
NOT_EQUAL(GraphTargetItem.PRECEDENCE_EQUALITY, true),
STRICT_NOT_EQUAL(GraphTargetItem.PRECEDENCE_EQUALITY, true),
AND(GraphTargetItem.PRECEDENCE_LOGICALAND, true),
OR(GraphTargetItem.PRECEDENCE_LOGICALOR, true),
INCREMENT(GraphTargetItem.PRECEDENCE_POSTFIX, false),//OR Unary
DECREMENT(GraphTargetItem.PRECEDENCE_POSTFIX, false), //OR Unary
PLUS(GraphTargetItem.PRECEDENCE_ADDITIVE, true),
MINUS(GraphTargetItem.PRECEDENCE_ADDITIVE, true), //OR Unary
MULTIPLY(GraphTargetItem.PRECEDENCE_MULTIPLICATIVE, true),
DIVIDE(GraphTargetItem.PRECEDENCE_MULTIPLICATIVE, true),
BITAND(GraphTargetItem.PRECEDENCE_BITWISEAND, true),
BITOR(GraphTargetItem.PRECEDENCE_BITWISEOR, true),
XOR(GraphTargetItem.PRECEDENCE_BITWISEXOR, true),
MODULO(GraphTargetItem.PRECEDENCE_BITWISESHIFT, true),
SHIFT_LEFT(GraphTargetItem.PRECEDENCE_BITWISESHIFT, true),
SHIFT_RIGHT(GraphTargetItem.PRECEDENCE_BITWISESHIFT, true),
USHIFT_RIGHT(GraphTargetItem.PRECEDENCE_BITWISESHIFT, true),
ASSIGN_PLUS(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_MINUS(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_MULTIPLY(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_DIVIDE(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_BITAND(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_BITOR(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_XOR(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_MODULO(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_SHIFT_LEFT(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_SHIFT_RIGHT(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_USHIFT_RIGHT(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
AS(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
DELETE(GraphTargetItem.PRECEDENCE_UNARY, false),
INSTANCEOF(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
IS(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
NAMESPACE_OP(GraphTargetItem.PRECEDENCE_PRIMARY, false),
NEW(GraphTargetItem.PRECEDENCE_PRIMARY, false),
TYPEOF(GraphTargetItem.PRECEDENCE_UNARY, false),
VOID,
ATTRIBUTE,
//Other
STRING(GraphTargetItem.PRECEDENCE_PRIMARY, false),
COMMENT,
//XML,
IDENTIFIER(GraphTargetItem.PRECEDENCE_PRIMARY, false),
INTEGER(GraphTargetItem.PRECEDENCE_PRIMARY, false),
DOUBLE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
TYPENAME(GraphTargetItem.PRECEDENCE_PRIMARY, false),
EOF,
//TRACE,
//GETURL,
//GOTOANDSTOP,
//NEXTFRAME,
//PLAY,
//PREVFRAME,
//TELLTARGET,
//STOP,
//STOPALLSOUNDS,
//TOGGLEHIGHQUALITY,
//ORD,
//CHR,
//DUPLICATEMOVIECLIP,
//STOPDRAG,
//GETTIMER,
//LOADVARIABLES,
//LOADMOVIE,
//GOTOANDPLAY,
//MBORD,
//MBCHR,
//MBLENGTH,
//MBSUBSTRING,
//RANDOM,
//REMOVEMOVIECLIP,
//STARTDRAG,
//SUBSTR,
//LENGTH, //string.length
INT(GraphTargetItem.PRECEDENCE_PRIMARY, false),
//TARGETPATH,
NUMBER_OP(GraphTargetItem.PRECEDENCE_PRIMARY, false),
STRING_OP(GraphTargetItem.PRECEDENCE_PRIMARY, false),
//IFFRAMELOADED,
INFINITY(GraphTargetItem.PRECEDENCE_PRIMARY, false),
//EVAL,
UNDEFINED(GraphTargetItem.PRECEDENCE_PRIMARY, false),
//NEWLINE,
NAN(GraphTargetItem.PRECEDENCE_PRIMARY, false),
//GETVERSION,
//CALL,
//LOADMOVIENUM,
//LOADVARIABLESNUM,
//PRINT,
//PRINTNUM,
//PRINTASBITMAP,
//PRINTASBITMAPNUM,
//UNLOADMOVIE,
//UNLOADMOVIENUM,
FINAL,
XML_STARTTAG_BEGIN(GraphTargetItem.PRECEDENCE_PRIMARY, false), // <xxx
XML_STARTVARTAG_BEGIN(GraphTargetItem.PRECEDENCE_PRIMARY, false), // <{
XML_STARTTAG_END(GraphTargetItem.PRECEDENCE_PRIMARY, false), // >
XML_FINISHVARTAG_BEGIN(GraphTargetItem.PRECEDENCE_PRIMARY, false), // </{
XML_FINISHTAG(GraphTargetItem.PRECEDENCE_PRIMARY, false), // </xxx>
XML_STARTFINISHTAG_END(GraphTargetItem.PRECEDENCE_PRIMARY, false), // />
XML_COMMENT(GraphTargetItem.PRECEDENCE_PRIMARY, false), // <!-- ... -->
XML_CDATA(GraphTargetItem.PRECEDENCE_PRIMARY, false), //<![CDATA[ ... ]]>
XML_INSTR_BEGIN(GraphTargetItem.PRECEDENCE_PRIMARY, false), // <?xxx
XML_INSTR_END(GraphTargetItem.PRECEDENCE_PRIMARY, false), // ?>
XML_VAR_BEGIN(GraphTargetItem.PRECEDENCE_PRIMARY, false), // {
XML_ATTRIBUTENAME(GraphTargetItem.PRECEDENCE_PRIMARY, false), // aaa=
XML_ATTRIBUTEVALUE(GraphTargetItem.PRECEDENCE_PRIMARY, false), // "vvv"
XML_TEXT(GraphTargetItem.PRECEDENCE_PRIMARY, false),
XML_ATTRNAMEVAR_BEGIN(GraphTargetItem.PRECEDENCE_PRIMARY, false), // {...}=
XML_ATTRVALVAR_BEGIN(GraphTargetItem.PRECEDENCE_PRIMARY, false), // aaa={
XML_INSTRATTRNAMEVAR_BEGIN(GraphTargetItem.PRECEDENCE_PRIMARY, false), // {...}=
XML_INSTRATTRVALVAR_BEGIN(GraphTargetItem.PRECEDENCE_PRIMARY, false), // aaa={
XML_INSTRVARTAG_BEGIN(GraphTargetItem.PRECEDENCE_PRIMARY, false), // <?{
FILTER(GraphTargetItem.PRECEDENCE_PRIMARY, false),
DESCENDANTS(GraphTargetItem.PRECEDENCE_PRIMARY, false),
NATIVE;
private int precedence = GraphTargetItem.NOPRECEDENCE;
private boolean binary = false;
private boolean rightAssociative = false;
public boolean isBinary() {
return binary;
}
public boolean isRightAssociative() {
return rightAssociative;
}
public int getPrecedence() {
return precedence;
}
private SymbolType(int precedence, boolean binary) {
this.precedence = precedence;
this.binary = binary;
}
private SymbolType(int precedence, boolean binary, boolean rightAssociative) {
this.precedence = precedence;
this.binary = binary;
this.rightAssociative = rightAssociative;
}
private SymbolType() {
}
}
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.abc.avm2.parser.script;
import com.jpexs.decompiler.graph.GraphTargetItem;
/**
*
* @author JPEXS
*/
public enum SymbolType {
//Keywords
BREAK,
CASE,
CONTINUE,
DEFAULT,
DO,
WHILE,
ELSE,
FOR,
EACH,
IN(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
IF,
RETURN,
SUPER(GraphTargetItem.PRECEDENCE_PRIMARY, false),
SWITCH,
THROW,
TRY,
CATCH,
FINALLY,
WITH,
DYNAMIC,
INTERNAL,
OVERRIDE,
PRIVATE,
PROTECTED,
PUBLIC,
STATIC,
CLASS,
CONST,
EXTENDS,
FUNCTION(GraphTargetItem.PRECEDENCE_PRIMARY, false),
GET,
IMPLEMENTS,
INTERFACE,
NAMESPACE,
PACKAGE,
SET,
VAR,
IMPORT,
USE,
FALSE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
NULL(GraphTargetItem.PRECEDENCE_PRIMARY, false),
THIS(GraphTargetItem.PRECEDENCE_PRIMARY, false),
TRUE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
//Operators
PARENT_OPEN(GraphTargetItem.PRECEDENCE_PRIMARY, false),
PARENT_CLOSE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
CURLY_OPEN(GraphTargetItem.PRECEDENCE_PRIMARY, false),
CURLY_CLOSE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
BRACKET_OPEN(GraphTargetItem.PRECEDENCE_PRIMARY, false),
BRACKET_CLOSE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
SEMICOLON,
COMMA(GraphTargetItem.PRECEDENCE_COMMA, false),
REST,
DOT(GraphTargetItem.PRECEDENCE_PRIMARY, false),
ASSIGN(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
GREATER_THAN(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
LOWER_THAN(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
NOT(GraphTargetItem.PRECEDENCE_UNARY, false),
NEGATE(GraphTargetItem.PRECEDENCE_UNARY, false),
TERNAR(GraphTargetItem.PRECEDENCE_CONDITIONAL, true, true), /*!! ternar !!!*/
COLON(GraphTargetItem.PRECEDENCE_CONDITIONAL, false),/*!! ternar !!!*/
EQUALS(GraphTargetItem.PRECEDENCE_EQUALITY, true),
STRICT_EQUALS(GraphTargetItem.PRECEDENCE_EQUALITY, true),
LOWER_EQUAL(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
GREATER_EQUAL(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
NOT_EQUAL(GraphTargetItem.PRECEDENCE_EQUALITY, true),
STRICT_NOT_EQUAL(GraphTargetItem.PRECEDENCE_EQUALITY, true),
AND(GraphTargetItem.PRECEDENCE_LOGICALAND, true),
OR(GraphTargetItem.PRECEDENCE_LOGICALOR, true),
INCREMENT(GraphTargetItem.PRECEDENCE_POSTFIX, false),//OR Unary
DECREMENT(GraphTargetItem.PRECEDENCE_POSTFIX, false), //OR Unary
PLUS(GraphTargetItem.PRECEDENCE_ADDITIVE, true),
MINUS(GraphTargetItem.PRECEDENCE_ADDITIVE, true), //OR Unary
MULTIPLY(GraphTargetItem.PRECEDENCE_MULTIPLICATIVE, true),
DIVIDE(GraphTargetItem.PRECEDENCE_MULTIPLICATIVE, true),
BITAND(GraphTargetItem.PRECEDENCE_BITWISEAND, true),
BITOR(GraphTargetItem.PRECEDENCE_BITWISEOR, true),
XOR(GraphTargetItem.PRECEDENCE_BITWISEXOR, true),
MODULO(GraphTargetItem.PRECEDENCE_BITWISESHIFT, true),
SHIFT_LEFT(GraphTargetItem.PRECEDENCE_BITWISESHIFT, true),
SHIFT_RIGHT(GraphTargetItem.PRECEDENCE_BITWISESHIFT, true),
USHIFT_RIGHT(GraphTargetItem.PRECEDENCE_BITWISESHIFT, true),
ASSIGN_PLUS(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_MINUS(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_MULTIPLY(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_DIVIDE(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_BITAND(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_BITOR(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_XOR(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_MODULO(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_SHIFT_LEFT(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_SHIFT_RIGHT(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_USHIFT_RIGHT(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
AS(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
DELETE(GraphTargetItem.PRECEDENCE_UNARY, false),
INSTANCEOF(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
IS(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
NAMESPACE_OP(GraphTargetItem.PRECEDENCE_PRIMARY, false),
NEW(GraphTargetItem.PRECEDENCE_PRIMARY, false),
TYPEOF(GraphTargetItem.PRECEDENCE_UNARY, false),
VOID,
ATTRIBUTE,
//Other
STRING(GraphTargetItem.PRECEDENCE_PRIMARY, false),
COMMENT,
//XML,
IDENTIFIER(GraphTargetItem.PRECEDENCE_PRIMARY, false),
INTEGER(GraphTargetItem.PRECEDENCE_PRIMARY, false),
DOUBLE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
TYPENAME(GraphTargetItem.PRECEDENCE_PRIMARY, false),
EOF,
//TRACE,
//GETURL,
//GOTOANDSTOP,
//NEXTFRAME,
//PLAY,
//PREVFRAME,
//TELLTARGET,
//STOP,
//STOPALLSOUNDS,
//TOGGLEHIGHQUALITY,
//ORD,
//CHR,
//DUPLICATEMOVIECLIP,
//STOPDRAG,
//GETTIMER,
//LOADVARIABLES,
//LOADMOVIE,
//GOTOANDPLAY,
//MBORD,
//MBCHR,
//MBLENGTH,
//MBSUBSTRING,
//RANDOM,
//REMOVEMOVIECLIP,
//STARTDRAG,
//SUBSTR,
//LENGTH, //string.length
INT(GraphTargetItem.PRECEDENCE_PRIMARY, false),
//TARGETPATH,
NUMBER_OP(GraphTargetItem.PRECEDENCE_PRIMARY, false),
STRING_OP(GraphTargetItem.PRECEDENCE_PRIMARY, false),
//IFFRAMELOADED,
INFINITY(GraphTargetItem.PRECEDENCE_PRIMARY, false),
//EVAL,
UNDEFINED(GraphTargetItem.PRECEDENCE_PRIMARY, false),
//NEWLINE,
NAN(GraphTargetItem.PRECEDENCE_PRIMARY, false),
//GETVERSION,
//CALL,
//LOADMOVIENUM,
//LOADVARIABLESNUM,
//PRINT,
//PRINTNUM,
//PRINTASBITMAP,
//PRINTASBITMAPNUM,
//UNLOADMOVIE,
//UNLOADMOVIENUM,
FINAL,
XML_STARTTAG_BEGIN(GraphTargetItem.PRECEDENCE_PRIMARY, false), // <xxx
XML_STARTVARTAG_BEGIN(GraphTargetItem.PRECEDENCE_PRIMARY, false), // <{
XML_STARTTAG_END(GraphTargetItem.PRECEDENCE_PRIMARY, false), // >
XML_FINISHVARTAG_BEGIN(GraphTargetItem.PRECEDENCE_PRIMARY, false), // </{
XML_FINISHTAG(GraphTargetItem.PRECEDENCE_PRIMARY, false), // </xxx>
XML_STARTFINISHTAG_END(GraphTargetItem.PRECEDENCE_PRIMARY, false), // />
XML_COMMENT(GraphTargetItem.PRECEDENCE_PRIMARY, false), // <!-- ... -->
XML_CDATA(GraphTargetItem.PRECEDENCE_PRIMARY, false), //<![CDATA[ ... ]]>
XML_INSTR_BEGIN(GraphTargetItem.PRECEDENCE_PRIMARY, false), // <?xxx
XML_INSTR_END(GraphTargetItem.PRECEDENCE_PRIMARY, false), // ?>
XML_VAR_BEGIN(GraphTargetItem.PRECEDENCE_PRIMARY, false), // {
XML_ATTRIBUTENAME(GraphTargetItem.PRECEDENCE_PRIMARY, false), // aaa=
XML_ATTRIBUTEVALUE(GraphTargetItem.PRECEDENCE_PRIMARY, false), // "vvv"
XML_TEXT(GraphTargetItem.PRECEDENCE_PRIMARY, false),
XML_ATTRNAMEVAR_BEGIN(GraphTargetItem.PRECEDENCE_PRIMARY, false), // {...}=
XML_ATTRVALVAR_BEGIN(GraphTargetItem.PRECEDENCE_PRIMARY, false), // aaa={
XML_INSTRATTRNAMEVAR_BEGIN(GraphTargetItem.PRECEDENCE_PRIMARY, false), // {...}=
XML_INSTRATTRVALVAR_BEGIN(GraphTargetItem.PRECEDENCE_PRIMARY, false), // aaa={
XML_INSTRVARTAG_BEGIN(GraphTargetItem.PRECEDENCE_PRIMARY, false), // <?{
FILTER(GraphTargetItem.PRECEDENCE_PRIMARY, false),
DESCENDANTS(GraphTargetItem.PRECEDENCE_PRIMARY, false),
NATIVE,
PREPROCESSOR(GraphTargetItem.PRECEDENCE_PRIMARY, false);
private int precedence = GraphTargetItem.NOPRECEDENCE;
private boolean binary = false;
private boolean rightAssociative = false;
public boolean isBinary() {
return binary;
}
public boolean isRightAssociative() {
return rightAssociative;
}
public int getPrecedence() {
return precedence;
}
private SymbolType(int precedence, boolean binary) {
this.precedence = precedence;
this.binary = binary;
}
private SymbolType(int precedence, boolean binary, boolean rightAssociative) {
this.precedence = precedence;
this.binary = binary;
this.rightAssociative = rightAssociative;
}
private SymbolType() {
}
}

View File

@@ -1,487 +1,487 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.action;
import com.jpexs.decompiler.flash.BaseLocalData;
import com.jpexs.decompiler.flash.FinalProcessLocalData;
import com.jpexs.decompiler.flash.action.model.DirectValueActionItem;
import com.jpexs.decompiler.flash.action.model.EnumerateActionItem;
import com.jpexs.decompiler.flash.action.model.FunctionActionItem;
import com.jpexs.decompiler.flash.action.model.SetTarget2ActionItem;
import com.jpexs.decompiler.flash.action.model.SetTargetActionItem;
import com.jpexs.decompiler.flash.action.model.SetTypeActionItem;
import com.jpexs.decompiler.flash.action.model.StoreRegisterActionItem;
import com.jpexs.decompiler.flash.action.model.clauses.ForInActionItem;
import com.jpexs.decompiler.flash.action.model.clauses.TellTargetActionItem;
import com.jpexs.decompiler.flash.action.model.operations.NeqActionItem;
import com.jpexs.decompiler.flash.action.model.operations.StrictEqActionItem;
import com.jpexs.decompiler.flash.action.swf4.ActionEquals;
import com.jpexs.decompiler.flash.action.swf4.ActionIf;
import com.jpexs.decompiler.flash.action.swf4.ActionNot;
import com.jpexs.decompiler.flash.action.swf4.ActionPush;
import com.jpexs.decompiler.flash.action.swf4.RegisterNumber;
import com.jpexs.decompiler.flash.action.swf5.ActionEquals2;
import com.jpexs.decompiler.flash.action.swf5.ActionStoreRegister;
import com.jpexs.decompiler.flash.action.swf6.ActionStrictEquals;
import com.jpexs.decompiler.flash.ecma.Null;
import com.jpexs.decompiler.graph.Graph;
import com.jpexs.decompiler.graph.GraphPart;
import com.jpexs.decompiler.graph.GraphSource;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.Loop;
import com.jpexs.decompiler.graph.TranslateStack;
import com.jpexs.decompiler.graph.model.BreakItem;
import com.jpexs.decompiler.graph.model.ContinueItem;
import com.jpexs.decompiler.graph.model.SwitchItem;
import com.jpexs.decompiler.graph.model.WhileItem;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
*
* @author JPEXS
*/
public class ActionGraph extends Graph {
public ActionGraph(List<Action> code, HashMap<Integer, String> registerNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, int version) {
super(new ActionGraphSource(code, version, registerNames, variables, functions), new ArrayList<Integer>());
//this.version = version;
/*heads = makeGraph(code, new ArrayList<GraphPart>());
for (GraphPart head : heads) {
fixGraph(head);
makeMulti(head, new ArrayList<GraphPart>());
}*/
}
public static List<GraphTargetItem> translateViaGraph(HashMap<Integer, String> registerNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, List<Action> code, int version, int staticOperation, String path) throws InterruptedException {
ActionGraph g = new ActionGraph(code, registerNames, variables, functions, version);
ActionLocalData localData = new ActionLocalData(registerNames);
g.init(localData);
return g.translate(localData, staticOperation, path);
}
@Override
public void finalProcessStack(TranslateStack stack, List<GraphTargetItem> output) {
if (stack.size() > 0) {
for (int i = stack.size() - 1; i >= 0; i--) {
//System.err.println(stack.get(i));
if (stack.get(i) instanceof FunctionActionItem) {
FunctionActionItem f = (FunctionActionItem) stack.remove(i);
if (!output.contains(f)) {
output.add(0, f);
}
}
}
}
}
@Override
protected void finalProcess(List<GraphTargetItem> list, int level, FinalProcessLocalData localData) {
super.finalProcess(list, level, localData);
List<GraphTargetItem> ret = Action.checkClass(list);
if (ret != list) {
list.clear();
list.addAll(ret);
}
int targetStart;
int targetEnd;
boolean again;
do {
again = false;
targetStart = -1;
targetEnd = -1;
GraphTargetItem targetStartItem = null;
GraphTargetItem target = null;
for (int t = 0; t < list.size(); t++) {
GraphTargetItem it = list.get(t);
if (it instanceof SetTargetActionItem) {
SetTargetActionItem st = (SetTargetActionItem) it;
if (st.target.isEmpty()) {
if (targetStart > -1) {
targetEnd = t;
break;
}
} else {
target = new DirectValueActionItem(null, 0, st.target, new ArrayList<>());
targetStart = t;
targetStartItem = it;
}
}
if (it instanceof SetTarget2ActionItem) {
SetTarget2ActionItem st = (SetTarget2ActionItem) it;
if ((st.target instanceof DirectValueActionItem) && st.target.getResult().equals("")) {
if (targetStart > -1) {
targetEnd = t;
break;
}
} else {
targetStart = t;
target = st.target;
targetStartItem = it;
}
}
}
if ((targetStart > -1) && (targetEnd > -1)) {
List<GraphTargetItem> newlist = new ArrayList<>();
for (int i = 0; i < targetStart; i++) {
newlist.add(list.get(i));
}
List<GraphTargetItem> tellist = new ArrayList<>();
for (int i = targetStart + 1; i < targetEnd; i++) {
tellist.add(list.get(i));
}
newlist.add(new TellTargetActionItem(targetStartItem.src, target, tellist));
for (int i = targetEnd + 1; i < list.size(); i++) {
newlist.add(list.get(i));
}
list.clear();
list.addAll(newlist);
again = true;
}
} while (again);
for (int t = 0; t < list.size(); t++) {
GraphTargetItem it = list.get(t);
if (it instanceof WhileItem) {
WhileItem wi = (WhileItem) it;
if ((!wi.commands.isEmpty()) && (wi.commands.get(0) instanceof SetTypeActionItem)) {
SetTypeActionItem sti = (SetTypeActionItem) wi.commands.get(0);
if (wi.expression.get(wi.expression.size() - 1) instanceof NeqActionItem) {
NeqActionItem ne = (NeqActionItem) wi.expression.get(wi.expression.size() - 1);
if (ne.rightSide instanceof DirectValueActionItem) {
DirectValueActionItem dv = (DirectValueActionItem) ne.rightSide;
if (dv.value instanceof Null) {
GraphTargetItem en = ne.leftSide;
if (en instanceof StoreRegisterActionItem) {
en = ((StoreRegisterActionItem) en).value;
}
if (en instanceof EnumerateActionItem) {
EnumerateActionItem eti = (EnumerateActionItem) en;
list.remove(t);
wi.commands.remove(0);
list.add(t, new ForInActionItem(null, wi.loop, sti.getObject(), eti.object, wi.commands));
}
}
}
}
}
}
}
//detectChained(list, temporaryRegisters);
}
@Override
protected List<GraphPart> checkPrecoNextParts(GraphPart part) {
List<GraphSourceItem> items = getPartItems(part);
part = makeMultiPart(part);
if (items.size() > 1) {
if (items.get(items.size() - 1) instanceof ActionIf) {
if (items.get(items.size() - 2) instanceof ActionStrictEquals) {
List<Integer> storeRegisters = new ArrayList<>();
for (GraphSourceItem s : items) {
if (s instanceof ActionStoreRegister) {
ActionStoreRegister sr = (ActionStoreRegister) s;
storeRegisters.add(sr.registerNumber);
}
}
if (!storeRegisters.isEmpty()) {
List<GraphPart> caseBodies = new ArrayList<>();
boolean proceed = false;
do {
proceed = false;
caseBodies.add(part.nextParts.get(0)); //jump
part = part.nextParts.get(1); //nojump
items = getPartItems(part);
part = makeMultiPart(part);
if (!items.isEmpty()) {
if (items.get(0) instanceof ActionPush) {
ActionPush pu = (ActionPush) items.get(0);
if (!pu.values.isEmpty()) {
if (pu.values.get(0) instanceof RegisterNumber) {
RegisterNumber rn = (RegisterNumber) pu.values.get(0);
if (storeRegisters.contains(rn.number)) {
storeRegisters.clear();
storeRegisters.add(rn.number);
if (items.get(items.size() - 1) instanceof ActionIf) {
if (items.size() > 1) {
if (items.get(items.size() - 2) instanceof ActionStrictEquals) {
proceed = true;
}
}
}
}
}
}
}
}
} while (proceed);
if (caseBodies.size() > 1) {
caseBodies.add(part); //TODO: properly detect default clause (?)
return caseBodies;
}
}
}
}
}
return null;
}
@Override
protected List<GraphTargetItem> check(GraphSource code, BaseLocalData localData, List<GraphPart> allParts, TranslateStack stack, GraphPart parent, GraphPart part, List<GraphPart> stopPart, List<Loop> loops, List<GraphTargetItem> output, Loop currentLoop, int staticOperation, String path) throws InterruptedException {
if (!output.isEmpty()) {
if (output.get(output.size() - 1) instanceof StoreRegisterActionItem) {
StoreRegisterActionItem str = (StoreRegisterActionItem) output.get(output.size() - 1);
if (str.value instanceof EnumerateActionItem) {
output.remove(output.size() - 1);
}
}
}
List<GraphTargetItem> ret = null;
if ((part.nextParts.size() == 2) && (!stack.isEmpty()) && (stack.peek() instanceof StrictEqActionItem)) {
GraphTargetItem switchedObject = null;
if (!output.isEmpty()) {
if (output.get(output.size() - 1) instanceof StoreRegisterActionItem) {
switchedObject = ((StoreRegisterActionItem) output.get(output.size() - 1)).value;
}
}
if (switchedObject == null) {
switchedObject = new DirectValueActionItem(null, -1, new Null(), null);
}
HashMap<Integer, GraphTargetItem> caseValuesMap = new HashMap<>();
int pos = 0;
StrictEqActionItem set = (StrictEqActionItem) stack.pop();
caseValuesMap.put(pos, set.rightSide);
if (set.leftSide instanceof StoreRegisterActionItem) {
switchedObject = ((StoreRegisterActionItem) set.leftSide).value;
}
//GraphPart switchLoc = part.nextParts.get(1).nextParts.get(0);
List<GraphPart> caseBodyParts = new ArrayList<>();
caseBodyParts.add(part.nextParts.get(0));
GraphTargetItem top = null;
int cnt = 1;
while (part.nextParts.size() > 1
&& part.nextParts.get(1).getHeight() > 1
&& code.get(part.nextParts.get(1).end >= code.size() ? code.size() - 1 : part.nextParts.get(1).end) instanceof ActionIf
&& ((top = translatePartGetStack(localData, part.nextParts.get(1), stack, staticOperation)) instanceof StrictEqActionItem)) {
cnt++;
part = part.nextParts.get(1);
pos++;
caseBodyParts.add(part.nextParts.get(0));
set = (StrictEqActionItem) top;
caseValuesMap.put(pos, set.rightSide);
}
if (cnt == 1) {
stack.push(set);
} else {
part = part.nextParts.get(1);
GraphPart defaultPart = part; //21-21
//caseBodyParts.add(defaultPart);
List<GraphPart> defaultAndLastPart = new ArrayList<>();
defaultAndLastPart.add(defaultPart);
defaultAndLastPart.add(caseBodyParts.get(caseBodyParts.size() - 1));
GraphPart defaultPart2 = getCommonPart(localData, defaultAndLastPart, loops);//34-37
List<GraphTargetItem> defaultCommands = new ArrayList<>();
List<GraphPart> stopPart2 = new ArrayList<>(stopPart);
stopPart2.add(defaultPart2);
defaultCommands = printGraph(localData, stack, allParts, null, defaultPart, stopPart2, loops, staticOperation, path);
List<GraphPart> loopContinues = new ArrayList<>();
for (Loop l : loops) {
if (l.loopContinue != null) {
loopContinues.add(l.loopContinue);
}
}
List<GraphPart> breakParts = new ArrayList<>();
/*for (int g = 0; g < caseBodyParts.size(); g++) {
if (g < caseBodyParts.size() - 1) {
if (caseBodyParts.get(g).leadsTo(code, caseBodyParts.get(g + 1), loops)) {
continue;
}
}
GraphPart nsp = caseBodyParts.get(g).getNextSuperPartPath(loopContinues);
if (nsp != null) {
breakParts.add(nsp);
}
}
Collections.sort(breakParts, new Comparator<GraphPart>() {
@Override
public int compare(GraphPart o1, GraphPart o2) {
return o2.path.length() - o1.path.length();
}
});*/
//GraphPart breakPart = breakParts.isEmpty() ? null : breakParts.get(0);
List<GraphPart> mcp = new ArrayList<>();
mcp.addAll(caseBodyParts);
if (defaultPart2 != null) {
mcp.add(defaultPart2);
}
GraphPart breakPart = getMostCommonPart(localData, mcp, loops);
if ((defaultPart2 != breakPart) && (defaultCommands.isEmpty())) {
defaultPart = defaultPart2;
}
List<GraphTargetItem> caseValues = new ArrayList<>();
for (int i = 0; i < caseBodyParts.size(); i++) {
if (caseValuesMap.containsKey(i)) {
caseValues.add(caseValuesMap.get(i));
} else {
continue;
}
}
List<List<GraphTargetItem>> caseCommands = new ArrayList<>();
GraphPart next = null;
next = breakPart;
GraphTargetItem ti = checkLoop(next, stopPart, loops);
currentLoop = new Loop(loops.size(), null, next);
currentLoop.phase = 1;
loops.add(currentLoop);
//switchLoc.getNextPartPath(new ArrayList<GraphPart>());
List<Integer> valuesMapping = new ArrayList<>();
List<GraphPart> caseBodies = new ArrayList<>();
for (int i = 0; i < caseValues.size(); i++) {
GraphPart cur = caseBodyParts.get(i);
if (!caseBodies.contains(cur)) {
caseBodies.add(cur);
}
valuesMapping.add(caseBodies.indexOf(cur));
}
if (defaultPart == breakPart) {
defaultPart = null;
}
if ((defaultPart != null) && (defaultCommands.isEmpty())) {
List<GraphPart> stopPart2x = new ArrayList<>(stopPart);
stopPart2x.add(next);
defaultCommands = printGraph(localData, stack, allParts, null, defaultPart, stopPart2x, loops, staticOperation, path);
}
if (!defaultCommands.isEmpty()) {
if (defaultCommands.get(defaultCommands.size() - 1) instanceof BreakItem) {
BreakItem bi = (BreakItem) defaultCommands.get(defaultCommands.size() - 1);
if (bi.loopId == currentLoop.id) {
defaultCommands.remove(defaultCommands.size() - 1);
}
}
}
List<GraphPart> ignored = new ArrayList<>();
for (Loop l : loops) {
ignored.add(l.loopContinue);
}
for (int i = 0; i < caseBodies.size(); i++) {
List<GraphTargetItem> cc = new ArrayList<>();
GraphPart nextCase = null;
nextCase = next;
if (next != null) {
if (i < caseBodies.size() - 1) {
if (!caseBodies.get(i).leadsTo(localData, this, code, caseBodies.get(i + 1), loops)) {
cc.add(new BreakItem(null, currentLoop.id));
} else {
nextCase = caseBodies.get(i + 1);
}
} else if (!defaultCommands.isEmpty()) {
if (!caseBodies.get(i).leadsTo(localData, this, code, defaultPart, loops)) {
cc.add(new BreakItem(null, currentLoop.id));
} else {
nextCase = defaultPart;
}
}
}
List<GraphPart> stopPart2x = new ArrayList<>(stopPart);
//stopPart2.add(nextCase);
for (GraphPart b : caseBodies) {
if (b != caseBodies.get(i)) {
stopPart2x.add(b);
}
}
if (defaultPart != null) {
stopPart2x.add(defaultPart);
}
if (breakPart != null) {
stopPart2x.add(breakPart);
}
cc.addAll(0, printGraph(localData, stack, allParts, null, caseBodies.get(i), stopPart2x, loops, staticOperation, path));
if (cc.size() >= 2) {
if (cc.get(cc.size() - 1) instanceof BreakItem) {
if ((cc.get(cc.size() - 2) instanceof ContinueItem) || (cc.get(cc.size() - 2) instanceof BreakItem)) {
cc.remove(cc.size() - 1);
}
}
}
caseCommands.add(cc);
}
ret = new ArrayList<>();
ret.addAll(output);
SwitchItem sti = new SwitchItem(null, currentLoop, switchedObject, caseValues, caseCommands, defaultCommands, valuesMapping);
ret.add(sti);
currentLoop.phase = 2;
if (next != null) {
if (ti != null) {
ret.add(ti);
} else {
ret.addAll(printGraph(localData, stack, allParts, null, next, stopPart, loops, staticOperation, path));
}
}
}
}
return ret;
}
@Override
protected int checkIp(int ip) {
int oldIp = ip;
//return in for..in
GraphSourceItem action = code.get(ip);
if ((action instanceof ActionPush) && (((ActionPush) action).values.size() == 1) && (((ActionPush) action).values.get(0) instanceof Null)) {
if (ip + 3 < code.size()) {
if ((code.get(ip + 1) instanceof ActionEquals) || (code.get(ip + 1) instanceof ActionEquals2)) {
if (code.get(ip + 2) instanceof ActionNot) {
if (code.get(ip + 3) instanceof ActionIf) {
ActionIf aif = (ActionIf) code.get(ip + 3);
if (code.adr2pos(code.pos2adr(ip + 4) + aif.getJumpOffset()) == ip) {
ip += 4;
}
}
}
}
}
}
if (oldIp != ip) {
return checkIp(ip);
}
return ip;
}
}
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.action;
import com.jpexs.decompiler.flash.BaseLocalData;
import com.jpexs.decompiler.flash.FinalProcessLocalData;
import com.jpexs.decompiler.flash.action.model.DirectValueActionItem;
import com.jpexs.decompiler.flash.action.model.EnumerateActionItem;
import com.jpexs.decompiler.flash.action.model.FunctionActionItem;
import com.jpexs.decompiler.flash.action.model.SetTarget2ActionItem;
import com.jpexs.decompiler.flash.action.model.SetTargetActionItem;
import com.jpexs.decompiler.flash.action.model.SetTypeActionItem;
import com.jpexs.decompiler.flash.action.model.StoreRegisterActionItem;
import com.jpexs.decompiler.flash.action.model.clauses.ForInActionItem;
import com.jpexs.decompiler.flash.action.model.clauses.TellTargetActionItem;
import com.jpexs.decompiler.flash.action.model.operations.NeqActionItem;
import com.jpexs.decompiler.flash.action.model.operations.StrictEqActionItem;
import com.jpexs.decompiler.flash.action.swf4.ActionEquals;
import com.jpexs.decompiler.flash.action.swf4.ActionIf;
import com.jpexs.decompiler.flash.action.swf4.ActionNot;
import com.jpexs.decompiler.flash.action.swf4.ActionPush;
import com.jpexs.decompiler.flash.action.swf4.RegisterNumber;
import com.jpexs.decompiler.flash.action.swf5.ActionEquals2;
import com.jpexs.decompiler.flash.action.swf5.ActionStoreRegister;
import com.jpexs.decompiler.flash.action.swf6.ActionStrictEquals;
import com.jpexs.decompiler.flash.ecma.Null;
import com.jpexs.decompiler.graph.Graph;
import com.jpexs.decompiler.graph.GraphPart;
import com.jpexs.decompiler.graph.GraphSource;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.Loop;
import com.jpexs.decompiler.graph.TranslateStack;
import com.jpexs.decompiler.graph.model.BreakItem;
import com.jpexs.decompiler.graph.model.ContinueItem;
import com.jpexs.decompiler.graph.model.PopItem;
import com.jpexs.decompiler.graph.model.SwitchItem;
import com.jpexs.decompiler.graph.model.WhileItem;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
*
* @author JPEXS
*/
public class ActionGraph extends Graph {
public ActionGraph(List<Action> code, HashMap<Integer, String> registerNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, int version) {
super(new ActionGraphSource(code, version, registerNames, variables, functions), new ArrayList<Integer>());
//this.version = version;
/*heads = makeGraph(code, new ArrayList<GraphPart>());
for (GraphPart head : heads) {
fixGraph(head);
makeMulti(head, new ArrayList<GraphPart>());
}*/
}
public static List<GraphTargetItem> translateViaGraph(HashMap<Integer, String> registerNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, List<Action> code, int version, int staticOperation, String path) throws InterruptedException {
ActionGraph g = new ActionGraph(code, registerNames, variables, functions, version);
ActionLocalData localData = new ActionLocalData(registerNames);
g.init(localData);
return g.translate(localData, staticOperation, path);
}
@Override
public void finalProcessStack(TranslateStack stack, List<GraphTargetItem> output) {
if (stack.size() > 0) {
for (int i = stack.size() - 1; i >= 0; i--) {
//System.err.println(stack.get(i));
if (stack.get(i) instanceof FunctionActionItem) {
FunctionActionItem f = (FunctionActionItem) stack.remove(i);
if (!output.contains(f)) {
output.add(0, f);
}
}
}
}
}
@Override
protected void finalProcess(List<GraphTargetItem> list, int level, FinalProcessLocalData localData) {
List<GraphTargetItem> ret = Action.checkClass(list);
if (ret != list) {
list.clear();
list.addAll(ret);
}
int targetStart;
int targetEnd;
boolean again;
do {
again = false;
targetStart = -1;
targetEnd = -1;
GraphTargetItem targetStartItem = null;
GraphTargetItem target = null;
for (int t = 0; t < list.size(); t++) {
GraphTargetItem it = list.get(t);
if (it instanceof SetTargetActionItem) {
SetTargetActionItem st = (SetTargetActionItem) it;
if (st.target.isEmpty()) {
if (targetStart > -1) {
targetEnd = t;
break;
}
} else {
target = new DirectValueActionItem(null, 0, st.target, new ArrayList<String>());
targetStart = t;
targetStartItem = it;
}
}
if (it instanceof SetTarget2ActionItem) {
SetTarget2ActionItem st = (SetTarget2ActionItem) it;
if ((st.target instanceof DirectValueActionItem) && st.target.getResult().equals("")) {
if (targetStart > -1) {
targetEnd = t;
break;
}
} else {
targetStart = t;
target = st.target;
targetStartItem = it;
}
}
}
if ((targetStart > -1) && (targetEnd > -1)) {
List<GraphTargetItem> newlist = new ArrayList<>();
for (int i = 0; i < targetStart; i++) {
newlist.add(list.get(i));
}
List<GraphTargetItem> tellist = new ArrayList<>();
for (int i = targetStart + 1; i < targetEnd; i++) {
tellist.add(list.get(i));
}
newlist.add(new TellTargetActionItem(targetStartItem.src, target, tellist));
for (int i = targetEnd + 1; i < list.size(); i++) {
newlist.add(list.get(i));
}
list.clear();
list.addAll(newlist);
again = true;
}
} while (again);
for (int t = 1/*not first*/; t < list.size(); t++) {
GraphTargetItem it = list.get(t);
if (it instanceof WhileItem) {
WhileItem wi = (WhileItem) it;
if ((!wi.commands.isEmpty()) && (wi.commands.get(0) instanceof SetTypeActionItem)) {
SetTypeActionItem sti = (SetTypeActionItem) wi.commands.get(0);
if (wi.expression.get(wi.expression.size() - 1) instanceof NeqActionItem) {
NeqActionItem ne = (NeqActionItem) wi.expression.get(wi.expression.size() - 1);
if (ne.rightSide instanceof DirectValueActionItem) {
DirectValueActionItem dv = (DirectValueActionItem) ne.rightSide;
if (dv.value instanceof Null) {
GraphTargetItem en = list.get(t - 1);
if (en instanceof EnumerateActionItem) {
EnumerateActionItem eti = (EnumerateActionItem) en;
list.remove(t);
wi.commands.remove(0);
list.add(t, new ForInActionItem(null, wi.loop, sti.getObject(), eti.object, wi.commands));
list.remove(t - 1);
t--;
}
}
}
}
}
}
}
//Handle for loops at the end:
super.finalProcess(list, level, localData);
}
@Override
protected List<GraphPart> checkPrecoNextParts(GraphPart part) {
List<GraphSourceItem> items = getPartItems(part);
part = makeMultiPart(part);
if (items.size() > 1) {
if (items.get(items.size() - 1) instanceof ActionIf) {
if (items.get(items.size() - 2) instanceof ActionStrictEquals) {
List<Integer> storeRegisters = new ArrayList<>();
for (GraphSourceItem s : items) {
if (s instanceof ActionStoreRegister) {
ActionStoreRegister sr = (ActionStoreRegister) s;
storeRegisters.add(sr.registerNumber);
}
}
if (!storeRegisters.isEmpty()) {
List<GraphPart> caseBodies = new ArrayList<>();
boolean proceed = false;
do {
proceed = false;
caseBodies.add(part.nextParts.get(0)); //jump
part = part.nextParts.get(1); //nojump
items = getPartItems(part);
part = makeMultiPart(part);
if (!items.isEmpty()) {
if (items.get(0) instanceof ActionPush) {
ActionPush pu = (ActionPush) items.get(0);
if (!pu.values.isEmpty()) {
if (pu.values.get(0) instanceof RegisterNumber) {
RegisterNumber rn = (RegisterNumber) pu.values.get(0);
if (storeRegisters.contains(rn.number)) {
storeRegisters.clear();
storeRegisters.add(rn.number);
if (items.get(items.size() - 1) instanceof ActionIf) {
if (items.size() > 1) {
if (items.get(items.size() - 2) instanceof ActionStrictEquals) {
proceed = true;
}
}
}
}
}
}
}
}
} while (proceed);
if (caseBodies.size() > 1) {
caseBodies.add(part); //TODO: properly detect default clause (?)
return caseBodies;
}
}
}
}
}
return null;
}
@Override
protected List<GraphTargetItem> check(GraphSource code, BaseLocalData localData, List<GraphPart> allParts, TranslateStack stack, GraphPart parent, GraphPart part, List<GraphPart> stopPart, List<Loop> loops, List<GraphTargetItem> output, Loop currentLoop, int staticOperation, String path) throws InterruptedException {
if (!output.isEmpty()) {
if (output.get(output.size() - 1) instanceof StoreRegisterActionItem) {
StoreRegisterActionItem str = (StoreRegisterActionItem) output.get(output.size() - 1);
if (str.value instanceof EnumerateActionItem) {
output.remove(output.size() - 1);
}
}
}
List<GraphTargetItem> ret = null;
if ((part.nextParts.size() == 2) && (!stack.isEmpty()) && (stack.peek() instanceof StrictEqActionItem)) {
GraphTargetItem switchedObject = null;
if (!output.isEmpty()) {
if (output.get(output.size() - 1) instanceof StoreRegisterActionItem) {
switchedObject = ((StoreRegisterActionItem) output.get(output.size() - 1)).value;
}
}
if (switchedObject == null) {
switchedObject = new DirectValueActionItem(null, -1, new Null(), null);
}
HashMap<Integer, GraphTargetItem> caseValuesMap = new HashMap<>();
int pos = 0;
StrictEqActionItem set = (StrictEqActionItem) stack.pop();
caseValuesMap.put(pos, set.rightSide);
if (set.leftSide instanceof StoreRegisterActionItem) {
switchedObject = ((StoreRegisterActionItem) set.leftSide).value;
}
//GraphPart switchLoc = part.nextParts.get(1).nextParts.get(0);
List<GraphPart> caseBodyParts = new ArrayList<>();
caseBodyParts.add(part.nextParts.get(0));
GraphTargetItem top = null;
int cnt = 1;
while (part.nextParts.size() > 1
&& part.nextParts.get(1).getHeight() > 1
&& code.get(part.nextParts.get(1).end >= code.size() ? code.size() - 1 : part.nextParts.get(1).end) instanceof ActionIf
&& ((top = translatePartGetStack(localData, part.nextParts.get(1), stack, staticOperation)) instanceof StrictEqActionItem)) {
cnt++;
part = part.nextParts.get(1);
pos++;
caseBodyParts.add(part.nextParts.get(0));
set = (StrictEqActionItem) top;
caseValuesMap.put(pos, set.rightSide);
}
if (cnt == 1) {
stack.push(set);
} else {
part = part.nextParts.get(1);
GraphPart defaultPart = part; //21-21
//caseBodyParts.add(defaultPart);
List<GraphPart> defaultAndLastPart = new ArrayList<>();
defaultAndLastPart.add(defaultPart);
defaultAndLastPart.add(caseBodyParts.get(caseBodyParts.size() - 1));
GraphPart defaultPart2 = getCommonPart(localData, defaultAndLastPart, loops);//34-37
List<GraphTargetItem> defaultCommands = new ArrayList<>();
List<GraphPart> stopPart2 = new ArrayList<>(stopPart);
stopPart2.add(defaultPart2);
defaultCommands = printGraph(localData, stack, allParts, null, defaultPart, stopPart2, loops, staticOperation, path);
List<GraphPart> loopContinues = new ArrayList<>();
for (Loop l : loops) {
if (l.loopContinue != null) {
loopContinues.add(l.loopContinue);
}
}
List<GraphPart> breakParts = new ArrayList<>();
/*for (int g = 0; g < caseBodyParts.size(); g++) {
if (g < caseBodyParts.size() - 1) {
if (caseBodyParts.get(g).leadsTo(code, caseBodyParts.get(g + 1), loops)) {
continue;
}
}
GraphPart nsp = caseBodyParts.get(g).getNextSuperPartPath(loopContinues);
if (nsp != null) {
breakParts.add(nsp);
}
}
Collections.sort(breakParts, new Comparator<GraphPart>() {
@Override
public int compare(GraphPart o1, GraphPart o2) {
return o2.path.length() - o1.path.length();
}
});*/
//GraphPart breakPart = breakParts.isEmpty() ? null : breakParts.get(0);
List<GraphPart> mcp = new ArrayList<>();
mcp.addAll(caseBodyParts);
if (defaultPart2 != null) {
mcp.add(defaultPart2);
}
GraphPart breakPart = getMostCommonPart(localData, mcp, loops);
if ((defaultPart2 != breakPart) && (defaultCommands.isEmpty())) {
defaultPart = defaultPart2;
}
List<GraphTargetItem> caseValues = new ArrayList<>();
for (int i = 0; i < caseBodyParts.size(); i++) {
if (caseValuesMap.containsKey(i)) {
caseValues.add(caseValuesMap.get(i));
} else {
continue;
}
}
List<List<GraphTargetItem>> caseCommands = new ArrayList<>();
GraphPart next = null;
next = breakPart;
GraphTargetItem ti = checkLoop(next, stopPart, loops);
currentLoop = new Loop(loops.size(), null, next);
currentLoop.phase = 1;
loops.add(currentLoop);
//switchLoc.getNextPartPath(new ArrayList<GraphPart>());
List<Integer> valuesMapping = new ArrayList<>();
List<GraphPart> caseBodies = new ArrayList<>();
for (int i = 0; i < caseValues.size(); i++) {
GraphPart cur = caseBodyParts.get(i);
if (!caseBodies.contains(cur)) {
caseBodies.add(cur);
}
valuesMapping.add(caseBodies.indexOf(cur));
}
if (defaultPart == breakPart) {
defaultPart = null;
}
if ((defaultPart != null) && (defaultCommands.isEmpty())) {
List<GraphPart> stopPart2x = new ArrayList<>(stopPart);
stopPart2x.add(next);
defaultCommands = printGraph(localData, stack, allParts, null, defaultPart, stopPart2x, loops, staticOperation, path);
}
if (!defaultCommands.isEmpty()) {
if (defaultCommands.get(defaultCommands.size() - 1) instanceof BreakItem) {
BreakItem bi = (BreakItem) defaultCommands.get(defaultCommands.size() - 1);
if (bi.loopId == currentLoop.id) {
defaultCommands.remove(defaultCommands.size() - 1);
}
}
}
List<GraphPart> ignored = new ArrayList<>();
for (Loop l : loops) {
ignored.add(l.loopContinue);
}
for (int i = 0; i < caseBodies.size(); i++) {
List<GraphTargetItem> cc = new ArrayList<>();
GraphPart nextCase = null;
nextCase = next;
if (next != null) {
if (i < caseBodies.size() - 1) {
if (!caseBodies.get(i).leadsTo(localData, this, code, caseBodies.get(i + 1), loops)) {
cc.add(new BreakItem(null, currentLoop.id));
} else {
nextCase = caseBodies.get(i + 1);
}
} else if (!defaultCommands.isEmpty()) {
if (!caseBodies.get(i).leadsTo(localData, this, code, defaultPart, loops)) {
cc.add(new BreakItem(null, currentLoop.id));
} else {
nextCase = defaultPart;
}
}
}
List<GraphPart> stopPart2x = new ArrayList<>(stopPart);
//stopPart2.add(nextCase);
for (GraphPart b : caseBodies) {
if (b != caseBodies.get(i)) {
stopPart2x.add(b);
}
}
if (defaultPart != null) {
stopPart2x.add(defaultPart);
}
if (breakPart != null) {
stopPart2x.add(breakPart);
}
cc.addAll(0, printGraph(localData, stack, allParts, null, caseBodies.get(i), stopPart2x, loops, staticOperation, path));
if (cc.size() >= 2) {
if (cc.get(cc.size() - 1) instanceof BreakItem) {
if ((cc.get(cc.size() - 2) instanceof ContinueItem) || (cc.get(cc.size() - 2) instanceof BreakItem)) {
cc.remove(cc.size() - 1);
}
}
}
caseCommands.add(cc);
}
ret = new ArrayList<>();
ret.addAll(output);
SwitchItem sti = new SwitchItem(null, currentLoop, switchedObject, caseValues, caseCommands, defaultCommands, valuesMapping);
ret.add(sti);
currentLoop.phase = 2;
if (next != null) {
if (ti != null) {
ret.add(ti);
} else {
ret.addAll(printGraph(localData, stack, allParts, null, next, stopPart, loops, staticOperation, path));
}
}
}
}
return ret;
}
@Override
protected int checkIp(int ip) {
int oldIp = ip;
//return in for..in
GraphSourceItem action = code.get(ip);
if ((action instanceof ActionPush) && (((ActionPush) action).values.size() == 1) && (((ActionPush) action).values.get(0) instanceof Null)) {
if (ip + 3 < code.size()) {
if ((code.get(ip + 1) instanceof ActionEquals) || (code.get(ip + 1) instanceof ActionEquals2)) {
if (code.get(ip + 2) instanceof ActionNot) {
if (code.get(ip + 3) instanceof ActionIf) {
ActionIf aif = (ActionIf) code.get(ip + 3);
if (code.adr2pos(code.pos2adr(ip + 4) + aif.getJumpOffset()) == ip) {
ip += 4;
}
}
}
}
}
}
if (oldIp != ip) {
return checkIp(ip);
}
return ip;
}
}

View File

@@ -223,7 +223,7 @@ public class ActionDeobfuscator extends ActionDeobfuscatorSimple {
private void executeActions(ActionList actions, int idx, int endIdx, ActionConstantPool constantPool, ExecutionResult result, Map<String, Object> fakeFunctions) {
List<GraphTargetItem> output = new ArrayList<>();
ActionLocalData localData = new ActionLocalData();
FixItemCounterTranslateStack stack = new FixItemCounterTranslateStack();
FixItemCounterTranslateStack stack = new FixItemCounterTranslateStack("");
int instructionsProcessed = 0;
ActionConstantPool lastConstantPool = null;
@@ -442,7 +442,7 @@ public class ActionDeobfuscator extends ActionDeobfuscatorSimple {
public Set<String> defines = new HashSet<>();
public TranslateStack stack = new TranslateStack();
public TranslateStack stack = new TranslateStack("?");
public Object resultValue;
}

View File

@@ -273,7 +273,7 @@ public class ActionDeobfuscatorSimple implements SWFDecompilerListener {
private void executeActions(ActionList actions, int idx, int endIdx, ExecutionResult result) {
List<GraphTargetItem> output = new ArrayList<>();
ActionLocalData localData = new ActionLocalData();
FixItemCounterTranslateStack stack = new FixItemCounterTranslateStack();
FixItemCounterTranslateStack stack = new FixItemCounterTranslateStack("");
int instructionsProcessed = 0;
try {
@@ -388,7 +388,7 @@ public class ActionDeobfuscatorSimple implements SWFDecompilerListener {
public int instructionsProcessed = -1;
public TranslateStack stack = new TranslateStack();
public TranslateStack stack = new TranslateStack("?");
public Object resultValue;
}

View File

@@ -1,18 +1,19 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.deobfuscation;
import com.jpexs.decompiler.graph.GraphTargetItem;
@@ -26,6 +27,10 @@ public class FixItemCounterTranslateStack extends TranslateStack {
private int fixItemCount = Integer.MAX_VALUE;
public FixItemCounterTranslateStack(String path) {
super(null); //null path => do not add PushItems
}
@Override
public GraphTargetItem pop() {
GraphTargetItem result = super.pop();

View File

@@ -26,6 +26,7 @@ import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SimpleValue;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.model.LocalData;
import com.jpexs.helpers.Helper;
@@ -34,7 +35,7 @@ import java.util.List;
import java.util.Objects;
import java.util.Set;
public class DirectValueActionItem extends ActionItem {
public class DirectValueActionItem extends ActionItem implements SimpleValue {
public Object value;
@@ -91,6 +92,11 @@ public class DirectValueActionItem extends ActionItem {
return value;
}
@Override
public boolean isSimpleValue() {
return !(value instanceof RegisterNumber);
}
@Override
public String toStringNoQuotes(LocalData localData) {
if (value instanceof Double) {

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.model;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
@@ -41,8 +42,9 @@ public class EnumerateActionItem extends ActionItem {
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.append("enumerate ");
writer.append("§§enumerate(");
object.toString(writer, localData);
return writer.append(")");
}
@Override

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -48,7 +49,7 @@ public class EqActionItem extends BinaryOpItem implements LogicalOpItem {
}
@Override
@Override
public GraphTargetItem invert(GraphSourceItem neqSrc) {
return new NeqActionItem(src, leftSide, rightSide, version2);
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -58,7 +59,7 @@ public class GeActionItem extends BinaryOpItem implements LogicalOpItem, Inverte
}
@Override
@Override
public GraphTargetItem invert(GraphSourceItem negSrc) {
return new LtActionItem(src, leftSide, rightSide, version2);
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -42,7 +43,7 @@ public class GtActionItem extends BinaryOpItem implements LogicalOpItem {
}
@Override
@Override
public GraphTargetItem invert(GraphSourceItem neqSrc) {
return new LeActionItem(src, leftSide, rightSide);
}

View File

@@ -12,9 +12,11 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
/**
@@ -23,5 +25,5 @@ import com.jpexs.decompiler.graph.GraphTargetItem;
*/
public interface Inverted {
public GraphTargetItem invert(GraphSourceItem src);
}

View File

@@ -50,7 +50,7 @@ public class LeActionItem extends BinaryOpItem implements LogicalOpItem, Inverte
return ret;//undefined
}
@Override
@Override
public GraphTargetItem invert(GraphSourceItem negSrc) {
return new GtActionItem(src, leftSide, rightSide);
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.model.operations;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -50,7 +51,7 @@ public class LtActionItem extends BinaryOpItem implements LogicalOpItem {
}
@Override
@Override
public GraphTargetItem invert(GraphSourceItem neqSrc) {
return new GeActionItem(src, leftSide, rightSide, version2);
}

View File

@@ -49,7 +49,7 @@ public class NeqActionItem extends BinaryOpItem implements LogicalOpItem, Invert
}
}
@Override
@Override
public GraphTargetItem invert(GraphSourceItem negSrc) {
return new EqActionItem(src, leftSide, rightSide, version2);
}

View File

@@ -42,7 +42,7 @@ public class StrictEqActionItem extends BinaryOpItem implements LogicalOpItem, I
&& EcmaScript.equals(x, y);
}
@Override
@Override
public GraphTargetItem invert(GraphSourceItem negSrc) {
return new StrictNeqActionItem(src, leftSide, rightSide);
}

View File

@@ -43,7 +43,7 @@ public class StrictNeqActionItem extends BinaryOpItem implements LogicalOpItem,
|| (!EcmaScript.equals(x, y));
}
@Override
@Override
public GraphTargetItem invert(GraphSourceItem negSrc) {
return new StrictEqActionItem(src, leftSide, rightSide);
}

View File

@@ -48,7 +48,7 @@ public class StringEqActionItem extends BinaryOpItem implements Inverted {
return TypeItem.BOOLEAN;
}
@Override
@Override
public GraphTargetItem invert(GraphSourceItem negSrc) {
return new StringNeActionItem(src, leftSide, rightSide);
}

View File

@@ -49,7 +49,7 @@ public class StringGeActionItem extends BinaryOpItem implements Inverted {
return TypeItem.BOOLEAN;
}
@Override
@Override
public GraphTargetItem invert(GraphSourceItem negSrc) {
return new StringLtActionItem(src, leftSide, rightSide);
}

View File

@@ -54,7 +54,7 @@ public class StringGtActionItem extends BinaryOpItem implements Inverted {
return TypeItem.BOOLEAN;
}
@Override
@Override
public GraphTargetItem invert(GraphSourceItem negSrc) {
return new StringLeActionItem(src, leftSide, rightSide);
}

View File

@@ -57,7 +57,7 @@ public class StringLeActionItem extends BinaryOpItem implements Inverted {
return TypeItem.BOOLEAN;
}
@Override
@Override
public GraphTargetItem invert(GraphSourceItem negSrc) {
return new StringGtActionItem(src, leftSide, rightSide);
}

View File

@@ -48,7 +48,7 @@ public class StringLtActionItem extends BinaryOpItem implements Inverted {
return TypeItem.BOOLEAN;
}
@Override
@Override
public GraphTargetItem invert(GraphSourceItem negSrc) {
return new StringGeActionItem(src, leftSide, rightSide);
}

View File

@@ -49,7 +49,7 @@ public class StringNeActionItem extends BinaryOpItem implements Inverted {
return TypeItem.BOOLEAN;
}
@Override
@Override
public GraphTargetItem invert(GraphSourceItem negSrc) {
return new StringEqActionItem(src, leftSide, rightSide);
}

View File

@@ -1,18 +1,19 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.parser.script;
/**
@@ -32,5 +33,6 @@ public enum SymbolGroup {
TYPENAME,
EOF,
GLOBALFUNC,
GLOBALFUNC,
GLOBALCONST,
PREPROCESSOR
}

View File

@@ -1,222 +1,223 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.parser.script;
import com.jpexs.decompiler.graph.GraphTargetItem;
/**
*
* @author JPEXS
*/
public enum SymbolType {
//Keywords
BREAK,
CASE,
CONTINUE,
DEFAULT,
DO,
WHILE,
ELSE,
FOR,
EACH,
IN(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
IF,
RETURN,
SUPER(GraphTargetItem.PRECEDENCE_PRIMARY, false),
SWITCH,
THROW,
TRY,
CATCH,
FINALLY,
WITH,
DYNAMIC,
INTERNAL,
OVERRIDE,
PRIVATE,
PROTECTED,
PUBLIC,
STATIC,
CLASS,
CONST,
EXTENDS,
FUNCTION(GraphTargetItem.PRECEDENCE_PRIMARY, false),
GET,
IMPLEMENTS,
INTERFACE,
NAMESPACE,
PACKAGE,
SET,
VAR,
IMPORT,
USE,
FALSE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
NULL(GraphTargetItem.PRECEDENCE_PRIMARY, false),
THIS(GraphTargetItem.PRECEDENCE_PRIMARY, false),
TRUE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
//Operators
PARENT_OPEN(GraphTargetItem.PRECEDENCE_PRIMARY, false),
PARENT_CLOSE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
CURLY_OPEN(GraphTargetItem.PRECEDENCE_PRIMARY, false),
CURLY_CLOSE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
BRACKET_OPEN(GraphTargetItem.PRECEDENCE_PRIMARY, false),
BRACKET_CLOSE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
SEMICOLON,
COMMA(GraphTargetItem.PRECEDENCE_COMMA, false),
REST,
DOT(GraphTargetItem.PRECEDENCE_PRIMARY, false),
ASSIGN(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
GREATER_THAN(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
LOWER_THAN(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
NOT(GraphTargetItem.PRECEDENCE_UNARY, false),
NEGATE(GraphTargetItem.PRECEDENCE_UNARY, false),
TERNAR(GraphTargetItem.PRECEDENCE_CONDITIONAL, true, true), /*!! ternar !!!*/
COLON(GraphTargetItem.PRECEDENCE_CONDITIONAL, false),/*!! ternar !!!*/
EQUALS(GraphTargetItem.PRECEDENCE_EQUALITY, true),
STRICT_EQUALS(GraphTargetItem.PRECEDENCE_EQUALITY, true),
LOWER_EQUAL(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
GREATER_EQUAL(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
NOT_EQUAL(GraphTargetItem.PRECEDENCE_EQUALITY, true),
STRICT_NOT_EQUAL(GraphTargetItem.PRECEDENCE_EQUALITY, true),
AND(GraphTargetItem.PRECEDENCE_LOGICALAND, true),
OR(GraphTargetItem.PRECEDENCE_LOGICALOR, true),
FULLAND(GraphTargetItem.PRECEDENCE_LOGICALAND, true),
FULLOR(GraphTargetItem.PRECEDENCE_LOGICALOR, true),
INCREMENT(GraphTargetItem.PRECEDENCE_POSTFIX, false),//OR Unary
DECREMENT(GraphTargetItem.PRECEDENCE_POSTFIX, false), //OR Unary
PLUS(GraphTargetItem.PRECEDENCE_ADDITIVE, true),
MINUS(GraphTargetItem.PRECEDENCE_ADDITIVE, true), //OR Unary
MULTIPLY(GraphTargetItem.PRECEDENCE_MULTIPLICATIVE, true),
DIVIDE(GraphTargetItem.PRECEDENCE_MULTIPLICATIVE, true),
BITAND(GraphTargetItem.PRECEDENCE_BITWISEAND, true),
BITOR(GraphTargetItem.PRECEDENCE_BITWISEOR, true),
XOR(GraphTargetItem.PRECEDENCE_BITWISEXOR, true),
MODULO(GraphTargetItem.PRECEDENCE_BITWISESHIFT, true),
SHIFT_LEFT(GraphTargetItem.PRECEDENCE_BITWISESHIFT, true),
SHIFT_RIGHT(GraphTargetItem.PRECEDENCE_BITWISESHIFT, true),
USHIFT_RIGHT(GraphTargetItem.PRECEDENCE_BITWISESHIFT, true),
ASSIGN_PLUS(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_MINUS(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_MULTIPLY(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_DIVIDE(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_BITAND(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_BITOR(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_XOR(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_MODULO(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_SHIFT_LEFT(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_SHIFT_RIGHT(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_USHIFT_RIGHT(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
AS(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
DELETE(GraphTargetItem.PRECEDENCE_UNARY, false),
INSTANCEOF(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
IS(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
NAMESPACE_OP(GraphTargetItem.PRECEDENCE_PRIMARY, false),
NEW(GraphTargetItem.PRECEDENCE_PRIMARY, false),
TYPEOF(GraphTargetItem.PRECEDENCE_UNARY, false),
VOID,
ATTRIBUTE,
//Other
STRING(GraphTargetItem.PRECEDENCE_PRIMARY, false),
COMMENT,
XML,
IDENTIFIER(GraphTargetItem.PRECEDENCE_PRIMARY, false),
INTEGER(GraphTargetItem.PRECEDENCE_PRIMARY, false),
DOUBLE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
TYPENAME(GraphTargetItem.PRECEDENCE_PRIMARY, false),
EOF,
TRACE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
GETURL(GraphTargetItem.PRECEDENCE_PRIMARY, false),
GOTOANDSTOP(GraphTargetItem.PRECEDENCE_PRIMARY, false),
NEXTFRAME(GraphTargetItem.PRECEDENCE_PRIMARY, false),
PLAY(GraphTargetItem.PRECEDENCE_PRIMARY, false),
PREVFRAME(GraphTargetItem.PRECEDENCE_PRIMARY, false),
TELLTARGET(GraphTargetItem.PRECEDENCE_PRIMARY, false),
STOP(GraphTargetItem.PRECEDENCE_PRIMARY, false),
STOPALLSOUNDS(GraphTargetItem.PRECEDENCE_PRIMARY, false),
TOGGLEHIGHQUALITY(GraphTargetItem.PRECEDENCE_PRIMARY, false),
ORD(GraphTargetItem.PRECEDENCE_PRIMARY, false),
CHR(GraphTargetItem.PRECEDENCE_PRIMARY, false),
DUPLICATEMOVIECLIP(GraphTargetItem.PRECEDENCE_PRIMARY, false),
STOPDRAG(GraphTargetItem.PRECEDENCE_PRIMARY, false),
GETTIMER(GraphTargetItem.PRECEDENCE_PRIMARY, false),
LOADVARIABLES(GraphTargetItem.PRECEDENCE_PRIMARY, false),
LOADMOVIE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
GOTOANDPLAY(GraphTargetItem.PRECEDENCE_PRIMARY, false),
MBORD(GraphTargetItem.PRECEDENCE_PRIMARY, false),
MBCHR(GraphTargetItem.PRECEDENCE_PRIMARY, false),
MBLENGTH(GraphTargetItem.PRECEDENCE_PRIMARY, false),
MBSUBSTRING(GraphTargetItem.PRECEDENCE_PRIMARY, false),
RANDOM(GraphTargetItem.PRECEDENCE_PRIMARY, false),
REMOVEMOVIECLIP(GraphTargetItem.PRECEDENCE_PRIMARY, false),
STARTDRAG(GraphTargetItem.PRECEDENCE_PRIMARY, false),
SUBSTR(GraphTargetItem.PRECEDENCE_PRIMARY, false),
LENGTH(GraphTargetItem.PRECEDENCE_PRIMARY, false), //string.length
INT(GraphTargetItem.PRECEDENCE_PRIMARY, false),
TARGETPATH(GraphTargetItem.PRECEDENCE_PRIMARY, false),
NUMBER_OP(GraphTargetItem.PRECEDENCE_PRIMARY, false),
STRING_OP(GraphTargetItem.PRECEDENCE_PRIMARY, false),
IFFRAMELOADED,
INFINITY(GraphTargetItem.PRECEDENCE_PRIMARY, false),
EVAL(GraphTargetItem.PRECEDENCE_PRIMARY, false),
UNDEFINED(GraphTargetItem.PRECEDENCE_PRIMARY, false),
NEWLINE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
NAN(GraphTargetItem.PRECEDENCE_PRIMARY, false),
GETVERSION(GraphTargetItem.PRECEDENCE_PRIMARY, false),
CALL(GraphTargetItem.PRECEDENCE_PRIMARY, false),
LOADMOVIENUM(GraphTargetItem.PRECEDENCE_PRIMARY, false),
LOADVARIABLESNUM(GraphTargetItem.PRECEDENCE_PRIMARY, false),
PRINT(GraphTargetItem.PRECEDENCE_PRIMARY, false),
PRINTNUM(GraphTargetItem.PRECEDENCE_PRIMARY, false),
PRINTASBITMAP(GraphTargetItem.PRECEDENCE_PRIMARY, false),
PRINTASBITMAPNUM(GraphTargetItem.PRECEDENCE_PRIMARY, false),
UNLOADMOVIE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
UNLOADMOVIENUM(GraphTargetItem.PRECEDENCE_PRIMARY, false),
FSCOMMAND(GraphTargetItem.PRECEDENCE_PRIMARY, false);
private int precedence = GraphTargetItem.NOPRECEDENCE;
private boolean binary = false;
private boolean rightAssociative = false;
public boolean isBinary() {
return binary;
}
public boolean isRightAssociative() {
return rightAssociative;
}
public int getPrecedence() {
return precedence;
}
private SymbolType(int precedence, boolean binary) {
this.precedence = precedence;
this.binary = binary;
}
private SymbolType(int precedence, boolean binary, boolean rightAssociative) {
this.precedence = precedence;
this.binary = binary;
this.rightAssociative = rightAssociative;
}
private SymbolType() {
}
}
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.parser.script;
import com.jpexs.decompiler.graph.GraphTargetItem;
/**
*
* @author JPEXS
*/
public enum SymbolType {
//Keywords
BREAK,
CASE,
CONTINUE,
DEFAULT,
DO,
WHILE,
ELSE,
FOR,
EACH,
IN(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
IF,
RETURN,
SUPER(GraphTargetItem.PRECEDENCE_PRIMARY, false),
SWITCH,
THROW,
TRY,
CATCH,
FINALLY,
WITH,
DYNAMIC,
INTERNAL,
OVERRIDE,
PRIVATE,
PROTECTED,
PUBLIC,
STATIC,
CLASS,
CONST,
EXTENDS,
FUNCTION(GraphTargetItem.PRECEDENCE_PRIMARY, false),
GET,
IMPLEMENTS,
INTERFACE,
NAMESPACE,
PACKAGE,
SET,
VAR,
IMPORT,
USE,
FALSE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
NULL(GraphTargetItem.PRECEDENCE_PRIMARY, false),
THIS(GraphTargetItem.PRECEDENCE_PRIMARY, false),
TRUE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
//Operators
PARENT_OPEN(GraphTargetItem.PRECEDENCE_PRIMARY, false),
PARENT_CLOSE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
CURLY_OPEN(GraphTargetItem.PRECEDENCE_PRIMARY, false),
CURLY_CLOSE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
BRACKET_OPEN(GraphTargetItem.PRECEDENCE_PRIMARY, false),
BRACKET_CLOSE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
SEMICOLON,
COMMA(GraphTargetItem.PRECEDENCE_COMMA, false),
REST,
DOT(GraphTargetItem.PRECEDENCE_PRIMARY, false),
ASSIGN(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
GREATER_THAN(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
LOWER_THAN(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
NOT(GraphTargetItem.PRECEDENCE_UNARY, false),
NEGATE(GraphTargetItem.PRECEDENCE_UNARY, false),
TERNAR(GraphTargetItem.PRECEDENCE_CONDITIONAL, true, true), /*!! ternar !!!*/
COLON(GraphTargetItem.PRECEDENCE_CONDITIONAL, false),/*!! ternar !!!*/
EQUALS(GraphTargetItem.PRECEDENCE_EQUALITY, true),
STRICT_EQUALS(GraphTargetItem.PRECEDENCE_EQUALITY, true),
LOWER_EQUAL(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
GREATER_EQUAL(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
NOT_EQUAL(GraphTargetItem.PRECEDENCE_EQUALITY, true),
STRICT_NOT_EQUAL(GraphTargetItem.PRECEDENCE_EQUALITY, true),
AND(GraphTargetItem.PRECEDENCE_LOGICALAND, true),
OR(GraphTargetItem.PRECEDENCE_LOGICALOR, true),
FULLAND(GraphTargetItem.PRECEDENCE_LOGICALAND, true),
FULLOR(GraphTargetItem.PRECEDENCE_LOGICALOR, true),
INCREMENT(GraphTargetItem.PRECEDENCE_POSTFIX, false),//OR Unary
DECREMENT(GraphTargetItem.PRECEDENCE_POSTFIX, false), //OR Unary
PLUS(GraphTargetItem.PRECEDENCE_ADDITIVE, true),
MINUS(GraphTargetItem.PRECEDENCE_ADDITIVE, true), //OR Unary
MULTIPLY(GraphTargetItem.PRECEDENCE_MULTIPLICATIVE, true),
DIVIDE(GraphTargetItem.PRECEDENCE_MULTIPLICATIVE, true),
BITAND(GraphTargetItem.PRECEDENCE_BITWISEAND, true),
BITOR(GraphTargetItem.PRECEDENCE_BITWISEOR, true),
XOR(GraphTargetItem.PRECEDENCE_BITWISEXOR, true),
MODULO(GraphTargetItem.PRECEDENCE_BITWISESHIFT, true),
SHIFT_LEFT(GraphTargetItem.PRECEDENCE_BITWISESHIFT, true),
SHIFT_RIGHT(GraphTargetItem.PRECEDENCE_BITWISESHIFT, true),
USHIFT_RIGHT(GraphTargetItem.PRECEDENCE_BITWISESHIFT, true),
ASSIGN_PLUS(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_MINUS(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_MULTIPLY(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_DIVIDE(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_BITAND(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_BITOR(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_XOR(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_MODULO(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_SHIFT_LEFT(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_SHIFT_RIGHT(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
ASSIGN_USHIFT_RIGHT(GraphTargetItem.PRECEDENCE_ASSIGMENT, true, true),
AS(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
DELETE(GraphTargetItem.PRECEDENCE_UNARY, false),
INSTANCEOF(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
IS(GraphTargetItem.PRECEDENCE_RELATIONAL, true),
NAMESPACE_OP(GraphTargetItem.PRECEDENCE_PRIMARY, false),
NEW(GraphTargetItem.PRECEDENCE_PRIMARY, false),
TYPEOF(GraphTargetItem.PRECEDENCE_UNARY, false),
VOID,
ATTRIBUTE,
//Other
STRING(GraphTargetItem.PRECEDENCE_PRIMARY, false),
COMMENT,
XML,
IDENTIFIER(GraphTargetItem.PRECEDENCE_PRIMARY, false),
INTEGER(GraphTargetItem.PRECEDENCE_PRIMARY, false),
DOUBLE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
TYPENAME(GraphTargetItem.PRECEDENCE_PRIMARY, false),
EOF,
TRACE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
GETURL(GraphTargetItem.PRECEDENCE_PRIMARY, false),
GOTOANDSTOP(GraphTargetItem.PRECEDENCE_PRIMARY, false),
NEXTFRAME(GraphTargetItem.PRECEDENCE_PRIMARY, false),
PLAY(GraphTargetItem.PRECEDENCE_PRIMARY, false),
PREVFRAME(GraphTargetItem.PRECEDENCE_PRIMARY, false),
TELLTARGET(GraphTargetItem.PRECEDENCE_PRIMARY, false),
STOP(GraphTargetItem.PRECEDENCE_PRIMARY, false),
STOPALLSOUNDS(GraphTargetItem.PRECEDENCE_PRIMARY, false),
TOGGLEHIGHQUALITY(GraphTargetItem.PRECEDENCE_PRIMARY, false),
ORD(GraphTargetItem.PRECEDENCE_PRIMARY, false),
CHR(GraphTargetItem.PRECEDENCE_PRIMARY, false),
DUPLICATEMOVIECLIP(GraphTargetItem.PRECEDENCE_PRIMARY, false),
STOPDRAG(GraphTargetItem.PRECEDENCE_PRIMARY, false),
GETTIMER(GraphTargetItem.PRECEDENCE_PRIMARY, false),
LOADVARIABLES(GraphTargetItem.PRECEDENCE_PRIMARY, false),
LOADMOVIE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
GOTOANDPLAY(GraphTargetItem.PRECEDENCE_PRIMARY, false),
MBORD(GraphTargetItem.PRECEDENCE_PRIMARY, false),
MBCHR(GraphTargetItem.PRECEDENCE_PRIMARY, false),
MBLENGTH(GraphTargetItem.PRECEDENCE_PRIMARY, false),
MBSUBSTRING(GraphTargetItem.PRECEDENCE_PRIMARY, false),
RANDOM(GraphTargetItem.PRECEDENCE_PRIMARY, false),
REMOVEMOVIECLIP(GraphTargetItem.PRECEDENCE_PRIMARY, false),
STARTDRAG(GraphTargetItem.PRECEDENCE_PRIMARY, false),
SUBSTR(GraphTargetItem.PRECEDENCE_PRIMARY, false),
LENGTH(GraphTargetItem.PRECEDENCE_PRIMARY, false), //string.length
INT(GraphTargetItem.PRECEDENCE_PRIMARY, false),
TARGETPATH(GraphTargetItem.PRECEDENCE_PRIMARY, false),
NUMBER_OP(GraphTargetItem.PRECEDENCE_PRIMARY, false),
STRING_OP(GraphTargetItem.PRECEDENCE_PRIMARY, false),
IFFRAMELOADED,
INFINITY(GraphTargetItem.PRECEDENCE_PRIMARY, false),
EVAL(GraphTargetItem.PRECEDENCE_PRIMARY, false),
UNDEFINED(GraphTargetItem.PRECEDENCE_PRIMARY, false),
NEWLINE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
NAN(GraphTargetItem.PRECEDENCE_PRIMARY, false),
GETVERSION(GraphTargetItem.PRECEDENCE_PRIMARY, false),
CALL(GraphTargetItem.PRECEDENCE_PRIMARY, false),
LOADMOVIENUM(GraphTargetItem.PRECEDENCE_PRIMARY, false),
LOADVARIABLESNUM(GraphTargetItem.PRECEDENCE_PRIMARY, false),
PRINT(GraphTargetItem.PRECEDENCE_PRIMARY, false),
PRINTNUM(GraphTargetItem.PRECEDENCE_PRIMARY, false),
PRINTASBITMAP(GraphTargetItem.PRECEDENCE_PRIMARY, false),
PRINTASBITMAPNUM(GraphTargetItem.PRECEDENCE_PRIMARY, false),
UNLOADMOVIE(GraphTargetItem.PRECEDENCE_PRIMARY, false),
UNLOADMOVIENUM(GraphTargetItem.PRECEDENCE_PRIMARY, false),
FSCOMMAND(GraphTargetItem.PRECEDENCE_PRIMARY, false),
PREPROCESSOR(GraphTargetItem.PRECEDENCE_PRIMARY, false);
private int precedence = GraphTargetItem.NOPRECEDENCE;
private boolean binary = false;
private boolean rightAssociative = false;
public boolean isBinary() {
return binary;
}
public boolean isRightAssociative() {
return rightAssociative;
}
public int getPrecedence() {
return precedence;
}
private SymbolType(int precedence, boolean binary) {
this.precedence = precedence;
this.binary = binary;
}
private SymbolType(int precedence, boolean binary, boolean rightAssociative) {
this.precedence = precedence;
this.binary = binary;
this.rightAssociative = rightAssociative;
}
private SymbolType() {
}
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.swf4;
import com.jpexs.decompiler.flash.action.Action;
@@ -36,6 +37,6 @@ public class ActionNot extends Action {
@Override
public void translate(TranslateStack stack, List<GraphTargetItem> output, HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, int staticOperation, String path) {
GraphTargetItem a = stack.pop();
GraphTargetItem a = stack.pop();
stack.push(a.invert(this));
}
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.swf4;
import com.jpexs.decompiler.flash.action.Action;
@@ -35,13 +36,7 @@ public class ActionPop extends Action {
@Override
public void translate(TranslateStack stack, List<GraphTargetItem> output, HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, int staticOperation, String path) {
public void translate(TranslateStack stack, List<GraphTargetItem> output, HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, int staticOperation, String path) {
if (stack.isEmpty()) {
return;
GraphTargetItem val = stack.pop();
GraphTargetItem val = stack.pop();
if (val instanceof DirectValueActionItem) {
return;
output.add(val);
}
}

View File

@@ -37,6 +37,8 @@ import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TranslateStack;
import com.jpexs.decompiler.graph.model.FalseItem;
import com.jpexs.decompiler.graph.model.TrueItem;
import com.jpexs.helpers.Helper;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -360,18 +362,27 @@ public class ActionPush extends Action {
}
}
}*/
DirectValueActionItem dvt = new DirectValueActionItem(this, pos, o, constantPool);
if (o instanceof RegisterNumber) {//TemporaryRegister
dvt.computedRegValue = variables.get("__register" + ((RegisterNumber) o).number);
if (regNames.containsKey(((RegisterNumber) o).number)) {
((RegisterNumber) o).name = regNames.get(((RegisterNumber) o).number);
if (o instanceof Boolean) {
Boolean b = (Boolean) o;
if (b) {
stack.push(new TrueItem(this));
} else {
stack.push(new FalseItem(this));
}
}
if (dvt.computedRegValue instanceof TemporaryRegister) {
stack.push(new TemporaryRegister(((RegisterNumber) o).number, ((TemporaryRegister) dvt.computedRegValue).value));
} else {
stack.push(dvt);
DirectValueActionItem dvt = new DirectValueActionItem(this, pos, o, constantPool);
if (o instanceof RegisterNumber) {//TemporaryRegister
dvt.computedRegValue = variables.get("__register" + ((RegisterNumber) o).number);
if (regNames.containsKey(((RegisterNumber) o).number)) {
((RegisterNumber) o).name = regNames.get(((RegisterNumber) o).number);
}
}
if (dvt.computedRegValue instanceof TemporaryRegister) {
stack.push(new TemporaryRegister(((RegisterNumber) o).number, ((TemporaryRegister) dvt.computedRegValue).value));
} else {
stack.push(dvt);
}
}
pos++;
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.swf5;
import com.jpexs.decompiler.flash.action.Action;
@@ -39,7 +40,7 @@ public class ActionEnumerate extends Action {
@Override
public void translate(TranslateStack stack, List<GraphTargetItem> output, HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, int staticOperation, String path) {
GraphTargetItem object = stack.pop();
GraphTargetItem object = stack.pop();
stack.push(new DirectValueActionItem(null, 0, new Null(), new ArrayList<>()));
//stack.push(new DirectValueActionItem(null, 0, new Null(), new ArrayList<String>()));
output.add(new EnumerateActionItem(this, object));
}
}

View File

@@ -12,13 +12,15 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.swf5;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.graph.GraphSourceItemPos;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TranslateStack;
import com.jpexs.decompiler.graph.model.DuplicateItem;
import java.util.HashMap;
import java.util.List;
@@ -36,7 +38,7 @@ public class ActionPushDuplicate extends Action {
@Override
public void translate(TranslateStack stack, List<GraphTargetItem> output, HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, int staticOperation, String path) {
GraphTargetItem value = stack.peek();
GraphTargetItem value = stack.peek();
stack.push(new DuplicateItem(this, value));
value.moreSrc.add(new GraphSourceItemPos(this, 0));
}
}

View File

@@ -1,42 +1,42 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.swf6;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.model.EnumerateActionItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TranslateStack;
import java.util.HashMap;
import java.util.List;
public class ActionEnumerate2 extends Action {
public ActionEnumerate2() {
super(0x55, 0);
}
@Override
public String toString() {
return "Enumerate2";
}
@Override
public void translate(TranslateStack stack, List<GraphTargetItem> output, HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, int staticOperation, String path) {
GraphTargetItem object = stack.pop();
stack.push(new EnumerateActionItem(this, object));
}
}
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.flash.action.swf6;
import com.jpexs.decompiler.flash.action.Action;
import com.jpexs.decompiler.flash.action.model.EnumerateActionItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TranslateStack;
import java.util.HashMap;
import java.util.List;
public class ActionEnumerate2 extends Action {
public ActionEnumerate2() {
super(0x55, 0);
}
@Override
public String toString() {
return "Enumerate2";
}
@Override
public void translate(TranslateStack stack, List<GraphTargetItem> output, HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions, int staticOperation, String path) {
GraphTargetItem object = stack.pop();
output.add(new EnumerateActionItem(this, object));
}
}

View File

@@ -16,6 +16,8 @@
*/
package com.jpexs.decompiler.graph;
import com.jpexs.decompiler.graph.model.PushItem;
import com.jpexs.decompiler.graph.model.PopItem;
import com.jpexs.decompiler.flash.BaseLocalData;
import com.jpexs.decompiler.flash.FinalProcessLocalData;
import com.jpexs.decompiler.flash.action.Action;
@@ -25,7 +27,9 @@ import com.jpexs.decompiler.graph.model.AndItem;
import com.jpexs.decompiler.graph.model.BreakItem;
import com.jpexs.decompiler.graph.model.ContinueItem;
import com.jpexs.decompiler.graph.model.DoWhileItem;
import com.jpexs.decompiler.graph.model.DuplicateItem;
import com.jpexs.decompiler.graph.model.ExitItem;
import com.jpexs.decompiler.graph.model.FalseItem;
import com.jpexs.decompiler.graph.model.ForItem;
import com.jpexs.decompiler.graph.model.IfItem;
import com.jpexs.decompiler.graph.model.IntegerValueItem;
@@ -37,8 +41,10 @@ import com.jpexs.decompiler.graph.model.OrItem;
import com.jpexs.decompiler.graph.model.ScriptEndItem;
import com.jpexs.decompiler.graph.model.SwitchItem;
import com.jpexs.decompiler.graph.model.TernarOpItem;
import com.jpexs.decompiler.graph.model.TrueItem;
import com.jpexs.decompiler.graph.model.UniversalLoopItem;
import com.jpexs.decompiler.graph.model.WhileItem;
import com.jpexs.helpers.Helper;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -422,7 +428,7 @@ public class Graph {
for (GraphPart head : heads) {
populateParts(head, allParts);
}
TranslateStack stack = new TranslateStack();
TranslateStack stack = new TranslateStack(path);
List<Loop> loops = new ArrayList<>();
getLoops(localData, heads.get(0), loops, null);
/*System.out.println("<loops>");
@@ -461,8 +467,59 @@ public class Graph {
finalProcessAfter(list, level, localData);
}
protected void finalProcessAfter(List<GraphTargetItem> list, int level, FinalProcessLocalData localData) {
private boolean processSubBlk(Block b, GraphTargetItem replacement) {
boolean allSubPush = true;
boolean atleastOne = false;
for (List<GraphTargetItem> sub : b.getSubs()) {
if (!sub.isEmpty()) {
int lastPos = sub.size() - 1;
GraphTargetItem last = sub.get(sub.size() - 1);
GraphTargetItem br = null;
if ((last instanceof BreakItem) && (sub.size() >= 2)) {
br = last;
lastPos--;
last = sub.get(lastPos);
}
if (last instanceof Block) {
if (!processSubBlk((Block) last, replacement)) {
allSubPush = false;
} else {
atleastOne = true;
}
} else if (last instanceof PushItem) {
if (replacement != null) {
GraphTargetItem e2 = (((GraphTargetItem) replacement).clone());
e2.value = last.value;
sub.set(lastPos, e2);
if (br != null) {
sub.remove(sub.size() - 1);
}
}
atleastOne = true;
} else if (!(last instanceof ExitItem)) {
allSubPush = false;
}
}
}
return allSubPush && atleastOne;
}
protected void finalProcessAfter(List<GraphTargetItem> list, int level, FinalProcessLocalData localData) {
if (list.size() >= 2) {
if (list.get(list.size() - 1) instanceof ExitItem) {
ExitItem e = (ExitItem) list.get(list.size() - 1);
if (list.get(list.size() - 1).value instanceof PopItem) {
if (list.get(list.size() - 2) instanceof Block) {
Block b = (Block) list.get(list.size() - 2);
if (processSubBlk(b, (GraphTargetItem) e)) {
list.remove(list.size() - 1);
}
}
}
}
}
}
protected void finalProcess(List<GraphTargetItem> list, int level, FinalProcessLocalData localData) {
@@ -527,7 +584,7 @@ public class Graph {
}
private void processIfs(List<GraphTargetItem> list) {
//if(true) return;
for (int i = 0; i < list.size(); i++) {
GraphTargetItem item = list.get(i);
if (item instanceof Block) {
@@ -1382,7 +1439,11 @@ public class Graph {
}
List<GraphTargetItem> currentRet = ret;
UniversalLoopItem loopItem = null;
TranslateStack sPreLoop = stack;
if (isLoop) {
//makeAllCommands(currentRet, stack);
stack = (TranslateStack) stack.clone();
stack.clear();
loopItem = new UniversalLoopItem(null, currentLoop);
//loopItem.commands=printGraph(visited, localData, stack, allParts, parent, part, stopPart, loops);
currentRet.add(loopItem);
@@ -1412,23 +1473,6 @@ public class Graph {
}
}
//Assuming part with two nextparts is an IF
/* //If with both branches empty
if (part.nextParts.size() == 2) {
if (part.nextParts.get(0) == part.nextParts.get(1)) {
if (!stack.isEmpty()) {
GraphTargetItem expr = stack.pop();
if (expr instanceof LogicalOpItem) {
expr = ((LogicalOpItem) expr).invert();
} else {
expr = new NotItem(null, expr);
}
output.add(new IfItem(null, expr, new ArrayList<GraphTargetItem>(), new ArrayList<GraphTargetItem>()));
}
part.nextParts.remove(0);
}
}*/
if (parseNext) {
List<GraphTargetItem> retCheck = check(code, localData, allParts, stack, parent, part, stopPart, loops, output, currentLoop, staticOperation, path);
if (retCheck != null) {
@@ -1441,134 +1485,15 @@ public class Graph {
currentRet.addAll(output);
}
}
/**
* AND / OR detection
*/
if (parseNext && part.nextParts.size() == 2) {
if ((stack.size() >= 2) && (stack.get(stack.size() - 1) instanceof NotItem) && (((NotItem) (stack.get(stack.size() - 1))).getOriginal().getNotCoerced() == stack.get(stack.size() - 2).getNotCoerced())) {
GraphPart sp0 = getNextNoJump(part.nextParts.get(0), localData);
GraphPart sp1 = getNextNoJump(part.nextParts.get(1), localData);
boolean reversed = false;
loopContinues = getLoopsContinues(loops);
loopContinues.add(part);//???
if (sp1.leadsTo(localData, this, code, sp0, loops)) {
} else if (sp0.leadsTo(localData, this, code, sp1, loops)) {
reversed = true;
}
GraphPart next = reversed ? sp0 : sp1;
GraphTargetItem ti;
if ((ti = checkLoop(next, stopPart, loops)) != null) {
currentRet.add(ti);
} else {
List<GraphPart> stopPart2 = new ArrayList<>(stopPart);
GraphPart andOrStopPart = reversed ? sp1 : sp0;
stopPart2.add(andOrStopPart);
GraphTargetItem first = ((NotItem) stack.pop()).getOriginal();
stack.pop();
stack.push(new MarkItem("disposable"));
printGraph(visited, localData, stack, allParts, parent, next, stopPart2, loops, null, staticOperation, path, recursionLevel + 1);
GraphTargetItem second = stack.pop();
if (!reversed) {
AndItem a = new AndItem(null, first, second);
stack.push(a);
a.firstPart = part;
if (second instanceof AndItem) {
a.firstPart = ((AndItem) second).firstPart;
}
if (second instanceof OrItem) {
a.firstPart = ((OrItem) second).firstPart;
}
} else {
OrItem o = new OrItem(null, first, second);
stack.push(o);
o.firstPart = part;
if (second instanceof AndItem) {
o.firstPart = ((AndItem) second).firstPart;
}
if (second instanceof OrItem) {
o.firstPart = ((OrItem) second).firstPart;
}
}
next = reversed ? sp1 : sp0;
if ((ti = checkLoop(next, stopPart, loops)) != null) {
currentRet.add(ti);
} else {
currentRet.addAll(printGraph(visited, localData, stack, allParts, parent, next, stopPart, loops, null, staticOperation, path, recursionLevel + 1));
}
}
parseNext = false;
//return ret;
} else if ((stack.size() >= 2) && (stack.get(stack.size() - 1).getNotCoerced() == stack.get(stack.size() - 2).getNotCoerced())) {
GraphPart sp0 = getNextNoJump(part.nextParts.get(0), localData);
GraphPart sp1 = getNextNoJump(part.nextParts.get(1), localData);
boolean reversed = false;
loopContinues = getLoopsContinues(loops);
loopContinues.add(part);//???
if (sp1.leadsTo(localData, this, code, sp0, loops)) {
} else if (sp0.leadsTo(localData, this, code, sp1, loops)) {
reversed = true;
}
GraphPart next = reversed ? sp0 : sp1;
GraphTargetItem ti;
if ((ti = checkLoop(next, stopPart, loops)) != null) {
currentRet.add(ti);
} else {
List<GraphPart> stopPart2 = new ArrayList<>(stopPart);
GraphPart andOrStopPart = reversed ? sp1 : sp0;
//andOrStopPart.stopPartType = GraphPart.StopPartType.AND_OR;
stopPart2.add(andOrStopPart);
GraphTargetItem first = stack.pop();
stack.pop();
stack.push(new MarkItem("disposable"));
printGraph(visited, localData, stack, allParts, parent, next, stopPart2, loops, null, staticOperation, path, recursionLevel + 1);
//stack = andOrStopPart.andOrStack; // Use stack that was stored upon reaching AND_OR stopPart
GraphTargetItem second = stack.pop();
//GraphTargetItem first = stack.pop();
//andOrStopPart.stopPartType = GraphPart.StopPartType.NONE; // Reset stopPartType
if (reversed) {
AndItem a = new AndItem(null, first, second);
stack.push(a);
a.firstPart = part;
if (second instanceof AndItem) {
a.firstPart = ((AndItem) second).firstPart;
}
if (second instanceof OrItem) {
a.firstPart = ((OrItem) second).firstPart;
}
} else {
OrItem o = new OrItem(null, first, second);
stack.push(o);
o.firstPart = part;
if (second instanceof OrItem) {
o.firstPart = ((OrItem) second).firstPart;
}
if (second instanceof AndItem) {
o.firstPart = ((AndItem) second).firstPart;
}
}
next = reversed ? sp1 : sp0;
if ((ti = checkLoop(next, stopPart, loops)) != null) {
currentRet.add(ti);
} else {
currentRet.addAll(printGraph(visited, localData, stack, allParts, parent, next, stopPart, loops, null, staticOperation, path, recursionLevel + 1));
}
}
parseNext = false;
//return ret;
}
}
//********************************END PART DECOMPILING
if (parseNext) {
if (part.nextParts.size() > 2) {//direct switch, seen in the wild...
GraphPart next = getMostCommonPart(localData, part.nextParts, loops);
List<GraphPart> vis = new ArrayList<>();
GraphTargetItem switchedItem = stack.pop();
makeAllCommands(currentRet, stack);
List<GraphTargetItem> caseValues = new ArrayList<>();
List<List<GraphTargetItem>> caseCommands = new ArrayList<>();
List<GraphTargetItem> defaultCommands = new ArrayList<>();
@@ -1604,10 +1529,15 @@ public class Graph {
}
}
if (next != p) {
//int stackLenBefore = stack.size();
TranslateStack s2 = (TranslateStack) stack.clone();
s2.clear();
List<GraphTargetItem> nextCommands = printGraph(visited, prepareBranchLocalData(localData), s2, allParts, part, p, stopPart2, loops, null, staticOperation, path, recursionLevel + 1);
makeAllCommands(nextCommands, s2);
if (first) {
defaultCommands = printGraph(visited, prepareBranchLocalData(localData), stack, allParts, part, p, stopPart2, loops, null, staticOperation, path, recursionLevel + 1);
defaultCommands = nextCommands;
} else {
caseCommands.add(printGraph(visited, prepareBranchLocalData(localData), stack, allParts, part, p, stopPart2, loops, null, staticOperation, path, recursionLevel + 1));
caseCommands.add(nextCommands);
}
vis.add(p);
}
@@ -1623,41 +1553,23 @@ public class Graph {
GraphPart nextOnePart = null;
if (part.nextParts.size() == 2) {
GraphTargetItem expr = stack.pop();
if (expr instanceof LogicalOpItem) {
expr = ((LogicalOpItem) expr).invert();
} else {
expr = new NotItem(null, expr);
}
if (staticOperation != SOP_USE_STATIC) {
if (expr.isCompileTime()) {
boolean doJump = EcmaScript.toBoolean(expr.getResult());
if (doJump) {
nextOnePart = part.nextParts.get(0);
} else {
nextOnePart = part.nextParts.get(1);
}
if (staticOperation == SOP_REMOVE_STATIC) {
//TODO
}
}
}
/*if (expr instanceof LogicalOpItem) {
expr = ((LogicalOpItem) expr).invert();
} else {
expr = new NotItem(null, expr);
}*/
if (nextOnePart == null) {
List<GraphPart> nps;
/*nps = new ArrayList<>(part.nextParts);
for(int i=0;i<nps.size();i++){
nps.set(i,getNextNoJump(nps.get(i),localData));
}
if(nps.get(0) == nps.get(1)){
nps = part.nextParts;
}*/
nps = part.nextParts;
GraphPart next = getCommonPart(localData, nps, loops);
TranslateStack trueStack = (TranslateStack) stack.clone();
TranslateStack falseStack = (TranslateStack) stack.clone();
int trueStackSizeBefore = trueStack.size();
int falseStackSizeBefore = falseStack.size();
List<GraphTargetItem> onTrue = new ArrayList<>();
trueStack.clear();
falseStack.clear();
/*int trueStackSizeBefore = trueStack.size();
int falseStackSizeBefore = falseStack.size();
*/
boolean isEmpty = nps.get(0) == nps.get(1);
if (isEmpty) {
@@ -1665,59 +1577,63 @@ public class Graph {
}
List<GraphPart> stopPart2 = new ArrayList<>(stopPart);
//GraphPart.CommonPartStack commonPartStack = null;
if ((!isEmpty) && (next != null)) {
/*commonPartStack = next.new CommonPartStack();
if (next.commonPartStacks == null) {
next.commonPartStacks = new ArrayList<>();
}
next.stopPartType = GraphPart.StopPartType.COMMONPART;
*/
stopPart2.add(next);
}
List<GraphTargetItem> onTrue = new ArrayList<>();
if (!isEmpty) {
onTrue = printGraph(visited, prepareBranchLocalData(localData), trueStack, allParts, part, nps.get(1), stopPart2, loops, null, staticOperation, path, recursionLevel + 1);
}
List<GraphTargetItem> onFalse = new ArrayList<>();
if (!isEmpty) {
/*if (next != null) {
commonPartStack.isTrueStack = false; //stopPart must know it needs to store falseStack
}*/
onFalse = printGraph(visited, prepareBranchLocalData(localData), falseStack, allParts, part, nps.get(0), stopPart2, loops, null, staticOperation, path, recursionLevel + 1);
}
//List<GraphTargetItem> out2 = new ArrayList<>();
//makeAllCommands(out2, stack);
makeAllCommands(onTrue, trueStack);
makeAllCommands(onFalse, falseStack);
/* if there is a stopPart (next), then Graph will be further analyzed starting from the stopPart:
* trueStack and falseStack must be set equal to corresponding stack that was built upon reaching stopPart.
if ((!isEmpty) && (next != null)) {
if ((commonPartStack.trueStack != null) && (commonPartStack.falseStack != null)) {
trueStack = commonPartStack.trueStack;
falseStack = commonPartStack.falseStack;
}
next.commonPartStacks.remove(next.commonPartStacks.size() - 1);
if (next.commonPartStacks.isEmpty()) {
next.stopPartType = GraphPart.StopPartType.NONE; // reset StopPartType
}
}*/
if (isEmpty(onTrue) && isEmpty(onFalse) && (trueStack.size() == trueStackSizeBefore + 1) && (falseStack.size() == falseStackSizeBefore + 1)) {
stack.push(new TernarOpItem(null, expr, trueStack.pop(), falseStack.pop()));
if (!isEmpty(onTrue) && !isEmpty(onFalse) && onTrue.size() == 1 && onFalse.size() == 1 && (onTrue.get(0) instanceof PushItem) && (onFalse.get(0) instanceof PushItem)) {
stack.push(new TernarOpItem(null, expr.invert(null), ((PushItem) onTrue.get(0)).value, ((PushItem) onFalse.get(0)).value));
} else {
currentRet.add(new IfItem(null, expr, onTrue, onFalse));
}
if (next != null) {
if (trueStack.size() != trueStackSizeBefore || falseStack.size() != falseStackSizeBefore) {
// it's a hack, because duplicates all instructions in the next part, but better than EmptyStackException
onTrue = printGraph(visited, localData, trueStack, allParts, part, next, stopPart, loops, null, staticOperation, path, recursionLevel + 1);
onFalse = printGraph(visited, localData, falseStack, allParts, part, next, stopPart, loops, null, staticOperation, path, recursionLevel + 1);
if (isEmpty(onTrue) && isEmpty(onFalse) && (trueStack.size() == trueStackSizeBefore + 1) && (falseStack.size() == falseStackSizeBefore + 1)) {
stack.push(new TernarOpItem(null, expr, trueStack.pop(), falseStack.pop()));
boolean isIf = true;
if (!stack.isEmpty() && onFalse.isEmpty() && onTrue.size() == 2 && (onTrue.get(0) instanceof PopItem) && (onTrue.get(1) instanceof PushItem)) {
GraphTargetItem prevExpr = stack.pop();
GraphTargetItem leftSide = expr;
GraphTargetItem rightSide = ((PushItem) onTrue.get(1)).value;
if (leftSide instanceof DuplicateItem) {
isIf = false;
stack.push(new OrItem(null, prevExpr, rightSide));
} else if (leftSide.invert(null) instanceof DuplicateItem) {
isIf = false;
stack.push(new AndItem(null, prevExpr, rightSide));
} else if (prevExpr instanceof FalseItem) {
isIf = false;
stack.push(new OrItem(null, leftSide, rightSide));
} else if (prevExpr instanceof TrueItem) {
isIf = false;
stack.push(new AndItem(null, leftSide, rightSide));
} else {
currentRet.add(new IfItem(null, expr, onTrue, onFalse));
//:-(
}
} else {
printGraph(visited, localData, stack, allParts, part, next, stopPart, loops, currentRet, staticOperation, path, recursionLevel + 1);
}
if (isIf) {
makeAllCommands(currentRet, stack);
IfItem b = new IfItem(null, expr.invert(null), onTrue, onFalse);
currentRet.add(b);
if (processSubBlk(b, null)) {
stack.push(new PopItem(null));
}
}
}
//currentRet.addAll(out2);
if (next != null) {
printGraph(visited, localData, stack, allParts, part, next, stopPart, loops, currentRet, staticOperation, path, recursionLevel + 1);
//currentRet.addAll();
}
}
@@ -1751,7 +1667,7 @@ public class Graph {
stopContPart.add(currentLoop.loopContinue);
GraphPart precoBackup = currentLoop.loopPreContinue;
currentLoop.loopPreContinue = null;
loopItem.commands.addAll(printGraph(visited, localData, new TranslateStack(), allParts, null, precoBackup, stopContPart, loops, null, staticOperation, path, recursionLevel + 1));
loopItem.commands.addAll(printGraph(visited, localData, new TranslateStack(path), allParts, null, precoBackup, stopContPart, loops, null, staticOperation, path, recursionLevel + 1));
}
}
@@ -1788,7 +1704,7 @@ public class Graph {
GraphTargetItem expr = ifi.expression;
if (inverted) {
if (expr instanceof LogicalOpItem) {
expr = ((LogicalOpItem) expr).invert();
expr = ((LogicalOpItem) expr).invert(null);
} else {
expr = new NotItem(null, expr);
}
@@ -1808,7 +1724,7 @@ public class Graph {
currentLoop.loopPreContinue = null;
List<GraphPart> stopPart2 = new ArrayList<>(stopPart);
stopPart2.add(currentLoop.loopContinue);
finalComm = printGraph(visited, localData, new TranslateStack(), allParts, null, backup, stopPart2, loops, null, staticOperation, path, recursionLevel + 1);
finalComm = printGraph(visited, localData, new TranslateStack(path), allParts, null, backup, stopPart2, loops, null, staticOperation, path, recursionLevel + 1);
currentLoop.loopPreContinue = backup;
checkContinueAtTheEnd(finalComm, currentLoop);
}
@@ -1848,11 +1764,7 @@ public class Graph {
List<GraphTargetItem> exprList = new ArrayList<>();
GraphTargetItem expr = ifi.expression;
if (inverted) {
if (expr instanceof LogicalOpItem) {
expr = ((LogicalOpItem) expr).invert();
} else {
expr = new NotItem(null, expr);
}
expr = expr.invert(null);
}
checkContinueAtTheEnd(bodyBranch, currentLoop);
@@ -1889,7 +1801,7 @@ public class Graph {
currentLoop.loopPreContinue = null;
List<GraphPart> stopPart2 = new ArrayList<>(stopPart);
stopPart2.add(currentLoop.loopContinue);
List<GraphTargetItem> finalComm = printGraph(visited, localData, new TranslateStack(), allParts, null, backup, stopPart2, loops, null, staticOperation, path, recursionLevel + 1);
List<GraphTargetItem> finalComm = printGraph(visited, localData, new TranslateStack(path), allParts, null, backup, stopPart2, loops, null, staticOperation, path, recursionLevel + 1);
currentLoop.loopPreContinue = backup;
checkContinueAtTheEnd(finalComm, currentLoop);
@@ -1914,11 +1826,7 @@ public class Graph {
List<GraphTargetItem> exprList = new ArrayList<>(finalComm);
GraphTargetItem expr = ifi.expression;
if (invert) {
if (expr instanceof LogicalOpItem) {
expr = ((LogicalOpItem) expr).invert();
} else {
expr = new NotItem(null, expr);
}
expr = expr.invert(null);
}
exprList.add(expr);
ret.add(index, li = new DoWhileItem(null, currentLoop, loopItem.commands, exprList));
@@ -1943,7 +1851,7 @@ public class Graph {
}
if (currentLoop.loopBreak != null) {
ret.addAll(printGraph(visited, localData, stack, allParts, part, currentLoop.loopBreak, stopPart, loops, null, staticOperation, path, recursionLevel + 1));
ret.addAll(printGraph(visited, localData, sPreLoop, allParts, part, currentLoop.loopBreak, stopPart, loops, null, staticOperation, path, recursionLevel + 1));
}
}
@@ -2157,4 +2065,35 @@ public class Graph {
} while (part != null);
return ret;
}
protected static void makeAllStack(List<GraphTargetItem> commands, TranslateStack stack) {
int pcnt = 0;
for (int i = commands.size() - 1; i >= 0; i--) {
if (commands.get(i) instanceof PushItem) {
pcnt++;
} else {
break;
}
}
for (int i = commands.size() - pcnt; i < commands.size(); i++) {
stack.push(commands.remove(i).value);
i--;
}
}
protected static void makeAllCommands(List<GraphTargetItem> commands, TranslateStack stack) {
int clen = commands.size();
BreakItem br = null;
if (!commands.isEmpty()) {
if (commands.get(commands.size() - 1) instanceof BreakItem) {
clen--;
}
}
while (stack.size() > 0) {
GraphTargetItem p = stack.pop();
if (!(p instanceof PopItem)) {
commands.add(clen, new PushItem(p));
}
}
}
}

View File

@@ -1,52 +1,52 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.graph;
import com.jpexs.decompiler.flash.BaseLocalData;
import java.io.Serializable;
import java.util.List;
/**
*
* @author JPEXS
*/
public interface GraphSourceItem extends Serializable {
public void translate(BaseLocalData localData, TranslateStack stack, List<GraphTargetItem> output, int staticOperation, String path) throws InterruptedException;
public boolean isJump();
public boolean isBranch();
public boolean isExit();
public long getOffset();
public boolean ignoredLoops();
public List<Integer> getBranches(GraphSource code);
public boolean isIgnored();
public void setIgnored(boolean ignored, int pos);
public boolean isDeobfuscatePop();
public int getLine();
public String getFile();
}
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.graph;
import com.jpexs.decompiler.flash.BaseLocalData;
import java.io.Serializable;
import java.util.List;
/**
*
* @author JPEXS
*/
public interface GraphSourceItem extends Serializable, Cloneable {
public void translate(BaseLocalData localData, TranslateStack stack, List<GraphTargetItem> output, int staticOperation, String path) throws InterruptedException;
public boolean isJump();
public boolean isBranch();
public boolean isExit();
public long getOffset();
public boolean ignoredLoops();
public List<Integer> getBranches(GraphSource code);
public boolean isIgnored();
public void setIgnored(boolean ignored, int pos);
public boolean isDeobfuscatePop();
public int getLine();
public String getFile();
}

View File

@@ -1,298 +1,319 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.graph;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightData;
import com.jpexs.decompiler.graph.model.BinaryOp;
import com.jpexs.decompiler.graph.model.LocalData;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
*
* @author JPEXS
*/
public abstract class GraphTargetItem implements Serializable {
public static final int PRECEDENCE_PRIMARY = 0;
public static final int PRECEDENCE_POSTFIX = 1;
public static final int PRECEDENCE_UNARY = 2;
public static final int PRECEDENCE_MULTIPLICATIVE = 3;
public static final int PRECEDENCE_ADDITIVE = 4;
public static final int PRECEDENCE_BITWISESHIFT = 5;
public static final int PRECEDENCE_RELATIONAL = 6;
public static final int PRECEDENCE_EQUALITY = 7;
public static final int PRECEDENCE_BITWISEAND = 8;
public static final int PRECEDENCE_BITWISEXOR = 9;
public static final int PRECEDENCE_BITWISEOR = 10;
public static final int PRECEDENCE_LOGICALAND = 11;
public static final int PRECEDENCE_LOGICALOR = 12;
public static final int PRECEDENCE_CONDITIONAL = 13;
public static final int PRECEDENCE_ASSIGMENT = 14;
public static final int PRECEDENCE_COMMA = 15;
public static final int NOPRECEDENCE = 16;
public GraphSourceItem src;
public int pos = -1;
protected int precedence;
public List<GraphSourceItemPos> moreSrc = new ArrayList<>();
public GraphPart firstPart;
public GraphTargetItem value;
protected HighlightData srcData = new HighlightData();
public int getLine() {
if (src != null) {
return src.getLine();
}
return 0;
}
public String getFile() {
if (src != null) {
return src.getFile();
}
return null;
}
public GraphPart getFirstPart() {
if (value == null) {
return firstPart;
}
GraphPart ret = value.getFirstPart();
if (ret == null) {
return firstPart;
}
return ret;
}
public GraphTargetItem() {
this(null, NOPRECEDENCE);
}
public GraphTargetItem(GraphSourceItem src, int precedence) {
this.src = src;
this.precedence = precedence;
}
public List<GraphSourceItemPos> getNeededSources() {
List<GraphSourceItemPos> ret = new ArrayList<>();
ret.add(new GraphSourceItemPos(src, pos));
ret.addAll(moreSrc);
if (value != null) {
ret.addAll(value.getNeededSources());
}
return ret;
}
public GraphTextWriter toStringSemicoloned(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.startOffset(src, pos, srcData);
appendTo(writer, localData);
if (needsSemicolon()) {
writer.appendNoHilight(";");
}
writer.endOffset();
return writer;
}
public boolean needsSemicolon() {
return true;
}
@Override
public String toString() {
return this.getClass().getName();
}
public GraphTextWriter toString(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.startOffset(src, pos, srcData);
appendTo(writer, localData);
writer.endOffset();
return writer;
}
public abstract GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException;
public String toString(LocalData localData) throws InterruptedException {
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
toString(writer, localData);
return writer.toString();
}
public int getPrecedence() {
return precedence;
}
public boolean isCompileTime() {
Set<GraphTargetItem> dependencies = new HashSet<>();
dependencies.add(this);
return isCompileTime(dependencies);
}
public boolean isCompileTime(Set<GraphTargetItem> dependencies) {
return false;
}
public boolean hasSideEffect() {
return false;
}
public boolean isVariableComputed() {
return false;
}
public Object getResult() {
return null;
}
public String toStringNoQuotes(LocalData localData) {
return toString();
}
public GraphTextWriter toStringNoQuotes(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.startOffset(src, pos, srcData);
appendToNoQuotes(writer, localData);
writer.endOffset();
return writer;
}
public GraphTextWriter appendToNoQuotes(GraphTextWriter writer, LocalData localData) throws InterruptedException {
return toString(writer, localData);
}
public GraphTargetItem getNotCoerced() {
return this;
}
public GraphTargetItem getThroughRegister() {
return this;
}
public boolean needsNewLine() {
return false;
}
public GraphTextWriter toStringNL(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.startOffset(src, pos, srcData);
appendTo(writer, localData);
if (needsNewLine()) {
writer.newLine();
}
writer.endOffset();
return writer;
}
public boolean isEmpty() {
return false;
}
public GraphTargetItem getThroughNotCompilable() {
return this;
}
public GraphTargetItem getThroughDuplicate() {
return this;
}
public boolean valueEquals(GraphTargetItem target) {
return equals(target);
}
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return new ArrayList<>();
}
public List<GraphSourceItem> toSourceIgnoreReturnValue(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
if (!hasReturnValue()) {
return toSource(localData, generator);
}
return generator.generateDiscardValue(localData, this);
}
protected List<GraphSourceItem> toSourceBinary(BinaryOp op, GraphSourceItem action) {
List<GraphSourceItem> ret = new ArrayList<>();
return ret;
}
public static List<GraphSourceItem> toSourceMerge(SourceGeneratorLocalData localData, SourceGenerator gen, Object... tar) throws CompilationException {
List<GraphSourceItem> ret = new ArrayList<>();
for (Object o : tar) {
if (o == null) {
continue;
}
if (o instanceof GraphTargetItem) {
ret.addAll(((GraphTargetItem) o).toSource(localData, gen));
}
if (o instanceof GraphSourceItem) {
ret.add((GraphSourceItem) o);
}
if (o instanceof List) {
List l = (List) o;
for (Object o2 : l) {
if (o2 instanceof GraphSourceItem) {
ret.add((GraphSourceItem) o2);
}
if (o2 instanceof GraphTargetItem) {
ret.addAll(((GraphTargetItem) o2).toSource(localData, gen));
}
}
}
}
return ret;
}
public abstract boolean hasReturnValue();
public List<GraphTargetItem> getAllSubItems() {
List<GraphTargetItem> ret = new ArrayList<>();
if (value != null) {
ret.add(value);
}
return ret;
}
public abstract GraphTargetItem returnType();
}
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.graph;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.configuration.Configuration;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.helpers.HighlightedTextWriter;
import com.jpexs.decompiler.flash.helpers.hilight.HighlightData;
import com.jpexs.decompiler.graph.model.BinaryOp;
import com.jpexs.decompiler.graph.model.LocalData;
import com.jpexs.decompiler.graph.model.LogicalOpItem;
import com.jpexs.decompiler.graph.model.NotItem;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author JPEXS
*/
public abstract class GraphTargetItem implements Serializable, Cloneable {
public static final int PRECEDENCE_PRIMARY = 0;
public static final int PRECEDENCE_POSTFIX = 1;
public static final int PRECEDENCE_UNARY = 2;
public static final int PRECEDENCE_MULTIPLICATIVE = 3;
public static final int PRECEDENCE_ADDITIVE = 4;
public static final int PRECEDENCE_BITWISESHIFT = 5;
public static final int PRECEDENCE_RELATIONAL = 6;
public static final int PRECEDENCE_EQUALITY = 7;
public static final int PRECEDENCE_BITWISEAND = 8;
public static final int PRECEDENCE_BITWISEXOR = 9;
public static final int PRECEDENCE_BITWISEOR = 10;
public static final int PRECEDENCE_LOGICALAND = 11;
public static final int PRECEDENCE_LOGICALOR = 12;
public static final int PRECEDENCE_CONDITIONAL = 13;
public static final int PRECEDENCE_ASSIGMENT = 14;
public static final int PRECEDENCE_COMMA = 15;
public static final int NOPRECEDENCE = 16;
public GraphSourceItem src;
public int pos = -1;
protected int precedence;
public List<GraphSourceItemPos> moreSrc = new ArrayList<>();
public GraphPart firstPart;
public GraphTargetItem value;
protected HighlightData srcData = new HighlightData();
public int getLine() {
if (src != null) {
return src.getLine();
}
return 0;
}
public String getFile() {
if (src != null) {
return src.getFile();
}
return null;
}
public GraphPart getFirstPart() {
if (value == null) {
return firstPart;
}
GraphPart ret = value.getFirstPart();
if (ret == null) {
return firstPart;
}
return ret;
}
public GraphTargetItem() {
this(null, NOPRECEDENCE);
}
public GraphTargetItem(GraphSourceItem src, int precedence) {
this.src = src;
this.precedence = precedence;
}
public List<GraphSourceItemPos> getNeededSources() {
List<GraphSourceItemPos> ret = new ArrayList<>();
ret.add(new GraphSourceItemPos(src, pos));
ret.addAll(moreSrc);
if (value != null) {
ret.addAll(value.getNeededSources());
}
return ret;
}
public GraphTextWriter toStringSemicoloned(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.startOffset(src, pos, srcData);
appendTo(writer, localData);
if (needsSemicolon()) {
writer.appendNoHilight(";");
}
writer.endOffset();
return writer;
}
public boolean needsSemicolon() {
return true;
}
@Override
public String toString() {
return this.getClass().getName();
}
public GraphTextWriter toString(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.startOffset(src, pos, srcData);
appendTo(writer, localData);
writer.endOffset();
return writer;
}
public abstract GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException;
public String toString(LocalData localData) throws InterruptedException {
HighlightedTextWriter writer = new HighlightedTextWriter(Configuration.getCodeFormatting(), false);
toString(writer, localData);
return writer.toString();
}
public int getPrecedence() {
return precedence;
}
public boolean isCompileTime() {
Set<GraphTargetItem> dependencies = new HashSet<>();
dependencies.add(this);
return isCompileTime(dependencies);
}
public boolean isCompileTime(Set<GraphTargetItem> dependencies) {
return false;
}
public boolean hasSideEffect() {
return false;
}
public boolean isVariableComputed() {
return false;
}
public Object getResult() {
return null;
}
public String toStringNoQuotes(LocalData localData) {
return toString();
}
public GraphTextWriter toStringNoQuotes(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.startOffset(src, pos, srcData);
appendToNoQuotes(writer, localData);
writer.endOffset();
return writer;
}
public GraphTextWriter appendToNoQuotes(GraphTextWriter writer, LocalData localData) throws InterruptedException {
return toString(writer, localData);
}
public GraphTargetItem getNotCoerced() {
return this;
}
public GraphTargetItem getThroughRegister() {
return this;
}
public boolean needsNewLine() {
return false;
}
public GraphTextWriter toStringNL(GraphTextWriter writer, LocalData localData) throws InterruptedException {
writer.startOffset(src, pos, srcData);
appendTo(writer, localData);
if (needsNewLine()) {
writer.newLine();
}
writer.endOffset();
return writer;
}
public boolean isEmpty() {
return false;
}
public GraphTargetItem getThroughNotCompilable() {
return this;
}
public GraphTargetItem getThroughDuplicate() {
return this;
}
public boolean valueEquals(GraphTargetItem target) {
return equals(target);
}
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return new ArrayList<>();
}
public List<GraphSourceItem> toSourceIgnoreReturnValue(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
if (!hasReturnValue()) {
return toSource(localData, generator);
}
return generator.generateDiscardValue(localData, this);
}
protected List<GraphSourceItem> toSourceBinary(BinaryOp op, GraphSourceItem action) {
List<GraphSourceItem> ret = new ArrayList<>();
return ret;
}
public static List<GraphSourceItem> toSourceMerge(SourceGeneratorLocalData localData, SourceGenerator gen, Object... tar) throws CompilationException {
List<GraphSourceItem> ret = new ArrayList<>();
for (Object o : tar) {
if (o == null) {
continue;
}
if (o instanceof GraphTargetItem) {
ret.addAll(((GraphTargetItem) o).toSource(localData, gen));
}
if (o instanceof GraphSourceItem) {
ret.add((GraphSourceItem) o);
}
if (o instanceof List) {
List l = (List) o;
for (Object o2 : l) {
if (o2 instanceof GraphSourceItem) {
ret.add((GraphSourceItem) o2);
}
if (o2 instanceof GraphTargetItem) {
ret.addAll(((GraphTargetItem) o2).toSource(localData, gen));
}
}
}
}
return ret;
}
public abstract boolean hasReturnValue();
public List<GraphTargetItem> getAllSubItems() {
List<GraphTargetItem> ret = new ArrayList<>();
if (value != null) {
ret.add(value);
}
return ret;
}
public abstract GraphTargetItem returnType();
@Override
protected GraphTargetItem clone() {
try {
return (GraphTargetItem) super.clone();
} catch (CloneNotSupportedException ex) {
return null;
}
}
/*public GraphTargetItem invert() {
return invert(null);
}*/
public GraphTargetItem invert(GraphSourceItem src) {
return new NotItem(src, this);
}
}

View File

@@ -0,0 +1,10 @@
package com.jpexs.decompiler.graph;
/**
*
* @author JPEXS
*/
public interface SimpleValue {
public boolean isSimpleValue();
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.graph;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -22,12 +23,14 @@ import com.jpexs.decompiler.graph.model.CommaExpressionItem;
import com.jpexs.decompiler.graph.model.ContinueItem;
import com.jpexs.decompiler.graph.model.DoWhileItem;
import com.jpexs.decompiler.graph.model.DuplicateItem;
import com.jpexs.decompiler.graph.model.FalseItem;
import com.jpexs.decompiler.graph.model.ForItem;
import com.jpexs.decompiler.graph.model.IfItem;
import com.jpexs.decompiler.graph.model.NotItem;
import com.jpexs.decompiler.graph.model.OrItem;
import com.jpexs.decompiler.graph.model.SwitchItem;
import com.jpexs.decompiler.graph.model.TernarOpItem;
import com.jpexs.decompiler.graph.model.TrueItem;
import com.jpexs.decompiler.graph.model.WhileItem;
import java.util.List;
@@ -37,6 +40,10 @@ import java.util.List;
*/
public interface SourceGenerator {
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, TrueItem item) throws CompilationException;
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, FalseItem item) throws CompilationException;
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, AndItem item) throws CompilationException;
public List<GraphSourceItem> generate(SourceGeneratorLocalData localData, OrItem item) throws CompilationException;

View File

@@ -16,11 +16,51 @@
*/
package com.jpexs.decompiler.graph;
import com.jpexs.decompiler.graph.model.PopItem;
import java.util.Stack;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author JPEXS
*/
public class TranslateStack extends Stack<GraphTargetItem> {
private static PopItem pop = new PopItem(null);
private String path;
public TranslateStack(String path) {
this.path = path;
}
public String getPath() {
return path;
}
@Override
public synchronized GraphTargetItem peek() {
if (path != null) {
if (this.isEmpty()) {
Logger.getLogger(TranslateStack.class.getName()).log(Level.FINE, "{0}: Attemp to Peek empty stack", path);
return pop;
}
}
return super.peek();
}
@Override
public synchronized GraphTargetItem pop() {
if (path != null) {
if (this.isEmpty()) {
PopItem oldpop = pop;
pop = new PopItem(null);
Logger.getLogger(TranslateStack.class.getName()).log(Level.FINE, "{0}: Attemp to Pop empty stack", path);
return oldpop;
}
}
return super.pop();
}
}

View File

@@ -1,18 +1,19 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -20,6 +21,7 @@ import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SimpleValue;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.List;
@@ -29,7 +31,7 @@ import java.util.Set;
*
* @author JPEXS
*/
*/
public class DuplicateItem extends GraphTargetItem implements SimpleValue {
public DuplicateItem(GraphSourceItem src, GraphTargetItem value) {
super(src, value.getPrecedence());
@@ -43,7 +45,12 @@ public class DuplicateItem extends GraphTargetItem {
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
if ((value instanceof SimpleValue) && (((SimpleValue) value).isSimpleValue())) {
return value.appendTo(writer, localData);
}
writer.append("§§dup(");
value.appendTo(writer, localData);
return writer.append(")");
}
@Override
@@ -89,4 +96,14 @@ public class DuplicateItem extends GraphTargetItem {
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
/*@Override
public GraphTargetItem invert(GraphSourceItem src) {
return //new DuplicateItem(src, value instanceof NotItem ? (value.value) : new NotItem(src, value));
}*/
@Override
public boolean isSimpleValue() {
return ((value instanceof SimpleValue) && ((SimpleValue) value).isSimpleValue());
}
}

View File

@@ -1,18 +1,19 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.graph.model;
/**

View File

@@ -0,0 +1,68 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. */
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SimpleValue;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.List;
/**
*
* @author JPEXS
*/
public class FalseItem extends GraphTargetItem implements LogicalOpItem, SimpleValue {
public FalseItem(GraphSourceItem src) {
super(src, PRECEDENCE_PRIMARY);
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) {
return writer.append("false");
}
@Override
public boolean hasReturnValue() {
return true;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.BOOLEAN;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public GraphTargetItem invert(GraphSourceItem neqSrc) {
return new TrueItem(null);
}
@Override
public boolean isSimpleValue() {
return true;
}
}

View File

@@ -75,11 +75,7 @@ public class IfItem extends GraphTargetItem implements Block {
expr = ((NotItem) expr).getOriginal();
}
} else {
if (expr instanceof LogicalOpItem) {
expr = ((LogicalOpItem) expr).invert();
} else {
expr = new NotItem(null, expr);
}
expr = expr.invert(null);
ifBranch = onFalse;
elseBranch = onTrue;
}
@@ -112,7 +108,10 @@ public class IfItem extends GraphTargetItem implements Block {
}
for (GraphTargetItem ti : elseBranch) {
if (!ti.isEmpty()) {
ti.toStringSemicoloned(writer, localData).newLine();
ti.toStringSemicoloned(writer, localData);
if (!elseIf) {
writer.newLine();
}
}
}
if (!elseIf) {

View File

@@ -12,9 +12,11 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
/**
@@ -23,5 +25,5 @@ import com.jpexs.decompiler.graph.GraphTargetItem;
*/
public interface LogicalOpItem {
public GraphTargetItem invert(GraphSourceItem src);
}

View File

@@ -12,7 +12,8 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
@@ -57,11 +58,6 @@ public class NotItem extends UnaryOpItem implements LogicalOpItem, Inverted {
return value.isCompileTime(dependencies);
}
@Override
public GraphTargetItem invert() {
return value;
}
public GraphTargetItem getOriginal() {
return value;
}
@@ -80,4 +76,10 @@ public class NotItem extends UnaryOpItem implements LogicalOpItem, Inverted {
public GraphTargetItem returnType() {
return TypeItem.BOOLEAN;
}
@Override
public GraphTargetItem invert(GraphSourceItem src) {
return value;
}
}

View File

@@ -0,0 +1,57 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.ecma.Null;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.TypeItem;
/**
*
* @author JPEXS
*/
public class PopItem extends GraphTargetItem {
public PopItem(GraphSourceItem src) {
super(src, PRECEDENCE_PRIMARY);
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
//Logger.getLogger(PopItem.class.getName()).log(Level.WARNING, "Pop item left in the source code");
writer.append("§§pop()");
return writer;
}
@Override
public boolean hasReturnValue() {
return true;
}
@Override
public GraphTargetItem returnType() {
return TypeItem.UNBOUNDED;
}
@Override
public Object getResult() {
return new Null();
}
}

View File

@@ -0,0 +1,67 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
*/
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.GraphTargetItem;
/**
*
* @author JPEXS
*/
public class PushItem extends GraphTargetItem {
public PushItem(GraphTargetItem val) {
super(val.src, val.getPrecedence());
this.value = val;
}
@Override
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
//Logger.getLogger(PushItem.class.getName()).log(Level.WARNING, "Push item left in the source code");
writer.append("§§push(");
value.appendTo(writer, localData);
writer.append(")");
return writer;
}
@Override
public boolean hasReturnValue() {
return true;
}
@Override
public GraphTargetItem returnType() {
return value.returnType();
}
@Override
public GraphTargetItem getNotCoerced() {
return value.getNotCoerced();
}
@Override
public GraphTargetItem getThroughDuplicate() {
return value.getThroughDuplicate();
}
@Override
public GraphTargetItem getThroughRegister() {
return value.getThroughRegister();
}
}

View File

@@ -1,30 +1,36 @@
/*
* Copyright (C) 2010-2015 JPEXS, All rights reserved.
*
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.graph.model;
import com.jpexs.decompiler.flash.SourceGeneratorLocalData;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.graph.CompilationException;
import com.jpexs.decompiler.graph.GraphSourceItem;
import com.jpexs.decompiler.graph.GraphTargetItem;
import com.jpexs.decompiler.graph.SimpleValue;
import com.jpexs.decompiler.graph.SourceGenerator;
import com.jpexs.decompiler.graph.TypeItem;
import java.util.List;
/**
*
* @author JPEXS
*/
*/
public class TrueItem extends GraphTargetItem implements LogicalOpItem, SimpleValue {
public TrueItem(GraphSourceItem src) {
super(src, PRECEDENCE_PRIMARY);
@@ -44,4 +50,19 @@ public class TrueItem extends GraphTargetItem {
public GraphTargetItem returnType() {
return TypeItem.BOOLEAN;
}
@Override
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
return generator.generate(localData, this);
}
@Override
public GraphTargetItem invert(GraphSourceItem neqSrc) {
return new FalseItem(null);
}
@Override
public boolean isSimpleValue() {
return true;
}
}

View File

@@ -25,8 +25,6 @@ import java.util.Set;
public abstract class UnaryOpItem extends GraphTargetItem implements UnaryOp {
public GraphTargetItem value;
public String operator;
public UnaryOpItem(GraphSourceItem instruction, int precedence, GraphTargetItem value, String operator) {