mirror of
https://github.com/Scandal-UK/Incognito_RCM.git
synced 2024-11-22 20:06:42 +00:00
read prodinfo partition and build hash blockwise
This commit is contained in:
parent
0cca558fe5
commit
5c0fdfd4b6
1 changed files with 71 additions and 79 deletions
|
@ -612,13 +612,11 @@ bool readData(u8* buffer, u32 offset, u32 length)
|
||||||
// EPRINTF("TOO BIG!!");
|
// EPRINTF("TOO BIG!!");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
//bool needMultipleSectors = newOffset + length > NX_EMMC_BLOCKSIZE;
|
//bool needMultipleSectors = newOffset + length > NX_EMMC_BLOCKSIZE;
|
||||||
|
|
||||||
u8 *tmp = (u8 *)malloc(sectorCount * NX_EMMC_BLOCKSIZE);
|
u8 *tmp = (u8 *)malloc(sectorCount * NX_EMMC_BLOCKSIZE);
|
||||||
disk_read_mod(tmp, sector, sectorCount, &storage, prodinfo_part);
|
disk_read_mod(tmp, sector, sectorCount, &storage, prodinfo_part);
|
||||||
|
|
||||||
|
|
||||||
// if (!needMultipleSectors)
|
// if (!needMultipleSectors)
|
||||||
// {
|
// {
|
||||||
// gfx_hexdump(0, tmp + newOffset, length);
|
// gfx_hexdump(0, tmp + newOffset, length);
|
||||||
|
@ -632,44 +630,42 @@ bool readData(u8* buffer, u32 offset, u32 length)
|
||||||
// memcpy(buffer + newLength, tmp, length - newLength);
|
// memcpy(buffer + newLength, tmp, length - newLength);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
|
||||||
free(tmp);
|
free(tmp);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool verifyHash(u32 hashOffset, u32 offset, u32 sz)
|
||||||
bool verifyHash(u64 hashOffset, u64 offset, u64 sz)
|
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
u8* buffer = (u8 *)malloc(sz);//new u8[sz];
|
u8 *buffer = (u8 *)malloc(NX_EMMC_BLOCKSIZE);
|
||||||
|
|
||||||
if (!readData(buffer, offset, sz))
|
|
||||||
{
|
|
||||||
EPRINTF("error: failed reading calibration data\n");
|
|
||||||
//printf("error: failed reading calibration data\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
u8 hash1[0x20];
|
|
||||||
u8 hash2[0x20];
|
|
||||||
|
|
||||||
SHA256_CTX ctx;
|
SHA256_CTX ctx;
|
||||||
sha256_init(&ctx);
|
sha256_init(&ctx);
|
||||||
|
|
||||||
|
while (sz > NX_EMMC_BLOCKSIZE)
|
||||||
|
{
|
||||||
|
|
||||||
|
readData(buffer, offset, NX_EMMC_BLOCKSIZE);
|
||||||
|
sha256_update(&ctx, buffer, NX_EMMC_BLOCKSIZE);
|
||||||
|
|
||||||
|
sz -= NX_EMMC_BLOCKSIZE;
|
||||||
|
offset += NX_EMMC_BLOCKSIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
readData(buffer, offset, sz);
|
||||||
|
|
||||||
sha256_update(&ctx, buffer, sz);
|
sha256_update(&ctx, buffer, sz);
|
||||||
|
u8 *hash1 = (u8 *)malloc(0x20);
|
||||||
sha256_final(&ctx, hash1);
|
sha256_final(&ctx, hash1);
|
||||||
|
|
||||||
|
u8 *hash2 = (u8 *)malloc(0x20);
|
||||||
//se_calc_sha256(hash1, buffer, sz);
|
//se_calc_sha256(hash1, buffer, sz);
|
||||||
//sha256CalculateHash(hash1, buffer, sz);
|
//sha256CalculateHash(hash1, buffer, sz);
|
||||||
|
|
||||||
if (!readData(hash2, hashOffset, sizeof(hash2)))
|
readData(hash2, hashOffset, 0x20);
|
||||||
{
|
|
||||||
EPRINTF("error: failed reading hash\n");
|
if (memcmp(hash1, hash2, 0x20))
|
||||||
//printf("error: failed reading hash\n");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (memcmp(hash1, hash2, sizeof(hash1)))
|
|
||||||
{
|
{
|
||||||
EPRINTF("error: hash verification failed\n");
|
EPRINTF("error: hash verification failed\n");
|
||||||
//printf("error: hash verification failed for %x %d\n", (long)offset, (long)sz);
|
//printf("error: hash verification failed for %x %d\n", (long)offset, (long)sz);
|
||||||
|
@ -681,25 +677,24 @@ bool readData(u8* buffer, u32 offset, u32 length)
|
||||||
{
|
{
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
gfx_hexdump(0, hash1, 0x08);
|
gfx_hexdump(0, hash1, 0x08);
|
||||||
gfx_hexdump(0, hash2, 0x08);
|
gfx_hexdump(0, hash2, 0x08);
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
free(hash1);
|
||||||
|
free(hash2);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
u32 certSize()
|
u32 certSize()
|
||||||
{
|
{
|
||||||
u32 buffer;
|
u32 buffer;
|
||||||
readData((u8 *)&buffer, 0x0AD0, sizeof(buffer));
|
readData((u8 *)&buffer, 0x0AD0, sizeof(buffer));
|
||||||
EPRINTF("certSize");
|
EPRINTF("certSize");
|
||||||
gfx_hexdump(0, (u8 *)&buffer, sizeof(buffer));
|
gfx_hexdump(0, (u8 *)&buffer, sizeof(buffer));
|
||||||
|
buffer = _read_le_u32(&buffer, 0);
|
||||||
|
gfx_hexdump(0, (u8 *)&buffer, sizeof(buffer));
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -709,6 +704,8 @@ bool readData(u8* buffer, u32 offset, u32 length)
|
||||||
readData((u8 *)&buffer, 0x08, sizeof(buffer));
|
readData((u8 *)&buffer, 0x08, sizeof(buffer));
|
||||||
EPRINTF("calSize");
|
EPRINTF("calSize");
|
||||||
gfx_hexdump(0, (u8 *)&buffer, sizeof(buffer));
|
gfx_hexdump(0, (u8 *)&buffer, sizeof(buffer));
|
||||||
|
buffer = _read_le_u32(&buffer, 0);
|
||||||
|
gfx_hexdump(0, (u8 *)&buffer, sizeof(buffer));
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -719,8 +716,3 @@ bool readData(u8* buffer, u32 offset, u32 length)
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
// u32 calibrationDataSize()
|
|
||||||
// {
|
|
||||||
// return read<u32>(0x08);
|
|
||||||
// }
|
|
Loading…
Reference in a new issue