Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void TitleKeyWnd::dump()
- {
- DzWnd* dz = DzWnd::instance();
- if (!dz)
- {
- return;
- }
- dz->drawLoadingScreen(string(translate().get("Dumping prodinfo")), 0, 1);
- dumpProdInfo();
- RsaKeyPair kp = keys().getRsaKeypair();
- dz->drawLoadingScreen(string(translate().get("Dumping ticket databases")), 0, 1);
- items().resize(0);
- Fat32<::File> f;
- if (f.open("system:/", ::File::Mode::R))
- {
- u64 ticketsFound = 0;
- auto ticketScanner = [&ticketsFound, &kp, this](Buffer<u8>& buffer, u32 cluster)
- {
- for (u64 i = 0; i < buffer.size(); i += 0x100)
- {
- if (buffer[i] == 0x04 && buffer[i + 1] == 0x00 && buffer[i + 2] == 0x01 && buffer[i + 3] == 0x00)
- {
- const TicketHeader* header = reinterpret_cast<const TicketHeader*>(buffer.buffer(i));
- const TicketData* data = reinterpret_cast<const TicketData*>(buffer.buffer(i + sizeof(TicketHeader) - 0x200 + header->signatureSize() + header->padding()));
- integer<128> key;
- DzWnd::instance()->drawLoadingScreen(string(translate().get("Processing tickets")), ticketsFound % 100, 100);
- if (data->titleKeyType == 1) // personal ticket
- {
- mbedtls_rsa_context ctx;
- mbedtls_rsa_init(&ctx, MBEDTLS_RSA_PKCS_V15, MBEDTLS_MD_SHA256);
- mbedtls_mpi_read_binary(&ctx.E, (const u8*)&kp.D, sizeof(kp.D));
- mbedtls_mpi_read_binary(&ctx.N, (const u8*)&kp.N, sizeof(kp.N));
- mbedtls_mpi_read_binary(&ctx.D, (const u8*)&kp.D, sizeof(kp.D));
- ctx.len = sizeof(kp.D);
- size_t len;
- Buffer<u8> result;
- result.resize(0x200);
- integer<256> label("E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855");
- if (!mbedtls_rsa_rsaes_oaep_decrypt(&ctx, NULL, NULL, MBEDTLS_RSA_PUBLIC, (const u8*)&label, sizeof(label), &len, (const u8*)&data->titleKeyBlock, result.buffer(), 0x200))
- {
- key = *reinterpret_cast<integer<128>*>(result.buffer());
- }
- else
- {
- continue;
- }
- }
- else
- {
- key = reinterpret_cast<const integer<128>&>(data->titleKeyBlock);
- }
- items().push(Row::TitleKey(data->rightsId, key));
- ticketsFound++;
- }
- }
- return true;
- };
- f.readChain("/save/80000000000000e1", ticketScanner);
- f.readChain("/save/80000000000000e2", ticketScanner);
- f.close();
- exportKeys();
- }
- else
- {
- error("Faile dto open system partition\n");
- }
- }
Add Comment
Please, Sign In to add comment