summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2012-01-07 11:42:10 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2012-01-07 11:42:10 +0100
commit106fb14319f27da60ed76667a11bdae3fb4db057 (patch)
tree08a3a43ab3ee21443af45bd9e29988ed8018c27a
parentd741d15777e4249d824f0ba5db3350ac6fe56cb7 (diff)
Make FAT RebuildBS works when there is a single FAT table
-rw-r--r--src/fat_adv.c17
-rw-r--r--src/fat_cluster.c12
-rw-r--r--src/fat_cluster.h4
-rw-r--r--src/fat_unformat.c2
4 files changed, 22 insertions, 13 deletions
diff --git a/src/fat_adv.c b/src/fat_adv.c
index 39b3d4c..1674383 100644
--- a/src/fat_adv.c
+++ b/src/fat_adv.c
@@ -1831,7 +1831,11 @@ static upart_type_t select_fat_info(const info_offset_t *info_offset, const unsi
{
wmove(stdscr,INTER_FAT_ASK_Y, INTER_FAT_ASK_X);
fat2_location=ask_number(fat2_location,0,max_sector_offset,"FAT2 location ");
- if(fat2_location>*reserved)
+ if(fat2_location == *reserved)
+ {
+ *fats=1;
+ }
+ else if(fat2_location > *reserved)
{
*fat_length=fat2_location-*reserved;
wmove(stdscr,INTER_FAT_ASK_Y, INTER_FAT_ASK_X);
@@ -2016,7 +2020,7 @@ int rebuild_FAT_BS(disk_t *disk_car, partition_t *partition, const int verbose,
(fat_length==0)||(reserved==0))
{
uint64_t start_data=0;
- if(find_sectors_per_cluster(disk_car, partition, verbose, dump_ind, interface,&sectors_per_cluster,&start_data)==0)
+ if(find_sectors_per_cluster(disk_car, partition, verbose, dump_ind, interface, &sectors_per_cluster, &start_data, upart_type)==0)
{
display_message("Can't find cluster size\n");
return 0;
@@ -2064,9 +2068,12 @@ int rebuild_FAT_BS(disk_t *disk_car, partition_t *partition, const int verbose,
fat_length=(start_data-reserved-((dir_entries-1)/16+1))/fats;
break;
case UP_FAT32:
- reserved=32;
- if((start_data&1)!=0)
- reserved+=1;
+ if(reserved==0)
+ {
+ reserved=32;
+ if((start_data&1)!=0)
+ reserved+=1;
+ }
fat_length=(start_data-reserved)/fats;
break;
default: /* No compiler warning */
diff --git a/src/fat_cluster.c b/src/fat_cluster.c
index 2c71927..d66a949 100644
--- a/src/fat_cluster.c
+++ b/src/fat_cluster.c
@@ -40,7 +40,7 @@
/* Using a couple of inodes of "." directory entries, get the cluster size and where the first cluster begins.
* */
-int find_sectors_per_cluster(disk_t *disk_car, partition_t *partition, const int verbose, const int dump_ind,const int interface, unsigned int *sectors_per_cluster, uint64_t *offset_org)
+int find_sectors_per_cluster(disk_t *disk_car, partition_t *partition, const int verbose, const int dump_ind,const int interface, unsigned int *sectors_per_cluster, uint64_t *offset_org, const upart_type_t upart_type)
{
unsigned int nbr_subdir=0;
sector_cluster_t sector_cluster[10];
@@ -96,10 +96,10 @@ int find_sectors_per_cluster(disk_t *disk_car, partition_t *partition, const int
}
}
free(buffer);
- return find_sectors_per_cluster_aux(sector_cluster,nbr_subdir,sectors_per_cluster,offset_org,verbose,partition->part_size/disk_car->sector_size);
+ return find_sectors_per_cluster_aux(sector_cluster,nbr_subdir,sectors_per_cluster,offset_org,verbose,partition->part_size/disk_car->sector_size, upart_type);
}
-int find_sectors_per_cluster_aux(const sector_cluster_t *sector_cluster, const unsigned int nbr_sector_cluster,unsigned int *sectors_per_cluster, uint64_t *offset, const int verbose, const unsigned long int part_size_in_sectors)
+int find_sectors_per_cluster_aux(const sector_cluster_t *sector_cluster, const unsigned int nbr_sector_cluster,unsigned int *sectors_per_cluster, uint64_t *offset, const int verbose, const unsigned long int part_size_in_sectors, const upart_type_t upart_type)
{
cluster_offset_t *cluster_offset;
unsigned int i,j;
@@ -162,13 +162,14 @@ int find_sectors_per_cluster_aux(const sector_cluster_t *sector_cluster, const u
unsigned int nbr_max=0;
for(i=0;i<nbr_sol;i++)
{
+ const upart_type_t upart_type_new=no_of_cluster2part_type((part_size_in_sectors-cluster_offset[i].offset)/cluster_offset[i].sectors_per_cluster);
if(verbose>0)
{
log_verbose("sectors_per_cluster=%u offset=%lu nbr=%u ",
cluster_offset[i].sectors_per_cluster,
cluster_offset[i].offset,
cluster_offset[i].nbr);
- switch(no_of_cluster2part_type((part_size_in_sectors-cluster_offset[i].offset)/cluster_offset[i].sectors_per_cluster))
+ switch(upart_type_new)
{
case UP_FAT12:
log_info("FAT : 12\n");
@@ -183,7 +184,8 @@ int find_sectors_per_cluster_aux(const sector_cluster_t *sector_cluster, const u
break;
}
}
- if(cluster_offset[i].nbr>nbr_max)
+ if((upart_type==UP_UNK || upart_type==upart_type_new) &&
+ cluster_offset[i].nbr>nbr_max)
{
nbr_max=cluster_offset[i].nbr;
*sectors_per_cluster=cluster_offset[i].sectors_per_cluster;
diff --git a/src/fat_cluster.h b/src/fat_cluster.h
index d648b4a..c890a42 100644
--- a/src/fat_cluster.h
+++ b/src/fat_cluster.h
@@ -42,9 +42,9 @@ struct cluster_offset_struct
unsigned int first_sol;
};
-int find_sectors_per_cluster(disk_t *disk_car, partition_t *partition, const int verbose, const int dump_ind,const int interface, unsigned int *sectors_per_cluster, uint64_t *offset);
+int find_sectors_per_cluster(disk_t *disk_car, partition_t *partition, const int verbose, const int dump_ind,const int interface, unsigned int *sectors_per_cluster, uint64_t *offset, const upart_type_t upart_type);
upart_type_t no_of_cluster2part_type(const unsigned long int no_of_cluster);
-int find_sectors_per_cluster_aux(const sector_cluster_t *sector_cluster, const unsigned int nbr_sector_cluster,unsigned int *sectors_per_cluster, uint64_t *offset, const int verbose, const unsigned long int part_size_in_sectors);
+int find_sectors_per_cluster_aux(const sector_cluster_t *sector_cluster, const unsigned int nbr_sector_cluster,unsigned int *sectors_per_cluster, uint64_t *offset, const int verbose, const unsigned long int part_size_in_sectors, const upart_type_t upart_type);
#ifdef __cplusplus
} /* closing brace for extern "c" */
diff --git a/src/fat_unformat.c b/src/fat_unformat.c
index 5b29735..dc27216 100644
--- a/src/fat_unformat.c
+++ b/src/fat_unformat.c
@@ -115,7 +115,7 @@ static int pfind_sectors_per_cluster(disk_t *disk, partition_t *partition, const
}
} /* end while(current_search_space!=list_search_space) */
free(buffer_start);
- return find_sectors_per_cluster_aux(sector_cluster,nbr_subdir,sectors_per_cluster,offset_org,verbose,partition->part_size/disk->sector_size);
+ return find_sectors_per_cluster_aux(sector_cluster,nbr_subdir,sectors_per_cluster,offset_org,verbose,partition->part_size/disk->sector_size, UP_UNK);
}
static int fat_copy_file(disk_t *disk, const partition_t *partition, const unsigned int block_size, const uint64_t start_data, const char *recup_dir, const unsigned int dir_num, const file_data_t *file)