diff --git a/CHANGELOG.md b/CHANGELOG.md index ed7cc0933..01ae0a31a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ All notable changes to this project will be documented in this file. - Show in tag list from tag scripts - Move/Copy tag to action on tag scripts - [#1879] False tag order error with SoundStreamHead +- Error messages during SWF/ABC reading have correct error icon and title, are translatable ### Changed - GFX - DefineExternalImage2 no longer handled as character 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 6864071a4..4a763355e 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/SWF.java @@ -1711,7 +1711,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { public static SWFHeader decodeHeader(byte[] headerData) throws IOException { String signature = new String(headerData, 0, 3, Utf8Helper.charset); if (!swfSignatures.contains(signature)) { - throw new SwfOpenException("Invalid SWF file, wrong signature."); + throw new SwfOpenException(AppResources.translate("error.swf.invalid")); } int version = headerData[3]; @@ -1733,7 +1733,7 @@ public final class SWF implements SWFContainerItem, Timelined, Openable { // SWFheader: signature, version and fileSize if (is.read(hdr) != 8) { - throw new SwfOpenException("SWF header is too short"); + throw new SwfOpenException(AppResources.translate("error.swf.headerTooShort")); } SWFHeader header = decodeHeader(hdr); diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java index a96e4a5bf..921b8c7f5 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABC.java @@ -16,6 +16,7 @@ */ package com.jpexs.decompiler.flash.abc; +import com.jpexs.decompiler.flash.AppResources; import com.jpexs.decompiler.flash.DeobfuscationListener; import com.jpexs.decompiler.flash.EndOfStreamException; import com.jpexs.decompiler.flash.EventListener; @@ -513,6 +514,20 @@ public class ABC implements Openable { if (file != null) { isOpenable = true; } + + try { + read(ais, swf); + } catch (IOException ie) { + throw new ABCOpenException(AppResources.translate("error.abc.invalid"), ie); + } + //this will read all method body codes. TODO: make this ondemand + refreshMultinameNamespaceSuffixes(); + getMethodIndexing(); + + SWFDecompilerPlugin.fireAbcParsed(this, swf); + } + + private void read(ABCInputStream ais, SWF swf) throws IOException { int minor_version = ais.readU16("minor_version"); int major_version = ais.readU16("major_version"); version = new ABCVersion(major_version, minor_version); @@ -735,12 +750,6 @@ public class ABC implements Openable { SWFDecompilerPlugin.fireMethodBodyParsed(this, mb, swf); } - - //this will read all method body codes. TODO: make this ondemand - refreshMultinameNamespaceSuffixes(); - getMethodIndexing(); - - SWFDecompilerPlugin.fireAbcParsed(this, swf); } public void saveToStream(OutputStream os) throws IOException { diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABCOpenException.java b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABCOpenException.java new file mode 100644 index 000000000..66ccb398f --- /dev/null +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/abc/ABCOpenException.java @@ -0,0 +1,18 @@ +package com.jpexs.decompiler.flash.abc; + +import java.io.IOException; + +/** + * + * @author JPEXS + */ +public class ABCOpenException extends IOException { + + public ABCOpenException(String message) { + super(message); + } + + public ABCOpenException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/locales/AppResources.properties b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/locales/AppResources.properties index 2c6f3867c..f2f397dac 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/locales/AppResources.properties +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/locales/AppResources.properties @@ -42,4 +42,8 @@ trait.instanceinitializer = instance initializer trait.classinitializer = class initializer #after 16.3.1 -package.default = \ No newline at end of file +package.default = + +error.swf.invalid = Invalid SWF file, wrong signature. +error.swf.headerTooShort = SWF header is too short. +error.abc.invalid = Invalid ABC file. \ No newline at end of file diff --git a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/locales/AppResources_cs.properties b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/locales/AppResources_cs.properties index 38ed6d047..3496f6a73 100644 --- a/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/locales/AppResources_cs.properties +++ b/libsrc/ffdec_lib/src/com/jpexs/decompiler/flash/locales/AppResources_cs.properties @@ -40,4 +40,8 @@ trait.instanceinitializer = inicializ\u00e1tor instance trait.classinitializer = inicializ\u00e1tor t\u0159\u00eddy #after 16.3.1 -package.default = \ No newline at end of file +package.default = + +error.swf.invalid = Neplatn\u00fd SWF soubor, \u0161patn\u00e1 signatura. +error.swf.headerTooShort = SWF hlavi\u010dka je p\u0159\u00edli\u0161 kr\u00e1tk\u00e1. +error.abc.invalid = Neplatn\u00fd ABC soubor. \ No newline at end of file diff --git a/src/com/jpexs/decompiler/flash/gui/Main.java b/src/com/jpexs/decompiler/flash/gui/Main.java index bb636b288..bfe03a76f 100644 --- a/src/com/jpexs/decompiler/flash/gui/Main.java +++ b/src/com/jpexs/decompiler/flash/gui/Main.java @@ -25,6 +25,7 @@ import com.jpexs.debugger.flash.DebuggerCommands; import com.jpexs.debugger.flash.Variable; import com.jpexs.debugger.flash.VariableType; import com.jpexs.debugger.flash.messages.in.InCallFunction; +import com.jpexs.decompiler.flash.AppResources; import com.jpexs.decompiler.flash.ApplicationInfo; import com.jpexs.decompiler.flash.EventListener; import com.jpexs.decompiler.flash.SWF; @@ -133,9 +134,11 @@ import javax.swing.UnsupportedLookAndFeelException; import javax.swing.filechooser.FileFilter; import org.pushingpixels.substance.api.SubstanceLookAndFeel; import com.jpexs.decompiler.flash.Bundle; +import com.jpexs.decompiler.flash.EndOfStreamException; import com.jpexs.decompiler.flash.OpenableSourceKind; import com.jpexs.decompiler.flash.abc.ABC; import com.jpexs.decompiler.flash.abc.ABCInputStream; +import com.jpexs.decompiler.flash.abc.ABCOpenException; import com.jpexs.decompiler.flash.tags.DoABC2Tag; import com.jpexs.decompiler.flash.treeitems.Openable; import com.jpexs.helpers.MemoryInputStream; @@ -1355,6 +1358,9 @@ public class Main { if (cause instanceof SwfOpenException) { throw (SwfOpenException) cause; } + if (cause instanceof ABCOpenException) { + throw (ABCOpenException) cause; + } throw ex; } @@ -1362,13 +1368,13 @@ public class Main { logger.log(Level.SEVERE, null, ex); handleOutOfMemory("Cannot load SWF file."); continue; - } catch (SwfOpenException ex) { + } catch (ABCOpenException | SwfOpenException ex) { logger.log(Level.SEVERE, null, ex); - ViewMessages.showMessageDialog(getDefaultMessagesComponent(), ex.getMessage()); + ViewMessages.showMessageDialog(getDefaultMessagesComponent(), ex.getMessage(), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE); continue; } catch (Exception ex) { logger.log(Level.SEVERE, null, ex); - ViewMessages.showMessageDialog(getDefaultMessagesComponent(), "Cannot load SWF file: " + ex.getLocalizedMessage()); + ViewMessages.showMessageDialog(getDefaultMessagesComponent(), "Cannot load SWF file: " + ex.getLocalizedMessage(), AppStrings.translate("error"), JOptionPane.ERROR_MESSAGE); continue; }