#1595 History of script search results per SWF

This commit is contained in:
Jindra Petřík
2021-02-22 21:48:08 +01:00
parent 0d2fcb0897
commit 4097d6b8f2
18 changed files with 528 additions and 27 deletions

View File

@@ -12,19 +12,33 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.search;
import com.jpexs.decompiler.flash.AppResources;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.abc.ABC;
import com.jpexs.decompiler.flash.abc.ClassPath;
import com.jpexs.decompiler.flash.abc.ScriptPack;
import com.jpexs.decompiler.flash.helpers.GraphTextWriter;
import com.jpexs.decompiler.flash.tags.ABCContainerTag;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.io.Serializable;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author JPEXS
*/
*/
public class ABCSearchResult implements Serializable {
public static String STR_INSTANCE_INITIALIZER = AppResources.translate("trait.instanceinitializer");
@@ -32,7 +46,7 @@ public class ABCSearchResult {
public static String STR_SCRIPT_INITIALIZER = AppResources.translate("trait.scriptinitializer");
private ScriptPack scriptPack;
private final boolean pcode;
@@ -40,6 +54,52 @@ public class ABCSearchResult {
private final int traitId;
@SuppressWarnings("unchecked")
public ABCSearchResult(SWF swf, InputStream is) throws IOException, ScriptNotFoundException {
ObjectInputStream ois = new ObjectInputStream(is);
int versionMajor = ois.read();
ois.read(); //minor
if (versionMajor != -1) {
throw new IOException("Unknown search result version");
}
ClassPath cp;
List<Integer> traitIndices;
try {
cp = (ClassPath) ois.readObject();
traitIndices = (List<Integer>) ois.readObject();
} catch (ClassNotFoundException ex) {
Logger.getLogger(ABCSearchResult.class.getName()).log(Level.SEVERE, null, ex);
throw new IOException();
}
this.pcode = ois.readBoolean();
this.classIndex = ois.readInt();
this.traitId = ois.readInt();
boolean packFound = false;
for (ScriptPack pack : swf.getAS3Packs()) {
if (cp.equals(pack.getClassPath()) && traitIndices.equals(pack.traitIndices)) {
this.scriptPack = pack;
packFound = true;
break;
}
}
if (!packFound) {
throw new ScriptNotFoundException();
}
}
public void save(OutputStream os) throws IOException {
ObjectOutputStream oos = new ObjectOutputStream(os);
oos.write(1); //version major
oos.write(0); //version minor
oos.writeObject(scriptPack.getClassPath());
oos.writeObject(scriptPack.traitIndices);
oos.writeBoolean(pcode);
oos.writeInt(classIndex);
oos.writeInt(traitId);
}
public ABCSearchResult(ScriptPack scriptPack) {
this.scriptPack = scriptPack;
pcode = false;

View File

@@ -12,10 +12,18 @@
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library.
* License along with this library.
*/
package com.jpexs.decompiler.flash.search;
import com.jpexs.decompiler.flash.SWF;
import com.jpexs.decompiler.flash.tags.base.ASMSource;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Map;
/**
*
@@ -29,6 +37,24 @@ public class ActionSearchResult {
private final String path;
public ActionSearchResult(SWF swf, InputStream is) throws IOException, ScriptNotFoundException {
Map<String, ASMSource> asms = swf.getASMs(false);
DataInputStream dais = new DataInputStream(is);
path = dais.readUTF();
if (asms.containsKey(path)) {
src = asms.get(path);
} else {
throw new ScriptNotFoundException();
}
pcode = dais.readBoolean();
}
public void save(OutputStream os) throws IOException {
DataOutputStream daos = new DataOutputStream(os);
daos.writeUTF(path);
daos.writeBoolean(pcode);
}
public ActionSearchResult(ASMSource src, boolean pcode, String path) {
this.src = src;
this.pcode = pcode;

View File

@@ -0,0 +1,9 @@
package com.jpexs.decompiler.flash.search;
/**
*
* @author JPEXS
*/
public class ScriptNotFoundException extends Exception {
}