move some shit around

This commit is contained in:
Arisotura
2021-08-21 16:49:44 +02:00
parent b49d75d1bb
commit 9993dbdd55
4 changed files with 216 additions and 147 deletions

View File

@ -349,6 +349,12 @@ bool LoadNAND()
{
printf("Loading DSi NAND\n");
if (!DSi_NAND::Init(SDMMCFile, &DSi::ARM7iBIOS[0x8308]))
{
printf("Failed to load DSi NAND\n");
return false;
}
// Make sure NWRAM is accessible.
// The Bits are set to the startup values in Reset() and we might
// still have them on default (0) or some bits cleared by the previous
@ -368,8 +374,6 @@ bool LoadNAND()
memset(NWRAMEnd, 0, sizeof(NWRAMEnd));
memset(NWRAMMask, 0, sizeof(NWRAMMask));
if (SDMMCFile)
{
u32 bootparams[8];
fseek(SDMMCFile, 0x220, SEEK_SET);
fread(bootparams, 4, 8, SDMMCFile);
@ -490,33 +494,10 @@ bool LoadNAND()
#define printhex(str, size) { for (int z = 0; z < (size); z++) printf("%02X", (str)[z]); printf("\n"); }
#define printhex_rev(str, size) { for (int z = (size)-1; z >= 0; z--) printf("%02X", (str)[z]); printf("\n"); }
// read the nocash footer
fseek(SDMMCFile, -0x40, SEEK_END);
char nand_footer[16];
const char* nand_footer_ref = "DSi eMMC CID/CPU";
fread(nand_footer, 1, 16, SDMMCFile);
if (memcmp(nand_footer, nand_footer_ref, 16))
{
// There is another copy of the footer at 000FF800h for the case
// that by external tools the image was cut off
// See https://problemkaputt.de/gbatek.htm#dsisdmmcimages
fseek(SDMMCFile, 0x000FF800, SEEK_SET);
fread(nand_footer, 1, 16, SDMMCFile);
if (memcmp(nand_footer, nand_footer_ref, 16))
{
printf("ERROR: NAND missing nocash footer\n");
return false;
}
}
fread(eMMC_CID, 1, 16, SDMMCFile);
fread(&ConsoleID, 1, 8, SDMMCFile);
DSi_NAND::GetIDs(eMMC_CID, ConsoleID);
printf("eMMC CID: "); printhex(eMMC_CID, 16);
printf("Console ID: %" PRIx64 "\n", ConsoleID);
}
memset(ITCMInit, 0, 0x8000);
memcpy(&ITCMInit[0x4400], &ARM9iBIOS[0x87F4], 0x400);
@ -530,10 +511,9 @@ bool LoadNAND()
memcpy(&ARM7Init[0x0254], &ARM7iBIOS[0xC6D0], 0x1048);
memcpy(&ARM7Init[0x129C], &ARM7iBIOS[0xD718], 0x1048);
DSi_NAND::Init();
DSi_NAND::PatchTSC();
DSi_NAND::ImportTest();
DSi_NAND::DeInit();
return true;
}

View File

