From 11ee052e33bfb6862e55db18aae42e1c7cfd01ca Mon Sep 17 00:00:00 2001 From: Honfika Date: Mon, 23 Dec 2013 16:16:00 +0100 Subject: [PATCH] Issue (Feature) #365 Search in memory: Filter fake SWFs: implemented --- trunk/src/com/jpexs/decompiler/flash/SWF.java | 10 ++ .../decompiler/flash/SWFInputStream.java | 10 +- .../com/jpexs/decompiler/flash/tags/Tag.java | 148 ++++++++++++++++++ .../decompiler/flash/tags/UnknownTag.java | 30 ++++ 4 files changed, 195 insertions(+), 3 deletions(-) create mode 100644 trunk/src/com/jpexs/decompiler/flash/tags/UnknownTag.java diff --git a/trunk/src/com/jpexs/decompiler/flash/SWF.java b/trunk/src/com/jpexs/decompiler/flash/SWF.java index 192225a1c..1d2a1f4a6 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWF.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWF.java @@ -406,6 +406,16 @@ public final class SWF { assignExportNamesToSymbols(); assignClassesToSymbols(); findFileAttributes(); + } else { + boolean hasNonUnknownTag = false; + for (Tag tag : tags) { + if(tag.getData(version).length > 0 && Tag.getRequiredTags().contains(tag.getId())) { + hasNonUnknownTag = true; + } + } + if (!hasNonUnknownTag) { + throw new IOException("Invalid SWF file. No known tag found."); + } } } diff --git a/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java b/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java index ba4eb640c..ec3bffa3a 100644 --- a/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java +++ b/trunk/src/com/jpexs/decompiler/flash/SWFInputStream.java @@ -1001,7 +1001,7 @@ public class SWFInputStream extends InputStream { ret = new DefineExternalImage2(swf, data, version, pos); break; default: - ret = new Tag(swf, tag.getId(), "Unknown", data, pos); + ret = new UnknownTag(swf, tag.getId(), data, pos); } } catch (IOException ex) { Logger.getLogger(SWFInputStream.class.getName()).log(Level.SEVERE, "Error during tag reading", ex); @@ -1038,7 +1038,7 @@ public class SWFInputStream extends InputStream { readLong = true; } byte[] data = readBytes((int) tagLength); - Tag ret = new Tag(swf, tagID, "Unknown", data, pos); + Tag ret = new Tag(swf, tagID, "Unresolved", data, pos); ret.forceWriteAsLong = readLong; byte[] dataNew = ret.getData(version); @@ -1074,7 +1074,11 @@ public class SWFInputStream extends InputStream { } } if (resolve) { - return resolveTag(swf, ret, version, level, parallel, skipUnusualTags); + try { + return resolveTag(swf, ret, version, level, parallel, skipUnusualTags); + } catch (EndOfStreamException ex) { + return ret; + } } return ret; } diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/Tag.java b/trunk/src/com/jpexs/decompiler/flash/tags/Tag.java index f3ac95464..be2677c0e 100644 --- a/trunk/src/com/jpexs/decompiler/flash/tags/Tag.java +++ b/trunk/src/com/jpexs/decompiler/flash/tags/Tag.java @@ -21,6 +21,8 @@ import com.jpexs.decompiler.flash.tags.base.CharacterTag; import com.jpexs.decompiler.flash.tags.base.ContainerItem; import com.jpexs.decompiler.flash.tags.base.Exportable; import com.jpexs.decompiler.flash.tags.base.NeedsCharacters; +import com.jpexs.decompiler.flash.tags.gfx.*; +import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.List; @@ -88,6 +90,152 @@ public class Tag implements NeedsCharacters, Exportable, ContainerItem { this.swf = swf; } + private static Object lockObject = new Object(); + private static List knownTagIds; + private static List requiredTagIds; + + public static List getKnownTags() { + if (knownTagIds == null) { + synchronized(lockObject) { + if (knownTagIds == null) { + List tagIds = Arrays.asList( + CSMTextSettingsTag.ID, + DebugIDTag.ID, + DefineBinaryDataTag.ID, + DefineBitsJPEG2Tag.ID, + DefineBitsJPEG3Tag.ID, + DefineBitsJPEG4Tag.ID, + DefineBitsLossless2Tag.ID, + DefineBitsLosslessTag.ID, + DefineBitsTag.ID, + DefineButton2Tag.ID, + DefineButtonCxformTag.ID, + DefineButtonSoundTag.ID, + DefineButtonTag.ID, + DefineEditTextTag.ID, + DefineFont2Tag.ID, + DefineFont3Tag.ID, + DefineFont4Tag.ID, + DefineFontAlignZonesTag.ID, + DefineFontInfo2Tag.ID, + DefineFontInfoTag.ID, + DefineFontNameTag.ID, + DefineFontTag.ID, + DefineMorphShape2Tag.ID, + DefineMorphShapeTag.ID, + DefineScalingGridTag.ID, + DefineSceneAndFrameLabelDataTag.ID, + DefineShape2Tag.ID, + DefineShape3Tag.ID, + DefineShape4Tag.ID, + DefineShapeTag.ID, + DefineSoundTag.ID, + DefineSpriteTag.ID, + DefineText2Tag.ID, + DefineTextTag.ID, + DefineVideoStreamTag.ID, + DoABCDefineTag.ID, + DoABCTag.ID, + DoActionTag.ID, + DoInitActionTag.ID, + EnableDebugger2Tag.ID, + EnableDebuggerTag.ID, + EnableTelemetryTag.ID, + EndTag.ID, + ExportAssetsTag.ID, + FileAttributesTag.ID, + FrameLabelTag.ID, + ImportAssets2Tag.ID, + ImportAssetsTag.ID, + JPEGTablesTag.ID, + MetadataTag.ID, + PlaceObject2Tag.ID, + PlaceObject3Tag.ID, + PlaceObject4Tag.ID, + PlaceObjectTag.ID, + ProductInfoTag.ID, + ProtectTag.ID, + RemoveObject2Tag.ID, + RemoveObjectTag.ID, + ScriptLimitsTag.ID, + SetBackgroundColorTag.ID, + SetTabIndexTag.ID, + ShowFrameTag.ID, + SoundStreamBlockTag.ID, + SoundStreamHead2Tag.ID, + SoundStreamHeadTag.ID, + StartSound2Tag.ID, + StartSoundTag.ID, + SymbolClassTag.ID, + TagStub.ID, + VideoFrameTag.ID, + DefineCompactedFont.ID, + DefineExternalGradient.ID, + DefineExternalImage.ID, + DefineExternalImage2.ID, + DefineExternalSound.ID, + DefineExternalStreamSound.ID, + DefineGradientMap.ID, + DefineSubImage.ID, + ExporterInfoTag.ID, + FontTextureInfo.ID); + knownTagIds = tagIds; + } + } + } + return knownTagIds; + } + + public static List getRequiredTags() { + if (requiredTagIds == null) { + synchronized(lockObject) { + if (requiredTagIds == null) { + List tagIds = Arrays.asList( + DefineBinaryDataTag.ID, + DefineBitsJPEG2Tag.ID, + DefineBitsJPEG3Tag.ID, + DefineBitsJPEG4Tag.ID, + DefineBitsLossless2Tag.ID, + DefineBitsLosslessTag.ID, + DefineBitsTag.ID, + DefineButton2Tag.ID, + DefineButtonCxformTag.ID, + DefineButtonSoundTag.ID, + DefineButtonTag.ID, + DefineEditTextTag.ID, + DefineFont2Tag.ID, + DefineFont3Tag.ID, + DefineFont4Tag.ID, + DefineFontAlignZonesTag.ID, + DefineFontInfo2Tag.ID, + DefineFontInfoTag.ID, + DefineFontNameTag.ID, + DefineFontTag.ID, + DefineMorphShape2Tag.ID, + DefineMorphShapeTag.ID, + DefineScalingGridTag.ID, + DefineSceneAndFrameLabelDataTag.ID, + DefineShape2Tag.ID, + DefineShape3Tag.ID, + DefineShape4Tag.ID, + DefineShapeTag.ID, + DefineSoundTag.ID, + DefineSpriteTag.ID, + DefineText2Tag.ID, + DefineTextTag.ID, + DefineVideoStreamTag.ID, + DoABCDefineTag.ID, + DoABCTag.ID, + DoActionTag.ID, + DoInitActionTag.ID, + ShowFrameTag.ID); + requiredTagIds = tagIds; + } + } + } + return requiredTagIds; + } + /** * Gets data bytes * diff --git a/trunk/src/com/jpexs/decompiler/flash/tags/UnknownTag.java b/trunk/src/com/jpexs/decompiler/flash/tags/UnknownTag.java new file mode 100644 index 000000000..f2a6f2815 --- /dev/null +++ b/trunk/src/com/jpexs/decompiler/flash/tags/UnknownTag.java @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2010-2013 JPEXS + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.jpexs.decompiler.flash.tags; + +import com.jpexs.decompiler.flash.SWF; + +/** + * + * @author JPEXS + */ +public class UnknownTag extends Tag { + + public UnknownTag(SWF swf, int id, byte[] data, long pos) { + super(swf, id, "Unknown", data, pos); + } +}