Advertisement
Guest User

Untitled

a guest
Aug 9th, 2011
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. // Copyright 2010 Sven Peter <svenpeter@gmail.com>
  2. // Licensed under the terms of the GNU GPL, version 2
  3. // http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8. #include <sys/stat.h>
  9. #include <unistd.h>
  10. #include "tools.h"
  11.  
  12. static u8 *nor = NULL;
  13.  
  14. static void new_dir(const char *n)
  15. {
  16. mkdir(n, 0777);
  17.  
  18. if (chdir(n) < 0)
  19. fail("chdir");
  20. }
  21.  
  22. static void do_toc(u8 *ptr)
  23. {
  24. u32 n_entries;
  25. u32 i;
  26. u8 *p;
  27. u8 *tmp;
  28. u64 size;
  29. char name[0x20];
  30.  
  31. n_entries = be32(ptr + 0x04);
  32. p = ptr + 0x10;
  33.  
  34. for(i = 0; i < n_entries; i++) {
  35. memcpy(name, p + 16, 0x20);
  36.  
  37. if (strncmp(name, "asecure_loader", 0x20) == 0) {
  38. new_dir("asecure_loader");
  39. do_toc(ptr + be64(p));
  40. if (chdir("..") < 0)
  41. fail("chdir(..)");
  42. } else if (strncmp(name, "ros", 3) == 0) {
  43. new_dir(name);
  44. do_toc(ptr + be64(p) + 0x10);
  45. if (chdir("..") < 0)
  46. fail("chdir(..)");
  47. } else {
  48. tmp = ptr + be64(p);
  49. size = be64(p + 0x08);
  50. if (be32(tmp + 0x10) == 0x53434500) {
  51. tmp += 0x10;
  52. size -= 0x10;
  53. }
  54.  
  55. memcpy_to_file(name, tmp, size);
  56. }
  57. p += 0x30;
  58. }
  59. }
  60.  
  61. static void modifyimage(u8 *ptr)
  62. {
  63. u32 i;
  64. u8 temp;
  65. for(i=0; i<16777216; i+=2)
  66. {
  67. temp = *(ptr+i);
  68. *(ptr+i) = *(ptr+i+1);
  69. *(ptr+i+1) = temp;
  70. }
  71. }
  72.  
  73. int main(int argc, char *argv[])
  74. {
  75. if (argc < 3)
  76. fail("usage: norunpack dump.b directory [byteswap]");
  77.  
  78. nor = mmap_file(argv[1]);
  79.  
  80. new_dir(argv[2]);
  81. if(argc > 3)
  82. modifyimage(nor);
  83.  
  84. do_toc(nor + 0x400);
  85.  
  86. return 0;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement