XU XUv0.16.0

#core/elf

import: #core/elf

counts: 1 functions, 16 methods, 8 types, 35 constants, 0 method sets

Pure zero-allocation ELF64 parser & validator for freestanding kernels.

const ELF_MAGIC

XuAPI
pub const ELF_MAGIC = 0x464C457F

Purpose

Constant ELF_MAGIC, defining protocol or algorithm parameters.

const ELFCLASS64

XuAPI
pub const ELFCLASS64 = 2

Purpose

Constant ELFCLASS64, defining protocol or algorithm parameters.

const ELFDATA2LSB

XuAPI
pub const ELFDATA2LSB = 1

Purpose

Constant ELFDATA2LSB, defining protocol or algorithm parameters.

const ET_EXEC

XuAPI
pub const ET_EXEC = 2

Purpose

Constant ET_EXEC, defining protocol or algorithm parameters.

const ET_DYN

XuAPI
pub const ET_DYN = 3

Purpose

Constant ET_DYN, defining protocol or algorithm parameters.

const EM_X86_64

XuAPI
pub const EM_X86_64 = 62

Purpose

Constant EM_X86_64, defining protocol or algorithm parameters.

const EM_AARCH64

XuAPI
pub const EM_AARCH64 = 183

Purpose

Constant EM_AARCH64, defining protocol or algorithm parameters.

const EM_RISCV

XuAPI
pub const EM_RISCV = 243

Purpose

Constant EM_RISCV, defining protocol or algorithm parameters.

const PT_NULL

XuAPI
pub const PT_NULL = 0

Purpose

Constant PT_NULL, defining protocol or algorithm parameters.

const PT_LOAD

XuAPI
pub const PT_LOAD = 1

Purpose

Constant PT_LOAD, defining protocol or algorithm parameters.

const PT_DYNAMIC

XuAPI
pub const PT_DYNAMIC = 2

Purpose

Constant PT_DYNAMIC, defining protocol or algorithm parameters.

const PT_INTERP

XuAPI
pub const PT_INTERP = 3

Purpose

Constant PT_INTERP, defining protocol or algorithm parameters.

const PT_NOTE

XuAPI
pub const PT_NOTE = 4

Purpose

Constant PT_NOTE, defining protocol or algorithm parameters.

const PT_PHDR

XuAPI
pub const PT_PHDR = 6

Purpose

Constant PT_PHDR, defining protocol or algorithm parameters.

const PT_TLS

XuAPI
pub const PT_TLS = 7

Purpose

Constant PT_TLS, defining protocol or algorithm parameters.

const PT_GNU_STACK

XuAPI
pub const PT_GNU_STACK = 0x6474E551

Purpose

Constant PT_GNU_STACK, defining protocol or algorithm parameters.

const PT_GNU_RELRO

XuAPI
pub const PT_GNU_RELRO = 0x6474E552

Purpose

Constant PT_GNU_RELRO, defining protocol or algorithm parameters.

const PF_X

XuAPI
pub const PF_X = 1

Purpose

Constant PF_X, defining protocol or algorithm parameters.

const PF_W

XuAPI
pub const PF_W = 2

Purpose

Constant PF_W, defining protocol or algorithm parameters.

const PF_R

XuAPI
pub const PF_R = 4

Purpose

Constant PF_R, defining protocol or algorithm parameters.

const DT_NULL

XuAPI
pub const DT_NULL = 0

Purpose

Constant DT_NULL, defining protocol or algorithm parameters.

const DT_RELA

XuAPI
pub const DT_RELA = 7

Purpose

Constant DT_RELA, defining protocol or algorithm parameters.

const DT_RELASZ

XuAPI
pub const DT_RELASZ = 8

Purpose

Constant DT_RELASZ, defining protocol or algorithm parameters.

const DT_RELAENT

XuAPI
pub const DT_RELAENT = 9

Purpose

Constant DT_RELAENT, defining protocol or algorithm parameters.

const DT_FLAGS

XuAPI
pub const DT_FLAGS = 30

Purpose

Constant DT_FLAGS, defining protocol or algorithm parameters.

