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
dc29018e
Commit
dc29018e
authored
Dec 28, 2016
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce wait interval and various bug fixes
parent
b6412afe
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
46 additions
and
50 deletions
+46
-50
magiskhide.c
jni/magiskhide.c
+46
-50
No files found.
jni/magiskhide.c
View file @
dc29018e
...
...
@@ -16,11 +16,11 @@
#define LOGFILE "/cache/magisk.log"
#define HIDELIST "/magisk/.core/magiskhide/hidelist"
#define DUMMYPATH "/dev/magisk/dummy"
FILE
*
logfile
;
int
i
,
list_size
,
pipefd
[
2
],
zygote_num
=
0
;
char
**
hide_list
=
NULL
;
char
zygote_ns
[
2
][
32
];
int
i
,
list_size
,
pipefd
[
2
];
char
**
hide_list
=
NULL
,
buffer
[
512
];
pthread_mutex_t
mutex
;
char
**
file_to_str_arr
(
FILE
*
fp
,
int
*
size
)
{
...
...
@@ -64,35 +64,49 @@ void lazy_unmount(const char* mountpoint) {
}
int
hideMagisk
()
{
int
pid
;
char
path
[
256
],
cache_block
[
256
],
namespace
[
32
];
cache_block
[
0
]
=
0
;
close
(
pipefd
[
1
]);
int
pid
,
zygote_num
=
0
;
char
cache_block
[
256
],
zygote_ns
[
2
][
32
];
cache_block
[
0
]
=
'\0'
;
// Get the mount namespace of zygote
FILE
*
p
=
popen
(
"/data/busybox/ps | grep zygote | grep -v grep"
,
"r"
);
while
(
fgets
(
buffer
,
sizeof
(
buffer
),
p
))
{
if
(
zygote_num
==
2
)
break
;
sscanf
(
buffer
,
"%d"
,
&
pid
);
read_namespace
(
pid
,
zygote_ns
[
zygote_num
],
32
);
++
zygote_num
;
}
pclose
(
p
);
for
(
i
=
0
;
i
<
zygote_num
;
++
i
)
fprintf
(
logfile
,
"Zygote(%d) ns=%s "
,
i
,
zygote_ns
[
i
]);
fprintf
(
logfile
,
"
\n
"
);
while
(
1
)
{
read
(
pipefd
[
0
],
&
pid
,
sizeof
(
pid
));
if
(
pid
==
-
1
)
break
;
int
badns
;
do
{
while
(
1
)
{
badns
=
0
;
read_namespace
(
pid
,
namespace
,
32
);
read_namespace
(
pid
,
buffer
,
32
);
for
(
i
=
0
;
i
<
zygote_num
;
++
i
)
{
if
(
strcmp
(
namespace
,
zygote_ns
[
i
])
==
0
)
{
usleep
(
50
000
);
if
(
strcmp
(
buffer
,
zygote_ns
[
i
])
==
0
)
{
usleep
(
1
000
);
badns
=
1
;
break
;
}
}
if
(
badns
)
continue
;
break
;
}
while
(
1
);
if
(
!
badns
)
break
;
}
fprintf
(
logfile
,
"ns=%s
\n
"
,
namespace
);
fprintf
(
logfile
,
"ns=%s
]
\n
"
,
buffer
);
snprintf
(
path
,
256
,
"/proc/%d/ns/mnt"
,
pid
);
snprintf
(
buffer
,
sizeof
(
buffer
)
,
"/proc/%d/ns/mnt"
,
pid
);
int
fd
=
open
(
path
,
O_RDONLY
);
int
fd
=
open
(
buffer
,
O_RDONLY
);
if
(
fd
==
-
1
)
continue
;
// Maybe process died..
if
(
setns
(
fd
,
0
)
==
-
1
)
{
fprintf
(
logfile
,
"MagiskHide: Unable to change namespace for pid=%d
\n
"
,
pid
);
...
...
@@ -100,15 +114,15 @@ int hideMagisk() {
}
close
(
fd
);
snprintf
(
path
,
256
,
"/proc/%d/mounts"
,
pid
);
FILE
*
mount_fp
=
fopen
(
path
,
"r"
);
snprintf
(
buffer
,
sizeof
(
buffer
)
,
"/proc/%d/mounts"
,
pid
);
FILE
*
mount_fp
=
fopen
(
buffer
,
"r"
);
if
(
mount_fp
==
NULL
)
{
fprintf
(
logfile
,
"MagiskHide: Error opening mount list!
\n
"
);
continue
;
}
int
mount_size
;
char
**
mount_list
=
file_to_str_arr
(
mount_fp
,
&
mount_size
)
,
mountpoint
[
256
],
cache_block
[
256
]
;
char
**
mount_list
=
file_to_str_arr
(
mount_fp
,
&
mount_size
);
// Find the cache block name if not found yet
if
(
strlen
(
cache_block
)
==
0
)
{
...
...
@@ -124,12 +138,11 @@ int hideMagisk() {
for
(
i
=
mount_size
-
1
;
i
>=
0
;
--
i
)
{
if
(
strstr
(
mount_list
[
i
],
"tmpfs /system/"
)
||
strstr
(
mount_list
[
i
],
"tmpfs /vendor/"
)
||
(
strstr
(
mount_list
[
i
],
cache_block
)
&&
strstr
(
mount_list
[
i
],
"/system"
))
)
{
sscanf
(
mount_list
[
i
],
"%*s %
256s"
,
mountpoint
);
lazy_unmount
(
mountpoint
);
sscanf
(
mount_list
[
i
],
"%*s %
512s"
,
buffer
);
lazy_unmount
(
buffer
);
}
free
(
mount_list
[
i
]);
}
// Free memory
free
(
mount_list
);
// Re-read mount infos
...
...
@@ -139,13 +152,12 @@ int hideMagisk() {
// Unmount loop mounts
for
(
i
=
mount_size
-
1
;
i
>=
0
;
--
i
)
{
if
(
strstr
(
mount_list
[
i
],
"/dev/block/loop"
))
{
sscanf
(
mount_list
[
i
],
"%*s %
256s"
,
mountpoint
);
lazy_unmount
(
mountpoint
);
if
(
strstr
(
mount_list
[
i
],
"/dev/block/loop"
)
&&
!
strstr
(
mount_list
[
i
],
DUMMYPATH
)
)
{
sscanf
(
mount_list
[
i
],
"%*s %
512s"
,
buffer
);
lazy_unmount
(
buffer
);
}
free
(
mount_list
[
i
]);
}
// Free memory
free
(
mount_list
);
}
...
...
@@ -154,7 +166,7 @@ int hideMagisk() {
}
void
update_list
(
const
char
*
listpath
)
{
FILE
*
hide_fp
=
fopen
(
(
char
*
)
listpath
,
"r"
);
FILE
*
hide_fp
=
fopen
(
listpath
,
"r"
);
if
(
hide_fp
==
NULL
)
{
fprintf
(
logfile
,
"MagiskHide: Error opening hide list
\n
"
);
exit
(
1
);
...
...
@@ -187,17 +199,17 @@ void *monitor_list(void *path) {
signal
(
SIGQUIT
,
quit_pthread
);
int
inotifyFd
=
-
1
;
char
buffe
r
[
512
];
char
st
r
[
512
];
while
(
1
)
{
if
(
inotifyFd
==
-
1
||
read
(
inotifyFd
,
buffer
,
512
)
==
-
1
)
{
if
(
inotifyFd
==
-
1
||
read
(
inotifyFd
,
str
,
sizeof
(
str
)
)
==
-
1
)
{
close
(
inotifyFd
);
inotifyFd
=
inotify_init
();
if
(
inotifyFd
==
-
1
)
{
fprintf
(
logfile
,
"MagiskHide: Unable to watch %s
\n
"
,
listpath
);
exit
(
1
);
}
if
(
inotify_add_watch
(
inotifyFd
,
(
char
*
)
listpath
,
IN_MODIFY
)
==
-
1
)
{
if
(
inotify_add_watch
(
inotifyFd
,
listpath
,
IN_MODIFY
)
==
-
1
)
{
fprintf
(
logfile
,
"MagiskHide: Unable to watch %s
\n
"
,
listpath
);
exit
(
1
);
}
...
...
@@ -230,22 +242,6 @@ int main(int argc, char **argv, char **envp) {
run_as_daemon
();
// Get the mount namespace of zygote for checking
char
buffer
[
512
];
int
pid
;
FILE
*
p
=
popen
(
"/data/busybox/ps | grep zygote | grep -v grep"
,
"r"
);
while
(
fgets
(
buffer
,
sizeof
(
buffer
),
p
))
{
if
(
zygote_num
==
2
)
break
;
sscanf
(
buffer
,
"%d"
,
&
pid
);
read_namespace
(
pid
,
zygote_ns
[
zygote_num
],
32
);
++
zygote_num
;
}
pclose
(
p
);
for
(
i
=
0
;
i
<
zygote_num
;
++
i
)
fprintf
(
logfile
,
"Zygote(%d) ns=%s "
,
i
,
zygote_ns
[
i
]);
fprintf
(
logfile
,
"
\n
"
);
// Fork a child to handle namespace switches and unmounts
pipe
(
pipefd
);
switch
(
fork
())
{
...
...
@@ -263,8 +259,8 @@ int main(int argc, char **argv, char **envp) {
pthread_mutex_init
(
&
mutex
,
NULL
);
pthread_create
(
&
list_monitor
,
NULL
,
monitor_list
,
HIDELIST
);
p
=
popen
(
"while true; do logcat -b events -v raw -s am_proc_start; sleep 1; done"
,
"r"
);
// Monitor am_proc_start in main thread
FILE
*
p
=
popen
(
"while true; do logcat -b events -v raw -s am_proc_start; sleep 1; done"
,
"r"
);
while
(
!
feof
(
p
))
{
//Format of am_proc_start is (as of Android 5.1 and 6.0)
//UserID, pid, unix uid, processName, hostingType, hostingName
...
...
@@ -289,7 +285,7 @@ int main(int argc, char **argv, char **envp) {
for
(
i
=
0
;
i
<
list_size
;
++
i
)
{
if
(
strstr
(
processName
,
hide_list
[
i
]))
{
fprintf
(
logfile
,
"MagiskHide:
Disabling for process=%s, PID=%d, "
,
processName
,
pid
,
u
id
);
fprintf
(
logfile
,
"MagiskHide:
%s[PID=%d "
,
processName
,
p
id
);
write
(
pipefd
[
1
],
&
pid
,
sizeof
(
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