Example #1
0
NS_IMETHODIMP
nsBinaryInputStream::ReadObject(bool aIsStrongRef, nsISupports* *aObject)
{
    nsCID cid;
    nsIID iid;
    nsresult rv = ReadID(&cid);
    if (NS_WARN_IF(NS_FAILED(rv)))
        return rv;

    rv = ReadID(&iid);
    if (NS_WARN_IF(NS_FAILED(rv)))
        return rv;

    // HACK: Intercept old (pre-gecko6) nsIURI IID, and replace with
    // the updated IID, so that we're QI'ing to an actual interface.
    // (As soon as we drop support for upgrading from pre-gecko6, we can
    // remove this chunk.)
    static const nsIID oldURIiid =
        { 0x7a22cc0, 0xce5, 0x11d3,
          { 0x93, 0x31, 0x0, 0x10, 0x4b, 0xa0, 0xfd, 0x40 }};

    // hackaround for bug 670542
    static const nsIID oldURIiid2 =
        { 0xd6d04c36, 0x0fa4, 0x4db3,
          { 0xbe, 0x05, 0x4a, 0x18, 0x39, 0x71, 0x03, 0xe2 }};

    // hackaround for bug 682031
    static const nsIID oldURIiid3 =
        { 0x12120b20, 0x0929, 0x40e9,
          { 0x88, 0xcf, 0x6e, 0x08, 0x76, 0x6e, 0x8b, 0x23 }};

    if (iid.Equals(oldURIiid) ||
        iid.Equals(oldURIiid2) ||
        iid.Equals(oldURIiid3)) {
        const nsIID newURIiid = NS_IURI_IID;
        iid = newURIiid;
    }
    // END HACK

    nsCOMPtr<nsISupports> object = do_CreateInstance(cid, &rv);
    if (NS_WARN_IF(NS_FAILED(rv)))
        return rv;

    nsCOMPtr<nsISerializable> serializable = do_QueryInterface(object);
    if (NS_WARN_IF(!serializable))
        return NS_ERROR_UNEXPECTED;

    rv = serializable->Read(this);
    if (NS_WARN_IF(NS_FAILED(rv)))
        return rv;

    return object->QueryInterface(iid, reinterpret_cast<void**>(aObject));
}
Example #2
0
  void MapReader::Visit (XmlReader& visitable)
  {
    BaseReaderVisitor::Visit (visitable);

    auto reader = visitable.ChangeRoot (xmlRootNodeName_);

    map_.SetID (
      reader->ReadID (
        XmlHelper::GetAttrNodeName (DEFAULT_XML_ID_NODE_NAME)));

    map_.SetName (reader->ReadString (DEFAULT_XML_NAME_NODE_NAME));

    /// @todo Integrate CollidableArea in xml loading (remove inclusion).
    GridCollidableArea* gridCollidableArea = new GridCollidableArea ();
    gridCollidableArea->SetSegmentCount (10, 10);
    map_.SetCollidableArea (gridCollidableArea);

    map_.SetSize (
      reader->ReadUInt (DEFAULT_XML_WIDTH_NODE_NAME),
      reader->ReadUInt (DEFAULT_XML_HEIGHT_NODE_NAME));

    auto staticObjectsReader = reader->ChangeRoot ("staticObjects");

    ReadStaticObjects (*staticObjectsReader);

    auto dynamicObjectsReader = reader->ChangeRoot ("dynamicObjects");

    ReadDynamicObjects (*dynamicObjectsReader);
  }
/* this returns true if supported and fills the info struct */
static bool GetFlashInfo(tFlashInfo* pInfo)
{
    rb->memset(pInfo, 0, sizeof(tFlashInfo));

    if (!ReadID(FB, &pInfo->manufacturer, &pInfo->id))
        return false;

    if (pInfo->manufacturer == 0xBF) /* SST */
    {
        if (pInfo->id == 0xD6)
        {
            pInfo->size = 256* 1024; /* 256k */
            rb->strcpy(pInfo->name, "SST39VF020");
            return true;
        }
        else if (pInfo->id == 0xD7)
        {
            pInfo->size = 512* 1024; /* 512k */
            rb->strcpy(pInfo->name, "SST39VF040");
            return true;
        }
        else
            return false;
    }
    return false;
}
Example #4
0
/*
 Input SimplePoint from a text file.
 */
istream& SimplePoint::ReadShape(istream &s)  {
	long int skip;
	ReadID(s);
	GenUtils::SkipTillNumber(s);
#ifdef WORDS_BIGENDIAN
	s >> skip;
	char q[16], t;
	double m1, m2;
	s.read((char*)q, sizeof(double) * 2);
	GDA_SWAP(q[0], q[7], t);
	GDA_SWAP(q[1], q[6], t);
	GDA_SWAP(q[2], q[5], t);
	GDA_SWAP(q[3], q[4], t);
	memcpy(&m1, &q[0], sizeof(double));
	GDA_SWAP(q[8], q[15], t);
	GDA_SWAP(q[9], q[14], t);
	GDA_SWAP(q[10], q[13], t);
	GDA_SWAP(q[11], q[12], t);
	memcpy(&m2, &q[8], sizeof(double));
	p = BasePoint(m1, m2);
#else
	s >> skip >> p;
#endif
	return s;
}
Example #5
0
void CInArchive::ReadArchiveProperties(CInArchiveInfo & /* archiveInfo */)
{
  for (;;)
  {
    if (ReadID() == NID::kEnd)
      break;
    SkipData();
  }
}
Example #6
0
  void SpriteReader::Visit (XmlReader& visitable)
  {
    auto reader = visitable.ChangeRoot (xmlRootNodeName_);
    reader = reader->ChangeRoot (DEFAULT_XML_TEXTURE_NODE_NAME);

    sprite_.SetTexture (
      ObjectFactory::Instance ().Create<Texture> (
        "Texture",
        reader->ReadID (
        XmlHelper::GetAttrNodeName (DEFAULT_XML_TEXTURE_ID_NODE_NAME))));
  }