const DT_FLAGS_1

XuAPI
pub const DT_FLAGS_1 = 0x6FFFFFFB

Purpose

Constant DT_FLAGS_1, defining protocol or algorithm parameters.

const R_X86_64_RELATIVE

XuAPI
pub const R_X86_64_RELATIVE = 8

Purpose

Constant R_X86_64_RELATIVE, defining protocol or algorithm parameters.

const R_AARCH64_RELATIVE

XuAPI
pub const R_AARCH64_RELATIVE = 1027

Purpose

Constant R_AARCH64_RELATIVE, defining protocol or algorithm parameters.

const R_RISCV_RELATIVE

XuAPI
pub const R_RISCV_RELATIVE = 3

Purpose

Constant R_RISCV_RELATIVE, defining protocol or algorithm parameters.

const SHT_NULL

XuAPI
pub const SHT_NULL = 0

Purpose

Constant SHT_NULL, defining protocol or algorithm parameters.

const SHT_PROGBITS

XuAPI
pub const SHT_PROGBITS = 1

Purpose

Constant SHT_PROGBITS, defining protocol or algorithm parameters.

const SHT_SYMTAB

XuAPI
pub const SHT_SYMTAB = 2

Purpose

Constant SHT_SYMTAB, defining protocol or algorithm parameters.

const SHT_STRTAB

XuAPI
pub const SHT_STRTAB = 3

Purpose

Constant SHT_STRTAB, defining protocol or algorithm parameters.

const SHT_NOBITS

XuAPI
pub const SHT_NOBITS = 8

Purpose

Constant SHT_NOBITS, defining protocol or algorithm parameters.

const STT_FUNC

XuAPI
pub const STT_FUNC = 2

Purpose

Constant STT_FUNC, defining protocol or algorithm parameters.

struct Elf64Ehdr

XuAPI
pub struct Elf64Ehdr {
    pub magic u32
    pub elf_class u8
    pub elf_data u8
    pub elf_version u8
    pub osabi u8
    pub pad0 u64
    pub e_type u16
    pub e_machine u16
    pub e_version u32
    pub e_entry u64
    pub e_phoff u64
    pub e_shoff u64
    pub e_flags u32
    pub e_ehsize u16
    pub e_phentsize u16
    pub e_phnum u16
    pub e_shentsize u16
    pub e_shnum u16
    pub e_shstrndx u16
}

Purpose

Structure encapsulating magic, elf_class, elf_data, elf_version, osabi.

Public fields

magic u32
field (u32)
elf_class u8
field (u8)
elf_data u8
field (u8)
elf_version u8
field (u8)
osabi u8
field (u8)
pad0 u64
field (u64)
e_type u16
field (u16)
e_machine u16
field (u16)
e_version u32
field (u32)
e_entry u64
field (u64)
e_phoff u64
field (u64)
e_shoff u64
field (u64)
e_flags u32
field (u32)
e_ehsize u16
field (u16)
e_phentsize u16
field (u16)
e_phnum u16
field (u16)
e_shentsize u16
field (u16)
e_shnum u16
field (u16)
e_shstrndx u16
field (u16)

struct Elf64Phdr

XuAPI
pub struct Elf64Phdr {
    pub p_type u32
    pub p_flags u32
    pub p_offset u64
    pub p_vaddr u64
    pub p_paddr u64
    pub p_filesz u64
    pub p_memsz u64
    pub p_align u64
}

Purpose

Structure encapsulating p_type, p_flags, p_offset, p_vaddr, p_paddr.

Public fields

p_type u32
field (u32)
p_flags u32
field (u32)
p_offset u64
field (u64)
p_vaddr u64
field (u64)
p_paddr u64
field (u64)
p_filesz u64
field (u64)
p_memsz u64
field (u64)
p_align u64
field (u64)

struct Elf64Dyn

XuAPI
pub struct Elf64Dyn {
    pub d_tag i64
    pub d_val u64
}

Purpose

Structure encapsulating d_tag, d_val.

Public fields

d_tag i64
field (i64)
d_val u64
field (u64)

struct Elf64Rela

