u32 GetNandCtr(u8* ctr, u32 offset)
{
int ctr_offset=0;
u8 temp[16]={0};
static const char* versions[] = {"4.x", "5.0","5.1","6.x", "7.x", "8.x", "9.x"};
static const u8* version_ctrs[] = {
(u8*)0x080D7CAC, //4.x
(u8*)0x080D866C, //5.0
(u8*)0x080D858C, //5.1
(u8*)0x080D748C, //6.x
(u8*)0x080D740C, //7.x
(u8*)0x080D74CC, //8.x
(u8*)0x080D794C //9.x
};
if (offset >= 0x0B100000){
ctr_offset=0x30; //ctr
}
else{
ctr_offset=0xB8; //twl
}
static const u32 version_ctrs_len = sizeof(version_ctrs) / sizeof(u32);
for (u32 i = 0; i < version_ctrs_len; i++) {
if (*(u32*)version_ctrs[i] == 0x5C980) {
memcpy(temp,(u8*)(version_ctrs[i] + ctr_offset),16);
goto finish;
}
}
// If value not in previous list start memory scanning (test range)
for (u8* c = (u8*)0x080D8FFF; c > (u8*)0x08000000; c--) {
if (*(u32*)c == 0x5C980 && *(u32*)(c + 1) == 0x800005C9) {
memcpy(temp,(u8*)(c + ctr_offset),16);
goto finish;
}
}
finish:
for(u32 i = 0; i < 16; i++) ctr[i] = temp[15-i];
add_ctr(ctr, offset / 0x10);
return 0;
}