github.com/HXSecurity/DongTai-agent-go@v0.4.2/hook/hook.go (about)

     1  package hook
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/HXSecurity/DongTai-agent-go/model"
     6  )
     7  
     8  //此处为定义了Hook的注册方法和卸载方法
     9  
    10  func HookFunc(s string) {
    11  	if model.HookMap[s] == nil {
    12  		fmt.Println("尚未注册此HOOK:", s)
    13  	} else {
    14  		model.HookMap[s].Hook()
    15  	}
    16  }
    17  
    18  func UnHookFunc(s string) {
    19  	if model.HookMap[s] == nil {
    20  		fmt.Println("尚未注册此HOOK")
    21  	} else {
    22  		model.HookMap[s].UnHook()
    23  	}
    24  }
    25  
    26  func Hook(funcs []string) {
    27  	for i := range funcs {
    28  		HookFunc(funcs[i])
    29  	}
    30  }
    31  
    32  func UnHook(funcs []string) {
    33  	for i := range funcs {
    34  		UnHookFunc(funcs[i])
    35  	}
    36  }
    37  
    38  func HookAll(h ...model.HookStruct) {
    39  	for i := range h {
    40  		h[i].HookAll()
    41  	}
    42  }
    43  
    44  func UnHookAll(h ...model.HookStruct) {
    45  	for i := range h {
    46  		h[i].UnHookAll()
    47  	}
    48  }
    49  
    50  func RunAllHook() {
    51  	HookAll(
    52  		new(Base),
    53  		new(Gin),
    54  		new(Gorilla),
    55  		new(Gorm),
    56  		new(Http),
    57  		new(HttpRouter),
    58  	)
    59  }
    60  
    61  func StopAllHook() {
    62  	UnHookAll(
    63  		new(Base),
    64  		new(Gin),
    65  		new(Gorilla),
    66  		new(Gorm),
    67  		new(Http),
    68  		new(HttpRouter),
    69  	)
    70  }