Source code for msl.enums

"""MSL format constants and enumerations (Memory Slice Specification v1.0.0 — binary format 1.1).

Magic bytes and all IntEnum/IntFlag types from the specification tables.
"""

from enum import Enum, IntEnum, IntFlag

# -- Magic bytes --
FILE_MAGIC = b"\x4D\x45\x4D\x53\x4C\x49\x43\x45"  # "MEMSLICE"
BLOCK_MAGIC = b"\x4D\x53\x4C\x43"  # "MSLC"
FILE_HEADER_SIZE = 64
FILE_HEADER_ENC_SIZE = 128
BLOCK_HEADER_SIZE = 80

# -- Encryption (spec §10) --
ENC_EXT_OFFSET = 0x40          # encryption extension starts here when Encrypted
ENC_EXT_SIZE = 64             # extension header is 64 bytes (0x40..0x7F)
AEAD_TAG_SIZE = 16            # both cipher suites use a 16-byte tag
# Header CipherLen (spec 1.1.1 Table 5, formerly Reserved3): u64 LE byte length
# of the primary AEAD ciphertext; 0 = not recorded. Excluded from the AAD
# (§10.2) and hashed as zero by FileHash (§10.7).
CIPHER_LEN_OFFSET = 0x78
CIPHER_LEN_SIZE = 8
# HKDF-BLAKE3 context (spec §10.4): info string for content-encryption-key derivation
MSL_CEK_INFO = b"MSL-CEK-v1"


