diff --git a/Makefile b/Makefile index ea081cba3..3d214b4c7 100644 --- a/Makefile +++ b/Makefile @@ -49,6 +49,10 @@ ifeq ($(DEBUG),1) DEBUG_PRINT := -DDEBUG_PRINT endif +ifndef ANDROID + ANDROID = 0 +endif + TARGET_TAG ?= linux ifeq ($(ANDROID),1) TARGET_TAG := androidgki diff --git a/user/config/config_gnutls_linux.go b/user/config/config_gnutls_linux.go index 9517bdbba..0ef1052a4 100644 --- a/user/config/config_gnutls_linux.go +++ b/user/config/config_gnutls_linux.go @@ -18,17 +18,18 @@ package config import ( + "errors" "os" + "path/filepath" "strings" ) -const DefaultGnutlsPath = "/lib/x86_64-linux-gnu/libgnutls.so.30" - func (gc *GnutlsConfig) Check() error { + var e error // 如果readline 配置,且存在,则直接返回。 if gc.Gnutls != "" || len(strings.TrimSpace(gc.Gnutls)) > 0 { - _, e := os.Stat(gc.Gnutls) + _, e = os.Stat(gc.Gnutls) if e != nil { return e } @@ -65,7 +66,26 @@ func (gc *GnutlsConfig) Check() error { return nil } */ - gc.Gnutls = DefaultGnutlsPath + var soLoadPaths = GetDynLibDirs() + var sslPath string + for _, soPath := range soLoadPaths { + _, e = os.Stat(soPath) + if e != nil { + continue + } + // libgnutls.so.30 default + sslPath = filepath.Join(soPath, "libgnutls.so.30") + _, e = os.Stat(sslPath) + if e != nil { + continue + } + gc.Gnutls = sslPath + break + } + if gc.Gnutls == "" { + return errors.New("cant found Gnutls so load path") + } + gc.ElfType = ElfTypeSo return nil diff --git a/user/config/config_openssl_linux.go b/user/config/config_openssl_linux.go index e3912cef9..8000769d5 100644 --- a/user/config/config_openssl_linux.go +++ b/user/config/config_openssl_linux.go @@ -28,18 +28,9 @@ import ( const ( DefaultIfname = "eth0" - // /lib/x86_64-linux-gnu/libssl.so.3 - //libsslSoFile = "libssl.so.1.1" ) var ( - soLoadPaths = []string{ - "/lib/x86_64-linux-gnu", - "/usr/lib64", - "/usr/lib", - "/lib", - } - libsslSharedObjects = []string{ "libssl.so.3", // ubuntu server 22.04 "libssl.so.1.1", // ubuntu server 21.04 @@ -54,6 +45,7 @@ var ( func (oc *OpensslConfig) checkOpenssl() error { var e error var sslPath string + var soLoadPaths = GetDynLibDirs() for _, soPath := range soLoadPaths { _, e = os.Stat(soPath) if e != nil { @@ -88,6 +80,7 @@ func (oc *OpensslConfig) checkConnect() error { var e error for _, so := range connectSharedObjects { var prefix string + var soLoadPaths = GetDynLibDirs() for _, soPath := range soLoadPaths { _, e = os.Stat(soPath) diff --git a/user/config/const.go b/user/config/const.go index 088b90f99..3428149ef 100644 --- a/user/config/const.go +++ b/user/config/const.go @@ -18,9 +18,3 @@ const ( ElfTypeBin uint8 = 1 ElfTypeSo uint8 = 2 ) - -// -//const ( -// X86BinaryPrefix = "/lib/x86_64-linux-gnu" -// OthersBinaryPrefix = "/usr/lib" -//) diff --git a/user/module/const.go b/user/module/const.go index 02c8329d9..bc583667f 100644 --- a/user/module/const.go +++ b/user/module/const.go @@ -14,6 +14,8 @@ package module +import "runtime" + const ( ProbeTypeUprobe = "uprobe" ProbeTypeKprobe = "kprobe" @@ -50,3 +52,11 @@ const ( const ( MasterSecretKeyLogName = "ecapture_masterkey.log" ) + +var defaultSoPath = "/lib/x86_64-linux-gnu" + +func init() { + if runtime.GOARCH == "arm64" { + defaultSoPath = "/lib/aarch64-linux-gnu" + } +} diff --git a/user/module/probe_gnutls.go b/user/module/probe_gnutls.go index 95918017e..ae351c708 100644 --- a/user/module/probe_gnutls.go +++ b/user/module/probe_gnutls.go @@ -28,6 +28,7 @@ import ( "log" "math" "os" + "path" ) type MGnutlsProbe struct { @@ -118,15 +119,12 @@ func (g *MGnutlsProbe) constantEditor() []manager.ConstantEditor { func (g *MGnutlsProbe) setupManagers() error { var binaryPath string switch g.conf.(*config.GnutlsConfig).ElfType { - //case config.ElfTypeBin: - // binaryPath = g.conf.(*config.GnutlsConfig).Curlpath case config.ElfTypeSo: binaryPath = g.conf.(*config.GnutlsConfig).Gnutls default: - //如果没找到 - binaryPath = "/lib/x86_64-linux-gnu/libgnutls.so.30" + //如果没找到 "/lib/x86_64-linux-gnu/libgnutls.so.30" + binaryPath = path.Join(defaultSoPath, "libgnutls.so.30") } - _, err := os.Stat(binaryPath) if err != nil { return err diff --git a/user/module/probe_nspr.go b/user/module/probe_nspr.go index f3935880d..ec622c415 100644 --- a/user/module/probe_nspr.go +++ b/user/module/probe_nspr.go @@ -28,6 +28,7 @@ import ( "log" "math" "os" + "path" ) type MNsprProbe struct { @@ -123,7 +124,7 @@ func (n *MNsprProbe) setupManagers() error { binaryPath = n.conf.(*config.NsprConfig).Nsprpath default: //如果没找到 - binaryPath = "/lib/x86_64-linux-gnu/libnspr4.so" + binaryPath = path.Join(defaultSoPath, "libnspr4.so") } _, err := os.Stat(binaryPath) diff --git a/user/module/probe_openssl_keylog.go b/user/module/probe_openssl_keylog.go index b32822c18..da4704521 100644 --- a/user/module/probe_openssl_keylog.go +++ b/user/module/probe_openssl_keylog.go @@ -22,6 +22,7 @@ import ( manager "github.com/gojue/ebpfmanager" "golang.org/x/sys/unix" "math" + "path" "strings" ) @@ -41,7 +42,7 @@ func (m *MOpenSSLProbe) setupManagersKeylog() error { } default: //如果没找到 - binaryPath = "/lib/x86_64-linux-gnu/libssl.so.1.1" + binaryPath = path.Join(defaultSoPath, "libssl.so.1.1") err := m.getSslBpfFile(binaryPath, sslVersion) if err != nil { return err diff --git a/user/module/probe_openssl_pcap.go b/user/module/probe_openssl_pcap.go index 7986b3559..c2b44286a 100644 --- a/user/module/probe_openssl_pcap.go +++ b/user/module/probe_openssl_pcap.go @@ -24,6 +24,7 @@ import ( "golang.org/x/sys/unix" "math" "net" + "path" "strings" ) @@ -64,7 +65,7 @@ func (m *MOpenSSLProbe) setupManagersPcap() error { } default: //如果没找到 - binaryPath = "/lib/x86_64-linux-gnu/libssl.so.1.1" + binaryPath = path.Join(defaultSoPath, "libssl.so.1.1") err := m.getSslBpfFile(binaryPath, sslVersion) if err != nil { return err diff --git a/user/module/probe_openssl_text.go b/user/module/probe_openssl_text.go index 49dbc058a..3517db58a 100644 --- a/user/module/probe_openssl_text.go +++ b/user/module/probe_openssl_text.go @@ -9,6 +9,7 @@ import ( "golang.org/x/sys/unix" "math" "os" + "path" "strings" ) @@ -27,7 +28,7 @@ func (m *MOpenSSLProbe) setupManagersText() error { } default: //如果没找到 - binaryPath = "/lib/x86_64-linux-gnu/libssl.so.1.1" + binaryPath = path.Join(defaultSoPath, "libssl.so.1.1") err := m.getSslBpfFile(binaryPath, sslVersion) if err != nil { return err