mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-06-18 05:31:53 +00:00
AS3 Fix and/or in try clause
This commit is contained in:
@@ -739,7 +739,7 @@ public class AVM2Graph extends Graph {
|
||||
return part;
|
||||
}
|
||||
|
||||
private List<GraphTargetItem> checkTry(List<GraphTargetItem> currentRet, List<GraphTargetItem> output, List<GotoItem> foundGotos, Map<GraphPart, List<GraphTargetItem>> partCodes, Map<GraphPart, Integer> partCodePos, AVM2LocalData localData, GraphPart part, List<GraphPart> stopPart, List<Loop> loops, Set<GraphPart> allParts, TranslateStack stack, int staticOperation, String path) throws InterruptedException {
|
||||
private boolean checkTry(List<GraphTargetItem> currentRet, List<GotoItem> foundGotos, Map<GraphPart, List<GraphTargetItem>> partCodes, Map<GraphPart, Integer> partCodePos, AVM2LocalData localData, GraphPart part, List<GraphPart> stopPart, List<Loop> loops, Set<GraphPart> allParts, TranslateStack stack, int staticOperation, String path) throws InterruptedException {
|
||||
if (localData.parsedExceptions == null) {
|
||||
localData.parsedExceptions = new ArrayList<>();
|
||||
}
|
||||
@@ -1036,7 +1036,7 @@ public class AVM2Graph extends Graph {
|
||||
}
|
||||
|
||||
if (!inlinedFinally && catchCommands.isEmpty() && finallyCommands.isEmpty() && tryCommands.isEmpty()) {
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
//remove default assignment to switched register
|
||||
@@ -1046,10 +1046,9 @@ public class AVM2Graph extends Graph {
|
||||
currentRet.remove(currentRet.size() - 1);
|
||||
}
|
||||
|
||||
List<GraphTargetItem> ret = new ArrayList<>();
|
||||
if (!inlinedFinally && catchedExceptions.isEmpty() && finallyCommands.isEmpty()) {
|
||||
ret.addAll(tryCommands);
|
||||
return ret;
|
||||
currentRet.addAll(tryCommands);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1077,29 +1076,33 @@ public class AVM2Graph extends Graph {
|
||||
tryItem = new TryAVM2Item(subTry.tryCommands, subTry.catchExceptions, subTry.catchCommands, tryItem.finallyCommands, "");
|
||||
}
|
||||
|
||||
ret.add(tryItem);
|
||||
currentRet.add(tryItem);
|
||||
|
||||
if (afterPart != null) {
|
||||
|
||||
if (finallyIndex > -1 && localData.finallyIndicesWithDoublePush.contains(finallyIndex)) {
|
||||
stack.push(new AnyItem());
|
||||
}
|
||||
ret.addAll(printGraph(foundGotos, partCodes, partCodePos, localData, stack, allParts, null, afterPart, stopPart, loops, staticOperation, path));
|
||||
currentRet.addAll(printGraph(foundGotos, partCodes, partCodePos, localData, stack, allParts, null, afterPart, stopPart, loops, staticOperation, path));
|
||||
}
|
||||
return ret;
|
||||
return true;
|
||||
}
|
||||
return null;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkPartOutput(List<GraphTargetItem> currentRet, List<GotoItem> foundGotos, Map<GraphPart, List<GraphTargetItem>> partCodes, Map<GraphPart, Integer> partCodePos, GraphSource code, BaseLocalData localData, Set<GraphPart> allParts, TranslateStack stack, GraphPart parent, GraphPart part, List<GraphPart> stopPart, List<Loop> loops, Loop currentLoop, int staticOperation, String path) throws InterruptedException {
|
||||
AVM2LocalData aLocalData = (AVM2LocalData) localData;
|
||||
return checkTry(currentRet, foundGotos, partCodes, partCodePos, aLocalData, part, stopPart, loops, allParts, stack, staticOperation, path);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<GraphTargetItem> check(List<GraphTargetItem> currentRet, List<GotoItem> foundGotos, Map<GraphPart, List<GraphTargetItem>> partCodes, Map<GraphPart, Integer> partCodePos, GraphSource code, BaseLocalData localData, Set<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 {
|
||||
List<GraphTargetItem> ret = null;
|
||||
|
||||
AVM2LocalData aLocalData = (AVM2LocalData) localData;
|
||||
ret = checkTry(currentRet, output, foundGotos, partCodes, partCodePos, aLocalData, part, stopPart, loops, allParts, stack, staticOperation, path);
|
||||
if (ret != null) {
|
||||
/*if (ret != null) {
|
||||
return ret;
|
||||
}
|
||||
}*/
|
||||
//Detect switch
|
||||
if ((part.nextParts.size() == 2) && (!stack.isEmpty()) && (stack.peek() instanceof StrictEqAVM2Item)) {
|
||||
GraphSourceItem switchStartItem = code.get(part.start);
|
||||
|
||||
@@ -914,7 +914,7 @@ public class Graph {
|
||||
if (!onFalse.isEmpty()
|
||||
&& ((onFalse.get(onFalse.size() - 1) instanceof BreakItem)
|
||||
|| (onFalse.get(onFalse.size() - 1) instanceof ExitItem)
|
||||
|| (onFalse.get(onFalse.size() - 1) instanceof ContinueItem) )
|
||||
|| (onFalse.get(onFalse.size() - 1) instanceof ContinueItem))
|
||||
&& !(onFalse.get(onFalse.size() - 1) instanceof ScriptEndItem)
|
||||
&& (onTrue.isEmpty() || !((onTrue.get(onTrue.size() - 1) instanceof BreakItem)
|
||||
|| (onTrue.get(onTrue.size() - 1) instanceof ExitItem)
|
||||
@@ -1444,6 +1444,10 @@ public class Graph {
|
||||
return part.nextParts;
|
||||
}
|
||||
|
||||
protected boolean checkPartOutput(List<GraphTargetItem> currentRet, List<GotoItem> foundGotos, Map<GraphPart, List<GraphTargetItem>> partCodes, Map<GraphPart, Integer> partCodePos, GraphSource code, BaseLocalData localData, Set<GraphPart> allParts, TranslateStack stack, GraphPart parent, GraphPart part, List<GraphPart> stopPart, List<Loop> loops, Loop currentLoop, int staticOperation, String path) throws InterruptedException {
|
||||
return false;
|
||||
}
|
||||
|
||||
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<Loop> loops, List<GraphTargetItem> ret, int staticOperation, String path, int recursionLevel) throws InterruptedException {
|
||||
if (Thread.currentThread().isInterrupted()) {
|
||||
throw new InterruptedException();
|
||||
@@ -1612,25 +1616,11 @@ public class Graph {
|
||||
//****************************DECOMPILING PART*************
|
||||
List<GraphTargetItem> output = new ArrayList<>();
|
||||
|
||||
List<GraphPart> parts = new ArrayList<>();
|
||||
if (part instanceof GraphPartMulti) {
|
||||
parts = ((GraphPartMulti) part).parts;
|
||||
if (checkPartOutput(currentRet, foundGotos, partCodes, partCodePos, code, localData, allParts, stack, parent, part, stopPart, loops, currentLoop, staticOperation, path)) {
|
||||
parseNext = false;
|
||||
} else {
|
||||
parts.add(part);
|
||||
/*while (getNextParts(localData, part).size() == 1 && getNextParts(localData, part).get(0).refs.size() == 1) {
|
||||
if (stopPart.contains(getNextParts(localData, part).get(0))) { //it might be referenced with try statement
|
||||
break;
|
||||
}
|
||||
part = getNextParts(localData, part).get(0);
|
||||
parts.add(part);
|
||||
}*/
|
||||
}
|
||||
for (GraphPart p : parts) {
|
||||
int end = p.end;
|
||||
int start = p.start;
|
||||
|
||||
output.addAll(code.translatePart(p, localData, stack, start, end, staticOperation, path));
|
||||
if ((end >= code.size() - 1) && getNextParts(localData, p).isEmpty()) {
|
||||
output.addAll(code.translatePart(part, localData, stack, part.start, part.end, staticOperation, path));
|
||||
if ((part.end >= code.size() - 1) && getNextParts(localData, part).isEmpty()) {
|
||||
output.add(new ScriptEndItem());
|
||||
}
|
||||
}
|
||||
@@ -2389,26 +2379,6 @@ public class Graph {
|
||||
return localData;
|
||||
}
|
||||
|
||||
protected GraphPart makeMultiPart(GraphPart part) {
|
||||
List<GraphPart> parts = new ArrayList<>();
|
||||
do {
|
||||
parts.add(part);
|
||||
if (part.nextParts.size() == 1 && part.nextParts.get(0).refs.size() == 1) {
|
||||
part = part.nextParts.get(0);
|
||||
} else {
|
||||
part = null;
|
||||
}
|
||||
} while (part != null);
|
||||
if (parts.size() > 1) {
|
||||
GraphPartMulti ret = new GraphPartMulti(parts);
|
||||
ret.refs.addAll(parts.get(0).refs);
|
||||
ret.nextParts.addAll(parts.get(parts.size() - 1).nextParts);
|
||||
return ret;
|
||||
} else {
|
||||
return parts.get(0);
|
||||
}
|
||||
}
|
||||
|
||||
protected List<GraphSourceItem> getPartItems(GraphPart part) {
|
||||
List<GraphSourceItem> ret = new ArrayList<>();
|
||||
do {
|
||||
|
||||
@@ -1,81 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2010-2021 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 java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author JPEXS
|
||||
*/
|
||||
public class GraphPartMulti extends GraphPart {
|
||||
|
||||
public List<GraphPart> parts;
|
||||
|
||||
public GraphPartMulti(List<GraphPart> parts) {
|
||||
super(parts.get(0).start, parts.get(parts.size() - 1).end);
|
||||
this.parts = parts;
|
||||
this.path = parts.get(0).path;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder ret = new StringBuilder();
|
||||
ret.append("[multi ");
|
||||
boolean first = true;
|
||||
for (GraphPart g : parts) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
ret.append(", ");
|
||||
}
|
||||
ret.append(g.toString());
|
||||
}
|
||||
ret.append("]");
|
||||
return ret.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getHeight() {
|
||||
int ret = 0;
|
||||
for (GraphPart p : parts) {
|
||||
ret += p.getHeight();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPosAt(int offset) {
|
||||
int ofs = 0;
|
||||
int pos = 0;
|
||||
for (GraphPart p : parts) {
|
||||
for (int i = 0; i < p.getHeight(); i++) {
|
||||
pos = p.start + i;
|
||||
ofs += 1;
|
||||
if (ofs == offset) {
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<GraphPart> getSubParts() {
|
||||
return Collections.unmodifiableList(parts);
|
||||
}
|
||||
Reference in New Issue
Block a user