void ParsePayload( const ParseInfo *info ) { printf( "\tParse payload...\n" ); uint8_t tmp = ReadByte(); uint8_t streamNumber = tmp & (BIT( 0 ) | BIT( 1 ) | BIT( 2 ) | BIT( 3 ) | BIT( 4 ) | BIT( 5 ) | BIT( 6 )); bool isKeyFrame = (tmp & BIT( 7 )) != 0; uint32_t mediaObjectNumber = ReadNumber( info->objectNumberLengthType ); uint32_t offset = ReadNumber( info->offsetLengthType ); uint32_t repLength = ReadNumber( info->repDataLengthType ); printf( "\t\tStream number: %d\n", streamNumber ); printf( "\t\tKey frame: %s\n", isKeyFrame ? "yes" : "no" ); printf( "\t\tMedia object number: %d\n", mediaObjectNumber ); printf( "\t\tOffset into object: %d\n", offset ); printf( "\t\tReplicated data length: %d\n", repLength ); if (repLength >= 8) { printf( "\t\tReplicated data:\n" ); printf( "\t\t\tMedia object size: %d\n", ReadDWord() ); printf( "\t\t\tPresentation time: %d\n", ReadDWord() ); printf( "\t\tSkipping rest of replicated data...\n" ); cursor += repLength - 8; } else { cursor += repLength; } size_t headerSize = cursor - packetStart; size_t dataSize = packetSize - headerSize - 0; printf( "\t\tData offset: %ld\n", cursor - buffer ); AddDataToObject( ¤tObjects[streamNumber], offset, dataSize, cursor ); }
void MMXCore::SwitchLevelEvent(bool ev) { WORD src, dest; switch(level) { case 2: sceneLayout[0x64] = sceneLayout[0xA0]; sceneLayout[0x65] = sceneLayout[0xA1]; sceneLayout[0x66] = sceneLayout[0xA2]; sceneLayout[0x67] = sceneLayout[0xA3]; sceneLayout[0x41] = sceneLayout[0xA4]; sceneLayout[0x42] = sceneLayout[0xA5]; sceneLayout[0x43] = sceneLayout[0xA6]; sceneLayout[0x44] = sceneLayout[0xA7]; break; case 4: src = (WORD)((ReadDWord(0x3C79) & 0xFFFFFF) - 0x7EE800); dest = (WORD)((ReadDWord(0x3C7D) & 0xFFFFFF) - 0x7EE800); sceneLayout[dest] = sceneLayout[src]; break; case 6: src = (WORD)((ReadDWord(0x3C8B) & 0xFFFFFF) - 0x7EE800); dest = (WORD)((ReadDWord(0x3C8F) & 0xFFFFFF) - 0x7EE800); sceneLayout[dest-3] = sceneLayout[src-4]; break; } }
/** * @name ParseHeader * Parse a Patch file header * @note The current implementation is far from complete! * * @param Patch * Buffer pointing to the raw patch data * * @param Header * The result of the parsed header * * @return STATUS_SUCCESS on success, an error code otherwise */ DWORD ParseHeader(SAFE_READ* Patch, PATCH_HEADER* Header) { DWORD Crc, Unknown; int Delta; ZeroMemory(Header, sizeof(*Header)); /* Validate the patch */ Crc = RtlComputeCrc32(0, Patch->Root, Patch->Size); if (Crc != ~0) return ERROR_PATCH_CORRUPT; if (ReadDWord(Patch) != '91AP') return ERROR_PATCH_DECODE_FAILURE; /* Read the flags, warn about an unknown combination */ Header->Flags = ReadDWord(Patch); if (Header->Flags ^ UNKNOWN_FLAGS_COMBINATION) ERR("Unknown flags: 0x%x, patch will most likely fail\n", Header->Flags ^ UNKNOWN_FLAGS_COMBINATION); /* 0x5bb3284e, 0x5bb33562, 0x5bb357b1 */ Unknown = ReadDWord(Patch); TRACE("Unknown: 0x%x\n", Unknown); Header->OutputSize = DecodeDWord(Patch); Header->OutputCrc = ReadDWord(Patch); Unknown = ReadByte(Patch); if (Unknown != 1) ERR("Field after CRC is not 1 but %u\n", Unknown); Delta = DecodeInt(Patch); Header->OldSize = Header->OutputSize + Delta; Header->OldCrc = ReadDWord(Patch); Unknown = ReadUShort(Patch); if (Unknown != 0) ERR("Field1 after OldCrc is not 0 but %u\n", Unknown); Unknown = DecodeDWord(Patch); if (Unknown != 0) ERR("Field2 after OldCrc is not 0 but %u\n", Unknown); Header->DataSize = DecodeDWord(Patch); /* Remaining data, minus the CRC appended */ if (Header->DataSize != (Patch->Size - (Patch->Ptr - Patch->Root) - sizeof(DWORD))) { ERR("Unable to read header, check previous logging!\n"); return ERROR_PATCH_DECODE_FAILURE; } return STATUS_SUCCESS; }
DWORD neTKVMRegAccess::ReadDWord(LPCTSTR lpzValueName, DWORD dwDefault, LPCTSTR lpzSubKey) { DWORD dwRes = 0; return (ReadDWord(lpzValueName, &dwRes, lpzSubKey) == TRUE)?dwRes:dwDefault; }
void ParseFileProperties() { printf( "\t\tFile ID: " ); PrintGUID(); printf( "\t\tFile size: %llu\n", ReadQWord() ); printf( "\t\tCreation date: %llu\n", ReadQWord() ); printf( "\t\tPacket count: %llu\n", ReadQWord() ); printf( "\t\tPlay duration: %llu\n", ReadQWord() ); printf( "\t\tSend duration: %llu\n", ReadQWord() ); printf( "\t\tPreroll: %llu\n", ReadQWord() ); printf( "\t\tFlags: %u\n", ReadDWord() ); packetSize = ReadDWord() ; printf( "\t\tMin Pack. size %u\n", packetSize ); uint32_t maxPacketSize = ReadDWord(); printf( "\t\tMax Pack. size %u\n", maxPacketSize ); printf( "\t\tMax bitrate %u\n", ReadDWord() ); printf( "\tend file properties\n" ); }
uint32_t ReadNumber( int type ) { switch (type) { case 1: return ReadByte(); case 2: return ReadWord(); case 3: return ReadDWord(); default: case 0: return 0; } }
void StdCompilerConfigRead::Character(char &rChar) { try { StdStrBuf szVal = ReadString(); rChar = *szVal.getData(); } catch (NotFoundException *pExc) { delete pExc; uint32_t iVal = ReadDWord(); rChar = char(iVal); } }
void StdCompilerConfigRead::Boolean(bool &rBool) { try { StdStrBuf szVal = ReadString(); rBool = (szVal == "true"); } catch (NotFoundException *pExc) { delete pExc; uint32_t iVal = ReadDWord(); rBool = !! iVal; } }
bool CBlockFile::FindBlock(const char *name) { long int curPos = 0; unsigned blockLen, nameLen, commentLen; if (mode != 'r') return FAIL; fseek(fp, 0, SEEK_SET); while (curPos < fileSize) { blockStartPos = curPos; // Read header curPos += ReadDWord(&blockLen); curPos += ReadDWord(&nameLen); curPos += ReadDWord(&commentLen); ReadString(strBuf,nameLen,1025); // Is this the block we want? if (!strcmp(strBuf,name)) { fseek(fp, blockStartPos+12+nameLen+commentLen, SEEK_SET); // move to beginning of data dataStartPos = ftell(fp); return OKAY; } // Move to next block fseek(fp, blockStartPos+blockLen, SEEK_SET); curPos = blockStartPos+blockLen; if (blockLen == 0) // this would never advance break; } return FAIL; }
void ParsePayloadHeader( uint8_t flags ) { printf( "\tParsing payload parsing information...\n" ); bool multiplePayloads = (flags & BIT( 0 )) != 0; int sequenceType = (flags & (BIT( 1 ) | BIT( 2 ))) >> 1; int paddingLengthType = (flags & (BIT( 3 ) | BIT( 4 ))) >> 3; int packetLengthType = (flags & (BIT( 5 ) | BIT( 6 ))) >> 5; bool ecPresent = (flags & BIT( 7 )) != 0; printf( "\tMultiple Payloads %s\n", multiplePayloads ? "yes" : "no" ); printf( "\tSequence type: %d\n", sequenceType ); printf( "\tPadding length type: %d\n", paddingLengthType ); printf( "\tPacket length type: %d\n", packetLengthType ); printf( "\tEC present: %s\n", ecPresent ? "yes" : "no" ); uint8_t propertyFlags = ReadByte(); ParseInfo info; info.repDataLengthType = propertyFlags & (BIT( 0 ) | BIT( 1 )); info.offsetLengthType = (propertyFlags & (BIT( 2 ) | BIT( 3 ))) >> 2; info.objectNumberLengthType = (propertyFlags & (BIT( 4 ) | BIT( 5 ))) >> 4; int streamNumberLengthType = (propertyFlags & (BIT( 6 ) | BIT( 7 ))) >> 6; printf( "\tRepl. data length type %d\n", info.repDataLengthType ); printf( "\tOffset into media object length type %d\n", info.offsetLengthType ); printf( "\tMedia object number lengtht type %d\n", info.objectNumberLengthType ); printf( "\tStream Number Length Type %d\n", streamNumberLengthType ); uint32_t packetLength = ReadNumber( packetLengthType ); printf( "\tPacket length: %d\n", packetLength ); uint32_t sequence = ReadNumber( sequenceType ); printf( "\tSequence number: %d\n", sequence ); uint32_t paddingLength = ReadNumber( paddingLengthType ); printf( "\tPadding length: %d\n", paddingLength ); uint32_t sendTime = ReadDWord(); printf( "\tSend time: %d\n", sendTime ); uint16_t duration = ReadWord(); printf( "\tDuration: %d\n", duration ); if (multiplePayloads) ParseMultiplePayloads( &info ); else ParsePayload( &info ); }
void MMXCore::LoadTiles() { BYTE tileSelect = checkpointInfo->tileLoad; int baseIndex = ReadWord(0x321D5 + level*2) + tileSelect*2; int mainIndex = ReadWord(0x321D5 + baseIndex); tileDecSize = ReadWord(0x321D5 + mainIndex); if (tileDecSize == NULL) return; tileDecDest = (ReadWord(0x321D5 + mainIndex + 2)<<1) -0x2000; tileDecPos = snes2pc(ReadDWord(0x321D5 + mainIndex + 4) & 0xFFFFFF); if (tileDecDest + tileDecSize > (WORD)0x8000) { MessageBox(NULL, "VRAM overflow.", "Error", MB_ICONERROR); } memcpy(vram+tileDecDest, rom+tileDecPos, tileDecSize); }
void ParseHeaderExtension() { cursor += 16; // Skip reserved field 1 cursor += 2; // Skip reserved field 2 uint16_t dataSize = ReadDWord(); printf( "\tHeader extension data size: %d\n", dataSize ); uint8_t *end = cursor + dataSize; while (cursor < end) { uint8_t *objectStart = cursor; GUIDType type = ReadGUID(); uint64_t size = ReadQWord(); uint8_t *next = objectStart + size; switch (type) { case GUIDUnknown: default: printf( "Unknown extended header object\n" ); break; } cursor = next; } }
void ParseHeaders() { printf( "Begin parsing headers\n" ); uint32_t headerCount = ReadDWord(); cursor += 2; printf( "\t%d headers\n\n", headerCount ); for (uint32_t i = 0; i < headerCount; i++) { uint8_t *objectStart = cursor; GUIDType type = ReadGUID(); uint64_t size = ReadQWord(); uint8_t *next = objectStart + size; printf( "\tOffset %ld, Object size: %llu\n", objectStart - buffer, size ); switch (type) { case GUIDFileProperties: printf( "\tFile properties found...\n" ); ParseFileProperties(); break; case GUIDStreamProperties: printf( "\tStream properties found...\n" ); ParseStreamProperties(); break; case GUIDHeaderExtension: printf( "\tHeader extension found...\n" ); ParseHeaderExtension(); break; case GUIDUnknown: default: printf( "\tUnknown GUID\n" ); break; } cursor = next; printf( "\n" ); } printf( "end parsing headers\n" ); }
/// \brief /// Helper function to read a float value inline BOOL ReadFloat(float &fVal) {return ReadDWord(&fVal)==sizeof(float);}
/// \brief /// Helper function to read an integer value inline BOOL ReadInt(int &iVal) {return ReadDWord(&iVal)==sizeof(int);}
void StdCompilerConfigRead::DWord(int32_t &rInt) { rInt = int32_t(ReadDWord()); }
void PrintGUID() { printf( "%04X-%02X-%02X-", ReadDWord(), ReadWord(), ReadWord() ); printf( "%02X%02X-", ReadByte(), ReadByte() ); printf( "%02X%02X%02X%02X%02X%02X\n", ReadByte(), ReadByte(), ReadByte(), ReadByte(), ReadByte(), ReadByte() ); }
uint64_t ReadQWord() { return ReadDWord() | (uint64_t)ReadDWord() << 32; }
/// \brief /// Helper function to read a BOOL (32bit) value inline BOOL ReadBOOL(BOOL &bVal) {return ReadDWord(&bVal)==sizeof(BOOL);}
void StdCompilerConfigRead::DWord(uint32_t &rInt) { rInt = ReadDWord(); }
void StdCompilerConfigRead::Byte(uint8_t &rInt) { rInt = uint8_t(ReadDWord()); }
void StdCompilerConfigRead::Word(uint16_t &rInt) { rInt = uint16_t(ReadDWord()); }
void ParseStreamProperties() { StreamType type = ReadStreamType(); printf( "\t\tStream type: " ); switch (type) { case StreamTypeAudio: printf( "Audio\n" ); break; case StreamTypeVideo: printf( "Video\n" ); break; default: printf( "Error, invalid\n" ); break; } ErrorCorrectionType ecType = ReadErrorCorrectionType(); printf( "\t\tEC type: " ); switch (ecType) { case ErrorCorrectionTypeNone: printf( "None\n" ); break; case ErrorCorrectionTypeAudioSpread: printf( "Audio spread\n" ); break; } uint64_t timeOffset = ReadQWord(); printf( "\t\tTime offset: %llu\n", timeOffset ); size_t specificLength = ReadDWord(); printf( "\t\tSpecific data length: %zu\n", specificLength ); size_t ecDataLength = ReadDWord(); printf( "\t\tEC data length: %zu\n", ecDataLength ); uint16_t flags = ReadWord(); cursor += 4; // Skip reserved uint8_t streamNumber = flags & (BIT( 0 ) | BIT( 1 ) | BIT( 2 ) | BIT( 3 ) | BIT( 4 ) | BIT( 5 ) | BIT( 6 ) | BIT( 7 )); printf( "\t\tStream number: %u\n", streamNumber ); bool encrypted = (flags & BIT( 15 )) != 0; printf( "\t\tEncrypted: %s\n", encrypted ? "yes" : "no" ); if (streamNumber > streamCount) { printf( "\t\tGrowing stream count from %zu to %d\n", streamCount, streamNumber ); streamCount = streamNumber; streams = realloc( streams, streamCount * sizeof (Stream) ); } streams[streamNumber - 1].type = type; streams[streamNumber - 1].ecType = ecType; streams[streamNumber - 1].specificDataLength = specificLength; streams[streamNumber - 1].ecDataLength = ecDataLength; streams[streamNumber - 1].specificData = cursor; streams[streamNumber - 1].ecData = cursor + specificLength; streams[streamNumber - 1].timeOffset = timeOffset; streams[streamNumber - 1].encrypted = encrypted; switch (type) { case StreamTypeAudio: DumpAudioInfo( streams[streamNumber - 1].audioInfo ); break; case StreamTypeVideo: DumpVideoInfo( streams[streamNumber - 1].videoInfo ); break; default: break; } }