summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2018-10-30 19:00:13 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2018-10-30 19:00:13 +0100
commit7da08fa5b30750325c4d8b3f94da698b25fa7b4c (patch)
tree7cfd3f18d9c2bd94735c03edc222a530b702256b
parenta6da0c4b9691c19f6daed3aab17a4b5fafa88429 (diff)
Remove ending space or dot when copying files from FAT
-rw-r--r--src/dir.c12
-rw-r--r--src/fat_unformat.c13
2 files changed, 25 insertions, 0 deletions
diff --git a/src/dir.c b/src/dir.c
index 12c8cf7..f1f0fdf 100644
--- a/src/dir.c
+++ b/src/dir.c
@@ -477,6 +477,17 @@ int set_mode(const char *pathname, unsigned int mode)
#endif
}
+static void strip_fn(char *fn)
+{
+ unsigned int i;
+ for(i=0;fn[i]!='\0';i++);
+ while(i>0 && (fn[i-1]==' '||fn[i-1]=='.'))
+ i--;
+ if(i==0 && (fn[i]==' '||fn[i]=='.'))
+ fn[i++]='_';
+ fn[i]='\0';
+}
+
#ifdef DJGPP
static inline unsigned char convert_char_dos(unsigned char car)
{
@@ -742,6 +753,7 @@ FILE *fopen_local(char **localfilename, const char *localroot, const char *filen
memcpy(dst, localroot, l1);
memcpy(dst+l1, filename, l2+1);
*localfilename=dst;
+ strip_fn(dst);
f_out=fopen(dst,"wb");
if(f_out)
return f_out;
diff --git a/src/fat_unformat.c b/src/fat_unformat.c
index 2bae824..4cf6a83 100644
--- a/src/fat_unformat.c
+++ b/src/fat_unformat.c
@@ -138,6 +138,17 @@ static int pfind_sectors_per_cluster(disk_t *disk, partition_t *partition, const
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 void strip_fn(char *fn)
+{
+ unsigned int i;
+ for(i=0; fn[i]!='\0'; i++);
+ while(i>0 && (fn[i-1]==' ' || fn[i-1]=='.'))
+ i--;
+ if(i==0 && (fn[0]==' ' || fn[0]=='.'))
+ fn[i++]='_';
+ fn[i]='\0';
+}
+
static int fat_copy_file(disk_t *disk, const partition_t *partition, const unsigned int cluster_size, const uint64_t start_data, const char *recup_dir, const unsigned int dir_num, const unsigned int inode_num, const file_info_t *file)
{
char *new_file;
@@ -158,12 +169,14 @@ static int fat_copy_file(disk_t *disk, const partition_t *partition, const unsig
#endif
snprintf(new_file, 1024, "%s.%u/inode_%u/%s", recup_dir, dir_num, inode_num,
file->name);
+ strip_fn(new_file);
if((f_out=fopen(new_file, "rb"))!=NULL)
{
fclose(f_out);
snprintf(new_file, 1024, "%s.%u/inode_%u/f%07u-%s", recup_dir, dir_num, inode_num,
(unsigned int)((start_data - partition->part_offset + (uint64_t)(cluster-2)*cluster_size)/disk->sector_size),
file->name);
+ strip_fn(new_file);
}
log_info("fat_copy_file %s\n", new_file);
f_out=fopen(new_file, "wb");