DOS MZ

class cle.backends.MZ[source]

Bases: Backend

Loader for ordinary 8086 DOS MZ executables.

The load module is represented in a canonical 20-bit linear address space: segment * 16 + offset. The Program Segment Prefix and runtime-selected extra allocation beyond the header’s required minimum are not materialized.

is_default = True
__init__(*args, **kwargs)[source]
Parameters:
  • binary – The path to the binary to load

  • binary_stream – The open stream to this binary. The reference to this will be held until you call close.

  • is_main_bin – Whether this binary should be loaded as the main executable

property mapped_address_bits: int

Width of the flat address space CLE uses for this object’s mappings.

property load_segment: int
property initial_stack: int

SP.

Type:

The canonical linear address corresponding to the initial SS

property initial_cs_value: int

The CS register value after DOS adds the runtime load segment.

property initial_ss_value: int

The SS register value after DOS adds the runtime load segment.

rebase(new_base)[source]

Rebase backend’s regions to the new base where they were mapped by the loader

classmethod is_compatible(stream)[source]

Determine quickly whether this backend can load an object from this stream

classmethod check_magic_compatibility(stream)[source]

Check if a stream of bytes contains the same magic number as the main object

classmethod check_compatibility(spec, obj)[source]

Performs a minimal static load of spec and returns whether it’s compatible with other_obj

MZ load modules use a canonical 20-bit linear analysis space. Their linked base is zero, so default loading preserves the relative segment words stored in the image. A paragraph-aligned base_addr together with force_rebase=True models a concrete DOS load segment and applies every header relocation to the corresponding word.

The single load-module segment includes the minimum allocation requested by the header in its memory size. Only bytes declared by the executable are backed; the Program Segment Prefix, uninitialized allocation, trailing overlays, and other DOS runtime state are not synthesized.

class cle.backends.mz.MZ[source]

Bases: Backend

Loader for ordinary 8086 DOS MZ executables.

The load module is represented in a canonical 20-bit linear address space: segment * 16 + offset. The Program Segment Prefix and runtime-selected extra allocation beyond the header’s required minimum are not materialized.

is_default = True
__init__(*args, **kwargs)[source]
Parameters:
  • binary – The path to the binary to load

  • binary_stream – The open stream to this binary. The reference to this will be held until you call close.

  • is_main_bin – Whether this binary should be loaded as the main executable

property mapped_address_bits: int

Width of the flat address space CLE uses for this object’s mappings.

property load_segment: int
property initial_stack: int

SP.

Type:

The canonical linear address corresponding to the initial SS

property initial_cs_value: int

The CS register value after DOS adds the runtime load segment.

property initial_ss_value: int

The SS register value after DOS adds the runtime load segment.

rebase(new_base)[source]

Rebase backend’s regions to the new base where they were mapped by the loader

classmethod is_compatible(stream)[source]

Determine quickly whether this backend can load an object from this stream

classmethod check_magic_compatibility(stream)[source]

Check if a stream of bytes contains the same magic number as the main object

classmethod check_compatibility(spec, obj)[source]

Performs a minimal static load of spec and returns whether it’s compatible with other_obj

class cle.backends.mz.MZHeader[source]

Bases: object

The fixed DOS MZ executable header.

bytes_in_last_page: int
pages_in_file: int
relocation_count: int
header_paragraphs: int
minimum_extra_paragraphs: int
maximum_extra_paragraphs: int
initial_ss: int
initial_sp: int
checksum: int
initial_ip: int
initial_cs: int
relocation_table_offset: int
overlay_number: int
property header_size: int
property declared_file_size: int
property image_size: int
property image_paragraphs: int
property minimum_allocation_size: int

The memory DOS must find before it will start the program.

property maximum_allocation_size: int

The memory DOS gives the program when it has that much to spare.

property entry_rva: int | None

IP names no byte of it.

Type:

Offset of the entry point in the load module, or None if CS

property stack_rva: int | None

SP names nothing DOS would give the program.

The stack may sit one byte past the end of the allocation, because DOS starts a program with SP at the top of the block and every push decrements it first.

Type:

Offset of the initial stack, or None if SS

__init__(bytes_in_last_page: int, pages_in_file: int, relocation_count: int, header_paragraphs: int, minimum_extra_paragraphs: int, maximum_extra_paragraphs: int, initial_ss: int, initial_sp: int, checksum: int, initial_ip: int, initial_cs: int, relocation_table_offset: int, overlay_number: int) → None
Parameters:
  • bytes_in_last_page (int)

  • pages_in_file (int)

  • relocation_count (int)

  • header_paragraphs (int)

  • minimum_extra_paragraphs (int)

  • maximum_extra_paragraphs (int)

  • initial_ss (int)

  • initial_sp (int)

  • checksum (int)

  • initial_ip (int)

  • initial_cs (int)

  • relocation_table_offset (int)

  • overlay_number (int)

Return type:

None

class cle.backends.mz.MZRelocation[source]

Bases: Relocation

A DOS load-segment relocation applied to a word in the load module.

__init__(owner: MZ, offset: int, segment: int)[source]
Parameters:
offset
segment
property value: int
relocate()[source]

Applies this relocation. Will make changes to the memory object of the object it came from.

This implementation is a generic version that can be overridden in subclasses.