Added memory address patching

This commit is contained in:
2023-10-29 12:24:40 +01:00
parent d6be76b85a
commit fbe6aa80bb
9 changed files with 98 additions and 35 deletions

View File

@ -3,11 +3,8 @@ package elf
import (
"encoding/binary"
"io"
)
const (
minAddress = 0x10000
baseAddress = 0x40 * minAddress
"git.akyoto.dev/cli/q/src/config"
)
// ELF represents an ELF file.
@ -31,7 +28,7 @@ func New(code []byte, data []byte) *ELF {
Type: TypeExecutable,
Architecture: ArchitectureAMD64,
FileVersion: 1,
EntryPointInMemory: baseAddress + 0x80,
EntryPointInMemory: config.BaseAddress + config.CodeOffset,
ProgramHeaderOffset: HeaderSize,
SectionHeaderOffset: 0,
Flags: 0,
@ -45,12 +42,12 @@ func New(code []byte, data []byte) *ELF {
ProgramHeader: ProgramHeader{
Type: ProgramTypeLOAD,
Flags: ProgramFlagsExecutable,
Offset: 0x80,
VirtualAddress: baseAddress + 0x80,
PhysicalAddress: baseAddress + 0x80,
Offset: config.CodeOffset,
VirtualAddress: config.BaseAddress + config.CodeOffset,
PhysicalAddress: config.BaseAddress + config.CodeOffset,
SizeInFile: int64(len(code)),
SizeInMemory: int64(len(code)),
Align: Align,
Align: config.Align,
},
Code: code,
Data: data,

View File

@ -5,7 +5,6 @@ const (
TypeExecutable = 2
ArchitectureAMD64 = 0x3E
HeaderSize = 64
Align = 16
)
// Header contains general information.