From 62be5e5ed16461d58f9d8dc3d8ac07743a44e1dd Mon Sep 17 00:00:00 2001 From: Christophe Grenier Date: Mon, 15 Mar 2021 19:08:34 +0100 Subject: [PATCH] src/file_z2d.c: add Frama-C annotations --- src/file_z2d.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/src/file_z2d.c b/src/file_z2d.c index 5d5557f7..1f6b6c96 100644 --- a/src/file_z2d.c +++ b/src/file_z2d.c @@ -31,29 +31,34 @@ #include "types.h" #include "filegen.h" +/*@ requires \valid(file_stat); */ static void register_header_check_z2d(file_stat_t *file_stat); -const file_hint_t file_hint_z2d= { - .extension="z2d", - .description="ZeroCad", - .max_filesize=PHOTOREC_MAX_FILE_SIZE, - .recover=1, - .enable_by_default=1, - .register_header_check=®ister_header_check_z2d +const file_hint_t file_hint_z2d = { + .extension = "z2d", + .description = "ZeroCad", + .max_filesize = PHOTOREC_MAX_FILE_SIZE, + .recover = 1, + .enable_by_default = 1, + .register_header_check = ®ister_header_check_z2d }; -static const unsigned char z2d_header[2]= { 0xc3, 0x40 }; - +/*@ + @ requires buffer_size >= 0x4a; + @ requires \valid_read(buffer+(0..buffer_size-1)); + @ requires valid_file_recovery(file_recovery); + @ requires \valid(file_recovery_new); + @ requires file_recovery_new->blocksize > 0; + @ requires separation: \separated(&file_hint_z2d, buffer+(..), file_recovery, file_recovery_new); + @ ensures \result!=0 ==> valid_file_recovery(file_recovery_new); + @ assigns *file_recovery_new; + @*/ static int header_check_z2d(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(buffer[0x28]==0xc3 && buffer[0x29]==0x40 && - buffer[0x30]==0xc3 && buffer[0x31]==0x40 && - buffer[0x38]==0xbf && buffer[0x39]==0x40 && - buffer[0x40]==0xbf && buffer[0x41]==0x40 && - buffer[0x48]==0xb7 && buffer[0x49]==0x40) + if(buffer[0x28] == 0xc3 && buffer[0x29] == 0x40 && buffer[0x30] == 0xc3 && buffer[0x31] == 0x40 && buffer[0x38] == 0xbf && buffer[0x39] == 0x40 && buffer[0x40] == 0xbf && buffer[0x41] == 0x40 && buffer[0x48] == 0xb7 && buffer[0x49] == 0x40) { reset_file_recovery(file_recovery_new); - file_recovery_new->extension=file_hint_z2d.extension; + file_recovery_new->extension = file_hint_z2d.extension; return 1; } return 0; @@ -61,6 +66,7 @@ static int header_check_z2d(const unsigned char *buffer, const unsigned int buff static void register_header_check_z2d(file_stat_t *file_stat) { + static const unsigned char z2d_header[2] = { 0xc3, 0x40 }; register_header_check(0x28, z2d_header, sizeof(z2d_header), &header_check_z2d, file_stat); } #endif