52 lines
1.2 KiB
Go
Raw Normal View History

2023-10-17 18:29:36 +00:00
package elf
import (
"encoding/binary"
"io"
)
const (
baseAddress = 0x400000
programAlign = 16
sectionAlign = 16
)
// ELF64 represents an ELF 64-bit file.
type ELF64 struct {
Header
}
// New creates a new 64-bit ELF binary.
func New() *ELF64 {
elf := &ELF64{
Header: Header{
Magic: [4]byte{0x7F, 'E', 'L', 'F'},
Class: 2,
Endianness: LittleEndian,
Version: 1,
OSABI: 0,
ABIVersion: 0,
Type: TypeExecutable,
Architecture: ArchitectureAMD64,
FileVersion: 1,
EntryPointInMemory: 0,
ProgramHeaderOffset: HeaderSize,
SectionHeaderOffset: 0, // TODO
Flags: 0,
Size: HeaderSize,
ProgramHeaderEntrySize: ProgramHeaderSize,
ProgramHeaderEntryCount: 0,
SectionHeaderEntrySize: SectionHeaderSize,
SectionHeaderEntryCount: 0,
SectionNameStringTableIndex: 0,
},
}
return elf
}
// Write writes the ELF64 format to the given writer.
func (elf *ELF64) Write(writer io.Writer) {
binary.Write(writer, binary.LittleEndian, &elf.Header)
}