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
a4a661bf
Commit
a4a661bf
authored
Mar 11, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small code restructuring
parent
771e5004
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
62 deletions
+61
-62
proc_monitor.cpp
native/jni/magiskhide/proc_monitor.cpp
+61
-62
No files found.
native/jni/magiskhide/proc_monitor.cpp
View file @
a4a661bf
...
...
@@ -391,74 +391,73 @@ void proc_monitor() {
ptrace
(
PTRACE_DETACH
,
pid
,
0
,
0
);
}
});
if
(
WIFSTOPPED
(
status
))
{
if
(
detaches
[
pid
])
{
PTRACE_LOG
(
"detach
\n
"
);
DETACH_AND_CONT
;
}
if
(
WSTOPSIG
(
status
)
==
SIGTRAP
&&
WEVENT
(
status
))
{
unsigned
long
msg
;
xptrace
(
PTRACE_GETEVENTMSG
,
pid
,
nullptr
,
&
msg
);
if
(
zygote_map
.
count
(
pid
))
{
// Zygote event
switch
(
WEVENT
(
status
))
{
case
PTRACE_EVENT_FORK
:
case
PTRACE_EVENT_VFORK
:
PTRACE_LOG
(
"zygote forked: [%d]
\n
"
,
msg
);
attaches
[
msg
]
=
true
;
if
(
unknowns
[
msg
])
{
/* Stop the child again to make sure
* we are monitoring the proper events */
unknowns
[
msg
]
=
false
;
tgkill
(
msg
,
msg
,
SIGSTOP
);
}
break
;
case
PTRACE_EVENT_EXIT
:
PTRACE_LOG
(
"zygote exited with status: [%d]
\n
"
,
msg
);
zygote_map
.
erase
(
pid
);
DETACH_AND_CONT
;
default:
PTRACE_LOG
(
"unknown event: %d
\n
"
,
WEVENT
(
status
));
break
;
}
xptrace
(
PTRACE_CONT
,
pid
);
}
else
{
switch
(
WEVENT
(
status
))
{
case
PTRACE_EVENT_CLONE
:
PTRACE_LOG
(
"create new threads: [%d]
\n
"
,
msg
);
detaches
[
msg
]
=
true
;
if
(
attaches
[
pid
]
&&
check_pid
(
pid
))
continue
;
break
;
case
PTRACE_EVENT_EXEC
:
case
PTRACE_EVENT_EXIT
:
PTRACE_LOG
(
"exited or execve
\n
"
);
DETACH_AND_CONT
;
default:
PTRACE_LOG
(
"unknown event: %d
\n
"
,
WEVENT
(
status
));
break
;
}
xptrace
(
PTRACE_CONT
,
pid
);
if
(
!
WIFSTOPPED
(
status
))
{
// Nothing to do with us
PTRACE_LOG
(
"terminate
\n
"
);
DETACH_AND_CONT
;
}
if
(
detaches
[
pid
])
{
PTRACE_LOG
(
"detach
\n
"
);
DETACH_AND_CONT
;
}
if
(
WSTOPSIG
(
status
)
==
SIGTRAP
&&
WEVENT
(
status
))
{
unsigned
long
msg
;
xptrace
(
PTRACE_GETEVENTMSG
,
pid
,
nullptr
,
&
msg
);
if
(
zygote_map
.
count
(
pid
))
{
// Zygote event
switch
(
WEVENT
(
status
))
{
case
PTRACE_EVENT_FORK
:
case
PTRACE_EVENT_VFORK
:
PTRACE_LOG
(
"zygote forked: [%d]
\n
"
,
msg
);
attaches
[
msg
]
=
true
;
if
(
unknowns
[
msg
])
{
/* Stop the child again to make sure
* we are monitoring the proper events */
unknowns
[
msg
]
=
false
;
tgkill
(
msg
,
msg
,
SIGSTOP
);
}
break
;
case
PTRACE_EVENT_EXIT
:
PTRACE_LOG
(
"zygote exited with status: [%d]
\n
"
,
msg
);
zygote_map
.
erase
(
pid
);
DETACH_AND_CONT
;
default:
PTRACE_LOG
(
"unknown event: %d
\n
"
,
WEVENT
(
status
));
break
;
}
}
else
if
(
WSTOPSIG
(
status
)
==
SIGSTOP
)
{
if
(
attaches
[
pid
])
{
PTRACE_LOG
(
"SIGSTOP from zygote child
\n
"
);
xptrace
(
PTRACE_SETOPTIONS
,
pid
,
nullptr
,
PTRACE_O_TRACECLONE
|
PTRACE_O_TRACEEXEC
|
PTRACE_O_TRACEEXIT
);
}
else
{
PTRACE_LOG
(
"SIGSTOP from unknown
\n
"
);
unknowns
[
pid
]
=
true
;
xptrace
(
PTRACE_CONT
,
pid
);
}
else
{
switch
(
WEVENT
(
status
))
{
case
PTRACE_EVENT_CLONE
:
PTRACE_LOG
(
"create new threads: [%d]
\n
"
,
msg
);
detaches
[
msg
]
=
true
;
if
(
attaches
[
pid
]
&&
check_pid
(
pid
))
continue
;
break
;
case
PTRACE_EVENT_EXEC
:
case
PTRACE_EVENT_EXIT
:
PTRACE_LOG
(
"exited or execve
\n
"
);
DETACH_AND_CONT
;
default:
PTRACE_LOG
(
"unknown event: %d
\n
"
,
WEVENT
(
status
));
break
;
}
xptrace
(
PTRACE_CONT
,
pid
);
}
}
else
if
(
WSTOPSIG
(
status
)
==
SIGSTOP
)
{
if
(
attaches
[
pid
])
{
PTRACE_LOG
(
"SIGSTOP from zygote child
\n
"
);
xptrace
(
PTRACE_SETOPTIONS
,
pid
,
nullptr
,
PTRACE_O_TRACECLONE
|
PTRACE_O_TRACEEXEC
|
PTRACE_O_TRACEEXIT
);
}
else
{
// Not caused by us, resend signal
xptrace
(
PTRACE_CONT
,
pid
,
nullptr
,
WSTOPSIG
(
status
));
PTRACE_LOG
(
"signal [%d]
\n
"
,
WSTOPSIG
(
status
));
PTRACE_LOG
(
"SIGSTOP from unknown
\n
"
);
unknowns
[
pid
]
=
true
;
}
xptrace
(
PTRACE_CONT
,
pid
);
}
else
{
// Not
hing to do with us
PTRACE_LOG
(
"terminate
\n
"
);
DETACH_AND_CONT
;
// Not
caused by us, resend signal
xptrace
(
PTRACE_CONT
,
pid
,
nullptr
,
WSTOPSIG
(
status
)
);
PTRACE_LOG
(
"signal [%d]
\n
"
,
WSTOPSIG
(
status
))
;
}
}
}
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