hookingo

package module
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 10 Imported by: 3

README

hookingo k2 changes

Go library for monkey patching This library has been forked from : https://github.com/fengyoulin/hookingo and contains changes with are proprietary to K2 Cyber Security Inc.

Compatibility

  • Go version: tested from go1.14 and above
  • Architectures: amd64
  • Operating systems: tested in macos, linux
Example
package main

import (
	"fmt"
	"github.com/k2io/hookingo"
)

func say1() {
	fmt.Printf("Hello k2\n")
}

func saywrap() {
	fmt.Printf("Hello k2 cyber\n")
	saywrap_s()
}
func saywrap_s() {
	fmt.Printf("Hello k2 cyber by _s\n")
}
func main() {
	h, e := hookingo.ApplyWrap(say1, saywrap,saywrap_s)
	if e != nil {
	fmt.Println("Unable to Hook ",e)
	}else if h == nil {
	    fmt.Println("Unable to Hook nil hookingo result")
	}
    say1()
}

Build the example with gcflags to prevent inline optimization:

go build -gcflags '-l' 

The example should output:

Hello k2 cyber
Hello k2

Documentation

Overview

Copyright (C) 2022 K2 Cyber Security Inc.

Copyright (C) 2022 K2 Cyber Security Inc.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrDoubleHook means already hooked
	ErrDoubleHook = errors.New("double hook")
	// ErrHookNotFound means the hook not found
	ErrHookNotFound = errors.New("hook not found")
	// ErrDifferentType means from and to are of different types
	ErrDifferentType = errors.New("inputs are of different type")
	// ErrInputType means inputs are not func type
	ErrInputType = errors.New("inputs are not func type")
	// ErrRelativeAddr means cannot call the origin function
	ErrRelativeAddr = errors.New("relative address in instruction")
)

Functions

func ApplyWrap

func ApplyWrap(from, to, toc interface{}) (*hook, error)

ApplyWrap is used to apply hooks on package public function

func ApplyWrapInterface

func ApplyWrapInterface(from, to, toc interface{}) (*hook, error)

HookWrapInterface is used to apply hooks on instance function

func ApplyWrapRaw

func ApplyWrapRaw(from uintptr, to, toc interface{}) (*hook, error)

ApplyWrapRaw is used to apply hooks on instance function

func GetSymbols

func GetSymbols(name string) (map[string]uintptr, error)

func SetDebug

func SetDebug(x bool)

Types

This section is empty.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL