phasor.Native
==============
Extract bytecode from a ELF / PE / MachO binary.
| Tuple[int, str] phasor.Native._arch_info |
( |
| binary | ) |
|
|
protected |
Detect the pointer width and byte order of a parsed ``lief`` binary.
Args:
binary: A ``lief.Binary`` instance (ELF, PE, or MachO).
Returns:
A ``(pointer_width, endian)`` tuple where *pointer_width* is ``4`` or ``8``
bytes and *endian* is ``"<"`` (little-endian) or ``">"`` (big-endian).
Falls back to ``(8, "<")`` if detection fails.
Definition at line 15 of file Native.py.
| Optional[int] phasor.Native._find_payload_size |
( |
bytes | sec_data, |
|
|
int | sz_width, |
|
|
str | endian ) |
|
protected |
Heuristically determine the bytecode payload size encoded in the ``.phsb`` section.
Scans *sec_data* for an integer field that plausibly encodes the length of a
contiguous non-zero region — the strategy used by the Phasor linker to store
the bytecode size alongside the payload.
Args:
sec_data: Raw bytes of the ``.phsb`` binary section.
sz_width: Width of the size field in bytes (``4`` or ``8``, from :func:`_arch_info`).
endian: Struct endian character (``"<"`` or ``">"``, from :func:`_arch_info`).
Returns:
The detected payload length in bytes, or ``None`` if no consistent size
field could be located.
Definition at line 100 of file Native.py.
| bytes phasor.Native.extract_phsb_bytes |
( |
Path | path | ) |
|
Extract the raw ``.phsb`` bytecode payload from a native binary.
Parses the ELF, PE, or MachO binary at *path* using ``lief``, locates the
``.phsb`` section, and returns the bytecode payload starting at the
:data:`_MAGIC_BYTES` marker.
Args:
path: Path to the compiled native binary.
Returns:
The raw ``.phsb`` bytes, suitable for passing to
:meth:`~phasor.Bytecode.Bytecode.from_bytes`.
Raises:
ImportError: If the ``lief`` package is not installed.
FileNotFoundError: If *path* does not exist.
RuntimeError: If the binary cannot be parsed, no ``.phsb`` section is
found, the PHSB magic bytes are absent, or the payload size cannot
be determined.
Definition at line 148 of file Native.py.