Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions user/config/config_bash.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,25 @@ func NewBashConfig() *BashConfig {
return config
}

func (this *BashConfig) Check() error {
func (bc *BashConfig) Check() error {

// 如果readline 配置,且存在,则直接返回。
if this.Readline != "" || len(strings.TrimSpace(this.Readline)) > 0 {
_, e := os.Stat(this.Readline)
if bc.Readline != "" || len(strings.TrimSpace(bc.Readline)) > 0 {
_, e := os.Stat(bc.Readline)
if e != nil {
return e
}
this.ElfType = ElfTypeSo
bc.ElfType = ElfTypeSo
return nil
}

//如果配置 bash的地址,且存在,则直接返回
if this.Bashpath != "" || len(strings.TrimSpace(this.Bashpath)) > 0 {
_, e := os.Stat(this.Bashpath)
if bc.Bashpath != "" || len(strings.TrimSpace(bc.Bashpath)) > 0 {
_, e := os.Stat(bc.Bashpath)
if e != nil {
return e
}
this.ElfType = ElfTypeBin
bc.ElfType = ElfTypeBin
return nil
}

Expand All @@ -61,12 +61,12 @@ func (this *BashConfig) Check() error {
if b {
soPath, e := getDynPathByElf(bash, "libreadline.so")
if e != nil {
//this.logger.Printf("get bash:%s dynamic library error:%v.\n", bash, e)
this.Bashpath = bash
this.ElfType = ElfTypeBin
//bc.logger.Printf("get bash:%s dynamic library error:%v.\n", bash, e)
bc.Bashpath = bash
bc.ElfType = ElfTypeBin
} else {
this.Bashpath = soPath
this.ElfType = ElfTypeSo
bc.Bashpath = soPath
bc.ElfType = ElfTypeSo
}

} else {
Expand Down
12 changes: 6 additions & 6 deletions user/config/config_gnutls_androidgki.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ import (

const DefaultGnutlsPath = "/apex/com.android.conscrypt/lib64/libgnutls"

func (this *GnutlsConfig) Check() error {
func (gc *GnutlsConfig) Check() error {

// 如果readline 配置,且存在,则直接返回。
if this.Gnutls != "" || len(strings.TrimSpace(this.Gnutls)) > 0 {
_, e := os.Stat(this.Gnutls)
if gc.Gnutls != "" || len(strings.TrimSpace(gc.Gnutls)) > 0 {
_, e := os.Stat(gc.Gnutls)
if e != nil {
return e
}
this.ElfType = ElfTypeSo
gc.ElfType = ElfTypeSo
return nil
}

this.Gnutls = DefaultGnutlsPath
this.ElfType = ElfTypeSo
gc.Gnutls = DefaultGnutlsPath
gc.ElfType = ElfTypeSo

return nil
}
30 changes: 15 additions & 15 deletions user/config/config_gnutls_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,52 +25,52 @@ import (
"errors"
)

func (this *GnutlsConfig) Check() error {
func (gc *GnutlsConfig) Check() error {

// 如果readline 配置,且存在,则直接返回。
if this.Gnutls != "" || len(strings.TrimSpace(this.Gnutls)) > 0 {
_, e := os.Stat(this.Gnutls)
if gc.Gnutls != "" || len(strings.TrimSpace(gc.Gnutls)) > 0 {
_, e := os.Stat(gc.Gnutls)
if e != nil {
return e
}
this.ElfType = ElfTypeSo
gc.ElfType = ElfTypeSo
return nil
}

if this.NoSearch {
if gc.NoSearch {
return errors.New("NoSearch requires specifying lib path")
}

//如果配置 Curlpath的地址,判断文件是否存在,不存在则直接返回
if this.Curlpath != "" || len(strings.TrimSpace(this.Curlpath)) > 0 {
_, e := os.Stat(this.Curlpath)
if gc.Curlpath != "" || len(strings.TrimSpace(gc.Curlpath)) > 0 {
_, e := os.Stat(gc.Curlpath)
if e != nil {
return e
}
} else {
//如果没配置,则直接指定。
this.Curlpath = "/usr/bin/wget"
gc.Curlpath = "/usr/bin/wget"
}

soPath, e := getDynPathByElf(this.Curlpath, "libgnutls.so")
soPath, e := getDynPathByElf(gc.Curlpath, "libgnutls.so")
if e != nil {
//this.logger.Printf("get bash:%s dynamic library error:%v.\n", bash, e)
//gc.logger.Printf("get bash:%s dynamic library error:%v.\n", bash, e)
_, e = os.Stat(X86BinaryPrefix)
prefix := X86BinaryPrefix
if e != nil {
prefix = OthersBinaryPrefix
}
this.Gnutls = filepath.Join(prefix, "libgnutls.so.30")
this.ElfType = ElfTypeSo
_, e = os.Stat(this.Gnutls)
gc.Gnutls = filepath.Join(prefix, "libgnutls.so.30")
gc.ElfType = ElfTypeSo
_, e = os.Stat(gc.Gnutls)
if e != nil {
return e
}
return nil
}

this.Gnutls = soPath
this.ElfType = ElfTypeSo
gc.Gnutls = soPath
gc.ElfType = ElfTypeSo

return nil
}
30 changes: 15 additions & 15 deletions user/config/config_gotls.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,22 @@ func NewGoTLSConfig() *GoTLSConfig {
return &GoTLSConfig{}
}

func (c *GoTLSConfig) Check() error {
if c.Path == "" {
func (gc *GoTLSConfig) Check() error {
if gc.Path == "" {
return ErrorGoBINNotFound
}

if c.Ifname == "" || len(c.Ifname) == 0 {
c.Ifname = DefaultIfname
if gc.Ifname == "" || len(gc.Ifname) == 0 {
gc.Ifname = DefaultIfname
}

_, err := os.Stat(c.Path)
_, err := os.Stat(gc.Path)
if err != nil {
return err
}

var goElf *elf.File
goElf, err = elf.Open(c.Path)
goElf, err = elf.Open(gc.Path)
if err != nil {
return err
}
Expand All @@ -91,20 +91,20 @@ func (c *GoTLSConfig) Check() error {
default:
err = fmt.Errorf("unsupport CPU arch :%s", goElfArch)
}
c.goElfArch = goElfArch
c.goElf = goElf
c.ReadTlsAddrs, err = c.findRetOffsets(GoTlsReadFunc)
gc.goElfArch = goElfArch
gc.goElf = goElf
gc.ReadTlsAddrs, err = gc.findRetOffsets(GoTlsReadFunc)
return err
}

// FindRetOffsets searches for the addresses of all RET instructions within
// the instruction set associated with the specified symbol in an ELF program.
// It is used for mounting uretprobe programs for Golang programs,
// which are actually mounted via uprobe on these addresses.
func (c *GoTLSConfig) findRetOffsets(symbolName string) ([]int, error) {
func (gc *GoTLSConfig) findRetOffsets(symbolName string) ([]int, error) {
var err error
var goSymbs []elf.Symbol
goSymbs, err = c.goElf.Symbols()
goSymbs, err = gc.goElf.Symbols()
if err != nil {
return nil, err
}
Expand All @@ -123,7 +123,7 @@ func (c *GoTLSConfig) findRetOffsets(symbolName string) ([]int, error) {
return nil, ErrorSymbolNotFound
}

section := c.goElf.Sections[symbol.Section]
section := gc.goElf.Sections[symbol.Section]

var elfText []byte
elfText, err = section.Data()
Expand All @@ -137,18 +137,18 @@ func (c *GoTLSConfig) findRetOffsets(symbolName string) ([]int, error) {
var offsets []int
var instHex []byte
instHex = elfText[start:end]
offsets, err = c.decodeInstruction(instHex)
offsets, err = gc.decodeInstruction(instHex)
if len(offsets) == 0 {
return offsets, ErrorNoRetFound
}
return offsets, nil
}

// decodeInstruction Decode into assembly instructions and identify the RET instruction to return the offset.
func (c *GoTLSConfig) decodeInstruction(instHex []byte) ([]int, error) {
func (gc *GoTLSConfig) decodeInstruction(instHex []byte) ([]int, error) {
var offsets []int
for i := 0; i < len(instHex); {
if c.goElfArch == "amd64" {
if gc.goElfArch == "amd64" {
inst, err := x86asm.Decode(instHex[i:], 64)
if err != nil {
return nil, err
Expand Down
28 changes: 14 additions & 14 deletions user/config/config_mysqld.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,32 @@ func NewMysqldConfig() *MysqldConfig {
return config
}

func (this *MysqldConfig) Check() error {
func (mc *MysqldConfig) Check() error {

// 如果readline 配置,且存在,则直接返回。
if this.Mysqldpath == "" || len(strings.TrimSpace(this.Mysqldpath)) <= 0 {
if mc.Mysqldpath == "" || len(strings.TrimSpace(mc.Mysqldpath)) <= 0 {
return errors.New("Mysqld path cant be null.")
}

_, e := os.Stat(this.Mysqldpath)
_, e := os.Stat(mc.Mysqldpath)
if e != nil {
return e
}
this.ElfType = ElfTypeBin
mc.ElfType = ElfTypeBin

//如果配置 funcname ,则使用用户指定的函数名
if this.FuncName != "" || len(strings.TrimSpace(this.FuncName)) > 0 {
if mc.FuncName != "" || len(strings.TrimSpace(mc.FuncName)) > 0 {
return nil
}

//如果配置 Offset ,则使用用户指定的Offset
if this.Offset > 0 {
this.FuncName = "[_IGNORE_]"
if mc.Offset > 0 {
mc.FuncName = "[_IGNORE_]"
return nil
}

//r, _ := regexp.Compile("^(?:# *)?(CONFIG_\\w*)(?:=| )(y|n|m|is not set|\\d+|0x.+|\".*\")$")
_elf, e := elf.Open(this.Mysqldpath)
_elf, e := elf.Open(mc.Mysqldpath)
if e != nil {
return e
}
Expand All @@ -103,11 +103,11 @@ func (this *MysqldConfig) Check() error {

//如果没找到,则报错。
if funcName == "" {
return errors.New(fmt.Sprintf("cant match mysql query function to hook with mysqld file::%s", this.Mysqldpath))
return errors.New(fmt.Sprintf("cant match mysql query function to hook with mysqld file::%s", mc.Mysqldpath))
}

this.Version = MysqldType56
this.VersionInfo = "mysqld-5.6"
mc.Version = MysqldType56
mc.VersionInfo = "mysqld-5.6"

// 判断mysqld 版本
found := strings.Contains(funcName, "COM_DATA")
Expand All @@ -120,11 +120,11 @@ func (this *MysqldConfig) Check() error {
if e == nil {
ver, verInfo = getMysqlVer(buf)
}
this.Version = ver
this.VersionInfo = verInfo
mc.Version = ver
mc.VersionInfo = verInfo
}

this.FuncName = funcName
mc.FuncName = funcName

return nil
}
Expand Down
12 changes: 6 additions & 6 deletions user/config/config_nspr_androidgki.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ import (

const DefaultNsprNssPath = "/apex/com.android.conscrypt/lib64/libnspr4.so"

func (this *NsprConfig) Check() error {
func (nc *NsprConfig) Check() error {

// 如果readline 配置,且存在,则直接返回。
if this.Nsprpath != "" || len(strings.TrimSpace(this.Nsprpath)) > 0 {
_, e := os.Stat(this.Nsprpath)
if nc.Nsprpath != "" || len(strings.TrimSpace(nc.Nsprpath)) > 0 {
_, e := os.Stat(nc.Nsprpath)
if e != nil {
return e
}
this.ElfType = ElfTypeSo
nc.ElfType = ElfTypeSo
return nil
}

this.Nsprpath = DefaultNsprNssPath
this.ElfType = ElfTypeSo
nc.Nsprpath = DefaultNsprNssPath
nc.ElfType = ElfTypeSo

return nil
}
Loading