avmpack.c
Include dependency graph for avmpack.c:
Defines
-
AVMPACK_SIZE 24
-
AVMPACK_SECTION_HEADER_SIZE 12
-
AVMPACK_MIN_SECTION_SIZE 16
-
AVMPACK_END_MARKER_SIZE 16
Enums
Functions
-
static inline size_t pad(size_t size)
-
bool avmpack_is_valid(const void *avmpack_binary, uint32_t size)
Returns
trueif the pointed binary starts with a valid AVM Pack header.Checks the 24-byte magic header only; see
avmpack_is_completeandavmpack_compute_sizefor truncation.- Parameters:
avmpack_binary – a pointer to an AVM Pack binary.
size – the size of AVM Pack binary.
- Returns:
trueif it is a valid AVM Pack binary,falseotherwise.
-
static bool is_end_marker_name(const char *name)
-
static enum AVMPackSectionKind read_section(const void *avmpack_binary, uint32_t avmpack_size, uint32_t offset, struct AVMPackSection *section)
-
int avmpack_find_section_by_flag(const void *avmpack_binary, uint32_t avmpack_size, uint32_t flags_mask, uint32_t flags_value, const void **ptr, uint32_t *size, const char **name)
Finds an AVM Pack section that has certain flags set.
Finds an AVM Pack section that has certain flags set and returns a pointer to it, its size and its name. The scan is bounded by
avmpack_size.- Parameters:
avmpack_binary – a pointer to valid AVM Pack file data.
avmpack_size – the size in bytes of the AVM Pack.
flags_mask – that will be matched against file sections.
flags_value – that will be matched against file sections.
ptr – [out] will point to the found file section.
size – [out] the payload size at
ptr, without the section header and the padded name; not updated if the section has not been found.name – [out] the section name, as defined in the module header.
- Returns:
1 if the file section has been found, 0 otherwise.
-
int avmpack_find_section_by_name(const void *avmpack_binary, uint32_t avmpack_size, const char *name, const void **ptr, uint32_t *size)
Finds an AVM Pack section that has certain name.
Finds an AVM Pack section with a certain name and returns a pointer to it and its size. The scan is bounded by
avmpack_size.- Parameters:
avmpack_binary – a pointer to valid AVM Pack file data.
avmpack_size – the size in bytes of the AVM Pack.
name – the file section name that will be searched.
ptr – [out] will point to the found file section; not updated if the section has not been found.
size – [out] the payload size at
ptr, without the section header and the padded name; not updated if the section has not been found.
- Returns:
1 if the file section has been found, 0 otherwise.
-
void *avmpack_fold(void *accum, const void *avmpack_binary, uint32_t avmpack_size, avmpack_fold_fun fold_fun)
Fold over all the sections in an AVM Pack.
This function will call the callback on each section of the AVM Pack, passing in the current section of each module in the AVM binary to the supplied fold function. The scan is bounded by
avmpack_sizeand stops on the terminator or on the first invalid section header.- Parameters:
accum – The accumulator supplied by the application.
avmpack_binary – a pointer to an AVM Pack binary.
avmpack_size – the size in bytes of the AVM Pack.
fold_fun – function that will be called for each AVM section.
-
bool avmpack_is_complete(const void *avmpack_binary, size_t exact_size)
Returns
trueif an AVM Pack of exactly known size ends with itsendterminator.Reads the header and the last 16 bytes only, so a memory-mapped pack stays lazily paged. Trailing bytes after the terminator and sizes above
UINT32_MAXare rejected.- Parameters:
avmpack_binary – a pointer to an AVM Pack binary.
exact_size – the exact size in bytes of the AVM Pack.
- Returns:
trueif the pack is complete,falseotherwise.
-
bool avmpack_compute_size(const void *avmpack_binary, uint32_t max_size, uint32_t *real_size)
Finds the end of an AVM Pack within a region and returns its real size.
Walks the section chain, validating every header, until the
endterminator ormax_sizeis reached.- Parameters:
avmpack_binary – a pointer to an AVM Pack binary.
max_size – the size in bytes of the region containing the AVM Pack.
real_size – [out] set to the size in bytes of the AVM Pack on success.
- Returns:
trueif the terminator was found withinmax_size,falseotherwise.
-
static void in_memory_avm_pack_destructor(struct AVMPackData *obj, GlobalContext *global)
-
static void const_avm_pack_destructor(struct AVMPackData *obj, GlobalContext *global)
Variables
-
const struct AVMPackInfo in_memory_avm_pack_info = {.destructor = in_memory_avm_pack_destructor}
-
const struct AVMPackInfo const_avm_pack_info = {.destructor = const_avm_pack_destructor}
-
struct AVMPackSection