PhotoRec: better check to avoid to concat mp3 files

This commit is contained in:
Christophe Grenier 2014-03-30 19:31:33 +02:00
parent 45903de1b5
commit a23c1b5a88
9 changed files with 27 additions and 25 deletions

View file

@ -80,7 +80,7 @@ static int header_check_bac(const unsigned char *buffer, const unsigned int buff
file_recovery_new->calculated_file_size=0;
if(file_recovery_new->blocksize >= 0x18/2)
{
file_recovery_new->data_check=data_check_bac;
file_recovery_new->data_check=&data_check_bac;
file_recovery_new->file_check=&file_check_size;
}
return 1;

View file

@ -106,7 +106,7 @@ static int header_check_caf(const unsigned char *buffer, const unsigned int buff
{
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_caf.extension;
file_recovery_new->data_check=data_check_caf;
file_recovery_new->data_check=&data_check_caf;
file_recovery_new->file_check=&file_check_size;
file_recovery_new->calculated_file_size=8;
return 1;

View file

@ -52,7 +52,7 @@ static void register_header_check_dv(file_stat_t *file_stat)
static int header_check_dv(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!=NULL && file_recovery->file_stat!=NULL && file_recovery->file_stat->file_hint==&file_hint_dv)
if(file_recovery!=NULL && file_recovery->data_check==&data_check_dv)
return 0;
/* The header may be only 3 bytes */
if(buffer[0]==0x1f && buffer[1]==0x07 && buffer[2]==0x00 && buffer[5]==0x78 && buffer[6]==0x78 && buffer[7]==0x78)
@ -60,7 +60,7 @@ static int header_check_dv(const unsigned char *buffer, const unsigned int buffe
/* NTSC */
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_dv.extension;
file_recovery_new->data_check=data_check_dv;
file_recovery_new->data_check=&data_check_dv;
file_recovery_new->file_check=&file_check_size;
return 1;
}

View file

@ -222,7 +222,7 @@ static int header_check_emf(const unsigned char *buffer, const unsigned int buff
const unsigned int atom_size=buffer[4]+(buffer[5]<<8)+(buffer[6]<<16)+(buffer[7]<<24);
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_emf.extension;
file_recovery_new->data_check=data_check_emf;
file_recovery_new->data_check=&data_check_emf;
file_recovery_new->file_check=&file_check_size;
file_recovery_new->calculated_file_size=atom_size;
return 1;

View file

@ -101,8 +101,8 @@ static int header_check_mov(const unsigned char *buffer, const unsigned int buff
if(buffer[4]=='f' && buffer[5]=='t' && buffer[6]=='y' && buffer[7]=='p')
{
}
else if(file_recovery!=NULL && file_recovery->file_stat!=NULL &&
file_recovery->file_stat->file_hint==&file_hint_mov &&
else if(file_recovery!=NULL &&
file_recovery->data_check==&data_check_mov &&
file_recovery->calculated_file_size == file_recovery->file_size)
{ /* PhotoRec is already trying to recover this mov file */
return 0;
@ -127,7 +127,7 @@ static int header_check_mov(const unsigned char *buffer, const unsigned int buff
return 0;
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_mov.extension;
file_recovery_new->data_check=data_check_mov;
file_recovery_new->data_check=&data_check_mov;
file_recovery_new->file_check=&file_check_size;
file_recovery_new->calculated_file_size=i+atom_size;
return 1;
@ -138,7 +138,7 @@ static int header_check_mov(const unsigned char *buffer, const unsigned int buff
return 0;
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_mov.extension;
file_recovery_new->data_check=data_check_mov;
file_recovery_new->data_check=&data_check_mov;
file_recovery_new->file_check=&file_check_size;
file_recovery_new->calculated_file_size=i+atom_size;
return 1;
@ -154,11 +154,11 @@ static int header_check_mov(const unsigned char *buffer, const unsigned int buff
if(i==0 && buffer[12]=='m' && buffer[13]=='v' && buffer[14]=='h' && buffer[15]=='d')
{
file_recovery_new->calculated_file_size=atom_size;
file_recovery_new->data_check=data_check_size;
file_recovery_new->data_check=&data_check_size;
}
else
*/
file_recovery_new->data_check=data_check_mov;
file_recovery_new->data_check=&data_check_mov;
file_recovery_new->file_check=&file_check_size;
file_recovery_new->calculated_file_size=i+atom_size;
return 1;
@ -176,7 +176,7 @@ static int header_check_mov(const unsigned char *buffer, const unsigned int buff
{
reset_file_recovery(file_recovery_new);
file_recovery_new->extension="mp4";
file_recovery_new->data_check=data_check_mov;
file_recovery_new->data_check=&data_check_mov;
file_recovery_new->file_check=&file_check_size;
file_recovery_new->calculated_file_size=i+atom_size;
return 1;
@ -186,7 +186,7 @@ static int header_check_mov(const unsigned char *buffer, const unsigned int buff
reset_file_recovery(file_recovery_new);
/* acc ? */
file_recovery_new->extension="m4p";
file_recovery_new->data_check=data_check_mov;
file_recovery_new->data_check=&data_check_mov;
file_recovery_new->file_check=&file_check_size;
file_recovery_new->calculated_file_size=i+atom_size;
return 1;
@ -196,7 +196,7 @@ static int header_check_mov(const unsigned char *buffer, const unsigned int buff
/* Video for 3G mobile phone (GSM) */
reset_file_recovery(file_recovery_new);
file_recovery_new->extension="3gp";
file_recovery_new->data_check=data_check_mov;
file_recovery_new->data_check=&data_check_mov;
file_recovery_new->file_check=&file_check_size;
file_recovery_new->calculated_file_size=i+atom_size;
return 1;
@ -206,7 +206,7 @@ static int header_check_mov(const unsigned char *buffer, const unsigned int buff
/* Video for 3G mobile phone (CDMA) */
reset_file_recovery(file_recovery_new);
file_recovery_new->extension="3g2";
file_recovery_new->data_check=data_check_mov;
file_recovery_new->data_check=&data_check_mov;
file_recovery_new->file_check=&file_check_size;
file_recovery_new->calculated_file_size=i+atom_size;
return 1;
@ -222,7 +222,7 @@ static int header_check_mov(const unsigned char *buffer, const unsigned int buff
{
reset_file_recovery(file_recovery_new);
file_recovery_new->extension="mov";
file_recovery_new->data_check=data_check_mov;
file_recovery_new->data_check=&data_check_mov;
file_recovery_new->file_check=&file_check_size;
file_recovery_new->file_rename=&file_rename_mov;
file_recovery_new->calculated_file_size=i+atom_size;
@ -234,7 +234,7 @@ static int header_check_mov(const unsigned char *buffer, const unsigned int buff
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_mov.extension;
file_recovery_new->file_rename=&file_rename_mov;
file_recovery_new->data_check=data_check_mov;
file_recovery_new->data_check=&data_check_mov;
file_recovery_new->file_check=&file_check_size;
file_recovery_new->calculated_file_size=i+atom_size;
return 1;

View file

@ -166,8 +166,10 @@ static int header_check_mp3(const unsigned char *buffer, const unsigned int buff
return 0;
if(file_recovery!=NULL && file_recovery->file_stat!=NULL)
{
if(file_recovery->file_stat->file_hint==&file_hint_mp3 ||
file_recovery->file_stat->file_hint==&file_hint_mkv)
if(file_recovery->data_check==&data_check_mp3 &&
file_recovery->calculated_file_size == file_recovery->file_size)
return 0;
if(file_recovery->file_stat->file_hint==&file_hint_mkv)
return 0;
/* RGV values from TIFF may be similar to the beginning of an mp3 */
if(file_recovery->file_stat->file_hint==&file_hint_tiff &&

View file

@ -86,7 +86,7 @@ static int header_check_oci(const unsigned char *buffer, const unsigned int buff
{
reset_file_recovery(file_recovery_new);
file_recovery_new->extension=file_hint_oci.extension;
file_recovery_new->data_check=data_check_oci;
file_recovery_new->data_check=&data_check_oci;
file_recovery_new->file_check=&file_check_size;
return 1;
}

View file

@ -64,7 +64,7 @@ typedef struct {
static void log_riff_list(const uint64_t offset, const unsigned int depth, const riff_list_header *list_header)
{
unsigned int i;
log_info("0x%08lx - 0x%08lx ", offset, offset + 8 + le32(list_header->dwSize) - 1);
log_info("0x%08lx - 0x%08lx ", offset, offset + 8 - 1 + le32(list_header->dwSize));
for(i = 0; i < depth; i++)
log_info(" ");
log_info("%c%c%c%c %c%c%c%c 0x%x\n",
@ -84,7 +84,7 @@ static void log_riff_chunk(const uint64_t offset, const unsigned int depth, cons
unsigned int i;
if(le32(list_header->dwSize)==0)
return ;
log_info("0x%08lx - 0x%08lx ", offset, offset + 8 + le32(list_header->dwSize) - 1);
log_info("0x%08lx - 0x%08lx ", offset, offset + 8 - 1 + le32(list_header->dwSize));
for(i = 0; i < depth; i++)
log_info(" ");
log_info("%c%c%c%c 0x%x\n",
@ -119,7 +119,7 @@ static void check_riff_list(file_recovery_t *fr, const unsigned int depth, const
#ifdef DEBUG_RIFF
log_riff_list(file_size, depth, &list_header);
#endif
check_riff_list(fr, depth+1, file_size + sizeof(list_header), file_size + 8 + le32(list_header.dwSize) - 1);
check_riff_list(fr, depth+1, file_size + sizeof(list_header), file_size + 8 - 1 + le32(list_header.dwSize));
}
else
{
@ -161,7 +161,7 @@ static void file_check_avi(file_recovery_t *fr)
fr->offset_error=fr->file_size;
return;
}
check_riff_list(fr, 1, file_size + sizeof(list_header), file_size + 8 + le32(list_header.dwSize) - 1);
check_riff_list(fr, 1, file_size + sizeof(list_header), file_size + 8 - 1 + le32(list_header.dwSize));
if(fr->offset_error > 0)
{
fr->file_size=0;

View file

@ -121,7 +121,7 @@ static int header_check_tib(const unsigned char *buffer, const unsigned int buff
{
reset_file_recovery(file_recovery_new);
file_recovery_new->file_check=&file_check_tib;
file_recovery_new->data_check=data_check_tib2;
file_recovery_new->data_check=&data_check_tib2;
file_recovery_new->extension=file_hint_tib.extension;
return 1;
}