Tabulation fix + potential misaligned read fix

This commit is contained in:
Nemoumbra 2024-08-11 20:20:07 +03:00
parent 169736dff6
commit b794532a8e
2 changed files with 13 additions and 11 deletions

View file

@ -1219,8 +1219,9 @@ static void parsePrxLibInfo(const u8* ptr, u32 headerSize) {
// The lib info prefix looks like {'\', 'y', 'r', '=', '`', 'c', '`', '0'} (Big Endian) // The lib info prefix looks like {'\', 'y', 'r', '=', '`', 'c', '`', '0'} (Big Endian)
const u64_le lib_info_prefix = 0x306063603D72795C; const u64_le lib_info_prefix = 0x306063603D72795C;
auto lib_info_ptr = reinterpret_cast<const u64_le*>(ptr);
if (*lib_info_ptr != lib_info_prefix) { // 'ptr' can potentially be misaligned here so let's use a memcmp instead of dereferencing 8 bytes at 'ptr'
if (memcmp(ptr, &lib_info_prefix, 8) != 0) {
// That's very wrong! // That's very wrong!
WARN_LOG(Log::sceModule, "~SCE module, unexpected header (not an error)"); WARN_LOG(Log::sceModule, "~SCE module, unexpected header (not an error)");
return; return;
@ -1236,13 +1237,14 @@ static void parsePrxLibInfo(const u8* ptr, u32 headerSize) {
} }
nameBuffer[12] = '\0'; nameBuffer[12] = '\0';
u8 versionBuffer[8] = "?.?.?.?"; u8 versionBuffer[7 + 1] = "?.?.?.?";
for (int i = 0; i < 4; ++i, ++ptr) { for (int i = 0; i < 4; ++i, ++ptr) {
u8 symbol = *ptr - 0x14u; u8 symbol = *ptr - 0x14u;
if (isprint(symbol)) { if (isprint(symbol)) {
versionBuffer[2 * i] = symbol; versionBuffer[2 * i] = symbol;
} }
} }
// The null byte is already in its place, no need to assign it manually
INFO_LOG(Log::sceModule, "~SCE module: Lib-PSP %s (SDK %s)", nameBuffer, versionBuffer); INFO_LOG(Log::sceModule, "~SCE module: Lib-PSP %s (SDK %s)", nameBuffer, versionBuffer);
} }