AbstractCEnum
Bases: IntEnum
Abstract C enum to Python class
Source code in cstruct/abstract.py
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
|
parse(__enum__, __name__=None, __size__=None, __native_format__=None, **kargs)
classmethod
Return a new Python Enum class mapping a C enum definition
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__enum__ |
Union[str, Tokens, Dict[str, Any]]
|
Definition of the enum in C syntax |
required |
__name__ |
Optional[str]
|
Name of the new Enum. If empty, a name based on the enum hash is generated |
None
|
__size__ |
Optional[int]
|
Number of bytes that the enum should be read as |
None
|
__native_format__ |
Optional[str]
|
struct module format |
None
|
Returns:
Name | Type | Description |
---|---|---|
cls |
Type[AbstractCEnum]
|
A new class mapping the definition |
Source code in cstruct/abstract.py
355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
|
AbstractCStruct
Abstract C struct to Python class
Source code in cstruct/abstract.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 |
|
__alignment__: int = 0
class-attribute
Alignament
__byte_order__: Optional[str] = None
class-attribute
Byte order
__is_union__: bool = False
class-attribute
True if the class is an union, False if it is a struct
__size__: int = 0
class-attribute
Size in bytes
size: int
property
Actual structure size (in bytes)
__getstate__()
This method is called and the returned object is pickled as the contents for the instance, instead of the contents of the instance’s dictionary
Returns:
Name | Type | Description |
---|---|---|
bytes |
bytes
|
The packed structure |
Source code in cstruct/abstract.py
280 281 282 283 284 285 286 287 288 289 |
|
__len__()
Actual structure size (in bytes)
Source code in cstruct/abstract.py
207 208 209 |
|
__setstate__(state)
This method it is called with the unpickled state
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state |
bytes
|
bytes to be unpacked |
required |
Source code in cstruct/abstract.py
291 292 293 294 295 296 297 298 |
|
inspect(start_addr=None, end_addr=None)
Return memory content in hexadecimal
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_addr |
Optional[int]
|
start address |
None
|
end_addr |
Optional[int]
|
end address |
None
|
Source code in cstruct/abstract.py
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 |
|
pack()
Pack the structure data into bytes
Returns:
Name | Type | Description |
---|---|---|
bytes |
bytes
|
The packed structure |
Source code in cstruct/abstract.py
195 196 197 198 199 200 201 202 |
|
parse(__struct__, __name__=None, __byte_order__=None, __is_union__=False, **kargs)
classmethod
Return a new class mapping a C struct/union definition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
__struct__ |
Union[str, Tokens, Dict[str, Any]]
|
definition of the struct (or union) in C syntax |
required |
__name__ |
Optional[str]
|
name of the new class. If empty, a name based on the struct hash is generated |
None
|
__byte_order__ |
Optional[str]
|
byte order, valid values are LITTLE_ENDIAN, BIG_ENDIAN, NATIVE_ORDER |
None
|
__is_union__ |
Optional[bool]
|
True for union, False for struct |
False
|
Returns:
Name | Type | Description |
---|---|---|
cls |
Type[AbstractCStruct]
|
a new class mapping the defintion |
Source code in cstruct/abstract.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
|
set_flexible_array_length(flexible_array_length)
Set flexible array length (i.e. number of elements)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
flexible_array_length |
Optional[int]
|
flexible array length |
required |
Raises:
Type | Description |
---|---|
CStructException
|
If flexible array is not present in the structure |
Source code in cstruct/abstract.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
|
sizeof()
classmethod
Structure size in bytes (flexible array member size is omitted)
Source code in cstruct/abstract.py
226 227 228 229 |
|
unpack(buffer, flexible_array_length=None)
Unpack bytes containing packed C structure data
Parameters:
Name | Type | Description | Default |
---|---|---|---|
buffer |
Optional[Union[bytes, BinaryIO]]
|
bytes or binary stream to be unpacked |
required |
flexible_array_length |
Optional[int]
|
flexible array length |
None
|
Source code in cstruct/abstract.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
unpack_from(buffer, offset=0, flexible_array_length=None)
Unpack bytes containing packed C structure data
Parameters:
Name | Type | Description | Default |
---|---|---|---|
buffer |
Optional[bytes]
|
bytes to be unpacked |
required |
offset |
int
|
optional buffer offset |
0
|
flexible_array_length |
Optional[int]
|
flexible array length |
None
|
Source code in cstruct/abstract.py
182 183 184 185 186 187 188 189 190 191 192 193 |
|
CEnumMeta
Bases: EnumMeta
Source code in cstruct/abstract.py
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
|
size: int
property
Enum size (in bytes)
CStructMeta
Bases: ABCMeta
Source code in cstruct/abstract.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
|
size: int
property
Structure size (in bytes)
__len__()
Structure size (in bytes)
Source code in cstruct/abstract.py
64 65 66 |
|