diff options
Diffstat (limited to 'tools/scramble.c')
-rw-r--r-- | tools/scramble.c | 64 |
1 files changed, 62 insertions, 2 deletions
diff --git a/tools/scramble.c b/tools/scramble.c index cabe15f48d..5d2b12fb84 100644 --- a/tools/scramble.c +++ b/tools/scramble.c | |||
@@ -33,6 +33,7 @@ | |||
33 | 33 | ||
34 | int iaudio_encode(char *iname, char *oname, char *idstring); | 34 | int iaudio_encode(char *iname, char *oname, char *idstring); |
35 | int ipod_encode(char *iname, char *oname, int fw_ver, bool fake_rsrc); | 35 | int ipod_encode(char *iname, char *oname, int fw_ver, bool fake_rsrc); |
36 | int ccpmp_encode(char *iname, char *oname); | ||
36 | 37 | ||
37 | enum | 38 | enum |
38 | { | 39 | { |
@@ -375,8 +376,7 @@ int main (int argc, char** argv) | |||
375 | oname = argv[3]; | 376 | oname = argv[3]; |
376 | return ipod_encode(iname, oname, 3, true); /* Firmware image v3 */ | 377 | return ipod_encode(iname, oname, 3, true); /* Firmware image v3 */ |
377 | } | 378 | } |
378 | else if(!strncmp(argv[1], "-creative=", 10)) | 379 | else if(!strncmp(argv[1], "-creative=", 10)) { |
379 | { | ||
380 | if(!strcmp(argv[2], "-no-ciff")) | 380 | if(!strcmp(argv[2], "-no-ciff")) |
381 | { | 381 | { |
382 | creative_enable_ciff = false; | 382 | creative_enable_ciff = false; |
@@ -405,6 +405,11 @@ int main (int argc, char** argv) | |||
405 | return 2; | 405 | return 2; |
406 | } | 406 | } |
407 | } | 407 | } |
408 | else if(!strcmp(argv[1], "-ccpmp")) { | ||
409 | iname = argv[2]; | ||
410 | oname = argv[3]; | ||
411 | return ccpmp_encode(iname, oname); | ||
412 | } | ||
408 | else if(!strncmp(argv[1], "-mi4", 4)) { | 413 | else if(!strncmp(argv[1], "-mi4", 4)) { |
409 | int mi4magic; | 414 | int mi4magic; |
410 | char model[4] = ""; | 415 | char model[4] = ""; |
@@ -824,3 +829,58 @@ int ipod_encode(char *iname, char *oname, int fw_ver, bool fake_rsrc) | |||
824 | return 0; | 829 | return 0; |
825 | } | 830 | } |
826 | 831 | ||
832 | #define CCPMP_SIZE 0x500000 | ||
833 | int ccpmp_encode(char *iname, char *oname) | ||
834 | { | ||
835 | size_t len; | ||
836 | int length; | ||
837 | FILE *file; | ||
838 | unsigned char *outbuf; | ||
839 | |||
840 | file = fopen(iname, "rb"); | ||
841 | if (!file) { | ||
842 | perror(iname); | ||
843 | return -1; | ||
844 | } | ||
845 | fseek(file,0,SEEK_END); | ||
846 | length = ftell(file); | ||
847 | |||
848 | fseek(file,0,SEEK_SET); | ||
849 | |||
850 | outbuf = malloc(CCPMP_SIZE); | ||
851 | |||
852 | if ( !outbuf ) { | ||
853 | printf("out of memory!\n"); | ||
854 | return -1; | ||
855 | } | ||
856 | |||
857 | len = fread(outbuf, 1, length, file); | ||
858 | if(len < (size_t)length) { | ||
859 | perror(iname); | ||
860 | return -2; | ||
861 | } | ||
862 | fclose(file); | ||
863 | |||
864 | /* Clear the tail area to 0xFF */ | ||
865 | memset(&outbuf[length], 0xFF, CCPMP_SIZE - length); | ||
866 | |||
867 | /* Header */ | ||
868 | int2le(length, &outbuf[0x4]); | ||
869 | |||
870 | file = fopen(oname, "wb"); | ||
871 | if (!file) { | ||
872 | perror(oname); | ||
873 | return -3; | ||
874 | } | ||
875 | |||
876 | len = fwrite(outbuf, 1, CCPMP_SIZE, file); | ||
877 | if(len < (size_t)length) { | ||
878 | perror(oname); | ||
879 | return -4; | ||
880 | } | ||
881 | |||
882 | fclose(file); | ||
883 | |||
884 | return 0; | ||
885 | } | ||
886 | |||