AS3 deobfuscation - remove traps

This commit is contained in:
Jindra Petk
2013-01-27 19:19:43 +01:00
parent da00857837
commit c40a72e402
11 changed files with 463 additions and 167 deletions

View File

@@ -21,7 +21,10 @@ import com.jpexs.asdec.abc.avm2.flowgraph.GraphPart;
import com.jpexs.asdec.gui.View;
import java.awt.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
@@ -42,33 +45,40 @@ public class GraphFrame extends JFrame {
public GraphPanel(Graph graph) {
this.graph = graph;
setPreferredSize(new Dimension((BLOCK_WIDTH + SPACE_HORIZONTAL) * getPartWidth(graph.head, new ArrayList<GraphPart>()), (BLOCK_HEIGHT + SPACE_VERTICAL) * getPartHeight(graph.head, new ArrayList<GraphPart>())));
setPreferredSize(new Dimension((BLOCK_WIDTH + SPACE_HORIZONTAL) * getPartWidth(graph.head, new HashSet<GraphPart>()), (BLOCK_HEIGHT + SPACE_VERTICAL) * getPartHeight(graph.head, new ArrayList<GraphPart>())));
}
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.black);
paintPart(g, graph.head, 0, getPartWidth(graph.head, new ArrayList<GraphPart>()) * (BLOCK_WIDTH + SPACE_HORIZONTAL) / 2, new ArrayList<GraphPart>());
paintPart(g, graph.head, 0, getPartWidth(graph.head, new HashSet<GraphPart>()) * (BLOCK_WIDTH + SPACE_HORIZONTAL) / 2, new HashMap<GraphPart,Point>());
}
private void paintPart(Graphics g, GraphPart part, int y, int x, List<GraphPart> used) {
List<GraphPart> l = new ArrayList<GraphPart>();
l.addAll(used);
int totalWidthParts = getPartWidth(part, l);
private void paintPart(Graphics g, GraphPart part, int y, int x, HashMap<GraphPart,Point> used) {
HashMap<GraphPart,Point> l = new HashMap<GraphPart,Point>();
l.putAll(used);
HashSet<GraphPart> hs=new HashSet<GraphPart>();
hs.addAll(l.keySet());
int totalWidthParts = getPartWidth(part, hs);
int totalWidth = totalWidthParts * (BLOCK_WIDTH + SPACE_HORIZONTAL);
g.drawRect(x - BLOCK_WIDTH / 2 - SPACE_HORIZONTAL / 2, y, BLOCK_WIDTH, BLOCK_HEIGHT);
g.drawString(part.toString(), x - BLOCK_WIDTH / 2, y + BLOCK_HEIGHT);
if (used.contains(part)) {
if (used.containsKey(part)) {
g.setColor(Color.black);
Point p=used.get(part);
g.drawLine(x, y, p.x, p.y);
return;
}
used.add(part);
g.drawRect(x - BLOCK_WIDTH / 2 - SPACE_HORIZONTAL / 2, y, BLOCK_WIDTH, BLOCK_HEIGHT);
g.drawString(part.toString(), x - BLOCK_WIDTH / 2, y + BLOCK_HEIGHT);
used.put(part,new Point(x,y));
if (part.nextParts.size() > 0) {
int cx = x - totalWidth / 2;
for (int p = 0; p < part.nextParts.size(); p++) {
l = new ArrayList<GraphPart>();
l.addAll(used);
int cellWidth = getPartWidth(part.nextParts.get(p), l) * (BLOCK_WIDTH + SPACE_HORIZONTAL);
HashSet<GraphPart> k = new HashSet<GraphPart>();
k.addAll(used.keySet());
int cellWidth = getPartWidth(part.nextParts.get(p), k) * (BLOCK_WIDTH + SPACE_HORIZONTAL);
g.setColor(Color.black);
g.drawLine(x, y + BLOCK_HEIGHT, cx + cellWidth / 2, y + BLOCK_HEIGHT + SPACE_VERTICAL);
paintPart(g, part.nextParts.get(p), y + BLOCK_HEIGHT + SPACE_VERTICAL, cx + cellWidth / 2, used);
@@ -94,7 +104,7 @@ public class GraphFrame extends JFrame {
return 1 + maxH;
}
private int getPartWidth(GraphPart part, List<GraphPart> used) {
private int getPartWidth(GraphPart part, HashSet<GraphPart> used) {
if (used.contains(part)) {
return 1;