Issue (Feature) #365 Search in memory: Filter fake SWFs: implemented

This commit is contained in:
Honfika
2013-12-23 16:16:00 +01:00
parent a09c7f7474
commit 11ee052e33
4 changed files with 195 additions and 3 deletions

View File

@@ -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.");
}
}
}

View File

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

View File

@@ -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<Integer> knownTagIds;
private static List<Integer> requiredTagIds;
public static List<Integer> getKnownTags() {
if (knownTagIds == null) {
synchronized(lockObject) {
if (knownTagIds == null) {
List<Integer> 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<Integer> getRequiredTags() {
if (requiredTagIds == null) {
synchronized(lockObject) {
if (requiredTagIds == null) {
List<Integer> 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
*

View File

@@ -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 <http://www.gnu.org/licenses/>.
*/
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);
}
}