Implemented ELF header

This commit is contained in:
2023-10-17 20:29:36 +02:00
parent cae6696c3e
commit 4554fb82cb
7 changed files with 217 additions and 2 deletions

51
build/elf/elf.go Normal file
View File

@ -0,0 +1,51 @@
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)
}