SquashFS compressed filesystem reader in pure OCaml
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

regenerate EverParse C files with wire 0.9.0

Wire_3d now generates ExternalTypedefs.h, ExternalAPI.h, Wrapper,
and Fields files for schemas using WireCtx. Bitfield padding is
fixed so .3d structs match the OCaml codec wire_size. Test.c passes
NULL for the WIRECTX parameter and links per-schema Field stubs.

Affected: ax25, cfdp, fsr, ltp, mbr, pid1, pus, rpmsg, sdls,
spacefibre, squashfs, tcpcl, udpcl, spacewire, and others via @gen.

+3601 -50
+243
c/EverParse.h
··· 1 + /*++ 2 + 3 + Copyright (c) Microsoft Corporation 4 + 5 + Module Name: 6 + 7 + EverParse.h 8 + 9 + Abstract: 10 + 11 + This is an EverParse-generated file that contains common auxiliary 12 + functions for EverParse-generated verified data validators. 13 + 14 + This file was generated by EverParse v2026.02.25 15 + 16 + Authors: 17 + 18 + nswamy, protz, taramana 5-Feb-2020 19 + 20 + --*/ 21 + 22 + 23 + #ifndef EverParse_H 24 + #define EverParse_H 25 + 26 + #if defined(__cplusplus) 27 + extern "C" { 28 + #endif 29 + 30 + #include "EverParseEndianness.h" 31 + 32 + static inline uint8_t EverParseGetBitfield8(uint8_t Value, uint32_t BitsFrom, uint32_t BitsTo) 33 + { 34 + uint8_t op1 = (uint32_t)Value << (8U - BitsTo); 35 + return (uint32_t)op1 >> (8U - BitsTo + BitsFrom); 36 + } 37 + 38 + static inline uint16_t 39 + EverParseGetBitfield16(uint16_t Value, uint32_t BitsFrom, uint32_t BitsTo) 40 + { 41 + uint16_t bf = (uint32_t)Value << (16U - BitsTo); 42 + return (uint32_t)bf >> (16U - BitsTo + BitsFrom); 43 + } 44 + 45 + static inline uint32_t 46 + EverParseGetBitfield32(uint32_t Value, uint32_t BitsFrom, uint32_t BitsTo) 47 + { 48 + return Value << (32U - BitsTo) >> (32U - BitsTo + BitsFrom); 49 + } 50 + 51 + static inline uint64_t 52 + EverParseGetBitfield64(uint64_t Value, uint32_t BitsFrom, uint32_t BitsTo) 53 + { 54 + return Value << (64U - BitsTo) >> (64U - BitsTo + BitsFrom); 55 + } 56 + 57 + static inline uint8_t 58 + EverParseGetBitfield8MsbFirst(uint8_t Value, uint32_t BitsFrom, uint32_t BitsTo) 59 + { 60 + return EverParseGetBitfield8(Value, 8U - BitsTo, 8U - BitsFrom); 61 + } 62 + 63 + static inline uint16_t 64 + EverParseGetBitfield16MsbFirst(uint16_t Value, uint32_t BitsFrom, uint32_t BitsTo) 65 + { 66 + return EverParseGetBitfield16(Value, 16U - BitsTo, 16U - BitsFrom); 67 + } 68 + 69 + static inline uint32_t 70 + EverParseGetBitfield32MsbFirst(uint32_t Value, uint32_t BitsFrom, uint32_t BitsTo) 71 + { 72 + return EverParseGetBitfield32(Value, 32U - BitsTo, 32U - BitsFrom); 73 + } 74 + 75 + static inline uint64_t 76 + EverParseGetBitfield64MsbFirst(uint64_t Value, uint32_t BitsFrom, uint32_t BitsTo) 77 + { 78 + return EverParseGetBitfield64(Value, 64U - BitsTo, 64U - BitsFrom); 79 + } 80 + 81 + #define EVERPARSE_VALIDATOR_MAX_LENGTH (1152921504606846975ULL) 82 + 83 + static inline BOOLEAN EverParseIsError(uint64_t PositionOrError) 84 + { 85 + return PositionOrError > EVERPARSE_VALIDATOR_MAX_LENGTH; 86 + } 87 + 88 + static inline BOOLEAN EverParseIsSuccess(uint64_t PositionOrError) 89 + { 90 + return PositionOrError <= EVERPARSE_VALIDATOR_MAX_LENGTH; 91 + } 92 + 93 + static inline uint64_t EverParseSetValidatorErrorPos(uint64_t Error, uint64_t Position) 94 + { 95 + return (Error & 17293822569102704640ULL) | Position << 0U; 96 + } 97 + 98 + static inline uint64_t EverParseGetValidatorErrorPos(uint64_t X) 99 + { 100 + return (X & 1152921504606846975ULL) >> 0U; 101 + } 102 + 103 + static inline uint64_t EverParseSetValidatorErrorKind(uint64_t Error, uint64_t Code) 104 + { 105 + return (Error & 1152921504606846975ULL) | Code << 60U; 106 + } 107 + 108 + static inline uint64_t EverParseGetValidatorErrorKind(uint64_t Error) 109 + { 110 + return (Error & 17293822569102704640ULL) >> 60U; 111 + } 112 + 113 + #define EVERPARSE_VALIDATOR_ERROR_GENERIC (1152921504606846976ULL) 114 + 115 + #define EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA (2305843009213693952ULL) 116 + 117 + #define EVERPARSE_VALIDATOR_ERROR_IMPOSSIBLE (3458764513820540928ULL) 118 + 119 + #define EVERPARSE_VALIDATOR_ERROR_LIST_SIZE_NOT_MULTIPLE (4611686018427387904ULL) 120 + 121 + #define EVERPARSE_VALIDATOR_ERROR_ACTION_FAILED (5764607523034234880ULL) 122 + 123 + #define EVERPARSE_VALIDATOR_ERROR_CONSTRAINT_FAILED (6917529027641081856ULL) 124 + 125 + #define EVERPARSE_VALIDATOR_ERROR_UNEXPECTED_PADDING (8070450532247928832ULL) 126 + 127 + #define EVERPARSE_VALIDATOR_ERROR_PROBE_FAILED (9223372036854775808ULL) 128 + 129 + static inline PRIMS_STRING EverParseErrorReasonOfResult(uint64_t Code) 130 + { 131 + switch (EverParseGetValidatorErrorKind(Code)) 132 + { 133 + case 1ULL: 134 + { 135 + return "generic error"; 136 + } 137 + case 2ULL: 138 + { 139 + return "not enough data"; 140 + } 141 + case 3ULL: 142 + { 143 + return "impossible"; 144 + } 145 + case 4ULL: 146 + { 147 + return "list size not multiple of element size"; 148 + } 149 + case 5ULL: 150 + { 151 + return "action failed"; 152 + } 153 + case 6ULL: 154 + { 155 + return "constraint failed"; 156 + } 157 + case 7ULL: 158 + { 159 + return "unexpected padding"; 160 + } 161 + case 8ULL: 162 + { 163 + return "probe failed"; 164 + } 165 + default: 166 + { 167 + return "unspecified"; 168 + } 169 + } 170 + } 171 + 172 + static inline uint64_t EverParseCheckConstraintOk(BOOLEAN Ok, uint64_t Position) 173 + { 174 + if (Ok) 175 + { 176 + return Position; 177 + } 178 + return EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_CONSTRAINT_FAILED, Position); 179 + } 180 + 181 + static inline BOOLEAN EverParseIsRangeOkay(uint32_t Size, uint32_t Offset, uint32_t AccessSize) 182 + { 183 + return Size >= AccessSize && (Size - AccessSize) >= Offset; 184 + } 185 + 186 + typedef struct EVERPARSE_ERROR_FRAME_s 187 + { 188 + BOOLEAN filled; 189 + uint64_t start_pos; 190 + PRIMS_STRING typename_s; 191 + PRIMS_STRING fieldname; 192 + PRIMS_STRING reason; 193 + uint64_t error_code; 194 + } 195 + EVERPARSE_ERROR_FRAME; 196 + 197 + typedef uint8_t *EVERPARSE_INPUT_BUFFER; 198 + 199 + typedef void *EVERPARSE__LIVE; 200 + 201 + static inline void 202 + EverParseDefaultErrorHandler( 203 + PRIMS_STRING TypenameS, 204 + PRIMS_STRING Fieldname, 205 + PRIMS_STRING Reason, 206 + uint64_t ErrorCode, 207 + EVERPARSE_ERROR_FRAME *Context, 208 + uint8_t *Input, 209 + uint64_t StartPos 210 + ) 211 + { 212 + KRML_MAYBE_UNUSED_VAR(Input); 213 + if (!(*Context).filled) 214 + { 215 + *Context = 216 + ( 217 + (EVERPARSE_ERROR_FRAME){ 218 + .filled = TRUE, 219 + .start_pos = StartPos, 220 + .typename_s = TypenameS, 221 + .fieldname = Fieldname, 222 + .reason = Reason, 223 + .error_code = ErrorCode 224 + } 225 + ); 226 + return; 227 + } 228 + } 229 + 230 + extern uint8_t *EverParseStreamOf(EVERPARSE_COPY_BUFFER_T uu___); 231 + 232 + extern uint64_t EverParseStreamLen(EVERPARSE_COPY_BUFFER_T c); 233 + 234 + typedef void *EVERPARSE_INV; 235 + 236 + typedef void *EVERPARSE_LIVENESS_PRESERVED; 237 + 238 + #if defined(__cplusplus) 239 + } 240 + #endif 241 + 242 + #define EverParse_H_DEFINED 243 + #endif /* EverParse_H */
+205
c/EverParseEndianness.h
··· 1 + /*++ 2 + 3 + Copyright (c) Microsoft Corporation 4 + 5 + Module Name: 6 + 7 + EverParseEndianness.h 8 + 9 + Abstract: 10 + 11 + This is an EverParse-related file to read integer values from raw 12 + bytes. 13 + 14 + Authors: 15 + 16 + nswamy, protz, taramana 5-Feb-2020 17 + 18 + --*/ 19 + /* This is a hand-written header that selectively includes relevant bits from 20 + * krmllib.h -- it has to be updated manually to track upstream changes. */ 21 + 22 + #ifndef __EverParseEndianness_H 23 + #define __EverParseEndianness_H 24 + 25 + #if defined(__cplusplus) 26 + extern "C" { 27 + #endif 28 + 29 + /***************************************************************************** 30 + ********* Implementation of LowStar.Endianness (selected bits) ************** 31 + *****************************************************************************/ 32 + 33 + #if defined(_MSC_VER) 34 + # include <windows.h> 35 + #endif 36 + 37 + #include <string.h> 38 + #include <stdint.h> 39 + 40 + typedef const char * EVERPARSE_STRING; 41 + typedef EVERPARSE_STRING PRIMS_STRING; 42 + typedef void* EVERPARSE_COPY_BUFFER_T; 43 + 44 + #ifndef KRML_MAYBE_UNUSED_VAR 45 + # define KRML_MAYBE_UNUSED_VAR(x) (void)(x) 46 + #endif 47 + 48 + #ifndef KRML_HOST_IGNORE 49 + # define KRML_HOST_IGNORE(x) (void)(x) 50 + #endif 51 + 52 + #ifndef KRML_HOST_PRINTF 53 + # include <stdio.h> 54 + # define KRML_HOST_PRINTF printf 55 + #endif 56 + 57 + #ifndef KRML_HOST_EXIT 58 + # include <stdlib.h> 59 + # define KRML_HOST_EXIT exit 60 + #endif 61 + 62 + #define KRML_CHECK_SIZE(size_elt, sz) \ 63 + do { \ 64 + if (((size_t)(sz)) > ((size_t)(SIZE_MAX / (size_elt)))) { \ 65 + KRML_HOST_PRINTF( \ 66 + "Maximum allocatable size exceeded, aborting before overflow at " \ 67 + "%s:%d\n", \ 68 + __FILE__, __LINE__); \ 69 + KRML_HOST_EXIT(253); \ 70 + } \ 71 + } while (0) 72 + 73 + /* ... for Windows (MSVC)... not targeting XBOX 360! */ 74 + #if defined(_MSC_VER) 75 + 76 + # include <stdlib.h> 77 + 78 + # define htobe16(x) _byteswap_ushort(x) 79 + # define htole16(x) (x) 80 + # define be16toh(x) _byteswap_ushort(x) 81 + # define le16toh(x) (x) 82 + 83 + # define htobe32(x) _byteswap_ulong(x) 84 + # define htole32(x) (x) 85 + # define be32toh(x) _byteswap_ulong(x) 86 + # define le32toh(x) (x) 87 + 88 + # define htobe64(x) _byteswap_uint64(x) 89 + # define htole64(x) (x) 90 + # define be64toh(x) _byteswap_uint64(x) 91 + # define le64toh(x) (x) 92 + 93 + #else 94 + 95 + typedef uint8_t BOOLEAN; 96 + #define FALSE 0 97 + #define TRUE 1 98 + 99 + /* ... for Linux */ 100 + #if defined(__linux__) || defined(__CYGWIN__) || defined (__USE_SYSTEM_ENDIAN_H__) 101 + # include <endian.h> 102 + 103 + 104 + /* ... for OSX */ 105 + #elif defined(__APPLE__) 106 + # include <libkern/OSByteOrder.h> 107 + # define htole64(x) OSSwapHostToLittleInt64(x) 108 + # define le64toh(x) OSSwapLittleToHostInt64(x) 109 + # define htobe64(x) OSSwapHostToBigInt64(x) 110 + # define be64toh(x) OSSwapBigToHostInt64(x) 111 + 112 + # define htole16(x) OSSwapHostToLittleInt16(x) 113 + # define le16toh(x) OSSwapLittleToHostInt16(x) 114 + # define htobe16(x) OSSwapHostToBigInt16(x) 115 + # define be16toh(x) OSSwapBigToHostInt16(x) 116 + 117 + # define htole32(x) OSSwapHostToLittleInt32(x) 118 + # define le32toh(x) OSSwapLittleToHostInt32(x) 119 + # define htobe32(x) OSSwapHostToBigInt32(x) 120 + # define be32toh(x) OSSwapBigToHostInt32(x) 121 + 122 + /* ... for other BSDs */ 123 + #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__DragonFly__) 124 + # include <sys/endian.h> 125 + #elif defined(__OpenBSD__) 126 + # include <endian.h> 127 + 128 + /* ... for Windows (GCC-like, e.g. mingw or clang) */ 129 + #elif (defined(_WIN32) || defined(_WIN64)) && \ 130 + (defined(__GNUC__) || defined(__clang__)) 131 + 132 + # define htobe16(x) __builtin_bswap16(x) 133 + # define htole16(x) (x) 134 + # define be16toh(x) __builtin_bswap16(x) 135 + # define le16toh(x) (x) 136 + 137 + # define htobe32(x) __builtin_bswap32(x) 138 + # define htole32(x) (x) 139 + # define be32toh(x) __builtin_bswap32(x) 140 + # define le32toh(x) (x) 141 + 142 + # define htobe64(x) __builtin_bswap64(x) 143 + # define htole64(x) (x) 144 + # define be64toh(x) __builtin_bswap64(x) 145 + # define le64toh(x) (x) 146 + 147 + #else 148 + 149 + #error "Unsupported platform" 150 + 151 + #endif 152 + 153 + #endif 154 + 155 + inline static uint16_t Load16(uint8_t *b) { 156 + uint16_t x; 157 + memcpy(&x, b, 2); 158 + return x; 159 + } 160 + 161 + inline static uint32_t Load32(uint8_t *b) { 162 + uint32_t x; 163 + memcpy(&x, b, 4); 164 + return x; 165 + } 166 + 167 + inline static uint64_t Load64(uint8_t *b) { 168 + uint64_t x; 169 + memcpy(&x, b, 8); 170 + return x; 171 + } 172 + 173 + inline static void Store16(uint8_t *b, uint16_t i) { 174 + memcpy(b, &i, 2); 175 + } 176 + 177 + inline static void Store32(uint8_t *b, uint32_t i) { 178 + memcpy(b, &i, 4); 179 + } 180 + 181 + inline static void Store64(uint8_t *b, uint64_t i) { 182 + memcpy(b, &i, 8); 183 + } 184 + 185 + #define Load16Le(b) (le16toh(Load16(b))) 186 + #define Store16Le(b, i) (Store16(b, htole16(i))) 187 + #define Load16Be(b) (be16toh(Load16(b))) 188 + #define Store16Be(b, i) (Store16(b, htobe16(i))) 189 + 190 + #define Load32Le(b) (le32toh(Load32(b))) 191 + #define Store32Le(b, i) (Store32(b, htole32(i))) 192 + #define Load32Be(b) (be32toh(Load32(b))) 193 + #define Store32Be(b, i) (Store32(b, htobe32(i))) 194 + 195 + #define Load64Le(b) (le64toh(Load64(b))) 196 + #define Store64Le(b, i) (Store64(b, htole64(i))) 197 + #define Load64Be(b) (be64toh(Load64(b))) 198 + #define Store64Be(b, i) (Store64(b, htobe64(i))) 199 + 200 + 201 + #if defined(__cplusplus) 202 + } 203 + #endif 204 + 205 + #endif
+4 -4
c/SquashfsExtDeviceBody.3d
··· 1 1 extern typedef struct _WireCtx WireCtx 2 2 3 - extern unit WireSetU32(mutable WireCtx *ctx, UINT32 idx, UINT32 v) 3 + extern unit SquashfsExtDeviceBodySetU32(mutable WireCtx *ctx, UINT32 idx, UINT32 v) 4 4 5 5 entrypoint 6 6 typedef struct _SquashfsExtDeviceBody(mutable WireCtx *ctx) 7 7 { 8 - UINT32 nlink {:on-success WireSetU32(ctx, (UINT32) 0, nlink); return true; }; 9 - UINT32 rdev {:on-success WireSetU32(ctx, (UINT32) 1, rdev); return true; }; 10 - UINT32 xattr_id {:on-success WireSetU32(ctx, (UINT32) 2, xattr_id); return true; }; 8 + UINT32 nlink {:on-success SquashfsExtDeviceBodySetU32(ctx, (UINT32) 0, nlink); return true; }; 9 + UINT32 rdev {:on-success SquashfsExtDeviceBodySetU32(ctx, (UINT32) 1, rdev); return true; }; 10 + UINT32 xattr_id {:on-success SquashfsExtDeviceBodySetU32(ctx, (UINT32) 2, xattr_id); return true; }; 11 11 } SquashfsExtDeviceBody; 12 12 13 13
+160
c/SquashfsExtDeviceBody.c
··· 1 + 2 + 3 + #include "SquashfsExtDeviceBody.h" 4 + 5 + #include "SquashfsExtDeviceBody_ExternalAPI.h" 6 + 7 + uint64_t 8 + SquashfsExtDeviceBodyValidateSquashfsExtDeviceBody( 9 + WIRECTX *Ctx, 10 + uint8_t *Ctxt, 11 + void 12 + (*ErrorHandlerFn)( 13 + EVERPARSE_STRING x0, 14 + EVERPARSE_STRING x1, 15 + EVERPARSE_STRING x2, 16 + uint64_t x3, 17 + uint8_t *x4, 18 + uint8_t *x5, 19 + uint64_t x6 20 + ), 21 + uint8_t *Input, 22 + uint64_t InputLength, 23 + uint64_t StartPosition 24 + ) 25 + { 26 + /* Validating field nlink */ 27 + /* Checking that we have enough space for a UINT32, i.e., 4 bytes */ 28 + BOOLEAN hasBytes0 = 4ULL <= (InputLength - StartPosition); 29 + uint64_t positionAfternlink0; 30 + if (hasBytes0) 31 + { 32 + positionAfternlink0 = StartPosition + 4ULL; 33 + } 34 + else 35 + { 36 + positionAfternlink0 = 37 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 38 + StartPosition); 39 + } 40 + uint64_t positionAfterSquashfsExtDeviceBody; 41 + if (EverParseIsError(positionAfternlink0)) 42 + { 43 + positionAfterSquashfsExtDeviceBody = positionAfternlink0; 44 + } 45 + else 46 + { 47 + uint32_t nlink = Load32Le(Input + (uint32_t)StartPosition); 48 + SquashfsExtDeviceBodySetU32(Ctx, (uint32_t)0U, nlink); 49 + BOOLEAN actionResult = TRUE; 50 + KRML_MAYBE_UNUSED_VAR(actionResult); 51 + positionAfterSquashfsExtDeviceBody = positionAfternlink0; 52 + } 53 + uint64_t positionAfternlink; 54 + if (EverParseIsSuccess(positionAfterSquashfsExtDeviceBody)) 55 + { 56 + positionAfternlink = positionAfterSquashfsExtDeviceBody; 57 + } 58 + else 59 + { 60 + ErrorHandlerFn("_SquashfsExtDeviceBody", 61 + "nlink", 62 + EverParseErrorReasonOfResult(positionAfterSquashfsExtDeviceBody), 63 + EverParseGetValidatorErrorKind(positionAfterSquashfsExtDeviceBody), 64 + Ctxt, 65 + Input, 66 + StartPosition); 67 + positionAfternlink = positionAfterSquashfsExtDeviceBody; 68 + } 69 + if (EverParseIsError(positionAfternlink)) 70 + { 71 + return positionAfternlink; 72 + } 73 + /* Validating field rdev */ 74 + /* Checking that we have enough space for a UINT32, i.e., 4 bytes */ 75 + BOOLEAN hasBytes1 = 4ULL <= (InputLength - positionAfternlink); 76 + uint64_t positionAfterrdev0; 77 + if (hasBytes1) 78 + { 79 + positionAfterrdev0 = positionAfternlink + 4ULL; 80 + } 81 + else 82 + { 83 + positionAfterrdev0 = 84 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 85 + positionAfternlink); 86 + } 87 + uint64_t positionAfterSquashfsExtDeviceBody0; 88 + if (EverParseIsError(positionAfterrdev0)) 89 + { 90 + positionAfterSquashfsExtDeviceBody0 = positionAfterrdev0; 91 + } 92 + else 93 + { 94 + uint32_t rdev = Load32Le(Input + (uint32_t)positionAfternlink); 95 + SquashfsExtDeviceBodySetU32(Ctx, (uint32_t)1U, rdev); 96 + BOOLEAN actionResult = TRUE; 97 + KRML_MAYBE_UNUSED_VAR(actionResult); 98 + positionAfterSquashfsExtDeviceBody0 = positionAfterrdev0; 99 + } 100 + uint64_t positionAfterrdev; 101 + if (EverParseIsSuccess(positionAfterSquashfsExtDeviceBody0)) 102 + { 103 + positionAfterrdev = positionAfterSquashfsExtDeviceBody0; 104 + } 105 + else 106 + { 107 + ErrorHandlerFn("_SquashfsExtDeviceBody", 108 + "rdev", 109 + EverParseErrorReasonOfResult(positionAfterSquashfsExtDeviceBody0), 110 + EverParseGetValidatorErrorKind(positionAfterSquashfsExtDeviceBody0), 111 + Ctxt, 112 + Input, 113 + positionAfternlink); 114 + positionAfterrdev = positionAfterSquashfsExtDeviceBody0; 115 + } 116 + if (EverParseIsError(positionAfterrdev)) 117 + { 118 + return positionAfterrdev; 119 + } 120 + /* Validating field xattr_id */ 121 + /* Checking that we have enough space for a UINT32, i.e., 4 bytes */ 122 + BOOLEAN hasBytes = 4ULL <= (InputLength - positionAfterrdev); 123 + uint64_t positionAfterxattrId; 124 + if (hasBytes) 125 + { 126 + positionAfterxattrId = positionAfterrdev + 4ULL; 127 + } 128 + else 129 + { 130 + positionAfterxattrId = 131 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 132 + positionAfterrdev); 133 + } 134 + uint64_t positionAfterSquashfsExtDeviceBody1; 135 + if (EverParseIsError(positionAfterxattrId)) 136 + { 137 + positionAfterSquashfsExtDeviceBody1 = positionAfterxattrId; 138 + } 139 + else 140 + { 141 + uint32_t xattrId = Load32Le(Input + (uint32_t)positionAfterrdev); 142 + SquashfsExtDeviceBodySetU32(Ctx, (uint32_t)2U, xattrId); 143 + BOOLEAN actionResult = TRUE; 144 + KRML_MAYBE_UNUSED_VAR(actionResult); 145 + positionAfterSquashfsExtDeviceBody1 = positionAfterxattrId; 146 + } 147 + if (EverParseIsSuccess(positionAfterSquashfsExtDeviceBody1)) 148 + { 149 + return positionAfterSquashfsExtDeviceBody1; 150 + } 151 + ErrorHandlerFn("_SquashfsExtDeviceBody", 152 + "xattr_id", 153 + EverParseErrorReasonOfResult(positionAfterSquashfsExtDeviceBody1), 154 + EverParseGetValidatorErrorKind(positionAfterSquashfsExtDeviceBody1), 155 + Ctxt, 156 + Input, 157 + positionAfterrdev); 158 + return positionAfterSquashfsExtDeviceBody1; 159 + } 160 +
+37
c/SquashfsExtDeviceBody.h
··· 1 + 2 + 3 + #ifndef SquashfsExtDeviceBody_H 4 + #define SquashfsExtDeviceBody_H 5 + 6 + #if defined(__cplusplus) 7 + extern "C" { 8 + #endif 9 + 10 + #include "EverParse.h" 11 + #include "SquashfsExtDeviceBody_ExternalTypedefs.h" 12 + 13 + uint64_t 14 + SquashfsExtDeviceBodyValidateSquashfsExtDeviceBody( 15 + WIRECTX *Ctx, 16 + uint8_t *Ctxt, 17 + void 18 + (*ErrorHandlerFn)( 19 + EVERPARSE_STRING x0, 20 + EVERPARSE_STRING x1, 21 + EVERPARSE_STRING x2, 22 + uint64_t x3, 23 + uint8_t *x4, 24 + uint8_t *x5, 25 + uint64_t x6 26 + ), 27 + uint8_t *Input, 28 + uint64_t InputLength, 29 + uint64_t StartPosition 30 + ); 31 + 32 + #if defined(__cplusplus) 33 + } 34 + #endif 35 + 36 + #define SquashfsExtDeviceBody_H_DEFINED 37 + #endif /* SquashfsExtDeviceBody_H */
+41
c/SquashfsExtDeviceBodyWrapper.c
··· 1 + #include "SquashfsExtDeviceBodyWrapper.h" 2 + #include "EverParse.h" 3 + #include "SquashfsExtDeviceBody.h" 4 + void SquashfsExtDeviceBodyEverParseError(const char *StructName, const char *FieldName, const char *Reason); 5 + 6 + static 7 + void DefaultErrorHandler( 8 + const char *typename_s, 9 + const char *fieldname, 10 + const char *reason, 11 + uint64_t error_code, 12 + uint8_t *context, 13 + EVERPARSE_INPUT_BUFFER input, 14 + uint64_t start_pos) 15 + { 16 + EVERPARSE_ERROR_FRAME *frame = (EVERPARSE_ERROR_FRAME*)context; 17 + EverParseDefaultErrorHandler( 18 + typename_s, 19 + fieldname, 20 + reason, 21 + error_code, 22 + frame, 23 + input, 24 + start_pos 25 + ); 26 + } 27 + 28 + BOOLEAN SquashfsExtDeviceBodyCheckSquashfsExtDeviceBody(WIRECTX* ctx, uint8_t *base, uint32_t len) { 29 + EVERPARSE_ERROR_FRAME frame; 30 + frame.filled = FALSE; 31 + uint64_t result = SquashfsExtDeviceBodyValidateSquashfsExtDeviceBody(ctx, (uint8_t*)&frame, &DefaultErrorHandler, base, len, 0); 32 + if (EverParseIsError(result)) 33 + { 34 + if (frame.filled) 35 + { 36 + SquashfsExtDeviceBodyEverParseError(frame.typename_s, frame.fieldname, frame.reason); 37 + } 38 + return FALSE; 39 + } 40 + return TRUE; 41 + }
+26
c/SquashfsExtDeviceBodyWrapper.h
··· 1 + #include "EverParseEndianness.h" 2 + #define EVERPARSE_SUCCESS 0ul 3 + #define EVERPARSE_ERROR_GENERIC 1uL 4 + #define EVERPARSE_ERROR_NOT_ENOUGH_DATA 2uL 5 + #define EVERPARSE_ERROR_IMPOSSIBLE 3uL 6 + #define EVERPARSE_ERROR_LIST_SIZE_NOT_MULTIPLE 4uL 7 + #define EVERPARSE_ERROR_ACTION_FAILED 5uL 8 + #define EVERPARSE_ERROR_CONSTRAINT_FAILED 6uL 9 + #define EVERPARSE_ERROR_UNEXPECTED_PADDING 7uL 10 + // Probe wrapper error codes 11 + #define EVERPARSE_PROBE_FAILURE_INCORRECT_SIZE 256uL 12 + #define EVERPARSE_PROBE_FAILURE_INIT 257uL 13 + #define EVERPARSE_PROBE_FAILURE_PROBE 258uL 14 + #define EVERPARSE_PROBE_FAILURE_VALIDATION 259uL 15 + 16 + 17 + #include "SquashfsExtDeviceBody_ExternalTypedefs.h" 18 + 19 + 20 + #ifdef __cplusplus 21 + extern "C" { 22 + #endif 23 + BOOLEAN SquashfsExtDeviceBodyCheckSquashfsExtDeviceBody(WIRECTX* ctx, uint8_t *base, uint32_t len); 24 + #ifdef __cplusplus 25 + } 26 + #endif
+20
c/SquashfsExtDeviceBody_ExternalAPI.h
··· 1 + 2 + 3 + #ifndef SquashfsExtDeviceBody_ExternalAPI_H 4 + #define SquashfsExtDeviceBody_ExternalAPI_H 5 + 6 + #if defined(__cplusplus) 7 + extern "C" { 8 + #endif 9 + 10 + #include "EverParse.h" 11 + #include "SquashfsExtDeviceBody_ExternalTypedefs.h" 12 + 13 + extern void SquashfsExtDeviceBodySetU32(WIRECTX *ctx, uint32_t idx, uint32_t v); 14 + 15 + #if defined(__cplusplus) 16 + } 17 + #endif 18 + 19 + #define SquashfsExtDeviceBody_ExternalAPI_H_DEFINED 20 + #endif /* SquashfsExtDeviceBody_ExternalAPI_H */
+4
c/SquashfsExtDeviceBody_ExternalTypedefs.h
··· 1 + #ifndef WIRECTX_DEFINED 2 + #define WIRECTX_DEFINED 3 + typedef struct SquashfsExtDeviceBodyFields WIRECTX; 4 + #endif
+15
c/SquashfsExtDeviceBody_Fields.c
··· 1 + #include <stdint.h> 2 + #include "SquashfsExtDeviceBody_Fields.h" 3 + #include "SquashfsExtDeviceBody_ExternalTypedefs.h" 4 + #include "SquashfsExtDeviceBody_ExternalAPI.h" 5 + 6 + void SquashfsExtDeviceBodySetU32(WIRECTX *ctx, uint32_t idx, uint32_t v) { 7 + SquashfsExtDeviceBodyFields *f = (SquashfsExtDeviceBodyFields *) ctx; 8 + switch (idx) { 9 + case 0: f->nlink = (uint32_t) v; break; 10 + case 1: f->rdev = (uint32_t) v; break; 11 + case 2: f->xattr_id = (uint32_t) v; break; 12 + default: (void) f; (void) v; break; 13 + } 14 + } 15 +
+18
c/SquashfsExtDeviceBody_Fields.h
··· 1 + #ifndef SQUASHFSEXTDEVICEBODY_FIELDS_H 2 + #define SQUASHFSEXTDEVICEBODY_FIELDS_H 3 + #include <stdint.h> 4 + 5 + /* Field indices -- use with the schema's WireSet* callbacks in a 6 + custom [WIRECTX] if you only want to capture a subset. */ 7 + #define SQUASHFSEXTDEVICEBODY_IDX_NLINK 0 8 + #define SQUASHFSEXTDEVICEBODY_IDX_RDEV 1 9 + #define SQUASHFSEXTDEVICEBODY_IDX_XATTR_ID 2 10 + 11 + /* Default plug: one typed member per named field. Pass a pointer to 12 + [SquashfsExtDeviceBodyFields] as [WIRECTX *] when you want every field populated. */ 13 + typedef struct SquashfsExtDeviceBodyFields { 14 + uint32_t nlink; 15 + uint32_t rdev; 16 + uint32_t xattr_id; 17 + } SquashfsExtDeviceBodyFields; 18 + #endif
+9 -9
c/SquashfsExtDirBody.3d
··· 1 1 extern typedef struct _WireCtx WireCtx 2 2 3 - extern unit WireSetU32(mutable WireCtx *ctx, UINT32 idx, UINT32 v) 3 + extern unit SquashfsExtDirBodySetU32(mutable WireCtx *ctx, UINT32 idx, UINT32 v) 4 4 5 - extern unit WireSetU16(mutable WireCtx *ctx, UINT32 idx, UINT16 v) 5 + extern unit SquashfsExtDirBodySetU16(mutable WireCtx *ctx, UINT32 idx, UINT16 v) 6 6 7 7 entrypoint 8 8 typedef struct _SquashfsExtDirBody(mutable WireCtx *ctx) 9 9 { 10 - UINT32 nlink {:on-success WireSetU32(ctx, (UINT32) 0, nlink); return true; }; 11 - UINT32 file_size {:on-success WireSetU32(ctx, (UINT32) 1, file_size); return true; }; 12 - UINT32 start_block {:on-success WireSetU32(ctx, (UINT32) 2, start_block); return true; }; 13 - UINT32 parent_inode {:on-success WireSetU32(ctx, (UINT32) 3, parent_inode); return true; }; 14 - UINT16 inodex_count {:on-success WireSetU16(ctx, (UINT32) 4, inodex_count); return true; }; 15 - UINT16 offset {:on-success WireSetU16(ctx, (UINT32) 5, offset); return true; }; 16 - UINT32 xattr_id {:on-success WireSetU32(ctx, (UINT32) 6, xattr_id); return true; }; 10 + UINT32 nlink {:on-success SquashfsExtDirBodySetU32(ctx, (UINT32) 0, nlink); return true; }; 11 + UINT32 file_size {:on-success SquashfsExtDirBodySetU32(ctx, (UINT32) 1, file_size); return true; }; 12 + UINT32 start_block {:on-success SquashfsExtDirBodySetU32(ctx, (UINT32) 2, start_block); return true; }; 13 + UINT32 parent_inode {:on-success SquashfsExtDirBodySetU32(ctx, (UINT32) 3, parent_inode); return true; }; 14 + UINT16 inodex_count {:on-success SquashfsExtDirBodySetU16(ctx, (UINT32) 4, inodex_count); return true; }; 15 + UINT16 offset {:on-success SquashfsExtDirBodySetU16(ctx, (UINT32) 5, offset); return true; }; 16 + UINT32 xattr_id {:on-success SquashfsExtDirBodySetU32(ctx, (UINT32) 6, xattr_id); return true; }; 17 17 } SquashfsExtDirBody; 18 18 19 19
+350
c/SquashfsExtDirBody.c
··· 1 + 2 + 3 + #include "SquashfsExtDirBody.h" 4 + 5 + #include "SquashfsExtDirBody_ExternalAPI.h" 6 + 7 + uint64_t 8 + SquashfsExtDirBodyValidateSquashfsExtDirBody( 9 + WIRECTX *Ctx, 10 + uint8_t *Ctxt, 11 + void 12 + (*ErrorHandlerFn)( 13 + EVERPARSE_STRING x0, 14 + EVERPARSE_STRING x1, 15 + EVERPARSE_STRING x2, 16 + uint64_t x3, 17 + uint8_t *x4, 18 + uint8_t *x5, 19 + uint64_t x6 20 + ), 21 + uint8_t *Input, 22 + uint64_t InputLength, 23 + uint64_t StartPosition 24 + ) 25 + { 26 + /* Validating field nlink */ 27 + /* Checking that we have enough space for a UINT32, i.e., 4 bytes */ 28 + BOOLEAN hasBytes0 = 4ULL <= (InputLength - StartPosition); 29 + uint64_t positionAfternlink0; 30 + if (hasBytes0) 31 + { 32 + positionAfternlink0 = StartPosition + 4ULL; 33 + } 34 + else 35 + { 36 + positionAfternlink0 = 37 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 38 + StartPosition); 39 + } 40 + uint64_t positionAfterSquashfsExtDirBody; 41 + if (EverParseIsError(positionAfternlink0)) 42 + { 43 + positionAfterSquashfsExtDirBody = positionAfternlink0; 44 + } 45 + else 46 + { 47 + uint32_t nlink = Load32Le(Input + (uint32_t)StartPosition); 48 + SquashfsExtDirBodySetU32(Ctx, (uint32_t)0U, nlink); 49 + BOOLEAN actionResult = TRUE; 50 + KRML_MAYBE_UNUSED_VAR(actionResult); 51 + positionAfterSquashfsExtDirBody = positionAfternlink0; 52 + } 53 + uint64_t positionAfternlink; 54 + if (EverParseIsSuccess(positionAfterSquashfsExtDirBody)) 55 + { 56 + positionAfternlink = positionAfterSquashfsExtDirBody; 57 + } 58 + else 59 + { 60 + ErrorHandlerFn("_SquashfsExtDirBody", 61 + "nlink", 62 + EverParseErrorReasonOfResult(positionAfterSquashfsExtDirBody), 63 + EverParseGetValidatorErrorKind(positionAfterSquashfsExtDirBody), 64 + Ctxt, 65 + Input, 66 + StartPosition); 67 + positionAfternlink = positionAfterSquashfsExtDirBody; 68 + } 69 + if (EverParseIsError(positionAfternlink)) 70 + { 71 + return positionAfternlink; 72 + } 73 + /* Validating field file_size */ 74 + /* Checking that we have enough space for a UINT32, i.e., 4 bytes */ 75 + BOOLEAN hasBytes1 = 4ULL <= (InputLength - positionAfternlink); 76 + uint64_t positionAfterfileSize; 77 + if (hasBytes1) 78 + { 79 + positionAfterfileSize = positionAfternlink + 4ULL; 80 + } 81 + else 82 + { 83 + positionAfterfileSize = 84 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 85 + positionAfternlink); 86 + } 87 + uint64_t positionAfterSquashfsExtDirBody0; 88 + if (EverParseIsError(positionAfterfileSize)) 89 + { 90 + positionAfterSquashfsExtDirBody0 = positionAfterfileSize; 91 + } 92 + else 93 + { 94 + uint32_t fileSize = Load32Le(Input + (uint32_t)positionAfternlink); 95 + SquashfsExtDirBodySetU32(Ctx, (uint32_t)1U, fileSize); 96 + BOOLEAN actionResult = TRUE; 97 + KRML_MAYBE_UNUSED_VAR(actionResult); 98 + positionAfterSquashfsExtDirBody0 = positionAfterfileSize; 99 + } 100 + uint64_t positionAfterfileSize0; 101 + if (EverParseIsSuccess(positionAfterSquashfsExtDirBody0)) 102 + { 103 + positionAfterfileSize0 = positionAfterSquashfsExtDirBody0; 104 + } 105 + else 106 + { 107 + ErrorHandlerFn("_SquashfsExtDirBody", 108 + "file_size", 109 + EverParseErrorReasonOfResult(positionAfterSquashfsExtDirBody0), 110 + EverParseGetValidatorErrorKind(positionAfterSquashfsExtDirBody0), 111 + Ctxt, 112 + Input, 113 + positionAfternlink); 114 + positionAfterfileSize0 = positionAfterSquashfsExtDirBody0; 115 + } 116 + if (EverParseIsError(positionAfterfileSize0)) 117 + { 118 + return positionAfterfileSize0; 119 + } 120 + /* Validating field start_block */ 121 + /* Checking that we have enough space for a UINT32, i.e., 4 bytes */ 122 + BOOLEAN hasBytes2 = 4ULL <= (InputLength - positionAfterfileSize0); 123 + uint64_t positionAfterstartBlock; 124 + if (hasBytes2) 125 + { 126 + positionAfterstartBlock = positionAfterfileSize0 + 4ULL; 127 + } 128 + else 129 + { 130 + positionAfterstartBlock = 131 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 132 + positionAfterfileSize0); 133 + } 134 + uint64_t positionAfterSquashfsExtDirBody1; 135 + if (EverParseIsError(positionAfterstartBlock)) 136 + { 137 + positionAfterSquashfsExtDirBody1 = positionAfterstartBlock; 138 + } 139 + else 140 + { 141 + uint32_t startBlock = Load32Le(Input + (uint32_t)positionAfterfileSize0); 142 + SquashfsExtDirBodySetU32(Ctx, (uint32_t)2U, startBlock); 143 + BOOLEAN actionResult = TRUE; 144 + KRML_MAYBE_UNUSED_VAR(actionResult); 145 + positionAfterSquashfsExtDirBody1 = positionAfterstartBlock; 146 + } 147 + uint64_t positionAfterstartBlock0; 148 + if (EverParseIsSuccess(positionAfterSquashfsExtDirBody1)) 149 + { 150 + positionAfterstartBlock0 = positionAfterSquashfsExtDirBody1; 151 + } 152 + else 153 + { 154 + ErrorHandlerFn("_SquashfsExtDirBody", 155 + "start_block", 156 + EverParseErrorReasonOfResult(positionAfterSquashfsExtDirBody1), 157 + EverParseGetValidatorErrorKind(positionAfterSquashfsExtDirBody1), 158 + Ctxt, 159 + Input, 160 + positionAfterfileSize0); 161 + positionAfterstartBlock0 = positionAfterSquashfsExtDirBody1; 162 + } 163 + if (EverParseIsError(positionAfterstartBlock0)) 164 + { 165 + return positionAfterstartBlock0; 166 + } 167 + /* Validating field parent_inode */ 168 + /* Checking that we have enough space for a UINT32, i.e., 4 bytes */ 169 + BOOLEAN hasBytes3 = 4ULL <= (InputLength - positionAfterstartBlock0); 170 + uint64_t positionAfterparentInode; 171 + if (hasBytes3) 172 + { 173 + positionAfterparentInode = positionAfterstartBlock0 + 4ULL; 174 + } 175 + else 176 + { 177 + positionAfterparentInode = 178 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 179 + positionAfterstartBlock0); 180 + } 181 + uint64_t positionAfterSquashfsExtDirBody2; 182 + if (EverParseIsError(positionAfterparentInode)) 183 + { 184 + positionAfterSquashfsExtDirBody2 = positionAfterparentInode; 185 + } 186 + else 187 + { 188 + uint32_t parentInode = Load32Le(Input + (uint32_t)positionAfterstartBlock0); 189 + SquashfsExtDirBodySetU32(Ctx, (uint32_t)3U, parentInode); 190 + BOOLEAN actionResult = TRUE; 191 + KRML_MAYBE_UNUSED_VAR(actionResult); 192 + positionAfterSquashfsExtDirBody2 = positionAfterparentInode; 193 + } 194 + uint64_t positionAfterparentInode0; 195 + if (EverParseIsSuccess(positionAfterSquashfsExtDirBody2)) 196 + { 197 + positionAfterparentInode0 = positionAfterSquashfsExtDirBody2; 198 + } 199 + else 200 + { 201 + ErrorHandlerFn("_SquashfsExtDirBody", 202 + "parent_inode", 203 + EverParseErrorReasonOfResult(positionAfterSquashfsExtDirBody2), 204 + EverParseGetValidatorErrorKind(positionAfterSquashfsExtDirBody2), 205 + Ctxt, 206 + Input, 207 + positionAfterstartBlock0); 208 + positionAfterparentInode0 = positionAfterSquashfsExtDirBody2; 209 + } 210 + if (EverParseIsError(positionAfterparentInode0)) 211 + { 212 + return positionAfterparentInode0; 213 + } 214 + /* Validating field inodex_count */ 215 + /* Checking that we have enough space for a UINT16, i.e., 2 bytes */ 216 + BOOLEAN hasBytes4 = 2ULL <= (InputLength - positionAfterparentInode0); 217 + uint64_t positionAfterinodexCount; 218 + if (hasBytes4) 219 + { 220 + positionAfterinodexCount = positionAfterparentInode0 + 2ULL; 221 + } 222 + else 223 + { 224 + positionAfterinodexCount = 225 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 226 + positionAfterparentInode0); 227 + } 228 + uint64_t positionAfterSquashfsExtDirBody3; 229 + if (EverParseIsError(positionAfterinodexCount)) 230 + { 231 + positionAfterSquashfsExtDirBody3 = positionAfterinodexCount; 232 + } 233 + else 234 + { 235 + uint16_t r = Load16Le(Input + (uint32_t)positionAfterparentInode0); 236 + uint16_t inodexCount = (uint16_t)(uint32_t)r; 237 + SquashfsExtDirBodySetU16(Ctx, (uint32_t)4U, inodexCount); 238 + BOOLEAN actionResult = TRUE; 239 + KRML_MAYBE_UNUSED_VAR(actionResult); 240 + positionAfterSquashfsExtDirBody3 = positionAfterinodexCount; 241 + } 242 + uint64_t positionAfterinodexCount0; 243 + if (EverParseIsSuccess(positionAfterSquashfsExtDirBody3)) 244 + { 245 + positionAfterinodexCount0 = positionAfterSquashfsExtDirBody3; 246 + } 247 + else 248 + { 249 + ErrorHandlerFn("_SquashfsExtDirBody", 250 + "inodex_count", 251 + EverParseErrorReasonOfResult(positionAfterSquashfsExtDirBody3), 252 + EverParseGetValidatorErrorKind(positionAfterSquashfsExtDirBody3), 253 + Ctxt, 254 + Input, 255 + positionAfterparentInode0); 256 + positionAfterinodexCount0 = positionAfterSquashfsExtDirBody3; 257 + } 258 + if (EverParseIsError(positionAfterinodexCount0)) 259 + { 260 + return positionAfterinodexCount0; 261 + } 262 + /* Validating field offset */ 263 + /* Checking that we have enough space for a UINT16, i.e., 2 bytes */ 264 + BOOLEAN hasBytes5 = 2ULL <= (InputLength - positionAfterinodexCount0); 265 + uint64_t positionAfteroffset0; 266 + if (hasBytes5) 267 + { 268 + positionAfteroffset0 = positionAfterinodexCount0 + 2ULL; 269 + } 270 + else 271 + { 272 + positionAfteroffset0 = 273 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 274 + positionAfterinodexCount0); 275 + } 276 + uint64_t positionAfterSquashfsExtDirBody4; 277 + if (EverParseIsError(positionAfteroffset0)) 278 + { 279 + positionAfterSquashfsExtDirBody4 = positionAfteroffset0; 280 + } 281 + else 282 + { 283 + uint16_t r = Load16Le(Input + (uint32_t)positionAfterinodexCount0); 284 + uint16_t offset = (uint16_t)(uint32_t)r; 285 + SquashfsExtDirBodySetU16(Ctx, (uint32_t)5U, offset); 286 + BOOLEAN actionResult = TRUE; 287 + KRML_MAYBE_UNUSED_VAR(actionResult); 288 + positionAfterSquashfsExtDirBody4 = positionAfteroffset0; 289 + } 290 + uint64_t positionAfteroffset; 291 + if (EverParseIsSuccess(positionAfterSquashfsExtDirBody4)) 292 + { 293 + positionAfteroffset = positionAfterSquashfsExtDirBody4; 294 + } 295 + else 296 + { 297 + ErrorHandlerFn("_SquashfsExtDirBody", 298 + "offset", 299 + EverParseErrorReasonOfResult(positionAfterSquashfsExtDirBody4), 300 + EverParseGetValidatorErrorKind(positionAfterSquashfsExtDirBody4), 301 + Ctxt, 302 + Input, 303 + positionAfterinodexCount0); 304 + positionAfteroffset = positionAfterSquashfsExtDirBody4; 305 + } 306 + if (EverParseIsError(positionAfteroffset)) 307 + { 308 + return positionAfteroffset; 309 + } 310 + /* Validating field xattr_id */ 311 + /* Checking that we have enough space for a UINT32, i.e., 4 bytes */ 312 + BOOLEAN hasBytes = 4ULL <= (InputLength - positionAfteroffset); 313 + uint64_t positionAfterxattrId; 314 + if (hasBytes) 315 + { 316 + positionAfterxattrId = positionAfteroffset + 4ULL; 317 + } 318 + else 319 + { 320 + positionAfterxattrId = 321 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 322 + positionAfteroffset); 323 + } 324 + uint64_t positionAfterSquashfsExtDirBody5; 325 + if (EverParseIsError(positionAfterxattrId)) 326 + { 327 + positionAfterSquashfsExtDirBody5 = positionAfterxattrId; 328 + } 329 + else 330 + { 331 + uint32_t xattrId = Load32Le(Input + (uint32_t)positionAfteroffset); 332 + SquashfsExtDirBodySetU32(Ctx, (uint32_t)6U, xattrId); 333 + BOOLEAN actionResult = TRUE; 334 + KRML_MAYBE_UNUSED_VAR(actionResult); 335 + positionAfterSquashfsExtDirBody5 = positionAfterxattrId; 336 + } 337 + if (EverParseIsSuccess(positionAfterSquashfsExtDirBody5)) 338 + { 339 + return positionAfterSquashfsExtDirBody5; 340 + } 341 + ErrorHandlerFn("_SquashfsExtDirBody", 342 + "xattr_id", 343 + EverParseErrorReasonOfResult(positionAfterSquashfsExtDirBody5), 344 + EverParseGetValidatorErrorKind(positionAfterSquashfsExtDirBody5), 345 + Ctxt, 346 + Input, 347 + positionAfteroffset); 348 + return positionAfterSquashfsExtDirBody5; 349 + } 350 +
+37
c/SquashfsExtDirBody.h
··· 1 + 2 + 3 + #ifndef SquashfsExtDirBody_H 4 + #define SquashfsExtDirBody_H 5 + 6 + #if defined(__cplusplus) 7 + extern "C" { 8 + #endif 9 + 10 + #include "EverParse.h" 11 + #include "SquashfsExtDirBody_ExternalTypedefs.h" 12 + 13 + uint64_t 14 + SquashfsExtDirBodyValidateSquashfsExtDirBody( 15 + WIRECTX *Ctx, 16 + uint8_t *Ctxt, 17 + void 18 + (*ErrorHandlerFn)( 19 + EVERPARSE_STRING x0, 20 + EVERPARSE_STRING x1, 21 + EVERPARSE_STRING x2, 22 + uint64_t x3, 23 + uint8_t *x4, 24 + uint8_t *x5, 25 + uint64_t x6 26 + ), 27 + uint8_t *Input, 28 + uint64_t InputLength, 29 + uint64_t StartPosition 30 + ); 31 + 32 + #if defined(__cplusplus) 33 + } 34 + #endif 35 + 36 + #define SquashfsExtDirBody_H_DEFINED 37 + #endif /* SquashfsExtDirBody_H */
+41
c/SquashfsExtDirBodyWrapper.c
··· 1 + #include "SquashfsExtDirBodyWrapper.h" 2 + #include "EverParse.h" 3 + #include "SquashfsExtDirBody.h" 4 + void SquashfsExtDirBodyEverParseError(const char *StructName, const char *FieldName, const char *Reason); 5 + 6 + static 7 + void DefaultErrorHandler( 8 + const char *typename_s, 9 + const char *fieldname, 10 + const char *reason, 11 + uint64_t error_code, 12 + uint8_t *context, 13 + EVERPARSE_INPUT_BUFFER input, 14 + uint64_t start_pos) 15 + { 16 + EVERPARSE_ERROR_FRAME *frame = (EVERPARSE_ERROR_FRAME*)context; 17 + EverParseDefaultErrorHandler( 18 + typename_s, 19 + fieldname, 20 + reason, 21 + error_code, 22 + frame, 23 + input, 24 + start_pos 25 + ); 26 + } 27 + 28 + BOOLEAN SquashfsExtDirBodyCheckSquashfsExtDirBody(WIRECTX* ctx, uint8_t *base, uint32_t len) { 29 + EVERPARSE_ERROR_FRAME frame; 30 + frame.filled = FALSE; 31 + uint64_t result = SquashfsExtDirBodyValidateSquashfsExtDirBody(ctx, (uint8_t*)&frame, &DefaultErrorHandler, base, len, 0); 32 + if (EverParseIsError(result)) 33 + { 34 + if (frame.filled) 35 + { 36 + SquashfsExtDirBodyEverParseError(frame.typename_s, frame.fieldname, frame.reason); 37 + } 38 + return FALSE; 39 + } 40 + return TRUE; 41 + }
+26
c/SquashfsExtDirBodyWrapper.h
··· 1 + #include "EverParseEndianness.h" 2 + #define EVERPARSE_SUCCESS 0ul 3 + #define EVERPARSE_ERROR_GENERIC 1uL 4 + #define EVERPARSE_ERROR_NOT_ENOUGH_DATA 2uL 5 + #define EVERPARSE_ERROR_IMPOSSIBLE 3uL 6 + #define EVERPARSE_ERROR_LIST_SIZE_NOT_MULTIPLE 4uL 7 + #define EVERPARSE_ERROR_ACTION_FAILED 5uL 8 + #define EVERPARSE_ERROR_CONSTRAINT_FAILED 6uL 9 + #define EVERPARSE_ERROR_UNEXPECTED_PADDING 7uL 10 + // Probe wrapper error codes 11 + #define EVERPARSE_PROBE_FAILURE_INCORRECT_SIZE 256uL 12 + #define EVERPARSE_PROBE_FAILURE_INIT 257uL 13 + #define EVERPARSE_PROBE_FAILURE_PROBE 258uL 14 + #define EVERPARSE_PROBE_FAILURE_VALIDATION 259uL 15 + 16 + 17 + #include "SquashfsExtDirBody_ExternalTypedefs.h" 18 + 19 + 20 + #ifdef __cplusplus 21 + extern "C" { 22 + #endif 23 + BOOLEAN SquashfsExtDirBodyCheckSquashfsExtDirBody(WIRECTX* ctx, uint8_t *base, uint32_t len); 24 + #ifdef __cplusplus 25 + } 26 + #endif
+22
c/SquashfsExtDirBody_ExternalAPI.h
··· 1 + 2 + 3 + #ifndef SquashfsExtDirBody_ExternalAPI_H 4 + #define SquashfsExtDirBody_ExternalAPI_H 5 + 6 + #if defined(__cplusplus) 7 + extern "C" { 8 + #endif 9 + 10 + #include "EverParse.h" 11 + #include "SquashfsExtDirBody_ExternalTypedefs.h" 12 + 13 + extern void SquashfsExtDirBodySetU32(WIRECTX *ctx, uint32_t idx, uint32_t v); 14 + 15 + extern void SquashfsExtDirBodySetU16(WIRECTX *ctx, uint32_t idx, uint16_t v); 16 + 17 + #if defined(__cplusplus) 18 + } 19 + #endif 20 + 21 + #define SquashfsExtDirBody_ExternalAPI_H_DEFINED 22 + #endif /* SquashfsExtDirBody_ExternalAPI_H */
+4
c/SquashfsExtDirBody_ExternalTypedefs.h
··· 1 + #ifndef WIRECTX_DEFINED 2 + #define WIRECTX_DEFINED 3 + typedef struct SquashfsExtDirBodyFields WIRECTX; 4 + #endif
+26
c/SquashfsExtDirBody_Fields.c
··· 1 + #include <stdint.h> 2 + #include "SquashfsExtDirBody_Fields.h" 3 + #include "SquashfsExtDirBody_ExternalTypedefs.h" 4 + #include "SquashfsExtDirBody_ExternalAPI.h" 5 + 6 + void SquashfsExtDirBodySetU32(WIRECTX *ctx, uint32_t idx, uint32_t v) { 7 + SquashfsExtDirBodyFields *f = (SquashfsExtDirBodyFields *) ctx; 8 + switch (idx) { 9 + case 0: f->nlink = (uint32_t) v; break; 10 + case 1: f->file_size = (uint32_t) v; break; 11 + case 2: f->start_block = (uint32_t) v; break; 12 + case 3: f->parent_inode = (uint32_t) v; break; 13 + case 6: f->xattr_id = (uint32_t) v; break; 14 + default: (void) f; (void) v; break; 15 + } 16 + } 17 + 18 + void SquashfsExtDirBodySetU16(WIRECTX *ctx, uint32_t idx, uint16_t v) { 19 + SquashfsExtDirBodyFields *f = (SquashfsExtDirBodyFields *) ctx; 20 + switch (idx) { 21 + case 4: f->inodex_count = (uint16_t) v; break; 22 + case 5: f->offset = (uint16_t) v; break; 23 + default: (void) f; (void) v; break; 24 + } 25 + } 26 +
+26
c/SquashfsExtDirBody_Fields.h
··· 1 + #ifndef SQUASHFSEXTDIRBODY_FIELDS_H 2 + #define SQUASHFSEXTDIRBODY_FIELDS_H 3 + #include <stdint.h> 4 + 5 + /* Field indices -- use with the schema's WireSet* callbacks in a 6 + custom [WIRECTX] if you only want to capture a subset. */ 7 + #define SQUASHFSEXTDIRBODY_IDX_NLINK 0 8 + #define SQUASHFSEXTDIRBODY_IDX_FILE_SIZE 1 9 + #define SQUASHFSEXTDIRBODY_IDX_START_BLOCK 2 10 + #define SQUASHFSEXTDIRBODY_IDX_PARENT_INODE 3 11 + #define SQUASHFSEXTDIRBODY_IDX_INODEX_COUNT 4 12 + #define SQUASHFSEXTDIRBODY_IDX_OFFSET 5 13 + #define SQUASHFSEXTDIRBODY_IDX_XATTR_ID 6 14 + 15 + /* Default plug: one typed member per named field. Pass a pointer to 16 + [SquashfsExtDirBodyFields] as [WIRECTX *] when you want every field populated. */ 17 + typedef struct SquashfsExtDirBodyFields { 18 + uint32_t nlink; 19 + uint32_t file_size; 20 + uint32_t start_block; 21 + uint32_t parent_inode; 22 + uint16_t inodex_count; 23 + uint16_t offset; 24 + uint32_t xattr_id; 25 + } SquashfsExtDirBodyFields; 26 + #endif
+9 -9
c/SquashfsExtFileBody.3d
··· 1 1 extern typedef struct _WireCtx WireCtx 2 2 3 - extern unit WireSetU64(mutable WireCtx *ctx, UINT32 idx, UINT64 v) 3 + extern unit SquashfsExtFileBodySetU64(mutable WireCtx *ctx, UINT32 idx, UINT64 v) 4 4 5 - extern unit WireSetU32(mutable WireCtx *ctx, UINT32 idx, UINT32 v) 5 + extern unit SquashfsExtFileBodySetU32(mutable WireCtx *ctx, UINT32 idx, UINT32 v) 6 6 7 7 entrypoint 8 8 typedef struct _SquashfsExtFileBody(mutable WireCtx *ctx) 9 9 { 10 - UINT64 start_block {:on-success WireSetU64(ctx, (UINT32) 0, start_block); return true; }; 11 - UINT64 file_size {:on-success WireSetU64(ctx, (UINT32) 1, file_size); return true; }; 12 - UINT64 sparse {:on-success WireSetU64(ctx, (UINT32) 2, sparse); return true; }; 13 - UINT32 nlink {:on-success WireSetU32(ctx, (UINT32) 3, nlink); return true; }; 14 - UINT32 fragment {:on-success WireSetU32(ctx, (UINT32) 4, fragment); return true; }; 15 - UINT32 offset {:on-success WireSetU32(ctx, (UINT32) 5, offset); return true; }; 16 - UINT32 xattr_id {:on-success WireSetU32(ctx, (UINT32) 6, xattr_id); return true; }; 10 + UINT64 start_block {:on-success SquashfsExtFileBodySetU64(ctx, (UINT32) 0, start_block); return true; }; 11 + UINT64 file_size {:on-success SquashfsExtFileBodySetU64(ctx, (UINT32) 1, file_size); return true; }; 12 + UINT64 sparse {:on-success SquashfsExtFileBodySetU64(ctx, (UINT32) 2, sparse); return true; }; 13 + UINT32 nlink {:on-success SquashfsExtFileBodySetU32(ctx, (UINT32) 3, nlink); return true; }; 14 + UINT32 fragment {:on-success SquashfsExtFileBodySetU32(ctx, (UINT32) 4, fragment); return true; }; 15 + UINT32 offset {:on-success SquashfsExtFileBodySetU32(ctx, (UINT32) 5, offset); return true; }; 16 + UINT32 xattr_id {:on-success SquashfsExtFileBodySetU32(ctx, (UINT32) 6, xattr_id); return true; }; 17 17 } SquashfsExtFileBody; 18 18 19 19
+348
c/SquashfsExtFileBody.c
··· 1 + 2 + 3 + #include "SquashfsExtFileBody.h" 4 + 5 + #include "SquashfsExtFileBody_ExternalAPI.h" 6 + 7 + uint64_t 8 + SquashfsExtFileBodyValidateSquashfsExtFileBody( 9 + WIRECTX *Ctx, 10 + uint8_t *Ctxt, 11 + void 12 + (*ErrorHandlerFn)( 13 + EVERPARSE_STRING x0, 14 + EVERPARSE_STRING x1, 15 + EVERPARSE_STRING x2, 16 + uint64_t x3, 17 + uint8_t *x4, 18 + uint8_t *x5, 19 + uint64_t x6 20 + ), 21 + uint8_t *Input, 22 + uint64_t InputLength, 23 + uint64_t StartPosition 24 + ) 25 + { 26 + /* Validating field start_block */ 27 + /* Checking that we have enough space for a UINT64, i.e., 8 bytes */ 28 + BOOLEAN hasBytes0 = 8ULL <= (InputLength - StartPosition); 29 + uint64_t positionAfterstartBlock; 30 + if (hasBytes0) 31 + { 32 + positionAfterstartBlock = StartPosition + 8ULL; 33 + } 34 + else 35 + { 36 + positionAfterstartBlock = 37 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 38 + StartPosition); 39 + } 40 + uint64_t positionAfterSquashfsExtFileBody; 41 + if (EverParseIsError(positionAfterstartBlock)) 42 + { 43 + positionAfterSquashfsExtFileBody = positionAfterstartBlock; 44 + } 45 + else 46 + { 47 + uint64_t startBlock = Load64Le(Input + (uint32_t)StartPosition); 48 + SquashfsExtFileBodySetU64(Ctx, (uint32_t)0U, startBlock); 49 + BOOLEAN actionResult = TRUE; 50 + KRML_MAYBE_UNUSED_VAR(actionResult); 51 + positionAfterSquashfsExtFileBody = positionAfterstartBlock; 52 + } 53 + uint64_t positionAfterstartBlock0; 54 + if (EverParseIsSuccess(positionAfterSquashfsExtFileBody)) 55 + { 56 + positionAfterstartBlock0 = positionAfterSquashfsExtFileBody; 57 + } 58 + else 59 + { 60 + ErrorHandlerFn("_SquashfsExtFileBody", 61 + "start_block", 62 + EverParseErrorReasonOfResult(positionAfterSquashfsExtFileBody), 63 + EverParseGetValidatorErrorKind(positionAfterSquashfsExtFileBody), 64 + Ctxt, 65 + Input, 66 + StartPosition); 67 + positionAfterstartBlock0 = positionAfterSquashfsExtFileBody; 68 + } 69 + if (EverParseIsError(positionAfterstartBlock0)) 70 + { 71 + return positionAfterstartBlock0; 72 + } 73 + /* Validating field file_size */ 74 + /* Checking that we have enough space for a UINT64, i.e., 8 bytes */ 75 + BOOLEAN hasBytes1 = 8ULL <= (InputLength - positionAfterstartBlock0); 76 + uint64_t positionAfterfileSize; 77 + if (hasBytes1) 78 + { 79 + positionAfterfileSize = positionAfterstartBlock0 + 8ULL; 80 + } 81 + else 82 + { 83 + positionAfterfileSize = 84 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 85 + positionAfterstartBlock0); 86 + } 87 + uint64_t positionAfterSquashfsExtFileBody0; 88 + if (EverParseIsError(positionAfterfileSize)) 89 + { 90 + positionAfterSquashfsExtFileBody0 = positionAfterfileSize; 91 + } 92 + else 93 + { 94 + uint64_t fileSize = Load64Le(Input + (uint32_t)positionAfterstartBlock0); 95 + SquashfsExtFileBodySetU64(Ctx, (uint32_t)1U, fileSize); 96 + BOOLEAN actionResult = TRUE; 97 + KRML_MAYBE_UNUSED_VAR(actionResult); 98 + positionAfterSquashfsExtFileBody0 = positionAfterfileSize; 99 + } 100 + uint64_t positionAfterfileSize0; 101 + if (EverParseIsSuccess(positionAfterSquashfsExtFileBody0)) 102 + { 103 + positionAfterfileSize0 = positionAfterSquashfsExtFileBody0; 104 + } 105 + else 106 + { 107 + ErrorHandlerFn("_SquashfsExtFileBody", 108 + "file_size", 109 + EverParseErrorReasonOfResult(positionAfterSquashfsExtFileBody0), 110 + EverParseGetValidatorErrorKind(positionAfterSquashfsExtFileBody0), 111 + Ctxt, 112 + Input, 113 + positionAfterstartBlock0); 114 + positionAfterfileSize0 = positionAfterSquashfsExtFileBody0; 115 + } 116 + if (EverParseIsError(positionAfterfileSize0)) 117 + { 118 + return positionAfterfileSize0; 119 + } 120 + /* Validating field sparse */ 121 + /* Checking that we have enough space for a UINT64, i.e., 8 bytes */ 122 + BOOLEAN hasBytes2 = 8ULL <= (InputLength - positionAfterfileSize0); 123 + uint64_t positionAftersparse0; 124 + if (hasBytes2) 125 + { 126 + positionAftersparse0 = positionAfterfileSize0 + 8ULL; 127 + } 128 + else 129 + { 130 + positionAftersparse0 = 131 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 132 + positionAfterfileSize0); 133 + } 134 + uint64_t positionAfterSquashfsExtFileBody1; 135 + if (EverParseIsError(positionAftersparse0)) 136 + { 137 + positionAfterSquashfsExtFileBody1 = positionAftersparse0; 138 + } 139 + else 140 + { 141 + uint64_t sparse = Load64Le(Input + (uint32_t)positionAfterfileSize0); 142 + SquashfsExtFileBodySetU64(Ctx, (uint32_t)2U, sparse); 143 + BOOLEAN actionResult = TRUE; 144 + KRML_MAYBE_UNUSED_VAR(actionResult); 145 + positionAfterSquashfsExtFileBody1 = positionAftersparse0; 146 + } 147 + uint64_t positionAftersparse; 148 + if (EverParseIsSuccess(positionAfterSquashfsExtFileBody1)) 149 + { 150 + positionAftersparse = positionAfterSquashfsExtFileBody1; 151 + } 152 + else 153 + { 154 + ErrorHandlerFn("_SquashfsExtFileBody", 155 + "sparse", 156 + EverParseErrorReasonOfResult(positionAfterSquashfsExtFileBody1), 157 + EverParseGetValidatorErrorKind(positionAfterSquashfsExtFileBody1), 158 + Ctxt, 159 + Input, 160 + positionAfterfileSize0); 161 + positionAftersparse = positionAfterSquashfsExtFileBody1; 162 + } 163 + if (EverParseIsError(positionAftersparse)) 164 + { 165 + return positionAftersparse; 166 + } 167 + /* Validating field nlink */ 168 + /* Checking that we have enough space for a UINT32, i.e., 4 bytes */ 169 + BOOLEAN hasBytes3 = 4ULL <= (InputLength - positionAftersparse); 170 + uint64_t positionAfternlink0; 171 + if (hasBytes3) 172 + { 173 + positionAfternlink0 = positionAftersparse + 4ULL; 174 + } 175 + else 176 + { 177 + positionAfternlink0 = 178 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 179 + positionAftersparse); 180 + } 181 + uint64_t positionAfterSquashfsExtFileBody2; 182 + if (EverParseIsError(positionAfternlink0)) 183 + { 184 + positionAfterSquashfsExtFileBody2 = positionAfternlink0; 185 + } 186 + else 187 + { 188 + uint32_t nlink = Load32Le(Input + (uint32_t)positionAftersparse); 189 + SquashfsExtFileBodySetU32(Ctx, (uint32_t)3U, nlink); 190 + BOOLEAN actionResult = TRUE; 191 + KRML_MAYBE_UNUSED_VAR(actionResult); 192 + positionAfterSquashfsExtFileBody2 = positionAfternlink0; 193 + } 194 + uint64_t positionAfternlink; 195 + if (EverParseIsSuccess(positionAfterSquashfsExtFileBody2)) 196 + { 197 + positionAfternlink = positionAfterSquashfsExtFileBody2; 198 + } 199 + else 200 + { 201 + ErrorHandlerFn("_SquashfsExtFileBody", 202 + "nlink", 203 + EverParseErrorReasonOfResult(positionAfterSquashfsExtFileBody2), 204 + EverParseGetValidatorErrorKind(positionAfterSquashfsExtFileBody2), 205 + Ctxt, 206 + Input, 207 + positionAftersparse); 208 + positionAfternlink = positionAfterSquashfsExtFileBody2; 209 + } 210 + if (EverParseIsError(positionAfternlink)) 211 + { 212 + return positionAfternlink; 213 + } 214 + /* Validating field fragment */ 215 + /* Checking that we have enough space for a UINT32, i.e., 4 bytes */ 216 + BOOLEAN hasBytes4 = 4ULL <= (InputLength - positionAfternlink); 217 + uint64_t positionAfterfragment0; 218 + if (hasBytes4) 219 + { 220 + positionAfterfragment0 = positionAfternlink + 4ULL; 221 + } 222 + else 223 + { 224 + positionAfterfragment0 = 225 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 226 + positionAfternlink); 227 + } 228 + uint64_t positionAfterSquashfsExtFileBody3; 229 + if (EverParseIsError(positionAfterfragment0)) 230 + { 231 + positionAfterSquashfsExtFileBody3 = positionAfterfragment0; 232 + } 233 + else 234 + { 235 + uint32_t fragment = Load32Le(Input + (uint32_t)positionAfternlink); 236 + SquashfsExtFileBodySetU32(Ctx, (uint32_t)4U, fragment); 237 + BOOLEAN actionResult = TRUE; 238 + KRML_MAYBE_UNUSED_VAR(actionResult); 239 + positionAfterSquashfsExtFileBody3 = positionAfterfragment0; 240 + } 241 + uint64_t positionAfterfragment; 242 + if (EverParseIsSuccess(positionAfterSquashfsExtFileBody3)) 243 + { 244 + positionAfterfragment = positionAfterSquashfsExtFileBody3; 245 + } 246 + else 247 + { 248 + ErrorHandlerFn("_SquashfsExtFileBody", 249 + "fragment", 250 + EverParseErrorReasonOfResult(positionAfterSquashfsExtFileBody3), 251 + EverParseGetValidatorErrorKind(positionAfterSquashfsExtFileBody3), 252 + Ctxt, 253 + Input, 254 + positionAfternlink); 255 + positionAfterfragment = positionAfterSquashfsExtFileBody3; 256 + } 257 + if (EverParseIsError(positionAfterfragment)) 258 + { 259 + return positionAfterfragment; 260 + } 261 + /* Validating field offset */ 262 + /* Checking that we have enough space for a UINT32, i.e., 4 bytes */ 263 + BOOLEAN hasBytes5 = 4ULL <= (InputLength - positionAfterfragment); 264 + uint64_t positionAfteroffset0; 265 + if (hasBytes5) 266 + { 267 + positionAfteroffset0 = positionAfterfragment + 4ULL; 268 + } 269 + else 270 + { 271 + positionAfteroffset0 = 272 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 273 + positionAfterfragment); 274 + } 275 + uint64_t positionAfterSquashfsExtFileBody4; 276 + if (EverParseIsError(positionAfteroffset0)) 277 + { 278 + positionAfterSquashfsExtFileBody4 = positionAfteroffset0; 279 + } 280 + else 281 + { 282 + uint32_t offset = Load32Le(Input + (uint32_t)positionAfterfragment); 283 + SquashfsExtFileBodySetU32(Ctx, (uint32_t)5U, offset); 284 + BOOLEAN actionResult = TRUE; 285 + KRML_MAYBE_UNUSED_VAR(actionResult); 286 + positionAfterSquashfsExtFileBody4 = positionAfteroffset0; 287 + } 288 + uint64_t positionAfteroffset; 289 + if (EverParseIsSuccess(positionAfterSquashfsExtFileBody4)) 290 + { 291 + positionAfteroffset = positionAfterSquashfsExtFileBody4; 292 + } 293 + else 294 + { 295 + ErrorHandlerFn("_SquashfsExtFileBody", 296 + "offset", 297 + EverParseErrorReasonOfResult(positionAfterSquashfsExtFileBody4), 298 + EverParseGetValidatorErrorKind(positionAfterSquashfsExtFileBody4), 299 + Ctxt, 300 + Input, 301 + positionAfterfragment); 302 + positionAfteroffset = positionAfterSquashfsExtFileBody4; 303 + } 304 + if (EverParseIsError(positionAfteroffset)) 305 + { 306 + return positionAfteroffset; 307 + } 308 + /* Validating field xattr_id */ 309 + /* Checking that we have enough space for a UINT32, i.e., 4 bytes */ 310 + BOOLEAN hasBytes = 4ULL <= (InputLength - positionAfteroffset); 311 + uint64_t positionAfterxattrId; 312 + if (hasBytes) 313 + { 314 + positionAfterxattrId = positionAfteroffset + 4ULL; 315 + } 316 + else 317 + { 318 + positionAfterxattrId = 319 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 320 + positionAfteroffset); 321 + } 322 + uint64_t positionAfterSquashfsExtFileBody5; 323 + if (EverParseIsError(positionAfterxattrId)) 324 + { 325 + positionAfterSquashfsExtFileBody5 = positionAfterxattrId; 326 + } 327 + else 328 + { 329 + uint32_t xattrId = Load32Le(Input + (uint32_t)positionAfteroffset); 330 + SquashfsExtFileBodySetU32(Ctx, (uint32_t)6U, xattrId); 331 + BOOLEAN actionResult = TRUE; 332 + KRML_MAYBE_UNUSED_VAR(actionResult); 333 + positionAfterSquashfsExtFileBody5 = positionAfterxattrId; 334 + } 335 + if (EverParseIsSuccess(positionAfterSquashfsExtFileBody5)) 336 + { 337 + return positionAfterSquashfsExtFileBody5; 338 + } 339 + ErrorHandlerFn("_SquashfsExtFileBody", 340 + "xattr_id", 341 + EverParseErrorReasonOfResult(positionAfterSquashfsExtFileBody5), 342 + EverParseGetValidatorErrorKind(positionAfterSquashfsExtFileBody5), 343 + Ctxt, 344 + Input, 345 + positionAfteroffset); 346 + return positionAfterSquashfsExtFileBody5; 347 + } 348 +
+37
c/SquashfsExtFileBody.h
··· 1 + 2 + 3 + #ifndef SquashfsExtFileBody_H 4 + #define SquashfsExtFileBody_H 5 + 6 + #if defined(__cplusplus) 7 + extern "C" { 8 + #endif 9 + 10 + #include "EverParse.h" 11 + #include "SquashfsExtFileBody_ExternalTypedefs.h" 12 + 13 + uint64_t 14 + SquashfsExtFileBodyValidateSquashfsExtFileBody( 15 + WIRECTX *Ctx, 16 + uint8_t *Ctxt, 17 + void 18 + (*ErrorHandlerFn)( 19 + EVERPARSE_STRING x0, 20 + EVERPARSE_STRING x1, 21 + EVERPARSE_STRING x2, 22 + uint64_t x3, 23 + uint8_t *x4, 24 + uint8_t *x5, 25 + uint64_t x6 26 + ), 27 + uint8_t *Input, 28 + uint64_t InputLength, 29 + uint64_t StartPosition 30 + ); 31 + 32 + #if defined(__cplusplus) 33 + } 34 + #endif 35 + 36 + #define SquashfsExtFileBody_H_DEFINED 37 + #endif /* SquashfsExtFileBody_H */
+41
c/SquashfsExtFileBodyWrapper.c
··· 1 + #include "SquashfsExtFileBodyWrapper.h" 2 + #include "EverParse.h" 3 + #include "SquashfsExtFileBody.h" 4 + void SquashfsExtFileBodyEverParseError(const char *StructName, const char *FieldName, const char *Reason); 5 + 6 + static 7 + void DefaultErrorHandler( 8 + const char *typename_s, 9 + const char *fieldname, 10 + const char *reason, 11 + uint64_t error_code, 12 + uint8_t *context, 13 + EVERPARSE_INPUT_BUFFER input, 14 + uint64_t start_pos) 15 + { 16 + EVERPARSE_ERROR_FRAME *frame = (EVERPARSE_ERROR_FRAME*)context; 17 + EverParseDefaultErrorHandler( 18 + typename_s, 19 + fieldname, 20 + reason, 21 + error_code, 22 + frame, 23 + input, 24 + start_pos 25 + ); 26 + } 27 + 28 + BOOLEAN SquashfsExtFileBodyCheckSquashfsExtFileBody(WIRECTX* ctx, uint8_t *base, uint32_t len) { 29 + EVERPARSE_ERROR_FRAME frame; 30 + frame.filled = FALSE; 31 + uint64_t result = SquashfsExtFileBodyValidateSquashfsExtFileBody(ctx, (uint8_t*)&frame, &DefaultErrorHandler, base, len, 0); 32 + if (EverParseIsError(result)) 33 + { 34 + if (frame.filled) 35 + { 36 + SquashfsExtFileBodyEverParseError(frame.typename_s, frame.fieldname, frame.reason); 37 + } 38 + return FALSE; 39 + } 40 + return TRUE; 41 + }
+26
c/SquashfsExtFileBodyWrapper.h
··· 1 + #include "EverParseEndianness.h" 2 + #define EVERPARSE_SUCCESS 0ul 3 + #define EVERPARSE_ERROR_GENERIC 1uL 4 + #define EVERPARSE_ERROR_NOT_ENOUGH_DATA 2uL 5 + #define EVERPARSE_ERROR_IMPOSSIBLE 3uL 6 + #define EVERPARSE_ERROR_LIST_SIZE_NOT_MULTIPLE 4uL 7 + #define EVERPARSE_ERROR_ACTION_FAILED 5uL 8 + #define EVERPARSE_ERROR_CONSTRAINT_FAILED 6uL 9 + #define EVERPARSE_ERROR_UNEXPECTED_PADDING 7uL 10 + // Probe wrapper error codes 11 + #define EVERPARSE_PROBE_FAILURE_INCORRECT_SIZE 256uL 12 + #define EVERPARSE_PROBE_FAILURE_INIT 257uL 13 + #define EVERPARSE_PROBE_FAILURE_PROBE 258uL 14 + #define EVERPARSE_PROBE_FAILURE_VALIDATION 259uL 15 + 16 + 17 + #include "SquashfsExtFileBody_ExternalTypedefs.h" 18 + 19 + 20 + #ifdef __cplusplus 21 + extern "C" { 22 + #endif 23 + BOOLEAN SquashfsExtFileBodyCheckSquashfsExtFileBody(WIRECTX* ctx, uint8_t *base, uint32_t len); 24 + #ifdef __cplusplus 25 + } 26 + #endif
+22
c/SquashfsExtFileBody_ExternalAPI.h
··· 1 + 2 + 3 + #ifndef SquashfsExtFileBody_ExternalAPI_H 4 + #define SquashfsExtFileBody_ExternalAPI_H 5 + 6 + #if defined(__cplusplus) 7 + extern "C" { 8 + #endif 9 + 10 + #include "EverParse.h" 11 + #include "SquashfsExtFileBody_ExternalTypedefs.h" 12 + 13 + extern void SquashfsExtFileBodySetU64(WIRECTX *ctx, uint32_t idx, uint64_t v); 14 + 15 + extern void SquashfsExtFileBodySetU32(WIRECTX *ctx, uint32_t idx, uint32_t v); 16 + 17 + #if defined(__cplusplus) 18 + } 19 + #endif 20 + 21 + #define SquashfsExtFileBody_ExternalAPI_H_DEFINED 22 + #endif /* SquashfsExtFileBody_ExternalAPI_H */
+4
c/SquashfsExtFileBody_ExternalTypedefs.h
··· 1 + #ifndef WIRECTX_DEFINED 2 + #define WIRECTX_DEFINED 3 + typedef struct SquashfsExtFileBodyFields WIRECTX; 4 + #endif
+26
c/SquashfsExtFileBody_Fields.c
··· 1 + #include <stdint.h> 2 + #include "SquashfsExtFileBody_Fields.h" 3 + #include "SquashfsExtFileBody_ExternalTypedefs.h" 4 + #include "SquashfsExtFileBody_ExternalAPI.h" 5 + 6 + void SquashfsExtFileBodySetU64(WIRECTX *ctx, uint32_t idx, uint64_t v) { 7 + SquashfsExtFileBodyFields *f = (SquashfsExtFileBodyFields *) ctx; 8 + switch (idx) { 9 + case 0: f->start_block = (uint64_t) v; break; 10 + case 1: f->file_size = (uint64_t) v; break; 11 + case 2: f->sparse = (uint64_t) v; break; 12 + default: (void) f; (void) v; break; 13 + } 14 + } 15 + 16 + void SquashfsExtFileBodySetU32(WIRECTX *ctx, uint32_t idx, uint32_t v) { 17 + SquashfsExtFileBodyFields *f = (SquashfsExtFileBodyFields *) ctx; 18 + switch (idx) { 19 + case 3: f->nlink = (uint32_t) v; break; 20 + case 4: f->fragment = (uint32_t) v; break; 21 + case 5: f->offset = (uint32_t) v; break; 22 + case 6: f->xattr_id = (uint32_t) v; break; 23 + default: (void) f; (void) v; break; 24 + } 25 + } 26 +
+26
c/SquashfsExtFileBody_Fields.h
··· 1 + #ifndef SQUASHFSEXTFILEBODY_FIELDS_H 2 + #define SQUASHFSEXTFILEBODY_FIELDS_H 3 + #include <stdint.h> 4 + 5 + /* Field indices -- use with the schema's WireSet* callbacks in a 6 + custom [WIRECTX] if you only want to capture a subset. */ 7 + #define SQUASHFSEXTFILEBODY_IDX_START_BLOCK 0 8 + #define SQUASHFSEXTFILEBODY_IDX_FILE_SIZE 1 9 + #define SQUASHFSEXTFILEBODY_IDX_SPARSE 2 10 + #define SQUASHFSEXTFILEBODY_IDX_NLINK 3 11 + #define SQUASHFSEXTFILEBODY_IDX_FRAGMENT 4 12 + #define SQUASHFSEXTFILEBODY_IDX_OFFSET 5 13 + #define SQUASHFSEXTFILEBODY_IDX_XATTR_ID 6 14 + 15 + /* Default plug: one typed member per named field. Pass a pointer to 16 + [SquashfsExtFileBodyFields] as [WIRECTX *] when you want every field populated. */ 17 + typedef struct SquashfsExtFileBodyFields { 18 + uint64_t start_block; 19 + uint64_t file_size; 20 + uint64_t sparse; 21 + uint32_t nlink; 22 + uint32_t fragment; 23 + uint32_t offset; 24 + uint32_t xattr_id; 25 + } SquashfsExtFileBodyFields; 26 + #endif
+3 -3
c/SquashfsExtIpcBody.3d
··· 1 1 extern typedef struct _WireCtx WireCtx 2 2 3 - extern unit WireSetU32(mutable WireCtx *ctx, UINT32 idx, UINT32 v) 3 + extern unit SquashfsExtIpcBodySetU32(mutable WireCtx *ctx, UINT32 idx, UINT32 v) 4 4 5 5 entrypoint 6 6 typedef struct _SquashfsExtIpcBody(mutable WireCtx *ctx) 7 7 { 8 - UINT32 nlink {:on-success WireSetU32(ctx, (UINT32) 0, nlink); return true; }; 9 - UINT32 xattr_id {:on-success WireSetU32(ctx, (UINT32) 1, xattr_id); return true; }; 8 + UINT32 nlink {:on-success SquashfsExtIpcBodySetU32(ctx, (UINT32) 0, nlink); return true; }; 9 + UINT32 xattr_id {:on-success SquashfsExtIpcBodySetU32(ctx, (UINT32) 1, xattr_id); return true; }; 10 10 } SquashfsExtIpcBody; 11 11 12 12
+113
c/SquashfsExtIpcBody.c
··· 1 + 2 + 3 + #include "SquashfsExtIpcBody.h" 4 + 5 + #include "SquashfsExtIpcBody_ExternalAPI.h" 6 + 7 + uint64_t 8 + SquashfsExtIpcBodyValidateSquashfsExtIpcBody( 9 + WIRECTX *Ctx, 10 + uint8_t *Ctxt, 11 + void 12 + (*ErrorHandlerFn)( 13 + EVERPARSE_STRING x0, 14 + EVERPARSE_STRING x1, 15 + EVERPARSE_STRING x2, 16 + uint64_t x3, 17 + uint8_t *x4, 18 + uint8_t *x5, 19 + uint64_t x6 20 + ), 21 + uint8_t *Input, 22 + uint64_t InputLength, 23 + uint64_t StartPosition 24 + ) 25 + { 26 + /* Validating field nlink */ 27 + /* Checking that we have enough space for a UINT32, i.e., 4 bytes */ 28 + BOOLEAN hasBytes0 = 4ULL <= (InputLength - StartPosition); 29 + uint64_t positionAfternlink0; 30 + if (hasBytes0) 31 + { 32 + positionAfternlink0 = StartPosition + 4ULL; 33 + } 34 + else 35 + { 36 + positionAfternlink0 = 37 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 38 + StartPosition); 39 + } 40 + uint64_t positionAfterSquashfsExtIpcBody; 41 + if (EverParseIsError(positionAfternlink0)) 42 + { 43 + positionAfterSquashfsExtIpcBody = positionAfternlink0; 44 + } 45 + else 46 + { 47 + uint32_t nlink = Load32Le(Input + (uint32_t)StartPosition); 48 + SquashfsExtIpcBodySetU32(Ctx, (uint32_t)0U, nlink); 49 + BOOLEAN actionResult = TRUE; 50 + KRML_MAYBE_UNUSED_VAR(actionResult); 51 + positionAfterSquashfsExtIpcBody = positionAfternlink0; 52 + } 53 + uint64_t positionAfternlink; 54 + if (EverParseIsSuccess(positionAfterSquashfsExtIpcBody)) 55 + { 56 + positionAfternlink = positionAfterSquashfsExtIpcBody; 57 + } 58 + else 59 + { 60 + ErrorHandlerFn("_SquashfsExtIpcBody", 61 + "nlink", 62 + EverParseErrorReasonOfResult(positionAfterSquashfsExtIpcBody), 63 + EverParseGetValidatorErrorKind(positionAfterSquashfsExtIpcBody), 64 + Ctxt, 65 + Input, 66 + StartPosition); 67 + positionAfternlink = positionAfterSquashfsExtIpcBody; 68 + } 69 + if (EverParseIsError(positionAfternlink)) 70 + { 71 + return positionAfternlink; 72 + } 73 + /* Validating field xattr_id */ 74 + /* Checking that we have enough space for a UINT32, i.e., 4 bytes */ 75 + BOOLEAN hasBytes = 4ULL <= (InputLength - positionAfternlink); 76 + uint64_t positionAfterxattrId; 77 + if (hasBytes) 78 + { 79 + positionAfterxattrId = positionAfternlink + 4ULL; 80 + } 81 + else 82 + { 83 + positionAfterxattrId = 84 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 85 + positionAfternlink); 86 + } 87 + uint64_t positionAfterSquashfsExtIpcBody0; 88 + if (EverParseIsError(positionAfterxattrId)) 89 + { 90 + positionAfterSquashfsExtIpcBody0 = positionAfterxattrId; 91 + } 92 + else 93 + { 94 + uint32_t xattrId = Load32Le(Input + (uint32_t)positionAfternlink); 95 + SquashfsExtIpcBodySetU32(Ctx, (uint32_t)1U, xattrId); 96 + BOOLEAN actionResult = TRUE; 97 + KRML_MAYBE_UNUSED_VAR(actionResult); 98 + positionAfterSquashfsExtIpcBody0 = positionAfterxattrId; 99 + } 100 + if (EverParseIsSuccess(positionAfterSquashfsExtIpcBody0)) 101 + { 102 + return positionAfterSquashfsExtIpcBody0; 103 + } 104 + ErrorHandlerFn("_SquashfsExtIpcBody", 105 + "xattr_id", 106 + EverParseErrorReasonOfResult(positionAfterSquashfsExtIpcBody0), 107 + EverParseGetValidatorErrorKind(positionAfterSquashfsExtIpcBody0), 108 + Ctxt, 109 + Input, 110 + positionAfternlink); 111 + return positionAfterSquashfsExtIpcBody0; 112 + } 113 +
+37
c/SquashfsExtIpcBody.h
··· 1 + 2 + 3 + #ifndef SquashfsExtIpcBody_H 4 + #define SquashfsExtIpcBody_H 5 + 6 + #if defined(__cplusplus) 7 + extern "C" { 8 + #endif 9 + 10 + #include "EverParse.h" 11 + #include "SquashfsExtIpcBody_ExternalTypedefs.h" 12 + 13 + uint64_t 14 + SquashfsExtIpcBodyValidateSquashfsExtIpcBody( 15 + WIRECTX *Ctx, 16 + uint8_t *Ctxt, 17 + void 18 + (*ErrorHandlerFn)( 19 + EVERPARSE_STRING x0, 20 + EVERPARSE_STRING x1, 21 + EVERPARSE_STRING x2, 22 + uint64_t x3, 23 + uint8_t *x4, 24 + uint8_t *x5, 25 + uint64_t x6 26 + ), 27 + uint8_t *Input, 28 + uint64_t InputLength, 29 + uint64_t StartPosition 30 + ); 31 + 32 + #if defined(__cplusplus) 33 + } 34 + #endif 35 + 36 + #define SquashfsExtIpcBody_H_DEFINED 37 + #endif /* SquashfsExtIpcBody_H */
+41
c/SquashfsExtIpcBodyWrapper.c
··· 1 + #include "SquashfsExtIpcBodyWrapper.h" 2 + #include "EverParse.h" 3 + #include "SquashfsExtIpcBody.h" 4 + void SquashfsExtIpcBodyEverParseError(const char *StructName, const char *FieldName, const char *Reason); 5 + 6 + static 7 + void DefaultErrorHandler( 8 + const char *typename_s, 9 + const char *fieldname, 10 + const char *reason, 11 + uint64_t error_code, 12 + uint8_t *context, 13 + EVERPARSE_INPUT_BUFFER input, 14 + uint64_t start_pos) 15 + { 16 + EVERPARSE_ERROR_FRAME *frame = (EVERPARSE_ERROR_FRAME*)context; 17 + EverParseDefaultErrorHandler( 18 + typename_s, 19 + fieldname, 20 + reason, 21 + error_code, 22 + frame, 23 + input, 24 + start_pos 25 + ); 26 + } 27 + 28 + BOOLEAN SquashfsExtIpcBodyCheckSquashfsExtIpcBody(WIRECTX* ctx, uint8_t *base, uint32_t len) { 29 + EVERPARSE_ERROR_FRAME frame; 30 + frame.filled = FALSE; 31 + uint64_t result = SquashfsExtIpcBodyValidateSquashfsExtIpcBody(ctx, (uint8_t*)&frame, &DefaultErrorHandler, base, len, 0); 32 + if (EverParseIsError(result)) 33 + { 34 + if (frame.filled) 35 + { 36 + SquashfsExtIpcBodyEverParseError(frame.typename_s, frame.fieldname, frame.reason); 37 + } 38 + return FALSE; 39 + } 40 + return TRUE; 41 + }
+26
c/SquashfsExtIpcBodyWrapper.h
··· 1 + #include "EverParseEndianness.h" 2 + #define EVERPARSE_SUCCESS 0ul 3 + #define EVERPARSE_ERROR_GENERIC 1uL 4 + #define EVERPARSE_ERROR_NOT_ENOUGH_DATA 2uL 5 + #define EVERPARSE_ERROR_IMPOSSIBLE 3uL 6 + #define EVERPARSE_ERROR_LIST_SIZE_NOT_MULTIPLE 4uL 7 + #define EVERPARSE_ERROR_ACTION_FAILED 5uL 8 + #define EVERPARSE_ERROR_CONSTRAINT_FAILED 6uL 9 + #define EVERPARSE_ERROR_UNEXPECTED_PADDING 7uL 10 + // Probe wrapper error codes 11 + #define EVERPARSE_PROBE_FAILURE_INCORRECT_SIZE 256uL 12 + #define EVERPARSE_PROBE_FAILURE_INIT 257uL 13 + #define EVERPARSE_PROBE_FAILURE_PROBE 258uL 14 + #define EVERPARSE_PROBE_FAILURE_VALIDATION 259uL 15 + 16 + 17 + #include "SquashfsExtIpcBody_ExternalTypedefs.h" 18 + 19 + 20 + #ifdef __cplusplus 21 + extern "C" { 22 + #endif 23 + BOOLEAN SquashfsExtIpcBodyCheckSquashfsExtIpcBody(WIRECTX* ctx, uint8_t *base, uint32_t len); 24 + #ifdef __cplusplus 25 + } 26 + #endif
+20
c/SquashfsExtIpcBody_ExternalAPI.h
··· 1 + 2 + 3 + #ifndef SquashfsExtIpcBody_ExternalAPI_H 4 + #define SquashfsExtIpcBody_ExternalAPI_H 5 + 6 + #if defined(__cplusplus) 7 + extern "C" { 8 + #endif 9 + 10 + #include "EverParse.h" 11 + #include "SquashfsExtIpcBody_ExternalTypedefs.h" 12 + 13 + extern void SquashfsExtIpcBodySetU32(WIRECTX *ctx, uint32_t idx, uint32_t v); 14 + 15 + #if defined(__cplusplus) 16 + } 17 + #endif 18 + 19 + #define SquashfsExtIpcBody_ExternalAPI_H_DEFINED 20 + #endif /* SquashfsExtIpcBody_ExternalAPI_H */
+4
c/SquashfsExtIpcBody_ExternalTypedefs.h
··· 1 + #ifndef WIRECTX_DEFINED 2 + #define WIRECTX_DEFINED 3 + typedef struct SquashfsExtIpcBodyFields WIRECTX; 4 + #endif
+14
c/SquashfsExtIpcBody_Fields.c
··· 1 + #include <stdint.h> 2 + #include "SquashfsExtIpcBody_Fields.h" 3 + #include "SquashfsExtIpcBody_ExternalTypedefs.h" 4 + #include "SquashfsExtIpcBody_ExternalAPI.h" 5 + 6 + void SquashfsExtIpcBodySetU32(WIRECTX *ctx, uint32_t idx, uint32_t v) { 7 + SquashfsExtIpcBodyFields *f = (SquashfsExtIpcBodyFields *) ctx; 8 + switch (idx) { 9 + case 0: f->nlink = (uint32_t) v; break; 10 + case 1: f->xattr_id = (uint32_t) v; break; 11 + default: (void) f; (void) v; break; 12 + } 13 + } 14 +
+16
c/SquashfsExtIpcBody_Fields.h
··· 1 + #ifndef SQUASHFSEXTIPCBODY_FIELDS_H 2 + #define SQUASHFSEXTIPCBODY_FIELDS_H 3 + #include <stdint.h> 4 + 5 + /* Field indices -- use with the schema's WireSet* callbacks in a 6 + custom [WIRECTX] if you only want to capture a subset. */ 7 + #define SQUASHFSEXTIPCBODY_IDX_NLINK 0 8 + #define SQUASHFSEXTIPCBODY_IDX_XATTR_ID 1 9 + 10 + /* Default plug: one typed member per named field. Pass a pointer to 11 + [SquashfsExtIpcBodyFields] as [WIRECTX *] when you want every field populated. */ 12 + typedef struct SquashfsExtIpcBodyFields { 13 + uint32_t nlink; 14 + uint32_t xattr_id; 15 + } SquashfsExtIpcBodyFields; 16 + #endif
+22 -22
c/SquashfsSuperblock.3d
··· 1 1 extern typedef struct _WireCtx WireCtx 2 2 3 - extern unit WireSetU32(mutable WireCtx *ctx, UINT32 idx, UINT32 v) 3 + extern unit SquashfsSuperblockSetU32(mutable WireCtx *ctx, UINT32 idx, UINT32 v) 4 4 5 - extern unit WireSetU16(mutable WireCtx *ctx, UINT32 idx, UINT16 v) 5 + extern unit SquashfsSuperblockSetU16(mutable WireCtx *ctx, UINT32 idx, UINT16 v) 6 6 7 - extern unit WireSetU64(mutable WireCtx *ctx, UINT32 idx, UINT64 v) 7 + extern unit SquashfsSuperblockSetU64(mutable WireCtx *ctx, UINT32 idx, UINT64 v) 8 8 9 9 entrypoint 10 10 typedef struct _SquashfsSuperblock(mutable WireCtx *ctx) 11 11 { 12 - UINT32 magic {:on-success WireSetU32(ctx, (UINT32) 0, magic); return true; }; 13 - UINT32 inode_count {:on-success WireSetU32(ctx, (UINT32) 1, inode_count); return true; }; 14 - UINT32 modification_time {:on-success WireSetU32(ctx, (UINT32) 2, modification_time); return true; }; 15 - UINT32 block_size {:on-success WireSetU32(ctx, (UINT32) 3, block_size); return true; }; 16 - UINT32 fragment_entry_count {:on-success WireSetU32(ctx, (UINT32) 4, fragment_entry_count); return true; }; 17 - UINT16 compression_id {:on-success WireSetU16(ctx, (UINT32) 5, compression_id); return true; }; 18 - UINT16 block_log {:on-success WireSetU16(ctx, (UINT32) 6, block_log); return true; }; 19 - UINT16 flags {:on-success WireSetU16(ctx, (UINT32) 7, flags); return true; }; 20 - UINT16 id_count {:on-success WireSetU16(ctx, (UINT32) 8, id_count); return true; }; 21 - UINT16 version_major {:on-success WireSetU16(ctx, (UINT32) 9, version_major); return true; }; 22 - UINT16 version_minor {:on-success WireSetU16(ctx, (UINT32) 10, version_minor); return true; }; 23 - UINT64 root_inode_ref {:on-success WireSetU64(ctx, (UINT32) 11, root_inode_ref); return true; }; 24 - UINT64 bytes_used {:on-success WireSetU64(ctx, (UINT32) 12, bytes_used); return true; }; 25 - UINT64 id_table_start {:on-success WireSetU64(ctx, (UINT32) 13, id_table_start); return true; }; 26 - UINT64 xattr_table_start {:on-success WireSetU64(ctx, (UINT32) 14, xattr_table_start); return true; }; 27 - UINT64 inode_table_start {:on-success WireSetU64(ctx, (UINT32) 15, inode_table_start); return true; }; 28 - UINT64 directory_table_start {:on-success WireSetU64(ctx, (UINT32) 16, directory_table_start); return true; }; 29 - UINT64 fragment_table_start {:on-success WireSetU64(ctx, (UINT32) 17, fragment_table_start); return true; }; 30 - UINT64 export_table_start {:on-success WireSetU64(ctx, (UINT32) 18, export_table_start); return true; }; 12 + UINT32 magic {:on-success SquashfsSuperblockSetU32(ctx, (UINT32) 0, magic); return true; }; 13 + UINT32 inode_count {:on-success SquashfsSuperblockSetU32(ctx, (UINT32) 1, inode_count); return true; }; 14 + UINT32 modification_time {:on-success SquashfsSuperblockSetU32(ctx, (UINT32) 2, modification_time); return true; }; 15 + UINT32 block_size {:on-success SquashfsSuperblockSetU32(ctx, (UINT32) 3, block_size); return true; }; 16 + UINT32 fragment_entry_count {:on-success SquashfsSuperblockSetU32(ctx, (UINT32) 4, fragment_entry_count); return true; }; 17 + UINT16 compression_id {:on-success SquashfsSuperblockSetU16(ctx, (UINT32) 5, compression_id); return true; }; 18 + UINT16 block_log {:on-success SquashfsSuperblockSetU16(ctx, (UINT32) 6, block_log); return true; }; 19 + UINT16 flags {:on-success SquashfsSuperblockSetU16(ctx, (UINT32) 7, flags); return true; }; 20 + UINT16 id_count {:on-success SquashfsSuperblockSetU16(ctx, (UINT32) 8, id_count); return true; }; 21 + UINT16 version_major {:on-success SquashfsSuperblockSetU16(ctx, (UINT32) 9, version_major); return true; }; 22 + UINT16 version_minor {:on-success SquashfsSuperblockSetU16(ctx, (UINT32) 10, version_minor); return true; }; 23 + UINT64 root_inode_ref {:on-success SquashfsSuperblockSetU64(ctx, (UINT32) 11, root_inode_ref); return true; }; 24 + UINT64 bytes_used {:on-success SquashfsSuperblockSetU64(ctx, (UINT32) 12, bytes_used); return true; }; 25 + UINT64 id_table_start {:on-success SquashfsSuperblockSetU64(ctx, (UINT32) 13, id_table_start); return true; }; 26 + UINT64 xattr_table_start {:on-success SquashfsSuperblockSetU64(ctx, (UINT32) 14, xattr_table_start); return true; }; 27 + UINT64 inode_table_start {:on-success SquashfsSuperblockSetU64(ctx, (UINT32) 15, inode_table_start); return true; }; 28 + UINT64 directory_table_start {:on-success SquashfsSuperblockSetU64(ctx, (UINT32) 16, directory_table_start); return true; }; 29 + UINT64 fragment_table_start {:on-success SquashfsSuperblockSetU64(ctx, (UINT32) 17, fragment_table_start); return true; }; 30 + UINT64 export_table_start {:on-success SquashfsSuperblockSetU64(ctx, (UINT32) 18, export_table_start); return true; }; 31 31 } SquashfsSuperblock; 32 32 33 33
+918
c/SquashfsSuperblock.c
··· 1 + 2 + 3 + #include "SquashfsSuperblock.h" 4 + 5 + #include "SquashfsSuperblock_ExternalAPI.h" 6 + 7 + uint64_t 8 + SquashfsSuperblockValidateSquashfsSuperblock( 9 + WIRECTX *Ctx, 10 + uint8_t *Ctxt, 11 + void 12 + (*ErrorHandlerFn)( 13 + EVERPARSE_STRING x0, 14 + EVERPARSE_STRING x1, 15 + EVERPARSE_STRING x2, 16 + uint64_t x3, 17 + uint8_t *x4, 18 + uint8_t *x5, 19 + uint64_t x6 20 + ), 21 + uint8_t *Input, 22 + uint64_t InputLength, 23 + uint64_t StartPosition 24 + ) 25 + { 26 + /* Validating field magic */ 27 + /* Checking that we have enough space for a UINT32, i.e., 4 bytes */ 28 + BOOLEAN hasBytes0 = 4ULL <= (InputLength - StartPosition); 29 + uint64_t positionAftermagic0; 30 + if (hasBytes0) 31 + { 32 + positionAftermagic0 = StartPosition + 4ULL; 33 + } 34 + else 35 + { 36 + positionAftermagic0 = 37 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 38 + StartPosition); 39 + } 40 + uint64_t positionAfterSquashfsSuperblock; 41 + if (EverParseIsError(positionAftermagic0)) 42 + { 43 + positionAfterSquashfsSuperblock = positionAftermagic0; 44 + } 45 + else 46 + { 47 + uint32_t magic = Load32Le(Input + (uint32_t)StartPosition); 48 + SquashfsSuperblockSetU32(Ctx, (uint32_t)0U, magic); 49 + BOOLEAN actionResult = TRUE; 50 + KRML_MAYBE_UNUSED_VAR(actionResult); 51 + positionAfterSquashfsSuperblock = positionAftermagic0; 52 + } 53 + uint64_t positionAftermagic; 54 + if (EverParseIsSuccess(positionAfterSquashfsSuperblock)) 55 + { 56 + positionAftermagic = positionAfterSquashfsSuperblock; 57 + } 58 + else 59 + { 60 + ErrorHandlerFn("_SquashfsSuperblock", 61 + "magic", 62 + EverParseErrorReasonOfResult(positionAfterSquashfsSuperblock), 63 + EverParseGetValidatorErrorKind(positionAfterSquashfsSuperblock), 64 + Ctxt, 65 + Input, 66 + StartPosition); 67 + positionAftermagic = positionAfterSquashfsSuperblock; 68 + } 69 + if (EverParseIsError(positionAftermagic)) 70 + { 71 + return positionAftermagic; 72 + } 73 + /* Validating field inode_count */ 74 + /* Checking that we have enough space for a UINT32, i.e., 4 bytes */ 75 + BOOLEAN hasBytes1 = 4ULL <= (InputLength - positionAftermagic); 76 + uint64_t positionAfterinodeCount; 77 + if (hasBytes1) 78 + { 79 + positionAfterinodeCount = positionAftermagic + 4ULL; 80 + } 81 + else 82 + { 83 + positionAfterinodeCount = 84 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 85 + positionAftermagic); 86 + } 87 + uint64_t positionAfterSquashfsSuperblock0; 88 + if (EverParseIsError(positionAfterinodeCount)) 89 + { 90 + positionAfterSquashfsSuperblock0 = positionAfterinodeCount; 91 + } 92 + else 93 + { 94 + uint32_t inodeCount = Load32Le(Input + (uint32_t)positionAftermagic); 95 + SquashfsSuperblockSetU32(Ctx, (uint32_t)1U, inodeCount); 96 + BOOLEAN actionResult = TRUE; 97 + KRML_MAYBE_UNUSED_VAR(actionResult); 98 + positionAfterSquashfsSuperblock0 = positionAfterinodeCount; 99 + } 100 + uint64_t positionAfterinodeCount0; 101 + if (EverParseIsSuccess(positionAfterSquashfsSuperblock0)) 102 + { 103 + positionAfterinodeCount0 = positionAfterSquashfsSuperblock0; 104 + } 105 + else 106 + { 107 + ErrorHandlerFn("_SquashfsSuperblock", 108 + "inode_count", 109 + EverParseErrorReasonOfResult(positionAfterSquashfsSuperblock0), 110 + EverParseGetValidatorErrorKind(positionAfterSquashfsSuperblock0), 111 + Ctxt, 112 + Input, 113 + positionAftermagic); 114 + positionAfterinodeCount0 = positionAfterSquashfsSuperblock0; 115 + } 116 + if (EverParseIsError(positionAfterinodeCount0)) 117 + { 118 + return positionAfterinodeCount0; 119 + } 120 + /* Validating field modification_time */ 121 + /* Checking that we have enough space for a UINT32, i.e., 4 bytes */ 122 + BOOLEAN hasBytes2 = 4ULL <= (InputLength - positionAfterinodeCount0); 123 + uint64_t positionAftermodificationTime; 124 + if (hasBytes2) 125 + { 126 + positionAftermodificationTime = positionAfterinodeCount0 + 4ULL; 127 + } 128 + else 129 + { 130 + positionAftermodificationTime = 131 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 132 + positionAfterinodeCount0); 133 + } 134 + uint64_t positionAfterSquashfsSuperblock1; 135 + if (EverParseIsError(positionAftermodificationTime)) 136 + { 137 + positionAfterSquashfsSuperblock1 = positionAftermodificationTime; 138 + } 139 + else 140 + { 141 + uint32_t modificationTime = Load32Le(Input + (uint32_t)positionAfterinodeCount0); 142 + SquashfsSuperblockSetU32(Ctx, (uint32_t)2U, modificationTime); 143 + BOOLEAN actionResult = TRUE; 144 + KRML_MAYBE_UNUSED_VAR(actionResult); 145 + positionAfterSquashfsSuperblock1 = positionAftermodificationTime; 146 + } 147 + uint64_t positionAftermodificationTime0; 148 + if (EverParseIsSuccess(positionAfterSquashfsSuperblock1)) 149 + { 150 + positionAftermodificationTime0 = positionAfterSquashfsSuperblock1; 151 + } 152 + else 153 + { 154 + ErrorHandlerFn("_SquashfsSuperblock", 155 + "modification_time", 156 + EverParseErrorReasonOfResult(positionAfterSquashfsSuperblock1), 157 + EverParseGetValidatorErrorKind(positionAfterSquashfsSuperblock1), 158 + Ctxt, 159 + Input, 160 + positionAfterinodeCount0); 161 + positionAftermodificationTime0 = positionAfterSquashfsSuperblock1; 162 + } 163 + if (EverParseIsError(positionAftermodificationTime0)) 164 + { 165 + return positionAftermodificationTime0; 166 + } 167 + /* Validating field block_size */ 168 + /* Checking that we have enough space for a UINT32, i.e., 4 bytes */ 169 + BOOLEAN hasBytes3 = 4ULL <= (InputLength - positionAftermodificationTime0); 170 + uint64_t positionAfterblockSize; 171 + if (hasBytes3) 172 + { 173 + positionAfterblockSize = positionAftermodificationTime0 + 4ULL; 174 + } 175 + else 176 + { 177 + positionAfterblockSize = 178 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 179 + positionAftermodificationTime0); 180 + } 181 + uint64_t positionAfterSquashfsSuperblock2; 182 + if (EverParseIsError(positionAfterblockSize)) 183 + { 184 + positionAfterSquashfsSuperblock2 = positionAfterblockSize; 185 + } 186 + else 187 + { 188 + uint32_t blockSize = Load32Le(Input + (uint32_t)positionAftermodificationTime0); 189 + SquashfsSuperblockSetU32(Ctx, (uint32_t)3U, blockSize); 190 + BOOLEAN actionResult = TRUE; 191 + KRML_MAYBE_UNUSED_VAR(actionResult); 192 + positionAfterSquashfsSuperblock2 = positionAfterblockSize; 193 + } 194 + uint64_t positionAfterblockSize0; 195 + if (EverParseIsSuccess(positionAfterSquashfsSuperblock2)) 196 + { 197 + positionAfterblockSize0 = positionAfterSquashfsSuperblock2; 198 + } 199 + else 200 + { 201 + ErrorHandlerFn("_SquashfsSuperblock", 202 + "block_size", 203 + EverParseErrorReasonOfResult(positionAfterSquashfsSuperblock2), 204 + EverParseGetValidatorErrorKind(positionAfterSquashfsSuperblock2), 205 + Ctxt, 206 + Input, 207 + positionAftermodificationTime0); 208 + positionAfterblockSize0 = positionAfterSquashfsSuperblock2; 209 + } 210 + if (EverParseIsError(positionAfterblockSize0)) 211 + { 212 + return positionAfterblockSize0; 213 + } 214 + /* Validating field fragment_entry_count */ 215 + /* Checking that we have enough space for a UINT32, i.e., 4 bytes */ 216 + BOOLEAN hasBytes4 = 4ULL <= (InputLength - positionAfterblockSize0); 217 + uint64_t positionAfterfragmentEntryCount; 218 + if (hasBytes4) 219 + { 220 + positionAfterfragmentEntryCount = positionAfterblockSize0 + 4ULL; 221 + } 222 + else 223 + { 224 + positionAfterfragmentEntryCount = 225 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 226 + positionAfterblockSize0); 227 + } 228 + uint64_t positionAfterSquashfsSuperblock3; 229 + if (EverParseIsError(positionAfterfragmentEntryCount)) 230 + { 231 + positionAfterSquashfsSuperblock3 = positionAfterfragmentEntryCount; 232 + } 233 + else 234 + { 235 + uint32_t fragmentEntryCount = Load32Le(Input + (uint32_t)positionAfterblockSize0); 236 + SquashfsSuperblockSetU32(Ctx, (uint32_t)4U, fragmentEntryCount); 237 + BOOLEAN actionResult = TRUE; 238 + KRML_MAYBE_UNUSED_VAR(actionResult); 239 + positionAfterSquashfsSuperblock3 = positionAfterfragmentEntryCount; 240 + } 241 + uint64_t positionAfterfragmentEntryCount0; 242 + if (EverParseIsSuccess(positionAfterSquashfsSuperblock3)) 243 + { 244 + positionAfterfragmentEntryCount0 = positionAfterSquashfsSuperblock3; 245 + } 246 + else 247 + { 248 + ErrorHandlerFn("_SquashfsSuperblock", 249 + "fragment_entry_count", 250 + EverParseErrorReasonOfResult(positionAfterSquashfsSuperblock3), 251 + EverParseGetValidatorErrorKind(positionAfterSquashfsSuperblock3), 252 + Ctxt, 253 + Input, 254 + positionAfterblockSize0); 255 + positionAfterfragmentEntryCount0 = positionAfterSquashfsSuperblock3; 256 + } 257 + if (EverParseIsError(positionAfterfragmentEntryCount0)) 258 + { 259 + return positionAfterfragmentEntryCount0; 260 + } 261 + /* Validating field compression_id */ 262 + /* Checking that we have enough space for a UINT16, i.e., 2 bytes */ 263 + BOOLEAN hasBytes5 = 2ULL <= (InputLength - positionAfterfragmentEntryCount0); 264 + uint64_t positionAftercompressionId; 265 + if (hasBytes5) 266 + { 267 + positionAftercompressionId = positionAfterfragmentEntryCount0 + 2ULL; 268 + } 269 + else 270 + { 271 + positionAftercompressionId = 272 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 273 + positionAfterfragmentEntryCount0); 274 + } 275 + uint64_t positionAfterSquashfsSuperblock4; 276 + if (EverParseIsError(positionAftercompressionId)) 277 + { 278 + positionAfterSquashfsSuperblock4 = positionAftercompressionId; 279 + } 280 + else 281 + { 282 + uint16_t r = Load16Le(Input + (uint32_t)positionAfterfragmentEntryCount0); 283 + uint16_t compressionId = (uint16_t)(uint32_t)r; 284 + SquashfsSuperblockSetU16(Ctx, (uint32_t)5U, compressionId); 285 + BOOLEAN actionResult = TRUE; 286 + KRML_MAYBE_UNUSED_VAR(actionResult); 287 + positionAfterSquashfsSuperblock4 = positionAftercompressionId; 288 + } 289 + uint64_t positionAftercompressionId0; 290 + if (EverParseIsSuccess(positionAfterSquashfsSuperblock4)) 291 + { 292 + positionAftercompressionId0 = positionAfterSquashfsSuperblock4; 293 + } 294 + else 295 + { 296 + ErrorHandlerFn("_SquashfsSuperblock", 297 + "compression_id", 298 + EverParseErrorReasonOfResult(positionAfterSquashfsSuperblock4), 299 + EverParseGetValidatorErrorKind(positionAfterSquashfsSuperblock4), 300 + Ctxt, 301 + Input, 302 + positionAfterfragmentEntryCount0); 303 + positionAftercompressionId0 = positionAfterSquashfsSuperblock4; 304 + } 305 + if (EverParseIsError(positionAftercompressionId0)) 306 + { 307 + return positionAftercompressionId0; 308 + } 309 + /* Validating field block_log */ 310 + /* Checking that we have enough space for a UINT16, i.e., 2 bytes */ 311 + BOOLEAN hasBytes6 = 2ULL <= (InputLength - positionAftercompressionId0); 312 + uint64_t positionAfterblockLog; 313 + if (hasBytes6) 314 + { 315 + positionAfterblockLog = positionAftercompressionId0 + 2ULL; 316 + } 317 + else 318 + { 319 + positionAfterblockLog = 320 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 321 + positionAftercompressionId0); 322 + } 323 + uint64_t positionAfterSquashfsSuperblock5; 324 + if (EverParseIsError(positionAfterblockLog)) 325 + { 326 + positionAfterSquashfsSuperblock5 = positionAfterblockLog; 327 + } 328 + else 329 + { 330 + uint16_t r = Load16Le(Input + (uint32_t)positionAftercompressionId0); 331 + uint16_t blockLog = (uint16_t)(uint32_t)r; 332 + SquashfsSuperblockSetU16(Ctx, (uint32_t)6U, blockLog); 333 + BOOLEAN actionResult = TRUE; 334 + KRML_MAYBE_UNUSED_VAR(actionResult); 335 + positionAfterSquashfsSuperblock5 = positionAfterblockLog; 336 + } 337 + uint64_t positionAfterblockLog0; 338 + if (EverParseIsSuccess(positionAfterSquashfsSuperblock5)) 339 + { 340 + positionAfterblockLog0 = positionAfterSquashfsSuperblock5; 341 + } 342 + else 343 + { 344 + ErrorHandlerFn("_SquashfsSuperblock", 345 + "block_log", 346 + EverParseErrorReasonOfResult(positionAfterSquashfsSuperblock5), 347 + EverParseGetValidatorErrorKind(positionAfterSquashfsSuperblock5), 348 + Ctxt, 349 + Input, 350 + positionAftercompressionId0); 351 + positionAfterblockLog0 = positionAfterSquashfsSuperblock5; 352 + } 353 + if (EverParseIsError(positionAfterblockLog0)) 354 + { 355 + return positionAfterblockLog0; 356 + } 357 + /* Validating field flags */ 358 + /* Checking that we have enough space for a UINT16, i.e., 2 bytes */ 359 + BOOLEAN hasBytes7 = 2ULL <= (InputLength - positionAfterblockLog0); 360 + uint64_t positionAfterflags0; 361 + if (hasBytes7) 362 + { 363 + positionAfterflags0 = positionAfterblockLog0 + 2ULL; 364 + } 365 + else 366 + { 367 + positionAfterflags0 = 368 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 369 + positionAfterblockLog0); 370 + } 371 + uint64_t positionAfterSquashfsSuperblock6; 372 + if (EverParseIsError(positionAfterflags0)) 373 + { 374 + positionAfterSquashfsSuperblock6 = positionAfterflags0; 375 + } 376 + else 377 + { 378 + uint16_t r = Load16Le(Input + (uint32_t)positionAfterblockLog0); 379 + uint16_t flags = (uint16_t)(uint32_t)r; 380 + SquashfsSuperblockSetU16(Ctx, (uint32_t)7U, flags); 381 + BOOLEAN actionResult = TRUE; 382 + KRML_MAYBE_UNUSED_VAR(actionResult); 383 + positionAfterSquashfsSuperblock6 = positionAfterflags0; 384 + } 385 + uint64_t positionAfterflags; 386 + if (EverParseIsSuccess(positionAfterSquashfsSuperblock6)) 387 + { 388 + positionAfterflags = positionAfterSquashfsSuperblock6; 389 + } 390 + else 391 + { 392 + ErrorHandlerFn("_SquashfsSuperblock", 393 + "flags", 394 + EverParseErrorReasonOfResult(positionAfterSquashfsSuperblock6), 395 + EverParseGetValidatorErrorKind(positionAfterSquashfsSuperblock6), 396 + Ctxt, 397 + Input, 398 + positionAfterblockLog0); 399 + positionAfterflags = positionAfterSquashfsSuperblock6; 400 + } 401 + if (EverParseIsError(positionAfterflags)) 402 + { 403 + return positionAfterflags; 404 + } 405 + /* Validating field id_count */ 406 + /* Checking that we have enough space for a UINT16, i.e., 2 bytes */ 407 + BOOLEAN hasBytes8 = 2ULL <= (InputLength - positionAfterflags); 408 + uint64_t positionAfteridCount; 409 + if (hasBytes8) 410 + { 411 + positionAfteridCount = positionAfterflags + 2ULL; 412 + } 413 + else 414 + { 415 + positionAfteridCount = 416 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 417 + positionAfterflags); 418 + } 419 + uint64_t positionAfterSquashfsSuperblock7; 420 + if (EverParseIsError(positionAfteridCount)) 421 + { 422 + positionAfterSquashfsSuperblock7 = positionAfteridCount; 423 + } 424 + else 425 + { 426 + uint16_t r = Load16Le(Input + (uint32_t)positionAfterflags); 427 + uint16_t idCount = (uint16_t)(uint32_t)r; 428 + SquashfsSuperblockSetU16(Ctx, (uint32_t)8U, idCount); 429 + BOOLEAN actionResult = TRUE; 430 + KRML_MAYBE_UNUSED_VAR(actionResult); 431 + positionAfterSquashfsSuperblock7 = positionAfteridCount; 432 + } 433 + uint64_t positionAfteridCount0; 434 + if (EverParseIsSuccess(positionAfterSquashfsSuperblock7)) 435 + { 436 + positionAfteridCount0 = positionAfterSquashfsSuperblock7; 437 + } 438 + else 439 + { 440 + ErrorHandlerFn("_SquashfsSuperblock", 441 + "id_count", 442 + EverParseErrorReasonOfResult(positionAfterSquashfsSuperblock7), 443 + EverParseGetValidatorErrorKind(positionAfterSquashfsSuperblock7), 444 + Ctxt, 445 + Input, 446 + positionAfterflags); 447 + positionAfteridCount0 = positionAfterSquashfsSuperblock7; 448 + } 449 + if (EverParseIsError(positionAfteridCount0)) 450 + { 451 + return positionAfteridCount0; 452 + } 453 + /* Validating field version_major */ 454 + /* Checking that we have enough space for a UINT16, i.e., 2 bytes */ 455 + BOOLEAN hasBytes9 = 2ULL <= (InputLength - positionAfteridCount0); 456 + uint64_t positionAfterversionMajor; 457 + if (hasBytes9) 458 + { 459 + positionAfterversionMajor = positionAfteridCount0 + 2ULL; 460 + } 461 + else 462 + { 463 + positionAfterversionMajor = 464 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 465 + positionAfteridCount0); 466 + } 467 + uint64_t positionAfterSquashfsSuperblock8; 468 + if (EverParseIsError(positionAfterversionMajor)) 469 + { 470 + positionAfterSquashfsSuperblock8 = positionAfterversionMajor; 471 + } 472 + else 473 + { 474 + uint16_t r = Load16Le(Input + (uint32_t)positionAfteridCount0); 475 + uint16_t versionMajor = (uint16_t)(uint32_t)r; 476 + SquashfsSuperblockSetU16(Ctx, (uint32_t)9U, versionMajor); 477 + BOOLEAN actionResult = TRUE; 478 + KRML_MAYBE_UNUSED_VAR(actionResult); 479 + positionAfterSquashfsSuperblock8 = positionAfterversionMajor; 480 + } 481 + uint64_t positionAfterversionMajor0; 482 + if (EverParseIsSuccess(positionAfterSquashfsSuperblock8)) 483 + { 484 + positionAfterversionMajor0 = positionAfterSquashfsSuperblock8; 485 + } 486 + else 487 + { 488 + ErrorHandlerFn("_SquashfsSuperblock", 489 + "version_major", 490 + EverParseErrorReasonOfResult(positionAfterSquashfsSuperblock8), 491 + EverParseGetValidatorErrorKind(positionAfterSquashfsSuperblock8), 492 + Ctxt, 493 + Input, 494 + positionAfteridCount0); 495 + positionAfterversionMajor0 = positionAfterSquashfsSuperblock8; 496 + } 497 + if (EverParseIsError(positionAfterversionMajor0)) 498 + { 499 + return positionAfterversionMajor0; 500 + } 501 + /* Validating field version_minor */ 502 + /* Checking that we have enough space for a UINT16, i.e., 2 bytes */ 503 + BOOLEAN hasBytes10 = 2ULL <= (InputLength - positionAfterversionMajor0); 504 + uint64_t positionAfterversionMinor; 505 + if (hasBytes10) 506 + { 507 + positionAfterversionMinor = positionAfterversionMajor0 + 2ULL; 508 + } 509 + else 510 + { 511 + positionAfterversionMinor = 512 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 513 + positionAfterversionMajor0); 514 + } 515 + uint64_t positionAfterSquashfsSuperblock9; 516 + if (EverParseIsError(positionAfterversionMinor)) 517 + { 518 + positionAfterSquashfsSuperblock9 = positionAfterversionMinor; 519 + } 520 + else 521 + { 522 + uint16_t r = Load16Le(Input + (uint32_t)positionAfterversionMajor0); 523 + uint16_t versionMinor = (uint16_t)(uint32_t)r; 524 + SquashfsSuperblockSetU16(Ctx, (uint32_t)10U, versionMinor); 525 + BOOLEAN actionResult = TRUE; 526 + KRML_MAYBE_UNUSED_VAR(actionResult); 527 + positionAfterSquashfsSuperblock9 = positionAfterversionMinor; 528 + } 529 + uint64_t positionAfterversionMinor0; 530 + if (EverParseIsSuccess(positionAfterSquashfsSuperblock9)) 531 + { 532 + positionAfterversionMinor0 = positionAfterSquashfsSuperblock9; 533 + } 534 + else 535 + { 536 + ErrorHandlerFn("_SquashfsSuperblock", 537 + "version_minor", 538 + EverParseErrorReasonOfResult(positionAfterSquashfsSuperblock9), 539 + EverParseGetValidatorErrorKind(positionAfterSquashfsSuperblock9), 540 + Ctxt, 541 + Input, 542 + positionAfterversionMajor0); 543 + positionAfterversionMinor0 = positionAfterSquashfsSuperblock9; 544 + } 545 + if (EverParseIsError(positionAfterversionMinor0)) 546 + { 547 + return positionAfterversionMinor0; 548 + } 549 + /* Validating field root_inode_ref */ 550 + /* Checking that we have enough space for a UINT64, i.e., 8 bytes */ 551 + BOOLEAN hasBytes11 = 8ULL <= (InputLength - positionAfterversionMinor0); 552 + uint64_t positionAfterrootInodeRef; 553 + if (hasBytes11) 554 + { 555 + positionAfterrootInodeRef = positionAfterversionMinor0 + 8ULL; 556 + } 557 + else 558 + { 559 + positionAfterrootInodeRef = 560 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 561 + positionAfterversionMinor0); 562 + } 563 + uint64_t positionAfterSquashfsSuperblock10; 564 + if (EverParseIsError(positionAfterrootInodeRef)) 565 + { 566 + positionAfterSquashfsSuperblock10 = positionAfterrootInodeRef; 567 + } 568 + else 569 + { 570 + uint64_t rootInodeRef = Load64Le(Input + (uint32_t)positionAfterversionMinor0); 571 + SquashfsSuperblockSetU64(Ctx, (uint32_t)11U, rootInodeRef); 572 + BOOLEAN actionResult = TRUE; 573 + KRML_MAYBE_UNUSED_VAR(actionResult); 574 + positionAfterSquashfsSuperblock10 = positionAfterrootInodeRef; 575 + } 576 + uint64_t positionAfterrootInodeRef0; 577 + if (EverParseIsSuccess(positionAfterSquashfsSuperblock10)) 578 + { 579 + positionAfterrootInodeRef0 = positionAfterSquashfsSuperblock10; 580 + } 581 + else 582 + { 583 + ErrorHandlerFn("_SquashfsSuperblock", 584 + "root_inode_ref", 585 + EverParseErrorReasonOfResult(positionAfterSquashfsSuperblock10), 586 + EverParseGetValidatorErrorKind(positionAfterSquashfsSuperblock10), 587 + Ctxt, 588 + Input, 589 + positionAfterversionMinor0); 590 + positionAfterrootInodeRef0 = positionAfterSquashfsSuperblock10; 591 + } 592 + if (EverParseIsError(positionAfterrootInodeRef0)) 593 + { 594 + return positionAfterrootInodeRef0; 595 + } 596 + /* Validating field bytes_used */ 597 + /* Checking that we have enough space for a UINT64, i.e., 8 bytes */ 598 + BOOLEAN hasBytes12 = 8ULL <= (InputLength - positionAfterrootInodeRef0); 599 + uint64_t positionAfterbytesUsed; 600 + if (hasBytes12) 601 + { 602 + positionAfterbytesUsed = positionAfterrootInodeRef0 + 8ULL; 603 + } 604 + else 605 + { 606 + positionAfterbytesUsed = 607 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 608 + positionAfterrootInodeRef0); 609 + } 610 + uint64_t positionAfterSquashfsSuperblock11; 611 + if (EverParseIsError(positionAfterbytesUsed)) 612 + { 613 + positionAfterSquashfsSuperblock11 = positionAfterbytesUsed; 614 + } 615 + else 616 + { 617 + uint64_t bytesUsed = Load64Le(Input + (uint32_t)positionAfterrootInodeRef0); 618 + SquashfsSuperblockSetU64(Ctx, (uint32_t)12U, bytesUsed); 619 + BOOLEAN actionResult = TRUE; 620 + KRML_MAYBE_UNUSED_VAR(actionResult); 621 + positionAfterSquashfsSuperblock11 = positionAfterbytesUsed; 622 + } 623 + uint64_t positionAfterbytesUsed0; 624 + if (EverParseIsSuccess(positionAfterSquashfsSuperblock11)) 625 + { 626 + positionAfterbytesUsed0 = positionAfterSquashfsSuperblock11; 627 + } 628 + else 629 + { 630 + ErrorHandlerFn("_SquashfsSuperblock", 631 + "bytes_used", 632 + EverParseErrorReasonOfResult(positionAfterSquashfsSuperblock11), 633 + EverParseGetValidatorErrorKind(positionAfterSquashfsSuperblock11), 634 + Ctxt, 635 + Input, 636 + positionAfterrootInodeRef0); 637 + positionAfterbytesUsed0 = positionAfterSquashfsSuperblock11; 638 + } 639 + if (EverParseIsError(positionAfterbytesUsed0)) 640 + { 641 + return positionAfterbytesUsed0; 642 + } 643 + /* Validating field id_table_start */ 644 + /* Checking that we have enough space for a UINT64, i.e., 8 bytes */ 645 + BOOLEAN hasBytes13 = 8ULL <= (InputLength - positionAfterbytesUsed0); 646 + uint64_t positionAfteridTableStart; 647 + if (hasBytes13) 648 + { 649 + positionAfteridTableStart = positionAfterbytesUsed0 + 8ULL; 650 + } 651 + else 652 + { 653 + positionAfteridTableStart = 654 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 655 + positionAfterbytesUsed0); 656 + } 657 + uint64_t positionAfterSquashfsSuperblock12; 658 + if (EverParseIsError(positionAfteridTableStart)) 659 + { 660 + positionAfterSquashfsSuperblock12 = positionAfteridTableStart; 661 + } 662 + else 663 + { 664 + uint64_t idTableStart = Load64Le(Input + (uint32_t)positionAfterbytesUsed0); 665 + SquashfsSuperblockSetU64(Ctx, (uint32_t)13U, idTableStart); 666 + BOOLEAN actionResult = TRUE; 667 + KRML_MAYBE_UNUSED_VAR(actionResult); 668 + positionAfterSquashfsSuperblock12 = positionAfteridTableStart; 669 + } 670 + uint64_t positionAfteridTableStart0; 671 + if (EverParseIsSuccess(positionAfterSquashfsSuperblock12)) 672 + { 673 + positionAfteridTableStart0 = positionAfterSquashfsSuperblock12; 674 + } 675 + else 676 + { 677 + ErrorHandlerFn("_SquashfsSuperblock", 678 + "id_table_start", 679 + EverParseErrorReasonOfResult(positionAfterSquashfsSuperblock12), 680 + EverParseGetValidatorErrorKind(positionAfterSquashfsSuperblock12), 681 + Ctxt, 682 + Input, 683 + positionAfterbytesUsed0); 684 + positionAfteridTableStart0 = positionAfterSquashfsSuperblock12; 685 + } 686 + if (EverParseIsError(positionAfteridTableStart0)) 687 + { 688 + return positionAfteridTableStart0; 689 + } 690 + /* Validating field xattr_table_start */ 691 + /* Checking that we have enough space for a UINT64, i.e., 8 bytes */ 692 + BOOLEAN hasBytes14 = 8ULL <= (InputLength - positionAfteridTableStart0); 693 + uint64_t positionAfterxattrTableStart; 694 + if (hasBytes14) 695 + { 696 + positionAfterxattrTableStart = positionAfteridTableStart0 + 8ULL; 697 + } 698 + else 699 + { 700 + positionAfterxattrTableStart = 701 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 702 + positionAfteridTableStart0); 703 + } 704 + uint64_t positionAfterSquashfsSuperblock13; 705 + if (EverParseIsError(positionAfterxattrTableStart)) 706 + { 707 + positionAfterSquashfsSuperblock13 = positionAfterxattrTableStart; 708 + } 709 + else 710 + { 711 + uint64_t xattrTableStart = Load64Le(Input + (uint32_t)positionAfteridTableStart0); 712 + SquashfsSuperblockSetU64(Ctx, (uint32_t)14U, xattrTableStart); 713 + BOOLEAN actionResult = TRUE; 714 + KRML_MAYBE_UNUSED_VAR(actionResult); 715 + positionAfterSquashfsSuperblock13 = positionAfterxattrTableStart; 716 + } 717 + uint64_t positionAfterxattrTableStart0; 718 + if (EverParseIsSuccess(positionAfterSquashfsSuperblock13)) 719 + { 720 + positionAfterxattrTableStart0 = positionAfterSquashfsSuperblock13; 721 + } 722 + else 723 + { 724 + ErrorHandlerFn("_SquashfsSuperblock", 725 + "xattr_table_start", 726 + EverParseErrorReasonOfResult(positionAfterSquashfsSuperblock13), 727 + EverParseGetValidatorErrorKind(positionAfterSquashfsSuperblock13), 728 + Ctxt, 729 + Input, 730 + positionAfteridTableStart0); 731 + positionAfterxattrTableStart0 = positionAfterSquashfsSuperblock13; 732 + } 733 + if (EverParseIsError(positionAfterxattrTableStart0)) 734 + { 735 + return positionAfterxattrTableStart0; 736 + } 737 + /* Validating field inode_table_start */ 738 + /* Checking that we have enough space for a UINT64, i.e., 8 bytes */ 739 + BOOLEAN hasBytes15 = 8ULL <= (InputLength - positionAfterxattrTableStart0); 740 + uint64_t positionAfterinodeTableStart; 741 + if (hasBytes15) 742 + { 743 + positionAfterinodeTableStart = positionAfterxattrTableStart0 + 8ULL; 744 + } 745 + else 746 + { 747 + positionAfterinodeTableStart = 748 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 749 + positionAfterxattrTableStart0); 750 + } 751 + uint64_t positionAfterSquashfsSuperblock14; 752 + if (EverParseIsError(positionAfterinodeTableStart)) 753 + { 754 + positionAfterSquashfsSuperblock14 = positionAfterinodeTableStart; 755 + } 756 + else 757 + { 758 + uint64_t inodeTableStart = Load64Le(Input + (uint32_t)positionAfterxattrTableStart0); 759 + SquashfsSuperblockSetU64(Ctx, (uint32_t)15U, inodeTableStart); 760 + BOOLEAN actionResult = TRUE; 761 + KRML_MAYBE_UNUSED_VAR(actionResult); 762 + positionAfterSquashfsSuperblock14 = positionAfterinodeTableStart; 763 + } 764 + uint64_t positionAfterinodeTableStart0; 765 + if (EverParseIsSuccess(positionAfterSquashfsSuperblock14)) 766 + { 767 + positionAfterinodeTableStart0 = positionAfterSquashfsSuperblock14; 768 + } 769 + else 770 + { 771 + ErrorHandlerFn("_SquashfsSuperblock", 772 + "inode_table_start", 773 + EverParseErrorReasonOfResult(positionAfterSquashfsSuperblock14), 774 + EverParseGetValidatorErrorKind(positionAfterSquashfsSuperblock14), 775 + Ctxt, 776 + Input, 777 + positionAfterxattrTableStart0); 778 + positionAfterinodeTableStart0 = positionAfterSquashfsSuperblock14; 779 + } 780 + if (EverParseIsError(positionAfterinodeTableStart0)) 781 + { 782 + return positionAfterinodeTableStart0; 783 + } 784 + /* Validating field directory_table_start */ 785 + /* Checking that we have enough space for a UINT64, i.e., 8 bytes */ 786 + BOOLEAN hasBytes16 = 8ULL <= (InputLength - positionAfterinodeTableStart0); 787 + uint64_t positionAfterdirectoryTableStart; 788 + if (hasBytes16) 789 + { 790 + positionAfterdirectoryTableStart = positionAfterinodeTableStart0 + 8ULL; 791 + } 792 + else 793 + { 794 + positionAfterdirectoryTableStart = 795 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 796 + positionAfterinodeTableStart0); 797 + } 798 + uint64_t positionAfterSquashfsSuperblock15; 799 + if (EverParseIsError(positionAfterdirectoryTableStart)) 800 + { 801 + positionAfterSquashfsSuperblock15 = positionAfterdirectoryTableStart; 802 + } 803 + else 804 + { 805 + uint64_t directoryTableStart = Load64Le(Input + (uint32_t)positionAfterinodeTableStart0); 806 + SquashfsSuperblockSetU64(Ctx, (uint32_t)16U, directoryTableStart); 807 + BOOLEAN actionResult = TRUE; 808 + KRML_MAYBE_UNUSED_VAR(actionResult); 809 + positionAfterSquashfsSuperblock15 = positionAfterdirectoryTableStart; 810 + } 811 + uint64_t positionAfterdirectoryTableStart0; 812 + if (EverParseIsSuccess(positionAfterSquashfsSuperblock15)) 813 + { 814 + positionAfterdirectoryTableStart0 = positionAfterSquashfsSuperblock15; 815 + } 816 + else 817 + { 818 + ErrorHandlerFn("_SquashfsSuperblock", 819 + "directory_table_start", 820 + EverParseErrorReasonOfResult(positionAfterSquashfsSuperblock15), 821 + EverParseGetValidatorErrorKind(positionAfterSquashfsSuperblock15), 822 + Ctxt, 823 + Input, 824 + positionAfterinodeTableStart0); 825 + positionAfterdirectoryTableStart0 = positionAfterSquashfsSuperblock15; 826 + } 827 + if (EverParseIsError(positionAfterdirectoryTableStart0)) 828 + { 829 + return positionAfterdirectoryTableStart0; 830 + } 831 + /* Validating field fragment_table_start */ 832 + /* Checking that we have enough space for a UINT64, i.e., 8 bytes */ 833 + BOOLEAN hasBytes17 = 8ULL <= (InputLength - positionAfterdirectoryTableStart0); 834 + uint64_t positionAfterfragmentTableStart; 835 + if (hasBytes17) 836 + { 837 + positionAfterfragmentTableStart = positionAfterdirectoryTableStart0 + 8ULL; 838 + } 839 + else 840 + { 841 + positionAfterfragmentTableStart = 842 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 843 + positionAfterdirectoryTableStart0); 844 + } 845 + uint64_t positionAfterSquashfsSuperblock16; 846 + if (EverParseIsError(positionAfterfragmentTableStart)) 847 + { 848 + positionAfterSquashfsSuperblock16 = positionAfterfragmentTableStart; 849 + } 850 + else 851 + { 852 + uint64_t fragmentTableStart = Load64Le(Input + (uint32_t)positionAfterdirectoryTableStart0); 853 + SquashfsSuperblockSetU64(Ctx, (uint32_t)17U, fragmentTableStart); 854 + BOOLEAN actionResult = TRUE; 855 + KRML_MAYBE_UNUSED_VAR(actionResult); 856 + positionAfterSquashfsSuperblock16 = positionAfterfragmentTableStart; 857 + } 858 + uint64_t positionAfterfragmentTableStart0; 859 + if (EverParseIsSuccess(positionAfterSquashfsSuperblock16)) 860 + { 861 + positionAfterfragmentTableStart0 = positionAfterSquashfsSuperblock16; 862 + } 863 + else 864 + { 865 + ErrorHandlerFn("_SquashfsSuperblock", 866 + "fragment_table_start", 867 + EverParseErrorReasonOfResult(positionAfterSquashfsSuperblock16), 868 + EverParseGetValidatorErrorKind(positionAfterSquashfsSuperblock16), 869 + Ctxt, 870 + Input, 871 + positionAfterdirectoryTableStart0); 872 + positionAfterfragmentTableStart0 = positionAfterSquashfsSuperblock16; 873 + } 874 + if (EverParseIsError(positionAfterfragmentTableStart0)) 875 + { 876 + return positionAfterfragmentTableStart0; 877 + } 878 + /* Validating field export_table_start */ 879 + /* Checking that we have enough space for a UINT64, i.e., 8 bytes */ 880 + BOOLEAN hasBytes = 8ULL <= (InputLength - positionAfterfragmentTableStart0); 881 + uint64_t positionAfterexportTableStart; 882 + if (hasBytes) 883 + { 884 + positionAfterexportTableStart = positionAfterfragmentTableStart0 + 8ULL; 885 + } 886 + else 887 + { 888 + positionAfterexportTableStart = 889 + EverParseSetValidatorErrorPos(EVERPARSE_VALIDATOR_ERROR_NOT_ENOUGH_DATA, 890 + positionAfterfragmentTableStart0); 891 + } 892 + uint64_t positionAfterSquashfsSuperblock17; 893 + if (EverParseIsError(positionAfterexportTableStart)) 894 + { 895 + positionAfterSquashfsSuperblock17 = positionAfterexportTableStart; 896 + } 897 + else 898 + { 899 + uint64_t exportTableStart = Load64Le(Input + (uint32_t)positionAfterfragmentTableStart0); 900 + SquashfsSuperblockSetU64(Ctx, (uint32_t)18U, exportTableStart); 901 + BOOLEAN actionResult = TRUE; 902 + KRML_MAYBE_UNUSED_VAR(actionResult); 903 + positionAfterSquashfsSuperblock17 = positionAfterexportTableStart; 904 + } 905 + if (EverParseIsSuccess(positionAfterSquashfsSuperblock17)) 906 + { 907 + return positionAfterSquashfsSuperblock17; 908 + } 909 + ErrorHandlerFn("_SquashfsSuperblock", 910 + "export_table_start", 911 + EverParseErrorReasonOfResult(positionAfterSquashfsSuperblock17), 912 + EverParseGetValidatorErrorKind(positionAfterSquashfsSuperblock17), 913 + Ctxt, 914 + Input, 915 + positionAfterfragmentTableStart0); 916 + return positionAfterSquashfsSuperblock17; 917 + } 918 +
+37
c/SquashfsSuperblock.h
··· 1 + 2 + 3 + #ifndef SquashfsSuperblock_H 4 + #define SquashfsSuperblock_H 5 + 6 + #if defined(__cplusplus) 7 + extern "C" { 8 + #endif 9 + 10 + #include "EverParse.h" 11 + #include "SquashfsSuperblock_ExternalTypedefs.h" 12 + 13 + uint64_t 14 + SquashfsSuperblockValidateSquashfsSuperblock( 15 + WIRECTX *Ctx, 16 + uint8_t *Ctxt, 17 + void 18 + (*ErrorHandlerFn)( 19 + EVERPARSE_STRING x0, 20 + EVERPARSE_STRING x1, 21 + EVERPARSE_STRING x2, 22 + uint64_t x3, 23 + uint8_t *x4, 24 + uint8_t *x5, 25 + uint64_t x6 26 + ), 27 + uint8_t *Input, 28 + uint64_t InputLength, 29 + uint64_t StartPosition 30 + ); 31 + 32 + #if defined(__cplusplus) 33 + } 34 + #endif 35 + 36 + #define SquashfsSuperblock_H_DEFINED 37 + #endif /* SquashfsSuperblock_H */
+41
c/SquashfsSuperblockWrapper.c
··· 1 + #include "SquashfsSuperblockWrapper.h" 2 + #include "EverParse.h" 3 + #include "SquashfsSuperblock.h" 4 + void SquashfsSuperblockEverParseError(const char *StructName, const char *FieldName, const char *Reason); 5 + 6 + static 7 + void DefaultErrorHandler( 8 + const char *typename_s, 9 + const char *fieldname, 10 + const char *reason, 11 + uint64_t error_code, 12 + uint8_t *context, 13 + EVERPARSE_INPUT_BUFFER input, 14 + uint64_t start_pos) 15 + { 16 + EVERPARSE_ERROR_FRAME *frame = (EVERPARSE_ERROR_FRAME*)context; 17 + EverParseDefaultErrorHandler( 18 + typename_s, 19 + fieldname, 20 + reason, 21 + error_code, 22 + frame, 23 + input, 24 + start_pos 25 + ); 26 + } 27 + 28 + BOOLEAN SquashfsSuperblockCheckSquashfsSuperblock(WIRECTX* ctx, uint8_t *base, uint32_t len) { 29 + EVERPARSE_ERROR_FRAME frame; 30 + frame.filled = FALSE; 31 + uint64_t result = SquashfsSuperblockValidateSquashfsSuperblock(ctx, (uint8_t*)&frame, &DefaultErrorHandler, base, len, 0); 32 + if (EverParseIsError(result)) 33 + { 34 + if (frame.filled) 35 + { 36 + SquashfsSuperblockEverParseError(frame.typename_s, frame.fieldname, frame.reason); 37 + } 38 + return FALSE; 39 + } 40 + return TRUE; 41 + }
+26
c/SquashfsSuperblockWrapper.h
··· 1 + #include "EverParseEndianness.h" 2 + #define EVERPARSE_SUCCESS 0ul 3 + #define EVERPARSE_ERROR_GENERIC 1uL 4 + #define EVERPARSE_ERROR_NOT_ENOUGH_DATA 2uL 5 + #define EVERPARSE_ERROR_IMPOSSIBLE 3uL 6 + #define EVERPARSE_ERROR_LIST_SIZE_NOT_MULTIPLE 4uL 7 + #define EVERPARSE_ERROR_ACTION_FAILED 5uL 8 + #define EVERPARSE_ERROR_CONSTRAINT_FAILED 6uL 9 + #define EVERPARSE_ERROR_UNEXPECTED_PADDING 7uL 10 + // Probe wrapper error codes 11 + #define EVERPARSE_PROBE_FAILURE_INCORRECT_SIZE 256uL 12 + #define EVERPARSE_PROBE_FAILURE_INIT 257uL 13 + #define EVERPARSE_PROBE_FAILURE_PROBE 258uL 14 + #define EVERPARSE_PROBE_FAILURE_VALIDATION 259uL 15 + 16 + 17 + #include "SquashfsSuperblock_ExternalTypedefs.h" 18 + 19 + 20 + #ifdef __cplusplus 21 + extern "C" { 22 + #endif 23 + BOOLEAN SquashfsSuperblockCheckSquashfsSuperblock(WIRECTX* ctx, uint8_t *base, uint32_t len); 24 + #ifdef __cplusplus 25 + } 26 + #endif
+24
c/SquashfsSuperblock_ExternalAPI.h
··· 1 + 2 + 3 + #ifndef SquashfsSuperblock_ExternalAPI_H 4 + #define SquashfsSuperblock_ExternalAPI_H 5 + 6 + #if defined(__cplusplus) 7 + extern "C" { 8 + #endif 9 + 10 + #include "EverParse.h" 11 + #include "SquashfsSuperblock_ExternalTypedefs.h" 12 + 13 + extern void SquashfsSuperblockSetU32(WIRECTX *ctx, uint32_t idx, uint32_t v); 14 + 15 + extern void SquashfsSuperblockSetU16(WIRECTX *ctx, uint32_t idx, uint16_t v); 16 + 17 + extern void SquashfsSuperblockSetU64(WIRECTX *ctx, uint32_t idx, uint64_t v); 18 + 19 + #if defined(__cplusplus) 20 + } 21 + #endif 22 + 23 + #define SquashfsSuperblock_ExternalAPI_H_DEFINED 24 + #endif /* SquashfsSuperblock_ExternalAPI_H */
+4
c/SquashfsSuperblock_ExternalTypedefs.h
··· 1 + #ifndef WIRECTX_DEFINED 2 + #define WIRECTX_DEFINED 3 + typedef struct SquashfsSuperblockFields WIRECTX; 4 + #endif
+45
c/SquashfsSuperblock_Fields.c
··· 1 + #include <stdint.h> 2 + #include "SquashfsSuperblock_Fields.h" 3 + #include "SquashfsSuperblock_ExternalTypedefs.h" 4 + #include "SquashfsSuperblock_ExternalAPI.h" 5 + 6 + void SquashfsSuperblockSetU32(WIRECTX *ctx, uint32_t idx, uint32_t v) { 7 + SquashfsSuperblockFields *f = (SquashfsSuperblockFields *) ctx; 8 + switch (idx) { 9 + case 0: f->magic = (uint32_t) v; break; 10 + case 1: f->inode_count = (uint32_t) v; break; 11 + case 2: f->modification_time = (uint32_t) v; break; 12 + case 3: f->block_size = (uint32_t) v; break; 13 + case 4: f->fragment_entry_count = (uint32_t) v; break; 14 + default: (void) f; (void) v; break; 15 + } 16 + } 17 + 18 + void SquashfsSuperblockSetU16(WIRECTX *ctx, uint32_t idx, uint16_t v) { 19 + SquashfsSuperblockFields *f = (SquashfsSuperblockFields *) ctx; 20 + switch (idx) { 21 + case 5: f->compression_id = (uint16_t) v; break; 22 + case 6: f->block_log = (uint16_t) v; break; 23 + case 7: f->flags = (uint16_t) v; break; 24 + case 8: f->id_count = (uint16_t) v; break; 25 + case 9: f->version_major = (uint16_t) v; break; 26 + case 10: f->version_minor = (uint16_t) v; break; 27 + default: (void) f; (void) v; break; 28 + } 29 + } 30 + 31 + void SquashfsSuperblockSetU64(WIRECTX *ctx, uint32_t idx, uint64_t v) { 32 + SquashfsSuperblockFields *f = (SquashfsSuperblockFields *) ctx; 33 + switch (idx) { 34 + case 11: f->root_inode_ref = (uint64_t) v; break; 35 + case 12: f->bytes_used = (uint64_t) v; break; 36 + case 13: f->id_table_start = (uint64_t) v; break; 37 + case 14: f->xattr_table_start = (uint64_t) v; break; 38 + case 15: f->inode_table_start = (uint64_t) v; break; 39 + case 16: f->directory_table_start = (uint64_t) v; break; 40 + case 17: f->fragment_table_start = (uint64_t) v; break; 41 + case 18: f->export_table_start = (uint64_t) v; break; 42 + default: (void) f; (void) v; break; 43 + } 44 + } 45 +
+50
c/SquashfsSuperblock_Fields.h
··· 1 + #ifndef SQUASHFSSUPERBLOCK_FIELDS_H 2 + #define SQUASHFSSUPERBLOCK_FIELDS_H 3 + #include <stdint.h> 4 + 5 + /* Field indices -- use with the schema's WireSet* callbacks in a 6 + custom [WIRECTX] if you only want to capture a subset. */ 7 + #define SQUASHFSSUPERBLOCK_IDX_MAGIC 0 8 + #define SQUASHFSSUPERBLOCK_IDX_INODE_COUNT 1 9 + #define SQUASHFSSUPERBLOCK_IDX_MODIFICATION_TIME 2 10 + #define SQUASHFSSUPERBLOCK_IDX_BLOCK_SIZE 3 11 + #define SQUASHFSSUPERBLOCK_IDX_FRAGMENT_ENTRY_COUNT 4 12 + #define SQUASHFSSUPERBLOCK_IDX_COMPRESSION_ID 5 13 + #define SQUASHFSSUPERBLOCK_IDX_BLOCK_LOG 6 14 + #define SQUASHFSSUPERBLOCK_IDX_FLAGS 7 15 + #define SQUASHFSSUPERBLOCK_IDX_ID_COUNT 8 16 + #define SQUASHFSSUPERBLOCK_IDX_VERSION_MAJOR 9 17 + #define SQUASHFSSUPERBLOCK_IDX_VERSION_MINOR 10 18 + #define SQUASHFSSUPERBLOCK_IDX_ROOT_INODE_REF 11 19 + #define SQUASHFSSUPERBLOCK_IDX_BYTES_USED 12 20 + #define SQUASHFSSUPERBLOCK_IDX_ID_TABLE_START 13 21 + #define SQUASHFSSUPERBLOCK_IDX_XATTR_TABLE_START 14 22 + #define SQUASHFSSUPERBLOCK_IDX_INODE_TABLE_START 15 23 + #define SQUASHFSSUPERBLOCK_IDX_DIRECTORY_TABLE_START 16 24 + #define SQUASHFSSUPERBLOCK_IDX_FRAGMENT_TABLE_START 17 25 + #define SQUASHFSSUPERBLOCK_IDX_EXPORT_TABLE_START 18 26 + 27 + /* Default plug: one typed member per named field. Pass a pointer to 28 + [SquashfsSuperblockFields] as [WIRECTX *] when you want every field populated. */ 29 + typedef struct SquashfsSuperblockFields { 30 + uint32_t magic; 31 + uint32_t inode_count; 32 + uint32_t modification_time; 33 + uint32_t block_size; 34 + uint32_t fragment_entry_count; 35 + uint16_t compression_id; 36 + uint16_t block_log; 37 + uint16_t flags; 38 + uint16_t id_count; 39 + uint16_t version_major; 40 + uint16_t version_minor; 41 + uint64_t root_inode_ref; 42 + uint64_t bytes_used; 43 + uint64_t id_table_start; 44 + uint64_t xattr_table_start; 45 + uint64_t inode_table_start; 46 + uint64_t directory_table_start; 47 + uint64_t fragment_table_start; 48 + uint64_t export_table_start; 49 + } SquashfsSuperblockFields; 50 + #endif
+33 -3
c/dune.inc
··· 9 9 (rule 10 10 (alias gen) 11 11 (mode fallback) 12 - (targets EverParse.h EverParseEndianness.h SquashfsSuperblock.h SquashfsSuperblock.c SquashfsExtDirBody.h SquashfsExtDirBody.c SquashfsExtFileBody.h SquashfsExtFileBody.c SquashfsExtDeviceBody.h SquashfsExtDeviceBody.c SquashfsExtIpcBody.h SquashfsExtIpcBody.c test.c) 12 + (targets EverParse.h EverParseEndianness.h SquashfsSuperblock.h SquashfsSuperblock.c SquashfsExtDirBody.h SquashfsExtDirBody.c SquashfsExtFileBody.h SquashfsExtFileBody.c SquashfsExtDeviceBody.h SquashfsExtDeviceBody.c SquashfsExtIpcBody.h SquashfsExtIpcBody.c SquashfsSuperblock_ExternalTypedefs.h SquashfsSuperblock_ExternalAPI.h SquashfsSuperblockWrapper.c SquashfsSuperblockWrapper.h SquashfsSuperblock_Fields.h SquashfsSuperblock_Fields.c SquashfsExtDirBody_ExternalTypedefs.h SquashfsExtDirBody_ExternalAPI.h SquashfsExtDirBodyWrapper.c SquashfsExtDirBodyWrapper.h SquashfsExtDirBody_Fields.h SquashfsExtDirBody_Fields.c SquashfsExtFileBody_ExternalTypedefs.h SquashfsExtFileBody_ExternalAPI.h SquashfsExtFileBodyWrapper.c SquashfsExtFileBodyWrapper.h SquashfsExtFileBody_Fields.h SquashfsExtFileBody_Fields.c SquashfsExtDeviceBody_ExternalTypedefs.h SquashfsExtDeviceBody_ExternalAPI.h SquashfsExtDeviceBodyWrapper.c SquashfsExtDeviceBodyWrapper.h SquashfsExtDeviceBody_Fields.h SquashfsExtDeviceBody_Fields.c SquashfsExtIpcBody_ExternalTypedefs.h SquashfsExtIpcBody_ExternalAPI.h SquashfsExtIpcBodyWrapper.c SquashfsExtIpcBodyWrapper.h SquashfsExtIpcBody_Fields.h SquashfsExtIpcBody_Fields.c test.c) 13 13 (deps gen.exe SquashfsSuperblock.3d SquashfsExtDirBody.3d SquashfsExtFileBody.3d SquashfsExtDeviceBody.3d SquashfsExtIpcBody.3d) 14 14 (action 15 15 (run ./gen.exe c))) 16 16 17 17 (rule 18 18 (alias runtest) 19 - (deps test.c EverParse.h EverParseEndianness.h SquashfsSuperblock.h SquashfsSuperblock.c SquashfsExtDirBody.h SquashfsExtDirBody.c SquashfsExtFileBody.h SquashfsExtFileBody.c SquashfsExtDeviceBody.h SquashfsExtDeviceBody.c SquashfsExtIpcBody.h SquashfsExtIpcBody.c) 19 + (deps test.c EverParse.h EverParseEndianness.h SquashfsSuperblock.h SquashfsSuperblock.c SquashfsExtDirBody.h SquashfsExtDirBody.c SquashfsExtFileBody.h SquashfsExtFileBody.c SquashfsExtDeviceBody.h SquashfsExtDeviceBody.c SquashfsExtIpcBody.h SquashfsExtIpcBody.c SquashfsSuperblock_ExternalTypedefs.h SquashfsSuperblock_ExternalAPI.h SquashfsSuperblockWrapper.c SquashfsSuperblockWrapper.h SquashfsSuperblock_Fields.h SquashfsSuperblock_Fields.c SquashfsExtDirBody_ExternalTypedefs.h SquashfsExtDirBody_ExternalAPI.h SquashfsExtDirBodyWrapper.c SquashfsExtDirBodyWrapper.h SquashfsExtDirBody_Fields.h SquashfsExtDirBody_Fields.c SquashfsExtFileBody_ExternalTypedefs.h SquashfsExtFileBody_ExternalAPI.h SquashfsExtFileBodyWrapper.c SquashfsExtFileBodyWrapper.h SquashfsExtFileBody_Fields.h SquashfsExtFileBody_Fields.c SquashfsExtDeviceBody_ExternalTypedefs.h SquashfsExtDeviceBody_ExternalAPI.h SquashfsExtDeviceBodyWrapper.c SquashfsExtDeviceBodyWrapper.h SquashfsExtDeviceBody_Fields.h SquashfsExtDeviceBody_Fields.c SquashfsExtIpcBody_ExternalTypedefs.h SquashfsExtIpcBody_ExternalAPI.h SquashfsExtIpcBodyWrapper.c SquashfsExtIpcBodyWrapper.h SquashfsExtIpcBody_Fields.h SquashfsExtIpcBody_Fields.c) 20 20 (action 21 21 (system 22 - "cc -std=c11 -Wall -Wextra -Werror -o test_squashfs test.c SquashfsSuperblock.c SquashfsExtDirBody.c SquashfsExtFileBody.c SquashfsExtDeviceBody.c SquashfsExtIpcBody.c && ./test_squashfs"))) 22 + "cc -std=c99 -Wall -Wextra -Werror -Wpedantic -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wcast-qual -o test_squashfs test.c SquashfsSuperblock.c SquashfsExtDirBody.c SquashfsExtFileBody.c SquashfsExtDeviceBody.c SquashfsExtIpcBody.c SquashfsSuperblock_Fields.c SquashfsExtDirBody_Fields.c SquashfsExtFileBody_Fields.c SquashfsExtDeviceBody_Fields.c SquashfsExtIpcBody_Fields.c && ./test_squashfs"))) 23 23 24 24 (install 25 25 (package squashfs) ··· 40 40 (SquashfsExtDeviceBody.c as c/SquashfsExtDeviceBody.c) 41 41 (SquashfsExtIpcBody.h as c/SquashfsExtIpcBody.h) 42 42 (SquashfsExtIpcBody.c as c/SquashfsExtIpcBody.c) 43 + (SquashfsSuperblock_ExternalTypedefs.h as c/SquashfsSuperblock_ExternalTypedefs.h) 44 + (SquashfsSuperblock_ExternalAPI.h as c/SquashfsSuperblock_ExternalAPI.h) 45 + (SquashfsSuperblockWrapper.c as c/SquashfsSuperblockWrapper.c) 46 + (SquashfsSuperblockWrapper.h as c/SquashfsSuperblockWrapper.h) 47 + (SquashfsSuperblock_Fields.h as c/SquashfsSuperblock_Fields.h) 48 + (SquashfsSuperblock_Fields.c as c/SquashfsSuperblock_Fields.c) 49 + (SquashfsExtDirBody_ExternalTypedefs.h as c/SquashfsExtDirBody_ExternalTypedefs.h) 50 + (SquashfsExtDirBody_ExternalAPI.h as c/SquashfsExtDirBody_ExternalAPI.h) 51 + (SquashfsExtDirBodyWrapper.c as c/SquashfsExtDirBodyWrapper.c) 52 + (SquashfsExtDirBodyWrapper.h as c/SquashfsExtDirBodyWrapper.h) 53 + (SquashfsExtDirBody_Fields.h as c/SquashfsExtDirBody_Fields.h) 54 + (SquashfsExtDirBody_Fields.c as c/SquashfsExtDirBody_Fields.c) 55 + (SquashfsExtFileBody_ExternalTypedefs.h as c/SquashfsExtFileBody_ExternalTypedefs.h) 56 + (SquashfsExtFileBody_ExternalAPI.h as c/SquashfsExtFileBody_ExternalAPI.h) 57 + (SquashfsExtFileBodyWrapper.c as c/SquashfsExtFileBodyWrapper.c) 58 + (SquashfsExtFileBodyWrapper.h as c/SquashfsExtFileBodyWrapper.h) 59 + (SquashfsExtFileBody_Fields.h as c/SquashfsExtFileBody_Fields.h) 60 + (SquashfsExtFileBody_Fields.c as c/SquashfsExtFileBody_Fields.c) 61 + (SquashfsExtDeviceBody_ExternalTypedefs.h as c/SquashfsExtDeviceBody_ExternalTypedefs.h) 62 + (SquashfsExtDeviceBody_ExternalAPI.h as c/SquashfsExtDeviceBody_ExternalAPI.h) 63 + (SquashfsExtDeviceBodyWrapper.c as c/SquashfsExtDeviceBodyWrapper.c) 64 + (SquashfsExtDeviceBodyWrapper.h as c/SquashfsExtDeviceBodyWrapper.h) 65 + (SquashfsExtDeviceBody_Fields.h as c/SquashfsExtDeviceBody_Fields.h) 66 + (SquashfsExtDeviceBody_Fields.c as c/SquashfsExtDeviceBody_Fields.c) 67 + (SquashfsExtIpcBody_ExternalTypedefs.h as c/SquashfsExtIpcBody_ExternalTypedefs.h) 68 + (SquashfsExtIpcBody_ExternalAPI.h as c/SquashfsExtIpcBody_ExternalAPI.h) 69 + (SquashfsExtIpcBodyWrapper.c as c/SquashfsExtIpcBodyWrapper.c) 70 + (SquashfsExtIpcBodyWrapper.h as c/SquashfsExtIpcBodyWrapper.h) 71 + (SquashfsExtIpcBody_Fields.h as c/SquashfsExtIpcBody_Fields.h) 72 + (SquashfsExtIpcBody_Fields.c as c/SquashfsExtIpcBody_Fields.c) 43 73 (EverParse.h as c/EverParse.h) 44 74 (EverParseEndianness.h as c/EverParseEndianness.h)))
+274
c/test.c
··· 1 + #include <stdio.h> 2 + #include <stdlib.h> 3 + #include <stdint.h> 4 + #include <string.h> 5 + #include "EverParse.h" 6 + #include "SquashfsSuperblock.h" 7 + #include "SquashfsSuperblock_Fields.h" 8 + #include "SquashfsExtDirBody.h" 9 + #include "SquashfsExtDirBody_Fields.h" 10 + #include "SquashfsExtFileBody.h" 11 + #include "SquashfsExtFileBody_Fields.h" 12 + #include "SquashfsExtDeviceBody.h" 13 + #include "SquashfsExtDeviceBody_Fields.h" 14 + #include "SquashfsExtIpcBody.h" 15 + #include "SquashfsExtIpcBody_Fields.h" 16 + 17 + static int error_count; 18 + 19 + static void counting_error_handler( 20 + EVERPARSE_STRING t, EVERPARSE_STRING f, EVERPARSE_STRING r, 21 + uint64_t c, uint8_t *ctx, uint8_t *i, uint64_t p) { 22 + (void)t; (void)f; (void)r; (void)c; (void)ctx; (void)i; (void)p; 23 + error_count++; 24 + } 25 + 26 + #define CHECK(msg, cond) do { \ 27 + if (cond) { pass++; } \ 28 + else { fail++; fprintf(stderr, " FAIL: %s\n", msg); } \ 29 + } while(0) 30 + 31 + int main(void) { 32 + int failures = 0; 33 + 34 + /* SquashfsSuperblock (96 bytes) */ 35 + { 36 + int pass = 0, fail = 0; 37 + uint8_t buf[96]; 38 + uint64_t r; 39 + SquashfsSuperblockFields ctx = {0}; 40 + 41 + memset(buf, 0, 96); 42 + r = SquashfsSuperblockValidateSquashfsSuperblock((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 96, 0); 43 + if (!EverParseIsSuccess(r) || r != 96) { 44 + fprintf(stderr, 45 + "FATAL: SquashfsSuperblock wire_size mismatch -- codec declared 96 bytes, " 46 + "EverParse validator returned %llu. Fix the OCaml codec's " 47 + "wire_size or the .3d projection.\n", 48 + (unsigned long long) r); 49 + return 2; 50 + } 51 + CHECK("zero buffer validates", EverParseIsSuccess(r)); 52 + CHECK("position advanced to 96", r == 96); 53 + 54 + r = SquashfsSuperblockValidateSquashfsSuperblock((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 192, 0); 55 + CHECK("larger buffer validates", EverParseIsSuccess(r)); 56 + CHECK("position is 96 not 192", r == 96); 57 + 58 + for (uint64_t len = 0; len < 96; len++) { 59 + error_count = 0; 60 + r = SquashfsSuperblockValidateSquashfsSuperblock((WIRECTX *) &ctx, NULL, counting_error_handler, buf, len, 0); 61 + CHECK("truncated to len fails", EverParseIsError(r)); 62 + } 63 + 64 + r = SquashfsSuperblockValidateSquashfsSuperblock((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 0, 0); 65 + CHECK("empty input fails", EverParseIsError(r)); 66 + 67 + srand(42); 68 + for (int i = 0; i < 1000; i++) { 69 + for (int j = 0; j < 96; j++) 70 + buf[j] = (uint8_t)(rand() & 0xff); 71 + r = SquashfsSuperblockValidateSquashfsSuperblock((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 96, 0); 72 + CHECK("random buffer validates", EverParseIsSuccess(r)); 73 + CHECK("random position correct", r == 96); 74 + } 75 + 76 + (void) ctx; 77 + printf("squashfssuperblock: %d passed, %d failed\n", pass, fail); 78 + failures += fail; 79 + } 80 + 81 + /* SquashfsExtDirBody (24 bytes) */ 82 + { 83 + int pass = 0, fail = 0; 84 + uint8_t buf[24]; 85 + uint64_t r; 86 + SquashfsExtDirBodyFields ctx = {0}; 87 + 88 + memset(buf, 0, 24); 89 + r = SquashfsExtDirBodyValidateSquashfsExtDirBody((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 24, 0); 90 + if (!EverParseIsSuccess(r) || r != 24) { 91 + fprintf(stderr, 92 + "FATAL: SquashfsExtDirBody wire_size mismatch -- codec declared 24 bytes, " 93 + "EverParse validator returned %llu. Fix the OCaml codec's " 94 + "wire_size or the .3d projection.\n", 95 + (unsigned long long) r); 96 + return 2; 97 + } 98 + CHECK("zero buffer validates", EverParseIsSuccess(r)); 99 + CHECK("position advanced to 24", r == 24); 100 + 101 + r = SquashfsExtDirBodyValidateSquashfsExtDirBody((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 48, 0); 102 + CHECK("larger buffer validates", EverParseIsSuccess(r)); 103 + CHECK("position is 24 not 48", r == 24); 104 + 105 + for (uint64_t len = 0; len < 24; len++) { 106 + error_count = 0; 107 + r = SquashfsExtDirBodyValidateSquashfsExtDirBody((WIRECTX *) &ctx, NULL, counting_error_handler, buf, len, 0); 108 + CHECK("truncated to len fails", EverParseIsError(r)); 109 + } 110 + 111 + r = SquashfsExtDirBodyValidateSquashfsExtDirBody((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 0, 0); 112 + CHECK("empty input fails", EverParseIsError(r)); 113 + 114 + srand(42); 115 + for (int i = 0; i < 1000; i++) { 116 + for (int j = 0; j < 24; j++) 117 + buf[j] = (uint8_t)(rand() & 0xff); 118 + r = SquashfsExtDirBodyValidateSquashfsExtDirBody((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 24, 0); 119 + CHECK("random buffer validates", EverParseIsSuccess(r)); 120 + CHECK("random position correct", r == 24); 121 + } 122 + 123 + (void) ctx; 124 + printf("squashfsextdirbody: %d passed, %d failed\n", pass, fail); 125 + failures += fail; 126 + } 127 + 128 + /* SquashfsExtFileBody (40 bytes) */ 129 + { 130 + int pass = 0, fail = 0; 131 + uint8_t buf[40]; 132 + uint64_t r; 133 + SquashfsExtFileBodyFields ctx = {0}; 134 + 135 + memset(buf, 0, 40); 136 + r = SquashfsExtFileBodyValidateSquashfsExtFileBody((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 40, 0); 137 + if (!EverParseIsSuccess(r) || r != 40) { 138 + fprintf(stderr, 139 + "FATAL: SquashfsExtFileBody wire_size mismatch -- codec declared 40 bytes, " 140 + "EverParse validator returned %llu. Fix the OCaml codec's " 141 + "wire_size or the .3d projection.\n", 142 + (unsigned long long) r); 143 + return 2; 144 + } 145 + CHECK("zero buffer validates", EverParseIsSuccess(r)); 146 + CHECK("position advanced to 40", r == 40); 147 + 148 + r = SquashfsExtFileBodyValidateSquashfsExtFileBody((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 80, 0); 149 + CHECK("larger buffer validates", EverParseIsSuccess(r)); 150 + CHECK("position is 40 not 80", r == 40); 151 + 152 + for (uint64_t len = 0; len < 40; len++) { 153 + error_count = 0; 154 + r = SquashfsExtFileBodyValidateSquashfsExtFileBody((WIRECTX *) &ctx, NULL, counting_error_handler, buf, len, 0); 155 + CHECK("truncated to len fails", EverParseIsError(r)); 156 + } 157 + 158 + r = SquashfsExtFileBodyValidateSquashfsExtFileBody((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 0, 0); 159 + CHECK("empty input fails", EverParseIsError(r)); 160 + 161 + srand(42); 162 + for (int i = 0; i < 1000; i++) { 163 + for (int j = 0; j < 40; j++) 164 + buf[j] = (uint8_t)(rand() & 0xff); 165 + r = SquashfsExtFileBodyValidateSquashfsExtFileBody((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 40, 0); 166 + CHECK("random buffer validates", EverParseIsSuccess(r)); 167 + CHECK("random position correct", r == 40); 168 + } 169 + 170 + (void) ctx; 171 + printf("squashfsextfilebody: %d passed, %d failed\n", pass, fail); 172 + failures += fail; 173 + } 174 + 175 + /* SquashfsExtDeviceBody (12 bytes) */ 176 + { 177 + int pass = 0, fail = 0; 178 + uint8_t buf[12]; 179 + uint64_t r; 180 + SquashfsExtDeviceBodyFields ctx = {0}; 181 + 182 + memset(buf, 0, 12); 183 + r = SquashfsExtDeviceBodyValidateSquashfsExtDeviceBody((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 12, 0); 184 + if (!EverParseIsSuccess(r) || r != 12) { 185 + fprintf(stderr, 186 + "FATAL: SquashfsExtDeviceBody wire_size mismatch -- codec declared 12 bytes, " 187 + "EverParse validator returned %llu. Fix the OCaml codec's " 188 + "wire_size or the .3d projection.\n", 189 + (unsigned long long) r); 190 + return 2; 191 + } 192 + CHECK("zero buffer validates", EverParseIsSuccess(r)); 193 + CHECK("position advanced to 12", r == 12); 194 + 195 + r = SquashfsExtDeviceBodyValidateSquashfsExtDeviceBody((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 24, 0); 196 + CHECK("larger buffer validates", EverParseIsSuccess(r)); 197 + CHECK("position is 12 not 24", r == 12); 198 + 199 + for (uint64_t len = 0; len < 12; len++) { 200 + error_count = 0; 201 + r = SquashfsExtDeviceBodyValidateSquashfsExtDeviceBody((WIRECTX *) &ctx, NULL, counting_error_handler, buf, len, 0); 202 + CHECK("truncated to len fails", EverParseIsError(r)); 203 + } 204 + 205 + r = SquashfsExtDeviceBodyValidateSquashfsExtDeviceBody((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 0, 0); 206 + CHECK("empty input fails", EverParseIsError(r)); 207 + 208 + srand(42); 209 + for (int i = 0; i < 1000; i++) { 210 + for (int j = 0; j < 12; j++) 211 + buf[j] = (uint8_t)(rand() & 0xff); 212 + r = SquashfsExtDeviceBodyValidateSquashfsExtDeviceBody((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 12, 0); 213 + CHECK("random buffer validates", EverParseIsSuccess(r)); 214 + CHECK("random position correct", r == 12); 215 + } 216 + 217 + (void) ctx; 218 + printf("squashfsextdevicebody: %d passed, %d failed\n", pass, fail); 219 + failures += fail; 220 + } 221 + 222 + /* SquashfsExtIpcBody (8 bytes) */ 223 + { 224 + int pass = 0, fail = 0; 225 + uint8_t buf[8]; 226 + uint64_t r; 227 + SquashfsExtIpcBodyFields ctx = {0}; 228 + 229 + memset(buf, 0, 8); 230 + r = SquashfsExtIpcBodyValidateSquashfsExtIpcBody((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 8, 0); 231 + if (!EverParseIsSuccess(r) || r != 8) { 232 + fprintf(stderr, 233 + "FATAL: SquashfsExtIpcBody wire_size mismatch -- codec declared 8 bytes, " 234 + "EverParse validator returned %llu. Fix the OCaml codec's " 235 + "wire_size or the .3d projection.\n", 236 + (unsigned long long) r); 237 + return 2; 238 + } 239 + CHECK("zero buffer validates", EverParseIsSuccess(r)); 240 + CHECK("position advanced to 8", r == 8); 241 + 242 + r = SquashfsExtIpcBodyValidateSquashfsExtIpcBody((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 16, 0); 243 + CHECK("larger buffer validates", EverParseIsSuccess(r)); 244 + CHECK("position is 8 not 16", r == 8); 245 + 246 + for (uint64_t len = 0; len < 8; len++) { 247 + error_count = 0; 248 + r = SquashfsExtIpcBodyValidateSquashfsExtIpcBody((WIRECTX *) &ctx, NULL, counting_error_handler, buf, len, 0); 249 + CHECK("truncated to len fails", EverParseIsError(r)); 250 + } 251 + 252 + r = SquashfsExtIpcBodyValidateSquashfsExtIpcBody((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 0, 0); 253 + CHECK("empty input fails", EverParseIsError(r)); 254 + 255 + srand(42); 256 + for (int i = 0; i < 1000; i++) { 257 + for (int j = 0; j < 8; j++) 258 + buf[j] = (uint8_t)(rand() & 0xff); 259 + r = SquashfsExtIpcBodyValidateSquashfsExtIpcBody((WIRECTX *) &ctx, NULL, counting_error_handler, buf, 8, 0); 260 + CHECK("random buffer validates", EverParseIsSuccess(r)); 261 + CHECK("random position correct", r == 8); 262 + } 263 + 264 + (void) ctx; 265 + printf("squashfsextipcbody: %d passed, %d failed\n", pass, fail); 266 + failures += fail; 267 + } 268 + 269 + if (failures == 0) 270 + printf("All tests passed.\n"); 271 + else 272 + printf("%d test(s) failed.\n", failures); 273 + return failures ? 1 : 0; 274 + }