Properly detect case where deviceList was populated with garbage data

Assume the device list is valid if it has a valid device that matches the path of the app
This commit is contained in:
Edoardo Lolletti 2024-04-27 23:31:07 +02:00
parent 593141e702
commit bfdd89218d

View File

@ -4,6 +4,8 @@
#define DEVICE_LIST_SENTINEL *(vu32*)0x02300020 #define DEVICE_LIST_SENTINEL *(vu32*)0x02300020
#define DEVICE_LIST_ADDR (vu8*)0x02300024 #define DEVICE_LIST_ADDR (vu8*)0x02300024
static u8 gotDeviceList = 0;
size_t getDeviceNameLenFromAppName(const char (appname)[0x40]) size_t getDeviceNameLenFromAppName(const char (appname)[0x40])
{ {
for(int i = 0; i < 0x40; ++i) for(int i = 0; i < 0x40; ++i)
@ -18,8 +20,8 @@ size_t getDeviceNameLenFromAppName(const char (appname)[0x40])
DeviceList* getDeviceList(void) DeviceList* getDeviceList(void)
{ {
static bool gotDeviceList = false;
if(!gotDeviceList) { if(!gotDeviceList) {
gotDeviceList = 1;
while(!DEVICE_LIST_SENTINEL); while(!DEVICE_LIST_SENTINEL);
DeviceList* list = (DeviceList*)DEVICE_LIST_ADDR; DeviceList* list = (DeviceList*)DEVICE_LIST_ADDR;
@ -29,18 +31,14 @@ DeviceList* getDeviceList(void)
{ {
return 0; return 0;
} }
bool isSd = false;
for(int i = 0; i < 11; ++i) for(int i = 0; i < 11; ++i)
{ {
Device* device = &list->devices[i]; Device* device = &list->devices[i];
if(device->deviceName[deviceNameLen] == '\0' && strncmp(device->deviceName, list->appname, deviceNameLen) == 0) if(device->deviceName[deviceNameLen] == '\0' && strncmp(device->deviceName, list->appname, deviceNameLen) == 0)
{ {
isSd = device->phisicalDrive == 0; gotDeviceList = 2;
break; bool isSd = device->phisicalDrive == 0;
}
}
if(isSd) if(isSd)
{ {
//transform the root path to sd:/ (can be sdmc:/, nand:/, nand2:/, etc) //transform the root path to sd:/ (can be sdmc:/, nand:/, nand2:/, etc)
@ -49,8 +47,13 @@ DeviceList* getDeviceList(void)
list->appname[1] = 'd'; list->appname[1] = 'd';
memset(list->appname + (sizeof(list->appname) - deviceNameLen + 2), 0, deviceNameLen - 2); memset(list->appname + (sizeof(list->appname) - deviceNameLen + 2), 0, deviceNameLen - 2);
} }
gotDeviceList = true; break;
} }
}
}
if(gotDeviceList == 1)
return 0;
return (DeviceList*)DEVICE_LIST_ADDR; return (DeviceList*)DEVICE_LIST_ADDR;
} }