summaryrefslogtreecommitdiffstats
path: root/src/file_spf.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2009-01-14 22:01:29 +0100
committerChristophe Grenier <grenier@cgsecurity.org>2009-01-14 22:01:29 +0100
commit9ba29380c83b62499c5d3806d63ff784c526641b (patch)
treefd57f28b68022676da0b160016530788691c8724 /src/file_spf.c
parentc40ded302d983dedb0e84286dabd584a977dd821 (diff)
PhotoRec: try to find ShadowProtect spf filesize (Recovered file may be truncated)
Diffstat (limited to 'src/file_spf.c')
-rw-r--r--src/file_spf.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/file_spf.c b/src/file_spf.c
index 32b0950..027bdba 100644
--- a/src/file_spf.c
+++ b/src/file_spf.c
@@ -27,11 +27,14 @@
#include <string.h>
#endif
#include <stdio.h>
+#include <stdlib.h>
#include "types.h"
#include "filegen.h"
+#include "common.h"
static void register_header_check_spf(file_stat_t *file_stat);
static int header_check_spf(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);
+static void file_check_spf(file_recovery_t *file_recovery);
const file_hint_t file_hint_spf= {
.extension="spf",
@@ -58,7 +61,46 @@ static int header_check_spf(const unsigned char *buffer, const unsigned int buff
{
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_spf.extension;
+ file_recovery_new->file_check=file_check_spf;
return 1;
}
return 0;
}
+
+enum { READ_SIZE=32*512 };
+
+static void file_check_spf(file_recovery_t *file_recovery)
+{
+ unsigned char*buffer;
+ buffer=(unsigned char*)MALLOC(READ_SIZE);
+ if(fseek(file_recovery->handle, 0, SEEK_SET)<0)
+ return;
+ file_recovery->file_size=0;
+ while(1)
+ {
+ int i;
+ int taille;
+ taille=fread(buffer,1,READ_SIZE,file_recovery->handle);
+ if(taille<512)
+ {
+ file_recovery->file_size=0;
+ free(buffer);
+ return ;
+ }
+ for(i=0; i<taille; i+=512)
+ {
+ int j;
+ int is_valid=0;
+ file_recovery->file_size+=512;
+ for(j=0; j<8; j++)
+ if(buffer[i+j]!=0)
+ is_valid=1;
+ for(j=8; j<512 && buffer[i+j]==0; j++);
+ if(is_valid > 0 && j==512)
+ {
+ free(buffer);
+ return;
+ }
+ }
+ }
+}