summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2009-05-27 09:19:13 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2009-05-27 09:19:13 +0200
commit7b41ff4c5709cb486d2e5dfbd64e364785077d67 (patch)
treea1868db023726d2c22ee5890f3283bbf3f74f7aa
parent8b30c36b5d8b6b44279622351636fd4468381a5b (diff)
PhotoRec: file_search_footer() gets a new parameter
-rw-r--r--src/file_als.c4
-rw-r--r--src/file_arj.c2
-rw-r--r--src/file_asm.c4
-rw-r--r--src/file_crw.c4
-rw-r--r--src/file_cwk.c4
-rw-r--r--src/file_drw.c4
-rw-r--r--src/file_dxf.c2
-rw-r--r--src/file_frm.c4
-rw-r--r--src/file_gif.c2
-rw-r--r--src/file_hr9.c4
-rw-r--r--src/file_jpg.c2
-rw-r--r--src/file_mfa.c4
-rw-r--r--src/file_mfg.c4
-rw-r--r--src/file_mid.c2
-rw-r--r--src/file_mus.c2
-rw-r--r--src/file_njx.c2
-rw-r--r--src/file_pdf.c2
-rw-r--r--src/file_png.c6
-rw-r--r--src/file_prt.c4
-rw-r--r--src/file_rar.c2
-rw-r--r--src/file_tph.c4
-rw-r--r--src/file_txt.c8
-rw-r--r--src/filegen.c19
-rw-r--r--src/filegen.h2
24 files changed, 35 insertions, 62 deletions
diff --git a/src/file_als.c b/src/file_als.c
index 3bcbd42..c83c3df 100644
--- a/src/file_als.c
+++ b/src/file_als.c
@@ -81,7 +81,5 @@ static void file_check_als(file_recovery_t *file_recovery)
0x80, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
0x80, 0x00, 0x00, 0x00, 0x80, 0x01
};
- file_search_footer(file_recovery, als_footer, sizeof(als_footer));
- if(file_recovery->file_size>0)
- file_recovery->file_size+=7;
+ file_search_footer(file_recovery, als_footer, sizeof(als_footer), 7);
}
diff --git a/src/file_arj.c b/src/file_arj.c
index 9a647ad..2eba549 100644
--- a/src/file_arj.c
+++ b/src/file_arj.c
@@ -152,5 +152,5 @@ static int header_check_arj(const unsigned char *buffer, const unsigned int buff
static void file_check_arj(file_recovery_t *file_recovery)
{
static const unsigned char arj_footer[4]={0x60, 0xEA, 0x00, 0x00 };
- file_search_footer(file_recovery, arj_footer,sizeof(arj_footer));
+ file_search_footer(file_recovery, arj_footer, sizeof(arj_footer), 0);
}
diff --git a/src/file_asm.c b/src/file_asm.c
index 9074a62..03e9a0b 100644
--- a/src/file_asm.c
+++ b/src/file_asm.c
@@ -71,7 +71,5 @@ static void file_check_asm(file_recovery_t *file_recovery)
const unsigned char asm_footer[11]= {
'#', 'E', 'N', 'D', '_', 'O', 'F', '_',
'U', 'G', 'C'};
- file_search_footer(file_recovery, asm_footer,sizeof(asm_footer));
- if(file_recovery->file_size>0)
- file_recovery->file_size+=12; /* sizeof(asm_footer) + nl*/
+ file_search_footer(file_recovery, asm_footer, sizeof(asm_footer), 1);
}
diff --git a/src/file_crw.c b/src/file_crw.c
index 994c9d7..508068a 100644
--- a/src/file_crw.c
+++ b/src/file_crw.c
@@ -70,7 +70,5 @@ static int header_check_crw(const unsigned char *buffer, const unsigned int buff
static void file_check_crw(file_recovery_t *file_recovery)
{
const unsigned char crw_footer[2]= { 0x0A, 0x30};
- file_search_footer(file_recovery, crw_footer, sizeof(crw_footer));
- if(file_recovery->file_size>0)
- file_recovery->file_size+=12;
+ file_search_footer(file_recovery, crw_footer, sizeof(crw_footer), 12);
}
diff --git a/src/file_cwk.c b/src/file_cwk.c
index 4e3bc21..cbaca0c 100644
--- a/src/file_cwk.c
+++ b/src/file_cwk.c
@@ -66,7 +66,5 @@ static int header_check_cwk(const unsigned char *buffer, const unsigned int buff
static void file_check_cwk(file_recovery_t *file_recovery)
{
const unsigned char cwk_footer[4]= {0xf0, 0xf1, 0xf2, 0xf3};
- file_search_footer(file_recovery, cwk_footer,sizeof(cwk_footer));
- if(file_recovery->file_size>0)
- file_recovery->file_size+=4;
+ file_search_footer(file_recovery, cwk_footer, sizeof(cwk_footer), 4);
}
diff --git a/src/file_drw.c b/src/file_drw.c
index 40d5e8a..36eecec 100644
--- a/src/file_drw.c
+++ b/src/file_drw.c
@@ -71,7 +71,5 @@ static void file_check_drw(file_recovery_t *file_recovery)
const unsigned char drw_footer[11]= {
'#', 'E', 'N', 'D', '_', 'O', 'F', '_',
'U', 'G', 'C'};
- file_search_footer(file_recovery, drw_footer,sizeof(drw_footer));
- if(file_recovery->file_size>0)
- file_recovery->file_size+=12; /* sizeof(drw_footer) + nl*/
+ file_search_footer(file_recovery, drw_footer, sizeof(drw_footer), 1);
}
diff --git a/src/file_dxf.c b/src/file_dxf.c
index ba1925f..82158b2 100644
--- a/src/file_dxf.c
+++ b/src/file_dxf.c
@@ -100,6 +100,6 @@ static int data_check_dxf(const unsigned char *buffer, const unsigned int buffer
static void file_check_dxf(file_recovery_t *file_recovery)
{
const unsigned char dxf_footer[4]= {'\n', 'E', 'O', 'F'};
- file_search_footer(file_recovery, dxf_footer, sizeof(dxf_footer));
+ file_search_footer(file_recovery, dxf_footer, sizeof(dxf_footer), 0);
file_allow_nl(file_recovery, NL_BARENL|NL_CRLF);
}
diff --git a/src/file_frm.c b/src/file_frm.c
index cdb42fc..a861fd9 100644
--- a/src/file_frm.c
+++ b/src/file_frm.c
@@ -71,7 +71,5 @@ static void file_check_frm(file_recovery_t *file_recovery)
const unsigned char frm_footer[11]= {
'#', 'E', 'N', 'D', '_', 'O', 'F', '_',
'U', 'G', 'C'};
- file_search_footer(file_recovery, frm_footer,sizeof(frm_footer));
- if(file_recovery->file_size>0)
- file_recovery->file_size+=12; /* sizeof(frm_footer) + nl*/
+ file_search_footer(file_recovery, frm_footer, sizeof(frm_footer), 1);
}
diff --git a/src/file_gif.c b/src/file_gif.c
index c91d621..f2cbf68 100644
--- a/src/file_gif.c
+++ b/src/file_gif.c
@@ -82,7 +82,7 @@ static int header_check_gif(const unsigned char *buffer, const unsigned int buff
static void file_check_gif(file_recovery_t *file_recovery)
{
const unsigned char gif_footer[2]= {0x00, 0x3b};
- file_search_footer(file_recovery, gif_footer,sizeof(gif_footer));
+ file_search_footer(file_recovery, gif_footer, sizeof(gif_footer), 0);
}
static int data_check_gif(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
diff --git a/src/file_hr9.c b/src/file_hr9.c
index 023b105..a725180 100644
--- a/src/file_hr9.c
+++ b/src/file_hr9.c
@@ -69,7 +69,5 @@ static int header_check_hr9(const unsigned char *buffer, const unsigned int buff
static void file_check_hr9(file_recovery_t *file_recovery)
{
const unsigned char hr9_footer[4]= {0xc0, 0xde, 0xca, 0xfe};
- file_search_footer(file_recovery, hr9_footer, sizeof(hr9_footer));
- if(file_recovery->file_size>0)
- file_recovery->file_size+=0x50-4;
+ file_search_footer(file_recovery, hr9_footer, sizeof(hr9_footer), 0x50-4);
}
diff --git a/src/file_jpg.c b/src/file_jpg.c
index eb03b71..8dd653e 100644
--- a/src/file_jpg.c
+++ b/src/file_jpg.c
@@ -470,7 +470,7 @@ static void file_check_jpg(file_recovery_t *file_recovery)
}
#endif
file_recovery->file_size=jpeg_size;
- file_search_footer(file_recovery, jpg_footer,sizeof(jpg_footer));
+ file_search_footer(file_recovery, jpg_footer, sizeof(jpg_footer), 0);
}
static void jpg_check_structure(file_recovery_t *file_recovery, const unsigned int extract_thumb)
diff --git a/src/file_mfa.c b/src/file_mfa.c
index 031b7d6..6afd609 100644
--- a/src/file_mfa.c
+++ b/src/file_mfa.c
@@ -66,7 +66,5 @@ static int header_check_mfa(const unsigned char *buffer, const unsigned int buff
static void file_check_mfa(file_recovery_t *file_recovery)
{
const unsigned char mfa_footer[5]= {'!','D','N','E', '!'};
- file_search_footer(file_recovery, mfa_footer,sizeof(mfa_footer));
- if(file_recovery->file_size>0)
- file_recovery->file_size+=0x84;
+ file_search_footer(file_recovery, mfa_footer, sizeof(mfa_footer), 0x84);
}
diff --git a/src/file_mfg.c b/src/file_mfg.c
index 83edb66..60e0b78 100644
--- a/src/file_mfg.c
+++ b/src/file_mfg.c
@@ -71,7 +71,5 @@ static void file_check_mfg(file_recovery_t *file_recovery)
const unsigned char mfg_footer[11]= {
'#', 'E', 'N', 'D', '_', 'O', 'F', '_',
'U', 'G', 'C'};
- file_search_footer(file_recovery, mfg_footer,sizeof(mfg_footer));
- if(file_recovery->file_size>0)
- file_recovery->file_size+=12; /* sizeof(mfg_footer) + nl*/
+ file_search_footer(file_recovery, mfg_footer, sizeof(mfg_footer), 1);
}
diff --git a/src/file_mid.c b/src/file_mid.c
index 0ac39a4..487697c 100644
--- a/src/file_mid.c
+++ b/src/file_mid.c
@@ -68,5 +68,5 @@ static int header_check_mid(const unsigned char *buffer, const unsigned int buff
static void file_check_mid(file_recovery_t *file_recovery)
{
const unsigned char mid_footer[3]= {0xff, 0x2f, 0x00};
- file_search_footer(file_recovery, mid_footer,sizeof(mid_footer));
+ file_search_footer(file_recovery, mid_footer, sizeof(mid_footer), 0);
}
diff --git a/src/file_mus.c b/src/file_mus.c
index 57c46f2..459460d 100644
--- a/src/file_mus.c
+++ b/src/file_mus.c
@@ -68,5 +68,5 @@ static int header_check_mus(const unsigned char *buffer, const unsigned int buff
static void file_check_mus(file_recovery_t *file_recovery)
{
const unsigned char mus_footer[5]= {'-','^','e','n','d'};
- file_search_footer(file_recovery, mus_footer,sizeof(mus_footer));
+ file_search_footer(file_recovery, mus_footer, sizeof(mus_footer), 0);
}
diff --git a/src/file_njx.c b/src/file_njx.c
index b37e4fc..4e703fd 100644
--- a/src/file_njx.c
+++ b/src/file_njx.c
@@ -68,5 +68,5 @@ static int header_check_njx(const unsigned char *buffer, const unsigned int buff
static void file_check_njx(file_recovery_t *file_recovery)
{
const unsigned char njx_footer[4]= {'N', 'J', '*', 0x04};
- file_search_footer(file_recovery, njx_footer,sizeof(njx_footer));
+ file_search_footer(file_recovery, njx_footer, sizeof(njx_footer), 0);
}
diff --git a/src/file_pdf.c b/src/file_pdf.c
index ef828ae..c2e1793 100644
--- a/src/file_pdf.c
+++ b/src/file_pdf.c
@@ -122,6 +122,6 @@ static void file_check_pdf_and_size(file_recovery_t *file_recovery)
static void file_check_pdf(file_recovery_t *file_recovery)
{
const unsigned char pdf_footer[4]= { '%', 'E', 'O', 'F'};
- file_search_footer(file_recovery, pdf_footer, sizeof(pdf_footer));
+ file_search_footer(file_recovery, pdf_footer, sizeof(pdf_footer), 0);
file_allow_nl(file_recovery, NL_BARENL|NL_CRLF|NL_BARECR);
}
diff --git a/src/file_png.c b/src/file_png.c
index 070f608..ee95146 100644
--- a/src/file_png.c
+++ b/src/file_png.c
@@ -103,9 +103,7 @@ static void file_check_png(file_recovery_t *file_recovery)
const unsigned char mng_footer[4]= {'M','E','N','D'};
const unsigned char png_footer[4]= {'I','E','N','D'};
if(strstr(file_recovery->filename,".mng")!=NULL)
- file_search_footer(file_recovery, mng_footer,sizeof(mng_footer));
+ file_search_footer(file_recovery, mng_footer, sizeof(mng_footer), 4);
else
- file_search_footer(file_recovery, png_footer,sizeof(png_footer));
- if(file_recovery->file_size>0)
- file_recovery->file_size+=4;
+ file_search_footer(file_recovery, png_footer, sizeof(png_footer), 4);
}
diff --git a/src/file_prt.c b/src/file_prt.c
index 8a9cc33..e45d1e2 100644
--- a/src/file_prt.c
+++ b/src/file_prt.c
@@ -71,7 +71,5 @@ static void file_check_prt(file_recovery_t *file_recovery)
const unsigned char prt_footer[11]= {
'#', 'E', 'N', 'D', '_', 'O', 'F', '_',
'U', 'G', 'C'};
- file_search_footer(file_recovery, prt_footer,sizeof(prt_footer));
- if(file_recovery->file_size>0)
- file_recovery->file_size+=12; /* sizeof(prt_footer) + nl*/
+ file_search_footer(file_recovery, prt_footer, sizeof(prt_footer), 1);
}
diff --git a/src/file_rar.c b/src/file_rar.c
index 55a5548..2da3d0c 100644
--- a/src/file_rar.c
+++ b/src/file_rar.c
@@ -68,5 +68,5 @@ static int header_check_rar(const unsigned char *buffer, const unsigned int buff
static void file_check_rar(file_recovery_t *file_recovery)
{
static const unsigned char rar_footer[7]={0xc4, 0x3d, 0x7b, 0x00, 0x40, 0x07, 0x00 };
- file_search_footer(file_recovery, rar_footer,sizeof(rar_footer));
+ file_search_footer(file_recovery, rar_footer, sizeof(rar_footer), 0);
}
diff --git a/src/file_tph.c b/src/file_tph.c
index 2d2b15a..243f52b 100644
--- a/src/file_tph.c
+++ b/src/file_tph.c
@@ -72,7 +72,5 @@ static void file_check_tph(file_recovery_t *file_recovery)
const unsigned char tph_footer[11]= {
'#', 'E', 'N', 'D', '_', 'O', 'F', '_',
'U', 'G', 'C'};
- file_search_footer(file_recovery, tph_footer,sizeof(tph_footer));
- if(file_recovery->file_size>0)
- file_recovery->file_size+=12; /* sizeof(tph_footer) + nl*/
+ file_search_footer(file_recovery, tph_footer, sizeof(tph_footer), 1);
}
diff --git a/src/file_txt.c b/src/file_txt.c
index 527269a..12743e4 100644
--- a/src/file_txt.c
+++ b/src/file_txt.c
@@ -949,28 +949,28 @@ static void file_check_emlx(file_recovery_t *file_recovery)
{
if(file_recovery->file_size > file_recovery->calculated_file_size+2048)
file_recovery->file_size=file_recovery->calculated_file_size+2048;
- file_search_footer(file_recovery, emlx_footer,sizeof(emlx_footer));
+ file_search_footer(file_recovery, emlx_footer, sizeof(emlx_footer), 0);
}
}
static void file_check_xml(file_recovery_t *file_recovery)
{
const unsigned char xml_footer[1]= { '>'};
- file_search_footer(file_recovery, xml_footer, sizeof(xml_footer));
+ file_search_footer(file_recovery, xml_footer, sizeof(xml_footer), 0);
file_allow_nl(file_recovery, NL_BARENL|NL_CRLF|NL_BARECR);
}
static void file_check_ers(file_recovery_t *file_recovery)
{
const unsigned char ers_footer[17]= "DatasetHeader End";
- file_search_footer(file_recovery, ers_footer, sizeof(ers_footer));
+ file_search_footer(file_recovery, ers_footer, sizeof(ers_footer), 0);
file_allow_nl(file_recovery, NL_BARENL|NL_CRLF|NL_BARECR);
}
static void file_check_svg(file_recovery_t *file_recovery)
{
const unsigned char svg_footer[6]= { '<', '/', 's', 'v', 'g', '>'};
- file_search_footer(file_recovery, svg_footer, sizeof(svg_footer));
+ file_search_footer(file_recovery, svg_footer, sizeof(svg_footer), 0);
file_allow_nl(file_recovery, NL_BARENL|NL_CRLF|NL_BARECR);
}
diff --git a/src/filegen.c b/src/filegen.c
index 0051295..9fe368b 100644
--- a/src/filegen.c
+++ b/src/filegen.c
@@ -192,24 +192,21 @@ void file_allow_nl(file_recovery_t *file_recovery, const unsigned int nl_mode)
file_recovery->file_size++;
}
-void file_search_footer(file_recovery_t *file_recovery, const unsigned char*footer, const unsigned int footer_length)
+void file_search_footer(file_recovery_t *file_recovery, const unsigned char*footer, const unsigned int footer_length, const unsigned int extra_length)
{
- const unsigned int read_size=4096;
unsigned char*buffer;
int64_t file_size;
- if(footer_length==0)
+ if(footer_length==0 || file_recovery->file_size <= extra_length)
return ;
- buffer=(unsigned char*)MALLOC(read_size+footer_length-1);
- file_size=file_recovery->file_size;
- memset(buffer+read_size,0,footer_length-1);
+ buffer=(unsigned char*)MALLOC(4096+footer_length-1);
+ file_size=file_recovery->file_size-extra_length;
+ memset(buffer+4096,0,footer_length-1);
do
{
int i;
int taille;
- if(file_size%read_size!=0)
- file_size=file_size-(file_size%read_size);
- else
- file_size-=read_size;
+ const unsigned int read_size=(file_size%4096!=0 ? file_size%4096 : 4096);
+ file_size-=read_size;
if(fseek(file_recovery->handle,file_size,SEEK_SET)<0)
{
free(buffer);
@@ -220,7 +217,7 @@ void file_search_footer(file_recovery_t *file_recovery, const unsigned char*foot
{
if(buffer[i]==footer[0] && memcmp(buffer+i,footer,footer_length)==0)
{
- file_recovery->file_size=file_size+i+footer_length;
+ file_recovery->file_size=file_size + i + footer_length + extra_length;
free(buffer);
return;
}
diff --git a/src/filegen.h b/src/filegen.h
index 24a5c97..ef0c4f9 100644
--- a/src/filegen.h
+++ b/src/filegen.h
@@ -119,7 +119,7 @@ typedef struct
void free_header_check(void);
void file_allow_nl(file_recovery_t *file_recovery, const unsigned int nl_mode);
-void file_search_footer(file_recovery_t *file_recovery, const unsigned char*footer, const unsigned int footer_length);
+void file_search_footer(file_recovery_t *file_recovery, const unsigned char*footer, const unsigned int footer_length, const unsigned int extra_length);
void file_search_lc_footer(file_recovery_t *file_recovery, const unsigned char*footer, const unsigned int footer_length);
void del_search_space(alloc_data_t *list_search_space, const uint64_t start, const uint64_t end);
int data_check_size(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery);