# MetaTrader compiled programs (EX4 and EX5) `inspect-artifact` and `extract-artifact` recognize a MetaTrader 4 compiled MQL4 program (`.ex4`, magic `EX-`) and a MetaTrader 5 compiled MQL5 program (`.ex5`, magic `EX5`), under any file name. Both share one header and resource table layout and report format `mql-program`. REA reads the plaintext header and resource table offline. It reports the program type, the build value, the `copyright`, `link` and `version` properties, and where the code body and embedded resources are stored. It does not decrypt, decompress, disassemble or decompile the body or the resources, and it does not run the program. ```sh rea inspect-artifact ./Expert.ex5 --json rea extract-artifact ./Indicator.ex4 --json ``` MetaQuotes does not publish this layout. REA's reading was established from 28 `.ex4` programs (build value 2421) and 170 `.ex5` programs (builds 3802, 3808 and 6275), with the matching `.mq4` and `.mq5` sources. Fields whose meaning is not established are reported raw rather than named. ## Program facts Root `format_metadata` has kind `mql-program`: | Field | Meaning | | ----------------------- | ----------------------------------------------------------------------------------------------------------- | | `container` | `ex4` or `ex5`, from the magic | | `program_type` | From the type byte at offset 3; see below. An unobserved code is `unknown` | | `program_type_code` | The type byte as stored | | `build` | The u16 at offset 0x06 | | `properties` | `copyright`, `link` and `version` slots, each with its `offset`, `state` and `text` | | `body` | `offset` and `length` of the opaque span from 0x2E8 to the resource table, or to the end of the file | | `resource_count` | Declared resource records | | `resource_section` | `offset` and `length` of the resource table and payloads, or null without resources | | `unknown_header_fields` | Nonzero header values of unknown meaning, with their `offset`, `width` and `value`; omitted fields are zero | Type codes 1, 2 and 4 are `script`, `expert` and `indicator` in both containers. Code 3 is `library` in EX4; no EX5 library was examined, so code 3 in EX5 is `unknown`. For EX5, `build` matched the build of the MetaTrader 5 terminal that compiled the samples. For EX4 it was 2421 while the MetaTrader 4 terminal reported build 1476, so its meaning there is not established. `copyright` and `link` are 256-byte UTF-16LE slots at 0xA8 and 0x1A8; `version` is a 64-byte slot at 0x2A8. A slot's `state` is `declared`, `empty` when the program did not declare it, or `malformed` when the slot is not well-formed UTF-16LE; `text` is null unless the state is `declared`. The header blocks at 0x20 to 0x2F and 0x78 to 0xA7 are opaque and are not reported. `#property description`, inputs, function names and other source facts are not in the readable header. Recovering them would require decrypting the body, which REA does not do. ## Stored ranges Inventory lists the body as `body.stored` and each resource payload as `resources/NNNN.stored`, in table order. Each entry carries kind `mql-program-entry` metadata: | Field | Meaning | | --------------- | ---------------------------------------------------------------------------------------- | | `role` | `body` or `resource` | | `table_index` | Position in the resource table; null for the body | | `name` | Resource name as declared, such as `res\Close.bmp`; null for the body or when ill-formed | | `resource_kind` | Record field 0x0C; 2 for every bitmap observed | | `record_index` | Record field 0x10; its ordering is unknown | | `unpacked_size` | Declared size before the stored encoding | `compare-artifacts` compares each resource's `name`, `resource_kind`, `record_index` and `unpacked_size`, which the resource table declares outside the stored payload, so a changed declaration is reported even when the payload bytes match. The body declares nothing beyond its bytes. `extract-artifact` writes the stored bytes unchanged. A resource payload is not the original file: its stored size is smaller than `unpacked_size` and its encoding is unknown, so it is named `.stored` rather than after the resource. ## Failures and limitations A file shorter than the 0x2E8-byte header, or a resource table that starts inside the header, ends past the file, or whose declared section does not end at the end of the file, is refused with its offset and field. A payload range that ends past the file is omitted and reported as a limitation, and coverage becomes `unknown`. A program declaring more than 65,536 resources is refused at the fixed MQL program resource record allowance; see [analysis settings, limits, and recovery](../../reference/limits-and-recovery.md).