diff --git a/CHANGELOG.md b/CHANGELOG.md index 7ce6ef519..43d5883e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +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 +- [#1701] Setting charset for SWF files with version 5 or lower (GUI, commandline) - [#1864] Commandline: Allow to set special value "/dev/stdin" for input files to read from stdin (even on Windows) ### Fixed 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 31658beea..b3ac75fb2 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -936,11 +936,13 @@ public final class SWF implements SWFContainerItem, Timelined { * @throws IOException */ public void saveTo(OutputStream os) throws IOException { + checkCharset(); byte[] uncompressedData = saveToByteArray(); compress(new ByteArrayInputStream(uncompressedData), os, compression, lzmaProperties); } public void saveTo(OutputStream os, boolean gfx) throws IOException { + checkCharset(); byte[] uncompressedData = saveToByteArray(gfx); compress(new ByteArrayInputStream(uncompressedData), os, compression, lzmaProperties); } @@ -980,6 +982,12 @@ public final class SWF implements SWFContainerItem, Timelined { private byte[] saveToByteArray() throws IOException { return saveToByteArray(gfx); } + + private void checkCharset() { + if (version > 5) { + charset = Utf8Helper.charsetName; + } + } private byte[] saveToByteArray(boolean gfx) throws IOException { byte[] data; diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfXmlExporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfXmlExporter.java index 845b71245..f34c0358b 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfXmlExporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/exporters/swf/SwfXmlExporter.java @@ -210,6 +210,9 @@ public class SwfXmlExporter { if (obj instanceof UnknownTag) { writer.writeAttribute("tagId", String.valueOf(((Tag) obj).getId())); + } + if (obj instanceof SWF) { + writer.writeAttribute("charset", ((SWF) obj).getCharset()); } for (Field f : fields) { @@ -222,6 +225,7 @@ public class SwfXmlExporter { logger.log(Level.SEVERE, null, ex); } } + writer.writeEndElement(); } else if (isListItem) { writer.writeStartElement(name); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SwfXmlImporter.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SwfXmlImporter.java index 4a80d3ad8..e7e9e9dbe 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SwfXmlImporter.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/importers/SwfXmlImporter.java @@ -311,6 +311,10 @@ public class SwfXmlImporter { if (name.equals("tagId") && "UnknownTag".equals(attributes.get("type"))) { continue; } + if (name.equals("charset") && "SWF".equals(attributes.get("type"))) { + ((SWF) obj).setCharset(val); + continue; + } if (!name.equals("type")) { try { Field field = getField(cls, name); diff --git a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java index ccca2b193..cc2c4c1ab 100644 --- a/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java +++ b/src/com/jpexs/decompiler/flash/console/CommandLineArgumentParser.java @@ -191,6 +191,7 @@ import java.io.PrintWriter; import java.io.StringReader; import java.io.UnsupportedEncodingException; import java.lang.reflect.Field; +import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; @@ -317,7 +318,7 @@ public class CommandLineArgumentParser { out.println(" " + (cnt++) + ") [ ...]"); out.println(" ...opens SWF file(s) with the decompiler GUI"); } - + if (filter == null || filter.equals("proxy")) { out.println(" " + (cnt++) + ") -proxy [-P]"); out.println(" ...auto start proxy in the tray. Optional parameter -P specifies port for proxy. Defaults to 55555. "); @@ -659,15 +660,21 @@ public class CommandLineArgumentParser { out.println(" ...: Where to save merged file"); out.println(" ...: Input SWF file"); } - + if (filter == null || filter.equals("swf2exe")) { out.println(" " + (cnt++) + ") -swf2exe "); out.println(" ...export SWF to executable file"); out.println(" ...: wrapper|projector_win||projector_mac|projector_linux"); - } + } + + if (filter == null || filter.equals("charset")) { + out.println(" " + (cnt++) + ") -charset "); + out.println(" ...sets desired character set for reading/writing SWF files with SWF version <= 5"); + out.println(" (use in combination with other commands)"); + } printCmdLineUsageExamples(out, filter); - + System.out.println("You can use special value \"/dev/stdin\" for input files to read data from standard input (even on Windows)"); } @@ -758,17 +765,17 @@ public class CommandLineArgumentParser { out.println(PREFIX + "-removeInstanceMetadata -instance myobj myfile.swf"); exampleFound = true; } - + if (filter == null || filter.equals("swf2exe")) { out.println(PREFIX + "-swf2exe wrapper result.exe myfile.swf"); } - + if (!exampleFound) { out.println("Sorry, no example found for command " + filter + ", Let us know in issue tracker when you need it."); } out.println(); - out.println("Instead of \"java -jar ffdec.jar\" you can use ffdec.bat on Windows, ffdec.sh on Linux/MacOs"); + out.println("Instead of \"java -jar ffdec.jar\" you can use ffdec.bat on Windows, ffdec.sh on Linux/MacOs"); } /** @@ -791,6 +798,7 @@ public class CommandLineArgumentParser { AbortRetryIgnoreHandler handler = null; Map format = new HashMap<>(); double zoom = 1; + String charset = Charset.defaultCharset().name(); boolean cliMode = false; Selection selection = new Selection(); Selection selectionIds = new Selection(); @@ -824,6 +832,9 @@ public class CommandLineArgumentParser { case "-format": format = parseFormat(args); break; + case "-charset": + charset = parseCharset(args); + break; case "-config": parseConfig(args); if (args.isEmpty()) { @@ -848,7 +859,7 @@ public class CommandLineArgumentParser { parseStat(args); break; case "-info": - parseInfo(args); + parseInfo(args, charset); break; case "-stdout": parseStdOut(args); @@ -888,19 +899,19 @@ public class CommandLineArgumentParser { } if (command.equals("swf2exe")) { - parseSwf2Exe(args); + parseSwf2Exe(args, charset); } else if (command.equals("abcmerge")) { - parseAbcMerge(args); + parseAbcMerge(args, charset); } else if (command.equals("swf2swc")) { - parseSwf2Swc(args); + parseSwf2Swc(args, charset); } else if (command.equals("linkreport")) { - parseLinkReport(selectionClasses, args); + parseLinkReport(selectionClasses, args, charset); } else if (command.equals("getinstancemetadata")) { - parseGetInstanceMetadata(args); + parseGetInstanceMetadata(args, charset); } else if (command.equals("setinstancemetadata")) { - parseSetInstanceMetadata(args); + parseSetInstanceMetadata(args, charset); } else if (command.equals("removeinstancemetadata")) { - parseRemoveInstanceMetadata(args); + parseRemoveInstanceMetadata(args, charset); } else if (command.equals("removefromcontextmenu")) { if (!args.isEmpty()) { badArguments(command); @@ -916,57 +927,57 @@ public class CommandLineArgumentParser { } else if (command.equals("proxy")) { parseProxy(args); } else if (command.equals("export")) { - parseExport(selectionClasses, selection, selectionIds, args, handler, traceLevel, format, zoom); + parseExport(selectionClasses, selection, selectionIds, args, handler, traceLevel, format, zoom, charset); } else if (command.equals("compress")) { parseCompress(args); } else if (command.equals("decompress")) { parseDecompress(args); } else if (command.equals("swf2xml")) { - parseSwf2Xml(args); + parseSwf2Xml(args, charset); } else if (command.equals("xml2swf")) { - parseXml2Swf(args); + parseXml2Swf(args, charset); } else if (command.equals("extract")) { parseExtract(args); } else if (command.equals("memorysearch")) { parseMemorySearch(args); } else if (command.equals("deobfuscate")) { - parseDeobfuscate(args); + parseDeobfuscate(args, charset); } else if (command.equals("renameinvalididentifiers")) { parseRenameInvalidIdentifiers(args); } else if (command.equals("dumpswf")) { parseDumpSwf(args); } else if (command.equals("dumpas2")) { - parseDumpAS2(args); + parseDumpAS2(args, charset); } else if (command.equals("dumpas3")) { - parseDumpAS3(args); + parseDumpAS3(args, charset); } else if (command.equals("enabledebugging")) { - parseEnableDebugging(args); + parseEnableDebugging(args, charset); } else if (command.equals("flashpaper2pdf")) { - parseFlashPaperToPdf(selection, zoom, args); + parseFlashPaperToPdf(selection, zoom, args, charset); } else if (command.equals("replace")) { - parseReplace(args); + parseReplace(args, charset); } else if (command.equals("replacealpha")) { - parseReplaceAlpha(args); + parseReplaceAlpha(args, charset); } else if (command.equals("replacecharacter")) { - parseReplaceCharacter(args); + parseReplaceCharacter(args, charset); } else if (command.equals("replacecharacterid")) { - parseReplaceCharacterId(args); + parseReplaceCharacterId(args, charset); } else if (command.equals("convert")) { - parseConvert(args); + parseConvert(args, charset); } else if (command.equals("remove")) { - parseRemove(args); + parseRemove(args, charset); } else if (command.equals("removecharacter")) { - parseRemoveCharacter(args, false); + parseRemoveCharacter(args, false, charset); } else if (command.equals("removecharacterwithdependencies")) { - parseRemoveCharacter(args, true); + parseRemoveCharacter(args, true, charset); } else if (command.equals("doc")) { parseDoc(args); } else if (command.equals("importscript")) { - parseImportScript(args); + parseImportScript(args, charset); } else if (command.equals("as3compiler")) { ActionScript3Parser.compile(null /*?*/, args.pop(), args.pop(), 0, 0); } else if (nextParam.equals("--debugtool")) { - parseDebugTool(args); + parseDebugTool(args, charset); } else if (nextParam.equals("--compareresources")) { parseCompareResources(args); } else if (nextParam.equals("--resourcedates")) { @@ -1127,20 +1138,20 @@ public class CommandLineArgumentParser { setConfigurations(args.pop()); } - private static void parseSwf2Exe(Stack args) { + private static void parseSwf2Exe(Stack args, String charset) { if (args.size() != 3) { - badArguments("swf2exe"); + badArguments("swf2exe"); } final String type = args.pop(); final File outFile = new File(args.pop()); final File swfFile = new File(args.pop()); ExeExportMode exportMode = enumFromStr(type, ExeExportMode.class); - processReadSWF(swfFile, null, (SWF swf, OutputStream stdout) -> { - Main.saveFileToExe(swf, exportMode, outFile); - }); + processReadSWF(swfFile, null, (SWF swf, OutputStream stdout) -> { + Main.saveFileToExe(swf, exportMode, outFile); + }, charset); } - - private static void parseAbcMerge(Stack args) { + + private static void parseAbcMerge(Stack args, String charset) { if (args.size() < 2) { badArguments("abcmerge"); } @@ -1157,11 +1168,11 @@ public class CommandLineArgumentParser { swf.removeTag((Tag) abcList.get(i)); } } - }); + }, charset); } - private static void parseSwf2Swc(Stack args) { + private static void parseSwf2Swc(Stack args, String charset) { if (args.size() < 2) { badArguments("swf2swc"); } @@ -1174,10 +1185,10 @@ public class CommandLineArgumentParser { } catch (IOException | InterruptedException ex) { Logger.getLogger(CommandLineArgumentParser.class.getName()).log(Level.SEVERE, null, ex); } - }); + }, charset); } - private static void parseLinkReport(List selectionClasses, Stack args) { + private static void parseLinkReport(List selectionClasses, Stack args, String charset) { if (args.isEmpty()) { badArguments("linkreport"); } @@ -1222,10 +1233,10 @@ public class CommandLineArgumentParser { } catch (InterruptedException ex) { System.err.println("Report generation interrupted"); } - }); + }, charset); } - private static void parseGetInstanceMetadata(Stack args) { + private static void parseGetInstanceMetadata(Stack args, String charset) { if (args.size() < 3) { badArguments("getinstancemetadata"); } @@ -1364,11 +1375,11 @@ public class CommandLineArgumentParser { } return false; } - }); + }, charset); System.exit(0); } - private static void parseSetInstanceMetadata(Stack args) { + private static void parseSetInstanceMetadata(Stack args, String charset) { if (args.size() < 3) { badArguments("setinstancemetadata"); } @@ -1574,11 +1585,11 @@ public class CommandLineArgumentParser { } return false; } - }); + }, charset); System.exit(0); } - private static void parseRemoveInstanceMetadata(Stack args) { + private static void parseRemoveInstanceMetadata(Stack args, String charset) { if (args.size() < 2) { badArguments("removeinstancemetadata"); } @@ -1703,7 +1714,7 @@ public class CommandLineArgumentParser { } return false; } - }); + }, charset); System.exit(0); } @@ -1962,7 +1973,7 @@ public class CommandLineArgumentParser { } } - private static void parseDebugTool(Stack args) { + private static void parseDebugTool(Stack args, String charset) { String cmd = args.pop().toLowerCase(Locale.ENGLISH); switch (cmd) { case "findtag": { @@ -1990,7 +2001,7 @@ public class CommandLineArgumentParser { for (File file : files) { SWFSourceInfo sourceInfo = new SWFSourceInfo(null, file.getAbsolutePath(), file.getName()); try { - SWF swf = new SWF(new FileInputStream(file), sourceInfo.getFile(), sourceInfo.getFileTitle(), Configuration.parallelSpeedUp.get()); + SWF swf = new SWF(new FileInputStream(file), sourceInfo.getFile(), sourceInfo.getFileTitle(), Configuration.parallelSpeedUp.get(), charset); swf.swfList = new SWFList(); swf.swfList.sourceInfo = sourceInfo; boolean found = false; @@ -2032,7 +2043,7 @@ public class CommandLineArgumentParser { for (File file : files) { SWFSourceInfo sourceInfo = new SWFSourceInfo(null, file.getAbsolutePath(), file.getName()); try { - SWF swf = new SWF(new FileInputStream(file), sourceInfo.getFile(), sourceInfo.getFileTitle(), Configuration.parallelSpeedUp.get()); + SWF swf = new SWF(new FileInputStream(file), sourceInfo.getFile(), sourceInfo.getFileTitle(), Configuration.parallelSpeedUp.get(), charset); swf.swfList = new SWFList(); swf.swfList.sourceInfo = sourceInfo; boolean found = false; @@ -2119,7 +2130,7 @@ public class CommandLineArgumentParser { } - private static void parseExport(List selectionClasses, Selection selection, Selection selectionIds, Stack args, AbortRetryIgnoreHandler handler, Level traceLevel, Map formats, double zoom) { + private static void parseExport(List selectionClasses, Selection selection, Selection selectionIds, Stack args, AbortRetryIgnoreHandler handler, Level traceLevel, Map formats, double zoom, String charset) { if (args.size() < 3) { badArguments("export"); } @@ -2213,7 +2224,7 @@ public class CommandLineArgumentParser { SWFSourceInfo sourceInfo = new SWFSourceInfo(null, inFile.getAbsolutePath(), inFile.getName()); SWF swf; try { - swf = new SWF(new StdInAwareFileInputStream(inFile), sourceInfo.getFile(), sourceInfo.getFileTitle(), Configuration.parallelSpeedUp.get()); + swf = new SWF(new StdInAwareFileInputStream(inFile), sourceInfo.getFile(), sourceInfo.getFileTitle(), Configuration.parallelSpeedUp.get(), charset); } catch (FileNotFoundException | SwfOpenException ex) { // FileNotFoundException when anti virus software blocks to open the file logger.log(Level.SEVERE, "Failed to open swf: " + inFile.getName(), ex); @@ -2387,7 +2398,7 @@ public class CommandLineArgumentParser { String scriptsFolder = Path.combine(outDir, ScriptExportSettings.EXPORT_FOLDER_NAME); Path.createDirectorySafe(new File(scriptsFolder)); String singleFileName = Path.combine(scriptsFolder, swf.getShortFileName() + scriptExportSettings.getFileExtension()); - try (FileTextWriter writer = scriptExportSettings.singleFile ? new FileTextWriter(Configuration.getCodeFormatting(), new FileOutputStream(singleFileName)) : null) { + try ( FileTextWriter writer = scriptExportSettings.singleFile ? new FileTextWriter(Configuration.getCodeFormatting(), new FileOutputStream(singleFileName)) : null) { scriptExportSettings.singleFileWriter = writer; List as3packs = as3classes.isEmpty() ? null : swf.getScriptPacksByClassNames(as3classes); exportOK = swf.exportActionScript(handler, scriptsFolder, as3classes.isEmpty() ? null : as3packs, scriptExportSettings, parallel, evl, exportAs2Script, exportAs3Script) != null && exportOK; @@ -2472,7 +2483,7 @@ public class CommandLineArgumentParser { } } - private static void parseDeobfuscate(Stack args) { + private static void parseDeobfuscate(Stack args, String charset) { if (args.size() < 3) { badArguments("deobfuscate"); } @@ -2509,9 +2520,8 @@ public class CommandLineArgumentParser { System.exit(1); } } - try (StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile); - FileOutputStream fos = new FileOutputStream(outFile)) { - SWF swf = new SWF(is, Configuration.parallelSpeedUp.get()); + try ( StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile); FileOutputStream fos = new FileOutputStream(outFile)) { + SWF swf = new SWF(is, Configuration.parallelSpeedUp.get(), charset); if (!swf.isAS3()) { System.out.println("Warning: The file is not AS3. Only AS3 deobfuscation from commandline is available."); System.exit(0); @@ -2565,8 +2575,7 @@ public class CommandLineArgumentParser { } } - try (InputStream fis = new BufferedInputStream(new StdInAwareFileInputStream(args.pop())); - OutputStream fos = new BufferedOutputStream(new FileOutputStream(args.pop()))) { + try ( InputStream fis = new BufferedInputStream(new StdInAwareFileInputStream(args.pop())); OutputStream fos = new BufferedOutputStream(new FileOutputStream(args.pop()))) { result = SWF.compress(fis, fos, compression); System.out.println(result ? "OK" : "FAIL"); } catch (FileNotFoundException ex) { @@ -2587,8 +2596,7 @@ public class CommandLineArgumentParser { boolean result = false; try { - try (InputStream fis = new BufferedInputStream(new StdInAwareFileInputStream(args.pop())); - OutputStream fos = new BufferedOutputStream(new FileOutputStream(args.pop()))) { + try ( InputStream fis = new BufferedInputStream(new StdInAwareFileInputStream(args.pop())); OutputStream fos = new BufferedOutputStream(new FileOutputStream(args.pop()))) { result = SWF.decompress(fis, fos); System.out.println(result ? "OK" : "FAIL"); } catch (FileNotFoundException ex) { @@ -2602,14 +2610,14 @@ public class CommandLineArgumentParser { System.exit(result ? 0 : 1); } - private static void parseSwf2Xml(Stack args) { + private static void parseSwf2Xml(Stack args, String charset) { if (args.size() < 2) { badArguments("swf2xml"); } try { - try (StdInAwareFileInputStream is = new StdInAwareFileInputStream(args.pop())) { - SWF swf = new SWF(is, Configuration.parallelSpeedUp.get()); + try ( StdInAwareFileInputStream is = new StdInAwareFileInputStream(args.pop())) { + SWF swf = new SWF(is, Configuration.parallelSpeedUp.get(), charset); new SwfXmlExporter().exportXml(swf, new File(args.pop())); } catch (FileNotFoundException ex) { System.err.println("File not found."); @@ -2624,17 +2632,17 @@ public class CommandLineArgumentParser { System.exit(0); } - private static void parseXml2Swf(Stack args) { + private static void parseXml2Swf(Stack args, String charset) { if (args.size() < 2) { badArguments("xml2swf"); } try { - SWF swf = new SWF(); - try (StdInAwareFileInputStream in = new StdInAwareFileInputStream(args.pop())) { + SWF swf = new SWF(charset); + try ( StdInAwareFileInputStream in = new StdInAwareFileInputStream(args.pop())) { new SwfXmlImporter().importSwf(swf, in); } - try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(new File(args.pop())))) { + try ( OutputStream fos = new BufferedOutputStream(new FileOutputStream(new File(args.pop())))) { swf.saveTo(fos); } } catch (IOException ex) { @@ -2717,7 +2725,7 @@ public class CommandLineArgumentParser { } } - try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(fileNameOut))) { + try ( OutputStream fos = new BufferedOutputStream(new FileOutputStream(fileNameOut))) { byte[] swfData = new byte[stream.available()]; int cnt = stream.read(swfData); fos.write(swfData, 0, cnt); @@ -2838,8 +2846,7 @@ public class CommandLineArgumentParser { boolean result = false; try { - try (InputStream fis = new BufferedInputStream(new StdInAwareFileInputStream(args.pop())); - OutputStream fos = new BufferedOutputStream(new FileOutputStream(args.pop()))) { + try ( InputStream fis = new BufferedInputStream(new StdInAwareFileInputStream(args.pop())); OutputStream fos = new BufferedOutputStream(new FileOutputStream(args.pop()))) { result = SWF.renameInvalidIdentifiers(renameType, fis, fos); System.out.println(result ? "OK" : "FAIL"); } catch (FileNotFoundException ex) { @@ -2853,6 +2860,27 @@ public class CommandLineArgumentParser { System.exit(result ? 0 : 1); } + private static String parseCharset(Stack args) { + if (args.size() < 1) { + badArguments("charset"); + } + String charsetName = args.pop(); + boolean charsetValid = false; + try { + if (Charset.isSupported(charsetName)) { + charsetValid = true; + } + } catch (Exception ex) { + charsetValid = false; + } + + if (!charsetValid) { + System.err.println("Specified charset is not valid"); + badArguments("charset"); + } + return charsetName; + } + private static Map parseFormat(Stack args) { if (args.size() < 1) { badArguments("format"); @@ -2875,7 +2903,7 @@ public class CommandLineArgumentParser { return ret; } - private static void parseFlashPaperToPdf(Selection selection, double zoom, Stack args) { + private static void parseFlashPaperToPdf(Selection selection, double zoom, Stack args, String charset) { if (args.size() < 2) { badArguments("flashpaper2pdf"); } @@ -2883,11 +2911,11 @@ public class CommandLineArgumentParser { File outFile = new File(args.pop()); printHeader(); - try (StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile)) { + try ( StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile)) { PDFJob job = null; - SWF swf = new SWF(is, Configuration.parallelSpeedUp.get()); + SWF swf = new SWF(is, Configuration.parallelSpeedUp.get(), charset); int totalPages = 0; for (Tag t : swf.getTags()) { @@ -2951,7 +2979,7 @@ public class CommandLineArgumentParser { System.exit(0); } - private static void parseReplace(Stack args) { + private static void parseReplace(Stack args, String charset) { if (args.size() < 3) { badArguments("replace"); } @@ -2980,8 +3008,8 @@ public class CommandLineArgumentParser { } try { - try (StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile)) { - SWF swf = new SWF(is, Configuration.parallelSpeedUp.get()); + try ( StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile)) { + SWF swf = new SWF(is, Configuration.parallelSpeedUp.get(), charset); while (true) { String objectToReplace = args.pop(); @@ -3118,7 +3146,7 @@ public class CommandLineArgumentParser { } try { - try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(outFile))) { + try ( OutputStream fos = new BufferedOutputStream(new FileOutputStream(outFile))) { swf.saveTo(fos); } } catch (IOException e) { @@ -3145,7 +3173,7 @@ public class CommandLineArgumentParser { return res; } - private static void parseReplaceAlpha(Stack args) { + private static void parseReplaceAlpha(Stack args, String charset) { if (args.size() < 4) { badArguments("replacealpha"); } @@ -3153,8 +3181,8 @@ public class CommandLineArgumentParser { File inFile = new File(args.pop()); File outFile = new File(args.pop()); try { - try (StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile)) { - SWF swf = new SWF(is, Configuration.parallelSpeedUp.get()); + try ( StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile)) { + SWF swf = new SWF(is, Configuration.parallelSpeedUp.get(), charset); while (true) { String objectToReplace = args.pop(); @@ -3187,7 +3215,7 @@ public class CommandLineArgumentParser { } try { - try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(outFile))) { + try ( OutputStream fos = new BufferedOutputStream(new FileOutputStream(outFile))) { swf.saveTo(fos); } } catch (IOException e) { @@ -3201,7 +3229,7 @@ public class CommandLineArgumentParser { } } - private static void parseReplaceCharacter(Stack args) { + private static void parseReplaceCharacter(Stack args, String charset) { if (args.size() < 4) { badArguments("replacecharacter"); } @@ -3209,8 +3237,8 @@ public class CommandLineArgumentParser { File inFile = new File(args.pop()); File outFile = new File(args.pop()); try { - try (StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile)) { - SWF swf = new SWF(is, Configuration.parallelSpeedUp.get()); + try ( StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile)) { + SWF swf = new SWF(is, Configuration.parallelSpeedUp.get(), charset); while (true) { String objectToReplace = args.pop(); @@ -3249,7 +3277,7 @@ public class CommandLineArgumentParser { } try { - try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(outFile))) { + try ( OutputStream fos = new BufferedOutputStream(new FileOutputStream(outFile))) { swf.saveTo(fos); } } catch (IOException e) { @@ -3263,7 +3291,7 @@ public class CommandLineArgumentParser { } } - private static void parseReplaceCharacterId(Stack args) { + private static void parseReplaceCharacterId(Stack args, String charset) { if (args.size() < 3) { badArguments("replacecharacterid"); } @@ -3271,8 +3299,8 @@ public class CommandLineArgumentParser { File inFile = new File(args.pop()); File outFile = new File(args.pop()); try { - try (StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile)) { - SWF swf = new SWF(is, Configuration.parallelSpeedUp.get()); + try ( StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile)) { + SWF swf = new SWF(is, Configuration.parallelSpeedUp.get(), charset); String arg = args.pop().toLowerCase(Locale.ENGLISH); if (arg.equals("pack")) { swf.packCharacterIds(); @@ -3305,7 +3333,7 @@ public class CommandLineArgumentParser { } try { - try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(outFile))) { + try ( OutputStream fos = new BufferedOutputStream(new FileOutputStream(outFile))) { swf.saveTo(fos); } } catch (IOException e) { @@ -3319,7 +3347,7 @@ public class CommandLineArgumentParser { } } - private static void parseConvert(Stack args) { + private static void parseConvert(Stack args, String charset) { if (args.size() < 4) { badArguments("convert"); } @@ -3327,8 +3355,8 @@ public class CommandLineArgumentParser { File inFile = new File(args.pop()); File outFile = new File(args.pop()); try { - try (StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile)) { - SWF swf = new SWF(is, Configuration.parallelSpeedUp.get()); + try ( StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile)) { + SWF swf = new SWF(is, Configuration.parallelSpeedUp.get(), charset); String objectToConvert = args.pop(); @@ -3372,7 +3400,7 @@ public class CommandLineArgumentParser { } try { - try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(outFile))) { + try ( OutputStream fos = new BufferedOutputStream(new FileOutputStream(outFile))) { swf.saveTo(fos); } } catch (IOException e) { @@ -3386,7 +3414,7 @@ public class CommandLineArgumentParser { } } - private static void parseRemove(Stack args) { + private static void parseRemove(Stack args, String charset) { if (args.size() < 3) { badArguments("remove"); } @@ -3394,8 +3422,8 @@ public class CommandLineArgumentParser { File inFile = new File(args.pop()); File outFile = new File(args.pop()); try { - try (StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile)) { - SWF swf = new SWF(is, Configuration.parallelSpeedUp.get()); + try ( StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile)) { + SWF swf = new SWF(is, Configuration.parallelSpeedUp.get(), charset); List tagNumbersToRemove = new ArrayList<>(); while (true) { String tagNoToRemoveStr = args.pop(); @@ -3428,7 +3456,7 @@ public class CommandLineArgumentParser { } try { - try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(outFile))) { + try ( OutputStream fos = new BufferedOutputStream(new FileOutputStream(outFile))) { swf.saveTo(fos); } } catch (IOException e) { @@ -3517,7 +3545,7 @@ public class CommandLineArgumentParser { outStream.print(doc); } - private static void parseRemoveCharacter(Stack args, boolean removeDependencies) { + private static void parseRemoveCharacter(Stack args, boolean removeDependencies, String charset) { if (args.size() < 3) { badArguments("removecharacter"); } @@ -3525,8 +3553,8 @@ public class CommandLineArgumentParser { File inFile = new File(args.pop()); File outFile = new File(args.pop()); try { - try (StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile)) { - SWF swf = new SWF(is, Configuration.parallelSpeedUp.get()); + try ( StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile)) { + SWF swf = new SWF(is, Configuration.parallelSpeedUp.get(), charset); while (true) { String objectToRemove = args.pop(); @@ -3551,7 +3579,7 @@ public class CommandLineArgumentParser { } try { - try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(outFile))) { + try ( OutputStream fos = new BufferedOutputStream(new FileOutputStream(outFile))) { swf.saveTo(fos); } } catch (IOException e) { @@ -3565,7 +3593,7 @@ public class CommandLineArgumentParser { } } - private static void parseImportScript(Stack args) { + private static void parseImportScript(Stack args, String charset) { String flexLocation = Configuration.flexSdkLocation.get(); if (Configuration.useFlexAs3Compiler.get() && (flexLocation.isEmpty() || (!new File(flexLocation).exists()))) { @@ -3580,14 +3608,14 @@ public class CommandLineArgumentParser { File inFile = new File(args.pop()); File outFile = new File(args.pop()); try { - try (StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile)) { - SWF swf = new SWF(is, Configuration.parallelSpeedUp.get()); + try ( StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile)) { + SWF swf = new SWF(is, Configuration.parallelSpeedUp.get(), charset); String scriptsFolder = Path.combine(args.pop(), ScriptExportSettings.EXPORT_FOLDER_NAME); new AS2ScriptImporter().importScripts(scriptsFolder, swf.getASMs(true)); new AS3ScriptImporter().importScripts(As3ScriptReplacerFactory.createByConfig(), scriptsFolder, swf.getAS3Packs()); try { - try (OutputStream fos = new BufferedOutputStream(new FileOutputStream(outFile))) { + try ( OutputStream fos = new BufferedOutputStream(new FileOutputStream(outFile))) { swf.saveTo(fos); } } catch (IOException e) { @@ -3754,7 +3782,7 @@ public class CommandLineArgumentParser { } } - private static void parseInfo(Stack args) throws FileNotFoundException { + private static void parseInfo(Stack args, String charset) throws FileNotFoundException { File out; PrintWriter pw = new PrintWriter(System.out); boolean found = false; @@ -3801,7 +3829,7 @@ public class CommandLineArgumentParser { public void progress(int p) { //... } - }, Configuration.parallelSpeedUp.get()); + }, Configuration.parallelSpeedUp.get(), charset); return swf; } }; @@ -3834,7 +3862,7 @@ public class CommandLineArgumentParser { public void progress(int p) { //startWork(AppStrings.translate("work.reading.swf"), p, worker); } - }, Configuration.parallelSpeedUp.get()); + }, Configuration.parallelSpeedUp.get(), charset); return swf; } }; @@ -3948,14 +3976,14 @@ public class CommandLineArgumentParser { System.exit(0); } - private static void parseDumpAS2(Stack args) { + private static void parseDumpAS2(Stack args, String charset) { if (args.isEmpty()) { badArguments("dumpas2"); } File file = new File(args.pop()); try { - try (StdInAwareFileInputStream is = new StdInAwareFileInputStream(file)) { - SWF swf = new SWF(is, Configuration.parallelSpeedUp.get()); + try ( StdInAwareFileInputStream is = new StdInAwareFileInputStream(file)) { + SWF swf = new SWF(is, Configuration.parallelSpeedUp.get(), charset); Map asms = swf.getASMs(false); for (String as2 : asms.keySet()) { System.out.println(as2); @@ -3967,7 +3995,7 @@ public class CommandLineArgumentParser { } } - private static void parseEnableDebugging(Stack args) { + private static void parseEnableDebugging(Stack args, String charset) { if (args.size() < 2) { badArguments("enabledebugging"); } @@ -4001,7 +4029,7 @@ public class CommandLineArgumentParser { try { System.out.print("Working..."); StdInAwareFileInputStream fis = new StdInAwareFileInputStream(file); - SWF swf = new SWF(fis, Configuration.parallelSpeedUp.get()); + SWF swf = new SWF(fis, Configuration.parallelSpeedUp.get(), charset); fis.close(); if (swf.isAS3()) { swf.enableDebugging(injectas3, new File(outfile).getParentFile(), doPCode); @@ -4014,7 +4042,7 @@ public class CommandLineArgumentParser { if (!swf.isAS3()) { if (generateSwd) { fis = new StdInAwareFileInputStream(outfile); - swf = new SWF(fis, Configuration.parallelSpeedUp.get()); + swf = new SWF(fis, Configuration.parallelSpeedUp.get(), charset); fis.close(); String outSwd = outfile; if (outSwd.toLowerCase(Locale.ENGLISH).endsWith(".swf")) { @@ -4049,14 +4077,14 @@ public class CommandLineArgumentParser { System.exit(0); } - private static void parseDumpAS3(Stack args) { + private static void parseDumpAS3(Stack args, String charset) { if (args.isEmpty()) { badArguments("dumpas3"); } File file = new File(args.pop()); try { - try (StdInAwareFileInputStream is = new StdInAwareFileInputStream(file)) { - SWF swf = new SWF(is, Configuration.parallelSpeedUp.get()); + try ( StdInAwareFileInputStream is = new StdInAwareFileInputStream(file)) { + SWF swf = new SWF(is, Configuration.parallelSpeedUp.get(), charset); List packs = swf.getAS3Packs(); for (ScriptPack entry : packs) { System.out.println(entry.getClassPath().toString() + " " + entry.scriptIndex); @@ -4090,7 +4118,7 @@ public class CommandLineArgumentParser { public void swfAction(SWF swf, OutputStream stdout) throws IOException; } - private static void processReadSWF(File inFile, File stdOutFile, SwfAction action) { + private static void processReadSWF(File inFile, File stdOutFile, SwfAction action, String charset) { OutputStream stdout = null; try { @@ -4105,8 +4133,8 @@ public class CommandLineArgumentParser { stdout = System.out; } - try (StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile)) { - SWF swf = new SWF(is, Configuration.parallelSpeedUp.get()); + try ( StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile)) { + SWF swf = new SWF(is, Configuration.parallelSpeedUp.get(), charset); action.swfAction(swf, stdout); } catch (FileNotFoundException ex) { System.err.println("File not found: " + ex.getMessage()); @@ -4131,7 +4159,7 @@ public class CommandLineArgumentParser { } } - private static void processModifySWF(File inFile, File outFile, File stdOutFile, SwfAction action) { + private static void processModifySWF(File inFile, File outFile, File stdOutFile, SwfAction action, String charset) { OutputStream stdout = null; @@ -4157,9 +4185,8 @@ public class CommandLineArgumentParser { System.exit(1); } } - try (StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile); - FileOutputStream fos = new FileOutputStream(outFile)) { - SWF swf = new SWF(is, Configuration.parallelSpeedUp.get()); + try ( StdInAwareFileInputStream is = new StdInAwareFileInputStream(inFile); FileOutputStream fos = new FileOutputStream(outFile)) { + SWF swf = new SWF(is, Configuration.parallelSpeedUp.get(), charset); action.swfAction(swf, stdout); swf.saveTo(fos); } catch (FileNotFoundException ex) { diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index 9cd3fff45..7480c5695 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -874,7 +874,8 @@ public class Main { final CancellableWorker worker = this; String fileKey = new File(streamEntry.getKey()).getName(); SwfSpecificCustomConfiguration conf = Configuration.getSwfSpecificCustomConfiguration(fileKey); - String charset = conf == null ? Utf8Helper.charsetName : conf.getCustomData(SwfSpecificCustomConfiguration.KEY_CHARSET, Utf8Helper.charsetName); + + String charset = conf == null ? Charset.defaultCharset().name() : conf.getCustomData(SwfSpecificCustomConfiguration.KEY_CHARSET, Charset.defaultCharset().name()); SWF swf = new SWF(stream, null, streamEntry.getKey(), new ProgressListener() { @Override public void progress(int p) { @@ -908,7 +909,7 @@ public class Main { String shortName = fileTitle != null ? fileTitle : file; String fileKey = shortName == null ? "" : new File(shortName).getName(); SwfSpecificCustomConfiguration conf = Configuration.getSwfSpecificCustomConfiguration(fileKey); - String charset = conf == null ? Utf8Helper.charsetName : conf.getCustomData(SwfSpecificCustomConfiguration.KEY_CHARSET, Utf8Helper.charsetName); + String charset = conf == null ? Charset.defaultCharset().name() : conf.getCustomData(SwfSpecificCustomConfiguration.KEY_CHARSET, Charset.defaultCharset().name()); SWF swf = new SWF(is, file, fileTitle, new ProgressListener() { @Override