Skip to content

Commit

Permalink
feat: add hash func helper in package entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
f1zm0 committed Apr 20, 2023
1 parent 26b26d7 commit 81bc1f4
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions acheron.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import (
"github.com/f1zm0/acheron/pkg/hashing"
)

// Acheron is the main struct of the acheron package.
type Acheron struct {
resolver resolver.Resolver
resolver resolver.Resolver
hashFunction hashing.HashFunction
}

type (
Expand Down Expand Up @@ -42,19 +44,25 @@ func New(opts ...Option) (*Acheron, error) {
return nil, err
} else {
return &Acheron{
resolver: r,
resolver: r,
hashFunction: options.hashFunction,
}, nil
}
}

// HashString is a helper function to hash a string which can be used as first arg for Syscall.
func (a *Acheron) HashString(s string) uint64 {
return a.hashFunction([]byte(s))
}

// Syscall executes an indirect syscall with the given function hash and arguments.
// Returns the error code returned by the syscall is something goes wrong.
func (a *Acheron) Syscall(fnHash uint64, args ...uintptr) error {
sys, err := a.resolver.GetSyscall(fnHash)
if err != nil {
return err
}
if errCode := execIndirectSyscall(sys.SSN, sys.TrampolineAddr, args...); errCode != 0 {
if errCode := execIndirectSyscall(sys.SSN, sys.TrampolineAddr, args...); errCode != 0 { // !NT_SUCCESS
return errors.New(fmt.Sprintf("syscall failed with error code %d", errCode))
}
return nil
Expand Down

0 comments on commit 81bc1f4

Please sign in to comment.