@ -31,14 +31,46 @@
namespace DSi_NAND
{
FILE* CurFile;
u8 eMMC_CID[16];
u64 ConsoleID;
u8 FATIV[16];
u8 FATKey[16];
u8 ESKey[16];
void Init()
bool Init(FILE* nandfile, u8* es_keyY)
{
if (!nandfile)
return false;
// read the nocash footer
fseek(nandfile, -0x40, SEEK_END);
char nand_footer[16];
const char* nand_footer_ref = "DSi eMMC CID/CPU";
fread(nand_footer, 1, 16, nandfile);
if (memcmp(nand_footer, nand_footer_ref, 16))
{
// There is another copy of the footer at 000FF800h for the case
// that by external tools the image was cut off
// See https://problemkaputt.de/gbatek.htm#dsisdmmcimages
fseek(nandfile, 0x000FF800, SEEK_SET);
fread(nand_footer, 1, 16, nandfile);
if (memcmp(nand_footer, nand_footer_ref, 16))
{
printf("ERROR: NAND missing nocash footer\n");
return false;
}
}
fread(eMMC_CID, 1, 16, nandfile);
fread(&ConsoleID, 1, 8, nandfile);
// init NAND crypto
SHA1_CTX sha;
@ -46,15 +78,15 @@ void Init()
u8 keyX[16], keyY[16];
SHA1Init(&sha);
SHA1Update(&sha, DSi::eMMC_CID, 16);
SHA1Update(&sha, eMMC_CID, 16);
SHA1Final(tmp, &sha);
DSi_AES::Swap16(FATIV, tmp);
*(u32*)&keyX[0] = (u32)DSi::ConsoleID;
*(u32*)&keyX[4] = (u32)DSi::ConsoleID ^ 0x24EE6906;
*(u32*)&keyX[8] = (u32)(DSi::ConsoleID >> 32) ^ 0xE65B601D;
*(u32*)&keyX[12] = (u32)(DSi::ConsoleID >> 32);
*(u32*)&keyX[0] = (u32)ConsoleID;
*(u32*)&keyX[4] = (u32)ConsoleID ^ 0x24EE6906;
*(u32*)&keyX[8] = (u32)(ConsoleID >> 32) ^ 0xE65B601D;
*(u32*)&keyX[12] = (u32)(ConsoleID >> 32);
*(u32*)&keyY[0] = 0x0AB9DC76;
*(u32*)&keyY[4] = 0xBD4DC4D3;
@ -67,13 +99,28 @@ void Init()
*(u32*)&keyX[0] = 0x4E00004A;
*(u32*)&keyX[4] = 0x4A00004E;
*(u32*)&keyX[8] = (u32)(DSi::ConsoleID >> 32) ^ 0xC80C4B72;
*(u32*)&keyX[12] = (u32)DSi::ConsoleID;
*(u32*)&keyX[8] = (u32)(ConsoleID >> 32) ^ 0xC80C4B72;
*(u32*)&keyX[12] = (u32)ConsoleID;
memcpy(keyY, &DSi::ARM7iBIOS[0x8308], 16);
memcpy(keyY, es_keyY, 16);
DSi_AES::DeriveNormalKey(keyX, keyY, tmp);
DSi_AES::Swap16(ESKey, tmp);
CurFile = nandfile;
return true;
}
void DeInit()
{
CurFile = nullptr;
}
void GetIDs(u8* emmc_cid, u64& consoleid)
{
memcpy(emmc_cid, eMMC_CID, 16);
consoleid = ConsoleID;
}

View File

@ -24,7 +24,10 @@
namespace DSi_NAND
{
void Init();
bool Init(FILE* nand, u8* es_keyY);
void DeInit();
void GetIDs(u8* emmc_cid, u64& consoleid);
void PatchTSC();

View File

@ -36,7 +36,46 @@ TitleManagerDialog::TitleManagerDialog(QWidget* parent) : QDialog(parent), ui(ne
ui->setupUi(this);
setAttribute(Qt::WA_DeleteOnClose);
//
//ui->lstTitleList->setViewMode(QListView::IconMode);
//ui->lstTitleList->setFlow(QListView::LeftToRight);
ui->lstTitleList->setIconSize(QSize(32, 32));
{
QPixmap boobs(32, 32);
boobs.fill(Qt::blue);
QIcon piss(boobs);
QListWidgetItem* derp = new QListWidgetItem("完全放棄宣言\nナナヲアカリ");
derp->setIcon(piss);
ui->lstTitleList->addItem(derp);
}
{
QPixmap boobs(32, 32);
boobs.fill(Qt::red);
QIcon piss(boobs);
QListWidgetItem* derp = new QListWidgetItem("death to\ncapitalism");
derp->setIcon(piss);
ui->lstTitleList->addItem(derp);
}
{
QPixmap boobs(32, 32);
boobs.fill(Qt::green);
QIcon piss(boobs);
QListWidgetItem* derp = new QListWidgetItem("piles of\ncontent");
derp->setIcon(piss);
ui->lstTitleList->addItem(derp);
}
{
QPixmap boobs(32, 32);
boobs.fill(Qt::yellow);
QIcon piss(boobs);
QListWidgetItem* derp = new QListWidgetItem("trans\nrights");
derp->setIcon(piss);
ui->lstTitleList->addItem(derp);
}
}
TitleManagerDialog::~TitleManagerDialog()