Separated FFDec core library and the rest (GUI).

FFDec Library is now LGPLv3, others stay GPLv3.
Version changed to 3.0.0 for FFDec, 1.0.0 for FFDec Library.
This commit is contained in:
Jindra Petřík
2014-08-24 17:55:42 +02:00
parent 2479c59b03
commit 04922aaf69
1323 changed files with 53605 additions and 52175 deletions

View File

@@ -0,0 +1,110 @@
/*
* Copyright (C) 2010-2014 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 com.jpexs.decompiler.flash.action.Action;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
*
* @author JPEXS
*/
public abstract class GraphSource implements Serializable {
public abstract int size();
public abstract GraphSourceItem get(int pos);
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;
private void visitCode(int ip, int lastIp, HashMap<Integer, List<Integer>> refs, int endIp) throws InterruptedException {
if (Thread.currentThread().isInterrupted()) {
throw new InterruptedException();
}
boolean debugMode = false;
while (((endIp == -1) || (ip < endIp)) && (ip < size())) {
refs.get(ip).add(lastIp);
lastIp = ip;
if (refs.get(ip).size() > 1) {
break;
}
GraphSourceItem ins = get(ip);
if (ins.isIgnored()) {
ip++;
continue;
}
if (debugMode) {
System.err.println("visit ip " + ip + " action:" + ins);
}
if (ins.isExit()) {
break;
}
if (ins instanceof GraphSourceItemContainer) {
GraphSourceItemContainer cnt = (GraphSourceItemContainer) ins;
if (ins instanceof Action) { //TODO: Remove dependency of AVM1
long endAddr = ((Action) ins).getAddress() + cnt.getHeaderSize();
for (long size : cnt.getContainerSizes()) {
if (size != 0) {
visitCode(adr2pos(endAddr), ip, refs, adr2pos(endAddr + size));
}
endAddr += size;
}
ip = adr2pos(endAddr);
continue;
}
}
if (ins.isBranch() || ins.isJump()) {
List<Integer> branches = ins.getBranches(this);
for (int b : branches) {
if (b >= 0) {
visitCode(b, ip, refs, endIp);
}
}
break;
}
ip++;
};
}
public HashMap<Integer, List<Integer>> visitCode(List<Integer> alternateEntries) throws InterruptedException {
HashMap<Integer, List<Integer>> refs = new HashMap<>();
int siz = size();
for (int i = 0; i < siz; i++) {
refs.put(i, new ArrayList<Integer>());
}
visitCode(0, 0, refs, -1);
int pos = 0;
for (int e : alternateEntries) {
pos++;
visitCode(e, -pos, refs, -1);
}
return refs;
}
public abstract int adr2pos(long adr);
public abstract long pos2adr(int pos);