XuAPI
pub struct Elf64Rela {
    pub r_offset u64
    pub r_info u64
    pub r_addend i64
}

Purpose

Structure encapsulating r_offset, r_info, r_addend.

Public fields

r_offset u64
field (u64)
r_info u64
field (u64)
r_addend i64
field (i64)

struct Elf64Shdr

XuAPI
pub struct Elf64Shdr {
    pub sh_name u32
    pub sh_type u32
    pub sh_flags u64
    pub sh_addr u64
    pub sh_offset u64
    pub sh_size u64
    pub sh_link u32
    pub sh_info u32
    pub sh_addralign u64
    pub sh_entsize u64
}

Purpose

Structure encapsulating sh_name, sh_type, sh_flags, sh_addr, sh_offset.

Public fields

sh_name u32
field (u32)
sh_type u32
field (u32)
sh_flags u64
field (u64)
sh_addr u64
field (u64)
sh_offset u64
field (u64)
sh_size u64
field (u64)
sh_link u32
field (u32)
sh_info u32
field (u32)
sh_addralign u64
field (u64)
sh_entsize u64
field (u64)

struct Elf64Sym

XuAPI
pub struct Elf64Sym {
    pub st_name u32
    pub st_info u8
    pub st_other u8
    pub st_shndx u16
    pub st_value u64
    pub st_size u64
}

Purpose

Structure encapsulating st_name, st_info, st_other, st_shndx, st_value.

Public fields

st_name u32
field (u32)
st_info u8
field (u8)
st_other u8
field (u8)
st_shndx u16
field (u16)
st_value u64
field (u64)
st_size u64
field (u64)

struct Elf64Image

XuAPI
pub struct Elf64Image {
    pub data *raw u8
    pub len usize
}

Purpose

Structure encapsulating data, len.

Public fields

data *raw u8
data
len usize
field (usize)

struct Elf64TlsInfo

XuAPI
pub struct Elf64TlsInfo {
    pub file_off u64
    pub file_sz u64
    pub mem_sz u64
    pub align u64
    pub vaddr u64
}

Purpose

Structure encapsulating file_off, file_sz, mem_sz, align, vaddr.

Public fields

file_off u64
field (u64)
file_sz u64
field (u64)
mem_sz u64
field (u64)
align u64
field (u64)
vaddr u64
field (u64)

elf64_parse

XuAPI
pub fn elf64_parse(data *raw u8, len usize) Elf64Image

Purpose

Elf64 parse.

Parameters

data *raw u8
data (*raw u8)
len usize
len (usize)

Returns

Elf64Image — a value of this type

(&Elf64Image) ehdr

XuAPI
pub fn (img &Elf64Image) ehdr() *raw Elf64Ehdr

Purpose

Execute ehdr on &Elf64Image.

Parameters

img &Elf64Image
The Elf64Image instance used by this call (borrow).

Returns

*raw Elf64Ehdr — a value of this type

(&Elf64Image) validate_exec_or_pie

XuAPI
pub fn (img &Elf64Image) validate_exec_or_pie(expected_machine u16) bool

Purpose

Operation on &Elf64Image: validate exec or pie.

Parameters

img &Elf64Image
The Elf64Image instance used by this call (borrow).
expected_machine u16
expected_machine (u16)

Returns

bool — true or false

(&Elf64Image) is_pie

XuAPI
pub fn (img &Elf64Image) is_pie() bool

Purpose

Operation on &Elf64Image: whether it is pie.

Parameters

img &Elf64Image
The Elf64Image instance used by this call (borrow).

Returns

bool — true or false

(&Elf64Image) find_phdr

XuAPI
pub fn (img &Elf64Image) find_phdr(p_type u32) *raw Elf64Phdr

Purpose

Operation on &Elf64Image: find phdr.

Parameters

img &Elf64Image
The Elf64Image instance used by this call (borrow).
p_type u32
p_type (u32)

Returns

*raw Elf64Phdr — a value of this type

(&Elf64Image) has_wx_violation

XuAPI
pub fn (img &Elf64Image) has_wx_violation() bool

Purpose

