summaryrefslogtreecommitdiffstats
path: root/src/file_zip.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2011-03-05 19:08:11 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2011-03-05 19:08:11 +0100
commit2ec2d24a6554297f03e97e3408e3579761a57c86 (patch)
tree6fa5fbf187d2cae3cd2ff82828c36fff88ec8882 /src/file_zip.c
parentaf5d50aff99af236bc4db50c5738d8dc7778bb1d (diff)
PhotoRec: for zip archive, set the filename according to the first file in the archive
Diffstat (limited to 'src/file_zip.c')
-rw-r--r--src/file_zip.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/src/file_zip.c b/src/file_zip.c
index b03927d..3524bc2 100644
--- a/src/file_zip.c
+++ b/src/file_zip.c
@@ -46,6 +46,7 @@ static int header_check_zip(const unsigned char *buffer, const unsigned int buff
static void file_check_zip(file_recovery_t *file_recovery);
static unsigned int pos_in_mem(const unsigned char *haystack, const unsigned int haystack_size, const unsigned char *needle, const unsigned int needle_size);
static void file_rename_zip(const char *old_filename);
+static char first_filename[256];
const file_hint_t file_hint_zip= {
.extension="zip",
@@ -166,6 +167,12 @@ static int zip_parse_file_entry(file_recovery_t *fr, const char **ext, const uns
return -1;
}
filename[len]='\0';
+ if(first_filename[0]=='\0')
+ {
+ const unsigned int len_tmp=(len<255?len:255);
+ strncpy(first_filename, filename, len_tmp);
+ first_filename[len_tmp]='\0';
+ }
#ifdef DEBUG_ZIP
log_info("%s", filename);
#endif
@@ -490,7 +497,7 @@ static void file_check_zip(file_recovery_t *fr)
fr->file_size = 0;
fr->offset_error=0;
fr->offset_ok=0;
-
+ first_filename[0]='\0';
while (1)
{
uint64_t file_size_old;
@@ -575,6 +582,7 @@ static void file_rename_zip(const char *old_filename)
fseek(fr.handle, 0, SEEK_SET);
fr.file_size = 0;
fr.offset_error=0;
+ first_filename[0]='\0';
while (1)
{
@@ -647,7 +655,15 @@ static void file_rename_zip(const char *old_filename)
/* Only end of central dir is end of archive, 64b version of it is before */
if (header==ZIP_END_CENTRAL_DIR)
{
+ unsigned int len;
fclose(fr.handle);
+ for(len=0; len<32 &&
+ first_filename[len]!='\0' &&
+ first_filename[len]!='.' &&
+ first_filename[len]!='/' &&
+ first_filename[len]!='\\';
+ len++);
+ file_rename(old_filename, first_filename, len, 0, "zip", 0);
return;
}
}