Subversion Repositories freemyipod

Rev

Rev 141 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 141 Rev 142
Line 21... Line 21...
21
  -- Initial version
21
  -- Initial version
22
 
22
 
23
  1.1 - 2007-09-15
23
  1.1 - 2007-09-15
24
  -- Stuff added to guess the header versions.
24
  -- Stuff added to guess the header versions.
25
 
25
 
-
 
26
  1.2 - 2010-08-15
-
 
27
  -- Added Nano 4G firmware support.
-
 
28
 
26
  Todo list:
29
  Todo list:
27
  -- Debug
30
  -- Debug
28
*/
31
*/
29
 
32
 
30
#include <stdlib.h>
33
#include <stdlib.h>
Line 34... Line 37...
34
#include <limits.h>
37
#include <limits.h>
35
 
38
 
36
#include "extract2g.h"
39
#include "extract2g.h"
37
 
40
 
38
#define VERSION_H 1
41
#define VERSION_H 1
39
#define VERSION_L 1
42
#define VERSION_L 2
40
 
43
 
41
#define B (0x0FFFFFFF)
44
#define B (0x0FFFFFFF)
42
 
45
 
43
/* Change endian of a 4 bytes memory zone */
46
/* Change endian of a 4 bytes memory zone */
44
void change_endian( char* buf )
47
void change_endian( char* buf )
Line 228... Line 231...
228
  else
231
  else
229
  {
232
  {
230
    fputs("Usage: extract_2g [OPTION] [FILE]\n", stdout);
233
    fputs("Usage: extract_2g [OPTION] [FILE]\n", stdout);
231
    fprintf(stdout,"Read & extract iPod Nano 2G data parts from a FILE dump.\n\
234
    fprintf(stdout,"Read & extract iPod Nano 2G data parts from a FILE dump.\n\
232
\n\
235
\n\
233
 -l, --list               only list avaible parts according to the dump directory\n\n\
236
-l, --list               only list avaible parts according to the dump directory\n\n\
234
 -H, --hash               do a hash on every part of the dump\n\n\
237
-H, --hash               do a hash on every part of the dump\n\n\
235
 -A, --all                extract ALL founded parts from dump (default names used)\n\n\
238
-A, --all                extract ALL founded parts from dump (default names used)\n\n\
-
 
239
-4, --nano4g-compat      forces iPod Nano 3G firmwares to be recognised as iPod Nano 4G's\n\n\
236
 -e, --extract=NAME       select which part you want to extract (default none)\n\
240
-e, --extract=NAME       select which part you want to extract (default none)\n\
237
 -o, --output=FILE        put the extracted part into FILE (default NAME.fw)\n\n\
241
-o, --output=FILE        put the extracted part into FILE (default NAME.fw)\n\n\
238
 -d, --directory-address  specify the directory address (default 0x%X )\n\
242
-d, --directory-address  specify the directory address (default 0x%X )\n\
239
 -a, --header-length      specify the header length of each part (default 0x800)\n\n\
243
-a, --header-length      specify the header length of each part (default 0x800)\n\n\
240
 -h, --help               display this help and exit\n", ADDR_DIR_DEFAULT);
244
-h, --help               display this help and exit\n", ADDR_DIR_DEFAULT);
241
  }
245
  }
242
 
246
 
243
  exit(status);
247
  exit(status);
244
}
248
}
245
 
249
 
Line 250... Line 254...
250
 
254
 
251
  char str_target[32];
255
  char str_target[32];
252
 
256
 
253
  char extract_is_set = 0;
257
  char extract_is_set = 0;
254
  char extract_all = 0;
258
  char extract_all = 0;
-
 
259
  char nano4g_compat = 0;
255
  char list_directories = 0;
260
  char list_directories = 0;
256
  char is_found = 0;
261
  char is_found = 0;
257
  char hash_parts = 0;
262
  char hash_parts = 0;
258
 
263
 
259
  /* REMOVE */
264
  /* REMOVE */
Line 269... Line 274...
269
  int addr_directory = -1;