Example #7
0
void CInArchive::WaitAttribute(UInt64 attribute)
{
  for (;;)
  {
    UInt64 type = ReadID();
    if (type == attribute)
      return;
    if (type == NID::kEnd)
      ThrowIncorrect();
    SkipData();
  }
}
Example #8
0
void CInArchive::ReadUnpackInfo(
    const CObjectVector<CByteBuffer> *dataVector,
    CObjectVector<CFolder> &folders)
{
  WaitAttribute(NID::kFolder);
  CNum numFolders = ReadNum();

  {
    CStreamSwitch streamSwitch;
    streamSwitch.Set(this, dataVector);
    folders.Clear();
    folders.Reserve(numFolders);
    for (CNum i = 0; i < numFolders; i++)
    {
      folders.Add(CFolder());
      GetNextFolderItem(folders.Back());
    }
  }

  WaitAttribute(NID::kCodersUnpackSize);

  CNum i;
  for (i = 0; i < numFolders; i++)
  {
    CFolder &folder = folders[i];
    CNum numOutStreams = folder.GetNumOutStreams();
    folder.UnpackSizes.Reserve(numOutStreams);
    for (CNum j = 0; j < numOutStreams; j++)
      folder.UnpackSizes.Add(ReadNumber());
  }

  for (;;)
  {
    UInt64 type = ReadID();
    if (type == NID::kEnd)
      return;
    if (type == NID::kCRC)
    {
      CBoolVector crcsDefined;
      CRecordVector<UInt32> crcs;
      ReadHashDigests(numFolders, crcsDefined, crcs);
      for (i = 0; i < numFolders; i++)
      {
        CFolder &folder = folders[i];
        folder.UnpackCRCDefined = crcsDefined[i];
        folder.UnpackCRC = crcs[i];
      }
      continue;
    }
    SkipData();
  }
}
	ParseResult IEbmlElement::ParseFromFile()
	{
		//std::cout << "On parsing IEbmlElement from file\n";
		PreClean();
		if (this->m_pReader == nullptr) return FAILED;
		long long total, available;
		m_pReader->Length(&total, &available);
		if (total > available) return E_FILE_FORMAT_INVALID;
		BytePostion cur_pos = this->GetDataStart();
		BytePostion stop_pos = this->GetDataSize() + cur_pos;
		if (stop_pos > total) return E_FILE_FORMAT_INVALID;
		if (cur_pos > stop_pos) return E_FILE_FORMAT_INVALID;
		while (cur_pos < stop_pos)
		{

			//std::cout << "e_start: " << cur_pos << std::endl;

			Uint64 status;
			long length = -1;
			BytePostion e_start = cur_pos;
			// Read ID
			status = ReadID(this->m_pReader, cur_pos, length);
			if (status < 0) return E_FILE_FORMAT_INVALID;
			if (!CheckIDLength(length)) return E_FILE_FORMAT_INVALID;
			cur_pos += length; // Consumes ID
			EbmlID id = (EbmlID)status;

			//std::cout << "ID: " << id << std::endl;

			// Read DataSize
			status = ReadUInt(this->m_pReader, cur_pos, length);
			if (status < 0) return E_FILE_FORMAT_INVALID;
			if (!CheckElementSize(length)) return E_FILE_FORMAT_INVALID;

			//std::cout << "d_size: " << status << std::endl;

			cur_pos += length; // Consumes Size
			Uint64 d_size = status;
			// Read Data

			//std::cout << "d_start: " << cur_pos << std::endl;
			//std::cout << std::endl;

			status = ParseChild(e_start, cur_pos + d_size - e_start, cur_pos, d_size, id);
			if (status != SUCCESS) return status;
			if (cur_pos > stop_pos) return E_FILE_FORMAT_INVALID;
			cur_pos += d_size;
		}
		if (cur_pos != stop_pos) return E_FILE_FORMAT_INVALID;
		AFewMoreActions();
		return SUCCESS;
	}
