Skip to content

Commit

Permalink
user: imporve Dynamic link library path loading logic under the schem…
Browse files Browse the repository at this point in the history
…a on aarch64 ubuntu

Signed-off-by: CFC4N <[email protected]>
  • Loading branch information
cfc4n committed Jan 27, 2024
1 parent ab13932 commit be9f29c
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 28 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 24 additions & 4 deletions user/config/config_gnutls_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
11 changes: 2 additions & 9 deletions user/config/config_openssl_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 0 additions & 6 deletions user/config/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,3 @@ const (
ElfTypeBin uint8 = 1
ElfTypeSo uint8 = 2
)

//
//const (
// X86BinaryPrefix = "/lib/x86_64-linux-gnu"
// OthersBinaryPrefix = "/usr/lib"
//)
10 changes: 10 additions & 0 deletions user/module/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package module

import "runtime"

const (
ProbeTypeUprobe = "uprobe"
ProbeTypeKprobe = "kprobe"
Expand Down Expand Up @@ -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"
}
}
8 changes: 3 additions & 5 deletions user/module/probe_gnutls.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"log"
"math"
"os"
"path"
)

type MGnutlsProbe struct {
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion user/module/probe_nspr.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"log"
"math"
"os"
"path"
)

type MNsprProbe struct {
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion user/module/probe_openssl_keylog.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
manager "github.com/gojue/ebpfmanager"
"golang.org/x/sys/unix"
"math"
"path"
"strings"
)

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion user/module/probe_openssl_pcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"golang.org/x/sys/unix"
"math"
"net"
"path"
"strings"
)

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion user/module/probe_openssl_text.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"golang.org/x/sys/unix"
"math"
"os"
"path"
"strings"
)

Expand All @@ -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
Expand Down

0 comments on commit be9f29c

Please sign in to comment.