diff options
author | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2008-09-07 21:45:52 +0000 |
---|---|---|
committer | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2008-09-07 21:45:52 +0000 |
commit | 11eff09e70a14ca0d9531bce119814da36d47f46 (patch) | |
tree | 5cc764de4fa33e8150e4c2569088349b02610aac | |
parent | 3d0f01c0f7ebad28a795b65e1ddcb707d945d3a3 (diff) | |
download | rockbox-11eff09e70a14ca0d9531bce119814da36d47f46.tar.gz rockbox-11eff09e70a14ca0d9531bce119814da36d47f46.zip |
* Clean up screenshot a bit and make it more self-descriptive
* Make mkzenboot truly standalone
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18443 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | tools/mkzenboot.c | 120 | ||||
-rw-r--r-- | utils/wpseditor/screenshot/main.c | 68 |
2 files changed, 109 insertions, 79 deletions
diff --git a/tools/mkzenboot.c b/tools/mkzenboot.c index 494838833a..e37708e1d1 100644 --- a/tools/mkzenboot.c +++ b/tools/mkzenboot.c | |||
@@ -21,6 +21,7 @@ | |||
21 | * | 21 | * |
22 | ****************************************************************************/ | 22 | ****************************************************************************/ |
23 | #include <stdio.h> | 23 | #include <stdio.h> |
24 | #include <stdarg.h> | ||
24 | #include <stdlib.h> | 25 | #include <stdlib.h> |
25 | #include <string.h> | 26 | #include <string.h> |
26 | #include <stdbool.h> | 27 | #include <stdbool.h> |
@@ -845,6 +846,8 @@ static struct player_info_t players[] = { | |||
845 | {NULL, NULL, NULL, NULL, false} | 846 | {NULL, NULL, NULL, NULL, false} |
846 | }; | 847 | }; |
847 | 848 | ||
849 | void log_message(const char* format, ...); | ||
850 | |||
848 | int mkboot(const char* infile, const char* bootfile, const char* outfile, struct player_info_t *player) | 851 | int mkboot(const char* infile, const char* bootfile, const char* outfile, struct player_info_t *player) |
849 | { | 852 | { |
850 | FILE *infd, *bootfd, *outfd; | 853 | FILE *infd, *bootfd, *outfd; |
@@ -856,21 +859,21 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
856 | infd = fopen(infile, "rb"); | 859 | infd = fopen(infile, "rb"); |
857 | if(infd == NULL) | 860 | if(infd == NULL) |
858 | { | 861 | { |
859 | fprintf(stderr, "[ERR] Could not open %s\n", infile); | 862 | log_message("[ERR] Could not open %s\n", infile); |
860 | return -1; | 863 | return -1; |
861 | } | 864 | } |
862 | 865 | ||
863 | buffer = malloc(filesize(infd)); | 866 | buffer = malloc(filesize(infd)); |
864 | if(buffer == NULL) | 867 | if(buffer == NULL) |
865 | { | 868 | { |
866 | fprintf(stderr, "[ERR] Could not allocate %d unsigned chars\n", filesize(infd)); | 869 | log_message("[ERR] Could not allocate %d unsigned chars\n", filesize(infd)); |
867 | fclose(infd); | 870 | fclose(infd); |
868 | return -2; | 871 | return -2; |
869 | } | 872 | } |
870 | 873 | ||
871 | if(fread(buffer, filesize(infd), 1, infd) != 1) | 874 | if(fread(buffer, filesize(infd), 1, infd) != 1) |
872 | { | 875 | { |
873 | fprintf(stderr, "[ERR] Short read\n"); | 876 | log_message("[ERR] Short read\n"); |
874 | fclose(infd); | 877 | fclose(infd); |
875 | free(buffer); | 878 | free(buffer); |
876 | return -3; | 879 | return -3; |
@@ -882,7 +885,7 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
882 | if(memcmp(&buffer[0], "MZ", 2) != 0 && | 885 | if(memcmp(&buffer[0], "MZ", 2) != 0 && |
883 | memcmp(&buffer[0x118], "PE", 2) != 0) | 886 | memcmp(&buffer[0x118], "PE", 2) != 0) |
884 | { | 887 | { |
885 | fprintf(stderr, "[ERR] Input file isn't an executable\n"); | 888 | log_message("[ERR] Input file isn't an executable\n"); |
886 | free(buffer); | 889 | free(buffer); |
887 | return -4; | 890 | return -4; |
888 | } | 891 | } |
@@ -900,46 +903,46 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
900 | 903 | ||
901 | if(data_ptr == 0 || data_size == 0) | 904 | if(data_ptr == 0 || data_size == 0) |
902 | { | 905 | { |
903 | fprintf(stderr, "[ERR] Couldn't find .data section\n"); | 906 | log_message("[ERR] Couldn't find .data section\n"); |
904 | free(buffer); | 907 | free(buffer); |
905 | return -5; | 908 | return -5; |
906 | } | 909 | } |
907 | 910 | ||
908 | fprintf(stderr, "[INFO] .data section is at 0x%x with size 0x%x\n", data_ptr, data_size); | 911 | log_message("[INFO] .data section is at 0x%x with size 0x%x\n", data_ptr, data_size); |
909 | 912 | ||
910 | fw_offset = find_firmware_offset(&buffer[data_ptr], data_size); | 913 | fw_offset = find_firmware_offset(&buffer[data_ptr], data_size); |
911 | if(fw_offset == 0) | 914 | if(fw_offset == 0) |
912 | { | 915 | { |
913 | fprintf(stderr, "[ERR] Couldn't find firmware offset\n"); | 916 | log_message("[ERR] Couldn't find firmware offset\n"); |
914 | free(buffer); | 917 | free(buffer); |
915 | return -6; | 918 | return -6; |
916 | } | 919 | } |
917 | fw_size = le2int(&buffer[data_ptr+fw_offset]); | 920 | fw_size = le2int(&buffer[data_ptr+fw_offset]); |
918 | fprintf(stderr, "[INFO] Firmware offset is at 0x%x with size 0x%x\n", data_ptr+fw_offset, fw_size); | 921 | log_message("[INFO] Firmware offset is at 0x%x with size 0x%x\n", data_ptr+fw_offset, fw_size); |
919 | 922 | ||
920 | fw_key = find_firmware_key(&buffer[0], filesize(infd)); | 923 | fw_key = find_firmware_key(&buffer[0], filesize(infd)); |
921 | if(fw_key == NULL) | 924 | if(fw_key == NULL) |
922 | { | 925 | { |
923 | fprintf(stderr, "[ERR] Couldn't find firmware key\n"); | 926 | log_message("[ERR] Couldn't find firmware key\n"); |
924 | free(buffer); | 927 | free(buffer); |
925 | return -7; | 928 | return -7; |
926 | } | 929 | } |
927 | fprintf(stderr, "[INFO] Firmware key is %s\n", fw_key); | 930 | log_message("[INFO] Firmware key is %s\n", fw_key); |
928 | 931 | ||
929 | fprintf(stderr, "[INFO] Descrambling firmware... "); | 932 | log_message("[INFO] Descrambling firmware... "); |
930 | if(!crypt_firmware(fw_key, &buffer[data_ptr+fw_offset+4], fw_size)) | 933 | if(!crypt_firmware(fw_key, &buffer[data_ptr+fw_offset+4], fw_size)) |
931 | { | 934 | { |
932 | fprintf(stderr, "Fail!\n"); | 935 | log_message("Fail!\n"); |
933 | free(buffer); | 936 | free(buffer); |
934 | return -8; | 937 | return -8; |
935 | } | 938 | } |
936 | else | 939 | else |
937 | fprintf(stderr, "Done!\n"); | 940 | log_message("Done!\n"); |
938 | 941 | ||
939 | out_buffer = malloc(fw_size*2); | 942 | out_buffer = malloc(fw_size*2); |
940 | if(out_buffer == NULL) | 943 | if(out_buffer == NULL) |
941 | { | 944 | { |
942 | fprintf(stderr, "[ERR] Couldn't allocate %d unsigned chars", fw_size*2); | 945 | log_message("[ERR] Couldn't allocate %d unsigned chars", fw_size*2); |
943 | free(buffer); | 946 | free(buffer); |
944 | return -9; | 947 | return -9; |
945 | } | 948 | } |
@@ -947,23 +950,23 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
947 | memset(out_buffer, 0, fw_size*2); | 950 | memset(out_buffer, 0, fw_size*2); |
948 | 951 | ||
949 | err_msg = NULL; | 952 | err_msg = NULL; |
950 | fprintf(stderr, "[INFO] Decompressing firmware... "); | 953 | log_message("[INFO] Decompressing firmware... "); |
951 | if(!inflate_to_buffer(&buffer[data_ptr+fw_offset+4], fw_size, out_buffer, fw_size*2, &err_msg)) | 954 | if(!inflate_to_buffer(&buffer[data_ptr+fw_offset+4], fw_size, out_buffer, fw_size*2, &err_msg)) |
952 | { | 955 | { |
953 | fprintf(stderr, "Fail!\n[ERR] ZLib error: %s\n", err_msg); | 956 | log_message("Fail!\n[ERR] ZLib error: %s\n", err_msg); |
954 | free(buffer); | 957 | free(buffer); |
955 | free(out_buffer); | 958 | free(out_buffer); |
956 | return -10; | 959 | return -10; |
957 | } | 960 | } |
958 | else | 961 | else |
959 | { | 962 | { |
960 | fprintf(stderr, "Done!\n"); | 963 | log_message("Done!\n"); |
961 | free(buffer); | 964 | free(buffer); |
962 | } | 965 | } |
963 | 966 | ||
964 | if(memcmp(out_buffer, "FFIC", 4) != 0) | 967 | if(memcmp(out_buffer, "FFIC", 4) != 0) |
965 | { | 968 | { |
966 | fprintf(stderr, "[ERR] CIFF header doesn't match\n"); | 969 | log_message("[ERR] CIFF header doesn't match\n"); |
967 | free(out_buffer); | 970 | free(out_buffer); |
968 | return -11; | 971 | return -11; |
969 | } | 972 | } |
@@ -973,7 +976,7 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
973 | bootfd = fopen(bootfile, "rb"); | 976 | bootfd = fopen(bootfile, "rb"); |
974 | if(bootfd == NULL) | 977 | if(bootfd == NULL) |
975 | { | 978 | { |
976 | fprintf(stderr, "[ERR] Could not open %s\n", bootfile); | 979 | log_message("[ERR] Could not open %s\n", bootfile); |
977 | free(out_buffer); | 980 | free(out_buffer); |
978 | return -12; | 981 | return -12; |
979 | } | 982 | } |
@@ -981,12 +984,12 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
981 | out_buffer = realloc(out_buffer, ciff_size+filesize(bootfd)); | 984 | out_buffer = realloc(out_buffer, ciff_size+filesize(bootfd)); |
982 | if(out_buffer == NULL) | 985 | if(out_buffer == NULL) |
983 | { | 986 | { |
984 | fprintf(stderr, "[ERR] Cannot allocate %d unsigned chars\n", ciff_size+40+filesize(bootfd)); | 987 | log_message("[ERR] Cannot allocate %d unsigned chars\n", ciff_size+40+filesize(bootfd)); |
985 | fclose(bootfd); | 988 | fclose(bootfd); |
986 | return -13; | 989 | return -13; |
987 | } | 990 | } |
988 | 991 | ||
989 | fprintf(stderr, "[INFO] Locating encoded block... "); | 992 | log_message("[INFO] Locating encoded block... "); |
990 | 993 | ||
991 | i = 8; | 994 | i = 8; |
992 | while(memcmp(&out_buffer[i], " LTŠ", 4) != 0 && i < ciff_size) | 995 | while(memcmp(&out_buffer[i], " LTŠ", 4) != 0 && i < ciff_size) |
@@ -1001,7 +1004,7 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
1001 | } | 1004 | } |
1002 | else | 1005 | else |
1003 | { | 1006 | { |
1004 | fprintf(stderr, "Fail!\n[ERR] Unknown block\n"); | 1007 | log_message("Fail!\n[ERR] Unknown block\n"); |
1005 | fclose(bootfd); | 1008 | fclose(bootfd); |
1006 | free(out_buffer); | 1009 | free(out_buffer); |
1007 | return -14; | 1010 | return -14; |
@@ -1010,18 +1013,18 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
1010 | 1013 | ||
1011 | if(i > ciff_size || memcmp(&out_buffer[i], " LTŠ", 4) != 0) | 1014 | if(i > ciff_size || memcmp(&out_buffer[i], " LTŠ", 4) != 0) |
1012 | { | 1015 | { |
1013 | fprintf(stderr, "Fail!\n[ERR] Couldn't find encoded block\n"); | 1016 | log_message("Fail!\n[ERR] Couldn't find encoded block\n"); |
1014 | fclose(bootfd); | 1017 | fclose(bootfd); |
1015 | free(out_buffer); | 1018 | free(out_buffer); |
1016 | return -15; | 1019 | return -15; |
1017 | } | 1020 | } |
1018 | 1021 | ||
1019 | fprintf(stderr, "Done!\n"); | 1022 | log_message("Done!\n"); |
1020 | 1023 | ||
1021 | outfd = fopen(outfile, "wb+"); | 1024 | outfd = fopen(outfile, "wb+"); |
1022 | if(outfd == NULL) | 1025 | if(outfd == NULL) |
1023 | { | 1026 | { |
1024 | fprintf(stderr, "[ERR] Could not open %s\n", outfile); | 1027 | log_message("[ERR] Could not open %s\n", outfile); |
1025 | fclose(bootfd); | 1028 | fclose(bootfd); |
1026 | free(out_buffer); | 1029 | free(out_buffer); |
1027 | return -16; | 1030 | return -16; |
@@ -1029,14 +1032,14 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
1029 | 1032 | ||
1030 | if(fwrite(&out_buffer[0], i, 1, outfd) != 1) | 1033 | if(fwrite(&out_buffer[0], i, 1, outfd) != 1) |
1031 | { | 1034 | { |
1032 | fprintf(stderr, "[ERR] Short write\n"); | 1035 | log_message("[ERR] Short write\n"); |
1033 | fclose(bootfd); | 1036 | fclose(bootfd); |
1034 | fclose(outfd); | 1037 | fclose(outfd); |
1035 | free(out_buffer); | 1038 | free(out_buffer); |
1036 | return -17; | 1039 | return -17; |
1037 | } | 1040 | } |
1038 | 1041 | ||
1039 | fprintf(stderr, "[INFO] Decrypting encoded block... "); | 1042 | log_message("[INFO] Decrypting encoded block... "); |
1040 | 1043 | ||
1041 | iv[0] = 0; | 1044 | iv[0] = 0; |
1042 | iv[1] = swap(le2int(&out_buffer[i+4])); | 1045 | iv[1] = swap(le2int(&out_buffer[i+4])); |
@@ -1044,20 +1047,20 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
1044 | le2int(&out_buffer[i+4]), (const unsigned char*)&iv) | 1047 | le2int(&out_buffer[i+4]), (const unsigned char*)&iv) |
1045 | == false) | 1048 | == false) |
1046 | { | 1049 | { |
1047 | fprintf(stderr, "Fail!\n[ERR] Couldn't decrypt encoded block\n"); | 1050 | log_message("Fail!\n[ERR] Couldn't decrypt encoded block\n"); |
1048 | fclose(bootfd); | 1051 | fclose(bootfd); |
1049 | fclose(outfd); | 1052 | fclose(outfd); |
1050 | free(out_buffer); | 1053 | free(out_buffer); |
1051 | return -18; | 1054 | return -18; |
1052 | } | 1055 | } |
1053 | 1056 | ||
1054 | fprintf(stderr, "Done!\n"); | 1057 | log_message("Done!\n"); |
1055 | 1058 | ||
1056 | cenc_size = le2int(&out_buffer[i+8]); | 1059 | cenc_size = le2int(&out_buffer[i+8]); |
1057 | 1060 | ||
1058 | if(cenc_size > le2int(&out_buffer[i+4])*3) | 1061 | if(cenc_size > le2int(&out_buffer[i+4])*3) |
1059 | { | 1062 | { |
1060 | fprintf(stderr, "[ERR] Decrypted length of encoded block is unexpectedly large: 0x%08x\n", cenc_size); | 1063 | log_message("[ERR] Decrypted length of encoded block is unexpectedly large: 0x%08x\n", cenc_size); |
1061 | fclose(bootfd); | 1064 | fclose(bootfd); |
1062 | fclose(outfd); | 1065 | fclose(outfd); |
1063 | free(out_buffer); | 1066 | free(out_buffer); |
@@ -1067,7 +1070,7 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
1067 | buffer = malloc(cenc_size); | 1070 | buffer = malloc(cenc_size); |
1068 | if(buffer == NULL) | 1071 | if(buffer == NULL) |
1069 | { | 1072 | { |
1070 | fprintf(stderr, "[ERR] Couldn't allocate %d unsigned chars\n", cenc_size); | 1073 | log_message("[ERR] Couldn't allocate %d unsigned chars\n", cenc_size); |
1071 | fclose(bootfd); | 1074 | fclose(bootfd); |
1072 | fclose(outfd); | 1075 | fclose(outfd); |
1073 | free(out_buffer); | 1076 | free(out_buffer); |
@@ -1076,11 +1079,11 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
1076 | 1079 | ||
1077 | memset(buffer, 0, cenc_size); | 1080 | memset(buffer, 0, cenc_size); |
1078 | 1081 | ||
1079 | fprintf(stderr, "[INFO] Decompressing encoded block... "); | 1082 | log_message("[INFO] Decompressing encoded block... "); |
1080 | 1083 | ||
1081 | if(!cenc_decode(&out_buffer[i+12], le2int(&out_buffer[i+4])-4, &buffer[0], cenc_size)) | 1084 | if(!cenc_decode(&out_buffer[i+12], le2int(&out_buffer[i+4])-4, &buffer[0], cenc_size)) |
1082 | { | 1085 | { |
1083 | fprintf(stderr, "Fail!\n[ERR] Couldn't decompress the encoded block\n"); | 1086 | log_message("Fail!\n[ERR] Couldn't decompress the encoded block\n"); |
1084 | fclose(bootfd); | 1087 | fclose(bootfd); |
1085 | fclose(outfd); | 1088 | fclose(outfd); |
1086 | free(out_buffer); | 1089 | free(out_buffer); |
@@ -1088,9 +1091,9 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
1088 | return -21; | 1091 | return -21; |
1089 | } | 1092 | } |
1090 | 1093 | ||
1091 | fprintf(stderr, "Done!\n"); | 1094 | log_message("Done!\n"); |
1092 | 1095 | ||
1093 | fprintf(stderr, "[INFO] Renaming encoded block to Hcreativeos.jrm... "); | 1096 | log_message("[INFO] Renaming encoded block to Hcreativeos.jrm... "); |
1094 | 1097 | ||
1095 | memcpy(&enc_data, "ATAD", 4); | 1098 | memcpy(&enc_data, "ATAD", 4); |
1096 | int2le(cenc_size+32, &enc_data[4]); | 1099 | int2le(cenc_size+32, &enc_data[4]); |
@@ -1098,7 +1101,7 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
1098 | memcpy(&enc_data[8], "H\0c\0r\0e\0a\0t\0i\0v\0e\0o\0s\0.\0j\0r\0m", 30); | 1101 | memcpy(&enc_data[8], "H\0c\0r\0e\0a\0t\0i\0v\0e\0o\0s\0.\0j\0r\0m", 30); |
1099 | if(fwrite(enc_data, 40, 1, outfd) != 1) | 1102 | if(fwrite(enc_data, 40, 1, outfd) != 1) |
1100 | { | 1103 | { |
1101 | fprintf(stderr, "Fail!\n[ERR] Short write\n"); | 1104 | log_message("Fail!\n[ERR] Short write\n"); |
1102 | fclose(bootfd); | 1105 | fclose(bootfd); |
1103 | fclose(outfd); | 1106 | fclose(outfd); |
1104 | free(out_buffer); | 1107 | free(out_buffer); |
@@ -1108,7 +1111,7 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
1108 | 1111 | ||
1109 | if(fwrite(&buffer[0], cenc_size, 1, outfd) != 1) | 1112 | if(fwrite(&buffer[0], cenc_size, 1, outfd) != 1) |
1110 | { | 1113 | { |
1111 | fprintf(stderr, "Fail!\n[ERR] Short write\n"); | 1114 | log_message("Fail!\n[ERR] Short write\n"); |
1112 | fclose(bootfd); | 1115 | fclose(bootfd); |
1113 | fclose(outfd); | 1116 | fclose(outfd); |
1114 | free(out_buffer); | 1117 | free(out_buffer); |
@@ -1117,7 +1120,7 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
1117 | } | 1120 | } |
1118 | 1121 | ||
1119 | free(buffer); | 1122 | free(buffer); |
1120 | fprintf(stderr, "Done!\n[INFO] Adding Hjukebox2.jrm... "); | 1123 | log_message("Done!\n[INFO] Adding Hjukebox2.jrm... "); |
1121 | 1124 | ||
1122 | memcpy(&enc_data, "ATAD", 4); | 1125 | memcpy(&enc_data, "ATAD", 4); |
1123 | int2le(filesize(bootfd)+32, &enc_data[4]); | 1126 | int2le(filesize(bootfd)+32, &enc_data[4]); |
@@ -1125,7 +1128,7 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
1125 | memcpy(&enc_data[8], "H\0j\0u\0k\0e\0b\0o\0x\0""2\0.\0j\0r\0m", 26); | 1128 | memcpy(&enc_data[8], "H\0j\0u\0k\0e\0b\0o\0x\0""2\0.\0j\0r\0m", 26); |
1126 | if(fwrite(enc_data, 40, 1, outfd) != 1) | 1129 | if(fwrite(enc_data, 40, 1, outfd) != 1) |
1127 | { | 1130 | { |
1128 | fprintf(stderr, "Fail!\n[ERR] Short write\n"); | 1131 | log_message("Fail!\n[ERR] Short write\n"); |
1129 | fclose(bootfd); | 1132 | fclose(bootfd); |
1130 | fclose(outfd); | 1133 | fclose(outfd); |
1131 | free(out_buffer); | 1134 | free(out_buffer); |
@@ -1134,7 +1137,7 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
1134 | 1137 | ||
1135 | if(fread(&out_buffer[ciff_size], filesize(bootfd), 1, bootfd) != 1) | 1138 | if(fread(&out_buffer[ciff_size], filesize(bootfd), 1, bootfd) != 1) |
1136 | { | 1139 | { |
1137 | fprintf(stderr, "Fail!\n[ERR] Short read\n"); | 1140 | log_message("Fail!\n[ERR] Short read\n"); |
1138 | fclose(bootfd); | 1141 | fclose(bootfd); |
1139 | fclose(outfd); | 1142 | fclose(outfd); |
1140 | free(out_buffer); | 1143 | free(out_buffer); |
@@ -1143,7 +1146,7 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
1143 | 1146 | ||
1144 | if(memcmp(&out_buffer[ciff_size], "EDOC", 4) != 0) | 1147 | if(memcmp(&out_buffer[ciff_size], "EDOC", 4) != 0) |
1145 | { | 1148 | { |
1146 | fprintf(stderr, "Fail!\n[ERR] Faulty bootloader\n"); | 1149 | log_message("Fail!\n[ERR] Faulty bootloader\n"); |
1147 | free(out_buffer); | 1150 | free(out_buffer); |
1148 | fclose(bootfd); | 1151 | fclose(bootfd); |
1149 | fclose(outfd); | 1152 | fclose(outfd); |
@@ -1152,7 +1155,7 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
1152 | 1155 | ||
1153 | if(fwrite(&out_buffer[ciff_size], filesize(bootfd), 1, outfd) != 1) | 1156 | if(fwrite(&out_buffer[ciff_size], filesize(bootfd), 1, outfd) != 1) |
1154 | { | 1157 | { |
1155 | fprintf(stderr, "Fail!\n[ERR] Short write\n"); | 1158 | log_message("Fail!\n[ERR] Short write\n"); |
1156 | fclose(bootfd); | 1159 | fclose(bootfd); |
1157 | fclose(outfd); | 1160 | fclose(outfd); |
1158 | free(out_buffer); | 1161 | free(out_buffer); |
@@ -1160,11 +1163,11 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
1160 | } | 1163 | } |
1161 | 1164 | ||
1162 | fclose(bootfd); | 1165 | fclose(bootfd); |
1163 | fprintf(stderr, "Done!\n"); | 1166 | log_message("Done!\n"); |
1164 | 1167 | ||
1165 | if(fwrite(&out_buffer[i+8+le2int(&out_buffer[i+4])], ciff_size-i-8-le2int(&out_buffer[i+4]), 1, outfd) != 1) | 1168 | if(fwrite(&out_buffer[i+8+le2int(&out_buffer[i+4])], ciff_size-i-8-le2int(&out_buffer[i+4]), 1, outfd) != 1) |
1166 | { | 1169 | { |
1167 | fprintf(stderr, "[ERR] Short write\n"); | 1170 | log_message("[ERR] Short write\n"); |
1168 | fclose(bootfd); | 1171 | fclose(bootfd); |
1169 | fclose(outfd); | 1172 | fclose(outfd); |
1170 | free(out_buffer); | 1173 | free(out_buffer); |
@@ -1175,7 +1178,7 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
1175 | int2le(filesize(outfd)-8-28, enc_data); | 1178 | int2le(filesize(outfd)-8-28, enc_data); |
1176 | if(fwrite(enc_data, 4, 1, outfd) != 1) | 1179 | if(fwrite(enc_data, 4, 1, outfd) != 1) |
1177 | { | 1180 | { |
1178 | fprintf(stderr, "[ERR] Short write\n"); | 1181 | log_message("[ERR] Short write\n"); |
1179 | fclose(outfd); | 1182 | fclose(outfd); |
1180 | free(out_buffer); | 1183 | free(out_buffer); |
1181 | return -29; | 1184 | return -29; |
@@ -1184,12 +1187,12 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
1184 | free(out_buffer); | 1187 | free(out_buffer); |
1185 | fflush(outfd); | 1188 | fflush(outfd); |
1186 | 1189 | ||
1187 | fprintf(stderr, "[INFO] Updating checksum... "); | 1190 | log_message("[INFO] Updating checksum... "); |
1188 | 1191 | ||
1189 | buffer = malloc(filesize(outfd)-28); | 1192 | buffer = malloc(filesize(outfd)-28); |
1190 | if(buffer == NULL) | 1193 | if(buffer == NULL) |
1191 | { | 1194 | { |
1192 | fprintf(stderr, "Fail!\n[ERR] Couldn't allocate %d unsigned chars\n", filesize(outfd)-28); | 1195 | log_message("Fail!\n[ERR] Couldn't allocate %d unsigned chars\n", filesize(outfd)-28); |
1193 | fclose(outfd); | 1196 | fclose(outfd); |
1194 | return -30; | 1197 | return -30; |
1195 | } | 1198 | } |
@@ -1197,7 +1200,7 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
1197 | fseek(outfd, 0, SEEK_SET); | 1200 | fseek(outfd, 0, SEEK_SET); |
1198 | if(fread(buffer, filesize(outfd)-28, 1, outfd) != 1) | 1201 | if(fread(buffer, filesize(outfd)-28, 1, outfd) != 1) |
1199 | { | 1202 | { |
1200 | fprintf(stderr, "Fail!\n[ERR] Short read\n"); | 1203 | log_message("Fail!\n[ERR] Short read\n"); |
1201 | fclose(outfd); | 1204 | fclose(outfd); |
1202 | free(buffer); | 1205 | free(buffer); |
1203 | return -31; | 1206 | return -31; |
@@ -1208,7 +1211,7 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
1208 | fseek(outfd, filesize(outfd)-20, SEEK_SET); | 1211 | fseek(outfd, filesize(outfd)-20, SEEK_SET); |
1209 | if(fwrite(hash_key, 20, 1, outfd) != 1) | 1212 | if(fwrite(hash_key, 20, 1, outfd) != 1) |
1210 | { | 1213 | { |
1211 | fprintf(stderr, "Fail!\n[ERR] Short write\n"); | 1214 | log_message("Fail!\n[ERR] Short write\n"); |
1212 | fclose(outfd); | 1215 | fclose(outfd); |
1213 | free(buffer); | 1216 | free(buffer); |
1214 | return -32; | 1217 | return -32; |
@@ -1216,7 +1219,7 @@ int mkboot(const char* infile, const char* bootfile, const char* outfile, struct | |||
1216 | 1219 | ||
1217 | fclose(outfd); | 1220 | fclose(outfd); |
1218 | 1221 | ||
1219 | fprintf(stderr, "Done!\n"); | 1222 | log_message("Done!\n"); |
1220 | return 0; | 1223 | return 0; |
1221 | } | 1224 | } |
1222 | 1225 | ||
@@ -1225,14 +1228,25 @@ static void usage(void) | |||
1225 | { | 1228 | { |
1226 | int i; | 1229 | int i; |
1227 | 1230 | ||
1228 | printf("Usage: mkzenboot <firmware file> <boot file> <output file> <player>\n"); | 1231 | fprintf(stdout, "Usage: mkzenboot <firmware file> <boot file> <output file> <player>\n"); |
1229 | printf("Players:\n"); | 1232 | fprintf(stdout, "Players:\n"); |
1230 | for (i = 0; players[i].name != NULL; i++) | 1233 | for (i = 0; players[i].name != NULL; i++) |
1231 | printf(" * \"%s\"\n", players[i].name); | 1234 | fprintf(stdout, " * \"%s\"\n", players[i].name); |
1232 | 1235 | ||
1233 | exit(1); | 1236 | exit(1); |
1234 | } | 1237 | } |
1235 | 1238 | ||
1239 | void log_message(const char* format, ...) | ||
1240 | { | ||
1241 | va_list ap; | ||
1242 | |||
1243 | va_start(ap, format); | ||
1244 | |||
1245 | vfprintf(stderr, format, ap); | ||
1246 | |||
1247 | va_end(ap); | ||
1248 | } | ||
1249 | |||
1236 | int main(int argc, char *argv[]) | 1250 | int main(int argc, char *argv[]) |
1237 | { | 1251 | { |
1238 | char *infile, *bootfile, *outfile; | 1252 | char *infile, *bootfile, *outfile; |
diff --git a/utils/wpseditor/screenshot/main.c b/utils/wpseditor/screenshot/main.c index fb81e069b0..72d75ab54d 100644 --- a/utils/wpseditor/screenshot/main.c +++ b/utils/wpseditor/screenshot/main.c | |||
@@ -70,23 +70,27 @@ static gdImagePtr backdrop; | |||
70 | extern gdImagePtr gdImageCreateFromBmp(FILE * inFile); | 70 | extern gdImagePtr gdImageCreateFromBmp(FILE * inFile); |
71 | extern char *get_current_dir_name (void) __THROW; | 71 | extern char *get_current_dir_name (void) __THROW; |
72 | 72 | ||
73 | static bool next_nl = false; | ||
74 | |||
73 | int _debug(const char* fmt,...) | 75 | int _debug(const char* fmt,...) |
74 | { | 76 | { |
75 | #if 0 /* Doesn't want to compile ?? */ | 77 | va_list ap; |
76 | struct va_list ap; | ||
77 | 78 | ||
78 | va_start(ap, fmt); | 79 | va_start(ap, fmt); |
79 | 80 | ||
80 | fprintf(stdout, "[DBG] "); | 81 | if(!next_nl) |
82 | fprintf(stdout, "[DBG] "); | ||
83 | |||
81 | vfprintf(stdout, fmt, ap); | 84 | vfprintf(stdout, fmt, ap); |
82 | fprintf(stdout, "\n"); | 85 | |
86 | if(fmt[strlen(fmt)-1] != 0xa) | ||
87 | next_nl = true; | ||
88 | else | ||
89 | next_nl = false; | ||
83 | 90 | ||
84 | va_end(ap); | 91 | va_end(ap); |
85 | 92 | ||
86 | return 0; | 93 | return 0; |
87 | #else | ||
88 | return -1; | ||
89 | #endif | ||
90 | } | 94 | } |
91 | 95 | ||
92 | void _putsxy(int x, int y, const unsigned char *str) | 96 | void _putsxy(int x, int y, const unsigned char *str) |
@@ -106,7 +110,7 @@ void _transparent_bitmap_part(const void *src, int src_x, int src_y, | |||
106 | gdImagePtr image; | 110 | gdImagePtr image; |
107 | int pink; | 111 | int pink; |
108 | 112 | ||
109 | DEBUGF2("transparent_bitmap_part(const void *src=%s, int src_x=%d, int src_y=%d, int stride=%d, int x=%d, int y=%d, int width=%d, int height=%d", (char*)src, src_x, src_y, stride, x, y, width, height); | 113 | DEBUGF2("transparent_bitmap_part(const void *src=%s, int src_x=%d, int src_y=%d, int stride=%d, int x=%d, int y=%d, int width=%d, int height=%d\n", (char*)src, src_x, src_y, stride, x, y, width, height); |
110 | 114 | ||
111 | _image = fopen(src, "rb"); | 115 | _image = fopen(src, "rb"); |
112 | if(_image == NULL) | 116 | if(_image == NULL) |
@@ -129,7 +133,7 @@ void _bitmap_part(const void *src, int src_x, int src_y, | |||
129 | FILE *_image; | 133 | FILE *_image; |
130 | gdImagePtr image; | 134 | gdImagePtr image; |
131 | 135 | ||
132 | DEBUGF2("bitmap_part(const void *src=%s, int src_x=%d, int src_y=%d, int stride=%d, int x=%d, int y=%d, int width=%d, int height=%d", (char*)src, src_x, src_y, stride, x, y, width, height); | 136 | DEBUGF2("bitmap_part(const void *src=%s, int src_x=%d, int src_y=%d, int stride=%d, int x=%d, int y=%d, int width=%d, int height=%d\n", (char*)src, src_x, src_y, stride, x, y, width, height); |
133 | 137 | ||
134 | _image = fopen(src, "rb"); | 138 | _image = fopen(src, "rb"); |
135 | if(_image == NULL) | 139 | if(_image == NULL) |
@@ -231,6 +235,7 @@ static int screenshot(char *model, char *wps, char *png) | |||
231 | char lib[255]; | 235 | char lib[255]; |
232 | void *handle; | 236 | void *handle; |
233 | FILE *out, *in; | 237 | FILE *out, *in; |
238 | int res; | ||
234 | 239 | ||
235 | in = fopen(wps, "rb"); | 240 | in = fopen(wps, "rb"); |
236 | if(in == NULL) | 241 | if(in == NULL) |
@@ -287,25 +292,19 @@ static int screenshot(char *model, char *wps, char *png) | |||
287 | api.read_bmp_file = &_read_bmp_file; | 292 | api.read_bmp_file = &_read_bmp_file; |
288 | api.debugf = &_debug; | 293 | api.debugf = &_debug; |
289 | 294 | ||
290 | wps_init(wps, &api, true); | 295 | res = wps_init(wps, &api, true); |
291 | 296 | if(res != 1) | |
292 | framebuffer = gdImageCreateTrueColor(api.getwidth(), api.getheight()); | ||
293 | |||
294 | _drawBackdrop(); | ||
295 | |||
296 | if(strcmp(api.get_model_name(), model) != 0) | ||
297 | { | 297 | { |
298 | fprintf(stderr, "[ERR] Model name doesn't match the one supplied by the library\n"); | 298 | fprintf(stderr, "[ERR] WPS wasn't correctly inited\n"); |
299 | fprintf(stderr, " %s <-> %s\n", model, api.get_model_name()); | ||
300 | dlclose(handle); | 299 | dlclose(handle); |
301 | fclose(out); | 300 | fclose(out); |
302 | gdImageDestroy(framebuffer); | ||
303 | gdImageDestroy(backdrop); | ||
304 | wps_init = NULL; | ||
305 | wps_display = NULL; | ||
306 | wps_refresh = NULL; | ||
307 | return -5; | 301 | return -5; |
308 | } | 302 | } |
303 | |||
304 | framebuffer = gdImageCreateTrueColor(api.getwidth(), api.getheight()); | ||
305 | |||
306 | _drawBackdrop(); | ||
307 | |||
309 | fprintf(stdout, "[INFO] Model: %s\n", api.get_model_name()); | 308 | fprintf(stdout, "[INFO] Model: %s\n", api.get_model_name()); |
310 | 309 | ||
311 | wpsdata.fontheight = getFont()->h; | 310 | wpsdata.fontheight = getFont()->h; |
@@ -323,7 +322,8 @@ static int screenshot(char *model, char *wps, char *png) | |||
323 | dlclose(handle); | 322 | dlclose(handle); |
324 | fclose(out); | 323 | fclose(out); |
325 | gdImageDestroy(framebuffer); | 324 | gdImageDestroy(framebuffer); |
326 | gdImageDestroy(backdrop); | 325 | if(backdrop != NULL) |
326 | gdImageDestroy(backdrop); | ||
327 | 327 | ||
328 | wps_init = NULL; | 328 | wps_init = NULL; |
329 | wps_display = NULL; | 329 | wps_display = NULL; |
@@ -334,8 +334,15 @@ static int screenshot(char *model, char *wps, char *png) | |||
334 | 334 | ||
335 | static void usage(void) | 335 | static void usage(void) |
336 | { | 336 | { |
337 | fprintf(stderr, "Usage: screenshot [-V] <MODEL> <WPS_FILE> <OUT_PNG>\n"); | 337 | fprintf(stderr, "Rockbox WPS screenshot utility\n"); |
338 | fprintf(stderr, "Example: screenshot h10_5gb iCatcher.wps out.png\n"); | 338 | fprintf(stderr, "Made by Maurus Cuelenaere\n"); |
339 | fprintf(stderr, "\n"); | ||
340 | fprintf(stderr, "Usage: screenshot [-V] <MODEL> <WPS> <OUT>.png\n"); | ||
341 | fprintf(stderr, " -> creates a PNG screenshot of the WPS for the specific MODEL\n"); | ||
342 | fprintf(stderr, " -> libwps_<MODEL>.so must be present in the same directory\n"); | ||
343 | fprintf(stderr, " -> -V sets verbose mode ON\n"); | ||
344 | fprintf(stderr, "\n"); | ||
345 | fprintf(stderr, "Example: screenshot IRIVER_H10_5GB iCatcher.wps out.png\n"); | ||
339 | } | 346 | } |
340 | 347 | ||
341 | int main(int argc, char ** argv) | 348 | int main(int argc, char ** argv) |
@@ -346,6 +353,15 @@ int main(int argc, char ** argv) | |||
346 | return -1; | 353 | return -1; |
347 | } | 354 | } |
348 | 355 | ||
356 | if(argv[1] == NULL || argv[2] == NULL || | ||
357 | argv[3] == NULL || | ||
358 | (strcmp(argv[1], "-V") == 0 && argv[4] == NULL) | ||
359 | ) | ||
360 | { | ||
361 | usage(); | ||
362 | return -1; | ||
363 | } | ||
364 | |||
349 | if(strcmp(argv[1], "-V") == 0) | 365 | if(strcmp(argv[1], "-V") == 0) |
350 | { | 366 | { |
351 | verbose = true; | 367 | verbose = true; |