Example #10
0
static SRes WaitId(CSzData *sd, UInt32 id)
{
  for (;;)
  {
    UInt64 type;
    RINOK(ReadID(sd, &type));
    if (type == id)
      return SZ_OK;
    if (type == k7zIdEnd)
      return SZ_ERROR_ARCHIVE;
    RINOK(SkipData(sd));
  }
}
NS_IMETHODIMP
nsBinaryInputStream::ReadObject(PRBool aIsStrongRef, nsISupports* *aObject)
{
    nsCID cid;
    nsIID iid;
    nsresult rv = ReadID(&cid);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = ReadID(&iid);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsISupports> object = do_CreateInstance(cid, &rv);
    NS_ENSURE_SUCCESS(rv, rv);

    nsCOMPtr<nsISerializable> serializable = do_QueryInterface(object);
    NS_ENSURE_TRUE(serializable, NS_ERROR_UNEXPECTED);

    rv = serializable->Read(this);
    NS_ENSURE_SUCCESS(rv, rv);    

    return object->QueryInterface(iid, reinterpret_cast<void**>(aObject));
}
Example #12
0
/************************************************************
*Function:18B20ID全处理
*parameter:
*Return:
*Modify:
*************************************************************/
void TemperatuerResult(void)
{
  	p = id_buff;
  	ReadID();
  	Config18b20();
	Init18b20 ();
	WriteByte(0xcc);   //skip rom
	WriteByte(0x44);   //Temperature convert

	Init18b20 ();
	WriteByte(0xcc);   //skip rom
	WriteByte(0xbe);   //read Temperature
	p = temp_buff;
	GemTemp();
}
Example #13
0
void CInArchive::ReadStreamsInfo(
    const CObjectVector<CByteBuffer> *dataVector,
    UInt64 &dataOffset,
    CRecordVector<UInt64> &packSizes,
    CBoolVector &packCRCsDefined,
    CRecordVector<UInt32> &packCRCs,
    CObjectVector<CFolder> &folders,
    CRecordVector<CNum> &numUnpackStreamsInFolders,
    CRecordVector<UInt64> &unpackSizes,
    CBoolVector &digestsDefined,
    CRecordVector<UInt32> &digests)
{
  for (;;)
  {
    UInt64 type = ReadID();
    if (type > ((UInt32)1 << 30))
      ThrowIncorrect();
    switch((UInt32)type)
    {
      case NID::kEnd:
        return;
      case NID::kPackInfo:
      {
        ReadPackInfo(dataOffset, packSizes, packCRCsDefined, packCRCs);
        break;
      }
      case NID::kUnpackInfo:
      {
        ReadUnpackInfo(dataVector, folders);
        break;
      }
      case NID::kSubStreamsInfo:
      {
        ReadSubStreamsInfo(folders, numUnpackStreamsInFolders,
            unpackSizes, digestsDefined, digests);
        break;
      }
      default:
        ThrowIncorrect();
    }
  }
}
Example #14
0
File: 7zIn.cpp Project: bks/qz7
void CInArchive::ReadPackInfo(
    UInt64 &dataOffset,
    CRecordVector<UInt64> &packSizes,
    CRecordVector<bool> &packCRCsDefined,
    CRecordVector<UInt32> &packCRCs)
{
    dataOffset = ReadNumber();
    CNum numPackStreams = ReadNum();

    WaitAttribute(NID::kSize);
    packSizes.Clear();
    packSizes.Reserve(numPackStreams);
    for (CNum i = 0; i < numPackStreams; i++)
        packSizes.Add(ReadNumber());

    UInt64 type;
    for (;;)
    {
        type = ReadID();
        if (type == NID::kEnd)
            break;
        if (type == NID::kCRC)
        {
            ReadHashDigests(numPackStreams, packCRCsDefined, packCRCs);
            continue;
        }
        SkeepData();
    }
    if (packCRCsDefined.IsEmpty())
    {
        packCRCsDefined.Reserve(numPackStreams);
        packCRCsDefined.Clear();
        packCRCs.Reserve(numPackStreams);
        packCRCs.Clear();
        for (CNum i = 0; i < numPackStreams; i++)
        {
            packCRCsDefined.Add(false);
            packCRCs.Add(0);
        }
    }
}
Example #15
0
  void SkillInfoReader::Visit (XmlReader& visitable)
  {
    auto reader = visitable.ChangeRoot (xmlRootNodeName_);

    skillInfo_.SetID (
      reader->ReadID (
      XmlHelper::GetAttrNodeName (DEFAULT_XML_ID_NODE_NAME)));

    skillInfo_.SetName (reader->ReadString (DEFAULT_XML_NAME_NODE_NAME));

    skillInfo_.SetDescription (
      reader->ReadString (
      DEFAULT_XML_DESCRIPTION_NODE_NAME));

    skillInfo_.SetPower (reader->ReadInt (DEFAULT_XML_POWER_NODE_NAME));

    skillInfo_.SetPP (reader->ReadInt (DEFAULT_XML_PP_NODE_NAME));

    skillInfo_.SetMaxPP (reader->ReadInt (DEFAULT_XML_MAX_PP_NODE_NAME));

    skillInfo_.SetAccuracy (reader->ReadInt (DEFAULT_XML_ACCURACY_NODE_NAME));

    // Type of the skill
    skillInfo_.SetType (
      TypeInfo (ID (reader->ReadInt (DEFAULT_XML_TYPE_NODE_NAME))));

    skillInfo_.SetCategory (reader->ReadInt (DEFAULT_XML_CATEGORY_NODE_NAME));

    skillInfo_.SetTarget (reader->ReadInt (DEFAULT_XML_TARGET_NODE_NAME));

    skillInfo_.SetEffect (reader->ReadInt (DEFAULT_XML_EFFECT_NODE_NAME));

    skillInfo_.SetUse (reader->ReadInt (DEFAULT_XML_USE_NODE_NAME));

    skillInfo_.SetPriority (reader->ReadInt (DEFAULT_XML_PRIORITY_NODE_NAME));
  }
