Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
13fbf397
Commit
13fbf397
authored
Jan 16, 2021
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Isolated processes might still be hide-able
parent
20be99ec
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
45 additions
and
57 deletions
+45
-57
hide_utils.cpp
native/jni/magiskhide/hide_utils.cpp
+26
-24
magiskhide.hpp
native/jni/magiskhide/magiskhide.hpp
+1
-0
proc_monitor.cpp
native/jni/magiskhide/proc_monitor.cpp
+18
-33
No files found.
native/jni/magiskhide/hide_utils.cpp
View file @
13fbf397
...
@@ -337,45 +337,47 @@ void auto_start_magiskhide(bool late_props) {
...
@@ -337,45 +337,47 @@ void auto_start_magiskhide(bool late_props) {
}
}
}
}
#if !ENABLE_INJECT
bool
is_hide_target
(
int
uid
,
string_view
process
)
{
void
test_proc_monitor
()
{
if
(
procfp
==
nullptr
&&
(
procfp
=
opendir
(
"/proc"
))
==
nullptr
)
exit
(
1
);
proc_monitor
();
}
#endif
#if ENABLE_INJECT
int
check_uid_map
(
int
client
)
{
mutex_guard
lock
(
hide_state_lock
);
mutex_guard
lock
(
hide_state_lock
);
if
(
!
hide_state
)
if
(
uid
%
100000
>=
90000
)
{
return
0
;
// Isolated processes
int
uid
=
read_int
(
client
);
string
process
=
read_string
(
client
);
if
(
uid
%
100000
>
90000
)
{
// Isolated process
auto
it
=
uid_proc_map
.
find
(
-
1
);
auto
it
=
uid_proc_map
.
find
(
-
1
);
if
(
it
==
uid_proc_map
.
end
())
if
(
it
==
uid_proc_map
.
end
())
return
0
;
return
false
;
for
(
auto
&
s
:
it
->
second
)
{
for
(
auto
&
s
:
it
->
second
)
{
if
(
str_starts
(
process
,
s
))
if
(
str_starts
(
process
,
s
))
return
1
;
return
true
;
}
}
}
else
{
}
else
{
auto
it
=
uid_proc_map
.
find
(
uid
);
auto
it
=
uid_proc_map
.
find
(
uid
);
if
(
it
==
uid_proc_map
.
end
())
if
(
it
==
uid_proc_map
.
end
())
return
0
;
return
false
;
for
(
auto
&
s
:
it
->
second
)
{
for
(
auto
&
s
:
it
->
second
)
{
if
(
process
==
s
)
if
(
s
==
proces
s
)
return
1
;
return
true
;
}
}
}
}
return
false
;
}
return
0
;
#if !ENABLE_INJECT
void
test_proc_monitor
()
{
if
(
procfp
==
nullptr
&&
(
procfp
=
opendir
(
"/proc"
))
==
nullptr
)
exit
(
1
);
proc_monitor
();
}
#endif
#if ENABLE_INJECT
int
check_uid_map
(
int
client
)
{
if
(
!
hide_enabled
())
return
0
;
int
uid
=
read_int
(
client
);
string
process
=
read_string
(
client
);
return
is_hide_target
(
uid
,
process
)
?
1
:
0
;
}
}
#endif
#endif
native/jni/magiskhide/magiskhide.hpp
View file @
13fbf397
...
@@ -35,6 +35,7 @@ void crawl_procfs(const std::function<bool (int)> &fn);
...
@@ -35,6 +35,7 @@ void crawl_procfs(const std::function<bool (int)> &fn);
void
crawl_procfs
(
DIR
*
dir
,
const
std
::
function
<
bool
(
int
)
>
&
fn
);
void
crawl_procfs
(
DIR
*
dir
,
const
std
::
function
<
bool
(
int
)
>
&
fn
);
bool
hide_enabled
();
bool
hide_enabled
();
void
update_uid_map
();
void
update_uid_map
();
bool
is_hide_target
(
int
uid
,
std
::
string_view
process
);
// Hide policies
// Hide policies
void
hide_daemon
(
int
pid
);
void
hide_daemon
(
int
pid
);
...
...
native/jni/magiskhide/proc_monitor.cpp
View file @
13fbf397
...
@@ -183,8 +183,10 @@ static bool check_pid(int pid) {
...
@@ -183,8 +183,10 @@ static bool check_pid(int pid) {
return
true
;
return
true
;
}
}
int
uid
=
st
.
st_uid
;
// UID hasn't changed
// UID hasn't changed
if
(
st
.
st_
uid
==
0
)
if
(
uid
==
0
)
return
false
;
return
false
;
sprintf
(
path
,
"/proc/%d/cmdline"
,
pid
);
sprintf
(
path
,
"/proc/%d/cmdline"
,
pid
);
...
@@ -200,43 +202,26 @@ static bool check_pid(int pid) {
...
@@ -200,43 +202,26 @@ static bool check_pid(int pid) {
cmdline
==
"usap32"
sv
||
cmdline
==
"usap64"
sv
)
cmdline
==
"usap32"
sv
||
cmdline
==
"usap64"
sv
)
return
false
;
return
false
;
int
uid
=
st
.
st_uid
;
if
(
!
is_hide_target
(
uid
,
cmdline
))
// Start accessing uid_proc_map
mutex_guard
lock
(
hide_state_lock
);
auto
it
=
uid_proc_map
.
end
();
if
(
uid
%
100000
>
90000
)
{
// No way to handle isolated process
goto
not_target
;
}
it
=
uid_proc_map
.
find
(
uid
);
if
(
it
==
uid_proc_map
.
end
())
goto
not_target
;
goto
not_target
;
for
(
auto
&
s
:
it
->
second
)
{
if
(
s
!=
cmdline
)
continue
;
// Check if ns is separated (could be app zygote)
// Ensure ns is separated
read_ns
(
pid
,
&
st
);
read_ns
(
pid
,
&
st
);
for
(
auto
&
zit
:
zygote_map
)
{
for
(
auto
&
zit
:
zygote_map
)
{
if
(
zit
.
second
.
st_ino
==
st
.
st_ino
&&
if
(
zit
.
second
.
st_ino
==
st
.
st_ino
&&
zit
.
second
.
st_dev
==
st
.
st_dev
)
{
zit
.
second
.
st_dev
==
st
.
st_dev
)
{
// ns not separated, abort
// ns not separated, abort
goto
not_target
;
goto
not_target
;
}
}
}
// Finally this is our target!
// Detach from ptrace but should still remain stopped.
// The hide daemon will resume the process.
LOGI
(
"proc_monitor: [%s] PID=[%d] UID=[%d]
\n
"
,
cmdline
,
pid
,
uid
);
detach_pid
(
pid
,
SIGSTOP
);
hide_daemon
(
pid
);
return
true
;
}
}
// Detach but the process should still remain stopped
// The hide daemon will resume the process after hiding it
LOGI
(
"proc_monitor: [%s] PID=[%d] UID=[%d]
\n
"
,
cmdline
,
pid
,
uid
);
detach_pid
(
pid
,
SIGSTOP
);
hide_daemon
(
pid
);
return
true
;
not_target:
not_target:
PTRACE_LOG
(
"[%s] is not our target
\n
"
,
cmdline
);
PTRACE_LOG
(
"[%s] is not our target
\n
"
,
cmdline
);
detach_pid
(
pid
);
detach_pid
(
pid
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment