本文整理汇总了C++中Read32函数的典型用法代码示例。如果您正苦于以下问题:C++ Read32函数的具体用法?C++ Read32怎么用?C++ Read32使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Read32函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Read32
void Elf32_Ehdr::Load(vfsStream& f)
{
e_magic = Read32(f);
e_class = Read8(f);
e_data = Read8(f);
e_curver = Read8(f);
e_os_abi = Read8(f);
if (IsLittleEndian())
{
e_abi_ver = Read64LE(f);
e_type = Read16LE(f);
e_machine = Read16LE(f);
e_version = Read32LE(f);
e_entry = Read32LE(f);
e_phoff = Read32LE(f);
e_shoff = Read32LE(f);
e_flags = Read32LE(f);
e_ehsize = Read16LE(f);
e_phentsize = Read16LE(f);
e_phnum = Read16LE(f);
e_shentsize = Read16LE(f);
e_shnum = Read16LE(f);
e_shstrndx = Read16LE(f);
}
else
{
e_abi_ver = Read64(f);
e_type = Read16(f);
e_machine = Read16(f);
e_version = Read32(f);
e_entry = Read32(f);
e_phoff = Read32(f);
e_shoff = Read32(f);
e_flags = Read32(f);
e_ehsize = Read16(f);
e_phentsize = Read16(f);
e_phnum = Read16(f);
e_shentsize = Read16(f);
e_shnum = Read16(f);
e_shstrndx = Read16(f);
}
}
示例2: Read32
void CFileSystemGCWii::InitFileSystem()
{
m_Initialized = true;
// read the whole FST
u64 FSTOffset = (u64)Read32(0x424) << m_OffsetShift;
// u32 FSTSize = Read32(0x428);
// u32 FSTMaxSize = Read32(0x42C);
// read all fileinfos
SFileInfo Root;
Root.m_NameOffset = Read32(FSTOffset + 0x0);
Root.m_Offset = (u64)Read32(FSTOffset + 0x4) << m_OffsetShift;
Root.m_FileSize = Read32(FSTOffset + 0x8);
if (Root.IsDirectory())
{
if (m_FileInfoVector.size())
PanicAlert("Wtf?");
u64 NameTableOffset = FSTOffset;
m_FileInfoVector.reserve((unsigned int)Root.m_FileSize);
for (u32 i = 0; i < Root.m_FileSize; i++)
{
SFileInfo sfi;
u64 Offset = FSTOffset + (i * 0xC);
sfi.m_NameOffset = Read32(Offset + 0x0);
sfi.m_Offset = (u64)Read32(Offset + 0x4) << m_OffsetShift;
sfi.m_FileSize = Read32(Offset + 0x8);
m_FileInfoVector.push_back(sfi);
NameTableOffset += 0xC;
}
BuildFilenames(1, m_FileInfoVector.size(), NULL, NameTableOffset);
}
}
示例3: Load
void SelfSection::Load(const fs::file& f)
{
*data = Read32(f);
size = Read64(f);
offset = Read64(f);
}
示例4: fopen
int SidFile::Parse(string file)
{
FILE *f = fopen(file.c_str(), "rb");
if(f == NULL)
{
return SIDFILE_ERROR_FILENOTFOUND;
}
uint8_t header[PSID_MAX_HEADER_LENGTH];
memset(header, 0, PSID_MAX_HEADER_LENGTH);
size_t read = fread(header, 1, PSID_MAX_HEADER_LENGTH, f);
if(read < PSID_MIN_HEADER_LENGTH || !IsPSIDHeader(header))
{
fclose(f);
return SIDFILE_ERROR_MALFORMED;
}
numOfSongs = Read16(header, SIDFILE_PSID_NUMBER);
if(numOfSongs == 0)
{
numOfSongs = 1;
}
firstSong = Read16(header, SIDFILE_PSID_DEFSONG);
if(firstSong)
{
firstSong--;
}
if (firstSong >= numOfSongs)
{
firstSong = 0;
}
initAddr = Read16(header, SIDFILE_PSID_INIT);
playAddr = Read16(header, SIDFILE_PSID_MAIN);
speedFlags = Read32(header, SIDFILE_PSID_SPEED);
moduleName = (char *)(header + SIDFILE_PSID_NAME);
authorName = (char *)(header + SIDFILE_PSID_AUTHOR);
string copyrightInfo = (char *)(header + SIDFILE_PSID_COPYRIGHT);
// Seek to start of module data
fseek(f, Read16(header, SIDFILE_PSID_LENGTH), SEEK_SET);
// Find load address
loadAddr = Read16(header, SIDFILE_PSID_START);
if(loadAddr == 0)
{
uint8_t lo = fgetc(f);
uint8_t hi = fgetc(f);
loadAddr = (hi << 8) | lo;
}
if(initAddr == 0)
{
initAddr = loadAddr;
}
// Load module data
dataLength = fread(dataBuffer, 1, 0x10000, f);
fclose(f);
return SIDFILE_OK;
}
示例5: while
bool PNGFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
{
istream& ifs = *pConv->GetInStream();
if(pConv->IsFirstInput())
{
_count=0;
_hasInputPngFile=true;
}
const char pngheader[] = {-119,80,78,71,13,10,26,10,0};
char readbytes[9];
ifs.read(readbytes, 8);
if(!equal(pngheader, pngheader+8, readbytes))
{
obErrorLog.ThrowError("PNG Format","Not a PNG file", obError);
return false;
}
//Loop through all the chunks
while(ifs)
{
unsigned int len = Read32(ifs);
ifs.read(readbytes,4);
string chunkid(readbytes, readbytes+4);
if(chunkid=="IEND")
{
bytesToIEND = ifs.tellg();
bytesToIEND -= 8;
break;
}
streampos pos = ifs.tellg();
const char* altid = pConv->IsOption("y",OBConversion::INOPTIONS);
if(chunkid=="tEXt" || chunkid=="zTXt" || (altid && chunkid==altid))
{
string keyword;
getline(ifs, keyword, '\0');
unsigned int datalength = len - keyword.size()-1;
//remove "file" from end of keyword
transform(keyword.begin(),keyword.end(),keyword.begin(),::tolower);
string::size_type pos = keyword.find("file");
if(pos!=string::npos)
keyword.erase(pos);
OBFormat* pFormat = OBConversion::FindFormat(keyword.c_str());
if(pFormat)
{
//We have found embedded text that we need to extract
stringstream ss;
if(chunkid[0]!='z')
{
//Copy it to a stringstream
istreambuf_iterator<char> initer(ifs);
ostreambuf_iterator<char> outiter(ss);
for (unsigned int i = 0; i < datalength; ++i)
*outiter++ = *initer++;
}
else
{
//Needs to be uncompressed first
Bytef* pCompTxt = new Bytef[datalength];
ifs.read((char*)pCompTxt, datalength);
--datalength; //for compression method byte
uLongf uncompLen;
Bytef* pUncTxt = new Bytef[datalength*6];//guess uncompressed length. NASTY!
if(*pCompTxt!=0 /*compression method*/
|| uncompress(pUncTxt, &uncompLen, pCompTxt+1, datalength)!=Z_OK)
{
obErrorLog.ThrowError("PNG Format","Errors in decompression", obError);
delete[] pUncTxt;
delete[] pCompTxt;
return false;
}
pUncTxt[uncompLen] = '\0';
ss.str((char*)pUncTxt);
delete[] pUncTxt;
delete[] pCompTxt;
}
//Use a new OBConversion object to convert embedded text
OBConversion conv2(&ss, pConv->GetOutStream());
conv2.CopyOptions(pConv);
conv2.SetInAndOutFormats(pFormat, pConv->GetOutFormat());
_count += conv2.Convert();
ifs.ignore(4);//CRC
continue; //already at the end of the chunk
}
}
//Move to end of chunk
ifs.seekg(pos);
ifs.ignore(len+4); //data + CRC
}
//if we will be writing a png file, read and save the whole input file.
CopyOfInput.clear();
if(pConv->GetOutFormat()==this)
//.........这里部分代码省略.........
示例6: ExecuteLevelScript
int ExecuteLevelScript()
{
dmsg(" - Level layout script: 0x%06X to 0x%06X (0x%X bytes)\n - Entry point at 0x%06X\n\n", LvlScript_Start, LvlScript_End, LvlScript_Length, LvlScript_Entry);
unsigned int ObjGeoOffset[256];
memset(ObjGeoOffset, 0x00, sizeof(ObjGeoOffset));
bool EndOfScript = false;
ColVtxBuffer = (unsigned char *) malloc (sizeof(char) * 0x8000);
ColTriBuffer = (unsigned char *) malloc (sizeof(char) * 0x10000);
ZWaterBuffer = (unsigned char *) malloc (sizeof(char) * 0x400); /* Room for 64 water boxes */
memset(ColTriBuffer, 0x10000, 0x0);
memset(ZWaterBuffer, 0x400, 0x0);
ZWaterOffset = 0;
#ifdef DEBUG
int i;
#endif
while (!(EndOfScript) && (TempScriptPos < ROMFilesize)) {
CurrentCmd = Read16(RAMSegment[TempScriptSegment].Data, TempScriptPos);
CurrentCmdLength = RAMSegment[TempScriptSegment].Data[TempScriptPos + 1];
JumpInScript = false;
if(CurrentCmdLength == 0x00) EndOfScript = true;
switch(CurrentCmd)
{
case 0x0204:
case 0x1E04:
// end
EndOfScript = true;
break;
case 0x0608: {
// jump
unsigned int TargetSeg = RAMSegment[TempScriptSegment].Data[TempScriptPos + 4];
if(RAMSegment[TargetSeg].IsSet) {
TempScriptPos_Backup = TempScriptPos;
TempScriptSegment_Backup = TempScriptSegment;
TempScriptPos = Read24(RAMSegment[TempScriptSegment].Data, TempScriptPos + 5);
TempScriptSegment = TargetSeg;
JumpInScript = true;
}
break; }
case 0x0704:
// return
TempScriptPos = (TempScriptPos_Backup + 4);
TempScriptSegment = TempScriptSegment_Backup;
break;
case 0x170C: {
// setup ram segment
unsigned int TempSeg = RAMSegment[TempScriptSegment].Data[TempScriptPos + 3];
dmsg("- Segment loader: 0x%02X\n", TempSeg);
unsigned int ROMData_Start = Read32(RAMSegment[TempScriptSegment].Data, TempScriptPos + 4);
unsigned int ROMData_End = Read32(RAMSegment[TempScriptSegment].Data, TempScriptPos + 8);
unsigned int ROMData_Length = ROMData_End - ROMData_Start;
RAMSegment[TempSeg].Data = (unsigned char *) malloc (sizeof(char) * ROMData_Length);
memcpy(RAMSegment[TempSeg].Data, &ROMBuffer[ROMData_Start], ROMData_Length);
RAMSegment[TempSeg].IsSet = true;
RAMSegment[TempSeg].Length = ROMData_Length;
dmsg("[ROM] RAM segment 0x%02X: 0x%08X to 0x%08X (0x%X bytes)\n", TempSeg, ROMData_Start, ROMData_End, ROMData_Length);
break; }
case 0x1A0C: {
// textures
unsigned int TempSeg = RAMSegment[TempScriptSegment].Data[TempScriptPos + 3];
dmsg("- Texture loader: 0x%02X\n", TempSeg);
if(TempSeg == 0x09) {
unsigned int TexData_Start = Read32(RAMSegment[TempScriptSegment].Data, TempScriptPos + 4);
unsigned int TexData_End = Read32(RAMSegment[TempScriptSegment].Data, TempScriptPos + 8);
TexData_Start += Read32(ROMBuffer, TexData_Start + 8);
TexData_Start += 2;
unsigned int TexData_Length = TexData_End - TexData_Start;
RAMSegment[TempSeg].Data = (unsigned char *) malloc (sizeof(char) * TexData_Length);
memcpy(RAMSegment[TempSeg].Data, &ROMBuffer[TexData_Start], TexData_Length);
RAMSegment[TempSeg].IsSet = true;
RAMSegment[TempSeg].Length = TexData_Length;
dmsg("[ROM] External texture data: 0x%08X to 0x%08X (0x%X bytes)\n", TexData_Start, TexData_End, TexData_Length);
}
break; }
case 0x1D04: {
// end of segment loading sequence
// generate initial zmap data
// only generate when segment 0x07 is already set, if it's not we're still executing segment 0x15
if(RAMSegment[0x07].IsSet == false) break;
msg(3, " - Generating initial Zelda map data...\n");
ZMapFilesize = RAMSegment[0x07].Length + ZMAP_HEADERGAP;
int PadSize = GetPaddingSize(ZMapFilesize, 0x08);
//.........这里部分代码省略.........
示例7: DumpObjDbgSyms
void DumpObjDbgSyms (FILE* F, unsigned long Offset)
/* Dump the debug symbols from an object file */
{
ObjHeader H;
Collection StrPool = AUTO_COLLECTION_INITIALIZER;
unsigned Count;
unsigned I;
/* Seek to the header position and read the header */
FileSetPos (F, Offset);
ReadObjHeader (F, &H);
/* Seek to the start of the string pool and read it */
FileSetPos (F, Offset + H.StrPoolOffs);
ReadStrPool (F, &StrPool);
/* Seek to the start of the debug syms */
FileSetPos (F, Offset + H.DbgSymOffs);
/* Output a header */
printf (" Debug symbols:\n");
/* Check if the object file was compiled with debug info */
if ((H.Flags & OBJ_FLAGS_DBGINFO) == 0) {
/* Print that there no debug symbols and bail out */
printf (" Count:%27u\n", 0);
return;
}
/* Read the number of exports and print it */
Count = ReadVar (F);
printf (" Count:%27u\n", Count);
/* Read and print all debug symbols */
for (I = 0; I < Count; ++I) {
unsigned long Value = 0;
unsigned long Size = 0;
unsigned ImportId = 0;
unsigned ExportId = 0;
/* Read the data for one symbol */
unsigned Type = ReadVar (F);
unsigned char AddrSize = Read8 (F);
unsigned long Owner = ReadVar (F);
const char* Name = GetString (&StrPool, ReadVar (F));
unsigned Len = strlen (Name);
if (SYM_IS_CONST (Type)) {
Value = Read32 (F);
} else {
SkipExpr (F);
}
if (SYM_HAS_SIZE (Type)) {
Size = ReadVar (F);
}
if (SYM_IS_IMPORT (Type)) {
ImportId = ReadVar (F);
}
if (SYM_IS_EXPORT (Type)) {
ExportId = ReadVar (F);
}
/* Skip both line info lists */
SkipLineInfoList (F);
SkipLineInfoList (F);
/* Print the header */
printf (" Index:%27u\n", I);
/* Print the data */
printf (" Type:%22s0x%02X (%s)\n", "", Type, GetExportFlags (Type, 0));
printf (" Address size:%14s0x%02X (%s)\n", "", AddrSize,
AddrSizeToStr (AddrSize));
printf (" Owner:%25lu\n", Owner);
printf (" Name:%*s\"%s\"\n", (int)(24-Len), "", Name);
if (SYM_IS_CONST (Type)) {
printf (" Value:%15s0x%08lX (%lu)\n", "", Value, Value);
}
if (SYM_HAS_SIZE (Type)) {
printf (" Size:%20s0x%04lX (%lu)\n", "", Size, Size);
}
if (SYM_IS_IMPORT (Type)) {
printf (" Import:%24u\n", ImportId);
}
if (SYM_IS_EXPORT (Type)) {
printf (" Export:%24u\n", ExportId);
}
}
/* Destroy the string pool */
DestroyStrPool (&StrPool);
}
示例8: if
bool PSFLoader::LoadValuesTable()
{
psf_f.Seek(psfhdr.psf_offset_values_table);
m_info.Reset();
for(uint i=0;i<m_table.GetCount(); i++)
{
if(!m_table[i].Cmp("TITLE_ID"))
{
m_info.serial = PsfHelper::ReadString(psf_f);
m_table[i].Append(wxString::Format(": %s", m_info.serial.mb_str()));
PsfHelper::GoToNN(psf_f);
}
else if(!m_table[i](0, 5).Cmp("TITLE"))
{
m_info.name = PsfHelper::FixName(PsfHelper::ReadString(psf_f));
m_table[i].Append(wxString::Format(": %s", m_info.name.mb_str()));
PsfHelper::GoToNN(psf_f);
}
else if(!m_table[i].Cmp("APP_VER"))
{
m_info.app_ver = PsfHelper::ReadString(psf_f, sizeof(u64));
m_table[i].Append(wxString::Format(": %s", m_info.app_ver.mb_str()));
}
else if(!m_table[i].Cmp("ATTRIBUTE"))
{
psf_f.Read(&m_info.attr, sizeof(m_info.attr));
m_table[i].Append(wxString::Format(": 0x%x", m_info.attr));
}
else if(!m_table[i].Cmp("CATEGORY"))
{
m_info.category = PsfHelper::ReadString(psf_f, sizeof(u32));
m_table[i].Append(wxString::Format(": %s", m_info.category.mb_str()));
}
else if(!m_table[i].Cmp("BOOTABLE"))
{
psf_f.Read(&m_info.bootable, sizeof(m_info.bootable));
m_table[i].Append(wxString::Format(": %d", m_info.bootable));
}
else if(!m_table[i].Cmp("LICENSE"))
{
m_table[i].Append(wxString::Format(": %s", PsfHelper::ReadString(psf_f).mb_str()));
psf_f.Seek(psf_f.Tell() + (sizeof(u64) * 7 * 2) - 1);
}
else if(!m_table[i](0, 14).Cmp("PARENTAL_LEVEL"))
{
u32 buf;
psf_f.Read(&buf, sizeof(buf));
if(!m_table[i].Cmp("PARENTAL_LEVEL"))
{
m_info.parental_lvl = buf;
}
m_table[i].Append(wxString::Format(": %d", buf));
}
else if(!m_table[i].Cmp("PS3_SYSTEM_VER"))
{
m_info.fw = PsfHelper::ReadString(psf_f, sizeof(u64));
m_table[i].Append(wxString::Format(": %s", m_info.fw.mb_str()));
}
else if(!m_table[i].Cmp("SOUND_FORMAT"))
{
m_info.sound_format = Read32(psf_f);
m_table[i].Append(wxString::Format(": 0x%x", m_info.sound_format));
}
else if(!m_table[i].Cmp("RESOLUTION"))
{
m_info.resolution = Read32(psf_f);
m_table[i].Append(wxString::Format(": 0x%x", m_info.resolution));
}
else
{
m_table[i].Append(wxString::Format(": %s", PsfHelper::ReadString(psf_f).mb_str()));
PsfHelper::GoToNN(psf_f);
}
}
if(m_info.serial.Length() == 9)
{
m_info.serial = m_info.serial(0, 4) + "-" + m_info.serial(4, 5);
}
return true;
}
示例9: switch
tTJSVariant* tTJSBinarySerializer::ReadBasicType( const tjs_uint8* buff, const tjs_uint size, tjs_uint& index ) {
if( index > size ) return NULL;
tjs_uint8 type = buff[index];
index++;
switch( type ) {
case TYPE_NIL:
return new tTJSVariant((iTJSDispatch2*)NULL);
case TYPE_VOID:
return new tTJSVariant();
case TYPE_TRUE:
return new tTJSVariant((tjs_int)1);
case TYPE_FALSE:
return new tTJSVariant((tjs_int)0);
case TYPE_STRING8: {
if( (index+sizeof(tjs_uint8)) > size ) TJS_eTJSError( TJSReadError );
tjs_uint8 len = buff[index]; index++;
if( (index+(len*sizeof(tjs_char))) > size ) TJS_eTJSError( TJSReadError );
return ReadStringVarint( buff, len, index );
}
case TYPE_STRING16: {
if( (index+sizeof(tjs_uint16)) > size ) TJS_eTJSError( TJSReadError );
tjs_uint16 len = Read16( buff, index );
if( (index+(len*sizeof(tjs_char))) > size ) TJS_eTJSError( TJSReadError );
return ReadStringVarint( buff, len, index );
}
case TYPE_STRING32: {
if( (index+sizeof(tjs_uint32)) > size ) TJS_eTJSError( TJSReadError );
tjs_uint32 len = Read32( buff, index );
if( (index+(len*sizeof(tjs_char))) > size ) TJS_eTJSError( TJSReadError );
return ReadStringVarint( buff, len, index );
}
case TYPE_FLOAT: {
if( (index+sizeof(float)) > size ) TJS_eTJSError( TJSReadError );
tjs_uint32 t = Read32( buff, index );
return new tTJSVariant(*(float*)&t);
}
case TYPE_DOUBLE: {
if( (index+sizeof(double)) > size ) TJS_eTJSError( TJSReadError );
tjs_uint64 t = Read64( buff, index );
return new tTJSVariant(*(double*)&t);
}
case TYPE_UINT8: {
if( (index+sizeof(tjs_uint8)) > size ) TJS_eTJSError( TJSReadError );
tjs_uint8 t = buff[index]; index++;
return new tTJSVariant( t );
}
case TYPE_UINT16: {
if( (index+sizeof(tjs_uint16)) > size ) TJS_eTJSError( TJSReadError );
tjs_uint16 t = Read16( buff, index );
return new tTJSVariant( t );
}
case TYPE_UINT32: {
if( (index+sizeof(tjs_uint32)) > size ) TJS_eTJSError( TJSReadError );
tjs_uint32 t = Read32( buff, index );
return new tTJSVariant( (tjs_int64)t );
}
case TYPE_UINT64: {
if( (index+sizeof(tjs_uint64)) > size ) TJS_eTJSError( TJSReadError );
tjs_uint64 t = Read64( buff, index );
return new tTJSVariant( (tjs_int64)t );
}
case TYPE_INT8: {
if( (index+sizeof(tjs_uint8)) > size ) TJS_eTJSError( TJSReadError );
tjs_uint8 t = buff[index]; index++;
return new tTJSVariant( (tjs_int8)t );
}
case TYPE_INT16: {
if( (index+sizeof(tjs_uint16)) > size ) TJS_eTJSError( TJSReadError );
tjs_uint16 t = Read16( buff, index );
return new tTJSVariant( (tjs_int16)t );
}
case TYPE_INT32: {
if( (index+sizeof(tjs_uint32)) > size ) TJS_eTJSError( TJSReadError );
tjs_uint32 t = Read32( buff, index );
return new tTJSVariant( (tjs_int32)t );
}
case TYPE_INT64: {
if( (index+sizeof(tjs_uint64)) > size ) TJS_eTJSError( TJSReadError );
tjs_uint64 t = Read64( buff, index );
return new tTJSVariant( (tjs_int64)t );
}
case TYPE_RAW16: {
if( (index+sizeof(tjs_uint16)) > size ) TJS_eTJSError( TJSReadError );
tjs_uint16 len = Read16( buff, index );
if( (index+len) > size ) TJS_eTJSError( TJSReadError );
return ReadOctetVarint( buff, len, index );
}
case TYPE_RAW32: {
if( (index+sizeof(tjs_uint32)) > size ) TJS_eTJSError( TJSReadError );
tjs_uint32 len = Read32( buff, index );
if( (index+len) > size ) TJS_eTJSError( TJSReadError );
return ReadOctetVarint( buff, len, index );
}
case TYPE_ARRAY16: {
if( (index+sizeof(tjs_uint16)) > size ) TJS_eTJSError( TJSReadError );
tjs_uint16 count = Read16( buff, index );
return ReadArray( buff, size, count, index );
}
case TYPE_ARRAY32: {
if( (index+sizeof(tjs_uint32)) > size ) TJS_eTJSError( TJSReadError );
//.........这里部分代码省略.........
示例10: LinkFile
static void LinkFile (const char* Name, FILETYPE Type)
/* Handle one file */
{
char* PathName;
FILE* F;
unsigned long Magic;
/* If we don't know the file type, determine it from the extension */
if (Type == FILETYPE_UNKNOWN) {
Type = GetFileType (Name);
}
/* For known file types, search the file in the directory list */
switch (Type) {
case FILETYPE_LIB:
PathName = SearchFile (LibSearchPath, Name);
if (PathName == 0) {
PathName = SearchFile (LibDefaultPath, Name);
}
break;
case FILETYPE_OBJ:
PathName = SearchFile (ObjSearchPath, Name);
if (PathName == 0) {
PathName = SearchFile (ObjDefaultPath, Name);
}
break;
default:
PathName = xstrdup (Name); /* Use the name as is */
break;
}
/* We must have a valid name now */
if (PathName == 0) {
Error ("Input file `%s' not found", Name);
}
/* Try to open the file */
F = fopen (PathName, "rb");
if (F == 0) {
Error ("Cannot open `%s': %s", PathName, strerror (errno));
}
/* Read the magic word */
Magic = Read32 (F);
/* Check the magic for known file types. The handling is somewhat weird
** since we may have given a file with a ".lib" extension, which was
** searched and found in a directory for library files, but we now find
** out (by looking at the magic) that it's indeed an object file. We just
** ignore the problem and hope no one will notice...
*/
switch (Magic) {
case OBJ_MAGIC:
ObjAdd (F, PathName);
++ObjFiles;
break;
case LIB_MAGIC:
LibAdd (F, PathName);
++LibFiles;
break;
default:
fclose (F);
Error ("File `%s' has unknown type", PathName);
}
/* Free allocated memory. */
xfree (PathName);
}
示例11: Read32
float kexBinFile::ReadFloat(void) {
fint_t fi;
fi.i = Read32();
return fi.f;
}
示例12: ReplayInfo
ReplayInfo *ReplayInfo::ReplayInfoFromFile(FILE *in)
{
char temp[256+1];
ReplayInfo *info = new ReplayInfo(0, 0);
uint32_t marker;
info->last_error = _("Unspecified error or end of file");
info->valid = false;
// Header magic
marker = Read32(in); // Header marker
if (marker != HEADER_MAGIC) {
info->last_error =
Format(_("Bad header 0x%08X instead of 0x%08X"), marker, HEADER_MAGIC);
return info;
}
// Version
if (!fscanf(in, "%256[^\n]\n", temp)) return info;
info->version = temp;
if (ferror(in)) return info;
// Time
info->duration_ms = Read32(in); // Duration
info->date = Read32(in); // Return of time(NULL)
if (ferror(in)) return info;
// Comment
if (!fscanf(in, "%256[^\n]\n", temp) || ferror(in)) return info;
info->comment = temp;
// map ID
if (!fscanf(in, "%256[^\n]\n", temp) || ferror(in)) return info;
info->map_id = temp;
// Teams
uint32_t num_teams = Read32(in); // Number of teams
if (num_teams > 8) {
info->last_error = Format(_("Suspicious number of teams 0x%08X"), num_teams);
return info;
}
while (num_teams) {
ConfigTeam team_cfg;
// Team No.i name
if (!fscanf(in, "%256[^\n]\n", temp) || ferror(in))
goto team_error;
team_cfg.id = std::string(temp);
// Player name for team No.i
if (!fscanf(in, "%256[^\n]\n", temp) || ferror(in))
goto team_error;
team_cfg.player_name = std::string(temp);
team_cfg.nb_characters = Read32(in);
if (ferror(in))
goto team_error;
// Nb characters for team ID No.i
if (!fscanf(in, "%256[^\n]\n", temp) || ferror(in))
goto team_error;
team_cfg.ai = std::string(temp);
info->teams.push_back(team_cfg);
num_teams--;
continue;
team_error:
info->last_error = _("End of file while parsing teams");
return info;
}
// Game mode
info->mode_info.allow_character_selection = Read32(in);
info->mode_info.turn_duration = Read32(in);
info->mode_info.duration_before_death_mode = Read32(in);
info->mode_info.damage_per_turn_during_death_mode = Read32(in);
info->mode_info.init_energy = Read32(in);
info->mode_info.max_energy = Read32(in);
info->mode_info.gravity = Read32(in);
if (Read32(in) != DATA_MAGIC) { // Data magic
info->last_error = Format(_("Bad data marker 0x%08X instead of 0x%08X"), marker, DATA_MAGIC);
return info;
}
info->valid = true;
return info;
}
示例13: Load
void SelfSection::Load(vfsStream& f)
{
*data = Read32(f);
size = Read64(f);
offset = Read64(f);
}
示例14: Read32
u64 TestEnvironment::TestMemory::Read64(VAddr addr) {
return Read32(addr) | static_cast<u64>(Read32(addr + 4)) << 32;
}
示例15: ReadObjHeader
void ReadObjHeader (FILE* F, ObjHeader* H)
/* Read an object file header from the file */
{
/* Read all fields */
H->Magic = Read32 (F);
H->Version = Read16 (F);
H->Flags = Read16 (F);
H->OptionOffs = Read32 (F);
H->OptionSize = Read32 (F);
H->FileOffs = Read32 (F);
H->FileSize = Read32 (F);
H->SegOffs = Read32 (F);
H->SegSize = Read32 (F);
H->ImportOffs = Read32 (F);
H->ImportSize = Read32 (F);
H->ExportOffs = Read32 (F);
H->ExportSize = Read32 (F);
H->DbgSymOffs = Read32 (F);
H->DbgSymSize = Read32 (F);
H->LineInfoOffs = Read32 (F);
H->LineInfoSize = Read32 (F);
H->StrPoolOffs = Read32 (F);
H->StrPoolSize = Read32 (F);
H->AssertOffs = Read32 (F);
H->AssertSize = Read32 (F);
H->ScopeOffs = Read32 (F);
H->ScopeSize = Read32 (F);
H->SpanOffs = Read32 (F);
H->SpanSize = Read32 (F);
}