Guest User

Untitled

a guest
Dec 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. bool IsDollZ (u8 *buff)
  2. {
  3. int ret;
  4.  
  5. u8 dollz_stamp[] = {0x3C, 0x20, 0x81, 0x60, 0x7C, 0x78, 0xE2, 0xA6, 0x64, 0x63, 0xA0, 0x00};
  6. int dollz_offs = 0x100;
  7.  
  8. ret = memcmp (&buff[dollz_offs], dollz_stamp, sizeof(dollz_stamp));
  9. if (ret == 0) return true;
  10.  
  11. return false;
  12. }
  13. /* tueidj Words: */
  14. /* 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.
  15. 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. */
  16.  
  17. #define EXECUTE_ADDR ((u8 *) 0x92000000)
  18. #define MAX_CMDLINE 4096
  19. #define MAX_ARGV 1000
  20. struct __argv args;
  21. char cmdline[MAX_CMDLINE];
  22. char *a_argv[MAX_ARGV];
  23. char *meta_buf = NULL;
  24.  
  25. void arg_init()
  26. {
  27. memset(&args, 0, sizeof(args));
  28. memset(cmdline, 0, sizeof(cmdline));
  29. memset(a_argv, 0, sizeof(a_argv));
  30. args.argvMagic = ARGV_MAGIC;
  31. args.length = 1; // double \0\0
  32. args.argc = 0;
  33. args.commandLine = cmdline;
  34. args.argv = a_argv;
  35. args.endARGV = a_argv;
  36. }
  37.  
  38. int arg_add(char *arg)
  39. {
  40. return arg_addl(arg, strlen(arg));
  41. }
  42.  
  43. void load_meta( const char *exe_path)
  44. {
  45. char meta_path[200];
  46. const char *p;
  47. struct stat st;
  48.  
  49. p = strrchr(exe_path, '/');
  50. snprintf( meta_path, sizeof(meta_path), "%.*smeta.xml",
  51. p ? p-exe_path+1 : 0, exe_path );
  52.  
  53. if (stat(meta_path, &st) != 0) {
  54. return;
  55. }
  56. if (st.st_size > 64*1024) {
  57. return;
  58. }
  59. // +1 so that the buf is 0 terminated
  60. meta_buf = calloc(st.st_size + 1, 1);
  61. if (!meta_buf) {
  62. return;
  63. }
  64. load_file(meta_path, meta_buf, st.st_size);
  65. }
  66.  
  67. void parse_meta()
  68. {
  69. char *p;
  70. char *e, *end;
  71. if (meta_buf == NULL) return;
  72. strip_comments(meta_buf);
  73. if (!strstr(meta_buf, "<app") || !strstr(meta_buf, "</app>")) {
  74. return;
  75. }
  76. p = strstr(meta_buf, "<arguments>");
  77. if (!p) return;
  78. end = strstr(meta_buf, "</arguments>");
  79. if (!end) return;
  80. do {
  81. p = strstr(p, "<arg>");
  82. if (!p) return;
  83. p += 5; //strlen("<arg>");
  84. e = strstr(p, "</arg>");
  85. if (!e) return;
  86. arg_addl(p, e-p);
  87. p = e + 6;
  88. } while (p < end);
  89. if (meta_buf) { free(meta_buf); meta_buf = NULL; }
  90. }
  91. void * exeBuffer = (void *)EXECUTE_ADDR;
  92. char filepath[200];
  93.  
  94. if (IsDollZ(exeBuffer) == false) {
  95. arg_init();
  96. arg_add(filepath); // argv[0] = filepath
  97. // load meta.xml
  98. load_meta(filepath);
  99. // parse <arguments> in meta.xml
  100. parse_meta();
  101. }
Add Comment
Please, Sign In to add comment