Exemplo n.º 1
0
int patch_options(void *address, uint32_t size, uint8_t options, enum types type)
{
    if (options & patch_option_keyx) {
        print("Patch option: Adding keyX");

        if (read_file(fcram_temp, PATH_SLOT0X25KEYX, AES_BLOCK_SIZE) != 0) {
            print("Failed to load keyX");
            draw_message("Failed to load keyX", "Make sure the keyX is\n  located at /slot0x25keyX.bin");
            return 1;
        }

        void *pos = memsearch(address, "slot0x25keyXhere", size, AES_BLOCK_SIZE);
        if (pos) {
            memcpy32(pos, fcram_temp, AES_BLOCK_SIZE);
        } else {
            print("I don't know where to add keyX.\n  Ignoring...");
        }
    }
    if (options & patch_option_emunand) {
        print("Patch option: Setting emuNAND offsets");

        uint32_t offset = 0;
        uint32_t header = 0;

        if (get_emunand_offsets(config->emunand_location, &offset, &header)) {
            print("Failed to get the emuNAND offsets");
            draw_message("Failed to get the emuNAND offsets",
                    "There's 3 possible causes for this error:\n"
                    " - You don't even have an emuNAND installed\n"
                    " - Your SD card can't be read\n"
                    " - You're using an unsupported emuNAND format");
            return 1;
        }

        uint32_t *pos_offset = memsearch(address, "NAND", size, 4);
        uint32_t *pos_header = memsearch(address, "NCSD", size, 4);
        if (pos_offset && pos_header) {
            *pos_offset = offset;
            *pos_header = header;
        } else {
            print("I don't know where to set the offsets.\n"
                  "  Ignoring...");
        }
    }
    if (options & patch_option_save && type == NATIVE_FIRM) {
        print("Patch option: Save firm");

        save_firm = 1;

        // This absolutely requires the -fshort-wchar option to be enabled.
        char *offset = address + size;
        memcpy(offset, L"sdmc:", 10);
        memcpy(offset + 10, L"" PATH_PATCHED_FIRMWARE, sizeof(PATH_PATCHED_FIRMWARE) * 2);
    }

    return 0;
}
Exemplo n.º 2
0
void menu_emunand()
{
    char emunands[MAX_OPTIONS][0x20];  // We have a max size for the strings...
    char unnamed[] = "emuNAND #";

    uint32_t gap;
    if (getMMCDevice(0)->total_size > 0x200000) {
        gap = 0x400000;
    } else {
        gap = 0x200000;
    }

    // Scan for available emuNANDS. Assume they're placed right behind eachother.
    int count;
    for (count = 0; count <= MAX_OPTIONS; count++) {
        if (get_emunand_offsets(count * gap, NULL, NULL) == 0) {
            if (sdmmc_sdcard_readsectors(count * gap, 1, fcram_temp) == 0 &&
                    memcmp(fcram_temp + 11, "NAME", 4) == 0) {
                memcpy(emunands[count], fcram_temp + 15, 0x1F);
                emunands[count][0x1F] = 0;
            } else {
                memcpy(emunands[count], unnamed, sizeof(unnamed));
                emunands[count][sizeof(unnamed) - 1] = '1' + count;
                emunands[count][sizeof(unnamed)] = 0;
            }
            continue;
        }

        break;
    }

    if (count <= 0) {
        print("Failed to find any emuNAND");
        draw_message("Failed to find any emuNAND",
                "There's 3 possible causes for this error:\n"
                " - You don't even have an emuNAND installed\n"
                " - Your SD card can't be read\n"
                " - You're using an unsupported emuNAND format");
        return;
    }

    // Make the pointer array
    char *options[count];
    for (int x = 0; x <= count; x++) options[x] = emunands[x];

    int result = draw_menu("Select emuNAND", 1, count, options);
    if (result == -1) return;

    config->emunand_location = result * gap;
    patches_modified = 1;
}