Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

scramble.c patch
Saturday, July 22nd, 2006 at 9:57:57pm UTC 

  1. --- scrambleORIG.c      2006-07-22 23:50:32.000000000 +0200
  2. +++ scramble.c  2006-07-22 23:52:30.000000000 +0200
  3. @@ -493,6 +493,22 @@
  4.                                           "----------------"\
  5.                                           "----------------"\
  6.                                           "---------------";
  7. +
  8. +   typedef struct _ipod_direntry {
  9. +    char dev[4];              /* '!ATA' */
  10. +    char type[4];            /* '' */
  11. +    unsigned id;              /* */
  12. +    /*char pad1[4];*/    /* 0000 0000 */
  13. +    unsigned devOffset;                /* byte offset of start of image code */
  14. +    unsigned len;            /* length in bytes of image */
  15. +    unsigned addr;          /* load address */
  16. +    unsigned entryOffset;      /* execution start within image */
  17. +    unsigned chksum;      /* checksum for image */
  18. +    unsigned vers;          /* image version */
  19. +    unsigned loadAddr;  /* load address for image */
  20. +   } ipod_direntry_t;
  21. +
  22. +
  23.      size_t len;
  24.      int length;
  25.      int rsrclength;
  26. @@ -503,6 +519,19 @@
  27.      unsigned char *outbuf;
  28.      int bufsize;
  29.      int i;
  30. +   
  31. +    FILE *rsrc_file;
  32. +    int rsrc_len=0;
  33. +    rsrc_file = fopen("apple_sw_5g_rcsc.bin", "rb");
  34. +    if (rsrc_file) {
  35. +       fprintf(stderr, "Including real rsrc for native firmware support in a file for iPod video\n");
  36. +       fseek(rsrc_file,0,SEEK_END);
  37. +       rsrc_len = ftell(rsrc_file)+0x200;/*is this enough for malloc?
  38. +           (if not then we get a segment error at line 605 (fread)*/
  39. +       fseek(rsrc_file,0,SEEK_SET);
  40. +    }else if(fake_rsrc){
  41. +       fprintf(stderr, "Including fake rsrc, supports booting rockbox & ipodlinux, but not for native firmware support for iPod video\n");
  42. +    }
  43.  
  44.      file = fopen(iname, "rb");
  45.      if (!file) {
  46. @@ -511,11 +540,10 @@
  47.      }
  48.      fseek(file,0,SEEK_END);
  49.      length = ftell(file);
  50. -   
  51.      fseek(file,0,SEEK_SET);
  52.  
  53. -    bufsize=(length+0x4600);
  54. -    if (fake_rsrc) {
  55. +    bufsize=(length+0x4600+rsrc_len);
  56. +    if (fake_rsrc&&rsrc_len==0) {
  57.          bufsize = (bufsize + 0x400) & ~0x200;
  58.      }
  59.  
  60. @@ -533,7 +561,7 @@
  61.      }
  62.      fclose(file);
  63.  
  64. -    /* Calculate checksum for later use in header */   
  65. +    /* Calculate checksum for later use in header */
  66.      for(i = 0x4600; i < 0x4600+length;i++)
  67.          sum += outbuf[i];
  68.  
  69. @@ -562,19 +590,48 @@
  70.  
  71.      /* "rsrc" entry (if applicable) */
  72.      if (fake_rsrc) {
  73. -        rsrcoffset=(length+0x4600+0x200) & ~0x200;
  74. -        rsrclength=0x200;
  75. -        rsrcsum=0;
  76. -
  77. -        memcpy(&outbuf[0x4228],"!ATAcrsr",8); /* dev and type */
  78. -        int2le(0,          &outbuf[0x4230]);  /* id */
  79. -        int2le(rsrcoffset, &outbuf[0x4234]);  /* devOffset */
  80. -        int2le(rsrclength, &outbuf[0x4238]);  /* Length of firmware */
  81. -        int2le(0x10000000, &outbuf[0x423c]);  /* Addr */
  82. -        int2le(0,          &outbuf[0x4240]);  /* Entry Offset */
  83. -        int2le(rsrcsum,    &outbuf[0x4244]);  /* Checksum */
  84. -        int2le(0x0000b000, &outbuf[0x4248]);  /* vers */
  85. -        int2le(0xffffffff, &outbuf[0x424c]);  /* LoadAddr - for flash images */
  86. +       /*rsrcoffset=(length+0x4600+0x200) & ~0x200;*/
  87. +       rsrcoffset = 0x4400 + length;
  88. +       rsrcoffset = ((rsrcoffset + 0x1ff) & ~0x1ff) + 0x200;
  89. +       ipod_direntry_t *rsrc_entry =malloc(sizeof(ipod_direntry_t));
  90. +       memset(rsrc_entry,0,sizeof(ipod_direntry_t));
  91. +       if(rsrc_len>0){ /*real rsrc*/
  92. +              fseek(rsrc_file,0,SEEK_SET);
  93. +              if (fread(rsrc_entry, 1,sizeof(ipod_direntry_t),rsrc_file)<sizeof(ipod_direntry_t)){
  94. +                     printf("Rsrc header read errror\n");
  95. +                     return -2;
  96. +              }
  97. +              rsrc_entry->devOffset=rsrcoffset;
  98. +              fseek(rsrc_file,512,SEEK_SET);
  99. +              if (fread(outbuf+rsrcoffset+0x200, 1,rsrc_entry->len,rsrc_file)<rsrc_entry->len){/*dangerous*/
  100. +                     printf("Rsrc read errror\n");
  101. +                     return -2;
  102. +              }
  103. +              rsrclength=rsrc_entry->len;
  104. +              for(i = rsrcoffset+0x200; i < rsrcoffset+0x200+rsrc_entry->len;i++)
  105. +                     rsrcsum += outbuf[i];
  106. +              if(rsrcsum!=rsrc_entry->chksum){
  107. +                     printf("rsrc checksum errror, corrupt file: apple_sw_5g_rcsc.bin\n");
  108. +                     return -2;
  109. +              }
  110. +              /*fclose(rsrc_file);*/
  111. +              rsrclength+=0x400;/*padding*/
  112. +       }else{/*fake rsrc*/
  113. +               rsrclength=0x200;
  114. +              rsrcsum=0;
  115. +              memcpy(rsrc_entry->dev,"!ATA",4); /* dev and type */
  116. +              memcpy(rsrc_entry->type,"crsr",4); /* dev and type */
  117. +              rsrc_entry->devOffset=rsrcoffset;
  118. +              rsrc_entry->len=rsrclength;
  119. +              rsrc_entry->addr=0x10000000;
  120. +              rsrc_entry->chksum=rsrcsum;
  121. +              rsrc_entry->vers=0x0000b000;
  122. +              rsrc_entry->loadAddr=0xffffffff;
  123. +              rsrclength=0;
  124. +       }
  125. +       memcpy(&outbuf[0x4228],rsrc_entry,sizeof(ipod_direntry_t));
  126. +       free(rsrc_entry);
  127. +       rsrclength=rsrcoffset+rsrclength;
  128.      }
  129.  
  130.      file = fopen(oname, "wb");
  131. @@ -582,8 +639,7 @@
  132.         perror(oname);
  133.         return -3;
  134.      }
  135. -   
  136. -    len = fwrite(outbuf, 1, length+0x4600, file);
  137. +    len = fwrite(outbuf, 1, rsrclength==0?length+0x4600:rsrclength, file);
  138.      if(len < length) {
  139.          perror(oname);
  140.          return -4;

Update the Post

Either update this post and resubmit it with changes, or make a new post.

You may also comment on this post.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.

comments powered by Disqus
worth-right
worth-right