mirror of
https://github.com/lukaszraczylo/go-obfuscation.git
synced 2026-10-14 05:48:22 +00:00
Initial commit
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package syscallobf
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"encoding/binary"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
dispatchKey uint64
|
||||
dispatchOnce sync.Once
|
||||
)
|
||||
|
||||
func initDispatchKey() {
|
||||
dispatchOnce.Do(func() {
|
||||
var buf [8]byte
|
||||
rand.Read(buf[:])
|
||||
dispatchKey = binary.LittleEndian.Uint64(buf[:])
|
||||
if dispatchKey == 0 {
|
||||
dispatchKey = 0xDEADBEEFCAFEBABE
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func EncodeTrap(num uintptr) uintptr {
|
||||
initDispatchKey()
|
||||
return uintptr(uint64(num) ^ dispatchKey)
|
||||
}
|
||||
|
||||
func DecodeTrap(encoded uintptr) uintptr {
|
||||
return uintptr(uint64(encoded) ^ dispatchKey)
|
||||
}
|
||||
|
||||
type encodedSyscall struct {
|
||||
encoded uintptr
|
||||
}
|
||||
|
||||
func NewEncodedSyscall(num uintptr) encodedSyscall {
|
||||
return encodedSyscall{encoded: EncodeTrap(num)}
|
||||
}
|
||||
|
||||
func (e encodedSyscall) Trap() uintptr {
|
||||
return DecodeTrap(e.encoded)
|
||||
}
|
||||
Reference in New Issue
Block a user