structstd.macho.LoadCommandIterator.LoadCommand[src]

Fields

hdr: load_command
data: []const u8

Functions

Functioncmd[src]

pub fn cmd(lc: LoadCommand) LC

Parameters

Source Code

Source code
pub fn cmd(lc: LoadCommand) LC {
    return lc.hdr.cmd;
}

Functioncmdsize[src]

pub fn cmdsize(lc: LoadCommand) u32

Parameters

Source Code

Source code
pub fn cmdsize(lc: LoadCommand) u32 {
    return lc.hdr.cmdsize;
}

Functioncast[src]

pub fn cast(lc: LoadCommand, comptime Cmd: type) ?Cmd

Parameters

Cmd: type

Source Code

Source code
pub fn cast(lc: LoadCommand, comptime Cmd: type) ?Cmd {
    if (lc.data.len < @sizeOf(Cmd)) return null;
    return @as(*align(1) const Cmd, @ptrCast(lc.data.ptr)).*;
}

FunctiongetSections[src]

pub fn getSections(lc: LoadCommand) []align(1) const section_64

Asserts LoadCommand is of type segment_command_64.

Parameters

Source Code

Source code
pub fn getSections(lc: LoadCommand) []align(1) const section_64 {
    const segment_lc = lc.cast(segment_command_64).?;
    if (segment_lc.nsects == 0) return &[0]section_64{};
    const data = lc.data[@sizeOf(segment_command_64)..];
    const sections = @as([*]align(1) const section_64, @ptrCast(data.ptr))[0..segment_lc.nsects];
    return sections;
}

FunctiongetDylibPathName[src]

pub fn getDylibPathName(lc: LoadCommand) []const u8

Asserts LoadCommand is of type dylib_command.

Parameters

Source Code

Source code
pub fn getDylibPathName(lc: LoadCommand) []const u8 {
    const dylib_lc = lc.cast(dylib_command).?;
    const data = lc.data[dylib_lc.dylib.name..];
    return mem.sliceTo(data, 0);
}

FunctiongetRpathPathName[src]

pub fn getRpathPathName(lc: LoadCommand) []const u8

Asserts LoadCommand is of type rpath_command.

Parameters

Source Code

Source code
pub fn getRpathPathName(lc: LoadCommand) []const u8 {
    const rpath_lc = lc.cast(rpath_command).?;
    const data = lc.data[rpath_lc.path..];
    return mem.sliceTo(data, 0);
}

FunctiongetBuildVersionTools[src]

pub fn getBuildVersionTools(lc: LoadCommand) []align(1) const build_tool_version

Asserts LoadCommand is of type build_version_command.

Parameters

Source Code

Source code
pub fn getBuildVersionTools(lc: LoadCommand) []align(1) const build_tool_version {
    const build_lc = lc.cast(build_version_command).?;
    const ntools = build_lc.ntools;
    if (ntools == 0) return &[0]build_tool_version{};
    const data = lc.data[@sizeOf(build_version_command)..];
    const tools = @as([*]align(1) const build_tool_version, @ptrCast(data.ptr))[0..ntools];
    return tools;
}

Source Code

Source code
pub const LoadCommand = struct {
    hdr: load_command,
    data: []const u8,

    pub fn cmd(lc: LoadCommand) LC {
        return lc.hdr.cmd;
    }

    pub fn cmdsize(lc: LoadCommand) u32 {
        return lc.hdr.cmdsize;
    }

    pub fn cast(lc: LoadCommand, comptime Cmd: type) ?Cmd {
        if (lc.data.len < @sizeOf(Cmd)) return null;
        return @as(*align(1) const Cmd, @ptrCast(lc.data.ptr)).*;
    }

    /// Asserts LoadCommand is of type segment_command_64.
    pub fn getSections(lc: LoadCommand) []align(1) const section_64 {
        const segment_lc = lc.cast(segment_command_64).?;
        if (segment_lc.nsects == 0) return &[0]section_64{};
        const data = lc.data[@sizeOf(segment_command_64)..];
        const sections = @as([*]align(1) const section_64, @ptrCast(data.ptr))[0..segment_lc.nsects];
        return sections;
    }

    /// Asserts LoadCommand is of type dylib_command.
    pub fn getDylibPathName(lc: LoadCommand) []const u8 {
        const dylib_lc = lc.cast(dylib_command).?;
        const data = lc.data[dylib_lc.dylib.name..];
        return mem.sliceTo(data, 0);
    }

    /// Asserts LoadCommand is of type rpath_command.
    pub fn getRpathPathName(lc: LoadCommand) []const u8 {
        const rpath_lc = lc.cast(rpath_command).?;
        const data = lc.data[rpath_lc.path..];
        return mem.sliceTo(data, 0);
    }

    /// Asserts LoadCommand is of type build_version_command.
    pub fn getBuildVersionTools(lc: LoadCommand) []align(1) const build_tool_version {
        const build_lc = lc.cast(build_version_command).?;
        const ntools = build_lc.ntools;
        if (ntools == 0) return &[0]build_tool_version{};
        const data = lc.data[@sizeOf(build_version_command)..];
        const tools = @as([*]align(1) const build_tool_version, @ptrCast(data.ptr))[0..ntools];
        return tools;
    }
}