mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-27 07:11:04 +00:00
format source code
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,317 +1,317 @@
|
||||
/*
|
||||
* 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.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class GraphPart implements Serializable {
|
||||
|
||||
public int start = 0;
|
||||
|
||||
public int end = 0;
|
||||
|
||||
public int instanceCount = 0;
|
||||
|
||||
public List<GraphPart> nextParts = new ArrayList<>();
|
||||
|
||||
public int posX = -1;
|
||||
|
||||
public int posY = -1;
|
||||
|
||||
public GraphPath path = new GraphPath();
|
||||
|
||||
public List<GraphPart> refs = new ArrayList<>();
|
||||
|
||||
public boolean ignored = false;
|
||||
|
||||
public List<Object> forContinues = new ArrayList<>();
|
||||
|
||||
public int level;
|
||||
|
||||
public int discoveredTime;
|
||||
|
||||
public int finishedTime;
|
||||
|
||||
public int order;
|
||||
|
||||
public List<GraphPart> throwParts = new ArrayList<>();
|
||||
|
||||
public enum StopPartType {
|
||||
|
||||
NONE, AND_OR, COMMONPART
|
||||
}
|
||||
|
||||
public StopPartType stopPartType = StopPartType.NONE;
|
||||
|
||||
public TranslateStack andOrStack; // Stores stack when AND_OR stopPart has been reached
|
||||
|
||||
public class CommonPartStack { // Stores stack when COMMONPART stopPart has been reached
|
||||
|
||||
boolean isTrueStack;
|
||||
|
||||
TranslateStack trueStack;
|
||||
|
||||
TranslateStack falseStack;
|
||||
}
|
||||
|
||||
public ArrayList<CommonPartStack> commonPartStacks;
|
||||
|
||||
public void setAndOrStack(TranslateStack stack) {
|
||||
andOrStack = stack;
|
||||
}
|
||||
|
||||
public void setCommonPartStack(TranslateStack stack) {
|
||||
CommonPartStack currentStack = commonPartStacks.get(commonPartStacks.size() - 1);
|
||||
if (currentStack.isTrueStack) {
|
||||
currentStack.trueStack = stack;
|
||||
} else {
|
||||
currentStack.falseStack = stack;
|
||||
}
|
||||
}
|
||||
|
||||
public int setTime(int time, List<GraphPart> ordered, List<GraphPart> visited) {
|
||||
if (visited.contains(this)) {
|
||||
return time;
|
||||
}
|
||||
discoveredTime = time;
|
||||
visited.add(this);
|
||||
for (GraphPart next : nextParts) {
|
||||
if (!visited.contains(next)) {
|
||||
time = next.setTime(time + 1, ordered, visited);
|
||||
}
|
||||
}
|
||||
time++;
|
||||
finishedTime = time;
|
||||
order = ordered.size();
|
||||
ordered.add(this);
|
||||
return time;
|
||||
}
|
||||
|
||||
private boolean leadsTo(BaseLocalData localData, Graph gr, GraphSource code, GraphPart part, List<GraphPart> visited, List<Loop> loops) throws InterruptedException {
|
||||
if (Thread.currentThread().isInterrupted()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
|
||||
GraphPart tpart = gr.checkPart(null, localData, this, null);
|
||||
if (tpart == null) {
|
||||
return false;
|
||||
}
|
||||
if (tpart != this) {
|
||||
return tpart.leadsTo(localData, gr, code, part, visited, loops);
|
||||
}
|
||||
Loop currentLoop = null;
|
||||
for (Loop l : loops) {
|
||||
/*if(l.phase==0){
|
||||
if(l.loopContinue==this){
|
||||
l.leadsToMark = 1;
|
||||
next = l.loopBreak;
|
||||
currentLoop = l;
|
||||
continue;
|
||||
}
|
||||
}*/
|
||||
if (l.phase == 1) {
|
||||
if (l.loopContinue == this) {
|
||||
return false;
|
||||
}
|
||||
if (l.loopPreContinue == this) {
|
||||
return false;
|
||||
}
|
||||
if (l.loopBreak == this) {
|
||||
//return false; //?
|
||||
}
|
||||
}
|
||||
}
|
||||
if (visited.contains(this)) {
|
||||
return false;
|
||||
}
|
||||
/*if (loops.contains(this)) {
|
||||
return false;
|
||||
}*/
|
||||
visited.add(this);
|
||||
if (end < code.size() && code.get(end).isBranch() && (code.get(end).ignoredLoops())) {
|
||||
return false;
|
||||
}
|
||||
for (GraphPart p : nextParts) {
|
||||
if (p == part) {
|
||||
return true;
|
||||
} else {
|
||||
if (p.leadsTo(localData, gr, code, part, visited, loops)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (GraphPart p : throwParts) {
|
||||
if (p == part) {
|
||||
return true;
|
||||
} else {
|
||||
if (p.leadsTo(localData, gr, code, part, visited, loops)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean leadsTo(BaseLocalData localData, Graph gr, GraphSource code, GraphPart part, List<Loop> loops) throws InterruptedException {
|
||||
for (Loop l : loops) {
|
||||
l.leadsToMark = 0;
|
||||
}
|
||||
return leadsTo(localData, gr, code, part, new ArrayList<GraphPart>(), loops);
|
||||
}
|
||||
|
||||
public GraphPart(int start, int end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
private GraphPart getNextPartPath(GraphPart original, GraphPath path, List<GraphPart> visited) {
|
||||
if (visited.contains(this) && (this == original)) {
|
||||
return null;
|
||||
}
|
||||
if (visited.contains(this) && (this != original)) {
|
||||
return null;
|
||||
}
|
||||
visited.add(this);
|
||||
for (GraphPart p : nextParts) {
|
||||
if (p == original) {
|
||||
continue;
|
||||
}
|
||||
if (p.path.equals(path)) {
|
||||
return p;
|
||||
} else if (p.path.length() >= path.length()) {
|
||||
GraphPart gp = p.getNextPartPath(original, path, visited);
|
||||
if (gp != null) {
|
||||
return gp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public GraphPart getNextPartPath(List<GraphPart> ignored) {
|
||||
List<GraphPart> visited = new ArrayList<>();
|
||||
visited.addAll(ignored);
|
||||
if (visited.contains(this)) {
|
||||
visited.remove(this);
|
||||
}
|
||||
return getNextPartPath(this, path, visited);
|
||||
}
|
||||
|
||||
public GraphPart getNextSuperPartPath(List<GraphPart> ignored) {
|
||||
List<GraphPart> visited = new ArrayList<>();
|
||||
visited.addAll(ignored);
|
||||
return getNextSuperPartPath(this, path, visited);
|
||||
}
|
||||
|
||||
private GraphPart getNextSuperPartPath(GraphPart original, GraphPath path, List<GraphPart> visited) {
|
||||
if (visited.contains(this)) {
|
||||
return null;
|
||||
}
|
||||
visited.add(this);
|
||||
for (GraphPart p : nextParts) {
|
||||
if (p == original) {
|
||||
continue;
|
||||
}
|
||||
if (p.path.length() < path.length()) {
|
||||
return p;
|
||||
} else {
|
||||
GraphPart gp = p.getNextSuperPartPath(original, path, visited);
|
||||
if (gp != null) {
|
||||
return gp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (end < start) {
|
||||
return "<-> " + (start + 1) + "-" + (end + 1);
|
||||
}
|
||||
return "" + (start + 1) + "-" + (end + 1) + (instanceCount > 1 ? "(" + instanceCount + " links)" : "");// + " p" + path;
|
||||
}
|
||||
|
||||
public boolean containsIP(int ip) {
|
||||
return (ip >= start) && (ip <= end);
|
||||
}
|
||||
|
||||
private boolean containsPart(GraphPart part, GraphPart what, List<GraphPart> used) {
|
||||
if (used.contains(part)) {
|
||||
return false;
|
||||
}
|
||||
used.add(part);
|
||||
for (GraphPart subpart : part.nextParts) {
|
||||
if (subpart == what) {
|
||||
return true;
|
||||
}
|
||||
if (containsPart(subpart, what, used)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return end - start + 1;
|
||||
}
|
||||
|
||||
public int getPosAt(int offset) {
|
||||
return start + offset;
|
||||
}
|
||||
|
||||
public boolean containsPart(GraphPart what) {
|
||||
return containsPart(this, what, new ArrayList<GraphPart>());
|
||||
}
|
||||
|
||||
public List<GraphPart> getSubParts() {
|
||||
List<GraphPart> ret = new ArrayList<>();
|
||||
ret.add(this);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof GraphPart)) {
|
||||
return false;
|
||||
}
|
||||
final GraphPart other = (GraphPart) obj;
|
||||
if (this.start != other.start) {
|
||||
return false;
|
||||
}
|
||||
if (this.end != other.end) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class GraphPart implements Serializable {
|
||||
|
||||
public int start = 0;
|
||||
|
||||
public int end = 0;
|
||||
|
||||
public int instanceCount = 0;
|
||||
|
||||
public List<GraphPart> nextParts = new ArrayList<>();
|
||||
|
||||
public int posX = -1;
|
||||
|
||||
public int posY = -1;
|
||||
|
||||
public GraphPath path = new GraphPath();
|
||||
|
||||
public List<GraphPart> refs = new ArrayList<>();
|
||||
|
||||
public boolean ignored = false;
|
||||
|
||||
public List<Object> forContinues = new ArrayList<>();
|
||||
|
||||
public int level;
|
||||
|
||||
public int discoveredTime;
|
||||
|
||||
public int finishedTime;
|
||||
|
||||
public int order;
|
||||
|
||||
public List<GraphPart> throwParts = new ArrayList<>();
|
||||
|
||||
public enum StopPartType {
|
||||
|
||||
NONE, AND_OR, COMMONPART
|
||||
}
|
||||
|
||||
public StopPartType stopPartType = StopPartType.NONE;
|
||||
|
||||
public TranslateStack andOrStack; // Stores stack when AND_OR stopPart has been reached
|
||||
|
||||
public class CommonPartStack { // Stores stack when COMMONPART stopPart has been reached
|
||||
|
||||
boolean isTrueStack;
|
||||
|
||||
TranslateStack trueStack;
|
||||
|
||||
TranslateStack falseStack;
|
||||
}
|
||||
|
||||
public ArrayList<CommonPartStack> commonPartStacks;
|
||||
|
||||
public void setAndOrStack(TranslateStack stack) {
|
||||
andOrStack = stack;
|
||||
}
|
||||
|
||||
public void setCommonPartStack(TranslateStack stack) {
|
||||
CommonPartStack currentStack = commonPartStacks.get(commonPartStacks.size() - 1);
|
||||
if (currentStack.isTrueStack) {
|
||||
currentStack.trueStack = stack;
|
||||
} else {
|
||||
currentStack.falseStack = stack;
|
||||
}
|
||||
}
|
||||
|
||||
public int setTime(int time, List<GraphPart> ordered, List<GraphPart> visited) {
|
||||
if (visited.contains(this)) {
|
||||
return time;
|
||||
}
|
||||
discoveredTime = time;
|
||||
visited.add(this);
|
||||
for (GraphPart next : nextParts) {
|
||||
if (!visited.contains(next)) {
|
||||
time = next.setTime(time + 1, ordered, visited);
|
||||
}
|
||||
}
|
||||
time++;
|
||||
finishedTime = time;
|
||||
order = ordered.size();
|
||||
ordered.add(this);
|
||||
return time;
|
||||
}
|
||||
|
||||
private boolean leadsTo(BaseLocalData localData, Graph gr, GraphSource code, GraphPart part, List<GraphPart> visited, List<Loop> loops) throws InterruptedException {
|
||||
if (Thread.currentThread().isInterrupted()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
|
||||
GraphPart tpart = gr.checkPart(null, localData, this, null);
|
||||
if (tpart == null) {
|
||||
return false;
|
||||
}
|
||||
if (tpart != this) {
|
||||
return tpart.leadsTo(localData, gr, code, part, visited, loops);
|
||||
}
|
||||
Loop currentLoop = null;
|
||||
for (Loop l : loops) {
|
||||
/*if(l.phase==0){
|
||||
if(l.loopContinue==this){
|
||||
l.leadsToMark = 1;
|
||||
next = l.loopBreak;
|
||||
currentLoop = l;
|
||||
continue;
|
||||
}
|
||||
}*/
|
||||
if (l.phase == 1) {
|
||||
if (l.loopContinue == this) {
|
||||
return false;
|
||||
}
|
||||
if (l.loopPreContinue == this) {
|
||||
return false;
|
||||
}
|
||||
if (l.loopBreak == this) {
|
||||
//return false; //?
|
||||
}
|
||||
}
|
||||
}
|
||||
if (visited.contains(this)) {
|
||||
return false;
|
||||
}
|
||||
/*if (loops.contains(this)) {
|
||||
return false;
|
||||
}*/
|
||||
visited.add(this);
|
||||
if (end < code.size() && code.get(end).isBranch() && (code.get(end).ignoredLoops())) {
|
||||
return false;
|
||||
}
|
||||
for (GraphPart p : nextParts) {
|
||||
if (p == part) {
|
||||
return true;
|
||||
} else {
|
||||
if (p.leadsTo(localData, gr, code, part, visited, loops)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (GraphPart p : throwParts) {
|
||||
if (p == part) {
|
||||
return true;
|
||||
} else {
|
||||
if (p.leadsTo(localData, gr, code, part, visited, loops)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean leadsTo(BaseLocalData localData, Graph gr, GraphSource code, GraphPart part, List<Loop> loops) throws InterruptedException {
|
||||
for (Loop l : loops) {
|
||||
l.leadsToMark = 0;
|
||||
}
|
||||
return leadsTo(localData, gr, code, part, new ArrayList<GraphPart>(), loops);
|
||||
}
|
||||
|
||||
public GraphPart(int start, int end) {
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
private GraphPart getNextPartPath(GraphPart original, GraphPath path, List<GraphPart> visited) {
|
||||
if (visited.contains(this) && (this == original)) {
|
||||
return null;
|
||||
}
|
||||
if (visited.contains(this) && (this != original)) {
|
||||
return null;
|
||||
}
|
||||
visited.add(this);
|
||||
for (GraphPart p : nextParts) {
|
||||
if (p == original) {
|
||||
continue;
|
||||
}
|
||||
if (p.path.equals(path)) {
|
||||
return p;
|
||||
} else if (p.path.length() >= path.length()) {
|
||||
GraphPart gp = p.getNextPartPath(original, path, visited);
|
||||
if (gp != null) {
|
||||
return gp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public GraphPart getNextPartPath(List<GraphPart> ignored) {
|
||||
List<GraphPart> visited = new ArrayList<>();
|
||||
visited.addAll(ignored);
|
||||
if (visited.contains(this)) {
|
||||
visited.remove(this);
|
||||
}
|
||||
return getNextPartPath(this, path, visited);
|
||||
}
|
||||
|
||||
public GraphPart getNextSuperPartPath(List<GraphPart> ignored) {
|
||||
List<GraphPart> visited = new ArrayList<>();
|
||||
visited.addAll(ignored);
|
||||
return getNextSuperPartPath(this, path, visited);
|
||||
}
|
||||
|
||||
private GraphPart getNextSuperPartPath(GraphPart original, GraphPath path, List<GraphPart> visited) {
|
||||
if (visited.contains(this)) {
|
||||
return null;
|
||||
}
|
||||
visited.add(this);
|
||||
for (GraphPart p : nextParts) {
|
||||
if (p == original) {
|
||||
continue;
|
||||
}
|
||||
if (p.path.length() < path.length()) {
|
||||
return p;
|
||||
} else {
|
||||
GraphPart gp = p.getNextSuperPartPath(original, path, visited);
|
||||
if (gp != null) {
|
||||
return gp;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (end < start) {
|
||||
return "<-> " + (start + 1) + "-" + (end + 1);
|
||||
}
|
||||
return "" + (start + 1) + "-" + (end + 1) + (instanceCount > 1 ? "(" + instanceCount + " links)" : "");// + " p" + path;
|
||||
}
|
||||
|
||||
public boolean containsIP(int ip) {
|
||||
return (ip >= start) && (ip <= end);
|
||||
}
|
||||
|
||||
private boolean containsPart(GraphPart part, GraphPart what, List<GraphPart> used) {
|
||||
if (used.contains(part)) {
|
||||
return false;
|
||||
}
|
||||
used.add(part);
|
||||
for (GraphPart subpart : part.nextParts) {
|
||||
if (subpart == what) {
|
||||
return true;
|
||||
}
|
||||
if (containsPart(subpart, what, used)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return end - start + 1;
|
||||
}
|
||||
|
||||
public int getPosAt(int offset) {
|
||||
return start + offset;
|
||||
}
|
||||
|
||||
public boolean containsPart(GraphPart what) {
|
||||
return containsPart(this, what, new ArrayList<GraphPart>());
|
||||
}
|
||||
|
||||
public List<GraphPart> getSubParts() {
|
||||
List<GraphPart> ret = new ArrayList<>();
|
||||
ret.add(this);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
return hash;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
}
|
||||
if (!(obj instanceof GraphPart)) {
|
||||
return false;
|
||||
}
|
||||
final GraphPart other = (GraphPart) obj;
|
||||
if (this.start != other.start) {
|
||||
return false;
|
||||
}
|
||||
if (this.end != other.end) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
/*
|
||||
* 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.action.parser.pcode.FlasmLexer;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public interface GraphSourceItemContainer {
|
||||
|
||||
public long getHeaderSize();
|
||||
|
||||
public List<Long> getContainerSizes();
|
||||
|
||||
public void setContainerSize(int index, long size);
|
||||
|
||||
public String getASMSourceBetween(int pos);
|
||||
|
||||
public boolean parseDivision(long size, FlasmLexer lexer);
|
||||
|
||||
public HashMap<Integer, String> getRegNames();
|
||||
|
||||
public void translateContainer(List<List<GraphTargetItem>> contents, TranslateStack stack, List<GraphTargetItem> output, HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions);
|
||||
|
||||
public String getName();
|
||||
}
|
||||
/*
|
||||
* 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.action.parser.pcode.FlasmLexer;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public interface GraphSourceItemContainer {
|
||||
|
||||
public long getHeaderSize();
|
||||
|
||||
public List<Long> getContainerSizes();
|
||||
|
||||
public void setContainerSize(int index, long size);
|
||||
|
||||
public String getASMSourceBetween(int pos);
|
||||
|
||||
public boolean parseDivision(long size, FlasmLexer lexer);
|
||||
|
||||
public HashMap<Integer, String> getRegNames();
|
||||
|
||||
public void translateContainer(List<List<GraphTargetItem>> contents, TranslateStack stack, List<GraphTargetItem> output, HashMap<Integer, String> regNames, HashMap<String, GraphTargetItem> variables, HashMap<String, GraphTargetItem> functions);
|
||||
|
||||
public String getName();
|
||||
}
|
||||
|
||||
@@ -1,298 +1,298 @@
|
||||
/*
|
||||
* 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 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();
|
||||
}
|
||||
|
||||
@@ -1,154 +1,154 @@
|
||||
/*
|
||||
* 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.flash.helpers.LoopWithType;
|
||||
import com.jpexs.decompiler.flash.helpers.NulWriter;
|
||||
import com.jpexs.decompiler.graph.Block;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.Loop;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
import com.jpexs.decompiler.graph.TypeItem;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ForItem extends LoopItem implements Block {
|
||||
|
||||
public List<GraphTargetItem> firstCommands;
|
||||
|
||||
public GraphTargetItem expression;
|
||||
|
||||
public List<GraphTargetItem> finalCommands;
|
||||
|
||||
public List<GraphTargetItem> commands;
|
||||
|
||||
private boolean labelUsed;
|
||||
|
||||
@Override
|
||||
public List<List<GraphTargetItem>> getSubs() {
|
||||
List<List<GraphTargetItem>> ret = new ArrayList<>();
|
||||
if (firstCommands != null) {
|
||||
ret.add(firstCommands);
|
||||
}
|
||||
if (commands != null) {
|
||||
ret.add(commands);
|
||||
}
|
||||
if (finalCommands != null) {
|
||||
ret.add(finalCommands);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public ForItem(GraphSourceItem src, Loop loop, List<GraphTargetItem> firstCommands, GraphTargetItem expression, List<GraphTargetItem> finalCommands, List<GraphTargetItem> commands) {
|
||||
super(src, loop);
|
||||
this.firstCommands = firstCommands;
|
||||
this.expression = expression;
|
||||
this.finalCommands = finalCommands;
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
|
||||
if (writer instanceof NulWriter) {
|
||||
((NulWriter) writer).startLoop(loop.id, LoopWithType.LOOP_TYPE_LOOP);
|
||||
}
|
||||
if (labelUsed) {
|
||||
writer.append("loop" + loop.id + ":").newLine();
|
||||
}
|
||||
writer.append("for");
|
||||
if (writer.getFormatting().spaceBeforeParenthesesForParentheses) {
|
||||
writer.append(" ");
|
||||
}
|
||||
writer.append("(");
|
||||
int p = 0;
|
||||
for (int i = 0; i < firstCommands.size(); i++) {
|
||||
if (firstCommands.get(i).isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (p > 0) {
|
||||
writer.append(",");
|
||||
}
|
||||
firstCommands.get(i).toString(writer, localData);
|
||||
p++;
|
||||
}
|
||||
writer.append("; ");
|
||||
expression.toString(writer, localData);
|
||||
writer.append("; ");
|
||||
p = 0;
|
||||
for (int i = 0; i < finalCommands.size(); i++) {
|
||||
if (finalCommands.get(i).isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (p > 0) {
|
||||
writer.append(",");
|
||||
}
|
||||
finalCommands.get(i).toString(writer, localData);
|
||||
p++;
|
||||
}
|
||||
writer.append(")").startBlock();
|
||||
for (GraphTargetItem ti : commands) {
|
||||
if (!ti.isEmpty()) {
|
||||
ti.toStringSemicoloned(writer, localData).newLine();
|
||||
}
|
||||
}
|
||||
writer.endBlock();
|
||||
if (writer instanceof NulWriter) {
|
||||
LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id);
|
||||
labelUsed = loopOjb.used;
|
||||
}
|
||||
return writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsSemicolon() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ContinueItem> getContinues() {
|
||||
List<ContinueItem> ret = new ArrayList<>();
|
||||
for (GraphTargetItem ti : commands) {
|
||||
if (ti instanceof ContinueItem) {
|
||||
ret.add((ContinueItem) ti);
|
||||
}
|
||||
if (ti instanceof Block) {
|
||||
ret.addAll(((Block) ti).getContinues());
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
|
||||
return generator.generate(localData, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasReturnValue() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphTargetItem returnType() {
|
||||
return TypeItem.UNBOUNDED;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* 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.flash.helpers.LoopWithType;
|
||||
import com.jpexs.decompiler.flash.helpers.NulWriter;
|
||||
import com.jpexs.decompiler.graph.Block;
|
||||
import com.jpexs.decompiler.graph.CompilationException;
|
||||
import com.jpexs.decompiler.graph.GraphSourceItem;
|
||||
import com.jpexs.decompiler.graph.GraphTargetItem;
|
||||
import com.jpexs.decompiler.graph.Loop;
|
||||
import com.jpexs.decompiler.graph.SourceGenerator;
|
||||
import com.jpexs.decompiler.graph.TypeItem;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ForItem extends LoopItem implements Block {
|
||||
|
||||
public List<GraphTargetItem> firstCommands;
|
||||
|
||||
public GraphTargetItem expression;
|
||||
|
||||
public List<GraphTargetItem> finalCommands;
|
||||
|
||||
public List<GraphTargetItem> commands;
|
||||
|
||||
private boolean labelUsed;
|
||||
|
||||
@Override
|
||||
public List<List<GraphTargetItem>> getSubs() {
|
||||
List<List<GraphTargetItem>> ret = new ArrayList<>();
|
||||
if (firstCommands != null) {
|
||||
ret.add(firstCommands);
|
||||
}
|
||||
if (commands != null) {
|
||||
ret.add(commands);
|
||||
}
|
||||
if (finalCommands != null) {
|
||||
ret.add(finalCommands);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
public ForItem(GraphSourceItem src, Loop loop, List<GraphTargetItem> firstCommands, GraphTargetItem expression, List<GraphTargetItem> finalCommands, List<GraphTargetItem> commands) {
|
||||
super(src, loop);
|
||||
this.firstCommands = firstCommands;
|
||||
this.expression = expression;
|
||||
this.finalCommands = finalCommands;
|
||||
this.commands = commands;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
|
||||
if (writer instanceof NulWriter) {
|
||||
((NulWriter) writer).startLoop(loop.id, LoopWithType.LOOP_TYPE_LOOP);
|
||||
}
|
||||
if (labelUsed) {
|
||||
writer.append("loop" + loop.id + ":").newLine();
|
||||
}
|
||||
writer.append("for");
|
||||
if (writer.getFormatting().spaceBeforeParenthesesForParentheses) {
|
||||
writer.append(" ");
|
||||
}
|
||||
writer.append("(");
|
||||
int p = 0;
|
||||
for (int i = 0; i < firstCommands.size(); i++) {
|
||||
if (firstCommands.get(i).isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (p > 0) {
|
||||
writer.append(",");
|
||||
}
|
||||
firstCommands.get(i).toString(writer, localData);
|
||||
p++;
|
||||
}
|
||||
writer.append("; ");
|
||||
expression.toString(writer, localData);
|
||||
writer.append("; ");
|
||||
p = 0;
|
||||
for (int i = 0; i < finalCommands.size(); i++) {
|
||||
if (finalCommands.get(i).isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (p > 0) {
|
||||
writer.append(",");
|
||||
}
|
||||
finalCommands.get(i).toString(writer, localData);
|
||||
p++;
|
||||
}
|
||||
writer.append(")").startBlock();
|
||||
for (GraphTargetItem ti : commands) {
|
||||
if (!ti.isEmpty()) {
|
||||
ti.toStringSemicoloned(writer, localData).newLine();
|
||||
}
|
||||
}
|
||||
writer.endBlock();
|
||||
if (writer instanceof NulWriter) {
|
||||
LoopWithType loopOjb = ((NulWriter) writer).endLoop(loop.id);
|
||||
labelUsed = loopOjb.used;
|
||||
}
|
||||
return writer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean needsSemicolon() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ContinueItem> getContinues() {
|
||||
List<ContinueItem> ret = new ArrayList<>();
|
||||
for (GraphTargetItem ti : commands) {
|
||||
if (ti instanceof ContinueItem) {
|
||||
ret.add((ContinueItem) ti);
|
||||
}
|
||||
if (ti instanceof Block) {
|
||||
ret.addAll(((Block) ti).getContinues());
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GraphSourceItem> toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException {
|
||||
return generator.generate(localData, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasReturnValue() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public GraphTargetItem returnType() {
|
||||
return TypeItem.UNBOUNDED;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user