Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- int slotmagic() {
- return 0; // insert 7.X KEYX
- }
- // this is not super stable but works, just a few things to check
- // i won't release it by the way as i don't want more piracy
- // to be used with ninjhax for now
- int main(int argc, char *argv[]) {
- FILE *f;
- u8 *save_buf, *out_buf, *xorpad_buf = NULL;
- u8 zerobuf[0x10];
- unsigned int size=0, xorpad_size = 0x0;
- int i;
- int enable_wearlevel = 1, enable_xorpad = 1;
- int load_xorpad = 0;
- int fargc = 1, argi = 1;
- char **fargv;
- struct stat filestat;
- char xorpad_path[256];
- // overwriting firm
- f = fopen(argv[1], "rb");
- if(f == NULL) {
- fprintf(stderr, "error: failed to open %s\n", argv[1]);
- return -1;
- }
- fseek(f, 0, SEEK_END);
- size = ftell(f);
- fseek(f, 0, SEEK_SET);
- save_buf = malloc(size);
- out_buf = malloc(size);
- fread(save_buf, size, 1, f);
- fclose(f);
- memset(xorpad_path, 0, 256);
- for(i = 1; i < argc - 1; i++) {
- if(strncmp(argv[i + 1], "--", 2))fargc++;
- }
- fargv = (char **) malloc(fargc * sizeof(char *));
- fargv[0] = argv[0];
- for(i = 1; i < argc - 1; i++) {
- #ifdef DEBUG
- printf("arg: '%s'\n", argv[i + 1]);
- #endif
- if(strncmp(argv[i + 1], "--nowear", 8)==0) {
- enable_wearlevel = 0;
- }
- else if(strncmp(argv[i + 1], "--xorpad=", 9)==0) {
- load_xorpad = 1;
- strncpy(xorpad_path, &argv[i + 1][9], 255);
- }
- else {
- fargv[argi] = argv[i + 1];
- argi++;
- }
- }
- if(enable_wearlevel) {
- if(rearrange(save_buf, out_buf, size) != 0) {
- free(save_buf);
- free(out_buf);
- return -2;
- }
- else {
- size -= 0x2000;
- }
- }
- else {
- memcpy(out_buf, save_buf, size);
- }
- memset(zerobuf, 0, 0x10);
- if(memcmp(&out_buf[0x10], zerobuf, 0x10)==0)enable_xorpad = 0;
- f = fopen("rawimage.bin", "wb");
- fwrite(out_buf, 1, size, f);
- fclose(f);
- // patch rsa check
- if(enable_xorpad) {
- if(load_xorpad) {
- if(stat(xorpad_path, &filestat)==-1) {
- fprintf(stderr, "error: failed to stat %s\n", xorpad_path);
- free(save_buf);
- free(out_buf);
- return -1;
- }
- xorpad_size = (unsigned int)filestat.st_size;
- xorpad_buf = (u8*)malloc(xorpad_size);
- if(xorpad_buf==NULL) {
- fprintf(stderr, "error: failed to allocate xorpad buffer.\n");
- free(save_buf);
- free(out_buf);
- return -1;
- }
- memset(xorpad_buf, 0, xorpad_size);
- f = fopen(xorpad_path, "rb");
- fread(xorpad_buf, 1, xorpad_size, f);
- fclose(f);
- }
- else
- {
- xorpad_size = 0x200;
- xorpad_buf = (u8*)malloc(xorpad_size);
- if(xorpad_buf==NULL) {
- fprintf(stderr, "error: failed to allocate xorpad buffer.\n");
- free(save_buf);
- free(out_buf);
- return -1;
- }
- memset(xorpad_buf, 0, xorpad_size);
- if(find_key(out_buf, size, xorpad_buf) == -1) {
- fprintf(stderr, "error: could not find xorpad block :(\n");
- free(save_buf);
- free(out_buf);
- return -1;
- }
- }
- xor(out_buf, size, NULL, xorpad_buf, xorpad_size);
- }
- else
- {
- xorpad_size = 0x200;
- xorpad_buf = (u8*)malloc(xorpad_size);
- if(xorpad_buf==NULL) {
- fprintf(stderr, "error: failed to allocate xorpad buffer.\n");
- free(save_buf);
- free(out_buf);
- return -1;
- }
- memset(xorpad_buf, 0, xorpad_size);
- }
- f = fopen("logical.bin", "wb");
- fwrite(out_buf, 1, size, f);
- fclose(f);
- #ifdef DEBUG
- printf("** FUSE GO! **\n");
- #endif
- return fuse_sav_init(out_buf, size, xorpad_buf, xorpad_size, fargc, fargv);
- }
- int find_key(u8 *buf, size_t len, u8 *out) {
- int i, j, count=0, found=0, rec_idx=0, rec_count=0;
- hash_entry **hash_list;
- u8 hash[16];
- u8 ff_hash[16]="\xde\x03\xfe\x65\xa6\x76\x5c\xaa\x8c\x91\x34\x3a\xcc\x62\xcf\xfc";
- hash_list = malloc(sizeof(hash_entry*) * ((len / 0x200)+1));
- memset(hash_list, 0, sizeof(hash_entry*) * ((len / 0x200)+1));
- for(i = 0; i < (len / 0x200); i++) {
- md5_buf(buf + (i*0x200), hash, 0x200);
- if(memcmp(hash, ff_hash, 16) == 0)
- continue;
- found = 0;
- for(j = 0; j < count; j++) {
- if (memcmp(hash_list[j]->hash, hash, 16) == 0) {
- hash_list[j]->count++;
- found = 1;
- break;
- }
- }
- // push new hashlist entry
- if(found == 0) {
- hash_list[count] = malloc(sizeof(hash_entry));
- memcpy(hash_list[count]->hash, hash, 16);
- hash_list[count]->count = 1;
- hash_list[count]->block_idx = i;
- count++;
- }
- }
- // this is a troll by the way
- // thanks to yellows8 for the random code
- for(i = 0; i < count; i++) {
- if (hash_list[i]->count > rec_count) {
- rec_count = hash_list[i]->count;
- rec_idx = i;
- }
- }
- if (rec_count == 0)
- return -1;
- #ifdef DEBUG
- printf("key hash: "); md5_print(hash_list[rec_idx]->hash); printf("\n");
- #endif
- memcpy(out, buf + (hash_list[rec_idx]->block_idx * 0x200), 0x200);
- for(i = 0; i < count; i++)free(hash_list[i]);
- free(hash_list);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement