src/file_chm.c: code cleanup

This commit is contained in:
Christophe Grenier 2013-12-08 14:43:05 +01:00
parent ccc47d5bf2
commit 12682f82d0

View file

@ -31,7 +31,6 @@
#include "filegen.h" #include "filegen.h"
static void register_header_check_chm(file_stat_t *file_stat); static void register_header_check_chm(file_stat_t *file_stat);
static int header_check_chm(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);
const file_hint_t file_hint_chm= { const file_hint_t file_hint_chm= {
.extension="chm", .extension="chm",
@ -43,24 +42,19 @@ const file_hint_t file_hint_chm= {
.register_header_check=&register_header_check_chm .register_header_check=&register_header_check_chm
}; };
static const unsigned char chm_header[16]={ 'I', 'T', 'S', 'F', 0x03, 0x00, 0x00, 0x00, static int header_check_chm(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)
0x60, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}; {
reset_file_recovery(file_recovery_new);
file_recovery_new->calculated_file_size=(buffer[104]<<0)+(buffer[105]<<8)+(buffer[106]<<16)+((uint64_t)buffer[107]<<24);
file_recovery_new->data_check=&data_check_size;
file_recovery_new->file_check=&file_check_size;
file_recovery_new->extension=file_hint_chm.extension;
return 1;
}
static void register_header_check_chm(file_stat_t *file_stat) static void register_header_check_chm(file_stat_t *file_stat)
{ {
static const unsigned char chm_header[16]={ 'I', 'T', 'S', 'F', 0x03, 0x00, 0x00, 0x00,
0x60, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};
register_header_check(0, chm_header,sizeof(chm_header), &header_check_chm, file_stat); register_header_check(0, chm_header,sizeof(chm_header), &header_check_chm, file_stat);
} }
static int header_check_chm(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(memcmp(buffer, chm_header, sizeof(chm_header))==0)
{
reset_file_recovery(file_recovery_new);
file_recovery_new->calculated_file_size=(buffer[104]<<0)+(buffer[105]<<8)+(buffer[106]<<16)+(buffer[107]<<24);
file_recovery_new->data_check=&data_check_size;
file_recovery_new->file_check=&file_check_size;
file_recovery_new->extension=file_hint_chm.extension;
return 1;
}
return 0;
}