Example #16
0
HRESULT CInArchive::ReadHeader(
    DECL_EXTERNAL_CODECS_LOC_VARS
    CArchiveDatabaseEx &db
    #ifndef _NO_CRYPTO
    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
    #endif
    )
{
  UInt64 type = ReadID();

  if (type == NID::kArchiveProperties)
  {
    ReadArchiveProperties(db.ArchiveInfo);
    type = ReadID();
  }
 
  CObjectVector<CByteBuffer> dataVector;
  
  if (type == NID::kAdditionalStreamsInfo)
  {
    HRESULT result = ReadAndDecodePackedStreams(
        EXTERNAL_CODECS_LOC_VARS
        db.ArchiveInfo.StartPositionAfterHeader,
        db.ArchiveInfo.DataStartPosition2,
        dataVector
        #ifndef _NO_CRYPTO
        , getTextPassword, passwordIsDefined
        #endif
        );
    RINOK(result);
    db.ArchiveInfo.DataStartPosition2 += db.ArchiveInfo.StartPositionAfterHeader;
    type = ReadID();
  }

  CRecordVector<UInt64> unpackSizes;
  CBoolVector digestsDefined;
  CRecordVector<UInt32> digests;
  
  if (type == NID::kMainStreamsInfo)
  {
    ReadStreamsInfo(&dataVector,
        db.ArchiveInfo.DataStartPosition,
        db.PackSizes,
        db.PackCRCsDefined,
        db.PackCRCs,
        db.Folders,
        db.NumUnpackStreamsVector,
        unpackSizes,
        digestsDefined,
        digests);
    db.ArchiveInfo.DataStartPosition += db.ArchiveInfo.StartPositionAfterHeader;
    type = ReadID();
  }
  else
  {
    for (int i = 0; i < db.Folders.Size(); i++)
    {
      db.NumUnpackStreamsVector.Add(1);
      CFolder &folder = db.Folders[i];
      unpackSizes.Add(folder.GetUnpackSize());
      digestsDefined.Add(folder.UnpackCRCDefined);
      digests.Add(folder.UnpackCRC);
    }
  }

  db.Files.Clear();

  if (type == NID::kEnd)
    return S_OK;
  if (type != NID::kFilesInfo)
    ThrowIncorrect();
  
  CNum numFiles = ReadNum();
  db.Files.Reserve(numFiles);
  CNum i;
  for (i = 0; i < numFiles; i++)
    db.Files.Add(CFileItem());

  db.ArchiveInfo.FileInfoPopIDs.Add(NID::kSize);
  if (!db.PackSizes.IsEmpty())
    db.ArchiveInfo.FileInfoPopIDs.Add(NID::kPackInfo);
  if (numFiles > 0  && !digests.IsEmpty())
    db.ArchiveInfo.FileInfoPopIDs.Add(NID::kCRC);

  CBoolVector emptyStreamVector;
  BoolVector_Fill_False(emptyStreamVector, (int)numFiles);
  CBoolVector emptyFileVector;
  CBoolVector antiFileVector;
  CNum numEmptyStreams = 0;

  for (;;)
  {
    UInt64 type = ReadID();
    if (type == NID::kEnd)
      break;
    UInt64 size = ReadNumber();
    size_t ppp = _inByteBack->_pos;
    bool addPropIdToList = true;
    bool isKnownType = true;
    if (type > ((UInt32)1 << 30))
      isKnownType = false;
    else switch((UInt32)type)
    {
      case NID::kName:
      {
        CStreamSwitch streamSwitch;
        streamSwitch.Set(this, &dataVector);
        for (int i = 0; i < db.Files.Size(); i++)
          _inByteBack->ReadString(db.Files[i].Name);
        break;
      }
      case NID::kWinAttributes:
      {
        CBoolVector boolVector;
        ReadBoolVector2(db.Files.Size(), boolVector);
        CStreamSwitch streamSwitch;
        streamSwitch.Set(this, &dataVector);
        for (i = 0; i < numFiles; i++)
        {
          CFileItem &file = db.Files[i];
          file.AttribDefined = boolVector[i];
          if (file.AttribDefined)
            file.Attrib = ReadUInt32();
        }
        break;
      }
      case NID::kEmptyStream:
      {
        ReadBoolVector(numFiles, emptyStreamVector);
        for (i = 0; i < (CNum)emptyStreamVector.Size(); i++)
          if (emptyStreamVector[i])
            numEmptyStreams++;

        BoolVector_Fill_False(emptyFileVector, numEmptyStreams);
        BoolVector_Fill_False(antiFileVector, numEmptyStreams);

        break;
      }
      case NID::kEmptyFile:  ReadBoolVector(numEmptyStreams, emptyFileVector); break;
      case NID::kAnti:  ReadBoolVector(numEmptyStreams, antiFileVector); break;
      case NID::kStartPos:  ReadUInt64DefVector(dataVector, db.StartPos, (int)numFiles); break;
      case NID::kCTime:  ReadUInt64DefVector(dataVector, db.CTime, (int)numFiles); break;
      case NID::kATime:  ReadUInt64DefVector(dataVector, db.ATime, (int)numFiles); break;
      case NID::kMTime:  ReadUInt64DefVector(dataVector, db.MTime, (int)numFiles); break;
      case NID::kDummy:
      {
        for (UInt64 j = 0; j < size; j++)
          if (ReadByte() != 0)
            ThrowIncorrect();
        addPropIdToList = false;
        break;
      }
      default:
        addPropIdToList = isKnownType = false;
    }
    if (isKnownType)
    {
      if(addPropIdToList)
        db.ArchiveInfo.FileInfoPopIDs.Add(type);
    }
    else
      SkipData(size);
    bool checkRecordsSize = (db.ArchiveInfo.Version.Major > 0 ||
        db.ArchiveInfo.Version.Minor > 2);
    if (checkRecordsSize && _inByteBack->_pos - ppp != size)
      ThrowIncorrect();
  }

  CNum emptyFileIndex = 0;
  CNum sizeIndex = 0;

  CNum numAntiItems = 0;
  for (i = 0; i < numEmptyStreams; i++)
    if (antiFileVector[i])
      numAntiItems++;
    
  for (i = 0; i < numFiles; i++)
  {
    CFileItem &file = db.Files[i];
    bool isAnti;
    file.HasStream = !emptyStreamVector[i];
    if (file.HasStream)
    {
      file.IsDir = false;
      isAnti = false;
      file.Size = unpackSizes[sizeIndex];
      file.Crc = digests[sizeIndex];
      file.CrcDefined = digestsDefined[sizeIndex];
      sizeIndex++;
    }
    else
    {
      file.IsDir = !emptyFileVector[emptyFileIndex];
      isAnti = antiFileVector[emptyFileIndex];
      emptyFileIndex++;
      file.Size = 0;
      file.CrcDefined = false;
    }
    if (numAntiItems != 0)
      db.IsAnti.Add(isAnti);
  }
  return S_OK;
}
Example #17
0
  void PokemonInfoReader::Visit (XmlReader& visitable)
  {
    auto reader = visitable.ChangeRoot (xmlRootNodeName_);

    pokemonInfo_.SetID (
      reader->ReadID (
      XmlHelper::GetAttrNodeName (DEFAULT_XML_ID_NODE_NAME)));

    pokemonInfo_.SetName (reader->ReadString (DEFAULT_XML_NAME_NODE_NAME));

    pokemonInfo_.SetDescription (
      reader->ReadString (DEFAULT_XML_DESCRIPTION_NODE_NAME));

    pokemonInfo_.SetSpecies (
      reader->ReadString (DEFAULT_XML_SPECIES_NODE_NAME));

    pokemonInfo_.SetHeight (
      reader->ReadFloat (DEFAULT_XML_HEIGHT_NODE_NAME));

    pokemonInfo_.SetWeight (
      reader->ReadFloat (DEFAULT_XML_WEIGHT_NODE_NAME));

    pokemonInfo_.SetRarity (
      reader->ReadInt (DEFAULT_XML_RARITY_NODE_NAME));

    pokemonInfo_.SetGenderProbability (
      reader->ReadFloat (DEFAULT_XML_GENDER_NODE_NAME));

    pokemonInfo_.SetExperience (
      reader->ReadInt (DEFAULT_XML_EXPERIENCE_NODE_NAME));

    pokemonInfo_.SetExperienceType (StringHelper::Parse<ExperienceType>
      (reader->ReadString (DEFAULT_XML_EXPERIENCE_TYPE_NODE_NAME)));

    auto statsReader = 
      reader->ChangeRoot (DEFAULT_XML_BASE_STATS_NODE_NAME);

    pokemonInfo_.SetHitPoint (
      statsReader->ReadInt (DEFAULT_XML_HP_NODE_NAME));
    pokemonInfo_.SetAttack (
      statsReader->ReadInt (DEFAULT_XML_ATTACK_NODE_NAME));
    pokemonInfo_.SetDefense (
      statsReader->ReadInt (DEFAULT_XML_DEFENSE_NODE_NAME));
    pokemonInfo_.SetSpecialAttack (
      statsReader->ReadInt (DEFAULT_XML_SPECIAL_ATTACK_NODE_NAME));
    pokemonInfo_.SetSpecialDefense (
      statsReader->ReadInt (DEFAULT_XML_SPECIAL_DEFENSE_NODE_NAME));
    pokemonInfo_.SetSpeed (
      statsReader->ReadInt (DEFAULT_XML_SPEED_NODE_NAME));

    auto EVReader = 
      reader->ChangeRoot (DEFAULT_XML_EFFORT_VALUES_NODE_NAME);

    pokemonInfo_.SetHitPointEV (
      EVReader->ReadInt (DEFAULT_XML_HP_NODE_NAME));
    pokemonInfo_.SetAttackEV (
      EVReader->ReadInt (DEFAULT_XML_ATTACK_NODE_NAME));
    pokemonInfo_.SetDefenseEV (
      EVReader->ReadInt (DEFAULT_XML_DEFENSE_NODE_NAME));
    pokemonInfo_.SetSpecialAttackEV (
      EVReader->ReadInt (DEFAULT_XML_SPECIAL_ATTACK_NODE_NAME));
    pokemonInfo_.SetSpecialDefenseEV (
      EVReader->ReadInt (DEFAULT_XML_SPECIAL_DEFENSE_NODE_NAME));
    pokemonInfo_.SetSpeedEV (
      EVReader->ReadInt (DEFAULT_XML_SPEED_NODE_NAME));

    if (reader->NodeExists (DEFAULT_XML_EVOLUTION_NODE_NAME))
    {
      auto evolutionReader = reader->ChangeRoot (
        DEFAULT_XML_EVOLUTION_NODE_NAME);

      pokemonInfo_.SetEvolutionLevel (
        evolutionReader->ReadInt (
        XmlHelper::GetAttrNodeName (DEFAULT_XML_LEVEL_ATTR_NAME)));
      pokemonInfo_.SetPokemonEvolutionID (evolutionReader->ReadID ());
    }

    auto baseSkillsReader = 
      reader->ChangeRoot (DEFAULT_XML_BASE_SKILLS_NODE_NAME);

    yap::XmlReaderCollection skillReaders;
    baseSkillsReader->ReadNodes 
      (DEFAULT_XML_SKILL_NODE_NAME, skillReaders);
    for (auto& skillReader : skillReaders)
    {
      UInt16 level = skillReader->ReadInt (
        XmlHelper::GetAttrNodeName (DEFAULT_XML_LEVEL_ATTR_NAME));
      ID skillID = skillReader->ReadID ();

      pokemonInfo_.AddBaseSkill (level, skillID);
    }

    auto typeReader = reader->ChangeRoot (DEFAULT_XML_TYPES_NODE_NAME);

    pokemonInfo_.SetType1 
      (typeReader->ReadInt (DEFAULT_XML_TYPE1_NODE_NAME));

    pokemonInfo_.SetType2 
      (typeReader->ReadInt (DEFAULT_XML_TYPE2_NODE_NAME));

    auto graphicReader = reader->ChangeRoot (DEFAULT_XML_GRAPHICS_NODE_NAME);

    pokemonInfo_.SetIconPath (graphicReader->ReadString (DEFAULT_XML_ICON_NODE_NAME));

    // <male>
    auto maleReader = graphicReader->ChangeRoot (DEFAULT_XML_MALE_NODE_NAME);
    pokemonInfo_.SetMaleFrontPath 
      (maleReader->ReadString (DEFAULT_XML_FRONT_NODE_NAME));
    pokemonInfo_.SetMaleBackPath 
      (maleReader->ReadString (DEFAULT_XML_BACK_NODE_NAME));

    auto shinyMaleReader = maleReader->ChangeRoot (DEFAULT_XML_SHINY_NODE_NAME);
    pokemonInfo_.SetShinyMaleFrontPath 
      (shinyMaleReader->ReadString (DEFAULT_XML_FRONT_NODE_NAME));
    pokemonInfo_.SetShinyMaleBackPath 
      (shinyMaleReader->ReadString (DEFAULT_XML_BACK_NODE_NAME));
    // </male>

    // <female>
    auto femaleReader = graphicReader->ChangeRoot (DEFAULT_XML_FEMALE_NODE_NAME);
    pokemonInfo_.SetFemaleFrontPath 
      (femaleReader->ReadString (DEFAULT_XML_FRONT_NODE_NAME));
    pokemonInfo_.SetFemaleBackPath 
      (femaleReader->ReadString (DEFAULT_XML_BACK_NODE_NAME));

    auto shinyFemaleReader = femaleReader->ChangeRoot (DEFAULT_XML_SHINY_NODE_NAME);
    pokemonInfo_.SetShinyFemaleFrontPath 
      (shinyFemaleReader->ReadString (DEFAULT_XML_FRONT_NODE_NAME));
    pokemonInfo_.SetShinyFemaleBackPath 
      (shinyFemaleReader->ReadString (DEFAULT_XML_BACK_NODE_NAME));
    // </female>
  }
