Exemplo n.º 1
0
static void de_run_t64(deark *c, de_module_params *mparams)
{
	lctx *d = NULL;
	de_int64 pos;
	de_int64 i;

	d = de_malloc(c, sizeof(lctx));

	pos = 32;
	d->version = de_getui16le(pos);
	de_dbg(c, "version: 0x%04x\n", (int)d->version);
	if(d->version!=0x100 && d->version!=0x101) {
		de_warn(c, "Unexpected version number. This might not be a T64 file.\n");
	}

	d->max_dir_entries = de_getui16le(pos+2);
	d->used_dir_entries = de_getui16le(pos+4);
	de_dbg(c, "max dir entries = %d, files = %d\n", (int)d->max_dir_entries, (int)d->used_dir_entries);

	pos += 32;
	for(i=0; i<d->max_dir_entries; i++) {
		do_dir_entry(c, d, i, pos+32*i);
	}

	de_free(c, d);
}
Exemplo n.º 2
0
void process_directory(const u8* base, const char* dir, u32 offset, u32 size,
		  const char* path)
{
   struct cramfs_inode* de;
   char* name;
   int namelen;
   u32 current=offset;
   u32 dirend=offset+size;
   
   // Do files
   while (current < dirend) {
      u32 nextoffset;
      
      de=(struct cramfs_inode*)(base+current);
      namelen=de->namelen<<2;
      nextoffset=current+sizeof(struct cramfs_inode)+namelen;
      
      name=(char*)(de+1);
      
      while (1) {
	 assert(namelen!=0);
	 
	 if (name[namelen-1])
	   break;
	 namelen--;
      }

      do_file_entry(base, dir, path, name, namelen, de);
      
      current=nextoffset;
   }

   // Recurse into directories
   current=offset;
   while (current < dirend) {
      u32 nextoffset;
      
      de=(struct cramfs_inode*)(base+current);
      namelen=de->namelen<<2;
      nextoffset=current+sizeof(struct cramfs_inode)+namelen;
      
      name=(char*)(de+1);
      
      while (1) {
	 assert(namelen!=0);
	 
	 if (name[namelen-1])
	   break;
	 namelen--;
      }

      do_dir_entry(base, dir, path, name, namelen, de);
      
      current=nextoffset;
   }
}
Exemplo n.º 3
0
int uncramfs(char const *dirname, char const *imagefile) {

	struct stat st;
	int fd;
	size_t fslen_ub;
	u8 const *rom_image;
	struct cramfs_super const *sb;

	// Check the directory
	if (access(dirname, W_OK) == -1) {
		if (errno != ENOENT) {
			perror(dirname);
			exit(1);
		}
	}
	// Check the image file
	if (stat(imagefile, &st) == -1) {
		perror(imagefile);
		exit(1);
	}
	// Map the cramfs image
	fd = open(imagefile, O_RDONLY);
	fslen_ub = st.st_size;
	rom_image = mmap(0, fslen_ub, PROT_READ, MAP_SHARED, fd, 0);
	if (rom_image == MAP_FAILED) {
		perror("Mapping cramfs file");
		exit(1);
	}

	sb = (struct cramfs_super const *)(rom_image);
	// Check cramfs magic number and signature
	if (CRAMFS_MAGIC != sb->magic || 0 != memcmp(sb->signature, CRAMFS_SIGNATURE, sizeof(sb->signature))) {
		fprintf(stderr, "The image file doesn't have cramfs signatures\n");
		exit(1);
	}
	// Set umask to 0 to let the image modes shine through
	umask(0);

	clearstats();

	// Start doing...
	do_file_entry(rom_image, dirname, "", "", 0, &sb->root);
	do_dir_entry(rom_image, dirname, "", "", 0, &sb->root);

	return 0;
}
Exemplo n.º 4
0
/*
 * Usage:
 *
 *      uncramfs directory-name outfile
 *
 * where "directory-name" is simply the root of the directory
 * tree that we want to expand the compressed filesystem into.
 */
int main(int argc, char **argv)
{
   char const* dirname;
   char const* imagefile;
   struct stat st;
   int fd;
   size_t fslen_ub;
   u8 const* rom_image;
   struct cramfs_super const* sb;
   int i;

   // Check the program usage
   if (argc)
     progname = argv[0];
   if (argc != 3 && argc != 5 && argc != 7)
     usage();

   if (argc == 3) {
      dirname=argv[1];
      imagefile=argv[2];
   } else if (argc == 5) {
      if (strcmp(argv[1],"-d")==0) {
         opt_devfile = argv[2];
      } else if (strcmp(argv[1],"-m")==0) {
         opt_idsfile = argv[2];
      } else
         usage();
      dirname=argv[3];
      imagefile=argv[4];
   } else {
      if (strcmp(argv[1],"-d")==0) {
         opt_devfile = argv[2];
      } else if (strcmp(argv[1],"-m")==0) {
         opt_idsfile = argv[2];
      } else
         usage();

      if (strcmp(argv[3],"-d")==0 && !opt_devfile) {
         opt_devfile = argv[4];
      } else if (strcmp(argv[3],"-m")==0 && !opt_idsfile) {
         opt_idsfile = argv[4];
      } else
         usage();
      dirname=argv[5];
      imagefile=argv[6];
   }
   
   // Check the directory
   if (access(dirname, W_OK) == -1) {
      if (errno != ENOENT ) {
	 perror(dirname);
	 exit(1);
      }
   }
   
   // Check the image file
   if (stat(imagefile, &st) == -1) {
      perror(imagefile);
      exit(1);
   }

   // Map the cramfs image
   fd = open(imagefile, O_RDONLY);
   fslen_ub = st.st_size;
   rom_image = mmap(0, fslen_ub, PROT_READ, MAP_SHARED, fd, 0);
   if (rom_image == MAP_FAILED) {
      perror("Mapping cramfs file");
      exit(1);
   }
   
   sb=(struct cramfs_super const*)(rom_image);
   // Check cramfs magic number and signature
   if (CRAMFS_MAGIC != sb->magic ||
       0 != memcmp(sb->signature, CRAMFS_SIGNATURE, sizeof(sb->signature))) {
      fprintf(stderr,"The image file doesn't have cramfs signatures\n");
      exit(1);
   }

   // Set umask to 0 to let the image modes shine through
   umask(0);
   
   // Print some reassuring blurb
   printf("[Volume size: 0x%x]\n", fslen_ub);
   printf("[Volume serial: ");
   for (i=0; i< sizeof(sb->fsid); ++i)
     printf("%02x", sb->fsid[i]);
   printf("]\n");
   printf("[Volume name: %s]\n", sb->name);
   printf("\n");

   clearstats();
   
   // Start doing...
   printf("do file entry \n");
   do_file_entry(rom_image, dirname, "", "", 0, &sb->root);
   printf("do dir entry\n");
   do_dir_entry(rom_image, dirname, "", "", 0, &sb->root);
   
   //process_directory(rom_image, dirname, sb->root.offset<<2, sb->root.size, ".");
   
   printstats();
   return 0;
}