u8 loadFirm() { sdmmc_storage_t storage; sdmmc_t sdmmc; //Init nand sdmmc_storage_init_mmc(&storage, &sdmmc, SDMMC_4, SDMMC_BUS_WIDTH_8, 4); sdmmc_storage_set_mmc_partition(&storage, 1); // Read package1. u8 *package1 = ReadPackage1(&storage); // Setup firmware specific data. pk11Offs = pkg11_offsentify(package1); u8 *keyblob = (u8 *)malloc(NX_EMMC_BLOCKSIZE); sdmmc_storage_read(&storage, 0x180000 / NX_EMMC_BLOCKSIZE + pk11Offs->kb, 1, keyblob); keygen(keyblob, pk11Offs->kb, package1 + pk11Offs->tsec_off); free(keyblob); // Decrypt package1 and setup warmboot. print("Decrypting Package1...\n"); u8 *pkg11 = package1 + pk11Offs->pkg11_off; u32 pkg11_size = *(u32 *)pkg11; se_aes_crypt_ctr(11, pkg11 + 0x20, pkg11_size, pkg11 + 0x20, pkg11_size, pkg11 + 0x10); pkg1_unpack(pk11Offs, package1); PMC(APBDEV_PMC_SCRATCH1) = pk11Offs->warmboot_base; free(package1); //Read package2 u8 *pkg2 = ReadPackage2(&storage); // Unpack Package2. print("Unpacking package2...\n"); pkg2_hdr_t *dec_pkg2 = unpackFirmwarePackage(pkg2); LIST_INIT(kip1_info); pkg2_parse_kips(&kip1_info, dec_pkg2); // Patch firmware. print("Patching OS...\n"); patch(pk11Offs, dec_pkg2, &kip1_info); // Load all KIPs. char **sysmods = NULL; size_t cnt = enumerateDir(&sysmods, "/ReiNX/sysmodules", "*.kip"); for (u32 i = 0; i < cnt ; i++) { print("%kLoading %s\n%k", YELLOW, sysmods[i], DEFAULT_TEXT_COL); loadKip(&kip1_info, sysmods[i]); free(sysmods[i]); } free(sysmods); // Build Package2. buildFirmwarePackage(dec_pkg2->data, dec_pkg2->sec_size[PKG2_SEC_KERNEL], &kip1_info); }
// these functions open all .ZIP files that they can find in // a specific directory. // they require support in the form of a function: enumerateDir(), // which is declared at the top of this file. int zppZipArchive::openAll(const std::string &_path) { std::list<std::string> *fileList = enumerateDir(_path,true); std::list<std::string>::iterator i; int count = 0; if (fileList == NULL) return 0; for (i = fileList->begin(); i != fileList->end(); i++ ) { zppZipArchive *zip; // open zip as std::ios::in, and global. zip = new zppZipArchive(*i); if (zip) { // got it... add it to our list. filesWeOpened.push_back(zip); count++; } } delete fileList; return count; }