示例#1
0
 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;
 }
示例#2
0
文件: psg.cpp 项目: djdron/zxtune
 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;
 }
示例#3
0
 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());
 }
示例#4
0
文件: mspack.cpp 项目: fgroen/zxtune
 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());
 }
示例#5
0
文件: ayc.cpp 项目: djdron/zxtune
 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;
 }
示例#6
0
文件: ayc.cpp 项目: djdron/zxtune
    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();
      }
    }
示例#7
0
    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();
      }
    }