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
a223f605
Commit
a223f605
authored
Apr 06, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add zygote namespace detection
parent
a1fd7704
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
28 additions
and
4 deletions
+28
-4
hide_daemon.c
jni/magiskhide/hide_daemon.c
+1
-1
magiskhide.c
jni/magiskhide/magiskhide.c
+12
-0
proc_monitor.c
jni/magiskhide/proc_monitor.c
+14
-3
misc.c
jni/utils/misc.c
+1
-0
No files found.
jni/magiskhide/hide_daemon.c
View file @
a223f605
...
@@ -9,10 +9,10 @@
...
@@ -9,10 +9,10 @@
#include <unistd.h>
#include <unistd.h>
#include <string.h>
#include <string.h>
#include <fcntl.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/mount.h>
#include <sys/mount.h>
#include <sys/prctl.h>
#include "magisk.h"
#include "magisk.h"
#include "utils.h"
#include "utils.h"
...
...
jni/magiskhide/magiskhide.c
View file @
a223f605
...
@@ -7,6 +7,8 @@
...
@@ -7,6 +7,8 @@
#include <stdlib.h>
#include <stdlib.h>
#include <unistd.h>
#include <unistd.h>
#include <pthread.h>
#include <pthread.h>
#include <signal.h>
#include <sys/types.h>
#include "magisk.h"
#include "magisk.h"
#include "utils.h"
#include "utils.h"
...
@@ -17,6 +19,10 @@ struct vector *hide_list, *new_list;
...
@@ -17,6 +19,10 @@ struct vector *hide_list, *new_list;
static
pthread_t
proc_monitor_thread
;
static
pthread_t
proc_monitor_thread
;
static
void
kill_proc
(
int
pid
)
{
kill
(
pid
,
SIGTERM
);
}
void
launch_magiskhide
()
{
void
launch_magiskhide
()
{
/*
/*
* The setns system call do not support multithread processes
* The setns system call do not support multithread processes
...
@@ -36,9 +42,15 @@ void launch_magiskhide() {
...
@@ -36,9 +42,15 @@ void launch_magiskhide() {
FILE
*
fp
=
xfopen
(
HIDELIST
,
"r"
);
FILE
*
fp
=
xfopen
(
HIDELIST
,
"r"
);
file_to_vector
(
hide_list
,
fp
);
file_to_vector
(
hide_list
,
fp
);
fclose
(
fp
);
fclose
(
fp
);
char
*
line
;
vec_for_each
(
hide_list
,
line
)
{
LOGI
(
"hide_list: [%s]
\n
"
,
line
);
ps_filter_proc_name
(
line
,
kill_proc
);
}
// Start a new thread to monitor processes
// Start a new thread to monitor processes
pthread_create
(
&
proc_monitor_thread
,
NULL
,
proc_monitor
,
NULL
);
pthread_create
(
&
proc_monitor_thread
,
NULL
,
proc_monitor
,
NULL
);
pthread_join
(
proc_monitor_thread
,
NULL
);
}
}
void
stop_magiskhide
()
{
void
stop_magiskhide
()
{
...
...
jni/magiskhide/proc_monitor.c
View file @
a223f605
...
@@ -20,6 +20,9 @@
...
@@ -20,6 +20,9 @@
#define pthread_cleanup_push_fix(routine, arg) \
#define pthread_cleanup_push_fix(routine, arg) \
pthread_cleanup_push(routine, arg) } while(0);
pthread_cleanup_push(routine, arg) } while(0);
static
int
zygote_num
=
0
;
static
char
init_ns
[
32
],
zygote_ns
[
2
][
32
];
static
void
read_namespace
(
const
int
pid
,
char
*
target
,
const
size_t
size
)
{
static
void
read_namespace
(
const
int
pid
,
char
*
target
,
const
size_t
size
)
{
char
path
[
32
];
char
path
[
32
];
snprintf
(
path
,
sizeof
(
path
),
"/proc/%d/ns/mnt"
,
pid
);
snprintf
(
path
,
sizeof
(
path
),
"/proc/%d/ns/mnt"
,
pid
);
...
@@ -40,13 +43,21 @@ static void cleanup_handler(void *arg) {
...
@@ -40,13 +43,21 @@ static void cleanup_handler(void *arg) {
hide_list
=
new_list
=
NULL
;
hide_list
=
new_list
=
NULL
;
}
}
static
void
store_zygote_ns
(
int
pid
)
{
do
{
usleep
(
500
);
read_namespace
(
pid
,
zygote_ns
[
zygote_num
],
32
);
}
while
(
strcmp
(
zygote_ns
[
zygote_num
],
init_ns
)
==
0
);
++
zygote_num
;
}
void
*
proc_monitor
(
void
*
args
)
{
void
*
proc_monitor
(
void
*
args
)
{
// Register the cancel signal
// Register the cancel signal
signal
(
SIGUSR1
,
quit_pthread
);
signal
(
SIGUSR1
,
quit_pthread
);
pthread_cleanup_push_fix
(
cleanup_handler
,
NULL
);
pthread_cleanup_push_fix
(
cleanup_handler
,
NULL
);
int
pid
,
zygote_num
=
0
;
int
pid
;
char
init_ns
[
32
],
zygote_ns
[
2
][
32
],
buffer
[
512
];
char
buffer
[
512
];
FILE
*
p
;
FILE
*
p
;
// Get the mount namespace of init
// Get the mount namespace of init
...
@@ -54,7 +65,7 @@ void *proc_monitor(void *args) {
...
@@ -54,7 +65,7 @@ void *proc_monitor(void *args) {
LOGI
(
"proc_monitor: init ns=%s
\n
"
,
init_ns
);
LOGI
(
"proc_monitor: init ns=%s
\n
"
,
init_ns
);
// Get the mount namespace of zygote
// Get the mount namespace of zygote
// TODO: Crawl through /proc to get process names
ps_filter_proc_name
(
"zygote"
,
store_zygote_ns
);
switch
(
zygote_num
)
{
switch
(
zygote_num
)
{
case
1
:
case
1
:
...
...
jni/utils/misc.c
View file @
a223f605
...
@@ -97,6 +97,7 @@ static void proc_name_filter(int pid) {
...
@@ -97,6 +97,7 @@ static void proc_name_filter(int pid) {
fdreadline
(
fd
,
buf
,
sizeof
(
buf
));
fdreadline
(
fd
,
buf
,
sizeof
(
buf
));
}
}
if
(
strstr
(
buf
,
ps_filter_pattern
))
{
if
(
strstr
(
buf
,
ps_filter_pattern
))
{
// printf("%d: %s\n", pid, buf);
ps_filter_cb
(
pid
);
ps_filter_cb
(
pid
);
}
}
close
(
fd
);
close
(
fd
);
...
...
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