summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2012-12-08 18:01:42 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2012-12-08 18:01:42 +0100
commitda6fe469c456e92aa4460b97a692fdd64b90043f (patch)
tree87072dbe21f9d5efe6d037b2e56b2a80b0233453
parent4ab4b390670703606b43791b2a03e3cbc1d56378 (diff)
Windows: workaround for NTFS Alternate Data Stream creation
fopen() creates normal files instead of ADS with ':' replaced by an UTF char replace ':' by '_' instead
-rw-r--r--src/ntfs_dir.c18
-rw-r--r--src/phbf.c10
-rw-r--r--src/phrecn.c6
3 files changed, 23 insertions, 11 deletions
diff --git a/src/ntfs_dir.c b/src/ntfs_dir.c
index ebbc05e..8c012e9 100644
--- a/src/ntfs_dir.c
+++ b/src/ntfs_dir.c
@@ -180,9 +180,8 @@ static int ntfs_td_list_entry( struct ntfs_dir_struct *ls, const ntfschar *name
const int name_len, const int name_type, const s64 pos,
const MFT_REF mref, const unsigned dt_type)
{
- char *filename = NULL;
int result = 0;
- filename = (char *)calloc (1, MAX_PATH);
+ char *filename = (char *)calloc (1, MAX_PATH);
if (!filename)
{
log_critical("ntfs_td_list_entry calloc failed\n");
@@ -369,7 +368,7 @@ static int ntfs_copy(disk_t *disk_car, const partition_t *partition, dir_data_t
FILE *f_out;
s64 offset;
u32 block_size;
- const char *stream_name=NULL;
+ char *stream_name;
buffer = (char *)MALLOC(bufsize);
if (!buffer)
{
@@ -407,7 +406,20 @@ static int ntfs_copy(disk_t *disk_car, const partition_t *partition, dir_data_t
block_size = index_get_size(inode);
else
block_size = 0;
+#if defined(__CYGWIN__) || defined(__MINGW32__)
+ if(stream_name)
+ {
+ /* fopen() create normal files instead of ADS with ':' replaced by an UTF char
+ * replace ':' by '_' instead */
+ stream_name--;
+ *stream_name='_';
+ f_out=fopen_local(&new_file, dir_data->local_dir, dir_data->current_directory);
+ }
+ else
+ f_out=fopen_local(&new_file, dir_data->local_dir, dir_data->current_directory);
+#else
f_out=fopen_local(&new_file, dir_data->local_dir, dir_data->current_directory);
+#endif
if(!f_out)
{
log_critical("Can't create file %s: %s\n",new_file, strerror(errno));
diff --git a/src/phbf.c b/src/phbf.c
index 3180a9f..160e5c1 100644
--- a/src/phbf.c
+++ b/src/phbf.c
@@ -253,7 +253,7 @@ int photorec_bf(struct ph_param *params, const struct ph_options *options, alloc
{
if(fwrite(buffer,blocksize,1,file_recovery.handle)<1)
{
- log_critical("Cannot write to file %s:%s\n", file_recovery.filename, strerror(errno));
+ log_critical("Cannot write to file %s: %s\n", file_recovery.filename, strerror(errno));
ind_stop=3;
}
}
@@ -386,7 +386,7 @@ static int photorec_bf_pad(struct ph_param *params, file_recovery_t *file_recove
}
if(fwrite(block_buffer, blocksize, 1, file_recovery->handle)<1)
{
- log_critical("Cannot write to file %s:%s\n", file_recovery->filename, strerror(errno));
+ log_critical("Cannot write to file %s: %s\n", file_recovery->filename, strerror(errno));
fclose(file_recovery->handle);
file_recovery->handle=NULL;
return BF_ERR_STOP;
@@ -413,7 +413,7 @@ static int photorec_bf_pad(struct ph_param *params, file_recovery_t *file_recove
params->disk->pread(params->disk, block_buffer, blocksize, *offset);
if(fwrite(block_buffer, blocksize, 1, file_recovery->handle)<1)
{
- log_critical("Cannot write to file %s:%s\n", file_recovery->filename, strerror(errno));
+ log_critical("Cannot write to file %s: %s\n", file_recovery->filename, strerror(errno));
fclose(file_recovery->handle);
file_recovery->handle=NULL;
return BF_ERR_STOP;
@@ -544,7 +544,7 @@ static int photorec_bf_frag_fast(struct ph_param *params, file_recovery_t *file_
}
if(fwrite(block_buffer, blocksize, 1, file_recovery->handle)<1)
{
- log_critical("Cannot write to file %s:%s\n", file_recovery->filename, strerror(errno));
+ log_critical("Cannot write to file %s: %s\n", file_recovery->filename, strerror(errno));
fclose(file_recovery->handle);
file_recovery->handle=NULL;
return BF_ERR_STOP;
@@ -811,7 +811,7 @@ static int photorec_bf_aux(struct ph_param *params, file_recovery_t *file_recove
/* FIXME: Handle ext2/ext3 */
if(fwrite(block_buffer, blocksize, 1, file_recovery->handle)<1)
{
- log_critical("Cannot write to file %s:%s\n", file_recovery->filename, strerror(errno));
+ log_critical("Cannot write to file %s: %s\n", file_recovery->filename, strerror(errno));
fclose(file_recovery->handle);
file_recovery->handle=NULL;
free(buffer);
diff --git a/src/phrecn.c b/src/phrecn.c
index 52dc519..3716924 100644
--- a/src/phrecn.c
+++ b/src/phrecn.c
@@ -363,7 +363,7 @@ static int photorec_aux(struct ph_param *params, const struct ph_options *option
{
if(fwrite(buffer,blocksize,1,file_recovery.handle)<1)
{
- log_critical("Cannot write to file %s:%s\n", file_recovery.filename, strerror(errno));
+ log_critical("Cannot write to file %s: %s\n", file_recovery.filename, strerror(errno));
if(errno==EFBIG)
{
/* File is too big for the destination filesystem */
@@ -619,7 +619,7 @@ static void gen_image(const char *filename, disk_t *disk, const alloc_data_t *li
disk->pread(disk, buffer, read_size, offset);
if(fwrite(buffer, read_size, 1, out)<1)
{
- log_critical("Cannot write to file %s:%s\n", filename, strerror(errno));
+ log_critical("Cannot write to file %s: %s\n", filename, strerror(errno));
free(buffer);
fclose(out);
return ;
@@ -699,7 +699,7 @@ static void test_files_aux(file_recovery_t *file_recovery, struct ph_param *para
}
if(fwrite(buffer, datasize, 1, file_recovery->handle)<1)
{
- log_critical("Cannot write to file %s:%s\n", file_recovery->filename, strerror(errno));
+ log_critical("Cannot write to file %s: %s\n", file_recovery->filename, strerror(errno));
fclose(file_recovery->handle);
file_recovery->handle=NULL;
free(buffer);