src/file_class.c: add frama-c annotations
This commit is contained in:
parent
f2515294ab
commit
1ef4dc4b3e
1 changed files with 19 additions and 9 deletions
|
@ -32,8 +32,8 @@
|
|||
#include "common.h"
|
||||
#include "filegen.h"
|
||||
|
||||
/*@ requires \valid(file_stat); */
|
||||
static void register_header_check_class(file_stat_t *file_stat);
|
||||
static int header_check_class(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_class= {
|
||||
.extension="class",
|
||||
|
@ -44,9 +44,6 @@ const file_hint_t file_hint_class= {
|
|||
.register_header_check=®ister_header_check_class
|
||||
};
|
||||
|
||||
/* http://en.wikipedia.org/wiki/Class_(file_format) */
|
||||
static const unsigned char class_magic[4]= { 0xCA, 0xFE, 0xBA, 0xBE };
|
||||
|
||||
struct class_header {
|
||||
uint32_t magic_number;
|
||||
uint16_t minor_version;
|
||||
|
@ -54,11 +51,17 @@ struct class_header {
|
|||
uint16_t constant_pool_count;
|
||||
};
|
||||
|
||||
static void register_header_check_class(file_stat_t *file_stat)
|
||||
{
|
||||
register_header_check(0, class_magic, sizeof(class_magic), &header_check_class, file_stat);
|
||||
}
|
||||
|
||||
/*@
|
||||
@ requires buffer_size >= sizeof(struct class_header);
|
||||
@ 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_class, buffer+(..), file_recovery, file_recovery_new);
|
||||
@ assigns *file_recovery_new;
|
||||
@ ensures \result == 0 || \result == 1;
|
||||
@ ensures \result!=0 ==> valid_file_recovery(file_recovery_new);
|
||||
@*/
|
||||
static int header_check_class(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 struct class_header *cafe=(const struct class_header *)buffer;
|
||||
|
@ -72,4 +75,11 @@ static int header_check_class(const unsigned char *buffer, const unsigned int bu
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void register_header_check_class(file_stat_t *file_stat)
|
||||
{
|
||||
/* https://en.wikipedia.org/wiki/Class_(file_format) */
|
||||
static const unsigned char class_magic[4]= { 0xCA, 0xFE, 0xBA, 0xBE };
|
||||
register_header_check(0, class_magic, sizeof(class_magic), &header_check_class, file_stat);
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue