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
92400ebc
Commit
92400ebc
authored
May 26, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Process monitor minor tweaks
parent
23d3e569
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
20 deletions
+15
-20
proc_monitor.cpp
native/jni/magiskhide/proc_monitor.cpp
+15
-20
No files found.
native/jni/magiskhide/proc_monitor.cpp
View file @
92400ebc
...
@@ -159,8 +159,8 @@ static void setup_inotify() {
...
@@ -159,8 +159,8 @@ static void setup_inotify() {
// Setup inotify asynchronous I/O
// Setup inotify asynchronous I/O
fcntl
(
inotify_fd
,
F_SETFL
,
O_ASYNC
);
fcntl
(
inotify_fd
,
F_SETFL
,
O_ASYNC
);
struct
f_owner_ex
ex
=
{
struct
f_owner_ex
ex
=
{
.
type
=
F_OWNER_TID
,
.
type
=
F_OWNER_TID
,
.
pid
=
gettid
()
.
pid
=
gettid
()
};
};
fcntl
(
inotify_fd
,
F_SETOWN_EX
,
&
ex
);
fcntl
(
inotify_fd
,
F_SETOWN_EX
,
&
ex
);
...
@@ -285,6 +285,7 @@ static void term_thread(int) {
...
@@ -285,6 +285,7 @@ static void term_thread(int) {
static
void
detach_pid
(
int
pid
,
int
signal
=
0
)
{
static
void
detach_pid
(
int
pid
,
int
signal
=
0
)
{
char
path
[
128
];
char
path
[
128
];
attaches
[
pid
]
=
false
;
xptrace
(
PTRACE_DETACH
,
pid
,
nullptr
,
signal
);
xptrace
(
PTRACE_DETACH
,
pid
,
nullptr
,
signal
);
// Detach all child threads too
// Detach all child threads too
...
@@ -318,10 +319,6 @@ static bool check_pid(int pid) {
...
@@ -318,10 +319,6 @@ static bool check_pid(int pid) {
if
(
strncmp
(
cmdline
,
"zygote"
,
6
)
==
0
)
if
(
strncmp
(
cmdline
,
"zygote"
,
6
)
==
0
)
return
false
;
return
false
;
/* This process is fully initialized, we will stop
* tracing it no matter if it is a target or not. */
attaches
[
pid
]
=
false
;
sprintf
(
path
,
"/proc/%d"
,
pid
);
sprintf
(
path
,
"/proc/%d"
,
pid
);
struct
stat
st
;
struct
stat
st
;
lstat
(
path
,
&
st
);
lstat
(
path
,
&
st
);
...
@@ -415,11 +412,11 @@ void proc_monitor() {
...
@@ -415,11 +412,11 @@ void proc_monitor() {
/* This mean we have nothing to wait, sleep
/* This mean we have nothing to wait, sleep
* and wait till signal interruption */
* and wait till signal interruption */
LOGD
(
"proc_monitor: nothing to monitor, wait for signal
\n
"
);
LOGD
(
"proc_monitor: nothing to monitor, wait for signal
\n
"
);
struct
timespec
t
imespec
=
{
struct
timespec
t
s
=
{
.
tv_sec
=
INT_MAX
,
.
tv_sec
=
INT_MAX
,
.
tv_nsec
=
0
.
tv_nsec
=
0
};
};
nanosleep
(
&
t
imespec
,
nullptr
);
nanosleep
(
&
t
s
,
nullptr
);
}
}
continue
;
continue
;
}
}
...
@@ -430,12 +427,13 @@ void proc_monitor() {
...
@@ -430,12 +427,13 @@ void proc_monitor() {
attaches
[
pid
]
=
false
;
attaches
[
pid
]
=
false
;
detaches
[
pid
]
=
false
;
detaches
[
pid
]
=
false
;
ptrace
(
PTRACE_DETACH
,
pid
,
0
,
0
);
ptrace
(
PTRACE_DETACH
,
pid
,
0
,
0
);
PTRACE_LOG
(
"detach
\n
"
);
}
}
});
});
if
(
!
WIFSTOPPED
(
status
)
||
detaches
[
pid
])
{
PTRACE_LOG
(
"detached
\n
"
);
if
(
!
WIFSTOPPED
(
status
)
/* Ignore if not ptrace-stop */
||
detaches
[
pid
])
DETACH_AND_CONT
;
DETACH_AND_CONT
;
}
if
(
WSTOPSIG
(
status
)
==
SIGTRAP
&&
WEVENT
(
status
))
{
if
(
WSTOPSIG
(
status
)
==
SIGTRAP
&&
WEVENT
(
status
))
{
unsigned
long
msg
;
unsigned
long
msg
;
xptrace
(
PTRACE_GETEVENTMSG
,
pid
,
nullptr
,
&
msg
);
xptrace
(
PTRACE_GETEVENTMSG
,
pid
,
nullptr
,
&
msg
);
...
@@ -449,13 +447,11 @@ void proc_monitor() {
...
@@ -449,13 +447,11 @@ void proc_monitor() {
break
;
break
;
case
PTRACE_EVENT_EXIT
:
case
PTRACE_EVENT_EXIT
:
PTRACE_LOG
(
"zygote exited with status: [%d]
\n
"
,
msg
);
PTRACE_LOG
(
"zygote exited with status: [%d]
\n
"
,
msg
);
[[
fallthrough
]];
default:
zygote_map
.
erase
(
pid
);
zygote_map
.
erase
(
pid
);
DETACH_AND_CONT
;
DETACH_AND_CONT
;
default:
PTRACE_LOG
(
"unknown event: %d
\n
"
,
WEVENT
(
status
));
break
;
}
}
xptrace
(
PTRACE_CONT
,
pid
);
}
else
{
}
else
{
switch
(
WEVENT
(
status
))
{
switch
(
WEVENT
(
status
))
{
case
PTRACE_EVENT_CLONE
:
case
PTRACE_EVENT_CLONE
:
...
@@ -465,14 +461,13 @@ void proc_monitor() {
...
@@ -465,14 +461,13 @@ void proc_monitor() {
break
;
break
;
case
PTRACE_EVENT_EXEC
:
case
PTRACE_EVENT_EXEC
:
case
PTRACE_EVENT_EXIT
:
case
PTRACE_EVENT_EXIT
:
PTRACE_LOG
(
"exit
ed
or execve
\n
"
);
PTRACE_LOG
(
"exit or execve
\n
"
);
DETACH_AND_CONT
;
[[
fallthrough
]]
;
default:
default:
PTRACE_LOG
(
"unknown event: %d
\n
"
,
WEVENT
(
status
));
DETACH_AND_CONT
;
break
;
}
}
xptrace
(
PTRACE_CONT
,
pid
);
}
}
xptrace
(
PTRACE_CONT
,
pid
);
}
else
if
(
WSTOPSIG
(
status
)
==
SIGSTOP
)
{
}
else
if
(
WSTOPSIG
(
status
)
==
SIGSTOP
)
{
PTRACE_LOG
(
"SIGSTOP from child
\n
"
);
PTRACE_LOG
(
"SIGSTOP from child
\n
"
);
xptrace
(
PTRACE_SETOPTIONS
,
pid
,
nullptr
,
xptrace
(
PTRACE_SETOPTIONS
,
pid
,
nullptr
,
...
...
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