Skip to content

Commit

Permalink
Merge pull request #119 from ehids/msg-firendly
Browse files Browse the repository at this point in the history
document: message friendly
  • Loading branch information
cfc4n authored Jul 3, 2022
2 parents 67983eb + 64d9390 commit 463c36e
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 33 deletions.
2 changes: 1 addition & 1 deletion cli/cmd/bash.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func bashCommandFunc(command *cobra.Command, args []string) {

mod := user.GetModuleByName(user.MODULE_NAME_BASH)

logger := log.New(os.Stdout, "ecapture_", log.LstdFlags)
logger := log.New(os.Stdout, "bash_", log.LstdFlags)

logger.Printf("start to run %s module", mod.Name())

Expand Down
15 changes: 8 additions & 7 deletions cli/cmd/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func openSSLCommandFunc(command *cobra.Command, args []string) {
signal.Notify(stopper, os.Interrupt, syscall.SIGTERM)
ctx, cancelFun := context.WithCancel(context.TODO())

logger := log.New(os.Stdout, "ecapture_", log.LstdFlags)
logger := log.New(os.Stdout, "tls_", log.LstdFlags)

// save global config
gConf, e := getGlobalConf(command)
Expand All @@ -73,7 +73,7 @@ func openSSLCommandFunc(command *cobra.Command, args []string) {
for _, modName := range modNames {
mod := user.GetModuleByName(modName)
if mod == nil {
logger.Printf("cant found module: %s", modName)
logger.Printf("[eCapture]\tcant found module: %s", modName)
break
}

Expand All @@ -91,7 +91,7 @@ func openSSLCommandFunc(command *cobra.Command, args []string) {
}

if conf == nil {
logger.Printf("cant found module %s config info.", mod.Name())
logger.Printf("[eCapture]\tcant found module %s config info.", mod.Name())
break
}

Expand All @@ -101,27 +101,28 @@ func openSSLCommandFunc(command *cobra.Command, args []string) {
conf.SetHex(gConf.IsHex)
conf.SetNoSearch(gConf.NoSearch)

logger.Printf("start to init %s module", mod.Name())
logger.Printf("%s\tmodule initialization", mod.Name())
if e := conf.Check(); e != nil {
logger.Printf("%s module init failed. skip it. error:%+v", mod.Name(), e)
logger.Printf("%s\tmodule initialization failed. [skip it]. error:%+v", mod.Name(), e)
continue
}

//初始化
err := mod.Init(ctx, logger, conf)
if err != nil {
logger.Printf("%s module init failed, skip it. error:%+v", mod.Name(), err)
logger.Printf("%s\tmodule initialization failed, [skip it]. error:%+v", mod.Name(), err)
continue
}

// 加载ebpf,挂载到hook点上,开始监听
go func(module user.IModule) {
err := module.Run()
if err != nil {
logger.Printf("%s module run failed, skip it. error:%+v", module.Name(), err)
logger.Printf("%s\tmodule run failed, [skip it]. error:%+v", module.Name(), err)
return
}
}(mod)
logger.Printf("%s\tmodule started successfully.", mod.Name())
runMods++
}

Expand Down
3 changes: 1 addition & 2 deletions pkg/event_processor/iworker.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package event_processor

import (
"log"
"time"
)

Expand Down Expand Up @@ -73,7 +72,7 @@ func (this *eventWorker) Display() {
this.processor.GetLogger().Printf("UUID:%s, Name:%s, Length:%d", this.UUID, this.parser.Name(), len(b))

// TODO 格式化的终端输出
log.Println(string(this.parser.Display()))
this.processor.GetLogger().Println(string(this.parser.Display()))
// 重置状态
this.parser.Reset()

Expand Down
1 change: 0 additions & 1 deletion pkg/event_processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func (this *EventProcessor) init() {

// Write event 处理器读取事件
func (this *EventProcessor) Serve() {
this.logger.Printf("EventProcessor.Serve(): start")
for {
select {
case event := <-this.incoming:
Expand Down
4 changes: 1 addition & 3 deletions user/imodule.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,17 @@ func (this *Module) Name() string {
}

func (this *Module) Run() error {
this.logger.Printf("Module.Run() %s", this.Name())
this.logger.Printf("%s\tModule.Run()", this.Name())
// start
err := this.child.Start()
if err != nil {
return err
}
this.logger.Printf("Module.Run() %s start success", this.Name())

go func() {
this.run()
}()

this.logger.Printf("Module:%s run success.", this.child.Name())
go func() {
this.processor.Serve()
}()
Expand Down
12 changes: 6 additions & 6 deletions user/probe_bash.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,15 @@ func (this *MBashProbe) constantEditor() []manager.ConstantEditor {
}

if this.conf.GetPid() <= 0 {
this.logger.Printf("target all process. \n")
this.logger.Printf("%s\ttarget all process. \n", this.Name())
} else {
this.logger.Printf("target PID:%d \n", this.conf.GetPid())
this.logger.Printf("%s\ttarget PID:%d \n", this.Name(), this.conf.GetPid())
}

if this.conf.GetUid() <= 0 {
this.logger.Printf("target all users. \n")
this.logger.Printf("%s\ttarget all users. \n", this.Name())
} else {
this.logger.Printf("target UID:%d \n", this.conf.GetUid())
this.logger.Printf("%s\ttarget UID:%d \n", this.Name(), this.conf.GetUid())
}

return editor
Expand All @@ -120,8 +120,8 @@ func (this *MBashProbe) setupManagers() {
binaryPath = "/bin/bash"
}

this.logger.Printf("HOOK binrayPath:%s, FunctionName:readline\n", binaryPath)
this.logger.Printf("HOOK binrayPath:%s, FunctionName:execute_command\n", binaryPath)
this.logger.Printf("%s\tHOOK binrayPath:%s, FunctionName:readline\n", this.Name(), binaryPath)
this.logger.Printf("%s\tHOOK binrayPath:%s, FunctionName:execute_command\n", this.Name(), binaryPath)

this.bpfManager = &manager.Manager{
Probes: []*manager.Probe{
Expand Down
6 changes: 3 additions & 3 deletions user/probe_gnutls.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ func (this *MGnutlsProbe) constantEditor() []manager.ConstantEditor {
}

if this.conf.GetPid() <= 0 {
this.logger.Printf("target all process. \n")
this.logger.Printf("%s\ttarget all process. \n", this.Name())
} else {
this.logger.Printf("target PID:%d \n", this.conf.GetPid())
this.logger.Printf("%s\ttarget PID:%d \n", this.Name(), this.conf.GetPid())
}
return editor
}
Expand All @@ -114,7 +114,7 @@ func (this *MGnutlsProbe) setupManagers() error {
return err
}

this.logger.Printf("HOOK type:%d, binrayPath:%s\n", this.conf.(*GnutlsConfig).elfType, binaryPath)
this.logger.Printf("%s\tHOOK type:%d, binrayPath:%s\n", this.Name(), this.conf.(*GnutlsConfig).elfType, binaryPath)

this.bpfManager = &manager.Manager{
Probes: []*manager.Probe{
Expand Down
2 changes: 1 addition & 1 deletion user/probe_mysqld.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (this *MMysqldProbe) setupManagers() error {
},
}

this.logger.Printf("Mysql Version:%s, binrayPath:%s, FunctionName:%s ,UprobeOffset:%d\n", versionInfo, binaryPath, attachFunc, offset)
this.logger.Printf("%s\tMysql Version:%s, binrayPath:%s, FunctionName:%s ,UprobeOffset:%d\n", this.Name(), versionInfo, binaryPath, attachFunc, offset)

this.bpfManagerOptions = manager.Options{
DefaultKProbeMaxActive: 512,
Expand Down
6 changes: 3 additions & 3 deletions user/probe_nspr.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ func (this *MNsprProbe) constantEditor() []manager.ConstantEditor {
}

if this.conf.GetPid() <= 0 {
this.logger.Printf("target all process. \n")
this.logger.Printf("%s\ttarget all process. \n", this.Name())
} else {
this.logger.Printf("target PID:%d \n", this.conf.GetPid())
this.logger.Printf("%s\ttarget PID:%d \n", this.Name(), this.conf.GetPid())
}
return editor
}
Expand All @@ -113,7 +113,7 @@ func (this *MNsprProbe) setupManagers() error {
return err
}

this.logger.Printf("HOOK type:%d, binrayPath:%s\n", this.conf.(*NsprConfig).elfType, binaryPath)
this.logger.Printf("%s\tHOOK type:%d, binrayPath:%s\n", this.Name(), this.conf.(*NsprConfig).elfType, binaryPath)

this.bpfManager = &manager.Manager{
Probes: []*manager.Probe{
Expand Down
12 changes: 6 additions & 6 deletions user/probe_openssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,15 +101,15 @@ func (this *MOpenSSLProbe) constantEditor() []manager.ConstantEditor {
}

if this.conf.GetPid() <= 0 {
this.logger.Printf("target all process. \n")
this.logger.Printf("%s\ttarget all process. \n", this.Name())
} else {
this.logger.Printf("target PID:%d \n", this.conf.GetPid())
this.logger.Printf("%s\ttarget PID:%d \n", this.Name(), this.conf.GetPid())
}

if this.conf.GetUid() <= 0 {
this.logger.Printf("target all users. \n")
this.logger.Printf("%s\ttarget all users. \n", this.Name())
} else {
this.logger.Printf("target UID:%d \n", this.conf.GetUid())
this.logger.Printf("%s\ttarget UID:%d \n", this.Name(), this.conf.GetUid())
}

return editor
Expand All @@ -136,8 +136,8 @@ func (this *MOpenSSLProbe) setupManagers() error {
return err
}

this.logger.Printf("HOOK type:%d, binrayPath:%s\n", this.conf.(*OpensslConfig).elfType, binaryPath)
this.logger.Printf("libPthread so Path:%s\n", libPthread)
this.logger.Printf("%s\tHOOK type:%d, binrayPath:%s\n", this.Name(), this.conf.(*OpensslConfig).elfType, binaryPath)
this.logger.Printf("%s\tlibPthread so Path:%s\n", this.Name(), libPthread)

this.bpfManager = &manager.Manager{
Probes: []*manager.Probe{
Expand Down

0 comments on commit 463c36e

Please sign in to comment.