mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-02 20:04:37 +00:00
Graph decompiling enhancements, better path handling
This commit is contained in:
@@ -18,7 +18,6 @@ package com.jpexs.decompiler.flash;
|
||||
|
||||
import SevenZip.Compression.LZMA.Encoder;
|
||||
import com.jpexs.decompiler.flash.abc.ABC;
|
||||
import com.jpexs.decompiler.flash.abc.CopyOutputStream;
|
||||
import com.jpexs.decompiler.flash.abc.ScriptPack;
|
||||
import com.jpexs.decompiler.flash.action.Action;
|
||||
import com.jpexs.decompiler.flash.action.ActionGraphSource;
|
||||
|
||||
@@ -27,7 +27,6 @@ import com.jpexs.decompiler.flash.action.parser.pcode.FlasmLexer;
|
||||
import com.jpexs.decompiler.flash.action.special.ActionEnd;
|
||||
import com.jpexs.decompiler.flash.action.swf4.*;
|
||||
import com.jpexs.decompiler.flash.action.swf5.*;
|
||||
import com.jpexs.decompiler.flash.action.swf6.ActionEnumerate2;
|
||||
import com.jpexs.decompiler.flash.action.swf7.ActionDefineFunction2;
|
||||
import com.jpexs.decompiler.flash.action.treemodel.*;
|
||||
import com.jpexs.decompiler.flash.action.treemodel.clauses.*;
|
||||
@@ -798,7 +797,6 @@ public class Action implements GraphSourceItem {
|
||||
ip++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (action instanceof GraphSourceItemContainer) {
|
||||
GraphSourceItemContainer cnt = (GraphSourceItemContainer) action;
|
||||
//List<GraphTargetItem> out=actionsPartToTree(new HashMap<Integer, String>(), new HashMap<String, GraphTargetItem>(),new HashMap<String, GraphTargetItem>(), new Stack<GraphTargetItem>(), src, ip+1,endip-1 , version);
|
||||
@@ -836,15 +834,15 @@ public class Action implements GraphSourceItem {
|
||||
}
|
||||
|
||||
/*ActionJump && ActionIf removed*/
|
||||
if ((action instanceof ActionEnumerate2) || (action instanceof ActionEnumerate)) {
|
||||
loopStart = ip + 1;
|
||||
isForIn = true;
|
||||
ip += 4;
|
||||
action.translate(localData, stack, output);
|
||||
EnumerateTreeItem en = (EnumerateTreeItem) stack.peek();
|
||||
inItem = en.object;
|
||||
continue;
|
||||
} else /*if (action instanceof ActionTry) {
|
||||
/*if ((action instanceof ActionEnumerate2) || (action instanceof ActionEnumerate)) {
|
||||
loopStart = ip + 1;
|
||||
isForIn = true;
|
||||
ip += 4;
|
||||
action.translate(localData, stack, output);
|
||||
EnumerateTreeItem en = (EnumerateTreeItem) stack.peek();
|
||||
inItem = en.object;
|
||||
continue;
|
||||
} else*/ /*if (action instanceof ActionTry) {
|
||||
ActionTry atry = (ActionTry) action;
|
||||
List<GraphTargetItem> tryCommands = ActionGraph.translateViaGraph(registerNames, variables, functions, atry.tryBody, version);
|
||||
TreeItem catchName;
|
||||
|
||||
@@ -112,9 +112,10 @@ public class Graph {
|
||||
i = part.path.length();
|
||||
}
|
||||
if (modify && ((uniqueRefs.size() > 1) && (prvni >= 0))) {
|
||||
GraphPath newpath = uniqueRefs.get(prvni).path.parent(i);
|
||||
GraphPath prvniUniq = uniqueRefs.get(prvni).path;
|
||||
GraphPath newpath = prvniUniq.parent(i);
|
||||
if (!part.path.equals(newpath)) {
|
||||
if (part.path.startsWith(newpath)) {
|
||||
if (part.path.startsWith(newpath) && ((newpath.length() == prvniUniq.length()) || (prvniUniq.getKey(newpath.length()) == part.path.getKey(newpath.length())))) {
|
||||
GraphPath origPath = part.path;
|
||||
GraphPart p = part;
|
||||
part.path = newpath;
|
||||
@@ -123,6 +124,7 @@ public class Graph {
|
||||
if (!p.path.equals(origPath)) {
|
||||
break;
|
||||
}
|
||||
|
||||
p.path = newpath;
|
||||
}
|
||||
fixGraphOnce(part, new ArrayList<GraphPart>(), true);
|
||||
@@ -146,7 +148,7 @@ public class Graph {
|
||||
GraphPart npart = part.nextParts.get(j);
|
||||
|
||||
if (npart.path.length() > part.path.length() + 1) {
|
||||
npart.path = part.path.sub(j);
|
||||
npart.path = part.path.sub(j, part.end);
|
||||
fixed = true;
|
||||
}
|
||||
}
|
||||
@@ -246,7 +248,7 @@ public class Graph {
|
||||
int pos = 0;
|
||||
for (GraphPart p : part.nextParts) {
|
||||
if (!visited.contains(p)) {
|
||||
p.path = part.path.sub(pos);
|
||||
p.path = part.path.sub(pos, p.end);
|
||||
}
|
||||
resetGraph(p, visited);
|
||||
pos++;
|
||||
@@ -832,7 +834,6 @@ public class Graph {
|
||||
}
|
||||
|
||||
loopContinues = getLoopsContinues(loops);
|
||||
|
||||
GraphPart next = part.getNextPartPath(loopContinues);
|
||||
List<GraphTargetItem> retx = ret;
|
||||
if ((!loop) || (doWhile && (part.nextParts.size() > 1))) {
|
||||
@@ -1293,7 +1294,7 @@ public class Graph {
|
||||
allBlocks.add(part);
|
||||
List<Integer> branches = ins.getBranches(code);
|
||||
for (int i = 0; i < branches.size(); i++) {
|
||||
part.nextParts.add(g = makeGraph(part, path.sub(i), code, branches.get(i), ip, allBlocks, refs, visited2));
|
||||
part.nextParts.add(g = makeGraph(part, path.sub(i, ip), code, branches.get(i), ip, allBlocks, refs, visited2));
|
||||
g.refs.add(part);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -69,6 +69,9 @@ public class GraphPart {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -92,6 +95,9 @@ public class GraphPart {
|
||||
public GraphPart getNextPartPath(List<GraphPart> ignored) {
|
||||
List<GraphPart> visited = new ArrayList<GraphPart>();
|
||||
visited.addAll(ignored);
|
||||
if (visited.contains(this)) {
|
||||
visited.remove(this);
|
||||
}
|
||||
return getNextPartPath(this, path, visited);
|
||||
}
|
||||
|
||||
|
||||
@@ -25,24 +25,35 @@ import java.util.List;
|
||||
*/
|
||||
public class GraphPath {
|
||||
|
||||
private List<Integer> parts = new ArrayList<Integer>();
|
||||
private List<Integer> keys = new ArrayList<Integer>();
|
||||
private List<Integer> vals = new ArrayList<Integer>();
|
||||
public String rootName = "";
|
||||
|
||||
public GraphPath(String rootName, List<Integer> parts) {
|
||||
public GraphPath(String rootName, List<Integer> keys, List<Integer> vals) {
|
||||
this.rootName = rootName;
|
||||
this.parts.addAll(parts);
|
||||
this.keys.addAll(keys);
|
||||
this.vals.addAll(vals);
|
||||
}
|
||||
|
||||
public GraphPath(List<Integer> parts) {
|
||||
this.parts.addAll(parts);
|
||||
public GraphPath(List<Integer> keys, List<Integer> vals) {
|
||||
this.keys.addAll(keys);
|
||||
this.vals.addAll(vals);
|
||||
}
|
||||
|
||||
public boolean startsWith(GraphPath p) {
|
||||
if (p.length() > length()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
List<Integer> otherKeys = new ArrayList<Integer>(p.keys);
|
||||
List<Integer> otherVals = new ArrayList<Integer>(p.vals);
|
||||
|
||||
for (int i = 0; i < p.length(); i++) {
|
||||
if (parts.get(i) != p.get(i)) {
|
||||
if (keys.get(i) != otherKeys.get(i)) {
|
||||
return false;
|
||||
}
|
||||
if (vals.get(i) != otherVals.get(i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -52,42 +63,44 @@ public class GraphPath {
|
||||
public GraphPath parent(int len) {
|
||||
GraphPath par = new GraphPath(rootName);
|
||||
for (int i = 0; i < len; i++) {
|
||||
par.parts.add(parts.get(i));
|
||||
par.keys.add(keys.get(i));
|
||||
par.vals.add(vals.get(i));
|
||||
}
|
||||
return par;
|
||||
}
|
||||
|
||||
public GraphPath sub(int part) {
|
||||
GraphPath next = new GraphPath(rootName, this.parts);
|
||||
next.parts.add(part);
|
||||
public GraphPath sub(int part, int codePos) {
|
||||
GraphPath next = new GraphPath(rootName, this.keys, this.vals);
|
||||
next.keys.add(codePos);
|
||||
next.vals.add(part);
|
||||
return next;
|
||||
}
|
||||
|
||||
public GraphPath(String rootName, Integer... parts) {
|
||||
public GraphPath(String rootName) {
|
||||
this.rootName = rootName;
|
||||
for (int p : parts) {
|
||||
this.parts.add(p);
|
||||
}
|
||||
}
|
||||
|
||||
public GraphPath(Integer... parts) {
|
||||
for (int p : parts) {
|
||||
this.parts.add(p);
|
||||
}
|
||||
public GraphPath() {
|
||||
}
|
||||
|
||||
public int length() {
|
||||
return parts.size();
|
||||
return vals.size();
|
||||
}
|
||||
|
||||
public int get(int index) {
|
||||
return parts.get(index);
|
||||
return vals.get(index);
|
||||
}
|
||||
|
||||
public int getKey(int index) {
|
||||
return keys.get(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int hash = 7;
|
||||
hash = 41 * hash + (this.parts != null ? this.parts.hashCode() : 0);
|
||||
int hash = 5;
|
||||
hash = 23 * hash + (this.keys != null ? this.keys.hashCode() : 0);
|
||||
hash = 23 * hash + (this.vals != null ? this.vals.hashCode() : 0);
|
||||
hash = 23 * hash + (this.rootName != null ? this.rootName.hashCode() : 0);
|
||||
return hash;
|
||||
}
|
||||
|
||||
@@ -112,11 +125,22 @@ public class GraphPath {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (this.parts.size() != other.parts.size()) {
|
||||
|
||||
if (!arrMatch(keys, other.keys)) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < this.parts.size(); i++) {
|
||||
if (this.parts.get(i) != other.parts.get(i)) {
|
||||
if (!arrMatch(vals, other.vals)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean arrMatch(List<Integer> arr, List<Integer> arr2) {
|
||||
if (arr.size() != arr2.size()) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < arr.size(); i++) {
|
||||
if (arr.get(i) != arr2.get(i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -126,8 +150,8 @@ public class GraphPath {
|
||||
@Override
|
||||
public String toString() {
|
||||
String ret = rootName;
|
||||
for (int i : parts) {
|
||||
ret += "/" + i;
|
||||
for (int i = 0; i < keys.size(); i++) {
|
||||
ret += "/" + keys.get(i) + ":" + vals.get(i);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user