Skip to content

Commit

Permalink
refactor: Use camel case instead of snake case.
Browse files Browse the repository at this point in the history
Signed-off-by: CFC4N <cfc4n.cs@gmail.com>
  • Loading branch information
cfc4n committed Feb 26, 2023
1 parent e5cc662 commit 3a813ac
Show file tree
Hide file tree
Showing 47 changed files with 379 additions and 379 deletions.
4 changes: 2 additions & 2 deletions cli/cmd/bash.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Auto find the bash of the current env as the capture target.`,
func init() {
bashCmd.PersistentFlags().StringVar(&bc.Bashpath, "bash", "", "$SHELL file path, eg: /bin/bash , will automatically find it from $ENV default.")
bashCmd.PersistentFlags().StringVar(&bc.Readline, "readlineso", "", "readline.so file path, will automatically find it from $BASH_PATH default.")
bashCmd.Flags().IntVarP(&bc.ErrNo, "errnumber", "e", module.BASH_ERRNO_DEFAULT, "only show the command which exec reulst equals err number.")
bashCmd.Flags().IntVarP(&bc.ErrNo, "errnumber", "e", module.BashErrnoDefault, "only show the command which exec reulst equals err number.")
rootCmd.AddCommand(bashCmd)

// Here you will define your flags and configuration settings.
Expand All @@ -59,7 +59,7 @@ func bashCommandFunc(command *cobra.Command, args []string) {
signal.Notify(stopper, os.Interrupt, syscall.SIGTERM)
ctx, cancelFun := context.WithCancel(context.TODO())

mod := module.GetModuleByName(module.MODULE_NAME_BASH)
mod := module.GetModuleByName(module.ModuleNameBash)

logger := log.New(os.Stdout, "bash_", log.LstdFlags)
logger.Printf("ECAPTURE :: version :%s", GitVersion)
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/gotls.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ func goTLSCommandFunc(command *cobra.Command, args []string) {
version, err = kernel.HostVersion()
logger.Printf("ECAPTURE :: Kernel Info : %s", version.String())

mod := module.GetModuleByName(module.MODULE_NAME_GOTLS)
mod := module.GetModuleByName(module.ModuleNameGotls)
if mod == nil {
logger.Printf("ECAPTURE :: \tcant found module: %s", module.MODULE_NAME_GOTLS)
logger.Printf("ECAPTURE :: \tcant found module: %s", module.ModuleNameGotls)
return
}

Expand Down
2 changes: 1 addition & 1 deletion cli/cmd/mysqld.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func mysqldCommandFunc(command *cobra.Command, args []string) {
signal.Notify(stopper, os.Interrupt, syscall.SIGTERM)
ctx, cancelFun := context.WithCancel(context.TODO())

mod := module.GetModuleByName(module.MODULE_NAME_MYSQLD)
mod := module.GetModuleByName(module.ModuleNameMysqld)

logger := log.New(os.Stdout, "mysqld_", log.LstdFlags)
logger.Printf("ECAPTURE :: version :%s", GitVersion)
Expand Down
4 changes: 2 additions & 2 deletions cli/cmd/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (

var postgresConfig = config.NewPostgresConfig()

//postgres Cmd represents the postgres command
// postgres Cmd represents the postgres command
var postgresCmd = &cobra.Command{
Use: "postgres",
Short: "capture sql queries from postgres 10+.",
Expand All @@ -50,7 +50,7 @@ func postgresCommandFunc(command *cobra.Command, args []string) {
signal.Notify(stopper, os.Interrupt, syscall.SIGTERM)
ctx, cancelFun := context.WithCancel(context.TODO())

mod := module.GetModuleByName(module.MODULE_NAME_POSTGRES)
mod := module.GetModuleByName(module.ModuleNamePostgres)

logger := log.New(os.Stdout, "postgress_", log.LstdFlags)
logger.Printf("ECAPTURE :: version :%s", GitVersion)
Expand Down
12 changes: 6 additions & 6 deletions cli/cmd/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ func openSSLCommandFunc(command *cobra.Command, args []string) {
logger.Printf("ECAPTURE :: Kernel Info : %s", version.String())

modNames := []string{}
if config.ELF_ARCH_ISANDROID {
modNames = []string{module.MODULE_NAME_OPENSSL}
if config.ElfArchIsandroid {
modNames = []string{module.ModuleNameOpenssl}
} else {
modNames = []string{module.MODULE_NAME_OPENSSL, module.MODULE_NAME_GNUTLS, module.MODULE_NAME_NSPR, module.MODULE_NAME_GOTLS}
modNames = []string{module.ModuleNameOpenssl, module.ModuleNameGnutls, module.ModuleNameNspr, module.ModuleNameGotls}
}

var runMods uint8
Expand All @@ -111,11 +111,11 @@ func openSSLCommandFunc(command *cobra.Command, args []string) {

var conf config.IConfig
switch mod.Name() {
case module.MODULE_NAME_OPENSSL:
case module.ModuleNameOpenssl:
conf = oc
case module.MODULE_NAME_GNUTLS:
case module.ModuleNameGnutls:
conf = gc
case module.MODULE_NAME_NSPR:
case module.ModuleNameNspr:
conf = nc
default:
}
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
)

const (
BTF_NOT_SUPPORT = "You can compile a no BTF version by youeself with command `make nocore`,Please read Makefile for more info."
BtfNotSupport = "You can compile a no BTF version by youeself with command `make nocore`,Please read Makefile for more info."
)

var (
Expand Down Expand Up @@ -61,11 +61,11 @@ func main() {
// BTF支持情况检测
enable, e := ebpf.IsEnableBTF()
if e != nil {
log.Fatalf("Can't found BTF config with error:%v.\n"+BTF_NOT_SUPPORT, e)
log.Fatalf("Can't found BTF config with error:%v.\n"+BtfNotSupport, e)
}
if !enable {
log.Fatal("BTF not support, please check it. shell: cat /boot/config-`uname -r` | grep CONFIG_DEBUG_INFO_BTF \n " +
BTF_NOT_SUPPORT)
BtfNotSupport)
}
}
}
Expand Down
72 changes: 36 additions & 36 deletions pkg/event_processor/base_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,27 @@ import (
type AttachType int64

const (
PROBE_ENTRY AttachType = iota
PROBE_RET
ProbeEntry AttachType = iota
ProbeRet
)

// 格式化输出相关

const CHUNK_SIZE = 16
const CHUNK_SIZE_HALF = CHUNK_SIZE / 2
const ChunkSize = 16
const ChunkSizeHalf = ChunkSize / 2

const MAX_DATA_SIZE = 1024 * 4
const SA_DATA_LEN = 14
const MaxDataSize = 1024 * 4
const SaDataLen = 14

const (
SSL2_VERSION = 0x0002
SSL3_VERSION = 0x0300
TLS1_VERSION = 0x0301
TLS1_1_VERSION = 0x0302
TLS1_2_VERSION = 0x0303
TLS1_3_VERSION = 0x0304
DTLS1_VERSION = 0xFEFF
DTLS1_2_VERSION = 0xFEFD
Ssl2Version = 0x0002
Ssl3Version = 0x0300
Tls1Version = 0x0301
Tls11Version = 0x0302
Tls12Version = 0x0303
Tls13Version = 0x0304
Dtls1Version = 0xFEFF
Dtls12Version = 0xFEFD
)

type tls_version struct {
Expand All @@ -53,21 +53,21 @@ type tls_version struct {

func (t tls_version) String() string {
switch t.version {
case SSL2_VERSION:
case Ssl2Version:
return "SSL2_VERSION"
case SSL3_VERSION:
case Ssl3Version:
return "SSL3_VERSION"
case TLS1_VERSION:
case Tls1Version:
return "TLS1_VERSION"
case TLS1_1_VERSION:
case Tls11Version:
return "TLS1_1_VERSION"
case TLS1_2_VERSION:
case Tls12Version:
return "TLS1_2_VERSION"
case TLS1_3_VERSION:
case Tls13Version:
return "TLS1_3_VERSION"
case DTLS1_VERSION:
case Dtls1Version:
return "DTLS1_VERSION"
case DTLS1_2_VERSION:
case Dtls12Version:
return "DTLS1_2_VERSION"
}
return fmt.Sprintf("TLS_VERSION_UNKNOW_%d", t.version)
Expand All @@ -79,7 +79,7 @@ type BaseEvent struct {
Timestamp uint64
Pid uint32
Tid uint32
Data [MAX_DATA_SIZE]byte
Data [MaxDataSize]byte
Data_len int32
Comm [16]byte
Fd uint32
Expand Down Expand Up @@ -135,9 +135,9 @@ func (this *BaseEvent) StringHex() string {

var perfix, connInfo string
switch AttachType(this.DataType) {
case PROBE_ENTRY:
case ProbeEntry:
connInfo = fmt.Sprintf("Recived %d bytes", this.Data_len)
case PROBE_RET:
case ProbeRet:
connInfo = fmt.Sprintf("Send %d bytes", this.Data_len)
default:
perfix = fmt.Sprintf("UNKNOW_%d", this.DataType)
Expand All @@ -154,9 +154,9 @@ func (this *BaseEvent) String() string {

var connInfo string
switch AttachType(this.DataType) {
case PROBE_ENTRY:
case ProbeEntry:
connInfo = fmt.Sprintf("Recived %dbytes", this.Data_len)
case PROBE_RET:
case ProbeRet:
connInfo = fmt.Sprintf("Send %d bytes", this.Data_len)
default:
connInfo = fmt.Sprintf("UNKNOW_%d", this.DataType)
Expand Down Expand Up @@ -188,22 +188,22 @@ func CToGoString(c []byte) string {
}

func dumpByteSlice(b []byte, perfix string) *bytes.Buffer {
var a [CHUNK_SIZE]byte
var a [ChunkSize]byte
bb := new(bytes.Buffer)
n := (len(b) + (CHUNK_SIZE - 1)) &^ (CHUNK_SIZE - 1)
n := (len(b) + (ChunkSize - 1)) &^ (ChunkSize - 1)

for i := 0; i < n; i++ {

// 序号列
if i%CHUNK_SIZE == 0 {
if i%ChunkSize == 0 {
bb.WriteString(perfix)
bb.WriteString(fmt.Sprintf("%04d", i))
}

// 长度的一半,则输出4个空格
if i%CHUNK_SIZE_HALF == 0 {
if i%ChunkSizeHalf == 0 {
bb.WriteString(" ")
} else if i%(CHUNK_SIZE_HALF/2) == 0 {
} else if i%(ChunkSizeHalf/2) == 0 {
bb.WriteString(" ")
}

Expand All @@ -215,15 +215,15 @@ func dumpByteSlice(b []byte, perfix string) *bytes.Buffer {

// 非ASCII 改为 .
if i >= len(b) {
a[i%CHUNK_SIZE] = ' '
a[i%ChunkSize] = ' '
} else if b[i] < 32 || b[i] > 126 {
a[i%CHUNK_SIZE] = '.'
a[i%ChunkSize] = '.'
} else {
a[i%CHUNK_SIZE] = b[i]
a[i%ChunkSize] = b[i]
}

// 如果到达size长度,则换行
if i%CHUNK_SIZE == (CHUNK_SIZE - 1) {
if i%ChunkSize == (ChunkSize - 1) {
bb.WriteString(fmt.Sprintf(" %s\n", string(a[:])))
}
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/event_processor/http_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (

type HTTPRequest struct {
request *http.Request
packerType PACKET_TYPE
packerType PacketType
isDone bool
isInit bool
reader *bytes.Buffer
Expand All @@ -40,12 +40,12 @@ func (this *HTTPRequest) Name() string {
return "HTTPRequest"
}

func (this *HTTPRequest) PacketType() PACKET_TYPE {
func (this *HTTPRequest) PacketType() PacketType {
return this.packerType
}

func (this *HTTPRequest) ParserType() PARSER_TYPE {
return PARSER_TYPE_HTTP_REQUEST
func (this *HTTPRequest) ParserType() ParserType {
return ParserTypeHttpRequest
}

func (this *HTTPRequest) Write(b []byte) (int, error) {
Expand Down
12 changes: 6 additions & 6 deletions pkg/event_processor/http_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

type HTTPResponse struct {
response *http.Response
packerType PACKET_TYPE
packerType PacketType
isDone bool
isInit bool
reader *bytes.Buffer
Expand All @@ -42,12 +42,12 @@ func (this *HTTPResponse) Name() string {
return "HTTPResponse"
}

func (this *HTTPResponse) PacketType() PACKET_TYPE {
func (this *HTTPResponse) PacketType() PacketType {
return this.packerType
}

func (this *HTTPResponse) ParserType() PARSER_TYPE {
return PARSER_TYPE_HTTP_RESPONSE
func (this *HTTPResponse) ParserType() ParserType {
return ParserTypeHttpResponse
}

func (this *HTTPResponse) Write(b []byte) (int, error) {
Expand Down Expand Up @@ -115,11 +115,11 @@ func (this *HTTPResponse) Display() []byte {

// gzip uncompressed success
this.response.Body = reader
this.packerType = PACKET_TYPE_GZIP
this.packerType = PacketTypeGzip
defer reader.Close()
default:
//reader = this.response.Body
this.packerType = PACKET_TYPE_NULL
this.packerType = PacketTypeNull
//TODO for debug
//return []byte("")
}
Expand Down
Loading

0 comments on commit 3a813ac

Please sign in to comment.