Improved section offset calculation
This commit is contained in:
@ -8,7 +8,10 @@ import (
|
||||
|
||||
"git.akyoto.dev/cli/q/src/config"
|
||||
"git.akyoto.dev/cli/q/src/dll"
|
||||
"git.akyoto.dev/cli/q/src/elf"
|
||||
"git.akyoto.dev/cli/q/src/fs"
|
||||
"git.akyoto.dev/cli/q/src/macho"
|
||||
"git.akyoto.dev/cli/q/src/pe"
|
||||
"git.akyoto.dev/cli/q/src/sizeof"
|
||||
"git.akyoto.dev/cli/q/src/x64"
|
||||
)
|
||||
@ -370,21 +373,40 @@ restart:
|
||||
}
|
||||
}
|
||||
|
||||
headerEnd := Address(0)
|
||||
|
||||
switch config.TargetOS {
|
||||
case "linux":
|
||||
headerEnd = elf.HeaderEnd
|
||||
case "macos":
|
||||
headerEnd = macho.HeaderEnd
|
||||
case "windows":
|
||||
headerEnd = pe.HeaderEnd
|
||||
}
|
||||
|
||||
codeStart, _ := fs.Align(headerEnd, config.Align)
|
||||
dataStart, _ := fs.Align(codeStart+Address(len(code)), config.Align)
|
||||
data, dataLabels = a.Data.Finalize()
|
||||
dataStart := config.BaseAddress + config.CodeOffset + len(code)
|
||||
dataStart, _ = fs.Align(dataStart, config.Align)
|
||||
|
||||
for _, pointer := range dataPointers {
|
||||
address := Address(dataStart) + pointer.Resolve()
|
||||
address := config.BaseAddress + Address(dataStart) + pointer.Resolve()
|
||||
slice := code[pointer.Position : pointer.Position+4]
|
||||
binary.LittleEndian.PutUint32(slice, uint32(address))
|
||||
}
|
||||
|
||||
for _, pointer := range dllPointers {
|
||||
destination := Address(0x3000) + pointer.Resolve()
|
||||
address := destination - Address(config.CodeOffset+pointer.Position+Address(pointer.Size))
|
||||
slice := code[pointer.Position : pointer.Position+4]
|
||||
binary.LittleEndian.PutUint32(slice, uint32(address))
|
||||
if config.TargetOS == "windows" {
|
||||
if len(data) == 0 {
|
||||
data = []byte{0}
|
||||
}
|
||||
|
||||
importsStart, _ := fs.Align(dataStart+Address(len(data)), config.Align)
|
||||
|
||||
for _, pointer := range dllPointers {
|
||||
destination := Address(importsStart) + pointer.Resolve()
|
||||
delta := destination - Address(codeStart+pointer.Position+Address(pointer.Size))
|
||||
slice := code[pointer.Position : pointer.Position+4]
|
||||
binary.LittleEndian.PutUint32(slice, uint32(delta))
|
||||
}
|
||||
}
|
||||
|
||||
return code, data
|
||||
|
Reference in New Issue
Block a user