Skip to content

Commit

Permalink
chore: move lib functions to entrypoint file
Browse files Browse the repository at this point in the history
  • Loading branch information
f1zm0 committed Apr 10, 2023
1 parent 9e2294c commit 88edc76
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
30 changes: 25 additions & 5 deletions acheron.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package acheron

import (
"errors"
"fmt"

"github.com/f1zm0/acheron/internal/resolver"
"github.com/f1zm0/acheron/internal/resolver/rvasort"
"github.com/f1zm0/acheron/pkg/hashing"
Expand All @@ -19,6 +22,14 @@ type options struct {
hasher hashing.HashFunction
}

// WithHashFunction returns an Option that sets a custom hashing (or obfuscation)
// function that will be used when resolving native api procedures by hash.
func WithHashFunction(f hashing.HashFunction) Option {
return func(o *options) {
o.hasher = f
}
}

// New returns a new Acheron instance that can be used as a proxy to perform
// indirect syscalls for native api functions, or an error if the initialization fails.
func New(opts ...Option) (*Acheron, error) {
Expand All @@ -38,10 +49,19 @@ func New(opts ...Option) (*Acheron, error) {
}
}

// WithHashFunction returns an Option that sets a custom hashing (or obfuscation)
// function that will be used when resolving native api procedures by hash.
func WithHashFunction(f hashing.HashFunction) Option {
return func(o *options) {
o.hasher = f
// Syscall executes a syscall with the given function hash and arguments.
// Returns the error code and an error if the syscall failed.
func (a *Acheron) Syscall(fnHash int64, args ...uintptr) error {
sys, err := a.resolver.GetSyscall(fnHash)
if err != nil {
return err
}
if errCode := execIndirectSyscall(sys.SSN, sys.TrampolineAddr, args...); errCode != 0 {
return errors.New(fmt.Sprintf("syscall failed with error code %d", errCode))
}
return nil
}

// execIndirectSyscall function signature for go-asm impelementation.
// returns 0 if the syscall was successful or an error code if the operation failed.
func execIndirectSyscall(ssn uint16, gateAddr uintptr, argh ...uintptr) (errcode uint32)
23 changes: 0 additions & 23 deletions syscall.go

This file was deleted.

0 comments on commit 88edc76

Please sign in to comment.