elf

package
v0.5.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const Header64Size = 64

Header64Size is equal to the size of the ELF header in bytes.

View Source
const ProgramHeader64Size = 56

ProgramHeader64Size is equal to the size of a program header in bytes.

View Source
const SectionHeader64Size = 64

SectionHeader64Size is equal to the size of a section header in bytes.

Variables

This section is empty.

Functions

This section is empty.

Types

type ELF64

type ELF64 struct {
	Header64
	Programs []*Program
	Sections []*Section
}

ELF64 represents an ELF 64-bit file.

func New

func New(a *asm.Assembler) *ELF64

New creates a new 64-bit ELF binary.

func (*ELF64) AddProgram

func (elf *ELF64) AddProgram(data []byte, typ ProgramType, flags ProgramFlags)

AddProgram adds a section to the ELF file.

func (*ELF64) AddSection

func (elf *ELF64) AddSection(data []byte, typ SectionType, flags SectionFlags)

AddSection adds a section to the ELF file.

func (*ELF64) WriteToFile

func (elf *ELF64) WriteToFile(fileName string) error

WriteToFile writes the ELF binary to a file.

type Header64

type Header64 struct {
	Magic      [4]byte
	Class      byte
	Endianness byte
	Version    byte
	OSABI      byte
	ABIVersion byte

	Type                        int16
	Architecture                int16
	FileVersion                 int32
	EntryPointInMemory          int64
	ProgramHeaderOffset         int64
	SectionHeaderOffset         int64
	Flags                       int32
	Size                        int16
	ProgramHeaderEntrySize      int16
	ProgramHeaderEntryCount     int16
	SectionHeaderEntrySize      int16
	SectionHeaderEntryCount     int16
	SectionNameStringTableIndex int16
	// contains filtered or unexported fields
}

Header contains general information.

type Program

type Program struct {
	Header  ProgramHeader64
	Padding []byte
	Data    []byte
}

Program includes the machine-code instructions.

type ProgramFlags

type ProgramFlags int32
const (
	ProgramFlagsExecutable ProgramFlags = 0x1
	ProgramFlagsWritable   ProgramFlags = 0x2
	ProgramFlagsReadable   ProgramFlags = 0x4
)

type ProgramHeader64

type ProgramHeader64 struct {
	Type            ProgramType
	Flags           ProgramFlags
	Offset          int64
	VirtualAddress  int64
	PhysicalAddress int64
	SizeInFileImage int64
	SizeInMemory    int64
	Align           int64
}

ProgramHeader points to the executable part of our program.

type ProgramType

type ProgramType int32
const (
	ProgramTypeNULL    ProgramType = 0
	ProgramTypeLOAD    ProgramType = 1
	ProgramTypeDYNAMIC ProgramType = 2
	ProgramTypeINTERP  ProgramType = 3
	ProgramTypeNOTE    ProgramType = 4
	ProgramTypeSHLIB   ProgramType = 5
	ProgramTypePHDR    ProgramType = 6
	ProgramTypeTLS     ProgramType = 7 // Thread local storage segment
)

type Section

type Section struct {
	Header  SectionHeader64
	Padding []byte
	Data    []byte
}

Section includes the text data and initialized variables.

type SectionFlags

type SectionFlags int64
const (
	SectionFlagsWritable   SectionFlags = 0x1
	SectionFlagsAllocate   SectionFlags = 0x2
	SectionFlagsExecutable SectionFlags = 0x4
)

type SectionHeader64

type SectionHeader64 struct {
	NameOffset      int32
	Type            SectionType
	Flags           SectionFlags
	VirtualAddress  int64
	Offset          int64
	SizeInFileImage int64
	Link            int32
	Info            int32
	Align           int64
	EntrySize       int64
}

SectionHeader points to the data sections of our program.

type SectionType

type SectionType int32
const (
	SectionTypeNULL     SectionType = 0
	SectionTypePROGBITS SectionType = 1
	SectionTypeSYMTAB   SectionType = 2
	SectionTypeSTRTAB   SectionType = 3
	SectionTypeRELA     SectionType = 4
	SectionTypeHASH     SectionType = 5
	SectionTypeDYNAMIC  SectionType = 6
	SectionTypeNOTE     SectionType = 7
	SectionTypeNOBITS   SectionType = 8
	SectionTypeREL      SectionType = 9
	SectionTypeSHLIB    SectionType = 10
	SectionTypeDYNSYM   SectionType = 11
	SectionTypeNUM      SectionType = 12
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL