AS2 script import: import pcode/constants

This commit is contained in:
2015-07-02 09:07:55 +02:00
parent 12378f508b
commit f96fb33c4d
18 changed files with 255 additions and 73 deletions
@@ -25,7 +25,7 @@ import com.jpexs.decompiler.flash.abc.avm2.instructions.AVM2Instruction;
import com.jpexs.decompiler.flash.abc.avm2.instructions.executing.CallPropertyIns;
import com.jpexs.decompiler.flash.abc.avm2.instructions.stack.PushStringIns;
import com.jpexs.decompiler.flash.abc.avm2.parser.AVM2ParseException;
import com.jpexs.decompiler.flash.abc.avm2.parser.script.ActionScriptParser;
import com.jpexs.decompiler.flash.abc.avm2.parser.script.ActionScript3Parser;
import com.jpexs.decompiler.flash.abc.types.ABCException;
import com.jpexs.decompiler.flash.abc.types.ClassInfo;
import com.jpexs.decompiler.flash.abc.types.InstanceInfo;
@@ -1247,7 +1247,7 @@ public class ABC {
}
List<ABC> otherAbcs = new ArrayList<>(pack.allABCs);
otherAbcs.remove(this);
ActionScriptParser.compile(as, this, otherAbcs, isDocumentClass, scriptName, newClassIndex);
ActionScript3Parser.compile(as, this, otherAbcs, isDocumentClass, scriptName, newClassIndex);
// Move newly added script to its position
script_info.set(oldIndex, script_info.get(newIndex));
script_info.remove(newIndex);
@@ -104,6 +104,15 @@ public class ScriptPack extends AS3ClassTreeItem {
return scriptName;
}
public File getExportFile(String directory, ScriptExportSettings exportSettings) throws IOException {
String scriptName = getPathScriptName();
String packageName = getPathPackage();
File outDir = new File(directory + File.separatorChar + makeDirPath(packageName));
Path.createDirectorySafe(outDir);
String fileName = outDir.toString() + File.separator + Helper.makeFileName(scriptName) + exportSettings.getFileExtension();
return new File(fileName);
}
/*public String getPath() {
String packageName = "";
String scriptName = "";
@@ -197,12 +206,7 @@ public class ScriptPack extends AS3ClassTreeItem {
File file = null;
if (!exportSettings.singleFile) {
String scriptName = getPathScriptName();
String packageName = getPathPackage();
File outDir = new File(directory + File.separatorChar + makeDirPath(packageName));
Path.createDirectorySafe(outDir);
String fileName = outDir.toString() + File.separator + Helper.makeFileName(scriptName) + exportSettings.getFileExtension();
file = new File(fileName);
file = getExportFile(directory, exportSettings);
}
try (FileTextWriter writer = exportSettings.singleFile ? null : new FileTextWriter(Configuration.getCodeFormatting(), new FileOutputStream(file))) {
@@ -903,6 +903,7 @@ public class AVM2Code implements Cloneable {
writer.newLine();
}
}
if (info != null) {
writer.appendNoHilight("method").newLine();
writer.appendNoHilight("name ");
@@ -1049,7 +1050,7 @@ public class AVM2Code implements Cloneable {
if (exportMode == ScriptExportMode.HEX) {
Helper.byteArrayToHexWithHeader(writer, getBytes());
} else {
} else if (exportMode == ScriptExportMode.PCODE || exportMode == ScriptExportMode.PCODE_HEX) {
for (AVM2Instruction ins : code) {
long ofs = ins.offset;
if (exportMode == ScriptExportMode.PCODE_HEX) {
@@ -1124,7 +1125,10 @@ public class AVM2Code implements Cloneable {
}
ip++;
}
} else if (exportMode == ScriptExportMode.CONSTANTS) {
writer.appendNoHilight("Constant export mode is not supported.").newLine();
}
return writer;
}
@@ -125,7 +125,7 @@ import java.util.logging.Logger;
*
* @author JPEXS
*/
public class ActionScriptParser {
public class ActionScript3Parser {
private long uniqLast = 0;
@@ -2376,7 +2376,7 @@ public class ActionScriptParser {
addScriptFromTree(traits, documentClass, classPos);
}
public ActionScriptParser(ABC abc, List<ABC> otherABCs) {
public ActionScript3Parser(ABC abc, List<ABC> otherABCs) {
this.abc = abc;
this.otherABCs = otherABCs;
}
@@ -2401,7 +2401,7 @@ public class ActionScriptParser {
initPlayer();
parABCs.addAll(playerABCs);
parABCs.addAll(otherABCs);
ActionScriptParser parser = new ActionScriptParser(abc, parABCs);
ActionScript3Parser parser = new ActionScript3Parser(abc, parABCs);
parser.addScript(src, documentClass, fileName, classPos);
}
@@ -2410,13 +2410,13 @@ public class ActionScriptParser {
try {
initPlayer();
ABC abc = new ABC(null);
ActionScriptParser parser = new ActionScriptParser(abc, playerABCs);
ActionScript3Parser parser = new ActionScript3Parser(abc, playerABCs);
parser.addScript(new String(Helper.readFile(src), Utf8Helper.charset), true, src, classPos);
try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(new File(dst)))) {
abc.saveToStream(fos);
}
} catch (Exception ex) {
Logger.getLogger(ActionScriptParser.class.getName()).log(Level.SEVERE, null, ex);
Logger.getLogger(ActionScript3Parser.class.getName()).log(Level.SEVERE, null, ex);
}
System.exit(0);
}