274
  int addr_directory = -1;
270
 
275
 
271
  int length_header = LEN_HEADER;
276
  int length_header = LEN_HEADER;
272
 
277
 
273
  /* Getopt short options */
278
  /* Getopt short options */
274
  static char const short_options[] = "e:o:d:a:AHlhv";
279
  static char const short_options[] = "e:o:d:a:AHl4hv";
275
  
280
  
276
  /* Getopt long options */
281
  /* Getopt long options */
277
  static struct option const long_options[] = {
282
  static struct option const long_options[] = {
278
    {"extract", required_argument, NULL, 'e'},
283
    {"extract", required_argument, NULL, 'e'},
279
    {"output", required_argument, NULL, 'o'},
284
    {"output", required_argument, NULL, 'o'},
280
    {"hash", no_argument, NULL, 'H'},
285
    {"hash", no_argument, NULL, 'H'},
281
    {"list", no_argument, NULL, 'l'},
286
    {"list", no_argument, NULL, 'l'},
282
    {"all", no_argument, NULL, 'A'},
287
    {"all", no_argument, NULL, 'A'},
283
    {"directory-address", required_argument, NULL, 'd'},
288
    {"directory-address", required_argument, NULL, 'd'},
284
    {"header-length", required_argument, NULL, 'a'},
289
    {"header-length", required_argument, NULL, 'a'},
-
 
290
    {"nano4g-compat", no_argument, NULL, '4'},
285
    {"help", no_argument, NULL, 'h'},
291
    {"help", no_argument, NULL, 'h'},
286
    {"version", no_argument, NULL, 'v'},
292
    {"version", no_argument, NULL, 'v'},
287
    {NULL, 0, NULL, 0}
293
    {NULL, 0, NULL, 0}
288
  };
294
  };
289
 
295
 
Line 338... Line 344...
338
 
344
 
339
    case 'A':
345
    case 'A':
340
        extract_all = 1;
346
        extract_all = 1;
341
      break;
347
      break;
342
 
348
 
-
 
349
    case '4':
-
 
350
        nano4g_compat = 1;
-
 
351
      break;
-
 
352
 
343
    case 'h':
353
    case 'h':
344
      usage(EXIT_SUCCESS);
354
      usage(EXIT_SUCCESS);
345
      break;
355
      break;
346
      
356
      
347
    case 'v':
357
    case 'v':
Line 373... Line 383...
373
  if( addr_directory < 0 )
383
  if( addr_directory < 0 )
374
    addr_directory = guess_directory_address(file);
384
    addr_directory = guess_directory_address(file);
375
  else
385
  else
376
    addr_directory = ADDR_DIR_DEFAULT;
386
    addr_directory = ADDR_DIR_DEFAULT;
377
 
387
 
-
 
388
  if (addr_directory == ADDR_DIR_3G && nano4g_compat)
-
 
389
    printf("> iPod nano 4g compat. mode enabled\n");
-
 
390
 
378
 
391
 
379
  fseek(file, addr_directory, SEEK_SET);
392
  fseek(file, addr_directory, SEEK_SET);
380
   
393
   
381
  DIRECTORY dir;
394
  DIRECTORY dir;
382
 
395
 
Line 402... Line 415...
402
      if(!directories)
415
      if(!directories)
403
      {
416
      {
404
        fprintf(stderr,"Memory allocation failure.\n");
417
        fprintf(stderr,"Memory allocation failure.\n");
405
        exit(EXIT_FAILURE);
418
        exit(EXIT_FAILURE);
406
      }
419
      }
-
 
420
	  
-
 
421
	  if (addr_directory == ADDR_DIR_3G && nano4g_compat)
-
 
422
        dir.devOffset += 4096;
407
 
423
	  
408
      memcpy(directories + directories_size - 1, &dir, sizeof(DIRECTORY));
424
      memcpy(directories + directories_size - 1, &dir, sizeof(DIRECTORY));
409
    }
425
    }
410
    else
426
    else
411
      break;
427
      break;
412
  }
428
  }