Phasor 3.1.1
Stack VM based Programming Language
Loading...
Searching...
No Matches
phasor.Native Namespace Reference

Functions

Tuple[int, str] _arch_info (binary)
Optional[object] _find_phasor_section (binary)
list[int] _find_all (bytes data, bytes pattern)
Optional[int] _find_payload_size (bytes sec_data, int sz_width, str endian)
bytes extract_phsb_bytes (Path path)

Variables

str _MAGIC_BYTES = b"\x50\x48\x53\x42"

Detailed Description

phasor.Native
==============
Extract bytecode from a ELF / PE / MachO binary.

Function Documentation

◆ _arch_info()

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.

Here is the caller graph for this function:

◆ _find_all()

list[int] phasor.Native._find_all ( bytes data,
bytes pattern )
protected
Return every byte offset at which *pattern* appears in *data*.

Args:
    data: The byte buffer to search.
    pattern: The byte sequence to look for.

Returns:
    A list of integer offsets in ascending order; empty if *pattern* is not found.

Definition at line 80 of file Native.py.

Here is the caller graph for this function:

◆ _find_payload_size()

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ _find_phasor_section()

Optional[object] phasor.Native._find_phasor_section ( binary)
protected
Locate the ``.phsb`` or ``phsb`` section in a parsed ``lief`` binary.

Checks top-level sections first; for MachO binaries it also searches
sections nested inside segments.

Args:
    binary: A ``lief.Binary`` instance (ELF, PE, or MachO).

Returns:
    The matching ``lief`` section object, or ``None`` if not found.

Definition at line 51 of file Native.py.

Here is the caller graph for this function:

◆ extract_phsb_bytes()

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.

Here is the call graph for this function:

Variable Documentation

◆ _MAGIC_BYTES

str phasor.Native._MAGIC_BYTES = b"\x50\x48\x53\x42"
protected

Definition at line 13 of file Native.py.