[docs] class Endianness(IntEnum): LITTLE = 0x01 BIG = 0x02
[docs] class HeaderFlag(IntFlag): IMPORTED = 1 << 0 INVESTIGATION = 1 << 1 ENCRYPTED = 1 << 2
[docs] class BlockType(IntEnum): """Block type registry (spec Table 9).""" INVALID = 0x0000 MEMORY_REGION = 0x0001 MODULE_ENTRY = 0x0002 MODULE_LIST_INDEX = 0x0010 THREAD_CONTEXT = 0x0011 FILE_DESCRIPTOR = 0x0012 NETWORK_CONNECTION = 0x0013 ENVIRONMENT_BLOCK = 0x0014 SECURITY_TOKEN = 0x0015 KEY_HINT = 0x0020 IMPORT_PROVENANCE = 0x0030 PROCESS_IDENTITY = 0x0040 RELATED_DUMP = 0x0041 SYSTEM_CONTEXT = 0x0050 PROCESS_TABLE = 0x0051 CONNECTION_TABLE = 0x0052 HANDLE_TABLE = 0x0053 CONNECTIVITY_TABLE = 0x0055 PHYSICAL_MEMORY_MAP = 0x0059 # spec 5.9 (v1.1) END_OF_EXTENSION = 0x0FFE # terminator of an extension segment (spec 4.6) END_OF_CAPTURE = 0x0FFF VAS_MAP = 0x1001 # POINTER_GRAPH (0x1003) is a producer-defined Structural block whose # payload the spec does not define, so it MAY only appear inside an # extension segment (spec 4.6): after the End-of-Capture block, chained # from it and closed by an End-of-Extension block. Readers that do not # implement extension segments stop at EoC and ignore it. Payload layout # is documented in docs/file_formats/msl_v1_0_0.md. POINTER_GRAPH = 0x1003
# Evidence block types that MUST NOT appear inside an extension segment # (spec 4.6): the capture segment is the evidence; a segment appended later # may only carry derived views (key hints, related dumps, manifests # 0x0059-0x005B and Structural blocks 0x1000-0x1FFF). EXTENSION_FORBIDDEN_TYPES = frozenset( {0x0001, 0x0002, 0x0030, 0x0040, 0x0FFF} | set(range(0x0010, 0x0016)) | set(range(0x0050, 0x0059)) )
[docs] class BlockFlag(IntFlag): """Per-block flags (spec Table 7).""" COMPRESSED = 1 << 0 COMP_ZSTD = 1 << 1 COMP_LZ4 = 2 << 1 HAS_KEY_HINTS = 1 << 3 HAS_CHILDREN = 1 << 4 CONTINUATION = 1 << 5
[docs] class CompAlgo(IntEnum): NONE = 0 ZSTD = 1 LZ4 = 2
[docs] class PageState(IntEnum): """Four-state page acquisition model (spec Table 24 / Section 7). ``NOT_RESIDENT`` (``0b11``) is a mapped page that was not resident at capture time. It contributes no captured bytes to PageData. ``RESERVED`` is kept as a backwards-compatible alias of the same value (older code named it that way and treated it as FAILED). """ CAPTURED = 0b00 FAILED = 0b01 UNMAPPED = 0b10 NOT_RESIDENT = 0b11 RESERVED = 0b11 # alias (resolves to NOT_RESIDENT)
[docs] class Protection(IntFlag): """Memory region protection flags (spec Section 5.1).""" READ = 0x01 WRITE = 0x02 EXECUTE = 0x04 GUARD = 0x08 COW = 0x10
[docs] class RegionType(IntEnum): """Memory region types (spec Section 5.1).""" UNKNOWN = 0x00 HEAP = 0x01 STACK = 0x02 IMAGE = 0x03 MAPPED_FILE = 0x04 ANONYMOUS = 0x05 SHARED_MEM = 0x06 OTHER = 0xFF
[docs] class ThreadState(IntEnum): """Scheduler state of a thread (Thread Context block, spec Table 19a).""" UNKNOWN = 0x00 RUNNING = 0x01 SLEEPING = 0x02 STOPPED = 0x03 WAITING = 0x04 UNINTERRUPTIBLE = 0x05 HALTED = 0x06 ZOMBIE = 0x07
# Thread Context ``Flags`` bits (spec Table 19a). TC_FLAG_CURRENT = 0x0001 # thread whose registers are the resumption point TC_FLAG_CRASHED = 0x0002 # thread that faulted TC_FLAG_SUSPENDED = 0x0004 # registers read from a stopped thread TC_FLAG_PARTIAL = 0x0008 # register file incomplete # Thread Context register ``Flags`` role bits (spec Table 19b). REG_ROLE_PC = 0x0001 # program counter REG_ROLE_SP = 0x0002 # stack pointer REG_ROLE_FP = 0x0004 # frame pointer REG_ROLE_FLAGS = 0x0008 # status / flags register REG_ROLE_TLS = 0x0010 # thread pointer / TLS base REG_ROLE_LR = 0x0020 # link register
[docs] class VasNameSource(IntEnum): """How a VAS Map entry's MappedPath was obtained (spec 5.8).""" UNSPECIFIED = 0 LIVE = 1 SOURCE_METADATA = 2 SYNTHESIZED = 3
[docs] class OSType(IntEnum): WINDOWS = 0x0000 LINUX = 0x0001 MACOS = 0x0002 ANDROID = 0x0003 IOS = 0x0004 FREEBSD = 0x0005 UNKNOWN = 0xFFFF
[docs] class ArchType(IntEnum): X86 = 0x0000 X86_64 = 0x0001 ARM64 = 0x0002 ARM32 = 0x0003 UNKNOWN = 0xFFFF
[docs] class SourceFormat(IntEnum): """Source artifact format for the IMPORT_PROVENANCE block `source_format`. The specification defines the wire codes. This enum also represents legacy MemDiver origins and internal classifications. Use :func:`memdiver.msl.source_format.wire_source_format` to encode them. """ RAW_DUMP = 0x01 # opaque raw memory .dump (fritap-style) ELF_CORE = 0x02 # ELF ET_CORE process core dump MINIDUMP = 0x03 # Windows Minidump (.dmp) MSL = 0x04 # an existing .msl (region-filtered materialize copy) # flat .bin + /proc/<pid>/maps sidecar (gdb_raw / lldb_raw / fridump): # region types come from the maps paths, i.e. real observations, so the # raw "unclassified" rule does not apply to it. REGIONED_RAW = 0x05 # Spec Table 40 "Other": a producer the spec registry has no code for # (e.g. a process extracted from a full physical memory image). OTHER = 0xFFFF # Classification-only members (never written, outside the u16 wire # range): spec v1.1.0 Table 40 0x0004 / 0x0005 from a NON-MemDiver writer. # MSL / REGIONED_RAW above keep the legacy MemDiver meaning of 0x04/0x05, # which collides with the spec; new files write OTHER (0xFFFF) + a note # origin field instead. See msl/source_format.py. MACOS_CORE = 0x10004 PROCDUMP = 0x10005
[docs] class MslKeyType(IntEnum): """Crypto key type codes (spec Table 17).""" UNKNOWN = 0x0000 PRE_MASTER_SECRET = 0x0001 MASTER_SECRET = 0x0002 SESSION_KEY = 0x0003 HANDSHAKE_SECRET = 0x0004 APP_TRAFFIC_SECRET = 0x0005 RSA_PRIVATE_KEY = 0x0006 ECDH_PRIVATE_KEY = 0x0007 IKE_SA_KEY = 0x0008 ESP_AH_KEY = 0x0009 SSH_SESSION_KEY = 0x000A WIREGUARD_KEY = 0x000B ML_KEM_PRIVATE_KEY = 0x000C OTHER = 0xFFFF
[docs] class MslProtocol(IntEnum): """Protocol codes (spec Table 17).""" UNKNOWN = 0x0000 TLS_12 = 0x0001 TLS_13 = 0x0002 DTLS_12 = 0x0003 DTLS_13 = 0x0004 QUIC = 0x0005 IKEV2_IPSEC = 0x0006 SSH = 0x0007 WIREGUARD = 0x0008 PQ_TLS = 0x0009 OTHER = 0xFFFF
[docs] class Confidence(IntEnum): """Key hint confidence levels (spec Section 5.6).""" SPECULATIVE = 0x00 HEURISTIC = 0x01 CONFIRMED = 0x02
[docs] class KeyState(IntEnum): """Key lifecycle state (spec Section 5.6).""" UNKNOWN = 0x00 ACTIVE = 0x01 EXPIRED = 0x02
[docs] class HandleType(IntEnum): """Handle Table entry type discriminator (spec Table 24, uint16).""" UNKNOWN = 0x00 FILE = 0x01 DIR = 0x02 SOCKET = 0x03 PIPE = 0x04 MUTEX = 0x05 TIMER = 0x06 OTHER = 0x07
[docs] class ConnRowType(IntEnum): """Connectivity Table row-type discriminator (spec Table 26, uint8).""" IPV4_ROUTE = 0x01 IPV6_ROUTE = 0x02 ARP_ENTRY = 0x03 PACKET_SOCKET = 0x04 IFACE_STATS = 0x05 SOCKET_FAMILY_AGG = 0x06 MIB_COUNTER = 0x07
# -- POINTER_GRAPH (0x1003) — MemDiver extension-segment block -- # Bit set in the POINTER_GRAPH payload header `flags` field when the # 32-byte BLAKE3 trailer is present. Kept from the pre-1.1 appendix era # (when the block lived outside the chain); the segment's SegmentHash and # the continued PrevHash chain now cover the block as well. POINTER_GRAPH_INTEGRITY_FLAG = 1 << 0 # -- Encryption enums (spec §10) --
[docs] class HashAlgo(IntEnum): """Integrity hash algorithm selector (file header offset 0x3D, spec Table 12). All registered algorithms produce 32-byte output, so field layouts are independent of the choice. Applies to PrevHash, EoC FileHash, DiskHash — NOT to HKDF key derivation (which always uses BLAKE3). """ BLAKE3 = 0x00 # default SHA256 = 0x01 SHA512_256 = 0x02 OTHER = 0xFF
[docs] class EncAlgo(IntEnum): """AEAD cipher suite (encryption extension offset 0x40, spec Table 30).""" AES_256_GCM = 0x01 # 12-byte nonce, 16-byte tag (default) XCHACHA20_POLY1305 = 0x02 # 24-byte nonce, 16-byte tag
[docs] class KdfType(IntEnum): """Key derivation function (encryption extension offset 0x41, spec §10.5).""" NONE = 0x00 # 256-bit CEK supplied externally ARGON2ID = 0x01 # passphrase-derived; min time=3, memory=65536 KiB, lanes=4
[docs] class KeyEncap(IntEnum): """Key encapsulation mechanism (encryption extension offset 0x42, spec Table 31).""" NONE = 0x00 # raw key / passphrase X25519 = 0x01 # classical ECDH; 32-byte ciphertext ML_KEM_768 = 0x02 # FIPS 203; 1088-byte ciphertext ML_KEM_1024 = 0x03 # FIPS 203; 1568-byte ciphertext X25519_ML_KEM_768 = 0x04 # hybrid (recommended); 1120-byte ciphertext OTHER = 0xFF
# KEM ciphertext lengths per spec Table 31 (bytes). 0 means no KEM ciphertext. KEM_CIPHERTEXT_LEN = { KeyEncap.NONE: 0, KeyEncap.X25519: 32, KeyEncap.ML_KEM_768: 1088, KeyEncap.ML_KEM_1024: 1568, KeyEncap.X25519_ML_KEM_768: 1120, # 32 (X25519) + 1088 (ML-KEM-768) } # AEAD nonce sizes per spec Table 30 (bytes). CIPHER_NONCE_LEN = { EncAlgo.AES_256_GCM: 12, EncAlgo.XCHACHA20_POLY1305: 24, } # Argon2id minimum parameters (spec §10.5). ARGON2ID_MIN_TIME = 3 ARGON2ID_MIN_MEMORY_KIB = 65536 ARGON2ID_MIN_LANES = 4
[docs] class TagStatus(Enum): """Result of AEAD tag verification, surfaced to the user by MslReader. Distinguishes the four states a consumer must communicate (spec §10, §14.2): a plaintext file, a verified decryption, a failed/tampered decryption, and an encrypted file opened without a key. """ NOT_ENCRYPTED = "not_encrypted" # file is not encrypted VALID = "valid" # AEAD tag verified, plaintext recovered CORRUPTED = "corrupted" # tag mismatch — wrong key or tampering MISSING_KEY = "missing_key" # encrypted, but no key/passphrase supplied @property def readable(self) -> bool: """Plaintext or a verified decryption: the dump's bytes can be read.""" return self in (TagStatus.NOT_ENCRYPTED, TagStatus.VALID)
[docs] class NodeKind(IntEnum): """POINTER_GRAPH node-kind discriminator (uint8). Distinguishes how to interpret the node's 64-bit `value` field. """ ADDRESS = 0x01 # absolute virtual address OFFSET = 0x02 # file or region offset SYMBOL = 0x03 # symbol identifier; `label` carries the name
[docs] class EdgeKind(IntEnum): """POINTER_GRAPH edge-kind discriminator (uint8).""" POINTER = 0x01 # data pointer reference CALL = 0x02 # function call edge IMPORT = 0x03 # module import / dependency edge