Ejemplo n.º 1
0
bool ELFHelper :: seekDebugSegment(StreamReader& reader, size_t& address)
{
   Elf32_Ehdr header;

   reader.read(&header, ELF_HEADER_SIZE);

   int count = header.e_phnum;
   Elf32_Phdr ph_header;
   bool skipRData = true;

   while (count > 0) {
      reader.read(&ph_header, header.e_phentsize);

      if (ph_header.p_type == PT_LOAD && ph_header.p_flags == PF_R) {
         if (!skipRData) {
            address = ph_header.p_vaddr;

            return true;
         }
         else skipRData = false;
      }

      count--;
   }

   return false;
}
Ejemplo n.º 2
0
Archivo: Mesh.cpp Proyecto: lcs2/carpg
//=================================================================================================
// Wczytuje dane wierzcho³ków z modelu (na razie dzia³a tylko dla Vec3)
//=================================================================================================
void Mesh::LoadVertexData(VertexData* vd, StreamReader& stream)
{
	// read and check header
	Header head;
	if(!stream.Read(head))
		throw "Failed to read file header.";
	if(memcmp(head.format, "QMSH", 4) != 0)
		throw Format("Invalid file signature '%.4s'.", head.format);
	if(head.version != 20)
		throw Format("Invalid file version '%d'.", head.version);
	if(head.flags != F_PHYSICS)
		throw Format("Invalid mesh flags '%d'.", head.flags);
	vd->radius = head.radius;

	// read vertices
	uint size = sizeof(Vec3) * head.n_verts;
	if(!stream.Ensure(size))
		throw "Failed to read vertex data.";
	vd->verts.resize(head.n_verts);
	stream.Read(vd->verts.data(), size);

	// read faces
	size = sizeof(Face) * head.n_tris;
	if(!stream.Ensure(size))
		throw "Failed to read triangle data.";
	vd->faces.resize(head.n_tris);
	stream.Read(vd->faces.data(), size);
}
 bool IOWrapper::seek( qint64 pos)
 {
     if (!m_streamReader.streamSeekable())
         return false;
     m_streamReader.setCurrentPos(pos);
     return true;
 }
Ejemplo n.º 4
0
void SISEmbeds::ExtractEmbeds(StreamReader& aReader )
	{
	iEmbeddedPkgUid = aReader.ReadInt32(); 
	iEmbeddedPkgName = aReader.ReadDescriptor();
	iEmbeddedVendorName = aReader.ReadDescriptor();
	iEmbeddedPkgIndex = aReader.ReadInt32();       
	}
