From 51f6cedbd812b88f3b1e85e3db2ffedadd3da1ff Mon Sep 17 00:00:00 2001 From: GaryOderNichts <12049776+GaryOderNichts@users.noreply.github.com> Date: Fri, 2 Sep 2022 17:52:29 +0200 Subject: [PATCH] Display CID and CSD --- README.md | 1 + main.c | 43 +++++++++++++++++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index bc5b047..073b4ad 100644 --- a/README.md +++ b/README.md @@ -10,3 +10,4 @@ Can be used to figure out what eMMC chip is built into a console. -> Shows known name and type for that ID * Product Revision * Product Name +* CID and CSD diff --git a/main.c b/main.c index 43e2955..5fe6978 100644 --- a/main.c +++ b/main.c @@ -22,14 +22,32 @@ struct MDBlkDriver { int32_t registered; int32_t unk[2]; struct SALDeviceParams params; - uint8_t unk2[204]; + int sal_handle; + int deviceId; + uint8_t unk2[196]; }; static_assert(sizeof(struct MDBlkDriver) == 724, "MDBlkDriver: wrong size"); #define MDBLK_DRIVER_ADDRESS 0x11c39e78 +#define MD_DEVICE_POINTERS_ADDRESS 0x10899308 struct MDBlkDriver blkDrivers[2] = { 0 }; +static uint32_t getDeviceAddressByID(int id) +{ + if (id - 0x42 >= 8) { + return 0; + } + + uint32_t devicePointers[8]; + if (IOSUHAX_kern_read32(MD_DEVICE_POINTERS_ADDRESS, devicePointers, 8) < 0) { + return 0; + } + + // virtual matches physical address for IOS-FS, no need to conversion + return devicePointers[id - 0x42]; +} + int main(int argc, char const *argv[]) { WHBProcInit(); @@ -40,7 +58,7 @@ int main(int argc, char const *argv[]) if (IOSUHAX_kern_read32(MDBLK_DRIVER_ADDRESS, (uint32_t *) blkDrivers, sizeof(blkDrivers) / 4) >= 0) { for (int i = 0; i < 2; ++i) { struct MDBlkDriver *drv = &blkDrivers[i]; - WHBLogPrintf("** Instance %d: (%s) **", i + 1, drv->registered ? "Attached" : "Detached"); + WHBLogPrintf("** Instance %d: (%s) Type: %d **", i + 1, drv->registered ? "Attached" : "Detached", drv->params.device_type); if (drv->registered) { uint16_t mid = drv->params.mid_prv >> 16; uint16_t prv = drv->params.mid_prv & 0xff; @@ -50,11 +68,24 @@ int main(int argc, char const *argv[]) WHBLogPrintf(" -> Manufacturer: '%s' Type: '%s'", db->manufacturer, db->type); WHBLogPrintf("Name 0: '%s' Name 1: '%s' Name 2: '%s'", drv->params.name0, drv->params.name1, drv->params.name2); - /* - for (int j = 0; j < 4; ++j) { - WHBLogPrintf("Unk %d: %08x %08x %08x %08x", j, drv->params.unk[j * 4 + 0], drv->params.unk[j * 4 + 1], drv->params.unk[j * 4 + 2], drv->params.unk[j * 4 + 3]); + uint32_t deviceAddress = getDeviceAddressByID(drv->deviceId); + if (!deviceAddress) { + continue; } - */ + + uint32_t cid[4]; + if (IOSUHAX_kern_read32(deviceAddress + 0x58, cid, 4) < 0) { + continue; + } + + WHBLogPrintf("CID: %08x%08x%08x%08x", cid[0], cid[1], cid[2], cid[3]); + + uint32_t csd[4]; + if (IOSUHAX_kern_read32(deviceAddress + 0x68, csd, 4) < 0) { + continue; + } + + WHBLogPrintf("CSD: %08x%08x%08x%08x", csd[0], csd[1], csd[2], csd[3]); } WHBLogPrintf("=================================================");