| 2486 | } |
| 2487 | |
| 2488 | RDResult RenderDoc::ReadExternalFiles(RDCFile *rdc) |
| 2489 | { |
| 2490 | int32_t idx = rdc->SectionIndex(SectionType::EmbeddedExternalFiles); |
| 2491 | if(idx < 0) |
| 2492 | RETURN_WARNING_RESULT(ResultCode::DataNotAvailable, "No EmbeddedExternalFiles section"); |
| 2493 | |
| 2494 | // int32_t countFileEntries; |
| 2495 | int32_t countFileEntries = 0; |
| 2496 | bytebuf sectionData; |
| 2497 | { |
| 2498 | StreamReader *reader = rdc->ReadSection(idx); |
| 2499 | sectionData.resize((size_t)reader->GetSize()); |
| 2500 | bool success = reader->Read(sectionData.data(), reader->GetSize()); |
| 2501 | delete reader; |
| 2502 | if(!success) |
| 2503 | sectionData.clear(); |
| 2504 | } |
| 2505 | const uint32_t bufferSize = (uint32_t)sectionData.size(); |
| 2506 | uint32_t readSize = sizeof(countFileEntries); |
| 2507 | uint32_t byteIndex = 0; |
| 2508 | if(byteIndex + readSize > bufferSize) |
| 2509 | RETURN_WARNING_RESULT(ResultCode::FileCorrupted, |
| 2510 | "EmbeddedExternalFiles section does not have valid data"); |
| 2511 | |
| 2512 | const byte *bufferPtr = sectionData.data(); |
| 2513 | memcpy(&countFileEntries, bufferPtr, readSize); |
| 2514 | byteIndex += readSize; |
| 2515 | bufferPtr += readSize; |
| 2516 | |
| 2517 | rdcarray<TrackedFile> externalFiles; |
| 2518 | externalFiles.resize(countFileEntries); |
| 2519 | // FileEntry fileEntries[]; |
| 2520 | for(int32_t i = 0; i < countFileEntries; ++i) |
| 2521 | { |
| 2522 | TrackedFile &externalFile = externalFiles[i]; |
| 2523 | externalFile.filepath.clear(); |
| 2524 | |
| 2525 | // FileEntry: |
| 2526 | // uint32_t nameSize; |
| 2527 | uint32_t nameSize = 0; |
| 2528 | readSize = sizeof(nameSize); |
| 2529 | if(byteIndex + readSize > bufferSize) |
| 2530 | RETURN_WARNING_RESULT(ResultCode::FileCorrupted, |
| 2531 | "EmbeddedExternalFiles section does not have valid data"); |
| 2532 | memcpy(&nameSize, bufferPtr, readSize); |
| 2533 | byteIndex += readSize; |
| 2534 | bufferPtr += readSize; |
| 2535 | |
| 2536 | // char name[]; |
| 2537 | readSize = nameSize; |
| 2538 | if(byteIndex + readSize > bufferSize) |
| 2539 | RETURN_WARNING_RESULT(ResultCode::FileCorrupted, |
| 2540 | "EmbeddedExternalFiles section does not have valid data"); |
| 2541 | externalFile.nickname.assign((const char *)bufferPtr, readSize); |
| 2542 | byteIndex += readSize; |
| 2543 | bufferPtr += readSize; |
| 2544 | |
| 2545 | // uint32_t dataSize; |
no test coverage detected