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
7b5d79d3
Commit
7b5d79d3
authored
Aug 07, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Kill all processes using the same UID of the target
To workaround OOS embryo optimization
parent
3e3f3850
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
32 deletions
+42
-32
utils.h
native/jni/include/utils.h
+1
-1
hide_utils.c
native/jni/magiskhide/hide_utils.c
+31
-6
misc.c
native/jni/utils/misc.c
+10
-25
No files found.
native/jni/include/utils.h
View file @
7b5d79d3
...
...
@@ -95,7 +95,7 @@ ssize_t fdgets(char *buf, size_t size, int fd);
ssize_t
my_getline
(
char
**
lineptr
,
size_t
*
n
,
FILE
*
stream
);
ssize_t
my_getdelim
(
char
**
lineptr
,
size_t
*
n
,
int
delim
,
FILE
*
stream
);
void
ps
(
void
(
*
func
)(
int
));
void
ps_filter_proc_name
(
const
char
*
filter
,
void
(
*
func
)(
int
)
);
int
check_proc_name
(
int
pid
,
const
char
*
filter
);
void
unlock_blocks
();
void
setup_sighandlers
(
void
(
*
handler
)(
int
));
int
exec_array
(
int
err
,
int
*
fd
,
void
(
*
setenv
)(
struct
vector
*
),
char
*
const
*
argv
);
...
...
native/jni/magiskhide/hide_utils.c
View file @
7b5d79d3
...
...
@@ -27,6 +27,9 @@ static char *prop_value[] =
"0"
,
"0"
,
"0"
,
"1"
,
"user"
,
"release-keys"
,
"0"
,
NULL
};
static
const
char
*
proc_name
;
static
gid_t
proc_gid
;
void
manage_selinux
()
{
char
val
;
int
fd
=
xopen
(
SELINUX_ENFORCE
,
O_RDONLY
);
...
...
@@ -60,8 +63,30 @@ static void rm_magisk_prop(const char *name, const char *value, void *v) {
}
}
static
void
kill_proc
(
int
pid
)
{
kill
(
pid
,
SIGTERM
);
static
void
kill_proc_cb
(
int
pid
)
{
if
(
check_proc_name
(
pid
,
proc_name
))
kill
(
pid
,
SIGTERM
);
else
if
(
proc_gid
>
0
)
{
char
buf
[
128
];
struct
stat
st
;
sprintf
(
buf
,
"/proc/%d"
,
pid
);
stat
(
buf
,
&
st
);
if
(
proc_gid
==
st
.
st_gid
)
kill
(
pid
,
SIGTERM
);
}
}
static
void
kill_process
(
const
char
*
name
)
{
proc_name
=
name
;
char
buf
[
128
];
struct
stat
st
;
sprintf
(
buf
,
"/data/data/%s"
,
name
);
if
(
stat
(
buf
,
&
st
)
==
0
)
proc_gid
=
st
.
st_gid
;
else
proc_gid
=
0
;
ps
(
kill_proc_cb
);
}
void
clean_magisk_props
()
{
...
...
@@ -94,7 +119,7 @@ int add_list(char *proc) {
vec_push_back
(
new_list
,
proc
);
LOGI
(
"hide_list add: [%s]
\n
"
,
proc
);
ps_filter_proc_name
(
proc
,
kill_
proc
);
kill_process
(
proc
);
// Critical region
pthread_mutex_lock
(
&
hide_lock
);
...
...
@@ -135,7 +160,7 @@ int rm_list(char *proc) {
if
(
do_rm
)
{
LOGI
(
"hide_list rm: [%s]
\n
"
,
proc
);
ps_filter_proc_name
(
proc
,
kill_
proc
);
kill_process
(
proc
);
// Critical region
pthread_mutex_lock
(
&
hide_lock
);
vec_destroy
(
hide_list
);
...
...
@@ -170,7 +195,7 @@ int init_list() {
char
*
line
;
vec_for_each
(
hide_list
,
line
)
{
LOGI
(
"hide_list: [%s]
\n
"
,
line
);
ps_filter_proc_name
(
line
,
kill_proc
);
kill_process
(
line
);
}
return
0
;
}
...
...
@@ -178,7 +203,7 @@ int init_list() {
int
destroy_list
()
{
char
*
line
;
vec_for_each
(
hide_list
,
line
)
{
ps_filter_proc_name
(
line
,
kill_proc
);
kill_process
(
line
);
}
vec_deep_destroy
(
hide_list
);
free
(
hide_list
);
...
...
native/jni/utils/misc.c
View file @
7b5d79d3
...
...
@@ -240,49 +240,34 @@ void ps(void (*func)(int)) {
closedir
(
dir
);
}
// Internal usage
static
void
(
*
ps_filter_cb
)(
int
);
static
const
char
*
ps_filter_pattern
;
static
void
proc_name_filter
(
int
pid
)
{
int
check_proc_name
(
int
pid
,
const
char
*
name
)
{
char
buf
[
128
];
FILE
*
f
;
sprintf
(
buf
,
"/proc/%d/comm"
,
pid
);
if
((
f
=
fopen
(
buf
,
"r"
)))
{
fgets
(
buf
,
sizeof
(
buf
),
f
);
if
(
strcmp
(
buf
,
ps_filter_pattern
)
==
0
)
goto
run_cb
;
if
(
strcmp
(
buf
,
name
)
==
0
)
return
1
;
}
else
{
// The PID is already killed
return
;
return
0
;
}
fclose
(
f
);
sprintf
(
buf
,
"/proc/%d/cmdline"
,
pid
);
f
=
fopen
(
buf
,
"r"
);
fgets
(
buf
,
sizeof
(
buf
),
f
);
if
(
strcmp
(
basename
(
buf
),
ps_filter_pattern
)
==
0
)
goto
run_cb
;
if
(
strcmp
(
basename
(
buf
),
name
)
==
0
)
return
1
;
fclose
(
f
);
sprintf
(
buf
,
"/proc/%d/exe"
,
pid
);
if
(
access
(
buf
,
F_OK
)
!=
0
)
return
;
return
0
;
xreadlink
(
buf
,
buf
,
sizeof
(
buf
));
if
(
strcmp
(
basename
(
buf
),
ps_filter_pattern
)
==
0
)
goto
run_cb
;
return
;
run_cb:
ps_filter_cb
(
pid
);
fclose
(
f
);
return
;
}
/* Call func with process name filtered with pattern */
void
ps_filter_proc_name
(
const
char
*
pattern
,
void
(
*
func
)(
int
))
{
ps_filter_cb
=
func
;
ps_filter_pattern
=
((
pattern
==
NULL
)
?
""
:
pattern
);
ps
(
proc_name_filter
);
if
(
strcmp
(
basename
(
buf
),
name
)
==
0
)
return
1
;
return
0
;
}
void
unlock_blocks
()
{
...
...
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