diff --git a/CHANGELOG.md b/CHANGELOG.md index d69b771e9..bc1e1dea7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ All notable changes to this project will be documented in this file. - Select position dialog has target file in its title - [#1649] Moving SWF files (and bundles) up and down (comtext menuitem + ALT up/down shortcut) - Moving tags up and down in the taglist view (context menuitem + ALT up/down shortcut) +- [#1701] Setting charset for SWF files with version 5 or lower ### Fixed - Exception when bundle selected @@ -2542,6 +2543,7 @@ All notable changes to this project will be documented in this file. [alpha 8]: https://github.com/jindrapetrik/jpexs-decompiler/compare/alpha7...alpha8 [alpha 7]: https://github.com/jindrapetrik/jpexs-decompiler/releases/tag/alpha7 [#1649]: https://www.free-decompiler.com/flash/issues/1649 +[#1701]: https://www.free-decompiler.com/flash/issues/1701 [#1863]: https://www.free-decompiler.com/flash/issues/1863 [#1414]: https://www.free-decompiler.com/flash/issues/1414 [#1755]: https://www.free-decompiler.com/flash/issues/1755 diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java index 4fd1feefa..31658beea 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -183,6 +183,7 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -366,6 +367,8 @@ public final class SWF implements SWFContainerItem, Timelined { private Set cyclicCharacters = null; private boolean headerModified = false; + + private String charset = "UTF-8"; private static final DecompilerPool decompilerPool = new DecompilerPool(); @@ -385,6 +388,14 @@ public final class SWF implements SWFContainerItem, Timelined { */ public static final Color ERROR_COLOR = Color.red; + public String getCharset() { + return charset; + } + + public void setCharset(String charset) { + this.charset = charset; + } + public void setHeaderModified(boolean headerModified) { this.headerModified = headerModified; } @@ -973,7 +984,7 @@ public final class SWF implements SWFContainerItem, Timelined { private byte[] saveToByteArray(boolean gfx) throws IOException { byte[] data; try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); - SWFOutputStream sos = new SWFOutputStream(baos, version)) { + SWFOutputStream sos = new SWFOutputStream(baos, version, charset)) { sos.write(getHeaderBytes(SWFCompression.NONE, gfx)); sos.writeUI8(version); sos.writeUI32(0); // placeholder for file length @@ -991,7 +1002,7 @@ public final class SWF implements SWFContainerItem, Timelined { // update file size try (ByteArrayOutputStream baos = new ByteArrayOutputStream(); - SWFOutputStream sos = new SWFOutputStream(baos, version)) { + SWFOutputStream sos = new SWFOutputStream(baos, version, charset)) { sos.writeUI32(data.length); byte[] lengthData = baos.toByteArray(); System.arraycopy(lengthData, 0, data, 4, lengthData.length); @@ -1037,7 +1048,7 @@ public final class SWF implements SWFContainerItem, Timelined { fileSize = sis.readUI32("fileSize"); } - SWFOutputStream sos = new SWFOutputStream(os, version); + SWFOutputStream sos = new SWFOutputStream(os, version, Utf8Helper.charsetName); sos.write(getHeaderBytes(compression, gfx)); sos.writeUI8(version); sos.writeUI32(fileSize); @@ -1152,6 +1163,11 @@ public final class SWF implements SWFContainerItem, Timelined { displayRect = new RECT(0, 1, 0, 1); dumpInfo = new DumpInfoSwfNode(this, "rootswf", "", null, 0, 0); } + + public SWF(String charset) { + this(); + this.charset = charset; + } /** * Construct SWF from stream @@ -1164,6 +1180,10 @@ public final class SWF implements SWFContainerItem, Timelined { public SWF(InputStream is, boolean parallelRead) throws IOException, InterruptedException { this(is, null, null, null, parallelRead, false, true); } + + public SWF(InputStream is, boolean parallelRead, String charset) throws IOException, InterruptedException { + this(is, null, null, null, parallelRead, false, true, charset); + } /** * Construct SWF from stream @@ -1177,6 +1197,10 @@ public final class SWF implements SWFContainerItem, Timelined { public SWF(InputStream is, boolean parallelRead, boolean lazy) throws IOException, InterruptedException { this(is, null, null, null, parallelRead, false, lazy); } + + public SWF(InputStream is, boolean parallelRead, boolean lazy, String charset) throws IOException, InterruptedException { + this(is, null, null, null, parallelRead, false, lazy, charset); + } /** * Construct SWF from stream @@ -1191,6 +1215,10 @@ public final class SWF implements SWFContainerItem, Timelined { public SWF(InputStream is, String file, String fileTitle, boolean parallelRead) throws IOException, InterruptedException { this(is, file, fileTitle, null, parallelRead, false, true); } + + public SWF(InputStream is, String file, String fileTitle, boolean parallelRead, String charset) throws IOException, InterruptedException { + this(is, file, fileTitle, null, parallelRead, false, true, charset); + } /** * Construct SWF from stream @@ -1205,6 +1233,11 @@ public final class SWF implements SWFContainerItem, Timelined { this(is, null, null, listener, parallelRead, false, true); } + public SWF(InputStream is, ProgressListener listener, boolean parallelRead, String charset) throws IOException, InterruptedException { + this(is, null, null, listener, parallelRead, false, true, charset); + } + + /** * Construct SWF from stream * @@ -1219,6 +1252,10 @@ public final class SWF implements SWFContainerItem, Timelined { public SWF(InputStream is, String file, String fileTitle, ProgressListener listener, boolean parallelRead) throws IOException, InterruptedException { this(is, file, fileTitle, listener, parallelRead, false, true); } + + public SWF(InputStream is, String file, String fileTitle, ProgressListener listener, boolean parallelRead, String charset) throws IOException, InterruptedException { + this(is, file, fileTitle, listener, parallelRead, false, true, charset); + } /** * Faster constructor to check SWF only @@ -1230,8 +1267,16 @@ public final class SWF implements SWFContainerItem, Timelined { decompress(is, new NulStream(), true); } + public SWF(InputStream is, String file, String fileTitle, ProgressListener listener, boolean parallelRead, boolean checkOnly, boolean lazy, String charset) throws IOException, InterruptedException { + this(is, file, fileTitle, listener, parallelRead, checkOnly, lazy, null, charset); + } + public SWF(InputStream is, String file, String fileTitle, ProgressListener listener, boolean parallelRead, boolean checkOnly, boolean lazy) throws IOException, InterruptedException { - this(is, file, fileTitle, listener, parallelRead, checkOnly, lazy, null); + this(is, file, fileTitle, listener, parallelRead, checkOnly, lazy, null, Utf8Helper.charsetName); + } + + public SWF(InputStream is, String file, String fileTitle, ProgressListener listener, boolean parallelRead, boolean checkOnly, boolean lazy, UrlResolver resolver) throws IOException, InterruptedException { + this(is, file, fileTitle, listener, parallelRead, checkOnly, lazy, resolver, Utf8Helper.charsetName); } /** @@ -1248,9 +1293,10 @@ public final class SWF implements SWFContainerItem, Timelined { * @throws IOException * @throws java.lang.InterruptedException */ - public SWF(InputStream is, String file, String fileTitle, ProgressListener listener, boolean parallelRead, boolean checkOnly, boolean lazy, UrlResolver resolver) throws IOException, InterruptedException { + public SWF(InputStream is, String file, String fileTitle, ProgressListener listener, boolean parallelRead, boolean checkOnly, boolean lazy, UrlResolver resolver, String charset) throws IOException, InterruptedException { this.file = file; this.fileTitle = fileTitle; + this.charset = charset; ByteArrayOutputStream baos = new ByteArrayOutputStream(); SWFHeader header = decompress(is, baos, true); gfx = header.gfx; @@ -1264,6 +1310,11 @@ public final class SWF implements SWFContainerItem, Timelined { sis.dumpInfo = dumpInfo; sis.skipBytesEx(3, "signature"); // skip siganture version = sis.readUI8("version"); + + if (version > 5) { + this.charset = Utf8Helper.charsetName; + } + fileSize = sis.readUI32("fileSize"); dumpInfo.lengthBytes = fileSize; if (listener != null) { @@ -1617,7 +1668,7 @@ public final class SWF implements SWFContainerItem, Timelined { SWFHeader header = decodeHeader(hdr); long fileSize = header.fileSize; - try (SWFOutputStream sos = new SWFOutputStream(os, header.version)) { + try (SWFOutputStream sos = new SWFOutputStream(os, header.version, Utf8Helper.charsetName)) { sos.write(getHeaderBytes(SWFCompression.NONE, header.gfx)); sos.writeUI8(header.version); sos.writeUI32(fileSize); @@ -2113,7 +2164,7 @@ public final class SWF implements SWFContainerItem, Timelined { GraphSourceItem ins = code.get(ip); if (debugMode) { - System.err.println("Visit " + ip + ": ofs" + Helper.formatAddress(((Action) ins).getAddress()) + ":" + ((Action) ins).getASMSource(new ActionList(), new HashSet<>(), ScriptExportMode.PCODE) + " stack:" + Helper.stackToString(stack, LocalData.create(new ConstantPool()))); + System.err.println("Visit " + ip + ": ofs" + Helper.formatAddress(((Action) ins).getAddress()) + ":" + ((Action) ins).getASMSource(new ActionList(code.getCharset()), new HashSet<>(), ScriptExportMode.PCODE) + " stack:" + Helper.stackToString(stack, LocalData.create(new ConstantPool()))); } if (ins.isExit()) { break; @@ -2171,7 +2222,7 @@ public final class SWF implements SWFContainerItem, Timelined { ip = code.adr2pos(addr); addr += size; int nextip = code.adr2pos(addr); - getVariables(aLocalData.insideDoInitAction, variables, functions, strings, usageTypes, new ActionGraphSource(path, aLocalData.insideDoInitAction, code.getActions().subList(ip, nextip), code.version, new HashMap<>(), new HashMap<>(), new HashMap<>()), 0, path + (cntName == null ? "" : "/" + cntName)); + getVariables(aLocalData.insideDoInitAction, variables, functions, strings, usageTypes, new ActionGraphSource(path, aLocalData.insideDoInitAction, code.getActions().subList(ip, nextip), code.version, new HashMap<>(), new HashMap<>(), new HashMap<>(), code.getCharset()), 0, path + (cntName == null ? "" : "/" + cntName)); ip = nextip; } List> r = new ArrayList<>(); @@ -2272,7 +2323,7 @@ public final class SWF implements SWFContainerItem, Timelined { ActionList actions = src.getActions(); actionsMap.put(src, actions); boolean insideDoInitAction = src instanceof DoInitActionTag; - getVariables(insideDoInitAction, variables, functions, strings, usageTypes, new ActionGraphSource(path, insideDoInitAction, actions, version, new HashMap<>(), new HashMap<>(), new HashMap<>()), 0, path); + getVariables(insideDoInitAction, variables, functions, strings, usageTypes, new ActionGraphSource(path, insideDoInitAction, actions, version, new HashMap<>(), new HashMap<>(), new HashMap<>(), src.getSwf().getCharset()), 0, path); return ret; } @@ -2428,7 +2479,7 @@ public final class SWF implements SWFContainerItem, Timelined { int staticOperation = Graph.SOP_USE_STATIC; //(Boolean) Configuration.getConfig("autoDeobfuscate", true) ? Graph.SOP_SKIP_STATIC : Graph.SOP_USE_STATIC; List dec; try { - dec = Action.actionsToTree(true /*Yes, inside doInitAction*/, false, dia.getActions(), version, staticOperation, ""/*FIXME*/); + dec = Action.actionsToTree(true /*Yes, inside doInitAction*/, false, dia.getActions(), version, staticOperation, ""/*FIXME*/, getCharset()); } catch (EmptyStackException ex) { continue; } @@ -2851,7 +2902,7 @@ public final class SWF implements SWFContainerItem, Timelined { throw ex; } catch (Exception ex) { logger.log(Level.SEVERE, null, ex); - return new ActionList(); + return new ActionList(src.getSwf().getCharset()); } } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java index f51d0914f..2a711c9d4 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFInputStream.java @@ -323,6 +323,13 @@ public class SWFInputStream implements AutoCloseable { private int limit; + public String getCharset() { + if (swf == null) { + return Utf8Helper.charsetName; + } + return swf.getCharset(); + } + public void addPercentListener(ProgressListener listener) { listeners.add(listener); } @@ -363,7 +370,7 @@ public class SWFInputStream implements AutoCloseable { this.swf = swf; this.startingPos = startingPos; this.data = data; - this.limit = limit; + this.limit = limit; is = new MemoryInputStream(data, 0, limit); } @@ -502,7 +509,7 @@ public class SWFInputStream implements AutoCloseable { r = readEx(); if (r == 0) { endDumpLevel(); - return new String(baos.toByteArray(), Utf8Helper.charset); + return new String(baos.toByteArray(), swf == null ? Utf8Helper.charsetName : swf.getCharset()); } baos.write(r); } @@ -1680,7 +1687,7 @@ public class SWFInputStream implements AutoCloseable { try { actionCode = readUI8("actionCode"); if (actionCode == 0) { - return new ActionEnd(); + return new ActionEnd(getCharset()); } if (actionCode == -1) { return null; @@ -1727,7 +1734,7 @@ public class SWFInputStream implements AutoCloseable { case 0x0D: return new ActionDivide(); case 0x0E: - return new ActionEquals(); + return new ActionEquals(getCharset()); case 0x0F: return new ActionLess(); case 0x10: @@ -1765,17 +1772,17 @@ public class SWFInputStream implements AutoCloseable { case 0x9D: return new ActionIf(actionLength, this); case 0x9E: - return new ActionCall(actionLength); + return new ActionCall(actionLength, getCharset()); case 0x1C: return new ActionGetVariable(); case 0x1D: return new ActionSetVariable(); case 0x9A: - return new ActionGetURL2(actionLength, this); + return new ActionGetURL2(actionLength, this, getCharset()); case 0x9F: return new ActionGotoFrame2(actionLength, this); case 0x20: - return new ActionSetTarget2(); + return new ActionSetTarget2(getCharset()); case 0x22: return new ActionGetProperty(); case 0x23: @@ -1862,11 +1869,11 @@ public class SWFInputStream implements AutoCloseable { case 0x50: return new ActionIncrement(); case 0x4C: - return new ActionPushDuplicate(); + return new ActionPushDuplicate(getCharset()); case 0x3E: return new ActionReturn(); case 0x4D: - return new ActionStackSwap(); + return new ActionStackSwap(getCharset()); case 0x87: return new ActionStoreRegister(actionLength, this); // SWF6 Actions @@ -1884,11 +1891,11 @@ public class SWFInputStream implements AutoCloseable { case 0x8E: return new ActionDefineFunction2(actionLength, this, swf.version); case 0x69: - return new ActionExtends(); + return new ActionExtends(getCharset()); case 0x2B: return new ActionCastOp(); case 0x2C: - return new ActionImplementsOp(); + return new ActionImplementsOp(getCharset()); case 0x8F: return new ActionTry(actionLength, this, swf.version); case 0x2A: @@ -1898,7 +1905,7 @@ public class SWFInputStream implements AutoCloseable { //skip(actionLength); }*/ //throw new UnknownActionException(actionCode); - Action r = new ActionUnknown(actionCode, actionLength); + Action r = new ActionUnknown(actionCode, actionLength, getCharset()); if (Configuration.useDetailedLogging.get()) { logger.log(Level.SEVERE, "Unknown action code: {0}", actionCode); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFOutputStream.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFOutputStream.java index 09abca00a..93cb64799 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFOutputStream.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWFOutputStream.java @@ -109,6 +109,8 @@ public class SWFOutputStream extends OutputStream { private int bitPos = 0; private int tempByte = 0; + + private String charset; public long getPos() { return pos; @@ -120,9 +122,10 @@ public class SWFOutputStream extends OutputStream { * @param os OutputStream for writing data * @param version Version of SWF */ - public SWFOutputStream(OutputStream os, int version) { + public SWFOutputStream(OutputStream os, int version, String charset) { this.version = version; this.os = os; + this.charset = charset; } /** @@ -180,7 +183,7 @@ public class SWFOutputStream extends OutputStream { * @throws IOException */ public void writeString(String value) throws IOException { - byte[] data = Utf8Helper.getBytes(value); + byte[] data = value.getBytes(charset); for (int i = 0; i < data.length; i++) { if (data[i] == 0) { throw new IOException("String should not contain null character."); @@ -806,7 +809,7 @@ public class SWFOutputStream extends OutputStream { public void writeCLIPACTIONRECORD(CLIPACTIONRECORD value) throws IOException { writeCLIPEVENTFLAGS(value.eventFlags); ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (SWFOutputStream sos = new SWFOutputStream(baos, version)) { + try (SWFOutputStream sos = new SWFOutputStream(baos, version, charset)) { if (value.eventFlags.clipEventKeyPress) { sos.writeUI8(value.keyCode); } @@ -1154,7 +1157,7 @@ public class SWFOutputStream extends OutputStream { */ public void writeBUTTONCONDACTION(BUTTONCONDACTION value, boolean isLast) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - try (SWFOutputStream sos = new SWFOutputStream(baos, version)) { + try (SWFOutputStream sos = new SWFOutputStream(baos, version, charset)) { sos.writeUB(1, value.condIdleToOverDown ? 1 : 0); sos.writeUB(1, value.condOutDownToIdle ? 1 : 0); sos.writeUB(1, value.condOutDownToOverDown ? 1 : 0); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java index f16d9c1dd..f051cdd1b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/Action.java @@ -81,6 +81,7 @@ import com.jpexs.helpers.Helper; import com.jpexs.helpers.Reference; import java.io.ByteArrayOutputStream; import java.io.IOException; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; @@ -122,12 +123,20 @@ public abstract class Action implements GraphSourceItem { private long address; private long virtualAddress = -1; + + private String charset; @Override public long getLineOffset() { return fileOffset; } + public String getCharset() { + return charset; + } + + + /** * Names of ActionScript properties */ @@ -174,12 +183,13 @@ public abstract class Action implements GraphSourceItem { * @param actionCode Action type identifier * @param actionLength Length of action data */ - public Action(int actionCode, int actionLength) { + public Action(int actionCode, int actionLength, String charset) { this.actionCode = actionCode; this.actionLength = actionLength; + this.charset = charset; } - public Action() { + public Action() { } /** @@ -333,7 +343,7 @@ public abstract class Action implements GraphSourceItem { */ public final byte[] getBytes(int version) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); - SWFOutputStream sos = new SWFOutputStream(baos, version); + SWFOutputStream sos = new SWFOutputStream(baos, version, charset); try { getContentBytes(sos); sos.close(); @@ -377,7 +387,7 @@ public abstract class Action implements GraphSourceItem { */ private byte[] surroundWithAction(byte[] data, int version) { ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); - SWFOutputStream sos2 = new SWFOutputStream(baos2, version); + SWFOutputStream sos2 = new SWFOutputStream(baos2, version, charset); try { sos2.writeUI8(actionCode); if (actionCode >= 0x80) { @@ -843,8 +853,8 @@ public abstract class Action implements GraphSourceItem { return -1; } - public static List actionsToTree(boolean insideDoInitAction, boolean insideFunction, List actions, int version, int staticOperation, String path) throws InterruptedException { - return actionsToTree(insideDoInitAction, insideFunction, new HashMap<>(), new HashMap<>(), new HashMap<>(), actions, version, staticOperation, path); + public static List actionsToTree(boolean insideDoInitAction, boolean insideFunction, List actions, int version, int staticOperation, String path, String charset) throws InterruptedException { + return actionsToTree(insideDoInitAction, insideFunction, new HashMap<>(), new HashMap<>(), new HashMap<>(), actions, version, staticOperation, path, charset); } /** @@ -857,7 +867,7 @@ public abstract class Action implements GraphSourceItem { * @return * @throws java.lang.InterruptedException */ - public static GraphTextWriter actionsToSource(final ASMSource asm, final List actions, final String path, GraphTextWriter writer) throws InterruptedException { + public static GraphTextWriter actionsToSource(final ASMSource asm, final List actions, final String path, GraphTextWriter writer, String charset) throws InterruptedException { writer.suspendMeasure(); List tree = null; Throwable convertException = null; @@ -870,7 +880,7 @@ public abstract class Action implements GraphSourceItem { public List call() throws Exception { int staticOperation = Graph.SOP_USE_STATIC; //(Boolean) Configuration.getConfig("autoDeobfuscate", true) ? Graph.SOP_SKIP_STATIC : Graph.SOP_USE_STATIC; boolean insideDoInitAction = (asm instanceof DoInitActionTag); - List tree = actionsToTree(insideDoInitAction, false, new HashMap<>(), new HashMap<>(), new HashMap<>(), actions, version, staticOperation, path); + List tree = actionsToTree(insideDoInitAction, false, new HashMap<>(), new HashMap<>(), new HashMap<>(), actions, version, staticOperation, path, charset); SWFDecompilerPlugin.fireActionTreeCreated(tree, swf); if (Configuration.autoDeobfuscate.get()) { new ActionDeobfuscator().actionTreeCreated(tree, swf); @@ -929,17 +939,17 @@ public abstract class Action implements GraphSourceItem { * @return List of treeItems * @throws java.lang.InterruptedException */ - public static List actionsToTree(boolean insideDoInitAction, boolean insideFunction, HashMap regNames, HashMap variables, HashMap functions, List actions, int version, int staticOperation, String path) throws InterruptedException { + public static List actionsToTree(boolean insideDoInitAction, boolean insideFunction, HashMap regNames, HashMap variables, HashMap functions, List actions, int version, int staticOperation, String path, String charset) throws InterruptedException { HashMap variablesBackup = new LinkedHashMap<>(variables); HashMap functionsBackup = new LinkedHashMap<>(functions); try { - return ActionGraph.translateViaGraph(null, insideDoInitAction, insideFunction, regNames, variables, functions, actions, version, staticOperation, path); + return ActionGraph.translateViaGraph(null, insideDoInitAction, insideFunction, regNames, variables, functions, actions, version, staticOperation, path, charset); } catch (SecondPassException spe) { variables.clear(); variables.putAll(variablesBackup); functions.clear(); functions.putAll(functionsBackup); - return ActionGraph.translateViaGraph(spe.getData(), insideDoInitAction, insideFunction, regNames, variables, functions, actions, version, staticOperation, path); + return ActionGraph.translateViaGraph(spe.getData(), insideDoInitAction, insideFunction, regNames, variables, functions, actions, version, staticOperation, path, charset); } } @@ -1000,7 +1010,7 @@ public abstract class Action implements GraphSourceItem { return variables2; } - public static List actionsPartToTree(SecondPassData secondPassData, boolean insideDoInitAction, Reference fi, HashMap registerNames, HashMap variables, HashMap functions, TranslateStack stack, List actions, int start, int end, int version, int staticOperation, String path) throws InterruptedException, GraphPartChangeException { + public static List actionsPartToTree(SecondPassData secondPassData, boolean insideDoInitAction, Reference fi, HashMap registerNames, HashMap variables, HashMap functions, TranslateStack stack, List actions, int start, int end, int version, int staticOperation, String path, String charset) throws InterruptedException, GraphPartChangeException { if (start < actions.size() && (end > 0) && (start > 0)) { logger.log(Level.FINE, "Entering {0}-{1}{2}", new Object[]{start, end, actions.size() > 0 ? (" (" + actions.get(start).toString() + " - " + actions.get(end == actions.size() ? end - 1 : end) + ")") : ""}); } @@ -1068,10 +1078,10 @@ public abstract class Action implements GraphSourceItem { } } try { - out = ActionGraph.translateViaGraph(null, insideDoInitAction, true, regNames, variables2, functions, actions.subList(adr2ip(actions, endAddr), adr2ip(actions, endAddr + size)), version, staticOperation, path + (cntName == null ? "" : "/" + cntName)); + out = ActionGraph.translateViaGraph(null, insideDoInitAction, true, regNames, variables2, functions, actions.subList(adr2ip(actions, endAddr), adr2ip(actions, endAddr + size)), version, staticOperation, path + (cntName == null ? "" : "/" + cntName), charset); } catch (SecondPassException spe) { variables2 = prepareVariables(cnt, variables); - out = ActionGraph.translateViaGraph(spe.getData(), insideDoInitAction, true, regNames, variables2, functions, actions.subList(adr2ip(actions, endAddr), adr2ip(actions, endAddr + size)), version, staticOperation, path + (cntName == null ? "" : "/" + cntName)); + out = ActionGraph.translateViaGraph(spe.getData(), insideDoInitAction, true, regNames, variables2, functions, actions.subList(adr2ip(actions, endAddr), adr2ip(actions, endAddr + size)), version, staticOperation, path + (cntName == null ? "" : "/" + cntName), charset); } } catch (OutOfMemoryError | TranslateException | StackOverflowError ex) { logger.log(Level.SEVERE, "Decompilation error in: " + path, ex); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionDefineFunctionPushRegistersCleaner.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionDefineFunctionPushRegistersCleaner.java index 3c4e0efee..de998beb9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionDefineFunctionPushRegistersCleaner.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionDefineFunctionPushRegistersCleaner.java @@ -293,7 +293,7 @@ public class ActionDefineFunctionPushRegistersCleaner extends SWFDecompilerAdapt if (newPushedValues.size() != currentPushedValues.size()) { code.removeAction(pos); //remove that push if (!newPushedValues.isEmpty()) { - ActionPush newPush = new ActionPush(newPushedValues.toArray()); + ActionPush newPush = new ActionPush(newPushedValues.toArray(), code.getCharset()); newPush.constantPool = currentPush.constantPool; code.addAction(pos, newPush); //replace with different push } else { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraph.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraph.java index 0ea8fd0b9..5953ddeca 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraph.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraph.java @@ -70,6 +70,7 @@ import com.jpexs.decompiler.graph.model.SwitchItem; import com.jpexs.decompiler.graph.model.WhileItem; import com.jpexs.helpers.Helper; import com.jpexs.helpers.Reference; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -88,8 +89,8 @@ public class ActionGraph extends Graph { private boolean insideFunction; - public ActionGraph(String path, boolean insideDoInitAction, boolean insideFunction, List code, HashMap registerNames, HashMap variables, HashMap functions, int version) { - super(new ActionGraphSource(path, insideDoInitAction, code, version, registerNames, variables, functions), new ArrayList<>()); + public ActionGraph(String path, boolean insideDoInitAction, boolean insideFunction, List code, HashMap registerNames, HashMap variables, HashMap functions, int version, String charset) { + super(new ActionGraphSource(path, insideDoInitAction, code, version, registerNames, variables, functions, charset), new ArrayList<>()); this.insideDoInitAction = insideDoInitAction; this.insideFunction = insideFunction; } @@ -107,7 +108,7 @@ public class ActionGraph extends Graph { List outs = new ArrayList<>(); for (long size : cnt.getContainerSizes()) { if (size == 0) { - outs.add(new ActionList()); + outs.add(new ActionList(((ActionGraphSource) code).getCharset())); continue; } outs.add(new ActionList(alist.subList(adr2ip(alist, endAddr), adr2ip(alist, endAddr + size)))); @@ -116,7 +117,7 @@ public class ActionGraph extends Graph { for (ActionList al : outs) { subgraphs.put("loc" + Helper.formatAddress(code.pos2adr(ip)) + ": function " + functionName, - new ActionGraph("", false, false, al, new HashMap<>(), new HashMap<>(), new HashMap<>(), SWF.DEFAULT_VERSION) + new ActionGraph("", false, false, al, new HashMap<>(), new HashMap<>(), new HashMap<>(), SWF.DEFAULT_VERSION, ((ActionGraphSource)getGraphCode()).getCharset()) ); } } @@ -134,8 +135,8 @@ public class ActionGraph extends Graph { } - public static List translateViaGraph(SecondPassData secondPassData, boolean insideDoInitAction, boolean insideFunction, HashMap registerNames, HashMap variables, HashMap functions, List code, int version, int staticOperation, String path) throws InterruptedException { - ActionGraph g = new ActionGraph(path, insideDoInitAction, insideFunction, code, registerNames, variables, functions, version); + public static List translateViaGraph(SecondPassData secondPassData, boolean insideDoInitAction, boolean insideFunction, HashMap registerNames, HashMap variables, HashMap functions, List code, int version, int staticOperation, String path, String charset) throws InterruptedException { + ActionGraph g = new ActionGraph(path, insideDoInitAction, insideFunction, code, registerNames, variables, functions, version, charset); ActionLocalData localData = new ActionLocalData(secondPassData, insideDoInitAction, registerNames); g.init(localData); return g.translate(localData, staticOperation, path); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraphSource.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraphSource.java index 0bb177cb8..c98308c9f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraphSource.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionGraphSource.java @@ -26,6 +26,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.TranslateStack; import com.jpexs.helpers.Helper; import com.jpexs.helpers.Reference; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -52,12 +53,14 @@ public class ActionGraphSource extends GraphSource { private final boolean insideDoInitAction; private final String path; + + private String charset; public List getActions() { return actions; } - public ActionGraphSource(String path, boolean insideDoInitAction, List actions, int version, HashMap registerNames, HashMap variables, HashMap functions) { + public ActionGraphSource(String path, boolean insideDoInitAction, List actions, int version, HashMap registerNames, HashMap variables, HashMap functions, String charset) { this.actions = actions instanceof ActionList ? (ActionList) actions : new ActionList(actions); this.version = version; this.registerNames = registerNames; @@ -65,8 +68,15 @@ public class ActionGraphSource extends GraphSource { this.functions = functions; this.insideDoInitAction = insideDoInitAction; this.path = path; + this.charset = charset; } + public String getCharset() { + return charset; + } + + + @Override public Set getImportantAddresses() { return Action.getActionsAllRefs(actions); @@ -103,7 +113,7 @@ public class ActionGraphSource extends GraphSource { public List translatePart(GraphPart part, BaseLocalData localData, TranslateStack stack, int start, int end, int staticOperation, String path) throws InterruptedException, GraphPartChangeException { Reference fi = new Reference<>(localData.lineStartInstruction); - List r = Action.actionsPartToTree(localData.secondPassData, this.insideDoInitAction, fi, registerNames, variables, functions, stack, actions, start, end, version, staticOperation, path); + List r = Action.actionsPartToTree(localData.secondPassData, this.insideDoInitAction, fi, registerNames, variables, functions, stack, actions, start, end, version, staticOperation, path, charset); localData.lineStartInstruction = fi.getVal(); return r; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionList.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionList.java index 30235daa6..5e7adc922 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionList.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionList.java @@ -35,6 +35,7 @@ import com.jpexs.decompiler.graph.GraphSourceItemContainer; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -51,10 +52,18 @@ public class ActionList extends ArrayList { public int deobfuscationMode; public byte[] fileData; + + private String charset; - public ActionList() { + public ActionList(String charset) { + this.charset = charset; } + public String getCharset() { + return charset; + } + + public ActionList(Collection actions) { super(actions); } @@ -501,7 +510,7 @@ public class ActionList extends ArrayList { ActionPush push = (ActionPush) action; ActionPush push2 = (ActionPush) action2; if (!(push.constantPool != null && push2.constantPool != null && push.constantPool != push2.constantPool)) { - ActionPush newPush = new ActionPush(0); + ActionPush newPush = new ActionPush(0, charset); newPush.constantPool = push.constantPool == null ? push2.constantPool : push.constantPool; newPush.values.clear(); newPush.values.addAll(push.values); @@ -525,7 +534,7 @@ public class ActionList extends ArrayList { int j = 0; for (Object value : push.values) { j++; - ActionPush newPush = new ActionPush(value); + ActionPush newPush = new ActionPush(value, charset); newPush.constantPool = push.constantPool; addAction(i + j, newPush); } @@ -556,7 +565,7 @@ public class ActionList extends ArrayList { public String toSource() { try { HighlightedTextWriter writer = new HighlightedTextWriter(new CodeFormatting(), false); - actionsToSource(null, this, "", writer); + actionsToSource(null, this, "", writer, charset); return writer.toString(); } catch (InterruptedException ex) { Logger.getLogger(ActionList.class.getName()).log(Level.SEVERE, null, ex); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java index e37997982..d6f96f7e9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/ActionListReader.java @@ -34,6 +34,7 @@ import com.jpexs.decompiler.graph.GraphSourceItemContainer; import com.jpexs.helpers.CancellableWorker; import com.jpexs.helpers.stat.Statistics; import java.io.IOException; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; @@ -94,7 +95,7 @@ public class ActionListReader { logger.log(Level.SEVERE, null, ex); } } - return new ActionList(); + return new ActionList(sis.getCharset()); } /** @@ -119,10 +120,11 @@ public class ActionListReader { Map nextOffsets = new HashMap<>(); Action entryAction = readActionListAtPos(listeners, null, sis, actionMap, nextOffsets, - ip, 0, endIp, path, false, new ArrayList<>()); + ip, 0, endIp, path, false, new ArrayList<>(), + sis.getCharset()); if (actionMap.isEmpty()) { - return new ActionList(); + return new ActionList(sis.getCharset()); } List addresses = new ArrayList<>(actionMap.keySet()); @@ -131,7 +133,7 @@ public class ActionListReader { Action lastAction = actionMap.get(addresses.get(addresses.size() - 1)); long endAddress; if (!(lastAction instanceof ActionEnd)) { - Action aEnd = new ActionEnd(); + Action aEnd = new ActionEnd(sis.getCharset()); aEnd.setAddress(nextOffsets.get(lastAction.getAddress())); endAddress = aEnd.getAddress(); actionMap.put(aEnd.getAddress(), aEnd); @@ -142,7 +144,7 @@ public class ActionListReader { // jump to the entry action when it is diffrent from the first action in the map if (entryAction != actions.get(0)) { - ActionJump jump = new ActionDeobfuscateJump(0); + ActionJump jump = new ActionDeobfuscateJump(0, sis.getCharset()); actions.addAction(0, jump); jump.setJumpOffset((int) (entryAction.getAddress() - jump.getTotalActionLength())); } @@ -187,7 +189,7 @@ public class ActionListReader { Map> containerLastActions = new HashMap<>(); getContainerLastActions(actions, containerLastActions); - ActionList ret = new ActionList(); + ActionList ret = new ActionList(actions.getCharset()); ret.fileData = actions.fileData; if (nextOffsets != null) { @@ -200,7 +202,7 @@ public class ActionListReader { long nextAddress = nextOffsets.get(action.getAddress()); if (actions.get(index).getAddress() != nextAddress) { if (!action.isExit() && !(action instanceof ActionJump)) { - ActionJump jump = new ActionDeobfuscateJump(0); + ActionJump jump = new ActionDeobfuscateJump(0, actions.getCharset()); jump.setAddress(action.getAddress()); int size = jump.getTotalActionLength(); jump.setJumpOffset((int) (nextAddress - action.getAddress() - size)); @@ -219,10 +221,10 @@ public class ActionListReader { getJumps(ret, jumps); updateActionLengths(ret); - updateAddresses(ret, 0); + updateAddresses(ret, 0, actions.getCharset()); long endAddress = ret.get(ret.size() - 1).getAddress(); - updateJumps(ret, jumps, containerLastActions, endAddress); + updateJumps(ret, jumps, containerLastActions, endAddress, actions.getCharset()); updateActionStores(ret, jumps); updateContainerSizes(ret, containerLastActions); @@ -235,7 +237,8 @@ public class ActionListReader { Map nextOffsets = new HashMap<>(); readActionListAtPos(new ArrayList<>(), null, sis, actionMap, nextOffsets, - startIp, startIp, endIp + 1, "", false, new ArrayList<>()); + startIp, startIp, endIp + 1, "", false, new ArrayList<>(), + sis.getCharset()); return new ArrayList<>(actionMap.values()); } @@ -328,14 +331,14 @@ public class ActionListReader { } } - private static long updateAddresses(List actions, long address) { + private static long updateAddresses(List actions, long address, String charset) { for (int i = 0; i < actions.size(); i++) { Action a = actions.get(i); a.setAddress(address); int length = a.getTotalActionLength(); if ((i != actions.size() - 1) && (a instanceof ActionEnd)) { // placeholder for jump action - length = new ActionDeobfuscateJump(0).getTotalActionLength(); + length = new ActionDeobfuscateJump(0, charset).getTotalActionLength(); } address += length; } @@ -406,7 +409,7 @@ public class ActionListReader { } } - private static void updateJumps(List actions, Map jumps, Map> containerLastActions, long endAddress) { + private static void updateJumps(List actions, Map jumps, Map> containerLastActions, long endAddress, String charset) { if (actions.isEmpty()) { return; } @@ -414,7 +417,7 @@ public class ActionListReader { for (int i = 0; i < actions.size(); i++) { Action a = actions.get(i); if ((i != actions.size() - 1) && (a instanceof ActionEnd)) { - ActionJump aJump = new ActionDeobfuscateJump(0); + ActionJump aJump = new ActionDeobfuscateJump(0, charset); aJump.setJumpOffset((int) (endAddress - a.getAddress() - aJump.getTotalActionLength())); aJump.setAddress(a.getAddress()); replaceJumpTargets(jumps, a, aJump); @@ -501,8 +504,8 @@ public class ActionListReader { actions.remove(index); updateActionLengths(actions); - updateAddresses(actions, startIp); - updateJumps(actions, jumps, containerLastActions, endAddress); + updateAddresses(actions, startIp, actions.getCharset()); + updateJumps(actions, jumps, containerLastActions, endAddress, actions.getCharset()); updateActionStores(actions, jumps); updateContainerSizes(actions, containerLastActions); @@ -564,8 +567,8 @@ public class ActionListReader { } updateActionLengths(actions); - updateAddresses(actions, startIp); - updateJumps(actions, jumps, containerLastActions, endAddress); + updateAddresses(actions, startIp, actions.getCharset()); + updateJumps(actions, jumps, containerLastActions, endAddress, actions.getCharset()); updateActionStores(actions, jumps); updateContainerSizes(actions, containerLastActions); @@ -593,7 +596,7 @@ public class ActionListReader { long startIp = actions.get(0).getAddress(); Action lastAction = actions.get(actions.size() - 1); if (!(lastAction instanceof ActionEnd)) { - Action aEnd = new ActionEnd(); + Action aEnd = new ActionEnd(actions.getCharset()); aEnd.setAddress(lastAction.getAddress() + lastAction.getTotalActionLength()); actions.add(aEnd); lastAction = aEnd; @@ -633,8 +636,8 @@ public class ActionListReader { actions.add(index, action); updateActionLengths(actions); - updateAddresses(actions, startIp); - updateJumps(actions, jumps, containerLastActions, endAddress); + updateAddresses(actions, startIp, actions.getCharset()); + updateJumps(actions, jumps, containerLastActions, endAddress, actions.getCharset()); updateActionStores(actions, jumps); updateContainerSizes(actions, containerLastActions); @@ -659,7 +662,7 @@ public class ActionListReader { long startIp = actions.get(0).getAddress(); Action lastAction = actions.get(actions.size() - 1); if (!(lastAction instanceof ActionEnd)) { - Action aEnd = new ActionEnd(); + Action aEnd = new ActionEnd(actions.getCharset()); aEnd.setAddress(lastAction.getAddress() + lastAction.getTotalActionLength()); actions.add(aEnd); lastAction = aEnd; @@ -678,8 +681,8 @@ public class ActionListReader { actions.addAll(index, newActions); updateActionLengths(actions); - updateAddresses(actions, startIp); - updateJumps(actions, jumps, containerLastActions, endAddress); + updateAddresses(actions, startIp, actions.getCharset()); + updateJumps(actions, jumps, containerLastActions, endAddress, actions.getCharset()); updateActionStores(actions, jumps); updateContainerSizes(actions, containerLastActions); @@ -688,7 +691,7 @@ public class ActionListReader { private static Action readActionListAtPos(List listeners, ConstantPool cpool, SWFInputStream sis, Map actions, Map nextOffsets, - long ip, long startIp, long endIp, String path, boolean indeterminate, List visitedContainers) throws IOException { + long ip, long startIp, long endIp, String path, boolean indeterminate, List visitedContainers, String charset) throws IOException { Action entryAction = null; @@ -718,7 +721,7 @@ public class ActionListReader { // unknown action, replace with jump if (a instanceof ActionUnknown && a.getActionCode() >= 0x80) { - ActionJump aJump = new ActionDeobfuscateJump(0); + ActionJump aJump = new ActionDeobfuscateJump(0, charset); int jumpLength = aJump.getTotalActionLength(); aJump.setAddress(a.getAddress()); //FIXME! This offset can be larger than SI16 value! @@ -774,7 +777,8 @@ public class ActionListReader { long endIp2 = ip + actionLengthWithHeader + size; readActionListAtPos(listeners, cpool, sis, actions, nextOffsets, - ip2, startIp, endIp2, newPath, indeterminate, visitedContainers); + ip2, startIp, endIp2, newPath, indeterminate, visitedContainers, + charset); actionLengthWithHeader += size; } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscator.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscator.java index 458735aba..4b1c576d9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscator.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/deobfuscation/ActionDeobfuscator.java @@ -146,7 +146,7 @@ public class ActionDeobfuscator extends SWFDecompilerAdapter { } if (isGetTime && a2 instanceof ActionIf) { - ActionJump jump = new ActionJump(0); + ActionJump jump = new ActionJump(0, actions.getCharset()); ActionItem jumpItem = new ActionItem(jump); jumpItem.setJumpTarget(a2Item.getJumpTarget()); iterator.remove(); // GetTime @@ -168,7 +168,7 @@ public class ActionDeobfuscator extends SWFDecompilerAdapter { ActionItem a2Item = iterator.peek(1); Action a2 = a2Item.action; if (a instanceof ActionGetTime && a1 instanceof ActionIncrement && a2 instanceof ActionIf) { - ActionJump jump = new ActionJump(0); + ActionJump jump = new ActionJump(0, actions.getCharset()); ActionItem jumpItem = new ActionItem(jump); jumpItem.setJumpTarget(a2Item.getJumpTarget()); iterator.remove(); // GetTime @@ -259,17 +259,17 @@ public class ActionDeobfuscator extends SWFDecompilerAdapter { } else { ActionItem prevActionItem = actionItem.prev; if (result.constantPool != null) { - ActionConstantPool constantPool2 = new ActionConstantPool(new ArrayList<>(result.constantPool.constantPool)); + ActionConstantPool constantPool2 = new ActionConstantPool(new ArrayList<>(result.constantPool.constantPool), actions.getCharset()); ActionItem constantPoolItem = new ActionItem(constantPool2); iterator.addBefore(constantPoolItem); } for (String variableName : result.variables.keySet()) { Object value = result.variables.get(variableName); - ActionPush push = new ActionPush(variableName); + ActionPush push = new ActionPush(variableName, actions.getCharset()); ActionItem pushItem = new ActionItem(push); iterator.addBefore(pushItem); - push = new ActionPush(value); + push = new ActionPush(value, actions.getCharset()); pushItem = new ActionItem(push); iterator.addBefore(pushItem); @@ -286,13 +286,13 @@ public class ActionDeobfuscator extends SWFDecompilerAdapter { if (!result.stack.isEmpty()) { for (Object obj : result.stack) { - ActionPush push = new ActionPush(obj); + ActionPush push = new ActionPush(obj, actions.getCharset()); ActionItem pushItem = new ActionItem(push); iterator.addBefore(pushItem); } } - ActionJump jump = new ActionJump(0); + ActionJump jump = new ActionJump(0, actions.getCharset()); ActionItem jumpItem = new ActionItem(jump); jumpItem.setJumpTarget(result.item); iterator.addBefore(jumpItem); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java index 860066daf..00adba486 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/fastactionlist/FastActionList.java @@ -24,6 +24,7 @@ import com.jpexs.decompiler.flash.action.swf4.ActionIf; import com.jpexs.decompiler.flash.action.swf4.ActionJump; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.graph.GraphSourceItemContainer; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; @@ -45,6 +46,8 @@ public class FastActionList implements Collection { private final Map actionItemMap; private final Set actionItemSet; + + private String charset; public FastActionList(ActionList actions) { actionItemMap = new HashMap<>(actions.size()); @@ -56,8 +59,15 @@ public class FastActionList implements Collection { size = actions.size(); getContainerLastActions(actions, actionItemMap); getJumps(actions, actionItemMap); + charset = actions.getCharset(); } + public String getCharset() { + return charset; + } + + + public final ActionItem insertItemBefore(ActionItem item, Action action) { ActionItem newItem = new ActionItem(action); return insertItemBefore(item, newItem); @@ -387,7 +397,7 @@ public class FastActionList implements Collection { if (push.values.size() > 1) { for (int i = 1; i < push.values.size(); i++) { Object value = push.values.get(i); - ActionPush newPush = new ActionPush(value); + ActionPush newPush = new ActionPush(value, charset); newPush.constantPool = push.constantPool; insertItemAfter(item, newPush); item = item.next; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/flashlite/ActionFSCommand2.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/flashlite/ActionFSCommand2.java index 540c1009b..ba775dd5b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/flashlite/ActionFSCommand2.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/flashlite/ActionFSCommand2.java @@ -24,6 +24,7 @@ import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.SecondPassData; import com.jpexs.decompiler.graph.TranslateStack; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -34,8 +35,8 @@ import java.util.List; */ public class ActionFSCommand2 extends Action { - public ActionFSCommand2() { - super(0x2D, 0); + public ActionFSCommand2(String charset) { + super(0x2D, 0, charset); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/flashlite/ActionStrictMode.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/flashlite/ActionStrictMode.java index 11ad80b3b..a08b75e9c 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/flashlite/ActionStrictMode.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/flashlite/ActionStrictMode.java @@ -28,6 +28,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.SecondPassData; import com.jpexs.decompiler.graph.TranslateStack; import java.io.IOException; +import java.nio.charset.Charset; import java.util.HashMap; import java.util.List; @@ -40,12 +41,12 @@ public class ActionStrictMode extends Action { public int mode; public ActionStrictMode(SWFInputStream sis) throws IOException { - super(0x89, 1); + super(0x89, 1, sis.getCharset()); mode = sis.readUI8("mode"); } - public ActionStrictMode(FlasmLexer lexer) throws IOException, ActionParseException { - super(0x89, 1); + public ActionStrictMode(FlasmLexer lexer, String charset) throws IOException, ActionParseException { + super(0x89, 1, charset); mode = (int) lexLong(lexer); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/ActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/ActionItem.java index 355eac968..0739c8287 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/ActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/ActionItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf4.ActionPop; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; @@ -27,6 +28,7 @@ import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; import com.jpexs.decompiler.graph.model.UnboundedTypeItem; import java.io.Serializable; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; @@ -74,11 +76,14 @@ public abstract class ActionItem extends GraphTargetItem implements Serializable } protected List toSourceCall(SourceGeneratorLocalData localData, SourceGenerator gen, List list) throws CompilationException { + ActionSourceGenerator asGenerator = (ActionSourceGenerator) gen; + String charset = asGenerator.getCharset(); + List ret = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { ret.addAll(0, list.get(i).toSource(localData, gen)); } - ret.add(new ActionPush((Long) (long) list.size())); + ret.add(new ActionPush((Long) (long) list.size(), charset)); return ret; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/CloneSpriteActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/CloneSpriteActionItem.java index bc7aed241..8deea443b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/CloneSpriteActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/CloneSpriteActionItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf4.ActionCloneSprite; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.ecma.Undefined; @@ -28,6 +29,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -81,7 +83,10 @@ public class CloneSpriteActionItem extends ActionItem { @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { - return toSourceMerge(localData, generator, source, target, depth, new ActionCloneSprite(), new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE})); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + + return toSourceMerge(localData, generator, source, target, depth, new ActionCloneSprite(), new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset)); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/DeleteActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/DeleteActionItem.java index 356ab2c08..d107120a1 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/DeleteActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/DeleteActionItem.java @@ -94,7 +94,7 @@ public class DeleteActionItem extends ActionItem { } @Override - public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { + public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { if (object == null) { return toSourceMerge(localData, generator, propertyName, new ActionDelete2()); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/DirectValueActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/DirectValueActionItem.java index 6eaa4fd98..6f7d2fac0 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/DirectValueActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/DirectValueActionItem.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.IdentifiersDeobfuscation; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.action.swf4.ConstantIndex; import com.jpexs.decompiler.flash.action.swf4.RegisterNumber; @@ -33,6 +34,7 @@ import com.jpexs.decompiler.graph.SimpleValue; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; import com.jpexs.helpers.Helper; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -259,7 +261,10 @@ public class DirectValueActionItem extends ActionItem implements SimpleValue { @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { - return toSourceMerge(localData, generator, new ActionPush(value)); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + + return toSourceMerge(localData, generator, new ActionPush(value, charset)); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/FSCommand2ActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/FSCommand2ActionItem.java index 227fe0676..6a606b2a9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/FSCommand2ActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/FSCommand2ActionItem.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; import com.jpexs.decompiler.flash.action.flashlite.ActionFSCommand2; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.graph.CompilationException; @@ -27,6 +28,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -78,13 +80,18 @@ public class FSCommand2ActionItem extends ActionItem { @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { + + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + + List ret = new ArrayList<>(); for (GraphTargetItem a : arguments) { ret.addAll(a.toSource(localData, generator)); } ret.addAll(command.toSource(localData, generator)); - ret.add(new ActionPush((Long) (long) arguments.size())); - ret.add(new ActionFSCommand2()); + ret.add(new ActionPush((Long) (long) arguments.size(), charset)); + ret.add(new ActionFSCommand2(charset)); return ret; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/FSCommandActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/FSCommandActionItem.java index 7042d0937..49b31ee89 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/FSCommandActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/FSCommandActionItem.java @@ -29,6 +29,7 @@ import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -66,11 +67,12 @@ public class FSCommandActionItem extends ActionItem { private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { - ActionSourceGenerator asg = (ActionSourceGenerator) generator; + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); if ((command instanceof DirectValueActionItem) && ((DirectValueActionItem) command).isString()) { - return toSourceMerge(localData, generator, new ActionGetURL("FSCommand:" + ((DirectValueActionItem) command).getAsString(), "")); + return toSourceMerge(localData, generator, new ActionGetURL("FSCommand:" + ((DirectValueActionItem) command).getAsString(), "", charset)); } - return toSourceMerge(localData, generator, new AddActionItem(null, null, asg.pushConstTargetItem("FSCommand:"), command, true), asg.pushConstTargetItem(""), new ActionGetURL2(1/*GET*/, false, false), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + return toSourceMerge(localData, generator, new AddActionItem(null, null, asGenerator.pushConstTargetItem("FSCommand:"), command, true), asGenerator.pushConstTargetItem(""), new ActionGetURL2(1/*GET*/, false, false, charset), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/FunctionActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/FunctionActionItem.java index 249145e60..3e89a7a35 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/FunctionActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/FunctionActionItem.java @@ -38,6 +38,7 @@ import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.BranchStackResistant; import com.jpexs.decompiler.graph.model.LocalData; import com.jpexs.helpers.Helper; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -282,13 +283,15 @@ public class FunctionActionItem extends ActionItem implements BranchStackResista @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + Set usedNames = new HashSet<>(); for (VariableActionItem v : variables) { usedNames.add(v.getVariableName()); } List ret = new ArrayList<>(); - ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; List paramRegs = new ArrayList<>(); SourceGeneratorLocalData localDataCopy = Helper.deepCopy(localData); localDataCopy.inFunction++; @@ -437,7 +440,7 @@ public class FunctionActionItem extends ActionItem implements BranchStackResista } int len = Action.actionsToBytes(asGenerator.toActionList(ret), false, SWF.DEFAULT_VERSION).length; if (!needsFun2 && paramNames.isEmpty()) { - ret.add(0, new ActionDefineFunction(functionName, paramNames, len, SWF.DEFAULT_VERSION)); + ret.add(0, new ActionDefineFunction(functionName, paramNames, len, SWF.DEFAULT_VERSION, charset)); } else { ret.add(0, new ActionDefineFunction2(functionName, preloadParentFlag, @@ -449,7 +452,7 @@ public class FunctionActionItem extends ActionItem implements BranchStackResista suppressThisFlag, preloadThisFlag, preloadGlobalFlag, - regCount, len, SWF.DEFAULT_VERSION, paramNames, paramRegs)); + regCount, len, SWF.DEFAULT_VERSION, paramNames, paramRegs, charset)); } return ret; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GetPropertyActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GetPropertyActionItem.java index c0515d998..e48d299c7 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GetPropertyActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GetPropertyActionItem.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; import com.jpexs.decompiler.flash.action.Action; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf4.ActionGetProperty; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; @@ -28,6 +29,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -136,7 +138,9 @@ public class GetPropertyActionItem extends ActionItem { @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { - return toSourceMerge(localData, generator, target, new ActionPush((Long) (long) propertyIndex), new ActionGetProperty()); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, target, new ActionPush((Long) (long) propertyIndex, charset), new ActionGetProperty()); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GetURL2ActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GetURL2ActionItem.java index a03fb1b7d..18b74408d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GetURL2ActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GetURL2ActionItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf4.ActionGetURL2; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.ecma.Undefined; @@ -28,6 +29,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -94,7 +96,9 @@ public class GetURL2ActionItem extends ActionItem { } private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { - return toSourceMerge(localData, generator, urlString, targetString, new ActionGetURL2(sendVarsMethod, false, false), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, urlString, targetString, new ActionGetURL2(sendVarsMethod, false, false, charset), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GetURLActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GetURLActionItem.java index 91f321326..883011187 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GetURLActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GetURLActionItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf3.ActionGetURL; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.graph.CompilationException; @@ -25,6 +26,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; import com.jpexs.helpers.Helper; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -57,7 +59,9 @@ public class GetURLActionItem extends ActionItem { @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { - return toSourceMerge(localData, generator, new ActionGetURL(urlString, targetString)); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, new ActionGetURL(urlString, targetString, charset)); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GetVersionActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GetVersionActionItem.java index 3dc672436..2b7038642 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GetVersionActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GetVersionActionItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf4.ActionGetVariable; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; @@ -24,6 +25,7 @@ import com.jpexs.decompiler.graph.CompilationException; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; /** @@ -45,7 +47,9 @@ public class GetVersionActionItem extends ActionItem { @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { - return toSourceMerge(localData, generator, new ActionPush("/:$version"), new ActionGetVariable()); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, new ActionPush("/:$version", charset), new ActionGetVariable()); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GotoFrame2ActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GotoFrame2ActionItem.java index baa090c80..dbc73aa34 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GotoFrame2ActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GotoFrame2ActionItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf3.ActionGoToLabel; import com.jpexs.decompiler.flash.action.swf3.ActionGotoFrame; import com.jpexs.decompiler.flash.action.swf3.ActionPlay; @@ -31,6 +32,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -96,12 +98,14 @@ public class GotoFrame2ActionItem extends ActionItem { } private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); if (!sceneBiasFlag && (frame instanceof DirectValueActionItem) && (((DirectValueActionItem) frame).isString())) { - return toSourceMerge(localData, generator, new ActionGoToLabel(((DirectValueActionItem) frame).getAsString()), playFlag ? new ActionPlay() : null, needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + return toSourceMerge(localData, generator, new ActionGoToLabel(((DirectValueActionItem) frame).getAsString(), charset), playFlag ? new ActionPlay() : null, needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } else if (!sceneBiasFlag && (frame instanceof DirectValueActionItem) && (((DirectValueActionItem) frame).value instanceof Long)) { - return toSourceMerge(localData, generator, new ActionGotoFrame((int) ((long) (Long) ((DirectValueActionItem) frame).value) - 1), playFlag ? new ActionPlay() : null, needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + return toSourceMerge(localData, generator, new ActionGotoFrame((int) ((long) (Long) ((DirectValueActionItem) frame).value) - 1, charset), playFlag ? new ActionPlay() : null, needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } else { - return toSourceMerge(localData, generator, frame, new ActionGotoFrame2(playFlag, sceneBiasFlag, sceneBias), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + return toSourceMerge(localData, generator, frame, new ActionGotoFrame2(playFlag, sceneBiasFlag, sceneBias, charset), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GotoFrameActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GotoFrameActionItem.java index 097af6bd6..29a048379 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GotoFrameActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GotoFrameActionItem.java @@ -17,12 +17,14 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf3.ActionGotoFrame; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.graph.CompilationException; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; /** @@ -49,7 +51,9 @@ public class GotoFrameActionItem extends ActionItem { @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { - return toSourceMerge(localData, generator, new ActionGotoFrame(frame)); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, new ActionGotoFrame(frame, charset)); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GotoLabelActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GotoLabelActionItem.java index 7baf7a390..9cd90022e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GotoLabelActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/GotoLabelActionItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf3.ActionGoToLabel; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.graph.CompilationException; @@ -24,6 +25,7 @@ import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; import com.jpexs.helpers.Helper; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -51,7 +53,9 @@ public class GotoLabelActionItem extends ActionItem { @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { - return toSourceMerge(localData, generator, new ActionGoToLabel(label)); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, new ActionGoToLabel(label, charset)); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/InitObjectActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/InitObjectActionItem.java index ac94f446a..78b2a1361 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/InitObjectActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/InitObjectActionItem.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.IdentifiersDeobfuscation; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.action.swf5.ActionInitObject; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; @@ -29,6 +30,7 @@ import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; import com.jpexs.decompiler.graph.model.TernarOpItem; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -90,12 +92,14 @@ public class InitObjectActionItem extends ActionItem { @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); List ret = new ArrayList<>(); for (int i = values.size() - 1; i >= 0; i--) { ret.addAll(names.get(i).toSource(localData, generator)); ret.addAll(values.get(i).toSource(localData, generator)); } - ret.add(new ActionPush((Long) (long) values.size())); + ret.add(new ActionPush((Long) (long) values.size(), charset)); ret.add(new ActionInitObject()); return ret; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/LoadMovieActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/LoadMovieActionItem.java index 0391e7d15..2f74e4537 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/LoadMovieActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/LoadMovieActionItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf4.ActionGetURL2; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.ecma.Undefined; @@ -27,6 +28,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -84,7 +86,9 @@ public class LoadMovieActionItem extends ActionItem { } private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { - return toSourceMerge(localData, generator, urlString, targetString, new ActionGetURL2(method, false, true), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, urlString, targetString, new ActionGetURL2(method, false, true, charset), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/LoadMovieNumActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/LoadMovieNumActionItem.java index 558479457..f4747a5b9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/LoadMovieNumActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/LoadMovieNumActionItem.java @@ -29,6 +29,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -87,13 +88,14 @@ public class LoadMovieNumActionItem extends ActionItem { private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); Object lev; if ((num instanceof DirectValueActionItem) && (((DirectValueActionItem) num).value instanceof Long)) { lev = asGenerator.pushConstTargetItem("_level" + ((DirectValueActionItem) num).value); } else { lev = new AddActionItem(getSrc(), getLineStartItem(), asGenerator.pushConstTargetItem("_level"), num, true); } - return toSourceMerge(localData, generator, urlString, lev, new ActionGetURL2(method, false, false), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + return toSourceMerge(localData, generator, urlString, lev, new ActionGetURL2(method, false, false, charset), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/LoadVariablesActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/LoadVariablesActionItem.java index ccad4da5d..79904b32b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/LoadVariablesActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/LoadVariablesActionItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf4.ActionGetURL2; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.ecma.Undefined; @@ -27,6 +28,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -84,7 +86,9 @@ public class LoadVariablesActionItem extends ActionItem { } private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { - return toSourceMerge(localData, generator, urlString, targetString, new ActionGetURL2(method, true, true), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, urlString, targetString, new ActionGetURL2(method, true, true, charset), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/LoadVariablesNumActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/LoadVariablesNumActionItem.java index 9ac19638f..766564daf 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/LoadVariablesNumActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/LoadVariablesNumActionItem.java @@ -29,6 +29,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -87,13 +88,14 @@ public class LoadVariablesNumActionItem extends ActionItem { private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); Object lev; if ((num instanceof DirectValueActionItem) && (((DirectValueActionItem) num).value instanceof Long)) { lev = asGenerator.pushConstTargetItem("_level" + ((DirectValueActionItem) num).value); } else { lev = new AddActionItem(getSrc(), getLineStartItem(), asGenerator.pushConstTargetItem("_level"), num, true); } - return toSourceMerge(localData, generator, urlString, lev, new ActionGetURL2(method, true, false), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + return toSourceMerge(localData, generator, urlString, lev, new ActionGetURL2(method, true, false, charset), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/NextFrameActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/NextFrameActionItem.java index 03211c732..caf5543b6 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/NextFrameActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/NextFrameActionItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf3.ActionNextFrame; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.ecma.Undefined; @@ -25,6 +26,7 @@ import com.jpexs.decompiler.graph.CompilationException; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; /** @@ -55,7 +57,9 @@ public class NextFrameActionItem extends ActionItem { } private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { - return toSourceMerge(localData, generator, new ActionNextFrame(), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, new ActionNextFrame(), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PlayActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PlayActionItem.java index 6e0230c50..25b8ffac8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PlayActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PlayActionItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf3.ActionPlay; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.ecma.Undefined; @@ -25,6 +26,7 @@ import com.jpexs.decompiler.graph.CompilationException; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; /** @@ -55,7 +57,9 @@ public class PlayActionItem extends ActionItem { } private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { - return toSourceMerge(localData, generator, new ActionPlay(), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, new ActionPlay(), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PostDecrementActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PostDecrementActionItem.java index 580369dcb..8dd670541 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PostDecrementActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PostDecrementActionItem.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; import com.jpexs.decompiler.flash.action.model.operations.SubtractActionItem; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.parser.script.VariableActionItem; import com.jpexs.decompiler.flash.action.swf4.ActionPop; import com.jpexs.decompiler.flash.action.swf4.ActionPush; @@ -34,6 +35,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -101,6 +103,9 @@ public class PostDecrementActionItem extends ActionItem implements SetTypeAction @Override public List toSourceIgnoreReturnValue(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + List ret = new ArrayList<>(); GraphTargetItem val = object; @@ -124,9 +129,9 @@ public class PostDecrementActionItem extends ActionItem implements SetTypeAction ret.add(new ActionSetMember()); } else if ((val instanceof DirectValueActionItem) && ((DirectValueActionItem) val).value instanceof RegisterNumber) { RegisterNumber rn = (RegisterNumber) ((DirectValueActionItem) val).value; - ret.add(new ActionPush(new RegisterNumber(rn.number))); + ret.add(new ActionPush(new RegisterNumber(rn.number), charset)); ret.add(new ActionDecrement()); - ret.add(new ActionStoreRegister(rn.number)); + ret.add(new ActionStoreRegister(rn.number, charset)); ret.add(new ActionPop()); } else if (val instanceof GetPropertyActionItem) { GetPropertyActionItem gp = (GetPropertyActionItem) val; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PostIncrementActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PostIncrementActionItem.java index 99684d609..1bb79c183 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PostIncrementActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PostIncrementActionItem.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; import com.jpexs.decompiler.flash.action.model.operations.AddActionItem; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.parser.script.VariableActionItem; import com.jpexs.decompiler.flash.action.swf4.ActionPop; import com.jpexs.decompiler.flash.action.swf4.ActionPush; @@ -34,6 +35,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -101,6 +103,10 @@ public class PostIncrementActionItem extends ActionItem implements SetTypeAction @Override public List toSourceIgnoreReturnValue(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { + + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + List ret = new ArrayList<>(); GraphTargetItem val = object; @@ -124,9 +130,9 @@ public class PostIncrementActionItem extends ActionItem implements SetTypeAction ret.add(new ActionSetMember()); } else if ((val instanceof DirectValueActionItem) && ((DirectValueActionItem) val).value instanceof RegisterNumber) { RegisterNumber rn = (RegisterNumber) ((DirectValueActionItem) val).value; - ret.add(new ActionPush(new RegisterNumber(rn.number))); + ret.add(new ActionPush(new RegisterNumber(rn.number), charset)); ret.add(new ActionIncrement()); - ret.add(new ActionStoreRegister(rn.number)); + ret.add(new ActionStoreRegister(rn.number, charset)); ret.add(new ActionPop()); } else if (val instanceof GetPropertyActionItem) { GetPropertyActionItem gp = (GetPropertyActionItem) val; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PrevFrameActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PrevFrameActionItem.java index c26376f62..d4acd4d4a 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PrevFrameActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PrevFrameActionItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf3.ActionPrevFrame; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.ecma.Undefined; @@ -25,6 +26,7 @@ import com.jpexs.decompiler.graph.CompilationException; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; /** @@ -55,7 +57,9 @@ public class PrevFrameActionItem extends ActionItem { } private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { - return toSourceMerge(localData, generator, new ActionPrevFrame(), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, new ActionPrevFrame(), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PrintActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PrintActionItem.java index 87a543cc0..3e4e0f54e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PrintActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PrintActionItem.java @@ -29,6 +29,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -77,7 +78,8 @@ public class PrintActionItem extends ActionItem { private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; - return toSourceMerge(localData, generator, new AddActionItem(getSrc(), getLineStartItem(), asGenerator.pushConstTargetItem("print:#"), boundingBox, true), target, new ActionGetURL2(0, false, false), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, new AddActionItem(getSrc(), getLineStartItem(), asGenerator.pushConstTargetItem("print:#"), boundingBox, true), target, new ActionGetURL2(0, false, false, charset), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PrintAsBitmapActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PrintAsBitmapActionItem.java index 96450aa95..1dc4e87f6 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PrintAsBitmapActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PrintAsBitmapActionItem.java @@ -29,6 +29,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -77,7 +78,8 @@ public class PrintAsBitmapActionItem extends ActionItem { private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; - return toSourceMerge(localData, generator, new AddActionItem(getSrc(), getLineStartItem(), asGenerator.pushConstTargetItem("printasbitmap:#"), boundingBox, true), target, new ActionGetURL2(0, false, false), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, new AddActionItem(getSrc(), getLineStartItem(), asGenerator.pushConstTargetItem("printasbitmap:#"), boundingBox, true), target, new ActionGetURL2(0, false, false, charset), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PrintAsBitmapNumActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PrintAsBitmapNumActionItem.java index fafe131dc..463101fe0 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PrintAsBitmapNumActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PrintAsBitmapNumActionItem.java @@ -29,6 +29,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -77,13 +78,14 @@ public class PrintAsBitmapNumActionItem extends ActionItem { private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); Object lev; if ((num instanceof DirectValueActionItem) && (((DirectValueActionItem) num).value instanceof Long)) { lev = asGenerator.pushConstTargetItem("_level" + ((DirectValueActionItem) num).value); } else { lev = new AddActionItem(getSrc(), getLineStartItem(), asGenerator.pushConstTargetItem("_level"), num, true); } - return toSourceMerge(localData, generator, new AddActionItem(getSrc(), getLineStartItem(), asGenerator.pushConstTargetItem("printasbitmap:#"), boundingBox, true), lev, new ActionGetURL2(0, false, false), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + return toSourceMerge(localData, generator, new AddActionItem(getSrc(), getLineStartItem(), asGenerator.pushConstTargetItem("printasbitmap:#"), boundingBox, true), lev, new ActionGetURL2(0, false, false, charset), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PrintNumActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PrintNumActionItem.java index 703fb53e6..7e8b831af 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PrintNumActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/PrintNumActionItem.java @@ -29,6 +29,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -77,13 +78,14 @@ public class PrintNumActionItem extends ActionItem { private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); Object lev; if ((num instanceof DirectValueActionItem) && (((DirectValueActionItem) num).value instanceof Long)) { lev = asGenerator.pushConstTargetItem("_level" + ((DirectValueActionItem) num).value); } else { lev = new AddActionItem(getSrc(), getLineStartItem(), asGenerator.pushConstTargetItem("_level"), num, true); } - return toSourceMerge(localData, generator, new AddActionItem(getSrc(), getLineStartItem(), asGenerator.pushConstTargetItem("print:#"), boundingBox, true), lev, new ActionGetURL2(0, false, false), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + return toSourceMerge(localData, generator, new AddActionItem(getSrc(), getLineStartItem(), asGenerator.pushConstTargetItem("print:#"), boundingBox, true), lev, new ActionGetURL2(0, false, false, charset), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/RemoveSpriteActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/RemoveSpriteActionItem.java index 864f180cf..718a02b6f 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/RemoveSpriteActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/RemoveSpriteActionItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.action.swf4.ActionRemoveSprite; import com.jpexs.decompiler.flash.ecma.Undefined; @@ -27,6 +28,7 @@ import com.jpexs.decompiler.graph.GraphSourceItemPos; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -67,7 +69,9 @@ public class RemoveSpriteActionItem extends ActionItem { } private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { - return toSourceMerge(localData, generator, value, new ActionRemoveSprite(), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, value, new ActionRemoveSprite(), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/ReturnActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/ReturnActionItem.java index 6232294c7..b1d366dad 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/ReturnActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/ReturnActionItem.java @@ -35,6 +35,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.ExitItem; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; import java.util.Objects; @@ -71,20 +72,20 @@ public class ReturnActionItem extends ActionItem implements ExitItem { @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; - List ret = new ArrayList<>(); + String charset = asGenerator.getCharset(); List ret = new ArrayList<>(); int forinlevel = asGenerator.getForInLevel(localData); for (int i = 0; i < forinlevel; i++) { //Must POP all remaining values from enumerations (for..in) List forinret = new ArrayList<>(); - forinret.add(new ActionPush(Null.INSTANCE)); + forinret.add(new ActionPush(Null.INSTANCE, charset)); forinret.add(new ActionEquals2()); forinret.add(new ActionNot()); - ActionIf aforinif = new ActionIf(0); + ActionIf aforinif = new ActionIf(0, charset); forinret.add(aforinif); aforinif.setJumpOffset(-Action.actionsToBytes(forinret, false, SWF.DEFAULT_VERSION).length); ret.addAll(forinret); } if (value == null) { - ret.add(new ActionPush(Undefined.INSTANCE)); + ret.add(new ActionPush(Undefined.INSTANCE, charset)); } else { ret.addAll(value.toSource(localData, generator)); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/SetMemberActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/SetMemberActionItem.java index 2025ebf3d..253bb72f9 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/SetMemberActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/SetMemberActionItem.java @@ -32,6 +32,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -140,9 +141,9 @@ public class SetMemberActionItem extends ActionItem implements SetTypeActionItem @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; - int tmpReg = asGenerator.getTempRegister(localData); + String charset = asGenerator.getCharset(); int tmpReg = asGenerator.getTempRegister(localData); try { - return toSourceMerge(localData, generator, object, objectName, value, new ActionStoreRegister(tmpReg), new ActionSetMember(), new ActionPush(new RegisterNumber(tmpReg))); + return toSourceMerge(localData, generator, object, objectName, value, new ActionStoreRegister(tmpReg, charset), new ActionSetMember(), new ActionPush(new RegisterNumber(tmpReg), charset)); } finally { asGenerator.releaseTempRegister(localData, tmpReg); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/SetPropertyActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/SetPropertyActionItem.java index e419feef6..9f12b714e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/SetPropertyActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/SetPropertyActionItem.java @@ -31,6 +31,7 @@ import com.jpexs.decompiler.graph.GraphSourceItemPos; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -117,9 +118,10 @@ public class SetPropertyActionItem extends ActionItem implements SetTypeActionIt @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); int tmpReg = asGenerator.getTempRegister(localData); try { - return toSourceMerge(localData, generator, target, new ActionPush((Long) (long) propertyIndex), value, new ActionStoreRegister(tmpReg), new ActionSetProperty(), new ActionPush(new RegisterNumber(tmpReg))); + return toSourceMerge(localData, generator, target, new ActionPush((Long) (long) propertyIndex, charset), value, new ActionStoreRegister(tmpReg, charset), new ActionSetProperty(), new ActionPush(new RegisterNumber(tmpReg), charset)); } finally { asGenerator.releaseTempRegister(localData, tmpReg); } @@ -127,7 +129,9 @@ public class SetPropertyActionItem extends ActionItem implements SetTypeActionIt @Override public List toSourceIgnoreReturnValue(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { - return toSourceMerge(localData, generator, target, new ActionPush((Long) (long) propertyIndex), value, new ActionSetProperty()); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, target, new ActionPush((Long) (long) propertyIndex, charset), value, new ActionSetProperty()); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/SetVariableActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/SetVariableActionItem.java index 645c624ba..5dd14f24d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/SetVariableActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/SetVariableActionItem.java @@ -33,6 +33,7 @@ import com.jpexs.decompiler.graph.GraphSourceItemPos; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; import java.util.Set; @@ -156,13 +157,14 @@ public class SetVariableActionItem extends ActionItem implements SetTypeActionIt @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); if (forceUseSet) { - return toSourceMerge(localData, generator, name, value, new ActionSetVariable(), new ActionPush(Undefined.INSTANCE)); + return toSourceMerge(localData, generator, name, value, new ActionSetVariable(), new ActionPush(Undefined.INSTANCE, charset)); } int tmpReg = asGenerator.getTempRegister(localData); try { - return toSourceMerge(localData, generator, name, value, new ActionStoreRegister(tmpReg), new ActionSetVariable(), new ActionPush(new RegisterNumber(tmpReg))); + return toSourceMerge(localData, generator, name, value, new ActionStoreRegister(tmpReg, charset), new ActionSetVariable(), new ActionPush(new RegisterNumber(tmpReg), charset)); } finally { asGenerator.releaseTempRegister(localData, tmpReg); } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StartDragActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StartDragActionItem.java index 6638cfdfd..0be1c2821 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StartDragActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StartDragActionItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.action.swf4.ActionStartDrag; import com.jpexs.decompiler.flash.ecma.Undefined; @@ -29,6 +30,7 @@ import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.FalseItem; import com.jpexs.decompiler.graph.model.LocalData; import com.jpexs.decompiler.graph.model.TrueItem; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -113,6 +115,10 @@ public class StartDragActionItem extends ActionItem { } private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { + + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + boolean hasConstrains = true; if (constrain instanceof DirectValueActionItem) { if (Double.compare(constrain.getResultAsNumber(), 0) == 0) { @@ -120,9 +126,9 @@ public class StartDragActionItem extends ActionItem { } } if (hasConstrains) { - return toSourceMerge(localData, generator, x1, y1, x2, y2, constrain, lockCenter, target, new ActionStartDrag(), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + return toSourceMerge(localData, generator, x1, y1, x2, y2, constrain, lockCenter, target, new ActionStartDrag(), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } else { - return toSourceMerge(localData, generator, constrain, lockCenter, target, new ActionStartDrag(), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + return toSourceMerge(localData, generator, constrain, lockCenter, target, new ActionStartDrag(), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StopActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StopActionItem.java index e8be35683..d358f2200 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StopActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StopActionItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf3.ActionStop; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.ecma.Undefined; @@ -25,6 +26,7 @@ import com.jpexs.decompiler.graph.CompilationException; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; /** @@ -55,7 +57,9 @@ public class StopActionItem extends ActionItem { } private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { - return toSourceMerge(localData, generator, new ActionStop(), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, new ActionStop(), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StopAllSoundsActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StopAllSoundsActionItem.java index 717a77223..270796723 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StopAllSoundsActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StopAllSoundsActionItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf3.ActionStopSounds; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.ecma.Undefined; @@ -25,6 +26,7 @@ import com.jpexs.decompiler.graph.CompilationException; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; /** @@ -55,7 +57,9 @@ public class StopAllSoundsActionItem extends ActionItem { } private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { - return toSourceMerge(localData, generator, new ActionStopSounds(), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, new ActionStopSounds(), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StopDragActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StopDragActionItem.java index 26fa0cf52..a41cded70 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StopDragActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StopDragActionItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf4.ActionEndDrag; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.ecma.Undefined; @@ -25,6 +26,7 @@ import com.jpexs.decompiler.graph.CompilationException; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; /** @@ -55,7 +57,9 @@ public class StopDragActionItem extends ActionItem { } private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { - return toSourceMerge(localData, generator, new ActionEndDrag(), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, new ActionEndDrag(), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StoreRegisterActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StoreRegisterActionItem.java index 3dbbcefc9..65e5fd37d 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StoreRegisterActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/StoreRegisterActionItem.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.IdentifiersDeobfuscation; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf4.RegisterNumber; import com.jpexs.decompiler.flash.action.swf5.ActionStoreRegister; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; @@ -30,6 +31,7 @@ import com.jpexs.decompiler.graph.GraphSourceItemPos; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; import java.util.Set; @@ -125,7 +127,9 @@ public class StoreRegisterActionItem extends ActionItem implements SetTypeAction @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { - return toSourceMerge(localData, generator, value, new ActionStoreRegister(register.number)); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, value, new ActionStoreRegister(register.number, charset)); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/ToggleHighQualityActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/ToggleHighQualityActionItem.java index 79a7cda4a..c58126472 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/ToggleHighQualityActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/ToggleHighQualityActionItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf3.ActionToggleQuality; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.ecma.Undefined; @@ -25,6 +26,7 @@ import com.jpexs.decompiler.graph.CompilationException; import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; /** @@ -60,7 +62,9 @@ public class ToggleHighQualityActionItem extends ActionItem { } private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { - return toSourceMerge(localData, generator, new ActionToggleQuality(), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, new ActionToggleQuality(), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/TraceActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/TraceActionItem.java index c32e14a11..f00171bee 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/TraceActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/TraceActionItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.action.swf4.ActionTrace; import com.jpexs.decompiler.flash.ecma.Undefined; @@ -27,6 +28,7 @@ import com.jpexs.decompiler.graph.GraphSourceItemPos; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -67,7 +69,9 @@ public class TraceActionItem extends ActionItem { } private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { - return toSourceMerge(localData, generator, value, new ActionTrace(), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, value, new ActionTrace(), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/UnLoadMovieActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/UnLoadMovieActionItem.java index 1dfcd5acf..55e43aedb 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/UnLoadMovieActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/UnLoadMovieActionItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf4.ActionGetURL2; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.ecma.Undefined; @@ -27,6 +28,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -68,7 +70,9 @@ public class UnLoadMovieActionItem extends ActionItem { } private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { - return toSourceMerge(localData, generator, new ActionPush(""), targetString, new ActionGetURL2(0, false, true), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, new ActionPush("", charset), targetString, new ActionGetURL2(0, false, true, charset), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/UnLoadMovieNumActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/UnLoadMovieNumActionItem.java index 94daee72c..7ca93fc85 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/UnLoadMovieNumActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/UnLoadMovieNumActionItem.java @@ -30,6 +30,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; @@ -72,10 +73,11 @@ public class UnLoadMovieNumActionItem extends ActionItem { private List toSource(SourceGeneratorLocalData localData, SourceGenerator generator, boolean needsReturn) throws CompilationException { ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); if ((num instanceof DirectValueActionItem) && (((DirectValueActionItem) num).value instanceof Long)) { - return toSourceMerge(localData, generator, new ActionGetURL("", "_level" + ((DirectValueActionItem) num).value), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + return toSourceMerge(localData, generator, new ActionGetURL("", "_level" + ((DirectValueActionItem) num).value, charset), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } else { - return toSourceMerge(localData, generator, new ActionPush(""), new AddActionItem(getSrc(), getLineStartItem(), asGenerator.pushConstTargetItem("_level"), num, true), new ActionGetURL2(0, false, true), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}) : null); + return toSourceMerge(localData, generator, new ActionPush("", charset), new AddActionItem(getSrc(), getLineStartItem(), asGenerator.pushConstTargetItem("_level"), num, true), new ActionGetURL2(0, false, true, charset), needsReturn ? new ActionPush(new Object[]{Undefined.INSTANCE, Undefined.INSTANCE}, charset) : null); } } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/UnresolvedConstantActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/UnresolvedConstantActionItem.java index 22b49b601..f955b68f8 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/UnresolvedConstantActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/UnresolvedConstantActionItem.java @@ -17,6 +17,7 @@ package com.jpexs.decompiler.flash.action.model; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf4.ActionPush; import com.jpexs.decompiler.flash.action.swf4.ConstantIndex; import com.jpexs.decompiler.flash.ecma.Undefined; @@ -27,6 +28,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.SimpleValue; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.List; import java.util.Objects; import java.util.Set; @@ -139,7 +141,9 @@ public class UnresolvedConstantActionItem extends ActionItem implements SimpleVa @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { - return toSourceMerge(localData, generator, new ActionPush(new ConstantIndex(index))); + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); + return toSourceMerge(localData, generator, new ActionPush(new ConstantIndex(index), charset)); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/clauses/ForInActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/clauses/ForInActionItem.java index b9dc85b68..03a921043 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/clauses/ForInActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/clauses/ForInActionItem.java @@ -45,6 +45,7 @@ import com.jpexs.decompiler.graph.Loop; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.ContinueItem; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -159,6 +160,7 @@ public class ForInActionItem extends LoopActionItem implements Block { public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { List ret = new ArrayList<>(); ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); HashMap registerVars = asGenerator.getRegisterVars(localData); ret.addAll(enumVariable.toSource(localData, generator)); ret.add(new ActionEnumerate2()); @@ -166,10 +168,10 @@ public class ForInActionItem extends LoopActionItem implements Block { List loopExpr = new ArrayList<>(); int exprReg = asGenerator.getTempRegister(localData); - loopExpr.add(new ActionStoreRegister(exprReg)); - loopExpr.add(new ActionPush(Null.INSTANCE)); + loopExpr.add(new ActionStoreRegister(exprReg, charset)); + loopExpr.add(new ActionPush(Null.INSTANCE, charset)); loopExpr.add(new ActionEquals2()); - ActionIf forInEndIf = new ActionIf(0); + ActionIf forInEndIf = new ActionIf(0, charset); loopExpr.add(forInEndIf); List loopBody = new ArrayList<>(); @@ -184,7 +186,7 @@ public class ForInActionItem extends LoopActionItem implements Block { asGenerator.setForInLevel(localData, oldForIn + 1); loopBody.addAll(asGenerator.toActionList(asGenerator.generate(localData, commands))); asGenerator.setForInLevel(localData, oldForIn); - ActionJump forinJmpBack = new ActionJump(0); + ActionJump forinJmpBack = new ActionJump(0, charset); loopBody.add(forinJmpBack); int bodyLen = Action.actionsToBytes(loopBody, false, SWF.DEFAULT_VERSION).length; int exprLen = Action.actionsToBytes(loopExpr, false, SWF.DEFAULT_VERSION).length; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/clauses/IfFrameLoadedActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/clauses/IfFrameLoadedActionItem.java index e353af5c3..506d19426 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/clauses/IfFrameLoadedActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/clauses/IfFrameLoadedActionItem.java @@ -18,6 +18,7 @@ package com.jpexs.decompiler.flash.action.model.clauses; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; import com.jpexs.decompiler.flash.action.model.ActionItem; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf4.ActionWaitForFrame2; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.graph.Block; @@ -29,6 +30,7 @@ import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.ContinueItem; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; @@ -94,7 +96,9 @@ public class IfFrameLoadedActionItem extends ActionItem implements Block { @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { List body = generator.generate(localData, actions); - return toSourceMerge(localData, generator, frame, new ActionWaitForFrame2(body.size()), body); + ActionSourceGenerator actionGenerator = (ActionSourceGenerator) generator; + String charset = actionGenerator.getCharset(); + return toSourceMerge(localData, generator, frame, new ActionWaitForFrame2(body.size(), charset), body); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/clauses/TellTargetActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/clauses/TellTargetActionItem.java index 56f081584..89c20316b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/clauses/TellTargetActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/clauses/TellTargetActionItem.java @@ -34,6 +34,7 @@ import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.ContinueItem; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; @@ -82,22 +83,23 @@ public class TellTargetActionItem extends ActionItem implements Block { public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { List ret = new ArrayList<>(); ActionSourceGenerator actionGenerator = (ActionSourceGenerator) generator; + String charset = actionGenerator.getCharset(); if (nested) { - ret.add(new ActionPush("")); - ret.add(new ActionPush(11)); //_target + ret.add(new ActionPush("", charset)); + ret.add(new ActionPush(11, charset)); //_target ret.add(new ActionGetProperty()); } if ((target instanceof DirectValueActionItem) && ((((DirectValueActionItem) target).value instanceof String) || (((DirectValueActionItem) target).value instanceof ConstantIndex))) { - ret.add(new ActionSetTarget((String) target.getResult())); + ret.add(new ActionSetTarget((String) target.getResult(), charset)); } else { ret.addAll(target.toSource(localData, generator)); - ret.add(new ActionSetTarget2()); + ret.add(new ActionSetTarget2(charset)); } ret.addAll(generator.generate(localData, commands)); - ret.add(new ActionSetTarget("")); + ret.add(new ActionSetTarget("", charset)); if (nested) { - ret.add(new ActionSetTarget2()); + ret.add(new ActionSetTarget2(charset)); } return ret; } diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/clauses/TryActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/clauses/TryActionItem.java index 513cc7b90..bf14bae80 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/clauses/TryActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/clauses/TryActionItem.java @@ -44,6 +44,7 @@ import com.jpexs.decompiler.graph.GraphTargetVisitorInterface; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.ContinueItem; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; import java.util.logging.Level; @@ -178,6 +179,7 @@ public class TryActionItem extends ActionItem implements Block { public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { List ret = new ArrayList<>(); ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); List tryCommandsA = asGenerator.toActionList(asGenerator.generate(localData, tryCommands)); List finallyCommandsA = finallyCommands == null ? null : asGenerator.toActionList(asGenerator.generate(localData, finallyCommands)); List catchCommandsA = null; @@ -212,7 +214,7 @@ public class TryActionItem extends ActionItem implements Block { if (!allCatched) { fullCatchBody.addAll(0, GraphTargetItem.toSourceMerge(localData, generator, - new ActionPush(new RegisterNumber(catchRegister)), + new ActionPush(new RegisterNumber(catchRegister), charset), new ActionThrow() )); } @@ -225,19 +227,19 @@ public class TryActionItem extends ActionItem implements Block { fullCatchBody.addAll(0, GraphTargetItem.toSourceMerge(localData, generator, new DirectValueActionItem(new RegisterNumber(catchRegister)), ename, - new ActionStackSwap(), + new ActionStackSwap(charset), new ActionDefineLocal(), ebody )); } else { List ifBody = GraphTargetItem.toSourceMerge(localData, generator, ename, - new ActionStackSwap(), + new ActionStackSwap(charset), new ActionDefineLocal(), ebody); fullCatchBody.add(0, new ActionPop()); int toFinishSize = Action.actionsToBytes(asGenerator.toActionList(fullCatchBody), false, SWF.DEFAULT_VERSION).length; - ActionJump finishJump = new ActionJump(toFinishSize); + ActionJump finishJump = new ActionJump(toFinishSize, charset); ifBody.add(finishJump); List ifBodyA = asGenerator.toActionList(ifBody); int ifBodySize = Action.actionsToBytes(ifBodyA, false, SWF.DEFAULT_VERSION).length; @@ -245,12 +247,12 @@ public class TryActionItem extends ActionItem implements Block { fullCatchBody.addAll(0, GraphTargetItem.toSourceMerge(localData, generator, etype, - new ActionPush(new RegisterNumber(catchRegister)), + new ActionPush(new RegisterNumber(catchRegister), charset), new ActionCastOp(), - new ActionPushDuplicate(), - new ActionPush(Null.INSTANCE), + new ActionPushDuplicate(charset), + new ActionPush(Null.INSTANCE, charset), new ActionEquals2(), - new ActionIf(ifBodySize) + new ActionIf(ifBodySize, charset) )); } @@ -259,14 +261,14 @@ public class TryActionItem extends ActionItem implements Block { } catchCommandsA = asGenerator.toActionList(fullCatchBody); catchSize = Action.actionsToBytes(catchCommandsA, false, SWF.DEFAULT_VERSION).length; - tryCommandsA.add(new ActionJump(catchSize)); + tryCommandsA.add(new ActionJump(catchSize, charset)); } int finallySize = 0; if (finallyCommandsA != null) { finallySize = Action.actionsToBytes(finallyCommandsA, false, SWF.DEFAULT_VERSION).length; } int trySize = Action.actionsToBytes(tryCommandsA, false, SWF.DEFAULT_VERSION).length; - ret.add(new ActionTry(catchInRegisterFlag, finallyCommands != null, !catchCommands.isEmpty(), catchName, catchRegister, trySize, catchSize, finallySize, SWF.DEFAULT_VERSION)); + ret.add(new ActionTry(catchInRegisterFlag, finallyCommands != null, !catchCommands.isEmpty(), catchName, catchRegister, trySize, catchSize, finallySize, SWF.DEFAULT_VERSION, charset)); ret.addAll(tryCommandsA); if (catchCommandsA != null) { ret.addAll(catchCommandsA); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/clauses/WithActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/clauses/WithActionItem.java index 63074877f..5f49c25d2 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/clauses/WithActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/clauses/WithActionItem.java @@ -20,6 +20,7 @@ import com.jpexs.decompiler.flash.SWF; import com.jpexs.decompiler.flash.SourceGeneratorLocalData; import com.jpexs.decompiler.flash.action.Action; import com.jpexs.decompiler.flash.action.model.ActionItem; +import com.jpexs.decompiler.flash.action.parser.script.ActionSourceGenerator; import com.jpexs.decompiler.flash.action.swf5.ActionWith; import com.jpexs.decompiler.flash.helpers.GraphTextWriter; import com.jpexs.decompiler.graph.CompilationException; @@ -27,6 +28,7 @@ import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.LocalData; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; @@ -68,6 +70,8 @@ public class WithActionItem extends ActionItem { @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { + ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); List data = generator.generate(localData, items); List dataA = new ArrayList<>(); for (GraphSourceItem s : data) { @@ -76,7 +80,7 @@ public class WithActionItem extends ActionItem { } } int codeLen = Action.actionsToBytes(dataA, false, SWF.DEFAULT_VERSION).length; - return toSourceMerge(localData, generator, scope, new ActionWith(codeLen), data); + return toSourceMerge(localData, generator, scope, new ActionWith(codeLen, charset), data); } @Override diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/operations/PreDecrementActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/operations/PreDecrementActionItem.java index 182c2f045..44cbf52bc 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/operations/PreDecrementActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/operations/PreDecrementActionItem.java @@ -35,6 +35,7 @@ import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.UnaryOpItem; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; @@ -56,6 +57,7 @@ public class PreDecrementActionItem extends UnaryOpItem { @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); List ret = new ArrayList<>(); GraphTargetItem val = value; if (val instanceof VariableActionItem) { @@ -68,9 +70,9 @@ public class PreDecrementActionItem extends UnaryOpItem { ret.addAll(gv.toSource(localData, generator)); ret.add(new ActionDecrement()); int tmpReg = asGenerator.getTempRegister(localData); - ret.add(new ActionStoreRegister(tmpReg)); + ret.add(new ActionStoreRegister(tmpReg, charset)); ret.add(new ActionSetVariable()); - ret.add(new ActionPush(new RegisterNumber(tmpReg))); + ret.add(new ActionPush(new RegisterNumber(tmpReg), charset)); asGenerator.releaseTempRegister(localData, tmpReg); } else if (val instanceof GetMemberActionItem) { GetMemberActionItem mem = (GetMemberActionItem) val; @@ -79,15 +81,15 @@ public class PreDecrementActionItem extends UnaryOpItem { ret.addAll(mem.toSource(localData, generator)); ret.add(new ActionDecrement()); int tmpReg = asGenerator.getTempRegister(localData); - ret.add(new ActionStoreRegister(tmpReg)); + ret.add(new ActionStoreRegister(tmpReg, charset)); ret.add(new ActionSetMember()); - ret.add(new ActionPush(new RegisterNumber(tmpReg))); + ret.add(new ActionPush(new RegisterNumber(tmpReg), charset)); asGenerator.releaseTempRegister(localData, tmpReg); } else if ((val instanceof DirectValueActionItem) && ((DirectValueActionItem) val).value instanceof RegisterNumber) { RegisterNumber rn = (RegisterNumber) ((DirectValueActionItem) val).value; - ret.add(new ActionPush(new RegisterNumber(rn.number))); + ret.add(new ActionPush(new RegisterNumber(rn.number), charset)); ret.add(new ActionDecrement()); - ret.add(new ActionStoreRegister(rn.number)); + ret.add(new ActionStoreRegister(rn.number, charset)); } else if (val instanceof GetPropertyActionItem) { GetPropertyActionItem gp = (GetPropertyActionItem) val; ret.addAll(gp.toSource(localData, generator)); // old value diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/operations/PreIncrementActionItem.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/operations/PreIncrementActionItem.java index 6feca591d..b8b3d9918 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/operations/PreIncrementActionItem.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/model/operations/PreIncrementActionItem.java @@ -35,6 +35,7 @@ import com.jpexs.decompiler.graph.GraphSourceItem; import com.jpexs.decompiler.graph.GraphTargetItem; import com.jpexs.decompiler.graph.SourceGenerator; import com.jpexs.decompiler.graph.model.UnaryOpItem; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; @@ -56,6 +57,7 @@ public class PreIncrementActionItem extends UnaryOpItem { @Override public List toSource(SourceGeneratorLocalData localData, SourceGenerator generator) throws CompilationException { ActionSourceGenerator asGenerator = (ActionSourceGenerator) generator; + String charset = asGenerator.getCharset(); List ret = new ArrayList<>(); GraphTargetItem val = value; if (val instanceof VariableActionItem) { @@ -69,9 +71,9 @@ public class PreIncrementActionItem extends UnaryOpItem { ret.add(new ActionIncrement()); int tmpReg = asGenerator.getTempRegister(localData); - ret.add(new ActionStoreRegister(tmpReg)); + ret.add(new ActionStoreRegister(tmpReg, charset)); ret.add(new ActionSetVariable()); - ret.add(new ActionPush(new RegisterNumber(tmpReg))); + ret.add(new ActionPush(new RegisterNumber(tmpReg), charset)); asGenerator.releaseTempRegister(localData, tmpReg); } else if (val instanceof GetMemberActionItem) { GetMemberActionItem mem = (GetMemberActionItem) val; @@ -80,15 +82,15 @@ public class PreIncrementActionItem extends UnaryOpItem { ret.addAll(mem.toSource(localData, generator)); ret.add(new ActionIncrement()); int tmpReg = asGenerator.getTempRegister(localData); - ret.add(new ActionStoreRegister(tmpReg)); + ret.add(new ActionStoreRegister(tmpReg, charset)); ret.add(new ActionSetMember()); - ret.add(new ActionPush(new RegisterNumber(tmpReg))); + ret.add(new ActionPush(new RegisterNumber(tmpReg), charset)); asGenerator.releaseTempRegister(localData, tmpReg); } else if ((val instanceof DirectValueActionItem) && ((DirectValueActionItem) val).value instanceof RegisterNumber) { RegisterNumber rn = (RegisterNumber) ((DirectValueActionItem) val).value; - ret.add(new ActionPush(new RegisterNumber(rn.number))); + ret.add(new ActionPush(new RegisterNumber(rn.number), charset)); ret.add(new ActionIncrement()); - ret.add(new ActionStoreRegister(rn.number)); + ret.add(new ActionStoreRegister(rn.number, charset)); } else if (val instanceof GetPropertyActionItem) { GetPropertyActionItem gp = (GetPropertyActionItem) val; ret.addAll(gp.toSource(localData, generator)); // old value diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/pcode/ASMParser.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/pcode/ASMParser.java index 5f6ffcdc6..e52052da7 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/pcode/ASMParser.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/action/parser/pcode/ASMParser.java @@ -129,6 +129,7 @@ import com.jpexs.decompiler.graph.GraphSourceItemContainer; import com.jpexs.helpers.Helper; import java.io.IOException; import java.io.StringReader; +import java.nio.charset.Charset; import java.util.ArrayList; import java.util.HashMap; import java.util.List; @@ -145,11 +146,11 @@ public class ASMParser { private static final Logger logger = Logger.getLogger(ASMParser.class.getName()); - public static ActionList parse(boolean ignoreNops, List