summaryrefslogtreecommitdiff
path: root/rbutil/ipodpatcher
diff options
context:
space:
mode:
Diffstat (limited to 'rbutil/ipodpatcher')
-rw-r--r--rbutil/ipodpatcher/ipodpatcher.c25
-rw-r--r--rbutil/ipodpatcher/ipodpatcher.h2
-rw-r--r--rbutil/ipodpatcher/main.c12
3 files changed, 26 insertions, 13 deletions
diff --git a/rbutil/ipodpatcher/ipodpatcher.c b/rbutil/ipodpatcher/ipodpatcher.c
index 6fcf0c8c27..331c7f0322 100644
--- a/rbutil/ipodpatcher/ipodpatcher.c
+++ b/rbutil/ipodpatcher/ipodpatcher.c
@@ -885,7 +885,7 @@ int write_firmware(struct ipod_t* ipod, char* filename, int type)
885 return 0; 885 return 0;
886} 886}
887 887
888int read_firmware(struct ipod_t* ipod, char* filename) 888int read_firmware(struct ipod_t* ipod, char* filename, int type)
889{ 889{
890 int length; 890 int length;
891 int i; 891 int i;
@@ -921,22 +921,25 @@ int read_firmware(struct ipod_t* ipod, char* filename)
921 return -1; 921 return -1;
922 } 922 }
923 923
924 chksum = ipod->modelnum;
925 for (i = 0; i < length; i++) {
926 /* add 8 unsigned bits but keep a 32 bit sum */
927 chksum += sectorbuf[i];
928 }
929
930 int2be(chksum,header);
931 memcpy(header+4, ipod->modelname,4);
932
933 outfile = open(filename,O_CREAT|O_TRUNC|O_WRONLY|O_BINARY,0666); 924 outfile = open(filename,O_CREAT|O_TRUNC|O_WRONLY|O_BINARY,0666);
934 if (outfile < 0) { 925 if (outfile < 0) {
935 fprintf(stderr,"[ERR] Couldn't open file %s\n",filename); 926 fprintf(stderr,"[ERR] Couldn't open file %s\n",filename);
936 return -1; 927 return -1;
937 } 928 }
938 929
939 write(outfile,header,8); 930 if (type == FILETYPE_DOT_IPOD) {
931 chksum = ipod->modelnum;
932 for (i = 0; i < length; i++) {
933 /* add 8 unsigned bits but keep a 32 bit sum */
934 chksum += sectorbuf[i];
935 }
936
937 int2be(chksum,header);
938 memcpy(header+4, ipod->modelname,4);
939
940 write(outfile,header,8);
941 }
942
940 write(outfile,sectorbuf,length); 943 write(outfile,sectorbuf,length);
941 close(outfile); 944 close(outfile);
942 945
diff --git a/rbutil/ipodpatcher/ipodpatcher.h b/rbutil/ipodpatcher/ipodpatcher.h
index 4c1eee58af..2339687318 100644
--- a/rbutil/ipodpatcher/ipodpatcher.h
+++ b/rbutil/ipodpatcher/ipodpatcher.h
@@ -41,7 +41,7 @@ int diskmove(struct ipod_t* ipod, int delta);
41int add_bootloader(struct ipod_t* ipod, char* filename, int type); 41int add_bootloader(struct ipod_t* ipod, char* filename, int type);
42int delete_bootloader(struct ipod_t* ipod); 42int delete_bootloader(struct ipod_t* ipod);
43int write_firmware(struct ipod_t* ipod, char* filename, int type); 43int write_firmware(struct ipod_t* ipod, char* filename, int type);
44int read_firmware(struct ipod_t* ipod, char* filename); 44int read_firmware(struct ipod_t* ipod, char* filename, int type);
45int read_directory(struct ipod_t* ipod); 45int read_directory(struct ipod_t* ipod);
46int list_images(struct ipod_t* ipod); 46int list_images(struct ipod_t* ipod);
47int getmodel(struct ipod_t* ipod, int ipod_version); 47int getmodel(struct ipod_t* ipod, int ipod_version);
diff --git a/rbutil/ipodpatcher/main.c b/rbutil/ipodpatcher/main.c
index e60b1d7034..6328e2df99 100644
--- a/rbutil/ipodpatcher/main.c
+++ b/rbutil/ipodpatcher/main.c
@@ -76,6 +76,7 @@ void print_usage(void)
76 fprintf(stderr," -r, --read-partition bootpartition.bin\n"); 76 fprintf(stderr," -r, --read-partition bootpartition.bin\n");
77 fprintf(stderr," -w, --write-partition bootpartition.bin\n"); 77 fprintf(stderr," -w, --write-partition bootpartition.bin\n");
78 fprintf(stderr," -rf, --read-firmware filename.ipod\n"); 78 fprintf(stderr," -rf, --read-firmware filename.ipod\n");
79 fprintf(stderr," -rfb, --read-firmware-bin filename.bin\n");
79 fprintf(stderr," -wf, --write-firmware filename.ipod\n"); 80 fprintf(stderr," -wf, --write-firmware filename.ipod\n");
80 fprintf(stderr," -wfb, --write-firmware-bin filename.bin\n"); 81 fprintf(stderr," -wfb, --write-firmware-bin filename.bin\n");
81 fprintf(stderr," -a, --add-bootloader filename.ipod\n"); 82 fprintf(stderr," -a, --add-bootloader filename.ipod\n");
@@ -234,6 +235,15 @@ int main(int argc, char* argv[])
234 } else if ((strcmp(argv[i],"-rf")==0) || 235 } else if ((strcmp(argv[i],"-rf")==0) ||
235 (strcmp(argv[i],"--read-firmware")==0)) { 236 (strcmp(argv[i],"--read-firmware")==0)) {
236 action = READ_FIRMWARE; 237 action = READ_FIRMWARE;
238 type = FILETYPE_DOT_IPOD;
239 i++;
240 if (i == argc) { print_usage(); return 1; }
241 filename=argv[i];
242 i++;
243 } else if ((strcmp(argv[i],"-rfb")==0) ||
244 (strcmp(argv[i],"--read-firmware-bin")==0)) {
245 action = READ_FIRMWARE;
246 type = FILETYPE_DOT_BIN;
237 i++; 247 i++;
238 if (i == argc) { print_usage(); return 1; } 248 if (i == argc) { print_usage(); return 1; }
239 filename=argv[i]; 249 filename=argv[i];
@@ -399,7 +409,7 @@ int main(int argc, char* argv[])
399 fprintf(stderr,"[ERR] --write-firmware failed.\n"); 409 fprintf(stderr,"[ERR] --write-firmware failed.\n");
400 } 410 }
401 } else if (action==READ_FIRMWARE) { 411 } else if (action==READ_FIRMWARE) {
402 if (read_firmware(&ipod, filename)==0) { 412 if (read_firmware(&ipod, filename, type)==0) {
403 fprintf(stderr,"[INFO] Firmware read to file %s.\n",filename); 413 fprintf(stderr,"[INFO] Firmware read to file %s.\n",filename);
404 } else { 414 } else {
405 fprintf(stderr,"[ERR] --read-firmware failed.\n"); 415 fprintf(stderr,"[ERR] --read-firmware failed.\n");