Ejemplo n.º 5
0
// reiserfs_read
static status_t
reiserfs_read(fs_volume *fs, fs_vnode *_node, void *cookie, off_t pos,
	void *buffer, size_t *bufferSize)
{
	TOUCH(fs);
//	FUNCTION_START();
//	Volume *volume = (Volume*)fs->private_volume;
	VNode *node = (VNode*)_node->private_node;
	FUNCTION(("((%Ld: %lu, %lu), %Ld, %p, %lu)\n", node->GetID(),
			  node->GetDirID(), node->GetObjectID(), pos, buffer,
			  *bufferSize));
	status_t error = B_OK;
	// don't read anything but files
	if (!node->IsFile()) {
		if (node->IsDir())
			error = B_IS_A_DIRECTORY;
		else
			error = B_BAD_VALUE;
	}

	// read
	StreamReader *reader = (StreamReader*)cookie;
	if (error == B_OK) {
		error = reader->Resume();
		if (error == B_OK) {
			error = reader->ReadAt(pos, buffer, *bufferSize, bufferSize);
			reader->Suspend();
		}
	}
	RETURN_ERROR(error);
}
Ejemplo n.º 6
0
StreamReader* FileUtil_Win32_Impl::LoadFile(const char* pszFileName)
{
	if (!pszFileName || strlen(pszFileName) <= 0) return NULL;

	std::string strFullPath = m_strRootPath + pszFileName;

	FILE* pFile = NULL;
	fopen_s(&pFile, strFullPath.c_str(), "rb");
	if (pFile == NULL)
	{
		LOGE("open file failed: %s", strFullPath.c_str());
		return NULL;
	}

	fseek(pFile, 0, SEEK_END);
	uint nFileSize = ftell(pFile);
	fseek(pFile, 0, SEEK_SET);

	char* pszBuffer = new char[nFileSize+1];
	int nReadSize = fread(pszBuffer, 1, nFileSize, pFile);
	fclose(pFile);

	pszBuffer[nFileSize] = '\0';

	StreamReader* pStreamReader = new StreamReader(pszBuffer, nFileSize, true);
	if (!pStreamReader || !pStreamReader->IsOK())
	{
		LOGE("create stream reader failed with file size: %d", nFileSize);
		SAFE_DELETE(pStreamReader);
		SAFE_DELETE_ARRAY(pszBuffer);
		return NULL;
	}

	return pStreamReader;
}
Ejemplo n.º 7
0
// reiserfs_open
static status_t
reiserfs_open(fs_volume *fs, fs_vnode *_node, int openMode, void **cookie)
{
//	FUNCTION_START();
	Volume *volume = (Volume*)fs->private_volume;
	VNode *node = (VNode*)_node->private_node;
FUNCTION(("node: (%Ld: %lu, %lu)\n", node->GetID(), node->GetDirID(),
		  node->GetObjectID()));
	status_t error = B_OK;
	// check the open mode
	if ((openMode & O_RWMASK) == O_WRONLY || (openMode & O_RWMASK) == O_RDWR
		|| (openMode & (O_TRUNC | O_CREAT))) {
		error = B_READ_ONLY_DEVICE;
	}
	// create a StreamReader
	if (error == B_OK) {
		StreamReader *reader = new(nothrow) StreamReader(volume->GetTree(),
			node->GetDirID(), node->GetObjectID());
		if (reader) {
			error = reader->Suspend();
			if (error == B_OK)
				*cookie = reader;
			else
				delete reader;
		} else
			error = B_NO_MEMORY;
	}
	RETURN_ERROR(error);
}
Ejemplo n.º 8
0
	static int FileRead(sqlite3_file* pFile, void* pBuf, int amt, sqlite3_int64 offset64)
	{
		DBFile* file = (DBFile*)pFile;
		StreamReader* reader = file->reader;

		if (reader == NULL)
			return SQLITE_IOERR_READ;

		assert(offset64 >= 0);

		size_t offset = (size_t)offset64; // TODO: support 64bit
		reader->seek(offset);

		int read = reader->readRaw(pBuf, amt);
		if (read < amt)
		{
			uint8* fillStart = (uint8*)pBuf;
			fillStart += read;

			// sqlite needs us to fill zeroes when IOERR_SHORT_READ
			memset(fillStart, 0, amt - read);
			return SQLITE_IOERR_SHORT_READ;
		}

		return SQLITE_OK;
	}
Ejemplo n.º 9
0
static void PngReaderCallback(png_structp pPngStruct, png_bytep pData, png_size_t nSize)
{
	StreamReader* pStream = (StreamReader*)png_get_io_ptr(pPngStruct);

	if (!pStream->Read(pData, nSize))
	{
		png_error(pPngStruct,"pngReaderCallback failed");
	}
}
Ejemplo n.º 10
0
		void Array2D::init(StreamReader& s)
		{
			for(unsigned i = 0, length = s.ber(); i < length; i++) {
				unsigned index = s.ber();
				insert( index, std::auto_ptr<Array1D>( new Array1D(*this, index, s) ) );
			}

			if( toElement().hasOwner() ) rpg2k_analyze_assert( s.eof() );
		}
Ejemplo n.º 11
0
void SISControllerInfo::ExtractControllerInfo(StreamReader& aReader )
	{	
	iMajor = aReader.ReadInt32();
	iMinor = aReader.ReadInt32();
	iBuild = aReader.ReadInt32();
	iOffset = aReader.ReadInt32();
	iAlgorithmType = aReader.ReadInt32();
	char* controllerHash = aReader.ReadDescriptor();
	delete [] controllerHash;
	}
