Improved segment load

This commit is contained in:
Eduard Urbach 2024-08-12 12:47:09 +02:00
parent cf52919edc
commit 985fa5ae14
Signed by: akyoto
GPG Key ID: C874F672B1AF20C0

View File

@ -52,8 +52,9 @@ func (m *MachO) Write(writer io.Writer) {
InitProt: 0,
})
codeStart := 32 + m.Header.SizeCommands
codeEnd := uint64(codeStart) + uint64(len(m.Code))
codeStart := uint64(32 + m.Header.SizeCommands)
codeLength := uint64(len(m.Code))
codeEnd := codeStart + codeLength
dataPadding := elf.Padding(codeEnd, 4096)
dataStart := codeEnd + dataPadding
@ -61,13 +62,13 @@ func (m *MachO) Write(writer io.Writer) {
LoadCommand: LcSegment64,
Length: 0x48,
Name: [16]byte{'_', '_', 'T', 'E', 'X', 'T'},
Address: config.BaseAddress,
SizeInMemory: codeEnd,
Address: config.BaseAddress + codeStart,
SizeInMemory: codeLength,
Offset: 0,
SizeInFile: codeEnd,
SizeInFile: codeLength,
NumSections: 0,
Flag: 0,
MaxProt: ProtReadable | ProtWritable | ProtExecutable,
MaxProt: ProtReadable | ProtExecutable,
InitProt: ProtReadable | ProtExecutable,
})