Example #18
0
void CInArchive::ReadSubStreamsInfo(
    const CObjectVector<CFolder> &folders,
    CRecordVector<CNum> &numUnpackStreamsInFolders,
    CRecordVector<UInt64> &unpackSizes,
    CBoolVector &digestsDefined,
    CRecordVector<UInt32> &digests)
{
  numUnpackStreamsInFolders.Clear();
  numUnpackStreamsInFolders.Reserve(folders.Size());
  UInt64 type;
  for (;;)
  {
    type = ReadID();
    if (type == NID::kNumUnpackStream)
    {
      for (int i = 0; i < folders.Size(); i++)
        numUnpackStreamsInFolders.Add(ReadNum());
      continue;
    }
    if (type == NID::kCRC || type == NID::kSize)
      break;
    if (type == NID::kEnd)
      break;
    SkipData();
  }

  if (numUnpackStreamsInFolders.IsEmpty())
    for (int i = 0; i < folders.Size(); i++)
      numUnpackStreamsInFolders.Add(1);

  int i;
  for (i = 0; i < numUnpackStreamsInFolders.Size(); i++)
  {
    // v3.13 incorrectly worked with empty folders
    // v4.07: we check that folder is empty
    CNum numSubstreams = numUnpackStreamsInFolders[i];
    if (numSubstreams == 0)
      continue;
    UInt64 sum = 0;
    for (CNum j = 1; j < numSubstreams; j++)
      if (type == NID::kSize)
      {
        UInt64 size = ReadNumber();
        unpackSizes.Add(size);
        sum += size;
      }
    unpackSizes.Add(folders[i].GetUnpackSize() - sum);
  }
  if (type == NID::kSize)
    type = ReadID();

  int numDigests = 0;
  int numDigestsTotal = 0;
  for (i = 0; i < folders.Size(); i++)
  {
    CNum numSubstreams = numUnpackStreamsInFolders[i];
    if (numSubstreams != 1 || !folders[i].UnpackCRCDefined)
      numDigests += numSubstreams;
    numDigestsTotal += numSubstreams;
  }

  for (;;)
  {
    if (type == NID::kCRC)
    {
      CBoolVector digestsDefined2;
      CRecordVector<UInt32> digests2;
      ReadHashDigests(numDigests, digestsDefined2, digests2);
      int digestIndex = 0;
      for (i = 0; i < folders.Size(); i++)
      {
        CNum numSubstreams = numUnpackStreamsInFolders[i];
        const CFolder &folder = folders[i];
        if (numSubstreams == 1 && folder.UnpackCRCDefined)
        {
          digestsDefined.Add(true);
          digests.Add(folder.UnpackCRC);
        }
        else
          for (CNum j = 0; j < numSubstreams; j++, digestIndex++)
          {
            digestsDefined.Add(digestsDefined2[digestIndex]);
            digests.Add(digests2[digestIndex]);
          }
      }
    }
    else if (type == NID::kEnd)
    {
      if (digestsDefined.IsEmpty())
      {
        BoolVector_Fill_False(digestsDefined, numDigestsTotal);
        digests.Clear();
        for (int i = 0; i < numDigestsTotal; i++)
          digests.Add(0);
      }
      return;
    }
    else
      SkipData();
    type = ReadID();
  }
}
Example #19
0
static ssize_t show_auo_id(struct device_driver *dev, char *buf)
{
	ReadID();
	return sprintf(buf, "%02X %02X %02X\n", LCMID[0], LCMID[1], LCMID[2]);
}
Example #20
0
SQInteger SQLexer::Lex()
{
	_lasttokenline = _currentline;
	while(CUR_CHAR != SQUIRREL_EOB) {
		switch(CUR_CHAR){
		case _SC('\t'): case _SC('\r'): case _SC(' '): NEXT(); continue;
		case _SC('\n'):
			_currentline++;
			_prevtoken=_curtoken;
			_curtoken=_SC('\n');
			NEXT();
			_currentcolumn=1;
			continue;
		case _SC('#'): LexLineComment(); continue;
		case _SC('/'):
			NEXT();
			switch(CUR_CHAR){
			case _SC('*'):
				NEXT();
				LexBlockComment();
				continue;	
			case _SC('/'):
				LexLineComment();
				continue;
			case _SC('='):
				NEXT();
				RETURN_TOKEN(TK_DIVEQ);
				continue;
			case _SC('>'):
				NEXT();
				RETURN_TOKEN(TK_ATTR_CLOSE);
				continue;
			default:
				RETURN_TOKEN('/');
			}
		case _SC('='):
			NEXT();
			if (CUR_CHAR != _SC('=')){ RETURN_TOKEN('=') }
			else { NEXT(); RETURN_TOKEN(TK_EQ); }
		case _SC('<'):
			NEXT();
			switch(CUR_CHAR) {
			case _SC('='):
				NEXT(); 
				if(CUR_CHAR == _SC('>')) {
					NEXT();
					RETURN_TOKEN(TK_3WAYSCMP); 
				}
				RETURN_TOKEN(TK_LE) 
				break;
			case _SC('-'): NEXT(); RETURN_TOKEN(TK_NEWSLOT); break;
			case _SC('<'): NEXT(); RETURN_TOKEN(TK_SHIFTL); break;
			case _SC('/'): NEXT(); RETURN_TOKEN(TK_ATTR_OPEN); break;
			}
			RETURN_TOKEN('<');
		case _SC('>'):
			NEXT();
			if (CUR_CHAR == _SC('=')){ NEXT(); RETURN_TOKEN(TK_GE);}
			else if(CUR_CHAR == _SC('>')){ 
				NEXT(); 
				if(CUR_CHAR == _SC('>')){
					NEXT();
					RETURN_TOKEN(TK_USHIFTR);
				}
				RETURN_TOKEN(TK_SHIFTR);
			}
			else { RETURN_TOKEN('>') }
		case _SC('!'):
			NEXT();
			if (CUR_CHAR != _SC('=')){ RETURN_TOKEN('!')}
			else { NEXT(); RETURN_TOKEN(TK_NE); }
		case _SC('@'): {
			SQInteger stype;
			NEXT();
			if(CUR_CHAR != _SC('"')) {
				RETURN_TOKEN('@');
			}
			if((stype=ReadString('"',true))!=-1) {
				RETURN_TOKEN(stype);
			}
			Error(_SC("error parsing the string"));
					   }
		case _SC('"'):
		case _SC('\''): {
			SQInteger stype;
			if((stype=ReadString(CUR_CHAR,false))!=-1){
				RETURN_TOKEN(stype);
			}
			Error(_SC("error parsing the string"));
			}
		case _SC('{'): case _SC('}'): case _SC('('): case _SC(')'): case _SC('['): case _SC(']'):
		case _SC(';'): case _SC(','): case _SC('?'): case _SC('^'): case _SC('~'):
			{SQInteger ret = CUR_CHAR;
			NEXT(); RETURN_TOKEN(ret); }
		case _SC('.'):
			NEXT();
			if (CUR_CHAR != _SC('.')){ RETURN_TOKEN('.') }
			NEXT();
			if (CUR_CHAR != _SC('.')){ Error(_SC("invalid token '..'")); }
			NEXT();
			RETURN_TOKEN(TK_VARPARAMS);
		case _SC('&'):
			NEXT();
			if (CUR_CHAR != _SC('&')){ RETURN_TOKEN('&') }
			else { NEXT(); RETURN_TOKEN(TK_AND); }
		case _SC('|'):
			NEXT();
			if (CUR_CHAR != _SC('|')){ RETURN_TOKEN('|') }
			else { NEXT(); RETURN_TOKEN(TK_OR); }
		case _SC(':'):
			NEXT();
			if (CUR_CHAR != _SC(':')){ RETURN_TOKEN(':') }
			else { NEXT(); RETURN_TOKEN(TK_DOUBLE_COLON); }
		case _SC('*'):
			NEXT();
			if (CUR_CHAR == _SC('=')){ NEXT(); RETURN_TOKEN(TK_MULEQ);}
			else RETURN_TOKEN('*');
		case _SC('%'):
			NEXT();
			if (CUR_CHAR == _SC('=')){ NEXT(); RETURN_TOKEN(TK_MODEQ);}
			else RETURN_TOKEN('%');
		case _SC('-'):
			NEXT();
			if (CUR_CHAR == _SC('=')){ NEXT(); RETURN_TOKEN(TK_MINUSEQ);}
			else if  (CUR_CHAR == _SC('-')){ NEXT(); RETURN_TOKEN(TK_MINUSMINUS);}
			else RETURN_TOKEN('-');
		case _SC('+'):
			NEXT();
			if (CUR_CHAR == _SC('=')){ NEXT(); RETURN_TOKEN(TK_PLUSEQ);}
			else if (CUR_CHAR == _SC('+')){ NEXT(); RETURN_TOKEN(TK_PLUSPLUS);}
			else RETURN_TOKEN('+');
		case SQUIRREL_EOB:
			return 0;
		default:{
				if (scisdigit(CUR_CHAR)) {
					SQInteger ret = ReadNumber();
					RETURN_TOKEN(ret);
				}
				else if (scisalpha(CUR_CHAR) || CUR_CHAR == _SC('_')) {
					SQInteger t = ReadID();
					RETURN_TOKEN(t);
				}
				else {
					SQInteger c = CUR_CHAR;
					if (sciscntrl((int)c)) Error(_SC("unexpected character(control)"));
					NEXT();
					RETURN_TOKEN(c);  
				}
				RETURN_TOKEN(0);
			}
		}
	}
	return 0;    
}
Example #21
0
HRESULT CInArchive::ReadDatabase2(
    DECL_EXTERNAL_CODECS_LOC_VARS
    CArchiveDatabaseEx &db
    #ifndef _NO_CRYPTO
    , ICryptoGetTextPassword *getTextPassword, bool &passwordIsDefined
    #endif
    )
{
  db.Clear();
  db.ArchiveInfo.StartPosition = _arhiveBeginStreamPosition;

  db.ArchiveInfo.Version.Major = _header[6];
  db.ArchiveInfo.Version.Minor = _header[7];

  if (db.ArchiveInfo.Version.Major != kMajorVersion)
    ThrowUnsupportedVersion();

  UInt32 crcFromArchive = Get32(_header + 8);
  UInt64 nextHeaderOffset = Get64(_header + 0xC);
  UInt64 nextHeaderSize = Get64(_header + 0x14);
  UInt32 nextHeaderCRC = Get32(_header + 0x1C);
  UInt32 crc = CrcCalc(_header + 0xC, 20);

  #ifdef FORMAT_7Z_RECOVERY
  if (crcFromArchive == 0 && nextHeaderOffset == 0 && nextHeaderSize == 0 && nextHeaderCRC == 0)
  {
    UInt64 cur, cur2;
    RINOK(_stream->Seek(0, STREAM_SEEK_CUR, &cur));
    const int kCheckSize = 500;
    Byte buf[kCheckSize];
    RINOK(_stream->Seek(0, STREAM_SEEK_END, &cur2));
    int checkSize = kCheckSize;
    if (cur2 - cur < kCheckSize)
      checkSize = (int)(cur2 - cur);
    RINOK(_stream->Seek(-checkSize, STREAM_SEEK_END, &cur2));
    
    RINOK(ReadStream_FALSE(_stream, buf, (size_t)checkSize));

    int i;
    for (i = (int)checkSize - 2; i >= 0; i--)
      if (buf[i] == 0x17 && buf[i + 1] == 0x6 || buf[i] == 0x01 && buf[i + 1] == 0x04)
        break;
    if (i < 0)
      return S_FALSE;
    nextHeaderSize = checkSize - i;
    nextHeaderOffset = cur2 - cur + i;
    nextHeaderCRC = CrcCalc(buf + i, (size_t)nextHeaderSize);
    RINOK(_stream->Seek(cur, STREAM_SEEK_SET, NULL));
  }
  else
  #endif
  {
    if (crc != crcFromArchive)
      ThrowIncorrect();
  }

  db.ArchiveInfo.StartPositionAfterHeader = _arhiveBeginStreamPosition + kHeaderSize;

  if (nextHeaderSize == 0)
    return S_OK;

  if (nextHeaderSize > (UInt64)0xFFFFFFFF)
    return S_FALSE;

  if ((Int64)nextHeaderOffset < 0)
    return S_FALSE;

  RINOK(_stream->Seek(nextHeaderOffset, STREAM_SEEK_CUR, NULL));

  CByteBuffer buffer2;
  buffer2.SetCapacity((size_t)nextHeaderSize);

  RINOK(ReadStream_FALSE(_stream, buffer2, (size_t)nextHeaderSize));
  HeadersSize += kHeaderSize + nextHeaderSize;
  db.PhySize = kHeaderSize + nextHeaderOffset + nextHeaderSize;

  if (CrcCalc(buffer2, (UInt32)nextHeaderSize) != nextHeaderCRC)
    ThrowIncorrect();
  
  CStreamSwitch streamSwitch;
  streamSwitch.Set(this, buffer2);
  
  CObjectVector<CByteBuffer> dataVector;
  
  UInt64 type = ReadID();
  if (type != NID::kHeader)
  {
    if (type != NID::kEncodedHeader)
      ThrowIncorrect();
    HRESULT result = ReadAndDecodePackedStreams(
        EXTERNAL_CODECS_LOC_VARS
        db.ArchiveInfo.StartPositionAfterHeader,
        db.ArchiveInfo.DataStartPosition2,
        dataVector
        #ifndef _NO_CRYPTO
        , getTextPassword, passwordIsDefined
        #endif
        );
    RINOK(result);
    if (dataVector.Size() == 0)
      return S_OK;
    if (dataVector.Size() > 1)
      ThrowIncorrect();
    streamSwitch.Remove();
    streamSwitch.Set(this, dataVector.Front());
    if (ReadID() != NID::kHeader)
      ThrowIncorrect();
  }

  db.HeadersSize = HeadersSize;

  return ReadHeader(
    EXTERNAL_CODECS_LOC_VARS
    db
    #ifndef _NO_CRYPTO
    , getTextPassword, passwordIsDefined
    #endif
    );
}
Example #22
0
int main(int argc, char **argv){
	
// Set I2C bus 	
	DEVICE = 2; // /dev/i2c-2 Olinuxino A20 micro, change if other board or i2c port used
	
	/* Read  program options */
	while(1){
		static struct option long_options[]=
		{
			{"verbose", no_argument,	&_DEBUG,	1},
			{"debug",	no_argument,	&_DEBUG,	1},
			
			
			{"relays?",	no_argument,0,'r'},
			{"adc",		required_argument,0,'a'},
			{"id",		no_argument,0,'i'},
			{"getport",		no_argument,0,'g'},
			{"getlat", no_argument,0,'G'},
			{"setrelays",	required_argument,0,'S'},
			{"setoutputs",	required_argument,0,'o'},
			{"settris",	required_argument,0,'t'},
			{"setpullups",	required_argument,0,'p'},
			{"switchon",	required_argument,0,'s'},
			{"switchoff",	required_argument,0,'n'},
			{"firmware",no_argument,0,'f'},
			{"help",	no_argument,0,'h'},
			{"busscan",	no_argument,0,'F'},
			{"setaddress", required_argument,0,'x'},
			{"setfactory",	no_argument,0,'X'},
			{0,		0, 			0,		0}
		};
		int option_index = 0;
		int c = getopt_long(argc, argv, "s:t:a:igGrp:o:S:n:fhx:bX?", long_options, &option_index);
		unsigned int value; 
		if (c == -1)
		{
			break;
		}
		
		switch(c)
		{
			case 'v':
				_DEBUG = 1;
				break;
			case 'h':
				Print_Help();
				break;
				
			case 'S':
				value = atoi(optarg);
				Relay(value);
				break;
			case 's':
				value = atoi(optarg);
				RelayOn(value);
				break;					
			case 'o':
				value = atoi(optarg);
				SetGPIO(value);
				break;	
			case 'n':
				value = atoi(optarg);
				RelayOff(value);
				break;				
			case 'b':
				DEVICE = atoi(optarg);
				break;					
			case 'a':
				value = atoi(optarg);
				ReadADC(value);
				break;
			case 'g':
				
				ReadGPIO();
				break;	
			case 'G':
				
				ReadLAT();
				break;	
			case 'F':
				BusScan();
				break;						
			case 'i':
				
				ReadID();
				break;	
			case 'X':
				Set_Factory();
				break;			
			case 'r':
				ReadRelays();
				break;
			case 't':
				value = atoi(optarg);
				Set_TRIS(value);
				break;
			case 'x':
				value = atoi(optarg);
				Set_Address(value);
				break;						
			case 'p':
				value = atoi(optarg);
				Set_PU(value);
				break;	
			case 'f':
			ReadSV();			
				break;
				
			default:
			
		//	Print_Help();
				break;
		}
	
	}
	
	
		
	return 0;
}