mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-26 23:50:45 +00:00
Fixed #1842 AS1/2 Better handling obfuscated code, for..in
This commit is contained in:
@@ -1485,7 +1485,7 @@ public class Graph {
|
||||
}
|
||||
end = p.end;
|
||||
int start = p.start;
|
||||
ret.addAll(code.translatePart(part, localData, stack, start, end, staticOperation, path));
|
||||
ret.addAll(code.translatePart(this, part, localData, stack, start, end, staticOperation, path));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
@@ -2039,6 +2039,7 @@ public class Graph {
|
||||
}
|
||||
|
||||
protected List<GraphTargetItem> printGraph(List<GotoItem> foundGotos, Map<GraphPart, List<GraphTargetItem>> partCodes, Map<GraphPart, Integer> partCodePos, Set<GraphPart> visited, BaseLocalData localData, TranslateStack stack, Set<GraphPart> allParts, GraphPart parent, GraphPart part, List<GraphPart> stopPart, List<StopPartKind> stopPartKind, List<Loop> loops, List<ThrowState> throwStates, List<GraphTargetItem> ret, int staticOperation, String path, int recursionLevel) throws InterruptedException {
|
||||
loopPrintGraph:while(true) {
|
||||
if (Thread.currentThread().isInterrupted()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
@@ -2273,7 +2274,7 @@ public class Graph {
|
||||
do {
|
||||
exHappened = false;
|
||||
try {
|
||||
output.addAll(code.translatePart(part, localData, stack, ipStart, part.end, staticOperation, path));
|
||||
output.addAll(code.translatePart(this, part, localData, stack, ipStart, part.end, staticOperation, path));
|
||||
} catch (GraphPartChangeException ex) { //Special case for ifFrameLoaded when it's over multiple parts
|
||||
output.addAll(ex.getOutput());
|
||||
for (GraphPart p : allParts) {
|
||||
@@ -2282,7 +2283,8 @@ public class Graph {
|
||||
currentRet.addAll(output);
|
||||
//to check for stopparts,etc. we need to call printGraph again
|
||||
part = p;
|
||||
return printGraph(foundGotos, partCodes, partCodePos, visited, localData, stack, allParts, parent, part, stopPart, stopPartKind, loops, throwStates, ret, staticOperation, path, recursionLevel);
|
||||
//return printGraph(foundGotos, partCodes, partCodePos, visited, localData, stack, allParts, parent, part, stopPart, stopPartKind, loops, throwStates, ret, staticOperation, path, recursionLevel);
|
||||
continue loopPrintGraph;
|
||||
}
|
||||
exHappened = true;
|
||||
ipStart = ex.getIp();
|
||||
@@ -2932,7 +2934,8 @@ public class Graph {
|
||||
printGraph(foundGotos, partCodes, partCodePos, visited, localData, sPreLoop, allParts, part, currentLoop.loopBreak, stopPart, stopPartKind, loops, throwStates, ret, staticOperation, path, recursionLevel + 1);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -3169,8 +3172,8 @@ public class Graph {
|
||||
i--;
|
||||
}
|
||||
}
|
||||
|
||||
public static void makeAllCommands(List<GraphTargetItem> commands, TranslateStack stack) {
|
||||
|
||||
public void makeAllCommands(List<GraphTargetItem> commands, TranslateStack stack) {
|
||||
int clen = commands.size();
|
||||
boolean isExit = false;
|
||||
if (clen > 0) {
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -73,11 +74,10 @@ public class GraphPart implements Serializable {
|
||||
public int finishedTime;
|
||||
|
||||
public int order;
|
||||
|
||||
|
||||
public int numBlocks = Integer.MAX_VALUE;
|
||||
|
||||
//public List<GraphPart> throwParts = new ArrayList<>();
|
||||
|
||||
public enum StopPartType {
|
||||
|
||||
NONE, AND_OR, COMMONPART
|
||||
@@ -125,7 +125,7 @@ public class GraphPart implements Serializable {
|
||||
ordered.add(this);
|
||||
return time;
|
||||
}
|
||||
|
||||
|
||||
public void setNumblocks(int numBlocks) {
|
||||
this.numBlocks = numBlocks;
|
||||
numBlocks++;
|
||||
@@ -133,7 +133,7 @@ public class GraphPart implements Serializable {
|
||||
if (next.numBlocks > numBlocks) {
|
||||
next.setNumblocks(numBlocks);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean leadsTo(BaseLocalData localData, Graph gr, GraphSource code, GraphPart prev, GraphPart part, HashSet<GraphPart> visited, List<Loop> loops, List<ThrowState> throwStates, boolean useThrow) throws InterruptedException {
|
||||
@@ -141,6 +141,74 @@ public class GraphPart implements Serializable {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
|
||||
Stack<GraphPart> todo = new Stack<>();
|
||||
todo.push(this);
|
||||
|
||||
looptodo:while (!todo.isEmpty()) {
|
||||
GraphPart thisPart = todo.pop();
|
||||
|
||||
GraphPart tpart = gr.checkPart(null, localData, prev, thisPart, null);
|
||||
if (tpart == null) {
|
||||
continue;
|
||||
}
|
||||
if (tpart != thisPart) {
|
||||
todo.push(tpart);
|
||||
continue;
|
||||
}
|
||||
for (Loop l : loops) {
|
||||
if (l.phase == 1) {
|
||||
if (l.loopContinue == thisPart) {
|
||||
continue looptodo;
|
||||
}
|
||||
if (l.loopPreContinue == thisPart) {
|
||||
continue looptodo;
|
||||
}
|
||||
if (l.loopBreak == thisPart) {
|
||||
//return false; //?
|
||||
}
|
||||
}
|
||||
}
|
||||
if (visited.contains(thisPart)) {
|
||||
continue;
|
||||
}
|
||||
visited.add(thisPart);
|
||||
if (thisPart.end < code.size() && code.get(thisPart.end).isBranch() && (code.get(thisPart.end).ignoredLoops())) {
|
||||
continue;
|
||||
}
|
||||
for (GraphPart p : thisPart.nextParts) {
|
||||
if (p == part) {
|
||||
return true;
|
||||
}
|
||||
if (visited.contains(p)) {
|
||||
continue;
|
||||
}
|
||||
todo.push(p);
|
||||
}
|
||||
for (ThrowState ts : throwStates) {
|
||||
if (ts.state != 1) {
|
||||
if (ts.throwingParts.contains(thisPart)) {
|
||||
GraphPart p = ts.targetPart;
|
||||
|
||||
if (p == part) {
|
||||
return true;
|
||||
}
|
||||
if (visited.contains(p)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
todo.push(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean leadsToRecursive(BaseLocalData localData, Graph gr, GraphSource code, GraphPart prev, GraphPart part, HashSet<GraphPart> visited, List<Loop> loops, List<ThrowState> throwStates, boolean useThrow) throws InterruptedException {
|
||||
if (Thread.currentThread().isInterrupted()) {
|
||||
throw new InterruptedException();
|
||||
}
|
||||
|
||||
GraphPart tpart = gr.checkPart(null, localData, prev, this, null);
|
||||
if (tpart == null) {
|
||||
return false;
|
||||
|
||||
@@ -36,7 +36,7 @@ public abstract class GraphSource implements Serializable {
|
||||
|
||||
public abstract boolean isEmpty();
|
||||
|
||||
public abstract List<GraphTargetItem> translatePart(GraphPart part, BaseLocalData localData, TranslateStack stack, int start, int end, int staticOperation, String path) throws InterruptedException, GraphPartChangeException;
|
||||
public abstract List<GraphTargetItem> translatePart(Graph graph, GraphPart part, BaseLocalData localData, TranslateStack stack, int start, int end, int staticOperation, String path) throws InterruptedException, GraphPartChangeException;
|
||||
|
||||
public abstract Set<Long> getImportantAddresses();
|
||||
|
||||
|
||||
@@ -48,6 +48,9 @@ public class CommaExpressionItem extends GraphTargetItem {
|
||||
public GraphTextWriter appendTo(GraphTextWriter writer, LocalData localData) throws InterruptedException {
|
||||
boolean first = true;
|
||||
for (GraphTargetItem t : commands) {
|
||||
if (t.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (!first) {
|
||||
writer.append(", ");
|
||||
}
|
||||
|
||||
@@ -101,13 +101,15 @@ public class DoWhileItem extends LoopItem implements Block {
|
||||
}
|
||||
writer.append("(");
|
||||
|
||||
boolean first = true;
|
||||
for (int i = 0; i < expression.size(); i++) {
|
||||
if (expression.get(i).isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (i != 0) {
|
||||
if (!first) {
|
||||
writer.append(", ");
|
||||
}
|
||||
first = false;
|
||||
if (i == expression.size() - 1) {
|
||||
expression.get(i).toStringBoolean(writer, localData);
|
||||
} else {
|
||||
|
||||
@@ -92,13 +92,15 @@ public class WhileItem extends LoopItem implements Block {
|
||||
writer.append(" ");
|
||||
}
|
||||
writer.append("(");
|
||||
boolean first = true;
|
||||
for (int i = 0; i < expression.size(); i++) {
|
||||
if (expression.get(i).isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
if (i != 0) {
|
||||
if (!first) {
|
||||
writer.append(", ");
|
||||
}
|
||||
first = false;
|
||||
if (i == expression.size() - 1) {
|
||||
expression.get(i).toStringBoolean(writer, localData);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user