Skip to content

Commit

Permalink
chore: cleanup and add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
f1zm0 committed Apr 20, 2023
1 parent f6ded30 commit 68036a7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
25 changes: 11 additions & 14 deletions acheron.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,17 @@ type Acheron struct {
hashFunction hashing.HashFunction
}

type (
// Option is a configuration option to configure the Acheron instance.
Option func(*options)
)
// Option is a configuration option to configure the Acheron instance.
type Option func(*options)

type options struct {
hashFunction hashing.HashFunction
}

// WithHashFunction returns an Option that sets a custom hashing or obfuscation function.
func WithHashFunction(f hashing.HashFunction) Option {
return func(o *options) {
o.hashFunction = f
}
}

// New returns a new Acheron instance with the given options, or an error if initialization fails.
func New(opts ...Option) (*Acheron, error) {
options := &options{
hashFunction: hashing.DJB2,
hashFunction: hashing.DJB2, // default
}
for _, o := range opts {
o(options)
Expand All @@ -50,13 +41,19 @@ func New(opts ...Option) (*Acheron, error) {
}
}

// WithHashFunction returns an Option that sets a custom hashing or obfuscation function.
func WithHashFunction(f hashing.HashFunction) Option {
return func(o *options) {
o.hashFunction = f
}
}

// 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.
// 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 {
sys, err := a.resolver.GetSyscall(fnHash)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion internal/resolver/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,5 @@ func ParseNtdllModule(hashFn hashing.HashFunction) []*Syscall {
})
}
}

return sysStubs
}
1 change: 1 addition & 0 deletions internal/resolver/rvasort/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type ssnSortResolver struct {

var _ resolver.Resolver = (*ssnSortResolver)(nil)

// NewResolver returns a new resolver that uses the given hash function to resolve syscalls SSNs.
func NewResolver(h hashing.HashFunction) (resolver.Resolver, error) {
r := &ssnSortResolver{
hasher: h,
Expand Down

0 comments on commit 68036a7

Please sign in to comment.