Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool IsDollZ (u8 *buff)
- {
- int ret;
- u8 dollz_stamp[] = {0x3C, 0x20, 0x81, 0x60, 0x7C, 0x78, 0xE2, 0xA6, 0x64, 0x63, 0xA0, 0x00};
- int dollz_offs = 0x100;
- ret = memcmp (&buff[dollz_offs], dollz_stamp, sizeof(dollz_stamp));
- if (ret == 0) return true;
- return false;
- }
- /* tueidj Words: */
- /* The proper fix for this is to only copy the new argv struct into the dol's memory if the "_arg" magic word is present there. The original appbooter code is backwards, it checks the "new" argv struct for the magic... which of course it always has, since it gets written there when the struct is initialized.
- The other thing you should be doing is making sure the memory pointed to by the argv struct (malloc'd to hold the command line) is not anywhere inside the new dol, otherwise it's going to be overwritten when the new program's sections are loaded. */
- #define EXECUTE_ADDR ((u8 *) 0x92000000)
- #define MAX_CMDLINE 4096
- #define MAX_ARGV 1000
- struct __argv args;
- char cmdline[MAX_CMDLINE];
- char *a_argv[MAX_ARGV];
- char *meta_buf = NULL;
- void arg_init()
- {
- memset(&args, 0, sizeof(args));
- memset(cmdline, 0, sizeof(cmdline));
- memset(a_argv, 0, sizeof(a_argv));
- args.argvMagic = ARGV_MAGIC;
- args.length = 1; // double \0\0
- args.argc = 0;
- args.commandLine = cmdline;
- args.argv = a_argv;
- args.endARGV = a_argv;
- }
- int arg_add(char *arg)
- {
- return arg_addl(arg, strlen(arg));
- }
- void load_meta( const char *exe_path)
- {
- char meta_path[200];
- const char *p;
- struct stat st;
- p = strrchr(exe_path, '/');
- snprintf( meta_path, sizeof(meta_path), "%.*smeta.xml",
- p ? p-exe_path+1 : 0, exe_path );
- if (stat(meta_path, &st) != 0) {
- return;
- }
- if (st.st_size > 64*1024) {
- return;
- }
- // +1 so that the buf is 0 terminated
- meta_buf = calloc(st.st_size + 1, 1);
- if (!meta_buf) {
- return;
- }
- load_file(meta_path, meta_buf, st.st_size);
- }
- void parse_meta()
- {
- char *p;
- char *e, *end;
- if (meta_buf == NULL) return;
- strip_comments(meta_buf);
- if (!strstr(meta_buf, "<app") || !strstr(meta_buf, "</app>")) {
- return;
- }
- p = strstr(meta_buf, "<arguments>");
- if (!p) return;
- end = strstr(meta_buf, "</arguments>");
- if (!end) return;
- do {
- p = strstr(p, "<arg>");
- if (!p) return;
- p += 5; //strlen("<arg>");
- e = strstr(p, "</arg>");
- if (!e) return;
- arg_addl(p, e-p);
- p = e + 6;
- } while (p < end);
- if (meta_buf) { free(meta_buf); meta_buf = NULL; }
- }
- void * exeBuffer = (void *)EXECUTE_ADDR;
- char filepath[200];
- if (IsDollZ(exeBuffer) == false) {
- arg_init();
- arg_add(filepath); // argv[0] = filepath
- // load meta.xml
- load_meta(filepath);
- // parse <arguments> in meta.xml
- parse_meta();
- }
Add Comment
Please, Sign In to add comment