Skip to content

Commit

Permalink
get android version
Browse files Browse the repository at this point in the history
Signed-off-by: cfc4n <[email protected]>
  • Loading branch information
cfc4n committed Nov 10, 2023
1 parent 356bf0d commit 82d5e3d
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
1 change: 1 addition & 0 deletions user/config/config_openssl.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type OpensslConfig struct {
CGroupPath string `json:"CGroupPath"` // cgroup path, used for filter process
ElfType uint8 //
IsAndroid bool // is Android OS ?
AndroidVer string // Android OS version
}

func NewOpensslConfig() *OpensslConfig {
Expand Down
27 changes: 23 additions & 4 deletions user/config/config_openssl_androidgki.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@
package config

import (
"bufio"
"os"
"strings"
)

const (
DefaultOpensslPath = "/apex/com.android.conscrypt/lib64/libssl.so"
DEFAULT_LIBC_PATH = "/apex/com.android.runtime/lib64/bionic/libc.so"

DefaultIfname = "wlan0"
DefaultLibcPath = "/apex/com.android.runtime/lib64/bionic/libc.so"
BuildPropPath = "/system/build.prop"
ReleasePrefix = "ro.build.version.release="
DefaultIfname = "wlan0"
)

func (oc *OpensslConfig) Check() error {
oc.AndroidVer = "12"
oc.IsAndroid = true
// 如果readline 配置,且存在,则直接返回。
if oc.Openssl != "" || len(strings.TrimSpace(oc.Openssl)) > 0 {
Expand All @@ -49,11 +52,27 @@ func (oc *OpensslConfig) Check() error {
return e
}
} else {
oc.Pthread = DEFAULT_LIBC_PATH
oc.Pthread = DefaultLibcPath
}

if oc.Ifname == "" || len(strings.TrimSpace(oc.Ifname)) == 0 {
oc.Ifname = DefaultIfname
}

f, err := os.Open(BuildPropPath)
if err != nil {
return nil
}
defer f.Close()

// detect android version (use Android version?), and set AndroidVer
sc := bufio.NewScanner(f)
for sc.Scan() {
line := sc.Text()
if strings.HasPrefix(line, ReleasePrefix) {
oc.AndroidVer = strings.TrimSpace(strings.TrimPrefix(line, ReleasePrefix))
break
}
}
return nil
}
19 changes: 0 additions & 19 deletions user/config/config_openssl_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,26 +156,7 @@ func (oc *OpensslConfig) Check() error {
oc.ElfType = ElfTypeSo
checkedOpenssl = true
}
/*
//如果配置 Curlpath的地址,判断文件是否存在,不存在则直接返回
if oc.Curlpath != "" || len(strings.TrimSpace(oc.Curlpath)) > 0 {
_, e := os.Stat(oc.Curlpath)
if e != nil {
return e
}
} else {
//如果没配置,则直接指定。
oc.Curlpath = "/usr/bin/curl"
}

if oc.Pthread != "" || len(strings.TrimSpace(oc.Pthread)) > 0 {
_, e := os.Stat(oc.Pthread)
if e != nil {
return e
}
checkedConnect = true
}
*/
if oc.Ifname == "" || len(strings.TrimSpace(oc.Ifname)) == 0 {
oc.Ifname = DefaultIfname
}
Expand Down
15 changes: 11 additions & 4 deletions user/module/probe_openssl_lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,22 @@ func (m *MOpenSSLProbe) detectOpenssl(soPath string) error {
}

isAndroid := m.conf.(*config.OpensslConfig).IsAndroid
androidVer := m.conf.(*config.OpensslConfig).AndroidVer
// if not found, use default
if isAndroid {
// sometimes,boringssl version always was "boringssl 1.1.1" on android. but offsets are different.
// see kern/boringssl_a_13_kern.c and kern/boringssl_a_14_kern.c
// Perhaps we can utilize the Android Version to choose a specific version of boringssl.
// TODO : detect android version (use Android version?), and use the corresponding bpfFile

bpfFile, _ = m.sslVersionBpfMap[AndroidDefauleFilename]
m.logger.Printf("%s\tOpenSSL/BoringSSL version not found, used default version :%s\n", m.Name(), AndroidDefauleFilename)
// use the corresponding bpfFile
bpfFildAndroid := fmt.Sprintf("boringssl_a_%s", androidVer)
bpfFile, found = m.sslVersionBpfMap[bpfFildAndroid]
if found {
m.sslBpfFile = bpfFile
m.logger.Printf("%s\tOpenSSL/BoringSSL version found, ro.build.version.release=%s\n", m.Name(), androidVer)
} else {
bpfFile, _ = m.sslVersionBpfMap[AndroidDefauleFilename]
m.logger.Printf("%s\tOpenSSL/BoringSSL version not found, used default version :%s\n", m.Name(), AndroidDefauleFilename)
}
} else {
if strings.Contains(soPath, "libssl.so.3") {
bpfFile, _ = m.sslVersionBpfMap[LinuxDefauleFilename_3_0]
Expand Down

0 comments on commit 82d5e3d

Please sign in to comment.