-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from ehids/support-android
New feature: #87 support Android 12+
- Loading branch information
Showing
8 changed files
with
197 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,8 @@ func main() { | |
} | ||
} | ||
|
||
// TODO check UPROBE | ||
|
||
cli.Start() | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
//go:build android12 | ||
// +build android12 | ||
|
||
package ebpf | ||
|
||
import ( | ||
"bufio" | ||
"compress/gzip" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
const ( | ||
BOOT_CONFIG_PATH = "/proc/config.gz" | ||
CONFIG_BTF_TAGNAME = "CONFIG_DEBUG_INFO_BTF" | ||
SYS_KERNEL_BTF_VMLINUX = "/sys/kernel/btf/vmlinux" | ||
CONFIG_ARCH_SUPPORTS_UPROBES = "CONFIG_ARCH_SUPPORTS_UPROBES" | ||
CONFIG_UPROBES = "CONFIG_UPROBES" | ||
) | ||
|
||
var ( | ||
// use same list of locations as libbpf | ||
// https://android.googlesource.com/platform/external/libbpf/ | ||
|
||
locations = []string{ | ||
//"/sys/kernel/btf/vmlinux", | ||
} | ||
) | ||
|
||
func IsEnableBTF() (bool, error) { | ||
found, e := checkKernelBTF() | ||
if e == nil && found { | ||
return true, nil | ||
} | ||
|
||
bootConf := fmt.Sprintf(BOOT_CONFIG_PATH) | ||
|
||
// Open file bootConf. | ||
f, err := os.Open(bootConf) | ||
if err != nil { | ||
return false, err | ||
} | ||
defer f.Close() | ||
|
||
// uncompress | ||
reader, err := gzip.NewReader(f) | ||
if err != nil { | ||
return false, err | ||
} | ||
defer reader.Close() | ||
|
||
var KernelConfig = make(map[string]string) | ||
s := bufio.NewScanner(reader) | ||
if err := parse(s, KernelConfig); err != nil { | ||
return false, err | ||
} | ||
bc, found := KernelConfig[CONFIG_BTF_TAGNAME] | ||
if !found { | ||
// 没有这个配置项 | ||
return false, nil | ||
} | ||
|
||
//如果有,在判断配置项的值 | ||
if bc != "y" { | ||
// 没有开启 | ||
return false, nil | ||
} | ||
return true, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//go:build !android12 | ||
// +build !android12 | ||
|
||
package ebpf | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
const ( | ||
BOOT_CONFIG_PATH = "/boot/config-%s" | ||
CONFIG_BTF_TAGNAME = "CONFIG_DEBUG_INFO_BTF" | ||
SYS_KERNEL_BTF_VMLINUX = "/sys/kernel/btf/vmlinux" | ||
CONFIG_ARCH_SUPPORTS_UPROBES = "CONFIG_ARCH_SUPPORTS_UPROBES" | ||
CONFIG_UPROBES = "CONFIG_UPROBES" | ||
) | ||
|
||
var ( | ||
// use same list of locations as libbpf | ||
// https://github.com/libbpf/libbpf/blob/9a3a42608dbe3731256a5682a125ac1e23bced8f/src/btf.c#L3114-L3122 | ||
|
||
locations = []string{ | ||
"/boot/vmlinux-%s", | ||
"/lib/modules/%s/vmlinux-%[1]s", | ||
"/lib/modules/%s/build/vmlinux", | ||
"/usr/lib/modules/%s/kernel/vmlinux", | ||
"/usr/lib/debug/boot/vmlinux-%s", | ||
"/usr/lib/debug/boot/vmlinux-%s.debug", | ||
"/usr/lib/debug/lib/modules/%s/vmlinux", | ||
} | ||
) | ||
|
||
func IsEnableBTF() (bool, error) { | ||
found, e := checkKernelBTF() | ||
if e == nil && found { | ||
return true, nil | ||
} | ||
|
||
i, e := getOSUnamer() | ||
if e != nil { | ||
return false, e | ||
} | ||
bootConf := fmt.Sprintf(BOOT_CONFIG_PATH, i.Release) | ||
|
||
// Open file bootConf. | ||
f, err := os.Open(bootConf) | ||
if err != nil { | ||
return false, err | ||
} | ||
defer f.Close() | ||
|
||
var KernelConfig = make(map[string]string) | ||
s := bufio.NewScanner(f) | ||
if err := parse(s, KernelConfig); err != nil { | ||
return false, err | ||
} | ||
bc, found := KernelConfig[CONFIG_BTF_TAGNAME] | ||
if !found { | ||
// 没有这个配置项 | ||
return false, nil | ||
} | ||
|
||
//如果有,在判断配置项的值 | ||
if bc != "y" { | ||
// 没有开启 | ||
return false, nil | ||
} | ||
return true, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//go:build android12 | ||
// +build android12 | ||
|
||
package user | ||
|
||
const ( | ||
LD_LOAD_PATH = "/etc/ld.so.conf" | ||
) | ||
|
||
// https://source.android.com/devices/architecture/vndk/linker-namespace | ||
var ( | ||
default_so_paths = []string{ | ||
"/data/asan/system/lib64", | ||
"/apex/com.android.conscrypt/lib64", | ||
"/apex/com.android.runtime/lib64/bionic", | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//go:build !android12 | ||
// +build !android12 | ||
|
||
package user | ||
|
||
const ( | ||
LD_LOAD_PATH = "/etc/ld.so.conf" | ||
) | ||
|
||
/* | ||
1, the RPATH binary header (set at build-time) of the library causing the lookup (if any) | ||
2, the RPATH binary header (set at build-time) of the executable | ||
3, the LD_LIBRARY_PATH environment variable (set at run-time) | ||
4, the RUNPATH binary header (set at build-time) of the executable | ||
5, /etc/ld.so.cache | ||
6, base library directories (/lib and /usr/lib) | ||
ref: http://blog.tremily.us/posts/rpath/ | ||
*/ | ||
var ( | ||
default_so_paths = []string{ | ||
"/lib", | ||
"/usr/lib", | ||
"/usr/lib64", | ||
"/lib64", | ||
} | ||
) |