Operation on &Elf64Image: whether it has wx violation.

Parameters

img &Elf64Image
The Elf64Image instance used by this call (borrow).

Returns

bool — true or false

(&Elf64Image) validate_exec

XuAPI
pub fn (img &Elf64Image) validate_exec(expected_machine u16) bool

Purpose

Operation on &Elf64Image: validate exec.

Parameters

img &Elf64Image
The Elf64Image instance used by this call (borrow).
expected_machine u16
expected_machine (u16)

Returns

bool — true or false

(&Elf64Image) entry

XuAPI
pub fn (img &Elf64Image) entry() u64

Purpose

Execute entry on &Elf64Image.

Parameters

img &Elf64Image
The Elf64Image instance used by this call (borrow).

Returns

u64 — a value of this type

(&Elf64Image) phdr_count

XuAPI
pub fn (img &Elf64Image) phdr_count() int

Purpose

Operation on &Elf64Image: phdr count.

Parameters

img &Elf64Image
The Elf64Image instance used by this call (borrow).

Returns

int — a value of this type

(&Elf64Image) phdr_at

XuAPI
pub fn (img &Elf64Image) phdr_at(idx int) *raw Elf64Phdr

Purpose

Operation on &Elf64Image: phdr at.

Parameters

img &Elf64Image
The Elf64Image instance used by this call (borrow).
idx int
idx (int)

Returns

*raw Elf64Phdr — a value of this type

(&Elf64Image) segment_valid

XuAPI
pub fn (img &Elf64Image) segment_valid(ph *raw Elf64Phdr) bool

Purpose

Operation on &Elf64Image: segment valid.

Parameters

img &Elf64Image
The Elf64Image instance used by this call (borrow).
ph *raw Elf64Phdr
ph (*raw Elf64Phdr)

Returns

bool — true or false

(&Elf64Image) segment_data

XuAPI
pub fn (img &Elf64Image) segment_data(ph *raw Elf64Phdr) *raw u8

Purpose

Operation on &Elf64Image: segment data.

Parameters

img &Elf64Image
The Elf64Image instance used by this call (borrow).
ph *raw Elf64Phdr
ph (*raw Elf64Phdr)

Returns

*raw u8 — a value of this type

(&Elf64Image) shdr_count

XuAPI
pub fn (img &Elf64Image) shdr_count() int

Purpose

Operation on &Elf64Image: shdr count.

Parameters

img &Elf64Image
The Elf64Image instance used by this call (borrow).

Returns

int — a value of this type

(&Elf64Image) shdr_at

XuAPI
pub fn (img &Elf64Image) shdr_at(idx int) *raw Elf64Shdr

Purpose

Operation on &Elf64Image: shdr at.

Parameters

img &Elf64Image
The Elf64Image instance used by this call (borrow).
idx int
idx (int)

Returns

*raw Elf64Shdr — a value of this type

(&Elf64Image) find_section_by_type

XuAPI
pub fn (img &Elf64Image) find_section_by_type(sh_type u32) *raw Elf64Shdr

Purpose

Operation on &Elf64Image: find section by type.

Parameters

img &Elf64Image
The Elf64Image instance used by this call (borrow).
sh_type u32
sh_type (u32)

Returns

*raw Elf64Shdr — a value of this type

(&Elf64Image) resolve_symbol

XuAPI
pub fn (img &Elf64Image) resolve_symbol(addr u64, out_sym_addr *raw u64) *raw u8

Purpose

Operation on &Elf64Image: resolve symbol.

Parameters

img &Elf64Image
The Elf64Image instance used by this call (borrow).
addr u64
address (u64)
out_sym_addr *raw u64
out_sym_addr (*raw u64)

Returns

*raw u8 — a value of this type

(&Elf64Image) tls_info

XuAPI
pub fn (img &Elf64Image) tls_info(out *raw Elf64TlsInfo) bool

Purpose

Operation on &Elf64Image: tls info.

Parameters

img &Elf64Image
The Elf64Image instance used by this call (borrow).
out *raw Elf64TlsInfo
out (*raw Elf64TlsInfo)

Returns

bool — true or false