コード例 #1
0
ファイル: rfs.c プロジェクト: AndrewSmart/testdisk
int recover_rfs(disk_t *disk_car, const struct reiserfs_super_block *sb,partition_t *partition,const int verbose, const int dump_ind)
{
  const struct reiser4_master_sb *sb4=(const struct reiser4_master_sb *)sb;
  if(test_rfs(disk_car, sb, partition, verbose)==0)
  {
    if(verbose>0 || dump_ind!=0)
    {
      log_info("\nrecover_rfs\n");
      log_info("block_count=%u\n",(unsigned int)le32(sb->s_block_count));
      log_info("block_size=%u\n",le16(sb->s_blocksize));
      if(dump_ind!=0)
      {
	dump_log(sb,DEFAULT_SECTOR_SIZE);
      }
    }
    partition->part_size = (uint64_t)le32(sb->s_block_count) * le16(sb->s_blocksize);
    partition->part_type_i386 = P_LINUX;
    partition->part_type_mac= PMAC_LINUX;
    partition->part_type_sun= PSUN_LINUX;
    partition->part_type_gpt=GPT_ENT_TYPE_LINUX_DATA;
    guid_cpy(&partition->part_uuid, (const efi_guid_t *)&sb->s_uuid);
    set_rfs_info(sb, partition);
    return 0;
  }
  if(test_rfs4(disk_car, sb4, partition, verbose)==0)
  {
    const struct format40_super *fmt40_super=(const struct format40_super *)((const char*)sb4+le16(sb4->blocksize));
    if(verbose>0 || dump_ind!=0)
    {
      log_info("\nrecover_rfs\n");
      log_info("block_count=%lu\n",(unsigned long int)le64(fmt40_super->sb_block_count));
      log_info("block_size=%u\n",le16(sb4->blocksize));
      if(dump_ind!=0)
      {
	dump_log(sb,DEFAULT_SECTOR_SIZE);
      }
    }
    partition->part_size = (uint64_t)le64(fmt40_super->sb_block_count) * le16(sb4->blocksize);
    partition->part_type_i386 = P_LINUX;
    partition->part_type_mac= PMAC_LINUX;
    partition->part_type_sun= PSUN_LINUX;
    partition->part_type_gpt=GPT_ENT_TYPE_LINUX_DATA;
    guid_cpy(&partition->part_uuid, (const efi_guid_t *)&sb4->uuid);
    set_rfs4_info(sb4, partition);
    return 0;
  }
  return 1;
}
コード例 #2
0
ファイル: ipp.c プロジェクト: andreiw/polaris
/*ARGSUSED*/
static int
packet(
	uintptr_t	addr,
	uint_t		flags,
	int		argc,
	const mdb_arg_t	*argv)
{
	ipp_packet_t	*pp;

	if ((flags & DCMD_ADDRSPEC) == 0)
		return (DCMD_ERR);

	pp = mdb_alloc(sizeof (ipp_packet_t), UM_SLEEP);
	if (mdb_vread(pp, sizeof (ipp_packet_t), addr) == -1) {
		mdb_warn("failed to read ipp_packet_t at %p", addr);
		mdb_free(pp, sizeof (ipp_packet_t));
		return (DCMD_ERR);
	}

	mdb_printf("%?p: %20s = 0x%p\n", addr, "data", pp->ippp_data);
	mdb_printf("%?s  %20s = 0x%p\n", "", "private", pp->ippp_private);
	dump_classes((uintptr_t)pp->ippp_class_array, pp->ippp_class_windex);
	dump_log((uintptr_t)pp->ippp_log, pp->ippp_log_windex);

	mdb_free(pp, sizeof (ipp_packet_t));
	return (DCMD_OK);
}
コード例 #3
0
ファイル: hpfs.c プロジェクト: Ctrlshiftm/ICU
static int test_HPFS(disk_t *disk_car,const struct fat_boot_sector *hpfs_header, partition_t *partition,const int verbose, const int dump_ind)
{
  const char*buffer=(const char*)hpfs_header;
  if(le16(hpfs_header->marker)==0xAA55)
  {
    if(memcmp(buffer+OS2_NAME,"IBM",3)==0)
    {   /* D'apres une analyse de OS2 sur systeme FAT...
           FAT_NAME1=FAT
         */
      if(verbose||dump_ind)
      {
        log_info("\nHPFS maybe at %u/%u/%u\n",
            offset2cylinder(disk_car,partition->part_offset),
            offset2head(disk_car,partition->part_offset),
            offset2sector(disk_car,partition->part_offset));
      }
      if(dump_ind!=0)
        dump_log(buffer, DEFAULT_SECTOR_SIZE);
      partition->part_size=(uint64_t)(fat_sectors(hpfs_header)>0?fat_sectors(hpfs_header):le32(hpfs_header->total_sect)) *
        fat_sector_size(hpfs_header);
      partition->upart_type=UP_HPFS;
      return 0;
    }
  }     /* fin marqueur de fin :)) */
  return 1;
}
コード例 #4
0
ファイル: profiler.c プロジェクト: nviennot/libscribe
int main(int argc, char **argv)
{
    if (argc != 2) {
        usage();
        return -1;
    }

    return dump_log(argv[1]) < 0 ? 1 : 0;
}
コード例 #5
0
ファイル: graph.c プロジェクト: John-D-Bell/cvs-fast-export
static void dot_commit_graph(git_commit *c, rev_ref *branch)
{
    rev_file	*f;

    printf("\"");
    if (branch)
	dot_ref_name(stdout, branch);
//    if (c->tail)
//	printf("*** TAIL");
    printf("\\n");
    printf("%s\\n", ctime_nonl(&c->date));
    dump_log(stdout, c->log);
    printf("\\n");
    if (difffiles) {
	rev_diff    *diff = git_commit_diff(c->parent, c);
	rev_file_list   *fl;

	for (fl = diff->add; fl; fl = fl->next) {
	    if (!rev_file_list_has_filename(diff->del, fl->file->file_name)) {
		printf("+");
		dump_number(fl->file->file_name, &fl->file->number);
		printf("\\n");
	    }
	}
	for (fl = diff->add; fl; fl = fl->next) {
	    if (rev_file_list_has_filename(diff->del, fl->file->file_name)) {
		printf("|");
		dump_number(fl->file->file_name, &fl->file->number);
		printf("\\n");
	    }
	}
	for (fl = diff->del; fl; fl = fl->next) {
	    if (!rev_file_list_has_filename(diff->add, fl->file->file_name)) {
		printf("-");
		dump_number(fl->file->file_name, &fl->file->number);
		printf("\\n");
	    }
	}
	rev_diff_free(diff);
    } else {
	int		i, j;
	for (i = 0; i < c->ndirs; i++) {
	    rev_dir *dir = c->dirs[i];
	    for (j = 0; j < dir->nfiles; j++) {
		 f = dir->files[j];
		 dump_number(f->file_name, &f->number);
		 printf("\\n");
	    }
	}
    }
    printf("%p", c);
    printf("\"");
}
コード例 #6
0
ファイル: intrfn.c プロジェクト: dennyfeng/testdisk
void dump_ncurses(const void *nom_dump, unsigned int lng)
{
  WINDOW *window=newwin(LINES, COLS, 0, 0);	/* full screen */
  keypad(window, TRUE); /* Need it to get arrow key */
  aff_copy(window);
  dump(window, nom_dump, lng);
  dump_log(nom_dump,lng);
  delwin(window);
  (void) clearok(stdscr, TRUE);
#ifdef HAVE_TOUCHWIN
  touchwin(stdscr);
#endif
}
コード例 #7
0
ファイル: zfs.c プロジェクト: AndrewSmart/testdisk
static int test_ZFS(disk_t *disk, const struct vdev_boot_header *sb, const partition_t *partition, const int dump_ind)
{
  if(le64(sb->vb_magic)!=VDEV_BOOT_MAGIC)
    return 1;
  if(dump_ind!=0)
  {
    if(partition!=NULL && disk!=NULL)
      log_info("\nZFS magic value at %u/%u/%u\n",
          offset2cylinder(disk,partition->part_offset),
          offset2head(disk,partition->part_offset),
          offset2sector(disk,partition->part_offset));
    dump_log(sb,DEFAULT_SECTOR_SIZE);
  }
  return 0;
}
コード例 #8
0
ファイル: bfs.c プロジェクト: AndychenCL/TestDisk
static int test_BeFS(disk_t *disk_car, const struct disk_super_block*beos_block,partition_t *partition, const int dump_ind)
{
  if(beos_block->magic1==le32(SUPER_BLOCK_MAGIC1) &&
      beos_block->magic2==le32(SUPER_BLOCK_MAGIC2) &&
      beos_block->magic3==le32(SUPER_BLOCK_MAGIC3))
  {
    partition->upart_type=UP_BEOS;
    if(dump_ind!=0)
    {
      log_info("\nBeFS magic value at %u/%u/%u\n", offset2cylinder(disk_car,partition->part_offset),offset2head(disk_car,partition->part_offset),offset2sector(disk_car,partition->part_offset));
      dump_log(beos_block,DEFAULT_SECTOR_SIZE);
    }
    return 0;
  }
  return 1;
}
コード例 #9
0
ファイル: gfs2.c プロジェクト: AndychenCL/TestDisk
static int test_gfs2(disk_t *disk, const struct gfs2_sb *sb, partition_t *partition, const int dump_ind)
{
  if(sb->sb_header.mh_magic != be32(GFS2_MAGIC))
    return 1;
  if(sb->sb_header.mh_format != be32(GFS2_FORMAT_SB))
    return 1;
  partition->upart_type=UP_GFS2;
  if(dump_ind!=0)
  {
    log_info("\ngfs2 magic value at %u/%u/%u\n",
	offset2cylinder(disk, partition->part_offset),
	offset2head(disk, partition->part_offset),
	offset2sector(disk, partition->part_offset));
    dump_log(sb,DEFAULT_SECTOR_SIZE);
  }
  return 0;
}
コード例 #10
0
ファイル: vmfs.c プロジェクト: Eemaa26/photorec-testdisk
static int test_VMFS(disk_t *disk, const struct vmfs_volume *sb, partition_t *partition, const int dump_ind)
{
  if(le32(sb->magic)!=0xc001d00d)
    return 1;
  if(dump_ind!=0)
  {
    if(partition!=NULL && disk!=NULL)
      log_info("\nVMFS magic value at %u/%u/%u\n",
          offset2cylinder(disk,partition->part_offset),
          offset2head(disk,partition->part_offset),
          offset2sector(disk,partition->part_offset));
    dump_log(sb,DEFAULT_SECTOR_SIZE);
  }
  if(partition==NULL)
    return 0;
  partition->upart_type=UP_VMFS;
  return 0;
}
コード例 #11
0
ファイル: sun.c プロジェクト: AndrewSmart/testdisk
int recover_sun_i386(disk_t *disk_car, const sun_partition_i386 *sunlabel, partition_t *partition,const int verbose, const int dump_ind)
{
  if(test_sun_i386(disk_car, sunlabel, partition, verbose)!=0)
    return 1;
  if(verbose>0 || dump_ind!=0)
  {
    log_info("\nrecover_sun\n");
    if(dump_ind!=0)
    {
      dump_log(sunlabel,sizeof(*sunlabel));
    }
  }
  partition->part_size=(uint64_t)le32(sunlabel->partitions[2].num_sectors) * le16(sunlabel->sector_size);
  set_sun_info_i386(partition);
  partition->part_type_i386 = P_SUN;
  partition->part_type_gpt=GPT_ENT_TYPE_SOLARIS_ROOT;
  return 0;
}
コード例 #12
0
ファイル: wbfs.c プロジェクト: AndychenCL/TestDisk
static int test_WBFS(disk_t *disk, const struct wbfs_head *sb, partition_t *partition, const int dump_ind)
{
  if(be32(sb->magic)!=WBFS_MAGIC)
    return 1;
  if(dump_ind!=0)
  {
    if(partition!=NULL && disk!=NULL)
      log_info("\nWBFS magic value at %u/%u/%u\n",
          offset2cylinder(disk,partition->part_offset),
          offset2head(disk,partition->part_offset),
          offset2sector(disk,partition->part_offset));
    dump_log(sb,DEFAULT_SECTOR_SIZE);
  }
  if(partition==NULL)
    return 0;
  partition->upart_type=UP_WBFS;
  return 0;
}
コード例 #13
0
ファイル: lvm.c プロジェクト: AndrewSmart/testdisk
static int test_LVM2(disk_t *disk_car, const struct lvm2_label_header *lh, const partition_t *partition, const int verbose, const int dump_ind)
{
  if (memcmp((const char *)lh->type,LVM2_LABEL,sizeof(lh->type)) == 0)
  {
    if(verbose>0 || dump_ind!=0)
    {
      log_info("\nLVM2 magic value at %u/%u/%u\n", offset2cylinder(disk_car,partition->part_offset),offset2head(disk_car,partition->part_offset),offset2sector(disk_car,partition->part_offset));
    }
    if(le32(lh->offset_xl)>400)
      return 1;
    if(dump_ind!=0)
    {
      /* There is a little offset ... */
      dump_log(lh,DEFAULT_SECTOR_SIZE);
    }
    return 0;
  }
  return 1;
}
コード例 #14
0
ファイル: hfsp.c プロジェクト: AndychenCL/TestDisk
int test_HFSP(disk_t *disk_car, const struct hfsp_vh *vh,partition_t *partition,const int verbose, const int dump_ind)
{
  if (be32(vh->free_blocks) > be32(vh->total_blocks))
    return 1;
  /* Blocksize must be a multiple of 512 */
  if (be32(vh->blocksize)<512 ||
      ((be32(vh->blocksize)-1) & be32(vh->blocksize))!=0)
    return 1;
  /* http://developer.apple.com/technotes/tn/tn1150.html */
  if (be16(vh->version)==4 && vh->signature==be16(HFSP_VOLHEAD_SIG))
  {
    partition->upart_type=UP_HFSP;
    if(verbose>0 || dump_ind!=0)
    {
      log_info("\nHFS+ magic value at %u/%u/%u\n", offset2cylinder(disk_car,partition->part_offset),offset2head(disk_car,partition->part_offset),offset2sector(disk_car,partition->part_offset));
    }
  }
  else if (be16(vh->version)==5 && vh->signature==be16(HFSX_VOLHEAD_SIG))
  {
    partition->upart_type=UP_HFSX;
    if(verbose>0 || dump_ind!=0)
    {
      log_info("\nHFSX magic value at %u/%u/%u\n", offset2cylinder(disk_car,partition->part_offset),offset2head(disk_car,partition->part_offset),offset2sector(disk_car,partition->part_offset));
    }
  }
  else
  {
    return 1;
  }
  if(dump_ind!=0)
  {
    /* There is a little offset ... */
    dump_log(vh,DEFAULT_SECTOR_SIZE);
  }
  if(verbose>1)
  {
    log_info("blocksize %u\n",(unsigned) be32(vh->blocksize));
    log_info("total_blocks %u\n",(unsigned) be32(vh->total_blocks));
    log_info("free_blocks  %u\n",(unsigned) be32(vh->free_blocks));
  }
  return 0;
}
コード例 #15
0
ファイル: cramfs.c プロジェクト: AndychenCL/TestDisk
int recover_cramfs(disk_t *disk_car, const struct cramfs_super *sb,partition_t *partition,const int verbose, const int dump_ind)
{
  if(test_cramfs(disk_car, sb, partition, verbose)!=0)
    return 1;
  if(verbose>0 || dump_ind!=0)
  {
    log_trace("\nrecover_cramfs\n");
    if(dump_ind!=0)
    {
      dump_log(sb,DEFAULT_SECTOR_SIZE);
    }
  }
  partition->part_size = sb->size;
  partition->part_type_i386 = P_LINUX;
  partition->part_type_mac= PMAC_LINUX;
  partition->part_type_sun= PSUN_LINUX;
  partition->part_type_gpt= GPT_ENT_TYPE_LINUX_DATA;
  set_cramfs_info(sb, partition);
  return 0;
}
コード例 #16
0
ファイル: jfs.c プロジェクト: Tom9X/TestDisk
static int test_JFS(disk_t *disk_car, const struct jfs_superblock *sb, partition_t *partition, const int dump_ind)
{
  if(memcmp(sb->s_magic,"JFS1",4)!=0)
    return 1;
  if(dump_ind!=0)
  {
    log_info("\nJFS magic value at %u/%u/%u\n", offset2cylinder(disk_car,partition->part_offset),offset2head(disk_car,partition->part_offset),offset2sector(disk_car,partition->part_offset));
    /* There is a little offset ... */
    dump_log(sb,DEFAULT_SECTOR_SIZE);
  }
  /*
  if( le32(sb->s_agsize) >= (1 << L2BPERDMAP) ) {
    return 2;
  }
  if(partition->part_size!=0 && (partition->part_size<le64(sb->s_size)))
    return 8;
    */
  partition->upart_type=UP_JFS;
  return 0;
}
コード例 #17
0
ファイル: xfs.c プロジェクト: AndrewSmart/testdisk
int recover_xfs(disk_t *disk_car, const struct xfs_sb *sb,partition_t *partition,const int verbose, const int dump_ind)
{
  if(test_xfs(disk_car, sb, partition, verbose)!=0)
    return 1;
  if(verbose>0 || dump_ind!=0)
  {
    log_info("\nrecover_xfs\n");
    if(dump_ind!=0)
    {
      dump_log(sb,DEFAULT_SECTOR_SIZE);
    }
  }
  set_xfs_info(sb, partition);
  partition->part_size = (uint64_t)be64(sb->sb_dblocks) * be32(sb->sb_blocksize);
  partition->part_type_i386=P_LINUX;
  partition->part_type_mac=PMAC_LINUX;
  partition->part_type_sun=PSUN_LINUX;
  partition->part_type_gpt=GPT_ENT_TYPE_LINUX_DATA;
  guid_cpy(&partition->part_uuid, (const efi_guid_t *)&sb->sb_uuid);
  return 0;
}
コード例 #18
0
ファイル: file_ab.c プロジェクト: Eemaa26/photorec-testdisk
static data_check_t data_check_addressbook(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
  while(file_recovery->calculated_file_size + buffer_size/2  >= file_recovery->file_size &&
      file_recovery->calculated_file_size + 8 < file_recovery->file_size + buffer_size/2)
  {
    const unsigned int i=file_recovery->calculated_file_size - file_recovery->file_size + buffer_size/2;
    const struct ab_header *ab=(const struct ab_header *)&buffer[i];
    const unsigned int length=be32(ab->size);
#ifdef DEBUG_AB
    log_debug("data_check_addressbook i=0x%x buffer_size=0x%x calculated_file_size=%lu file_size=%lu\n",
        i, buffer_size,
        (long unsigned)file_recovery->calculated_file_size,
        (long unsigned)file_recovery->file_size);
    dump_log(buffer+i,8);
#endif
    if(ab->magic[0]!='L' || ab->magic[1]!='J' || ab->magic[3]!=0x00 || length<8)
      return DC_STOP;
    file_recovery->calculated_file_size+=length;
  }
  return DC_CONTINUE;
}
コード例 #19
0
ファイル: lvm.c プロジェクト: AndrewSmart/testdisk
static int test_LVM(disk_t *disk_car, const pv_disk_t *pv, const partition_t *partition, const int verbose, const int dump_ind)
{
  if ((memcmp((const char *)pv->id,LVM_ID,sizeof(pv->id)) == 0) && (le16(pv->version) == 1 || le16(pv->version) == 2))
  {
    uint32_t size;
    if(verbose>0 || dump_ind!=0)
    {
      log_info("\nLVM magic value at %u/%u/%u\n", offset2cylinder(disk_car,partition->part_offset),offset2head(disk_car,partition->part_offset),offset2sector(disk_car,partition->part_offset));
    }
    if(dump_ind!=0)
    {
      /* There is a little offset ... */
      dump_log(pv,DEFAULT_SECTOR_SIZE);
    }
    if (le32(pv->pv_size) > LVM_MAX_SIZE)
      return (1);
    if (le32(pv->pv_status) != 0 && le32(pv->pv_status) != PV_ACTIVE)
      return (1);
    if (le32(pv->pv_allocatable) != 0 && le32(pv->pv_allocatable) != PV_ALLOCATABLE)
      return (1);
    if (le32(pv->lv_cur) > MAX_LV)
      return (1);
    if (strlen((const char *)pv->vg_name) > NAME_LEN / 2)
      return (1);
    size = le32(pv->pe_size) / LVM_MIN_PE_SIZE * LVM_MIN_PE_SIZE;
    if ((le32(pv->pe_size) != size) ||
	(le32(pv->pe_size) < LVM_MIN_PE_SIZE) ||
	(le32(pv->pe_size) > LVM_MAX_PE_SIZE))
      return (1);

    if (le32(pv->pe_total) > ( pv->pe_on_disk.size / sizeof ( disk_pe_t)))
      return (1);
    if (le32(pv->pe_allocated) > le32(pv->pe_total))
      return (1);
    return 0;
  }
  return 1;
}
コード例 #20
0
ファイル: md.c プロジェクト: AndrewSmart/testdisk
static int test_MD_be(disk_t *disk_car, const struct mdp_superblock_s *sb, const partition_t *partition, const int dump_ind)
{
  if(be32(sb->md_magic)!=(unsigned int)MD_SB_MAGIC)
    return 1;
  log_info("\nRaid magic value at %u/%u/%u\n",
      offset2cylinder(disk_car,partition->part_offset),
      offset2head(disk_car,partition->part_offset),
      offset2sector(disk_car,partition->part_offset));
  log_info("Raid apparent size: %llu sectors\n", (long long unsigned)(sb->size<<1));
  if(be32(sb->major_version)==0)
  {
    /* chunk_size may be 0 */
    log_info("Raid chunk size: %llu bytes\n",(long long unsigned)be32(sb->chunk_size));
  }
  if(be32(sb->major_version)>1)
    return 1;
  if(dump_ind!=0)
  {
    /* There is a little offset ... */
    dump_log(sb,DEFAULT_SECTOR_SIZE);
  }
  return 0;
}
コード例 #21
0
ファイル: btrfs.c プロジェクト: dbrant/testdisk
/*
Primary superblock is at 1024 (SUPERBLOCK_OFFSET)
Group 0 begin at s_first_data_block
*/
int recover_btrfs(disk_t *disk, const struct btrfs_super_block *sb, partition_t *partition, const int verbose, const int dump_ind)
{
    if(test_btrfs(sb)!=0)
        return 1;
    if(dump_ind!=0)
    {
        if(partition!=NULL && disk!=NULL)
            log_info("\nbtrfs magic value at %u/%u/%u\n",
                     offset2cylinder(disk,partition->part_offset),
                     offset2head(disk,partition->part_offset),
                     offset2sector(disk,partition->part_offset));
        dump_log(sb, BTRFS_SUPER_INFO_SIZE);
    }
    if(partition==NULL)
        return 0;
    set_btrfs_info(sb, partition);
    partition->part_type_i386=P_LINUX;
    partition->part_type_mac=PMAC_LINUX;
    partition->part_type_sun=PSUN_LINUX;
    partition->part_type_gpt=GPT_ENT_TYPE_LINUX_DATA;
    partition->part_size=(uint64_t)le64(sb->dev_item.total_bytes);
    guid_cpy(&partition->part_uuid, (const efi_guid_t *)&sb->fsid);
    if(verbose>0)
    {
        log_info("\n");
    }
    partition->sborg_offset=BTRFS_SUPER_INFO_OFFSET;
    partition->sb_size=BTRFS_SUPER_INFO_SIZE;
    if(verbose>0)
    {
        if(disk==NULL)
            log_info("recover_btrfs: part_size %lu\n", (long unsigned)(partition->part_size / le32(sb->dev_item.sector_size)));
        else
            log_info("recover_btrfs: part_size %lu\n", (long unsigned)(partition->part_size / disk->sector_size));
    }
    return 0;
}
コード例 #22
0
ファイル: hfs.c プロジェクト: AndrewSmart/testdisk
int test_HFS(disk_t *disk_car, const hfs_mdb_t *hfs_mdb, const partition_t *partition, const int verbose, const int dump_ind)
{
  /* Check for HFS signature */
  if (hfs_mdb->drSigWord!=be16(HFS_SUPER_MAGIC))
    return 1;
  /* Blocksize must be a multiple of 512 */
  if(be32(hfs_mdb->drAlBlkSiz)<512 ||
      ((be32(hfs_mdb->drAlBlkSiz)-1) & be32(hfs_mdb->drAlBlkSiz))!=0)
    return 1;
  /* Check for valid number of allocation blocks */
  if(be16(hfs_mdb->drNmAlBlks)==0)
    return 1;
  /* Check for coherent block numbers */
  if(be16(hfs_mdb->drFreeBks) > be16(hfs_mdb->drNmAlBlks))
    return 1;
  /* Size must be less than 2TB (tolerate a little bit more)*/
  if((uint64_t)be16(hfs_mdb->drNmAlBlks)*be32(hfs_mdb->drAlBlkSiz)+be16(hfs_mdb->drAlBlSt)*512+0x400 > (uint64_t)2049*1024*1024*1024)
    return 1;
  if(verbose>0 || dump_ind!=0)
  {
    log_info("\nHFS magic value at %u/%u/%u\n", offset2cylinder(disk_car,partition->part_offset),offset2head(disk_car,partition->part_offset),offset2sector(disk_car,partition->part_offset));
  }
  if(dump_ind!=0)
  {
    /* There is a little offset ... */
    dump_log(hfs_mdb,DEFAULT_SECTOR_SIZE);
  }
  if(verbose>1)
  {
    log_info("drNmAlBlks %u\n",(unsigned) be16(hfs_mdb->drNmAlBlks));
    log_info("drAlBlkSiz %u\n",(unsigned) be32(hfs_mdb->drAlBlkSiz));
    log_info("drAlBlSt %u\n",(unsigned) be16(hfs_mdb->drAlBlSt));
    log_info("drFreeBks %u\n",(unsigned) be16(hfs_mdb->drFreeBks));
  }
  return 0;
}
コード例 #23
0
ファイル: ufs.c プロジェクト: foreverlikeyou9999/TestDisk
int recover_ufs(disk_t *disk_car, const struct ufs_super_block *sb, partition_t *partition,const int verbose, const int dump_ind)
{
  if(test_ufs(disk_car, sb, partition, verbose)!=0)
    return 1;
  if(dump_ind!=0)
  {
    log_info("recover_ufs\n");
    dump_log(sb,sizeof(*sb));
  }
  switch(partition->upart_type)
  {
    case UP_UFS_LE:
      partition->part_size = (uint64_t)le32(sb->fs_size)*le32(sb->fs_fsize);
      if(verbose>1)
      {
	log_info("fs_size %lu, fs_fsize %lu\n", (long unsigned)le32(sb->fs_size), (long unsigned)le32(sb->fs_fsize));
	log_info("fs_sblkno %lu\n", (long unsigned)le32(sb->fs_sblkno));
      }
      break;
    case UP_UFS2_LE:
      partition->part_size = (uint64_t)le64(sb->fs_u11.fs_u2.fs_size)*le32(sb->fs_fsize);
      if(verbose>1)
      {
	log_info("fs_size %lu, fs_fsize %lu\n", (long unsigned)le64(sb->fs_u11.fs_u2.fs_size), (long unsigned)le32(sb->fs_fsize));
	log_info("fs_sblkno %lu\n", (long unsigned)le32(sb->fs_sblkno));
	log_info("fs_sblockloc %llu\n", (long long unsigned)le64(sb->fs_u11.fs_u2.fs_sblockloc));
      }
      break;
    case UP_UFS:
      partition->part_size = (uint64_t)be32(sb->fs_size)*be32(sb->fs_fsize);
      if(verbose>1)
      {
	log_info("fs_size %lu, fs_fsize %lu\n",(long unsigned)be32(sb->fs_size),(long unsigned)be32(sb->fs_fsize));
      }
      break;
    case UP_UFS2:
      partition->part_size = (uint64_t)be64(sb->fs_u11.fs_u2.fs_size)*be32(sb->fs_fsize);
      if(verbose>1)
      {
	log_info("fs_size %lu, fs_fsize %lu\n", (long unsigned)be64(sb->fs_u11.fs_u2.fs_size), (long unsigned)be32(sb->fs_fsize));
      }
      break;
  }

  set_ufs_info(sb, partition);
  if(strcmp(partition->fsname,"/")==0)
  {
    partition->part_type_sun = (unsigned char)PSUN_ROOT;
    partition->part_type_gpt=GPT_ENT_TYPE_SOLARIS_ROOT;
  }
  else if(strcmp(partition->fsname,"/var")==0)
  {
    partition->part_type_sun = (unsigned char)PSUN_VAR;
    partition->part_type_gpt=GPT_ENT_TYPE_SOLARIS_VAR;
  }
  else if(strcmp(partition->fsname,"/usr")==0)
  {
    partition->part_type_sun = (unsigned char)PSUN_USR;
    partition->part_type_gpt=GPT_ENT_TYPE_SOLARIS_USR;
  }
  else if(strcmp(partition->fsname,"/export/home")==0)
  {
    partition->part_type_sun = (unsigned char)PSUN_HOME;
    partition->part_type_gpt=GPT_ENT_TYPE_SOLARIS_HOME;
  }
  else
  {
    partition->part_type_sun = (unsigned char)PSUN_ROOT;
    partition->part_type_gpt=GPT_ENT_TYPE_SOLARIS_HOME;
  }
  return 0;
}
コード例 #24
0
ファイル: file_doc.c プロジェクト: Ctrlshiftm/ICU
static void OLE_parse_summary_aux(const unsigned char *dataPt, const unsigned int dirLen, const char **ext, char **title, time_t *file_time)
{
  unsigned int pos;
#ifdef DEBUG_OLE
  dump_log(dataPt, dirLen);
#endif
  if(dataPt[0]!=0xfe || dataPt[1]!=0xff)
    return ;
  pos=get32u(dataPt, 44);
  {
//    unsigned int size;
    unsigned int numEntries;
    unsigned int i;
    if(pos+8 > dirLen)
      return ;
    numEntries=get32u(dataPt, pos+4);
#ifdef DEBUG_OLE
    {
      unsigned int size=get32u(dataPt, pos);
      log_info("Property Info %u - %u at 0x%x\n", numEntries, size, pos);
    }
#endif
    if(pos + 8 + 8 * numEntries > dirLen)
      return ;
    for(i=0; i<numEntries; i++)
    {
      const unsigned int entry = pos + 8 + 8 * i;
      const unsigned int tag=get32u(dataPt, entry);
      const unsigned int offset=get32u(dataPt, entry + 4);
      const unsigned int valStart = pos + 4 + offset;
      unsigned int type;
      if(valStart >= dirLen)
	return ;
      type=get32u(dataPt, pos + offset);
#ifdef DEBUG_OLE
      log_info("entry 0x%x, tag 0x%x, offset 0x%x, valStart 0x%x, type 0x%x\n",
	  entry, tag, offset, valStart, type);
#endif
      /* tag: Software, type: VT_LPSTR */
      if(tag==0x12 && type==30)
      {
	unsigned int count=get32u(dataPt, valStart);
	if(valStart + 4 + count > dirLen)
	  return ;
#ifdef DEBUG_OLE
	{
	  unsigned int j;
	  log_info("Software ");
	  for(j=0; j<count; j++)
	  {
	    log_info("%c", dataPt[valStart + 4 + j]);
	  }
	  log_info("\n");
	}
#endif
	software2ext(ext, count, &dataPt[valStart + 4]);
      }
      /* tag: Software, type: VT_LPWSTR */
      if(tag==0x12 && type==31)
      {
	unsigned int count=get32u(dataPt, valStart);
	if(valStart + 4 + 2 * count > dirLen)
	  return ;
#ifdef DEBUG_OLE
	{
	  unsigned int j;
	  log_info("Software ");
	  for(j=0; j < 2 * count; j+=2)
	  {
	    log_info("%c", dataPt[valStart + 4 + j]);
	  }
	  log_info("\n");
	}
#endif
	*ext=software_uni2ext(count, &dataPt[valStart + 4]);
      }
      if(tag==0x02 && type==30 && *title==NULL)
      {
	const unsigned int count=get32u(dataPt, valStart);
	if(valStart + 4 + count > dirLen)
	  return ;
	*title=(char*)MALLOC(count+1);
	memcpy(*title, &dataPt[valStart + 4], count);
	(*title)[count]='\0';
#ifdef DEBUG_OLE
	log_info("Title %s\n", *title);
#endif
      }
      /* ModifyDate, type=VT_FILETIME */
      if(tag==0x0d && type==64)
      {
	uint64_t tmp=get64u(dataPt, valStart);
	tmp/=10000000;
	if(tmp > (uint64_t)134774 * 24 * 3600)
	{
	  tmp -= (uint64_t)134774 * 24 * 3600;
	  *file_time=tmp;
	}
      }
    }
  }
}
コード例 #25
0
ファイル: hdwin32.c プロジェクト: AndrewSmart/testdisk
void file_win32_disk_get_model(HANDLE handle, disk_t *dev, const int verbose)
{
  DWORD               cbBytesReturned = 0;
  STORAGE_PROPERTY_QUERY query;
  char buffer [10240];
  memset((void *) & query, 0, sizeof (query));
  query.PropertyId = StorageDeviceProperty;
  query.QueryType = PropertyStandardQuery;
  memset(&buffer, 0, sizeof (buffer));

  if ( DeviceIoControl(handle, IOCTL_STORAGE_QUERY_PROPERTY,
	&query,
	sizeof (query),
	&buffer,
	sizeof (buffer)-1,
	&cbBytesReturned, NULL) )
  {
    const STORAGE_DEVICE_DESCRIPTOR * descrip = (const STORAGE_DEVICE_DESCRIPTOR *) & buffer;
    const unsigned int offsetVendor=descrip->VendorIdOffset;
    const unsigned int offsetProduct=descrip->ProductIdOffset;
    unsigned int lenVendor=0;
    unsigned int lenProduct=0;
    if(verbose>1)
    {
      log_info("IOCTL_STORAGE_QUERY_PROPERTY:\n");
      dump_log(&buffer, cbBytesReturned);
    }
    buffer[cbBytesReturned]='\0';
    if(descrip->SerialNumberOffset!=0 && descrip->SerialNumberOffset < cbBytesReturned)
      dev->serial_no=strip_dup(&buffer[descrip->SerialNumberOffset]);
    if(descrip->ProductRevisionOffset!=0 && descrip->ProductRevisionOffset < cbBytesReturned)
      dev->fw_rev=strip_dup(&buffer[descrip->ProductRevisionOffset]);
    if(offsetVendor > 0 && offsetVendor < cbBytesReturned)
      lenVendor=strlen(&buffer[offsetVendor]);
    if(offsetProduct > 0 && offsetProduct < cbBytesReturned)
      lenProduct=strlen(&buffer[offsetProduct]);
    if(lenVendor+lenProduct > 0)
    {
      dev->model = (char*) MALLOC(lenVendor+1+lenProduct+1);
      dev->model[0]='\0';
      if(lenVendor>0 && offsetVendor + lenVendor <= cbBytesReturned)
      {
	int i;
	memcpy(dev->model, &buffer[offsetVendor], lenVendor);
	dev->model[lenVendor]='\0';
	for(i=lenVendor-1;i>=0 && dev->model[i]==' ';i--);
	if(i>=0)
	  dev->model[++i]=' ';
	dev->model[++i]='\0';
      }
      if(lenProduct>0 && offsetProduct + lenProduct <= cbBytesReturned)
      {
	int i;
	strncat(dev->model, &buffer[offsetProduct], lenProduct);
	for(i=strlen(dev->model)-1; i>=0 && dev->model[i]==' '; i--);
	dev->model[++i]='\0';
      }
      if(strlen(dev->model)>0)
	return ;
      free(dev->model);
      dev->model=NULL;
    }
  }
}
コード例 #26
0
ファイル: ext2.c プロジェクト: Ctrlshiftm/ICU
/*
Primary superblock is at 1024 (SUPERBLOCK_OFFSET)
Group 0 begin at s_first_data_block
*/
int recover_EXT2(disk_t *disk, const struct ext2_super_block *sb,partition_t *partition,const int verbose, const int dump_ind)
{
  if(test_EXT2(sb, partition)!=0)
    return 1;
  if(dump_ind!=0)
  {
    if(partition!=NULL && disk!=NULL)
      log_info("\nEXT2/EXT3 magic value at %u/%u/%u\n",
	  offset2cylinder(disk,partition->part_offset),
	  offset2head(disk,partition->part_offset),
	  offset2sector(disk,partition->part_offset));
    /* There is a little offset ... */
    dump_log(sb,DEFAULT_SECTOR_SIZE);
  }
  if(partition==NULL)
    return 0;
  set_EXT2_info(sb, partition, verbose);
  partition->part_type_i386=P_LINUX;
  partition->part_type_mac=PMAC_LINUX;
  partition->part_type_sun=PSUN_LINUX;
  partition->part_type_gpt=GPT_ENT_TYPE_LINUX_DATA;
  partition->part_size=td_ext2fs_blocks_count(sb) * EXT2_MIN_BLOCK_SIZE<<le32(sb->s_log_block_size);
  guid_cpy(&partition->part_uuid, (const efi_guid_t *)&sb->s_uuid);
  if(verbose>0)
  {
    log_info("\n");
  }
  partition->sborg_offset=0x400;
  partition->sb_size=EXT2_SUPERBLOCK_SIZE;
  if(le16(sb->s_block_group_nr)>0)
  {
    const unsigned long int block_nr=(le32(sb->s_first_data_block)+le16(sb->s_block_group_nr)*le32(sb->s_blocks_per_group));
    if(partition->part_offset< (uint64_t)block_nr * (EXT2_MIN_BLOCK_SIZE<<le32(sb->s_log_block_size)))
    {
      log_error("recover_EXT2: part_offset problem\n");
      return 1;
    }
    partition->sb_offset=(uint64_t)block_nr * (EXT2_MIN_BLOCK_SIZE<<le32(sb->s_log_block_size));
    partition->part_offset-=partition->sb_offset;
    log_warning("recover_EXT2: \"e2fsck -b %lu -B %u device\" may be needed\n",
        block_nr, partition->blocksize);
  }
  else
  {
    partition->sb_offset=0;
  }
  if(verbose>0)
  {
    log_info("recover_EXT2: s_block_group_nr=%u/%u, s_mnt_count=%u/%u, s_blocks_per_group=%u, s_inodes_per_group=%u\n",
        le16(sb->s_block_group_nr),
        (unsigned int)(td_ext2fs_blocks_count(sb) /le32(sb->s_blocks_per_group)),
        le16(sb->s_mnt_count), le16(sb->s_max_mnt_count),
        (unsigned int)le32(sb->s_blocks_per_group),
        (unsigned int)le32(sb->s_inodes_per_group));
    log_info("recover_EXT2: s_blocksize=%u\n", partition->blocksize);
    log_info("recover_EXT2: s_blocks_count %lu\n", (long unsigned int)td_ext2fs_blocks_count(sb));
    if(disk==NULL)
      log_info("recover_EXT2: part_size %lu\n", (long unsigned)(partition->part_size / DEFAULT_SECTOR_SIZE));
    else
      log_info("recover_EXT2: part_size %lu\n", (long unsigned)(partition->part_size / disk->sector_size));
  }
  return 0;
}
コード例 #27
0
ファイル: bsd.c プロジェクト: AndrewSmart/testdisk
static int test_BSD(disk_t *disk_car, const struct disklabel*bsd_header, const partition_t *partition,const int verbose, const int dump_ind, const unsigned int max_partitions)
{
  unsigned int i;
  const uint16_t* cp;
  uint16_t crc;
  if(le32(bsd_header->d_magic) != DISKMAGIC || le32(bsd_header->d_magic2)!=DISKMAGIC)
    return 0;
  if(verbose)
    log_info("\nBSD offset %lu, nbr_part %u, CHS=(%u,%u,%u) ",
	(long unsigned)(partition->part_offset/disk_car->sector_size),
	(unsigned int)le16(bsd_header->d_npartitions),
	(unsigned int)le32(bsd_header->d_ncylinders),
	(unsigned int)le32(bsd_header->d_ntracks),
	(unsigned int)le32(bsd_header->d_nsectors));
  if(le16(bsd_header->d_npartitions) > max_partitions)
    return 1;
  crc=0;
  for(cp=(const uint16_t*)bsd_header;
      cp<(const uint16_t*)&bsd_header->d_partitions[le16(bsd_header->d_npartitions)];cp++)
    crc^=*cp;
  if(crc==0)
  {
    if(verbose>0)
    {
      log_info("CRC Ok\n");
    }
  }
  else
    log_error("Bad CRC! CRC must be xor'd by %04X\n",crc);
  for(i=0;i<le16(bsd_header->d_npartitions);i++)
  {
    if(bsd_header->d_partitions[i].p_fstype>0)
    {
      if(verbose>0)
      {
	/* UFS UFS2 SWAP */
	log_info("BSD %c: ", 'a'+i);
	switch(bsd_header->d_partitions[i].p_fstype)
	{
	  case TST_FS_SWAP:
	    log_info("swap");
	    break;
	  case TST_FS_BSDFFS:
	    log_info("4.2BSD fast filesystem");
	    break;
	  case TST_FS_BSDLFS:
	    log_info("4.4BSD log-structured filesystem");
	    break;
	  default:
	    log_info("type %02X", bsd_header->d_partitions[i].p_fstype);
	    break;
	}
	log_info(", offset %9u, size %9u ",
	    (unsigned int)le32(bsd_header->d_partitions[i].p_offset),
	    (unsigned int)le32(bsd_header->d_partitions[i].p_size));
	log_CHS_from_LBA(disk_car,le32(bsd_header->d_partitions[i].p_offset));
	log_info(" -> ");
	log_CHS_from_LBA(disk_car,le32(bsd_header->d_partitions[i].p_offset)+le32(bsd_header->d_partitions[i].p_size)-1);
	log_info("\n");
      }
    }
  }
  if(crc)
    return 1;
  if(dump_ind!=0)
  {
    dump_log(bsd_header,DEFAULT_SECTOR_SIZE);
  }
  return 0;
}
コード例 #28
0
ファイル: edit.c プロジェクト: AndrewSmart/testdisk
static int dump_editor(const unsigned char *nom_dump,const unsigned int lng, const int menu_pos)
{
  unsigned int pos;
  int done=0;
  unsigned int menu;
  const struct MenuItem menuDump[]=
  {
	{ 'P', "Previous",""},
	{ 'N', "Next","" },
	{ 'Q',"Quit","Quit dump section"},
	{ 0, NULL, NULL }
  };
  /* write dump to log file*/
  dump_log(nom_dump, lng);
  /* ncurses interface */
  pos=(menu_pos==KEY_DOWN?0:lng/0x10-EDIT_MAX_LINES);
  menu=(menu_pos==KEY_DOWN?1:0);
  mvwaddstr(stdscr, EDIT_Y, EDIT_X, msg_DUMP_HEXA);
  do
  {
    	unsigned int i,j;
  	unsigned char car;
	for (i=pos; (i<lng/0x10)&&((i-pos)<EDIT_MAX_LINES); i++)
	{
	  wmove(stdscr,EDIT_Y+i-pos,EDIT_X);
	  wclrtoeol(stdscr);
	  wprintw(stdscr,"%04X ",i*0x10);
	  for(j=0; j< 0x10;j++)
	  {
		car=*(nom_dump+i*0x10+j);
		wprintw(stdscr,"%02x", car);
		if(j%4==(4-1))
		  wprintw(stdscr," ");
	  }
	  wprintw(stdscr,"  ");
	  for(j=0; j< 0x10;j++)
	  {
		car=*(nom_dump+i*0x10+j);
		if ((car<32)||(car >= 127))
		  wprintw(stdscr,".");
		else
		  wprintw(stdscr,"%c",  car);
	  }
	}
	switch (wmenuSelect(stdscr, INTER_EDIT_Y+1, INTER_EDIT_Y, INTER_EDIT_X, menuDump, 8, "PNQ", MENU_HORIZ | MENU_BUTTON | MENU_ACCEPT_OTHERS, menu))
	{
	  case 'p':
	  case 'P':
	  case KEY_UP:
		menu=0;
		if(pos>0)
		  pos--;
		else
		  done=KEY_UP;
		break;
	  case 'n':
	  case 'N':
	  case KEY_DOWN:
		menu=1;
		if(pos<lng/0x10-EDIT_MAX_LINES)
		  pos++;
		else
		  done = KEY_DOWN;
		break;
	  case KEY_PPAGE:
		menu=0;
		if(pos==0)
		  done=KEY_UP;
		if(pos>EDIT_MAX_LINES-1)
		  pos-=EDIT_MAX_LINES-1;
		else
		  pos=0;
		break;
	  case KEY_NPAGE:
		menu=1;
		if(pos==lng/0x10-EDIT_MAX_LINES)
		  done=KEY_DOWN;
		if(pos<lng/0x10-EDIT_MAX_LINES-(EDIT_MAX_LINES-1))
		  pos+=EDIT_MAX_LINES-1;
		else
		  pos=lng/0x10-EDIT_MAX_LINES;
		break;
	  case key_ESC:
	  case 'q':
	  case 'Q':
		done = 'Q';
		break;
	}
  } while(done==0);
  return done;
}