Skip to content

Commit

Permalink
chore: change hash func return type
Browse files Browse the repository at this point in the history
  • Loading branch information
f1zm0 committed Apr 10, 2023
1 parent 4312610 commit 011fe8d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion acheron.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func New(opts ...Option) (*Acheron, error) {

// 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 {
func (a *Acheron) Syscall(fnHash uint64, args ...uintptr) error {
sys, err := a.resolver.GetSyscall(fnHash)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion internal/resolver/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
)

type Syscall struct {
NameHash int64
NameHash uint64
RVA uint32
VA uintptr
SSN uint16
Expand Down
2 changes: 1 addition & 1 deletion internal/resolver/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package resolver

type Resolver interface {
// GetSyscallSSN returns the syscall SSN.
GetSyscall(funcNameHash int64) (*Syscall, error)
GetSyscall(funcNameHash uint64) (*Syscall, error)
}
6 changes: 3 additions & 3 deletions internal/resolver/rvasort/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (

type ssnSortResolver struct {
hasher hashing.HashFunction
zwStubs map[int64]*resolver.Syscall
zwStubs map[uint64]*resolver.Syscall
cleanTrampolines []uintptr
}

Expand All @@ -35,7 +35,7 @@ func NewResolver(h hashing.HashFunction) (resolver.Resolver, error) {
}
}

r.zwStubs = make(map[int64]*resolver.Syscall, len(zwStubs))
r.zwStubs = make(map[uint64]*resolver.Syscall, len(zwStubs))
for idx, st := range zwStubs {
st.SSN = uint16(idx)

Expand All @@ -57,7 +57,7 @@ func NewResolver(h hashing.HashFunction) (resolver.Resolver, error) {
return r, nil
}

func (r *ssnSortResolver) GetSyscall(fnHash int64) (*resolver.Syscall, error) {
func (r *ssnSortResolver) GetSyscall(fnHash uint64) (*resolver.Syscall, error) {
if v, ok := r.zwStubs[fnHash]; ok {
return v, nil
}
Expand Down
9 changes: 4 additions & 5 deletions pkg/hashing/hashing.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package hashing

type HashFunction func([]byte) int64
type HashFunction func([]byte) uint64

// DJB2 hashing algorithm; ref: http://www.cse.yorku.ca/~oz/hash.html
func DJB2(s []byte) int64 {
var hash int64 = 5381
func DJB2(s []byte) uint64 {
var hash uint64 = 5381
for _, c := range s {
hash = ((hash << 5) + hash) + int64(c)
hash = ((hash << 5) + hash) + uint64(c)
}
return hash
}

0 comments on commit 011fe8d

Please sign in to comment.