Added Saving Harman encrypted SWFs

Added Editing encrypted flag on header panel
Added `-encrypt` command on CLI for Harman encryption
This commit is contained in:
Jindra Petřík
2023-12-30 18:06:08 +01:00
parent c4cfad716b
commit 8ad981ff25
10 changed files with 614 additions and 177 deletions
@@ -485,9 +485,14 @@ public class CommandLineArgumentParser {
out.println(" ...Decompress <infile> and save it to <outfile>");
}
if (filter == null || filter.equals("encrypt")) {
out.println(" " + (cnt++) + ") -encrypt <infile> <outfile>");
out.println(" ...Encrypts file <infile> with HARMAN Air encryption and saves it to <outfile>");
}
if (filter == null || filter.equals("decrypt")) {
out.println(" " + (cnt++) + ") -decrypt <infile> <outfile>");
out.println(" ...Decrypts HARMAN Air encrypted file <infile> and save it to <outfile>");
out.println(" ...Decrypts HARMAN Air encrypted file <infile> and saves it to <outfile>");
}
if (filter == null || filter.equals("swf2xml")) {
@@ -1057,6 +1062,9 @@ public class CommandLineArgumentParser {
} else if (command.equals("decompress")) {
parseDecompress(args);
System.exit(0);
} else if (command.equals("encrypt")) {
parseDecrypt(args);
System.exit(0);
} else if (command.equals("decrypt")) {
parseDecrypt(args);
System.exit(0);
@@ -2764,6 +2772,27 @@ public class CommandLineArgumentParser {
System.exit(result ? 0 : 1);
}
private static void parseEncrypt(Stack<String> args) {
if (args.size() < 2) {
badArguments("encrypt");
}
boolean result = false;
try {
try (InputStream fis = new BufferedInputStream(new StdInAwareFileInputStream(args.pop())); OutputStream fos = new BufferedOutputStream(new FileOutputStream(args.pop()))) {
result = SWF.encrypt(fis, fos);
System.out.println(result ? "OK" : "FAIL");
} catch (FileNotFoundException ex) {
System.err.println("File not found.");
System.exit(1);
}
} catch (IOException ex) {
logger.log(Level.SEVERE, null, ex);
}
System.exit(result ? 0 : 1);
}
private static void parseDecrypt(Stack<String> args) {
if (args.size() < 2) {
badArguments("decrypt");
@@ -4535,6 +4564,7 @@ public class CommandLineArgumentParser {
pw.println("fileSize=" + swf.fileSize);
pw.println("version=" + swf.version);
pw.println("compression=" + swf.compression);
pw.println("encrypted=" + swf.encrypted);
pw.println("gfx=" + swf.gfx);
pw.println("width=" + doubleToString(swf.displayRect.getWidth() / SWF.unitDivisor));
pw.println("height=" + doubleToString(swf.displayRect.getHeight() / SWF.unitDivisor));
@@ -4564,9 +4594,11 @@ public class CommandLineArgumentParser {
pw.println("actionScript3=" + fa.actionScript3);
pw.println("hasMetadata=" + fa.hasMetadata);
pw.println("noCrossDomainCache=" + fa.noCrossDomainCache);
pw.println("swfRelativeUrls=" + fa.swfRelativeUrls);
pw.println("useDirectBlit=" + fa.useDirectBlit);
pw.println("useGPU=" + fa.useGPU);
pw.println("useNetwork=" + fa.useNetwork);
pw.println();
}
@@ -4886,6 +4918,7 @@ public class CommandLineArgumentParser {
pw.println("fileSize=" + swf.fileSize);
pw.println("version=" + swf.version);
pw.println("compression=" + swf.compression);
pw.println("encrypted=" + swf.encrypted);
pw.println("gfx=" + swf.gfx);
pw.println("displayRect=[" + swf.displayRect.Xmin + ", " + swf.displayRect.Ymin + ", " + swf.displayRect.Xmax + ", " + swf.displayRect.Ymax + "]");
pw.println("width=" + swf.displayRect.getWidth());
@@ -57,6 +57,8 @@ public class HeaderInfoPanel extends JPanel implements TagEditorPanel {
private final JLabel gfxLabel = new JLabel();
private final JLabel encryptedLabel = new JLabel();
private final JLabel versionLabel = new JLabel();
private final JLabel fileSizeLabel = new JLabel();
@@ -82,6 +84,8 @@ public class HeaderInfoPanel extends JPanel implements TagEditorPanel {
private final JSpinner versionEditor = new JSpinner();
private final JCheckBox gfxCheckBox = new JCheckBox();
private final JCheckBox encryptedCheckBox = new JCheckBox();
private final JPanel frameRateEditorPanel = new JPanel();
@@ -132,7 +136,7 @@ public class HeaderInfoPanel extends JPanel implements TagEditorPanel {
{TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED,
TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED,
TableLayout.PREFERRED, TableLayout.PREFERRED, TableLayout.PREFERRED,
TableLayout.PREFERRED}
TableLayout.PREFERRED, TableLayout.PREFERRED}
}));
FlowLayout layout = new FlowLayout(SwingConstants.WEST);
@@ -155,7 +159,11 @@ public class HeaderInfoPanel extends JPanel implements TagEditorPanel {
});
versionEditorPanel.add(versionEditor);
gfxCheckBox.addActionListener((ActionEvent e) -> {
encryptedCheckBox.addChangeListener((ChangeEvent e) -> {
validateHeader();
});
gfxCheckBox.addChangeListener((ChangeEvent e) -> {
validateHeader();
});
@@ -237,23 +245,26 @@ public class HeaderInfoPanel extends JPanel implements TagEditorPanel {
propertiesPanel.add(new JLabel(AppStrings.translate("header.version")), "0,2");
propertiesPanel.add(versionLabel, "1,2");
propertiesPanel.add(versionEditorPanel, "1,2");
propertiesPanel.add(new JLabel(AppStrings.translate("header.gfx")), "0,3");
propertiesPanel.add(gfxLabel, "1,3");
propertiesPanel.add(gfxCheckBox, "1,3");
propertiesPanel.add(new JLabel(AppStrings.translate("header.filesize")), "0,4");
propertiesPanel.add(fileSizeLabel, "1,4");
propertiesPanel.add(new JLabel(AppStrings.translate("header.framerate")), "0,5");
propertiesPanel.add(frameRateLabel, "1,5");
propertiesPanel.add(frameRateEditorPanel, "1,5");
propertiesPanel.add(new JLabel(AppStrings.translate("header.framecount")), "0,6");
propertiesPanel.add(frameCountLabel, "1,6");
propertiesPanel.add(frameCountEditorPanel, "1,6");
propertiesPanel.add(new JLabel(AppStrings.translate("header.displayrect")), "0,7");
propertiesPanel.add(displayRectTwipsLabel, "1,7");
propertiesPanel.add(displayRectEditorPanel, "1,7");
propertiesPanel.add(new JLabel(""), "0,8");
propertiesPanel.add(displayRectPixelsLabel, "1,8");
propertiesPanel.add(warningPanel, "0,9,1,9");
propertiesPanel.add(new JLabel(AppStrings.translate("header.encrypted")), "0,3");
propertiesPanel.add(encryptedLabel, "1,3");
propertiesPanel.add(encryptedCheckBox, "1,3");
propertiesPanel.add(new JLabel(AppStrings.translate("header.gfx")), "0,4");
propertiesPanel.add(gfxLabel, "1,4");
propertiesPanel.add(gfxCheckBox, "1,4");
propertiesPanel.add(new JLabel(AppStrings.translate("header.filesize")), "0,5");
propertiesPanel.add(fileSizeLabel, "1,5");
propertiesPanel.add(new JLabel(AppStrings.translate("header.framerate")), "0,6");
propertiesPanel.add(frameRateLabel, "1,6");
propertiesPanel.add(frameRateEditorPanel, "1,6");
propertiesPanel.add(new JLabel(AppStrings.translate("header.framecount")), "0,7");
propertiesPanel.add(frameCountLabel, "1,7");
propertiesPanel.add(frameCountEditorPanel, "1,7");
propertiesPanel.add(new JLabel(AppStrings.translate("header.displayrect")), "0,8");
propertiesPanel.add(displayRectTwipsLabel, "1,8");
propertiesPanel.add(displayRectEditorPanel, "1,8");
propertiesPanel.add(new JLabel(""), "0,9");
propertiesPanel.add(displayRectPixelsLabel, "1,9");
propertiesPanel.add(warningPanel, "0,10,1,10");
add(propertiesPanel, BorderLayout.CENTER);
@@ -305,6 +316,7 @@ public class HeaderInfoPanel extends JPanel implements TagEditorPanel {
swf.compression = getCompression();
swf.version = getVersionNumber();
swf.gfx = gfxCheckBox.isSelected();
swf.encrypted = encryptedCheckBox.isSelected() && !gfxCheckBox.isSelected();
swf.frameRate = ((Number) (frameRateEditor.getModel().getValue())).floatValue();
swf.frameCount = ((Number) (frameCountEditor.getModel().getValue())).intValue();
double multiplier = 1.0;
@@ -350,9 +362,12 @@ public class HeaderInfoPanel extends JPanel implements TagEditorPanel {
versionLabel.setText(Integer.toString(swf.version));
versionEditor.setModel(new SpinnerNumberModel(swf.version, 1, SWF.MAX_VERSION, 1));
encryptedLabel.setText(swf.encrypted ? AppStrings.translate("yes") : AppStrings.translate("no"));
encryptedCheckBox.setSelected(swf.encrypted);
gfxLabel.setText(swf.gfx ? AppStrings.translate("yes") : AppStrings.translate("no"));
gfxCheckBox.setSelected(swf.gfx);
fileSizeLabel.setText(Long.toString(swf.fileSize));
frameRateLabel.setText(Float.toString(swf.frameRate));
@@ -391,6 +406,9 @@ public class HeaderInfoPanel extends JPanel implements TagEditorPanel {
versionEditor.addChangeListener((ChangeEvent e) -> {
setModified();
});
encryptedCheckBox.addChangeListener((ChangeEvent e) -> {
setModified();
});
gfxCheckBox.addChangeListener((ChangeEvent e) -> {
setModified();
});
@@ -441,6 +459,8 @@ public class HeaderInfoPanel extends JPanel implements TagEditorPanel {
compressionEditorPanel.setVisible(edit);
versionLabel.setVisible(!edit);
versionEditorPanel.setVisible(edit);
encryptedLabel.setVisible(!edit);
encryptedCheckBox.setVisible(edit);
gfxLabel.setVisible(!edit);
gfxCheckBox.setVisible(edit);
frameRateLabel.setVisible(!edit);
@@ -470,6 +490,7 @@ public class HeaderInfoPanel extends JPanel implements TagEditorPanel {
private boolean validateHeader() {
int version = getVersionNumber();
boolean gfx = gfxCheckBox.isSelected();
boolean encrypted = encryptedCheckBox.isSelected();
SWFCompression compression = getCompression();
String resultStr = "";
boolean result = true;
@@ -477,6 +498,11 @@ public class HeaderInfoPanel extends JPanel implements TagEditorPanel {
resultStr += AppStrings.translate("header.warning.unsupportedGfxCompression") + " ";
result = false;
}
if (gfx && encrypted) {
resultStr += AppStrings.translate("header.warning.unsupportedGfxEncryption") + " ";
result = false;
}
if (compression == SWFCompression.ZLIB && version < 6) {
resultStr += AppStrings.translate("header.warning.minimumZlibVersion") + " ";
+5 -5
View File
@@ -1320,7 +1320,7 @@ public class Main {
result.sourceInfo = sourceInfo;
boolean hasVideoStreams = false;
boolean hasEncrypted = false;
//boolean hasEncrypted = false;
for (Openable openable : result) {
openable.setOpenableList(result);
@@ -1342,9 +1342,9 @@ public class Main {
}
}
if (swf.encrypted) {
/*if (swf.encrypted) {
hasEncrypted = true;
}
}*/
swf.addEventListener(new EventListener() {
@Override
@@ -1402,7 +1402,7 @@ public class Main {
});
}
if (hasEncrypted) {
/*if (hasEncrypted) {
View.execInEventDispatchLater(new Runnable() {
@Override
public void run() {
@@ -1410,7 +1410,7 @@ public class Main {
}
});
}
}*/
return result;
}
@@ -1236,4 +1236,7 @@ debug.export.bytearray = Export byte array data...
debug.import = Import to %name%
debug.import.bytearray = Import byte array data...
action.edit.flex = (Flex compiler)
action.edit.flex = (Flex compiler)
header.encrypted = Harman encrypted:
header.warning.unsupportedGfxEncryption = GFX does not support Harman encryption.
@@ -1213,4 +1213,7 @@ debug.export.bytearray = Exportovat byte array data...
debug.import = Importovat do %name%
debug.import.bytearray = Importovat byte array data...
action.edit.flex = (kompil\u00e1tor Flex)
action.edit.flex = (kompil\u00e1tor Flex)
header.encrypted = Harman \u0161ifrov\u00e1n\u00ed:
header.warning.unsupportedGfxEncryption = GFX nepodporuje Harman \u0161ifrov\u00e1n\u00ed.