summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/ipodpatcher/ipodpatcher.c45
1 files changed, 32 insertions, 13 deletions
diff --git a/tools/ipodpatcher/ipodpatcher.c b/tools/ipodpatcher/ipodpatcher.c
index 3144107a0c..38b13de2a2 100644
--- a/tools/ipodpatcher/ipodpatcher.c
+++ b/tools/ipodpatcher/ipodpatcher.c
@@ -29,7 +29,7 @@
29#include "parttypes.h" 29#include "parttypes.h"
30#include "ipodio.h" 30#include "ipodio.h"
31 31
32#define VERSION "0.7" 32#define VERSION "0.8svn"
33 33
34int verbose = 0; 34int verbose = 0;
35 35
@@ -1012,6 +1012,8 @@ int read_directory(struct ipod_t* ipod)
1012 unsigned char* p; 1012 unsigned char* p;
1013 unsigned short version; 1013 unsigned short version;
1014 1014
1015 ipod->nimages=0;
1016
1015 /* Read firmware partition header (first 512 bytes of disk - but 1017 /* Read firmware partition header (first 512 bytes of disk - but
1016 let's read a whole sector) */ 1018 let's read a whole sector) */
1017 1019
@@ -1028,7 +1030,7 @@ int read_directory(struct ipod_t* ipod)
1028 } 1030 }
1029 1031
1030 if (memcmp(sectorbuf,apple_stop_sign,sizeof(apple_stop_sign))!=0) { 1032 if (memcmp(sectorbuf,apple_stop_sign,sizeof(apple_stop_sign))!=0) {
1031 fprintf(stderr,"[ERR] Firmware partition doesn't contain Apple copyright, aborting."); 1033 fprintf(stderr,"[ERR] Firmware partition doesn't contain Apple copyright, aborting.\n");
1032 return -1; 1034 return -1;
1033 } 1035 }
1034 1036
@@ -1059,7 +1061,6 @@ int read_directory(struct ipod_t* ipod)
1059 return -1; 1061 return -1;
1060 } 1062 }
1061 1063
1062 ipod->nimages=0;
1063 p = sectorbuf + x; 1064 p = sectorbuf + x;
1064 1065
1065 while ((ipod->nimages < MAX_IMAGES) && (p < (sectorbuf + x + 400)) && 1066 while ((ipod->nimages < MAX_IMAGES) && (p < (sectorbuf + x + 400)) &&
@@ -1213,6 +1214,7 @@ int ipod_scan(struct ipod_t* ipod)
1213 int i; 1214 int i;
1214 int n = 0; 1215 int n = 0;
1215 int ipod_version; 1216 int ipod_version;
1217 char last_ipod[4096];
1216 1218
1217 printf("[INFO] Scanning disk devices...\n"); 1219 printf("[INFO] Scanning disk devices...\n");
1218 1220
@@ -1257,21 +1259,27 @@ int ipod_scan(struct ipod_t* ipod)
1257 printf("[INFO] Ipod found - %s (\"%s\") - %s\n", 1259 printf("[INFO] Ipod found - %s (\"%s\") - %s\n",
1258 ipod->modelstr,ipod->macpod ? "macpod" : "winpod",ipod->diskname); 1260 ipod->modelstr,ipod->macpod ? "macpod" : "winpod",ipod->diskname);
1259#endif 1261#endif
1262
1260 if (ipod->macpod) { 1263 if (ipod->macpod) {
1261 print_macpod_warning(); 1264 print_macpod_warning();
1262 } 1265 }
1263 n++; 1266 n++;
1267 strcpy(last_ipod,ipod->diskname);
1264 } 1268 }
1265 1269
1266 if (n==0) { 1270 if (n==0) {
1267 fprintf(stderr,"[ERR] No ipods found.\n"); 1271 fprintf(stderr,"[ERR] No ipods found.\n");
1272 } else if (n==1) {
1273 /* Remember the disk name */
1274 strcpy(ipod->diskname,last_ipod);
1268 } 1275 }
1269 return 0; 1276 return n;
1270} 1277}
1271 1278
1272int main(int argc, char* argv[]) 1279int main(int argc, char* argv[])
1273{ 1280{
1274 int i; 1281 int i;
1282 int n;
1275 int infile, outfile; 1283 int infile, outfile;
1276 unsigned int inputsize; 1284 unsigned int inputsize;
1277 char* filename; 1285 char* filename;
@@ -1283,8 +1291,7 @@ int main(int argc, char* argv[])
1283 fprintf(stderr,"This is free software; see the source for copying conditions. There is NO\n"); 1291 fprintf(stderr,"This is free software; see the source for copying conditions. There is NO\n");
1284 fprintf(stderr,"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n"); 1292 fprintf(stderr,"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\n");
1285 1293
1286 if ((argc < 2) || (strcmp(argv[1],"-h")==0) || 1294 if ((argc > 1) && ((strcmp(argv[1],"-h")==0) || (strcmp(argv[1],"--help")==0))) {
1287 (strcmp(argv[1],"--help")==0)) {
1288 print_usage(); 1295 print_usage();
1289 return 1; 1296 return 1;
1290 } 1297 }
@@ -1293,21 +1300,33 @@ int main(int argc, char* argv[])
1293 fprintf(stderr,"Failed to allocate memory buffer\n"); 1300 fprintf(stderr,"Failed to allocate memory buffer\n");
1294 } 1301 }
1295 1302
1296 if (strcmp(argv[1],"--scan")==0) { 1303 if ((argc > 1) && (strcmp(argv[1],"--scan")==0)) {
1297 ipod_scan(&ipod); 1304 ipod_scan(&ipod);
1298 return 0; 1305 return 0;
1299 } 1306 }
1300 1307
1301 i = 1; 1308 /* If the first parameter doesn't start with -, then we interpret it as a device */
1302 ipod.diskname[0]=0; 1309 if ((argc > 1) && (argv[1][0] != '-')) {
1303 1310 ipod.diskname[0]=0;
1304#ifdef __WIN32__ 1311#ifdef __WIN32__
1305 snprintf(ipod.diskname,sizeof(ipod.diskname),"\\\\.\\PhysicalDrive%s",argv[1]); 1312 snprintf(ipod.diskname,sizeof(ipod.diskname),"\\\\.\\PhysicalDrive%s",argv[1]);
1306#else 1313#else
1307 strncpy(ipod.diskname,argv[1],sizeof(ipod.diskname)); 1314 strncpy(ipod.diskname,argv[1],sizeof(ipod.diskname));
1308#endif 1315#endif
1316 i = 2;
1317 } else {
1318 /* Autoscan for ipods */
1319 n = ipod_scan(&ipod);
1320 if (n==0) {
1321 fprintf(stderr,"[ERR] No ipods found, aborting\n");
1322 return 0;
1323 } else if (n > 1) {
1324 fprintf(stderr,"[ERR] %d ipods found, aborting\n",n);
1325 return 0;
1326 }
1327 i = 1;
1328 }
1309 1329
1310 i = 2;
1311 while (i < argc) { 1330 while (i < argc) {
1312 if ((strcmp(argv[i],"-l")==0) || (strcmp(argv[i],"--list")==0)) { 1331 if ((strcmp(argv[i],"-l")==0) || (strcmp(argv[i],"--list")==0)) {
1313 action = LIST_IMAGES; 1332 action = LIST_IMAGES;