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
3a2a2a4f
Commit
3a2a2a4f
authored
Nov 13, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Micro optimizations
parent
9592a699
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
26 additions
and
26 deletions
+26
-26
bootstages.cpp
native/jni/daemon/bootstages.cpp
+7
-7
daemon.cpp
native/jni/daemon/daemon.cpp
+14
-0
daemon.h
native/jni/include/daemon.h
+1
-0
proc_monitor.cpp
native/jni/magiskhide/proc_monitor.cpp
+4
-4
utils.h
native/jni/utils/include/utils.h
+0
-1
misc.cpp
native/jni/utils/misc.cpp
+0
-14
No files found.
native/jni/daemon/bootstages.cpp
View file @
3a2a2a4f
...
@@ -506,21 +506,21 @@ static bool magisk_env() {
...
@@ -506,21 +506,21 @@ static bool magisk_env() {
strcmp
(
entry
->
d_name
,
".core"
)
==
0
||
strcmp
(
entry
->
d_name
,
".core"
)
==
0
||
strcmp
(
entry
->
d_name
,
"lost+found"
)
==
0
)
strcmp
(
entry
->
d_name
,
"lost+found"
)
==
0
)
continue
;
continue
;
snprintf
(
buf
,
PATH_MAX
,
"%s/%s/remove"
,
MOUNTPOINT
,
entry
->
d_name
);
snprintf
(
buf
,
PATH_MAX
,
"%s/%s"
,
MOUNTPOINT
,
entry
->
d_name
);
if
(
access
(
buf
,
F_OK
)
==
0
)
{
chdir
(
buf
);
snprintf
(
buf
,
PATH_MAX
,
"%s/%s"
,
MOUNTPOINT
,
entry
->
d_name
);
if
(
access
(
"remove"
,
F_OK
)
==
0
)
{
chdir
(
".."
);
rm_rf
(
buf
);
rm_rf
(
buf
);
continue
;
continue
;
}
}
snprintf
(
buf
,
PATH_MAX
,
"%s/%s/update"
,
MOUNTPOINT
,
entry
->
d_name
);
unlink
(
"update"
);
unlink
(
buf
);
if
(
access
(
"disable"
,
F_OK
)
==
0
)
snprintf
(
buf
,
PATH_MAX
,
"%s/%s/disable"
,
MOUNTPOINT
,
entry
->
d_name
);
if
(
access
(
buf
,
F_OK
)
==
0
)
continue
;
continue
;
module_list
.
push_back
(
entry
->
d_name
);
module_list
.
push_back
(
entry
->
d_name
);
}
}
}
}
closedir
(
dir
);
closedir
(
dir
);
chdir
(
"/"
);
return
trim_img
(
MAINIMG
,
MOUNTPOINT
,
magiskloop
)
==
0
;
return
trim_img
(
MAINIMG
,
MOUNTPOINT
,
magiskloop
)
==
0
;
}
}
...
...
native/jni/daemon/daemon.cpp
View file @
3a2a2a4f
...
@@ -132,6 +132,20 @@ static void main_daemon() {
...
@@ -132,6 +132,20 @@ static void main_daemon() {
}
}
}
}
int
switch_mnt_ns
(
int
pid
)
{
char
mnt
[
32
];
snprintf
(
mnt
,
sizeof
(
mnt
),
"/proc/%d/ns/mnt"
,
pid
);
if
(
access
(
mnt
,
R_OK
)
==
-
1
)
return
1
;
// Maybe process died..
int
fd
,
ret
;
fd
=
xopen
(
mnt
,
O_RDONLY
);
if
(
fd
<
0
)
return
1
;
// Switch to its namespace
ret
=
xsetns
(
fd
,
0
);
close
(
fd
);
return
ret
;
}
int
connect_daemon
()
{
int
connect_daemon
()
{
struct
sockaddr_un
sun
;
struct
sockaddr_un
sun
;
socklen_t
len
=
setup_sockaddr
(
&
sun
,
MAIN_SOCKET
);
socklen_t
len
=
setup_sockaddr
(
&
sun
,
MAIN_SOCKET
);
...
...
native/jni/include/daemon.h
View file @
3a2a2a4f
...
@@ -37,6 +37,7 @@ enum {
...
@@ -37,6 +37,7 @@ enum {
// daemon.c
// daemon.c
int
connect_daemon
();
int
connect_daemon
();
int
switch_mnt_ns
(
int
pid
);
// log_monitor.c
// log_monitor.c
...
...
native/jni/magiskhide/proc_monitor.cpp
View file @
3a2a2a4f
...
@@ -72,9 +72,10 @@ static void hide_daemon(int pid) {
...
@@ -72,9 +72,10 @@ static void hide_daemon(int pid) {
if
(
switch_mnt_ns
(
pid
))
if
(
switch_mnt_ns
(
pid
))
goto
exit
;
goto
exit
;
snprintf
(
buffer
,
sizeof
(
buffer
),
"/proc/%d
/mounts
"
,
pid
);
snprintf
(
buffer
,
sizeof
(
buffer
),
"/proc/%d"
,
pid
);
file_to_vector
(
buffer
,
mounts
);
chdir
(
buffer
);
file_to_vector
(
"mounts"
,
mounts
);
// Unmount dummy skeletons and /sbin links
// Unmount dummy skeletons and /sbin links
for
(
auto
&
s
:
mounts
)
{
for
(
auto
&
s
:
mounts
)
{
if
(
s
.
contains
(
"tmpfs /system/"
)
||
s
.
contains
(
"tmpfs /vendor/"
)
||
s
.
contains
(
"tmpfs /sbin"
))
{
if
(
s
.
contains
(
"tmpfs /system/"
)
||
s
.
contains
(
"tmpfs /vendor/"
)
||
s
.
contains
(
"tmpfs /sbin"
))
{
...
@@ -85,8 +86,7 @@ static void hide_daemon(int pid) {
...
@@ -85,8 +86,7 @@ static void hide_daemon(int pid) {
mounts
.
clear
();
mounts
.
clear
();
// Re-read mount infos
// Re-read mount infos
snprintf
(
buffer
,
sizeof
(
buffer
),
"/proc/%d/mounts"
,
pid
);
file_to_vector
(
"mounts"
,
mounts
);
file_to_vector
(
buffer
,
mounts
);
// Unmount everything under /system, /vendor, and loop mounts
// Unmount everything under /system, /vendor, and loop mounts
for
(
auto
&
s
:
mounts
)
{
for
(
auto
&
s
:
mounts
)
{
...
...
native/jni/utils/include/utils.h
View file @
3a2a2a4f
...
@@ -94,7 +94,6 @@ int is_num(const char *s);
...
@@ -94,7 +94,6 @@ int is_num(const char *s);
int
exec_array
(
int
err
,
int
*
fd
,
void
(
*
cb
)(
void
),
const
char
*
argv
[]);
int
exec_array
(
int
err
,
int
*
fd
,
void
(
*
cb
)(
void
),
const
char
*
argv
[]);
int
exec_command
(
int
err
,
int
*
fd
,
void
(
*
cb
)(
void
),
const
char
*
argv0
,
...);
int
exec_command
(
int
err
,
int
*
fd
,
void
(
*
cb
)(
void
),
const
char
*
argv0
,
...);
int
exec_command_sync
(
const
char
*
argv0
,
...);
int
exec_command_sync
(
const
char
*
argv0
,
...);
int
switch_mnt_ns
(
int
pid
);
int
fork_dont_care
();
int
fork_dont_care
();
void
gen_rand_str
(
char
*
buf
,
int
len
);
void
gen_rand_str
(
char
*
buf
,
int
len
);
int
strend
(
const
char
*
s1
,
const
char
*
s2
);
int
strend
(
const
char
*
s1
,
const
char
*
s2
);
...
...
native/jni/utils/misc.cpp
View file @
3a2a2a4f
...
@@ -67,20 +67,6 @@ ssize_t fdgets(char *buf, const size_t size, int fd) {
...
@@ -67,20 +67,6 @@ ssize_t fdgets(char *buf, const size_t size, int fd) {
return
len
;
return
len
;
}
}
int
switch_mnt_ns
(
int
pid
)
{
char
mnt
[
32
];
snprintf
(
mnt
,
sizeof
(
mnt
),
"/proc/%d/ns/mnt"
,
pid
);
if
(
access
(
mnt
,
R_OK
)
==
-
1
)
return
1
;
// Maybe process died..
int
fd
,
ret
;
fd
=
xopen
(
mnt
,
O_RDONLY
);
if
(
fd
<
0
)
return
1
;
// Switch to its namespace
ret
=
xsetns
(
fd
,
0
);
close
(
fd
);
return
ret
;
}
int
fork_dont_care
()
{
int
fork_dont_care
()
{
int
pid
=
xfork
();
int
pid
=
xfork
();
if
(
pid
)
{
if
(
pid
)
{
...
...
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