Added Setting charset in commandline (-charset XXX)

Default charset for SWF files version <= 5 is system charset
This commit is contained in:
Jindra Petřík
2022-11-11 09:58:13 +01:00
parent 3c3a8545a5
commit e3ed5bd4a5
6 changed files with 176 additions and 132 deletions

View File

@@ -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;

View File

@@ -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);

View File

@@ -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);