Common string operations (padding, chunks, base64)
Supports most common string operations e.g.:
- packing/unpacking:
p64()
,p32()
,p16()
,p8()
u64()
,u32()
,u16()
,u8()
chunks:
chunks_iter()
,chunks()
chunks/chunks_iter
asciiz/utf16z
enhex/unhex
- malduck.base64(s: str | bytes) bytes
Base64 encoder/decoder
Padding (null/pkcs7)
- malduck.pad(s: bytes, block_size: int) bytes
Padding PKCS7/NULL
- malduck.unpad(s: bytes) bytes
Unpadding PKCS7/NULL
Packing/unpacking (p64/p32/p16/p8, u64/u32/u16/u8, bigint)
- malduck.uint64(other: bytes, offset: int = 0, fixed: bool = True) IntType | int | None
Unpacks single value from provided buffer with little-endian order
- Parameters:
other (bytes) – Buffer object containing value to unpack
offset (int) – Buffer offset
fixed (bool (default: True)) – Convert to fixed-size integer (IntType instance)
- Return type:
IntType instance or None if there are not enough data to unpack
Warning
Fixed-size integer operations are 4-5 times slower than equivalent on built-in integer types
- malduck.uint32(other: bytes, offset: int = 0, fixed: bool = True) IntType | int | None
Unpacks single value from provided buffer with little-endian order
- Parameters:
other (bytes) – Buffer object containing value to unpack
offset (int) – Buffer offset
fixed (bool (default: True)) – Convert to fixed-size integer (IntType instance)
- Return type:
IntType instance or None if there are not enough data to unpack
Warning
Fixed-size integer operations are 4-5 times slower than equivalent on built-in integer types
- malduck.uint16(other: bytes, offset: int = 0, fixed: bool = True) IntType | int | None
Unpacks single value from provided buffer with little-endian order
- Parameters:
other (bytes) – Buffer object containing value to unpack
offset (int) – Buffer offset
fixed (bool (default: True)) – Convert to fixed-size integer (IntType instance)
- Return type:
IntType instance or None if there are not enough data to unpack
Warning
Fixed-size integer operations are 4-5 times slower than equivalent on built-in integer types
- malduck.uint8(other: bytes, offset: int = 0, fixed: bool = True) IntType | int | None
Unpacks single value from provided buffer with little-endian order
- Parameters:
other (bytes) – Buffer object containing value to unpack
offset (int) – Buffer offset
fixed (bool (default: True)) – Convert to fixed-size integer (IntType instance)
- Return type:
IntType instance or None if there are not enough data to unpack
Warning
Fixed-size integer operations are 4-5 times slower than equivalent on built-in integer types
- malduck.u64(other: bytes, offset: int = 0, fixed: bool = True) IntType | int | None
Unpacks single value from provided buffer with little-endian order
- Parameters:
other (bytes) – Buffer object containing value to unpack
offset (int) – Buffer offset
fixed (bool (default: True)) – Convert to fixed-size integer (IntType instance)
- Return type:
IntType instance or None if there are not enough data to unpack
Warning
Fixed-size integer operations are 4-5 times slower than equivalent on built-in integer types
- malduck.u32(other: bytes, offset: int = 0, fixed: bool = True) IntType | int | None
Unpacks single value from provided buffer with little-endian order
- Parameters:
other (bytes) – Buffer object containing value to unpack
offset (int) – Buffer offset
fixed (bool (default: True)) – Convert to fixed-size integer (IntType instance)
- Return type:
IntType instance or None if there are not enough data to unpack
Warning
Fixed-size integer operations are 4-5 times slower than equivalent on built-in integer types
- malduck.u16(other: bytes, offset: int = 0, fixed: bool = True) IntType | int | None
Unpacks single value from provided buffer with little-endian order
- Parameters:
other (bytes) – Buffer object containing value to unpack
offset (int) – Buffer offset
fixed (bool (default: True)) – Convert to fixed-size integer (IntType instance)
- Return type:
IntType instance or None if there are not enough data to unpack
Warning
Fixed-size integer operations are 4-5 times slower than equivalent on built-in integer types
- malduck.u8(other: bytes, offset: int = 0, fixed: bool = True) IntType | int | None
Unpacks single value from provided buffer with little-endian order
- Parameters:
other (bytes) – Buffer object containing value to unpack
offset (int) – Buffer offset
fixed (bool (default: True)) – Convert to fixed-size integer (IntType instance)
- Return type:
IntType instance or None if there are not enough data to unpack
Warning
Fixed-size integer operations are 4-5 times slower than equivalent on built-in integer types
- malduck.bigint.unpack(other: bytes, size: int | None = None) int
Unpacks bigint value from provided buffer with little-endian order
New in version 4.0.0: Use bigint.unpack instead of bigint() method
- Parameters:
other (bytes) – Buffer object containing value to unpack
size (bytes, optional) – Size of bigint in bytes
- Return type:
int
- malduck.bigint.pack(other: int, size: int | None = None) bytes
Packs bigint value into bytes with little-endian order
New in version 4.0.0: Use bigint.pack instead of bigint() method
- Parameters:
other (int) – Value to be packed
size (bytes, optional) – Size of bigint in bytes
- Return type:
bytes
- malduck.bigint.unpack_be(other: bytes, size: int | None = None) int
Unpacks bigint value from provided buffer with big-endian order
- Parameters:
other (bytes) – Buffer object containing value to unpack
size (bytes, optional) – Size of bigint in bytes
- Return type:
int
- malduck.bigint.pack_be(other: int, size: int | None = None) bytes
Packs bigint value into bytes with big-endian order
New in version 4.0.0: Use bigint.pack instead of bigint() method
- Parameters:
other (int) – Value to be packed
size (bytes, optional) – Size of bigint in bytes
- Return type:
bytes