From 888487021de9c5b9048cc9c84c14a54d9c3216ad Mon Sep 17 00:00:00 2001 From: lgjint <78463565+lgjint@users.noreply.github.com> Date: Sat, 1 Jun 2024 11:06:53 +0800 Subject: [PATCH] Add KernelSU root permission detection for auto-redirect --- inbound/tun_auto_redirect.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/inbound/tun_auto_redirect.go b/inbound/tun_auto_redirect.go index 8ebc04d2..c79232f7 100644 --- a/inbound/tun_auto_redirect.go +++ b/inbound/tun_auto_redirect.go @@ -61,17 +61,20 @@ func newAutoRedirect(t *Tun) (*tunAutoRedirect, error) { suPath string err error ) - if t.platformInterface != nil { - suPath, err = exec.LookPath("/bin/su") - } else { - suPath, err = exec.LookPath("su") + for _, suPath = range []string{ + "su", + "/system/bin/su", + } { + suPath, err = exec.LookPath(suPath) + if err == nil { + break + } } - if err == nil { - s.androidSu = true - s.suPath = suPath - } else { + if err != nil { return nil, E.Extend(E.Cause(err, "root permission is required for auto redirect"), os.Getenv("PATH")) } + s.androidSu = true + s.suPath = suPath } } else { err := s.initializeNfTables()