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
c8c57c74
Commit
c8c57c74
authored
Nov 23, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimize proc_monitor
parent
0784448c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
27 deletions
+16
-27
proc_monitor.cpp
native/jni/magiskhide/proc_monitor.cpp
+16
-27
No files found.
native/jni/magiskhide/proc_monitor.cpp
View file @
c8c57c74
...
@@ -43,29 +43,27 @@ static int read_ns(const int pid, struct stat *st) {
...
@@ -43,29 +43,27 @@ static int read_ns(const int pid, struct stat *st) {
return
stat
(
path
,
st
);
return
stat
(
path
,
st
);
}
}
static
void
lazy_unmount
(
const
char
*
mountpoint
)
{
static
inline
void
lazy_unmount
(
const
char
*
mountpoint
)
{
if
(
umount2
(
mountpoint
,
MNT_DETACH
)
!=
-
1
)
if
(
umount2
(
mountpoint
,
MNT_DETACH
)
!=
-
1
)
LOGD
(
"hide_daemon: Unmounted (%s)
\n
"
,
mountpoint
);
LOGD
(
"hide_daemon: Unmounted (%s)
\n
"
,
mountpoint
);
}
}
static
int
parse_ppid
(
int
pid
)
{
static
int
parse_ppid
(
int
pid
)
{
char
stat
[
512
],
path
[
32
];
char
path
[
32
];
int
fd
,
ppid
;
int
ppid
;
sprintf
(
path
,
"/proc/%d/stat"
,
pid
);
sprintf
(
path
,
"/proc/%d/stat"
,
pid
);
fd
=
xopen
(
path
,
O_RDONLY
);
FILE
*
stat
=
fopen
(
path
,
"r"
);
if
(
fd
<
0
)
if
(
stat
==
nullptr
)
return
-
1
;
return
-
1
;
xread
(
fd
,
stat
,
sizeof
(
stat
));
close
(
fd
);
/* PID COMM STATE PPID ..... */
/* PID COMM STATE PPID ..... */
s
scanf
(
stat
,
"%*d %*s %*c %d"
,
&
ppid
);
f
scanf
(
stat
,
"%*d %*s %*c %d"
,
&
ppid
);
return
ppid
;
return
ppid
;
}
}
static
void
hide_daemon
(
int
pid
)
{
static
void
hide_daemon
(
int
pid
)
{
LOGD
(
"hide_daemon: start unmount for pid=[%d]
\n
"
,
pid
);
LOGD
(
"hide_daemon: start unmount for pid=[%d]
\n
"
,
pid
);
char
buffer
[
PATH_MAX
];
char
buffer
[
4096
];
Vector
<
CharArray
>
mounts
;
Vector
<
CharArray
>
mounts
;
manage_selinux
();
manage_selinux
();
...
@@ -126,30 +124,27 @@ void proc_monitor() {
...
@@ -126,30 +124,27 @@ void proc_monitor() {
// Connect to the log daemon
// Connect to the log daemon
sockfd
=
connect_log_daemon
();
sockfd
=
connect_log_daemon
();
if
(
sockfd
<
0
)
if
(
sockfd
<
0
)
return
;
pthread_exit
(
nullptr
)
;
write_int
(
sockfd
,
HIDE_CONNECT
);
write_int
(
sockfd
,
HIDE_CONNECT
);
FILE
*
log_in
=
fdopen
(
sockfd
,
"r"
);
FILE
*
log_in
=
fdopen
(
sockfd
,
"r"
);
char
buf
[
4096
];
char
buf
[
4096
];
while
(
fgets
(
buf
,
sizeof
(
buf
),
log_in
))
{
while
(
fgets
(
buf
,
sizeof
(
buf
),
log_in
))
{
char
*
ss
=
strchr
(
buf
,
'['
);
char
*
ss
=
strchr
(
buf
,
'['
)
+
1
;
int
pid
,
ppid
,
num
=
0
;
int
pid
,
ppid
,
num
=
0
;
char
*
pos
=
ss
,
proc
[
256
];
char
*
pos
=
ss
,
proc
[
256
];
struct
stat
ns
,
pns
;
struct
stat
ns
,
pns
;
while
(
1
)
{
while
((
pos
=
strchr
(
pos
,
','
)))
{
pos
=
strchr
(
pos
,
','
);
*
pos
=
' '
;
if
(
pos
==
NULL
)
break
;
pos
[
0
]
=
' '
;
++
num
;
++
num
;
}
}
if
(
sscanf
(
ss
,
num
==
6
?
"
[%*d %d %*d %*d %256s"
:
"[
%*d %d %*d %256s"
,
&
pid
,
proc
)
!=
2
)
if
(
sscanf
(
ss
,
num
==
6
?
"
%*d %d %*d %*d %256s"
:
"
%*d %d %*d %256s"
,
&
pid
,
proc
)
!=
2
)
continue
;
continue
;
// Make sure our target is alive
// Make sure our target is alive
if
(
kill
(
pid
,
0
))
if
(
(
ppid
=
parse_ppid
(
pid
))
<
0
||
read_ns
(
ppid
,
&
pns
))
continue
;
continue
;
// Allow hiding sub-services of applications
// Allow hiding sub-services of applications
...
@@ -167,17 +162,11 @@ void proc_monitor() {
...
@@ -167,17 +162,11 @@ void proc_monitor() {
}
}
pthread_mutex_unlock
(
&
list_lock
);
pthread_mutex_unlock
(
&
list_lock
);
if
(
!
hide
||
(
ppid
=
parse_ppid
(
pid
))
<
0
||
read_ns
(
ppid
,
&
pns
)
==
-
1
)
if
(
!
hide
)
continue
;
continue
;
do
{
while
(
read_ns
(
pid
,
&
ns
)
==
0
&&
ns
.
st_dev
==
pns
.
st_dev
&&
ns
.
st_ino
==
pns
.
st_ino
)
if
(
read_ns
(
pid
,
&
ns
)
==
-
1
)
usleep
(
500
);
break
;
if
(
ns
.
st_dev
==
pns
.
st_dev
&&
ns
.
st_ino
==
pns
.
st_ino
)
usleep
(
50
);
else
break
;
}
while
(
1
);
// Send pause signal ASAP
// Send pause signal ASAP
if
(
kill
(
pid
,
SIGSTOP
)
==
-
1
)
if
(
kill
(
pid
,
SIGSTOP
)
==
-
1
)
...
...
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