DoActionTag::DoActionTag(RECORDHEADER h, std::istream& in):DisplayListTag(h) { LOG(LOG_CALLS,_("DoActionTag")); int dest=in.tellg(); dest+=h.getLength(); while(1) { ACTIONRECORDHEADER ah(in); if(ah.ActionCode==0) break; else actions.push_back(ah.createTag(in)); if(actions.back()==NULL) { actions.pop_back(); LOG(LOG_ERROR,_("Not supported action opcode")); ignore(in,dest-in.tellg()); break; } } }
_NR<Tag> TagFactory::readTag() { RECORDHEADER h; //Catch eofs try { f >> h; } catch (ifstream::failure e) { if(!f.eof()) //Only handle eof throw e; f.clear(); LOG(LOG_INFO,"Simulating EndTag at EOF @ " << f.tellg()); return _MR(new EndTag(h,f)); } unsigned int expectedLen=h.getLength(); unsigned int start=f.tellg(); Tag* ret=NULL; LOG(LOG_TRACE,_("Reading tag type: ") << h.getTagType() << _(" at byte ") << start << _(" with length ") << expectedLen << _(" bytes")); switch(h.getTagType()) { case 0: LOG(LOG_INFO,_("End of parsing @ ") << f.tellg()); ret=new EndTag(h,f); break; case 1: ret=new ShowFrameTag(h,f); break; case 2: ret=new DefineShapeTag(h,f); break; // case 4: // ret=new PlaceObjectTag(h,f); case 6: ret=new DefineBitsTag(h,f); break; case 9: ret=new SetBackgroundColorTag(h,f); break; case 10: ret=new DefineFontTag(h,f); break; case 11: ret=new DefineTextTag(h,f); break; case 13: ret=new DefineFontInfoTag(h,f); break; case 14: ret=new DefineSoundTag(h,f); break; case 15: ret=new StartSoundTag(h,f); break; case 18: ret=new SoundStreamHeadTag(h,f); break; case 19: ret=new SoundStreamBlockTag(h,f); break; case 20: ret=new DefineBitsLosslessTag(h,f,1); break; case 21: ret=new DefineBitsJPEG2Tag(h,f); break; case 22: ret=new DefineShape2Tag(h,f); break; case 24: ret=new ProtectTag(h,f); break; case 26: ret=new PlaceObject2Tag(h,f); break; case 28: ret=new RemoveObject2Tag(h,f); break; case 32: ret=new DefineShape3Tag(h,f); break; case 33: ret=new DefineText2Tag(h,f); break; case 34: ret=new DefineButton2Tag(h,f); break; case 35: ret=new DefineBitsJPEG3Tag(h,f); break; case 36: ret=new DefineBitsLosslessTag(h,f,2); break; case 37: ret=new DefineEditTextTag(h,f); break; case 39: ret=new DefineSpriteTag(h,f); break; case 41: ret=new ProductInfoTag(h,f); break; case 43: ret=new FrameLabelTag(h,f); break; case 45: ret=new SoundStreamHead2Tag(h,f); break; case 46: ret=new DefineMorphShapeTag(h,f); break; case 48: ret=new DefineFont2Tag(h,f); break; case 58: ret=new EnableDebuggerTag(h,f); break; case 60: ret=new DefineVideoStreamTag(h,f); break; case 63: ret=new DebugIDTag(h,f); break; case 64: ret=new EnableDebugger2Tag(h,f); break; case 65: ret=new ScriptLimitsTag(h,f); break; case 69: //FileAttributes tag is mandatory on version>=8 and must be the first tag if(pt->version>=8) { if(!firstTag) LOG(LOG_ERROR,_("FileAttributes tag not in the beginning")); } ret=new FileAttributesTag(h,f); break; case 70: ret=new PlaceObject3Tag(h,f); break; case 72: ret=new DoABCTag(h,f); break; case 73: ret=new DefineFontAlignZonesTag(h,f); break; case 74: ret=new CSMTextSettingsTag(h,f); break; case 75: ret=new DefineFont3Tag(h,f); break; case 76: ret=new SymbolClassTag(h,f); break; case 77: ret=new MetadataTag(h,f); break; case 78: ret=new DefineScalingGridTag(h,f); break; case 82: ret=new DoABCDefineTag(h,f); break; case 83: ret=new DefineShape4Tag(h,f); break; case 86: ret=new DefineSceneAndFrameLabelDataTag(h,f); break; case 87: ret=new DefineBinaryDataTag(h,f); break; case 88: ret=new DefineFontNameTag(h,f); break; case 91: ret=new DefineFont4Tag(h,f); break; default: LOG(LOG_NOT_IMPLEMENTED,_("Unsupported tag type ") << h.getTagType()); ret=new UnimplementedTag(h,f); } //Check if this clip is the main clip and if AVM2 has been enabled by a FileAttributes tag if(topLevel && firstTag && pt->getRootMovie()==sys) { sys->needsAVM2(pt->useAVM2); if(pt->useNetwork && sys->securityManager->getSandboxType() == SecurityManager::LOCAL_WITH_FILE) { sys->securityManager->setSandboxType(SecurityManager::LOCAL_WITH_NETWORK); LOG(LOG_INFO, _("Switched to local-with-networking sandbox by FileAttributesTag")); } } firstTag=false; unsigned int end=f.tellg(); unsigned int actualLen=end-start; if(actualLen<expectedLen) { LOG(LOG_ERROR,_("Error while reading tag ") << h.getTagType() << _(". Size=") << actualLen << _(" expected: ") << expectedLen); ignore(f,expectedLen-actualLen); } else if(actualLen>expectedLen) { LOG(LOG_ERROR,_("Error while reading tag ") << h.getTagType() << _(". Size=") << actualLen << _(" expected: ") << expectedLen); throw ParseException("Malformed SWF file"); } return _MNR(ret); }
Tag* TagFactory::readTag() { RECORDHEADER h; f >> h; unsigned int expectedLen=h.getLength(); unsigned int start=f.tellg(); Tag* ret=NULL; LOG(LOG_TRACE,_("Reading tag type: ") << h.getTagType() << _(" at byte ") << start << _(" with length ") << expectedLen << _(" bytes")); switch(h.getTagType()) { case 0: LOG(LOG_TRACE, _("EndTag at position ") << f.tellg()); ret=new EndTag(h,f); break; case 1: ret=new ShowFrameTag(h,f); break; case 2: ret=new DefineShapeTag(h,f); break; // case 4: // ret=new PlaceObjectTag(h,f); case 6: ret=new DefineBitsTag(h,f); break; case 9: ret=new SetBackgroundColorTag(h,f); break; case 10: ret=new DefineFontTag(h,f); break; case 11: ret=new DefineTextTag(h,f); break; case 12: ret=new DoActionTag(h,f); break; case 13: ret=new DefineFontInfoTag(h,f); break; case 14: ret=new DefineSoundTag(h,f); break; case 15: ret=new StartSoundTag(h,f); break; case 18: ret=new SoundStreamHeadTag(h,f); break; case 19: ret=new SoundStreamBlockTag(h,f); break; case 20: ret=new DefineBitsLosslessTag(h,f); break; case 21: ret=new DefineBitsJPEG2Tag(h,f); break; case 22: ret=new DefineShape2Tag(h,f); break; case 24: ret=new ProtectTag(h,f); break; case 26: ret=new PlaceObject2Tag(h,f); break; case 28: ret=new RemoveObject2Tag(h,f); break; case 32: ret=new DefineShape3Tag(h,f); break; case 33: ret=new DefineText2Tag(h,f); break; case 34: ret=new DefineButton2Tag(h,f); break; case 35: ret=new DefineBitsJPEG3Tag(h,f); break; case 36: ret=new DefineBitsLossless2Tag(h,f); break; case 37: ret=new DefineEditTextTag(h,f); break; case 39: ret=new DefineSpriteTag(h,f); break; case 41: ret=new ProductInfoTag(h,f); break; case 43: ret=new FrameLabelTag(h,f); break; case 45: ret=new SoundStreamHead2Tag(h,f); break; case 46: ret=new DefineMorphShapeTag(h,f); break; case 48: ret=new DefineFont2Tag(h,f); break; case 56: ret=new ExportAssetsTag(h,f); break; case 58: ret=new EnableDebuggerTag(h,f); break; case 59: ret=new DoInitActionTag(h,f); break; case 60: ret=new DefineVideoStreamTag(h,f); break; case 63: ret=new DebugIDTag(h,f); break; case 64: ret=new EnableDebugger2Tag(h,f); break; case 65: ret=new ScriptLimitsTag(h,f); break; case 69: //FileAttributes tag is mandatory on version>=8 and must be the first tag if(pt->version>=8) { if(!firstTag) LOG(LOG_ERROR,_("FileAttributes tag not in the beginning")); } ret=new FileAttributesTag(h,f); break; case 70: ret=new PlaceObject3Tag(h,f); break; case 73: ret=new DefineFontAlignZonesTag(h,f); break; case 74: ret=new CSMTextSettingsTag(h,f); break; case 75: ret=new DefineFont3Tag(h,f); break; case 76: ret=new SymbolClassTag(h,f); break; case 77: ret=new MetadataTag(h,f); break; case 78: ret=new DefineScalingGridTag(h,f); break; case 82: ret=new DoABCTag(h,f); break; case 83: ret=new DefineShape4Tag(h,f); break; case 86: ret=new DefineSceneAndFrameLabelDataTag(h,f); break; case 87: ret=new DefineBinaryDataTag(h,f); break; case 88: ret=new DefineFontNameTag(h,f); break; default: LOG(LOG_NOT_IMPLEMENTED,_("Unsupported tag type ") << h.getTagType()); ret=new UnimplementedTag(h,f); } //Check if this clip is the main clip and if AVM2 has been enabled by a FileAttributes tag if(topLevel && firstTag && pt->root==sys) sys->needsAVM2(pt->useAVM2); firstTag=false; unsigned int end=f.tellg(); unsigned int actualLen=end-start; if(actualLen<expectedLen) { LOG(LOG_ERROR,_("Error while reading tag ") << h.getTagType() << _(". Size=") << actualLen << _(" expected: ") << expectedLen); ignore(f,expectedLen-actualLen); } else if(actualLen>expectedLen) { LOG(LOG_ERROR,_("Error while reading tag ") << h.getTagType() << _(". Size=") << actualLen << _(" expected: ") << expectedLen); throw ParseException("Malformed SWF file"); } return ret; }
Tag* TagFactory::readTag(RootMovieClip* root) { RECORDHEADER h; //Catch eofs try { f >> h; } catch (ifstream::failure& e) { if(!f.eof()) //Only handle eof throw; f.clear(); LOG(LOG_INFO,"Simulating EndTag at EOF @ " << f.tellg()); return new EndTag(h,f); } unsigned int expectedLen=h.getLength(); unsigned int start=f.tellg(); Tag* ret=NULL; LOG(LOG_TRACE,_("Reading tag type: ") << h.getTagType() << _(" at byte ") << start << _(" with length ") << expectedLen << _(" bytes")); switch(h.getTagType()) { case 0: ret=new EndTag(h,f); break; case 1: ret=new ShowFrameTag(h,f); break; case 2: ret=new DefineShapeTag(h,f,root); break; // case 4: // ret=new PlaceObjectTag(h,f); case 6: ret=new DefineBitsTag(h,f,root); break; case 7: ret=new DefineButtonTag(h,f,1,root); break; case 8: ret=new JPEGTablesTag(h,f); break; case 9: ret=new SetBackgroundColorTag(h,f); break; case 10: ret=new DefineFontTag(h,f,root); break; case 11: ret=new DefineTextTag(h,f,root); break; case 13: ret=new DefineFontInfoTag(h,f); break; case 14: ret=new DefineSoundTag(h,f,root); break; case 15: ret=new StartSoundTag(h,f); break; case 18: ret=new SoundStreamHeadTag(h,f); break; case 19: ret=new SoundStreamBlockTag(h,f); break; case 20: ret=new DefineBitsLosslessTag(h,f,1,root); break; case 21: ret=new DefineBitsJPEG2Tag(h,f,root); break; case 22: ret=new DefineShape2Tag(h,f,root); break; case 24: ret=new ProtectTag(h,f); break; case 26: ret=new PlaceObject2Tag(h,f,root); break; case 28: ret=new RemoveObject2Tag(h,f); break; case 32: ret=new DefineShape3Tag(h,f,root); break; case 33: ret=new DefineText2Tag(h,f,root); break; case 34: ret=new DefineButtonTag(h,f,2,root); break; case 35: ret=new DefineBitsJPEG3Tag(h,f,root); break; case 36: ret=new DefineBitsLosslessTag(h,f,2,root); break; case 37: ret=new DefineEditTextTag(h,f,root); break; case 39: ret=new DefineSpriteTag(h,f,root); break; case 41: ret=new ProductInfoTag(h,f); break; case 43: ret=new FrameLabelTag(h,f); break; case 45: ret=new SoundStreamHead2Tag(h,f); break; case 46: ret=new DefineMorphShapeTag(h,f,root); break; case 48: ret=new DefineFont2Tag(h,f,root); break; case 58: ret=new EnableDebuggerTag(h,f); break; case 60: ret=new DefineVideoStreamTag(h,f,root); break; case 63: ret=new DebugIDTag(h,f); break; case 64: ret=new EnableDebugger2Tag(h,f); break; case 65: ret=new ScriptLimitsTag(h,f); break; case 69: //FileAttributes tag is mandatory on version>=8 and must be the first tag if(!firstTag) LOG(LOG_ERROR,_("FileAttributes tag not in the beginning")); ret=new FileAttributesTag(h,f); break; case 70: ret=new PlaceObject3Tag(h,f,root); break; case 72: ret=new DoABCTag(h,f); break; case 73: ret=new DefineFontAlignZonesTag(h,f); break; case 74: ret=new CSMTextSettingsTag(h,f); break; case 75: ret=new DefineFont3Tag(h,f,root); break; case 76: ret=new SymbolClassTag(h,f); break; case 77: ret=new MetadataTag(h,f); break; case 78: ret=new DefineScalingGridTag(h,f); break; case 82: ret=new DoABCDefineTag(h,f); break; case 83: ret=new DefineShape4Tag(h,f,root); break; case 84: ret=new DefineMorphShape2Tag(h,f,root); break; case 86: ret=new DefineSceneAndFrameLabelDataTag(h,f); break; case 87: ret=new DefineBinaryDataTag(h,f,root); break; case 88: ret=new DefineFontNameTag(h,f); break; case 91: ret=new DefineFont4Tag(h,f,root); break; default: LOG(LOG_NOT_IMPLEMENTED,_("Unsupported tag type ") << h.getTagType()); ret=new UnimplementedTag(h,f); } firstTag=false; unsigned int end=f.tellg(); unsigned int actualLen=end-start; if(actualLen<expectedLen) { LOG(LOG_ERROR,_("Error while reading tag ") << h.getTagType() << _(". Size=") << actualLen << _(" expected: ") << expectedLen); ignore(f,expectedLen-actualLen); } else if(actualLen>expectedLen) { LOG(LOG_ERROR,_("Error while reading tag ") << h.getTagType() << _(". Size=") << actualLen << _(" expected: ") << expectedLen); throw ParseException("Malformed SWF file"); } // don't set loaded bytes if we are at the end of the file (this is done in RootMovieClip::initFrame() ) if (root->loaderInfo->getBytesTotal() != f.tellg()) root->loaderInfo->setBytesLoaded(f.tellg()); return ret; }