Fixed-integer types¶
Object properties¶
-
class
malduck.ints.
IntType
[source]¶ Fixed-size variant of long type with C-style operators and casting
Supports ctypes-like multiplication for unpacking tuple of values
IntTypes are derived from
long
type, so they are fully compatible with other numeric typesres = u32(0x8080FFFF) << 16 | 0xFFFF > 0xFFFFFFFF res = Int32(res) > -1
Using IntTypes you don’t need to mask everything with 0xFFFFFFFF, only if you remember about appropriate casting.
from malduck import DWORD def rol7_hash(name: bytes): hh = 0 for c in name: hh = DWORD(x).rol(7) ^ c return x def sdbm_hash(name: bytes): hh = 0 for c in name: hh = DWORD(c) + (hh << 6) + (hh << 16) - hh return hh
Type coercion between native and fixed integers depends on LHS type:
UInt32 = UInt32 + int int = int + UInt32
IntTypes can be multiplied like ctypes classes for unpacking tuple of values:
values = (BYTE * 3).unpack('\x01\x02\x03') values -> (1, 2, 3)
-
classmethod
unpack
(other, offset=0, fixed=True)[source]¶ 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
-
classmethod
unpack_be
(other, offset=0, fixed=True)[source]¶ Unpacks single value from provided buffer with big-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
UInt64/UInt32/UInt16/UInt8 (QWORD/DWORD/WORD/BYTE)¶
-
malduck.
QWORD
¶ alias of
malduck.ints.UInt64
-
malduck.
DWORD
¶ alias of
malduck.ints.UInt32
-
malduck.
WORD
¶ alias of
malduck.ints.UInt16
-
malduck.
BYTE
¶ alias of
malduck.ints.UInt8
-
class
malduck.ints.
UInt64
¶
-
class
malduck.ints.
UInt32
¶
-
class
malduck.ints.
UInt16
¶
-
class
malduck.ints.
UInt8
¶