Added memory address patching

This commit is contained in:
Eduard Urbach 2023-10-29 12:24:40 +01:00
parent 6f097c9eee
commit 23e8b67e88
Signed by: eduard
GPG key ID: 49226B848C78F6C8
9 changed files with 98 additions and 35 deletions

View file

@ -43,8 +43,16 @@ func (build *Build) Run() error {
a.MoveRegisterNumber(register.Syscall0, syscall.Write)
a.MoveRegisterNumber(register.Syscall1, 1)
a.MoveRegisterNumber(register.Syscall2, 0x4000a2)
a.MoveRegisterNumber(register.Syscall3, 6)
hello := []byte("Hello\n")
a.MoveRegisterData(register.Syscall2, hello)
a.MoveRegisterNumber(register.Syscall3, uint64(len(hello)))
a.Syscall()
a.MoveRegisterNumber(register.Syscall0, syscall.Write)
a.MoveRegisterNumber(register.Syscall1, 1)
world := []byte("World\n")
a.MoveRegisterData(register.Syscall2, world)
a.MoveRegisterNumber(register.Syscall3, uint64(len(world)))
a.Syscall()
a.MoveRegisterNumber(register.Syscall0, syscall.Exit)
@ -52,13 +60,12 @@ func (build *Build) Run() error {
a.Syscall()
result := a.Finalize()
result.Data.WriteString("Hello\n")
if !build.WriteExecutable {
return nil
}
return writeToDisk(build.Executable(), result.Code.Bytes(), result.Data.Bytes())
return writeToDisk(build.Executable(), result.Code, result.Data)
}
// Compile compiles all the functions.