diff --git a/source/incognito/incognito.c b/source/incognito/incognito.c index 3f7b6ef..5990d6f 100644 --- a/source/incognito/incognito.c +++ b/source/incognito/incognito.c @@ -376,22 +376,29 @@ bool writeSerial() } const u32 serialOffset = 0x250; - const u32 serialBlockSize = 0x1E; - if (!writeData((u8 *)junkSerial, serialOffset, 14, NULL)) return false; // write crc at end of serial-number block - char serial[31] = ""; - readData((u8 *)serial, serialOffset, serialBlockSize, NULL); - - const char *serialBytes = serial; - u16 crcValue = get_crc_16(serialBytes, serialBlockSize); - u8 crc[2] = { crcValue & 0xff, crcValue >> 8 }; // bytes of u16 - - return writeData(crc, serialOffset + serialBlockSize, 2, NULL); + return writeCrc(serialOffset, 0x1E); } +bool writeCrc(u32 offset, u32 size) +{ + char buffer[size + 1]; + if (!readData((u8 *)buffer, offset, size, NULL)) + return false; + + const char *bytes = buffer; + free(buffer); + u16 crcValue = get_crc_16(bytes, size); + u8 crc[2] = { crcValue & 0xff, crcValue >> 8 }; // bytes of u16 + + return writeData(crc, offset + size, 2, NULL); +} + +// todo: write a method to add a crc! +// todo: include crc block in sizes bool incognito() { gfx_printf("%kChecking if backup exists...\n", COLOR_YELLOW); diff --git a/source/incognito/io/io.c b/source/incognito/io/io.c index 0d7cf3d..818a731 100644 --- a/source/incognito/io/io.c +++ b/source/incognito/io/io.c @@ -77,6 +77,14 @@ out:; return res; } +// replacement for nx_emmc_part_write in storage/nx_emmc, which uses sdmmc_storage_write +int nx_emummc_part_write(sdmmc_storage_t *storage, emmc_part_t *part, u32 sector_off, u32 num_sectors, void *buf) +{ + // The last LBA is inclusive. + if (part->lba_start + sector_off > part->lba_end) + return 0; + return emummc_storage_write(storage, part->lba_start + sector_off, num_sectors, buf); +} bool prodinfo_read( u8 *buff, /* Data buffer to store read data */ @@ -157,12 +165,3 @@ bool prodinfo_write( return false; } - -// replacement for nx_emmc_part_write in storage/nx_emmc, which uses sdmmc_storage_write -int nx_emummc_part_write(sdmmc_storage_t *storage, emmc_part_t *part, u32 sector_off, u32 num_sectors, void *buf) -{ - // The last LBA is inclusive. - if (part->lba_start + sector_off > part->lba_end) - return 0; - return emummc_storage_write(storage, part->lba_start + sector_off, num_sectors, buf); -}