diff --git a/tools/readrpl/main.cpp b/tools/readrpl/main.cpp index 2741dfb9..5d61a5dd 100644 --- a/tools/readrpl/main.cpp +++ b/tools/readrpl/main.cpp @@ -458,6 +458,45 @@ printRplImports(std::vector
§ions, } } +static void +checkRplCrcs(std::vector
§ions) +{ + elf::RplCrc *crcs = NULL; + auto crcSectionIndex = 0u; + + for (auto i = 0u; i < sections.size(); ++i) { + auto §ion = sections[i]; + if (section.header.type == elf::SHT_RPL_CRCS) { + crcs = reinterpret_cast(section.data.data()); + crcSectionIndex = i; + break; + } + } + + if (!crcs) { + return; + } + + for (auto i = 0u; i < sections.size(); ++i) { + auto §ion = sections[i]; + auto crc = uint32_t { 0u }; + + if (i == crcSectionIndex) { + continue; + } + + if (section.data.size()) { + crc = crc32(0, Z_NULL, 0); + crc = crc32(crc, reinterpret_cast(section.data.data()), section.data.size()); + } + + if (crc != crcs[i].crc) { + fmt::print("Unexpected crc for section {}, read 0x{:08X} but calculated 0x{:08X}", + i, crcs[i].crc, crc); + } + } +} + static void printRplCrcs(std::vector
§ions, const char *shStrTab, @@ -662,6 +701,8 @@ int main(int argc, char **argv) printSectionSummary(sections, shStrTab); } + checkRplCrcs(sections); + // Print section data for (auto i = 0u; i < sections.size(); ++i) { auto §ion = sections[i];