Ejemplo n.º 12
0
	void Program::Run()
	{
		StreamWriter* sw = new StreamWriter(new String("test.txt"));
		sw->WriteLine(new String("Hi! I'm a stream writer"));
		sw->Flush();
		sw->Close();
		StreamReader* sr = new StreamReader(new String("test.txt"));
		String* text = sr->ReadToEnd();
		sr->Close();
		Console::WriteLine(text);
	}
Ejemplo n.º 13
0
SyntaxTree::Node SyntaxTree:: read(StreamReader& reader)
{
   int type = reader.getDWord(-1);
   ref_t arg = reader.getDWord();
   int str = reader.getDWord();

   if (type == -1) {
      return Node();
   }
   else return Node(this, reader.Position(), (LexicalType)type, arg, str);
}
Ejemplo n.º 14
0
static string HttpGet(string url) {
  HttpWebRequest req = WebRequest.Create(url)
                       as HttpWebRequest;
  string result = null;
  using (HttpWebResponse resp = req.GetResponse()
                                as HttpWebResponse)
  {
    StreamReader reader =
        new StreamReader(resp.GetResponseStream());
    result = reader.ReadToEnd();
  }
Ejemplo n.º 15
0
static Error loadSectionContribs(FixedStreamArray<ContribType> &Output,
                                 StreamReader &Reader) {
  if (Reader.bytesRemaining() % sizeof(ContribType) != 0)
    return make_error<RawError>(
        raw_error_code::corrupt_file,
        "Invalid number of bytes of section contributions");

  uint32_t Count = Reader.bytesRemaining() / sizeof(ContribType);
  if (auto EC = Reader.readArray(Output, Count))
    return EC;
  return Error::success();
}
Ejemplo n.º 16
0
int StreamReader::seekCallback(void *data, const uint64_t pos)
{
    StreamReader *that = static_cast<StreamReader *>(data);
    if (static_cast<int64_t>(pos) > that->streamSize()) { // krazy:exclude=typedefs
        // attempt to seek past the end of our data.
        return -1;
    }

    that->setCurrentPos(pos);
    // this should return a true/false, but it doesn't, so assume success.

    return 0;
}
Ejemplo n.º 17
0
std::error_code ByteStream::initialize(StreamReader &Reader, uint32_t Length) {
  initialize(Length);
  std::error_code EC = Reader.readBytes(Data);
  if (EC)
    reset();
  return EC;
}
Ejemplo n.º 18
0
Error ByteStream::load(StreamReader &Reader, uint32_t Length) {
  load(Length);
  auto EC = Reader.readBytes(Data);
  if (EC)
    reset();
  return EC;
}
Ejemplo n.º 19
0
Error ByteStream::initialize(StreamReader &Reader, uint32_t Length) {
  initialize(Length);
  auto EC = Reader.readBytes(Data);
  if (EC)
    reset();
  return EC;
}
Ejemplo n.º 20
0
Archivo: Mesh.cpp Proyecto: lcs2/carpg
//=================================================================================================
// Load metadata only from mesh (points)
void Mesh::LoadMetadata(StreamReader& stream)
{
	if(vb)
		return;
	LoadHeader(stream);
	stream.SetOffset(head.points_offset);
	LoadPoints(stream);
}
Ejemplo n.º 21
0
void SISFileDescription::ExtractSISFileDescription(StreamReader& aReader )
	{
	iTarget = aReader.ReadDescriptor();
	iMimeType = aReader.ReadDescriptor();
	iOperation = aReader.ReadInt32();
	//indicates which options are applicable to the processing of this file during installation
	iOperationOptions = aReader.ReadInt32();
	//indicates the algorithm used to generate the hash
	iAlgorithm = aReader.ReadInt32();
	iHash = aReader.ReadDescriptor();
	iUncompressedLengthl = aReader.ReadInt32();
	iUncompressedLengthh = aReader.ReadInt32();
	iIndex = aReader.ReadInt32();
	iSid = aReader.ReadInt32();
	}
Ejemplo n.º 22
0
void
FndbManager::GetIgnorableFiles (/*[in]*/ const char *	lpszPath,
				/*[out]*/ vector<string> & filesToBeIgnored)
{
  PathName ignoreFile (lpszPath, FN_MIKTEXIGNORE, 0);
  if (! File::Exists(ignoreFile))
    {
      return;
    }
  StreamReader reader (ignoreFile);
  filesToBeIgnored.reserve (10);
  string line;
  while (reader.ReadLine(line))
    {
      filesToBeIgnored.push_back (line);
    }
  sort (filesToBeIgnored.begin(),
	filesToBeIgnored.end(),
	StringComparerIgnoringCase());
}
Ejemplo n.º 23
0
int StreamReader::readCallback(void *data, const char *cookie,
                               int64_t *dts, int64_t *pts, unsigned *flags, // krazy:exclude=typedefs
                               size_t *bufferSize, void **buffer)
{
    Q_UNUSED(cookie);
    Q_UNUSED(dts);
    Q_UNUSED(pts);
    Q_UNUSED(flags);

    StreamReader *that = static_cast<StreamReader *>(data);
    size_t length = BLOCKSIZE;

    *buffer = new char[length];

    int size = length;
    bool ret = that->read(that->currentPos(), &size, static_cast<char*>(*buffer));

    *bufferSize = static_cast<size_t>(size);

    return ret ? 0 : -1;
}
Ejemplo n.º 24
0
bool Debugger :: findSignature(StreamReader& reader, char* signature)
{
   reader.seek(0x08048000u);

   size_t rva = 0;
   ELFHelper::seekRDataSegment(reader, rva);

   // load Executable image
   current->readDump(rva, signature, strlen(ELENACLIENT_SIGNITURE));
   signature[strlen(ELENACLIENT_SIGNITURE)] = 0;

   return true;
}
Ejemplo n.º 25
0
bool DebugController :: loadDebugData(StreamReader& reader, bool setEntryAddress)
{
   if (setEntryAddress) {
      // read entry point
      _entryPoint = reader.getDWord();

      if (_entryPoint != 0)
         setEntryAddress = false;
   }

   IdentifierString reference;
   while (!reader.Eof()) {
      // read reference
      reader.readString(reference);

      // define the next record position
      int size = reader.getDWord() - 4;
      int nextPosition = reader.Position() + size;

      if (setEntryAddress) {
         // if entry address was not defined take the first one
         _entryPoint = reader.getDWord();

         reader.seek(reader.Position() - 4);
         setEntryAddress = false;
      }

   //   // if it is a VM temporal symbol and tape debugging as allowed
   //   if (ConstantIdentifier::compare(reference, TAPE_SYMBOL) && _debugTape) {
   //      loadTapeDebugInfo(reader, size);
   //   }
      // otherwise load standard debug info
   /*   else */loadSymbolDebugInfo(reference, reader);

      reader.seek(nextPosition);
   }

   return true;
}
Ejemplo n.º 26
0
bool Debugger :: initDebugInfo(bool standalone, StreamReader& reader, size_t& debugInfoPtr)
{
   if (standalone) {
      reader.seek(0x08048000u);

      _ELENA_::ELFHelper::seekDebugSegment(reader, debugInfoPtr);
   }
//   else if (_vmHook == 0) {
//      size_t rdata = Context()->readDWord(0x4000D0);
//      //HOTFIX : the actual length should be used
//      _vmHook = Context()->readDWord(0x400000 + rdata + _ELENA_::align(strlen(ELENACLIENT_SIGNITURE) + 3, 4));
//
//      // enable debug mode
//      Context()->writeDWord(_vmHook, -1);
//
//      return false;
//   }
//   // load VM debug section address
//   else debugInfoPtr = Context()->readDWord(_vmHook + 4);

   return true;
}
Ejemplo n.º 27
0
Archivo: Mesh.cpp Proyecto: lcs2/carpg
//=================================================================================================
void Mesh::LoadHeader(StreamReader& stream)
{
	// head
	if(!stream.Read(head))
		throw "Failed to read file header.";
	if(memcmp(head.format, "QMSH", 4) != 0)
		throw Format("Invalid file signature '%.4s'.", head.format);
	if(head.version < 12 || head.version > 20)
		throw Format("Invalid file version '%u'.", head.version);
	if(head.version < 20)
		throw Format("Unsupported file version '%u'.", head.version);
	if(head.n_bones >= 32)
		throw Format("Too many bones (%u).", head.n_bones);
	if(head.n_subs == 0)
		throw "Missing model mesh!";
	if(IS_SET(head.flags, F_ANIMATED) && !IS_SET(head.flags, F_STATIC))
	{
		if(head.n_bones == 0)
			throw "No bones.";
		if(head.n_groups == 0)
			throw "No bone groups.";
	}
}
Ejemplo n.º 28
0
Error NameHashTable::load(StreamReader &Stream) {
  struct Header {
    support::ulittle32_t Signature;
    support::ulittle32_t HashVersion;
    support::ulittle32_t ByteSize;
  };

  const Header *H;
  if (auto EC = Stream.readObject(H))
    return EC;

  if (H->Signature != 0xEFFEEFFE)
    return make_error<RawError>(raw_error_code::corrupt_file,
                                "Invalid hash table signature");
  if (H->HashVersion != 1 && H->HashVersion != 2)
    return make_error<RawError>(raw_error_code::corrupt_file,
                                "Unsupported hash version");

  Signature = H->Signature;
  HashVersion = H->HashVersion;
  if (auto EC = Stream.readStreamRef(NamesBuffer, H->ByteSize))
    return joinErrors(std::move(EC),
                      make_error<RawError>(raw_error_code::corrupt_file,
                                           "Invalid hash table byte length"));

  const support::ulittle32_t *HashCount;
  if (auto EC = Stream.readObject(HashCount))
    return EC;

  if (auto EC = Stream.readArray(IDs, *HashCount))
    return joinErrors(std::move(EC),
                      make_error<RawError>(raw_error_code::corrupt_file,
                                           "Could not read bucket array"));

  if (Stream.bytesRemaining() < sizeof(support::ulittle32_t))
    return make_error<RawError>(raw_error_code::corrupt_file,
                                "Missing name count");

  if (auto EC = Stream.readInteger(NameCount))
    return EC;
  return Error::success();
}
        qint64 IOWrapper::readData(char * data, qint64 maxSize)
        {
            int oldSize = m_streamReader.currentBufferSize();
            while (m_streamReader.currentBufferSize() < maxSize) {
                m_streamReader.needData();
                if (oldSize == m_streamReader.currentBufferSize()) {
                    break; //we didn't get any data
                }
                oldSize = m_streamReader.currentBufferSize();
            }

            qint64 bytesRead = qMin(qint64(m_streamReader.currentBufferSize()), maxSize);
            {
                QWriteLocker locker(&m_streamReader.m_lock);
                qMemCopy(data, m_streamReader.m_buffer.data(), bytesRead);
                //truncate the buffer
                m_streamReader.m_buffer = m_streamReader.m_buffer.mid(bytesRead);
            }
            return bytesRead;
        }
Ejemplo n.º 30
0
Archivo: Mesh.cpp Proyecto: lcs2/carpg
void Mesh::LoadPoints(StreamReader& stream)
{
	uint size = Point::MIN_SIZE * head.n_points;
	if(!stream.Ensure(size))
		throw "Failed to read points.";
	attach_points.clear();
	attach_points.resize(head.n_points);
	for(word i = 0; i < head.n_points; ++i)
	{
		Point& p = attach_points[i];

		stream.Read(p.name);
		stream.Read(p.mat);
		stream.Read(p.bone);
		stream.Read(p.type);
		stream.Read(p.size);
		stream.Read(p.rot);
		p.rot.y = Clip(-p.rot.y);
	}
}