summaryrefslogtreecommitdiffstats
path: root/src/file_mpg.c
diff options
context:
space:
mode:
authorChristophe Grenier <grenier@cgsecurity.org>2016-09-23 14:00:17 +0200
committerChristophe Grenier <grenier@cgsecurity.org>2016-09-23 14:00:17 +0200
commit4dab23d10572db08a5099bd2043eb35a4e518a9b (patch)
treea75ad9e35a6bc2c877447c2bdecaf1c09783b3bf /src/file_mpg.c
parent29cd490a9fb078fa972b73d7bded19ceccd4093f (diff)
src/file_mpg.c: factor code by using a new function header_mpg_found()
Diffstat (limited to 'src/file_mpg.c')
-rw-r--r--src/file_mpg.c62
1 files changed, 18 insertions, 44 deletions
diff --git a/src/file_mpg.c b/src/file_mpg.c
index 9a09c9f..c0ca71b 100644
--- a/src/file_mpg.c
+++ b/src/file_mpg.c
@@ -133,7 +133,6 @@ static int calculate_packet_size(const unsigned char *buffer)
}
}
-
static data_check_t data_check_mpg(const unsigned char *buffer, const unsigned int buffer_size, file_recovery_t *file_recovery)
{
while(file_recovery->calculated_file_size + buffer_size/2 >= file_recovery->file_size &&
@@ -151,6 +150,17 @@ static data_check_t data_check_mpg(const unsigned char *buffer, const unsigned i
return DC_CONTINUE;
}
+static int header_mpg_found(file_recovery_t *file_recovery_new)
+{
+ reset_file_recovery(file_recovery_new);
+ file_recovery_new->extension=file_hint_mpg.extension;
+ if(file_recovery_new->blocksize < 14)
+ return 1;
+ file_recovery_new->data_check=&data_check_mpg;
+ file_recovery_new->file_check=&file_check_size;
+ return 1;
+}
+
static int header_check_mpg_Pack(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)
{
unsigned int i=0;
@@ -168,26 +178,14 @@ static int header_check_mpg_Pack(const unsigned char *buffer, const unsigned int
{
if(buffer[5]==0 && buffer[6]==1 && buffer[7]==0 && buffer[8]==1)
{
- reset_file_recovery(file_recovery_new);
- file_recovery_new->extension=file_hint_mpg.extension;
- if(file_recovery_new->blocksize < 14)
- return 1;
- file_recovery_new->data_check=&data_check_mpg;
- file_recovery_new->file_check=&file_check_size;
- return 1;
+ return header_mpg_found(file_recovery_new);
}
if(file_recovery->file_stat!=NULL && file_recovery->file_stat->file_hint==&file_hint_mpg)
{
header_ignored(file_recovery_new);
return 0;
}
- reset_file_recovery(file_recovery_new);
- file_recovery_new->extension=file_hint_mpg.extension;
- if(file_recovery_new->blocksize < 14)
- return 1;
- file_recovery_new->data_check=&data_check_mpg;
- file_recovery_new->file_check=&file_check_size;
- return 1;
+ return header_mpg_found(file_recovery_new);
}
/* MPEG-2 Program stream http://neuron2.net/library/mpeg2/iso13818-1.pdf */
/* MPEG2 system header start code, several per file */
@@ -214,26 +212,14 @@ static int header_check_mpg_Pack(const unsigned char *buffer, const unsigned int
if(buffer[4]==0x44 && buffer[5]==0 && buffer[6]==4 && buffer[7]==0 && (buffer[8]&0xfc)==4)
{ /* SCR=0 */
- reset_file_recovery(file_recovery_new);
- file_recovery_new->extension=file_hint_mpg.extension;
- if(file_recovery_new->blocksize < 14)
- return 1;
- file_recovery_new->data_check=&data_check_mpg;
- file_recovery_new->file_check=&file_check_size;
- return 1;
+ return header_mpg_found(file_recovery_new);
}
if(file_recovery->file_stat!=NULL && file_recovery->file_stat->file_hint==&file_hint_mpg)
{
header_ignored(file_recovery_new);
return 0;
}
- reset_file_recovery(file_recovery_new);
- file_recovery_new->extension=file_hint_mpg.extension;
- if(file_recovery_new->blocksize < 14)
- return 1;
- file_recovery_new->data_check=&data_check_mpg;
- file_recovery_new->file_check=&file_check_size;
- return 1;
+ return header_mpg_found(file_recovery_new);
}
return 0;
}
@@ -274,11 +260,7 @@ static int header_check_mpg_System(const unsigned char *buffer, const unsigned i
header_ignored(file_recovery_new);
return 0;
}
- reset_file_recovery(file_recovery_new);
- file_recovery_new->extension=file_hint_mpg.extension;
- file_recovery_new->data_check=&data_check_mpg;
- file_recovery_new->file_check=&file_check_size;
- return 1;
+ return header_mpg_found(file_recovery_new);
}
return 0;
}
@@ -312,11 +294,7 @@ static int header_check_mpg_Sequence(const unsigned char *buffer, const unsigned
header_ignored(file_recovery_new);
return 0;
}
- reset_file_recovery(file_recovery_new);
- file_recovery_new->extension=file_hint_mpg.extension;
- file_recovery_new->data_check=&data_check_mpg;
- file_recovery_new->file_check=&file_check_size;
- return 1;
+ return header_mpg_found(file_recovery_new);
}
return 0;
}
@@ -347,11 +325,7 @@ static int header_check_mpg4_ElemVideo(const unsigned char *buffer, const unsign
header_ignored(file_recovery_new);
return 0;
}
- reset_file_recovery(file_recovery_new);
- file_recovery_new->extension=file_hint_mpg.extension;
- file_recovery_new->data_check=&data_check_mpg;
- file_recovery_new->file_check=&file_check_size;
- return 1;
+ return header_mpg_found(file_recovery_new);
}
return 0;
}