bool FastCheck(const Binary::Container& rawData) { if (rawData.Size() < MIN_SIZE) { return false; } const SignatureType& sign = *static_cast<const SignatureType*>(rawData.Start()); return sign == SIGNATURE; }
bool FastCheck(const Binary::Container& rawData) { if (rawData.Size() <= sizeof(Header)) { return false; } const Header* const header = static_cast<const Header*>(rawData.Start()); return 0 == std::memcmp(header->Sign, SIGNATURE, sizeof(SIGNATURE)) && MARKER == header->Marker; }
virtual Container::Ptr Decode(const Binary::Container& rawData) const { const void* const data = rawData.Start(); const std::size_t availSize = rawData.Size(); const FullDiskImage::Container container(data, availSize); if (!container.FastCheck()) { return Container::Ptr(); } FullDiskImage::Decoder decoder(container); return CreatePackedContainer(decoder.GetResult(), decoder.GetUsedSize()); }
virtual Container::Ptr Decode(const Binary::Container& rawData) const { if (!Depacker->Match(rawData)) { return Container::Ptr(); } const MSPack::Container container(rawData.Start(), rawData.Size()); if (!container.FastCheck()) { return Container::Ptr(); } MSPack::DataDecoder decoder(container); return CreatePackedContainer(decoder.GetResult(), container.GetUsedSize()); }
bool FastCheck(const Binary::Container& rawData) { if (rawData.Size() <= sizeof(Header)) { return false; } const Header& header = *static_cast<const Header*>(rawData.Start()); std::size_t minDataStart = sizeof(header); for (uint_t reg = 0; reg != header.Buffers.size(); ++reg) { const BufferDescription& buf = header.Buffers[reg]; if (buf.SizeHi != 1 && buf.SizeHi != 4) { return false; } const std::size_t dataOffset = buf.GetAbsoluteOffset(reg); if (dataOffset < minDataStart) { return false; } minDataStart = dataOffset; } return true; }
Formats::Chiptune::Container::Ptr Parse(const Binary::Container& rawData, Builder& target) { if (!FastCheck(rawData)) { return Formats::Chiptune::Container::Ptr(); } try { const std::size_t size = rawData.Size(); const uint8_t* const begin = static_cast<const uint8_t*>(rawData.Start()); const uint8_t* const end = begin + size; const Header& header = *safe_ptr_cast<const Header*>(begin); const uint_t frames = fromLE(header.Duration); target.SetFrames(frames); std::size_t usedBegin = size; std::size_t usedEnd = 0; for (uint_t reg = 0; reg != header.Buffers.size(); ++reg) { target.StartChannel(reg); const BufferDescription& buf = header.Buffers[reg]; const std::size_t offset = buf.GetAbsoluteOffset(reg); Require(offset < size); Stream stream(buf.SizeHi, begin + offset, end); ParseBuffer(frames, stream, target); usedBegin = std::min(usedBegin, offset); usedEnd = std::max<std::size_t>(usedEnd, stream.GetCursor() - begin); } const Binary::Container::Ptr subData = rawData.GetSubcontainer(0, usedEnd); return CreateCalculatingCrcContainer(subData, usedBegin, usedEnd - usedBegin); } catch (const std::exception&) { return Formats::Chiptune::Container::Ptr(); } }
Module::Holder::Ptr CreateModule(const Parameters::Accessor& params, const Binary::Container& rawData, Parameters::Container::Ptr properties) const override { try { const TunePtr tune = std::make_shared<SidTune>(static_cast<const uint_least8_t*>(rawData.Start()), static_cast<uint_least32_t>(rawData.Size())); CheckSidplayError(tune->getStatus()); const unsigned songIdx = tune->selectSong(0); const SidTuneInfo& tuneInfo = *tune->getInfo(); if (tuneInfo.songs() > 1) { Require(HasSidContainer(*properties)); } PropertiesHelper props(*properties); switch (tuneInfo.numberOfInfoStrings()) { default: case 3: //copyright/publisher really props.SetComment(FromStdString(tuneInfo.infoString(2))); case 2: props.SetAuthor(FromStdString(tuneInfo.infoString(1))); case 1: props.SetTitle(FromStdString(tuneInfo.infoString(0))); case 0: break; } const Binary::Container::Ptr data = rawData.GetSubcontainer(0, tuneInfo.dataFileLen()); const Formats::Chiptune::Container::Ptr source = Formats::Chiptune::CreateCalculatingCrcContainer(data, 0, data->Size()); props.SetSource(*source); const uint_t fps = tuneInfo.songSpeed() == SidTuneInfo::SPEED_CIA_1A || tuneInfo.clockSpeed() == SidTuneInfo::CLOCK_NTSC ? 60 : 50; props.SetFramesFrequency(fps); const Information::Ptr info = MakePtr<Information>(GetDuration(params), tune, fps, songIdx); return MakePtr<Holder>(tune, info, properties); } catch (const std::exception&) { return Holder::Ptr(); } }