Skip to content

Commit

Permalink
feat!: change signature for syscall func
Browse files Browse the repository at this point in the history
  • Loading branch information
f1zm0 committed Apr 24, 2023
1 parent e040b8a commit 89ce53c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
23 changes: 12 additions & 11 deletions acheron.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type options struct {
}

// stub for asm implementation
func execIndirectSyscall(ssn uint16, gateAddr uintptr, argh ...uintptr) (errcode uint32)
func execIndirectSyscall(ssn uint16, gateAddr uintptr, argh ...uintptr) uint32

// New returns a new Acheron instance with the given options, or an error if initialization fails.
func New(opts ...Option) (*Acheron, error) {
Expand Down Expand Up @@ -58,20 +58,21 @@ func (a *Acheron) HashString(s string) uint64 {
// GetSyscall returns the Syscall struct for the given function hash.
func (a *Acheron) GetSyscall(fnHash uint64) (*resolver.Syscall, error) {
if sys := a.resolver.GetSyscall(fnHash); sys == nil {
return nil, fmt.Errorf("failed with code: %d", ErrSyscallNotFound)
return nil, fmt.Errorf("failed with code: 0x%x", ErrSyscallNotFound)
} else {
return sys, nil
}
}

// Syscall executes an indirect syscall with the given function hash and arguments. Returns the error code if it fails.
func (a *Acheron) Syscall(fnHash uint64, args ...uintptr) error {
if sys := a.resolver.GetSyscall(fnHash); sys == nil {
return fmt.Errorf("failed with: %d", ErrSyscallNotFound)
} else {
if st := execIndirectSyscall(sys.SSN, sys.TrampolineAddr, args...); !NT_SUCCESS(st) {
return fmt.Errorf("failed with: %d", st)
}
// Syscall makes an indirect syscall with the provided arguments. Returns the status code and an error message if it fails.
func (a *Acheron) Syscall(fnHash uint64, args ...uintptr) (uint32, error) {
sys := a.resolver.GetSyscall(fnHash)
if sys == nil {
return ErrSyscallNotFound, fmt.Errorf("failed with: 0x%x", ErrSyscallNotFound)
}
st := execIndirectSyscall(sys.SSN, sys.TrampolineAddr, args...)
if !NT_SUCCESS(st) {
return st, fmt.Errorf("failed with code: 0x%x", st)
}
return nil
return st, nil
}
4 changes: 2 additions & 2 deletions syscall_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
// but we use an unsigned integer instead of LONG (int32), since working with uint types is easier in Go


// func execIndirectSyscall(ssn uint16, trampoline uintptr, argh ...uintptr) (errcode uint32)
TEXT ·execIndirectSyscall(SB),NOSPLIT, $0-144
// func execIndirectSyscall(ssn uint16, trampoline uintptr, argh ...uintptr) uint32
TEXT ·execIndirectSyscall(SB),NOSPLIT, $0-40
XORQ AX, AX
MOVW ssn+0(FP), AX

Expand Down

0 comments on commit 89ce53c

Please sign in to comment.