summaryrefslogtreecommitdiffstats
path: root/src/file_txt.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2015-09-17 20:51:28 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2015-09-17 20:51:28 +0200
commitd4bacb5f650c3fdd7ed498d9ae72e1c6dde0704d (patch)
treef5ef0cf9ec6c3c20d0cd450ef6d2edba7f9fc6d3 /src/file_txt.c
parentb5f5bb37887dca729d9368b04877fcb81d8b182b (diff)
PhotoRec: recover OpenDocument Flat XML Spreadsheet .fods files.
Use title when naming .html files
Diffstat (limited to 'src/file_txt.c')
-rw-r--r--src/file_txt.c80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/file_txt.c b/src/file_txt.c
index 3792285..814816b 100644
--- a/src/file_txt.c
+++ b/src/file_txt.c
@@ -581,6 +581,74 @@ static int header_check_dc(const unsigned char *buffer, const unsigned int buffe
return 0;
}
+static void file_rename_fods(file_recovery_t *file_recovery)
+{
+ FILE *file;
+ char buffer[4096];
+ char *tmp;
+ if((file=fopen(file_recovery->filename, "rb"))==NULL)
+ return;
+ memset(buffer, 0, sizeof(buffer));
+ if(fread(&buffer, 1, sizeof(buffer)-1, file) <= 0)
+ {
+ fclose(file);
+ return ;
+ }
+ tmp=strchr(buffer,'<');
+ while(tmp!=NULL)
+ {
+ if(strncasecmp(tmp, "<office:meta><dc:title>", 23)==0)
+ {
+ const char *title=tmp+23;
+ tmp=strchr(title,'<');
+ if(tmp!=NULL)
+ *tmp='\0';
+ file_rename(file_recovery, (const unsigned char*)title, strlen(title), 0, NULL, 1);
+ fclose(file);
+ return ;
+ }
+ tmp++;
+ tmp=strchr(tmp,'<');
+ }
+ fclose(file);
+}
+static void file_rename_html(file_recovery_t *file_recovery)
+{
+ FILE *file;
+ char buffer[4096];
+ char *tmp;
+ if((file=fopen(file_recovery->filename, "rb"))==NULL)
+ return;
+ memset(buffer, 0, sizeof(buffer));
+ if(fread(&buffer, 1, sizeof(buffer)-1, file) <= 0)
+ {
+ fclose(file);
+ return ;
+ }
+ tmp=strchr(buffer,'<');
+ while(tmp!=NULL)
+ {
+ if(strncasecmp(tmp, "</head", 5)==0)
+ {
+ fclose(file);
+ return ;
+ }
+ if(strncasecmp(tmp, "<title>", 7)==0)
+ {
+ const char *title=tmp+7;
+ tmp=strchr(title,'<');
+ if(tmp!=NULL)
+ *tmp='\0';
+ file_rename(file_recovery, (const unsigned char*)title, strlen(title), 0, NULL, 1);
+ fclose(file);
+ return ;
+ }
+ tmp++;
+ tmp=strchr(tmp,'<');
+ }
+ fclose(file);
+}
+
static int header_check_html(const unsigned char *buffer, const unsigned int buffer_size, const unsigned int safe_header_only, const file_recovery_t *file_recovery, file_recovery_t *file_recovery_new)
{
if(file_recovery->file_stat!=NULL &&
@@ -598,6 +666,7 @@ static int header_check_html(const unsigned char *buffer, const unsigned int buf
#else
file_recovery_new->extension="html";
#endif
+ file_recovery_new->file_rename=&file_rename_html;
return 1;
}
@@ -644,6 +713,7 @@ static int header_check_xml(const unsigned char *buffer, const unsigned int buff
#else
file_recovery_new->extension="html";
#endif
+ file_recovery_new->file_rename=&file_rename_html;
}
else if(strncasecmp(tmp, "<Version>QBFSD", 14)==0)
{
@@ -683,6 +753,13 @@ static int header_check_xml(const unsigned char *buffer, const unsigned int buff
/* FictionBook, see http://www.fictionbook.org */
file_recovery_new->extension="fb2";
}
+ else if(strncasecmp(tmp, "<office:document", 16)==0)
+ {
+ /* OpenDocument Flat XML Spreadsheet */
+ file_recovery_new->extension="fods";
+ file_recovery_new->data_check=NULL;
+ file_recovery_new->file_rename=&file_rename_fods;
+ }
tmp++;
tmp=strchr(tmp,'<');
}
@@ -1177,7 +1254,10 @@ static int header_check_txt(const unsigned char *buffer, const unsigned int buff
}
reset_file_recovery(file_recovery_new);
if(strcmp(ext, "html")==0)
+ {
+ file_recovery_new->file_rename=&file_rename_html;
file_recovery_new->data_check=&data_check_html;
+ }
else
file_recovery_new->data_check=&data_check_txt;
file_recovery_new->file_check=&file_check_size;