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
0bf04c04
Commit
0bf04c04
authored
Dec 29, 2016
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Final fix for MagiskHide, all is well!
parent
dc29018e
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
22 deletions
+36
-22
magiskhide.c
jni/magiskhide.c
+36
-22
No files found.
jni/magiskhide.c
View file @
0bf04c04
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
FILE
*
logfile
;
FILE
*
logfile
;
int
i
,
list_size
,
pipefd
[
2
];
int
i
,
list_size
,
pipefd
[
2
];
char
**
hide_list
=
NULL
,
buffer
[
512
];
char
**
hide_list
=
NULL
,
buffer
[
512
];
pthread_t
list_monitor
;
pthread_mutex_t
mutex
;
pthread_mutex_t
mutex
;
char
**
file_to_str_arr
(
FILE
*
fp
,
int
*
size
)
{
char
**
file_to_str_arr
(
FILE
*
fp
,
int
*
size
)
{
...
@@ -86,15 +87,17 @@ int hideMagisk() {
...
@@ -86,15 +87,17 @@ int hideMagisk() {
while
(
1
)
{
while
(
1
)
{
read
(
pipefd
[
0
],
&
pid
,
sizeof
(
pid
));
read
(
pipefd
[
0
],
&
pid
,
sizeof
(
pid
));
// Termination called
if
(
pid
==
-
1
)
break
;
if
(
pid
==
-
1
)
break
;
int
badns
;
int
badns
,
fd
;
while
(
1
)
{
while
(
1
)
{
badns
=
0
;
badns
=
0
;
read_namespace
(
pid
,
buffer
,
32
);
read_namespace
(
pid
,
buffer
,
32
);
printf
(
"%s
\n
"
,
buffer
);
for
(
i
=
0
;
i
<
zygote_num
;
++
i
)
{
for
(
i
=
0
;
i
<
zygote_num
;
++
i
)
{
if
(
strcmp
(
buffer
,
zygote_ns
[
i
])
==
0
)
{
if
(
strcmp
(
buffer
,
zygote_ns
[
i
])
==
0
)
{
usleep
(
10
00
);
usleep
(
5
00
);
badns
=
1
;
badns
=
1
;
break
;
break
;
}
}
...
@@ -102,12 +105,13 @@ int hideMagisk() {
...
@@ -102,12 +105,13 @@ int hideMagisk() {
if
(
!
badns
)
break
;
if
(
!
badns
)
break
;
}
}
fprintf
(
logfile
,
"ns=%s]
\n
"
,
buffer
);
// Send pause signal ASAP
if
(
kill
(
pid
,
SIGSTOP
)
==
-
1
)
continue
;
snprintf
(
buffer
,
sizeof
(
buffer
),
"/proc/%d/ns/mnt"
,
pid
);
fprintf
(
logfile
,
"ns=%s)
\n
"
,
buffer
);
int
fd
=
open
(
buffer
,
O_RDONLY
);
snprintf
(
buffer
,
sizeof
(
buffer
),
"/proc/%d/ns/mnt"
,
pid
);
if
(
fd
==
-
1
)
continue
;
// Maybe process died..
if
(
(
fd
=
open
(
buffer
,
O_RDONLY
))
==
-
1
)
continue
;
// Maybe process died..
if
(
setns
(
fd
,
0
)
==
-
1
)
{
if
(
setns
(
fd
,
0
)
==
-
1
)
{
fprintf
(
logfile
,
"MagiskHide: Unable to change namespace for pid=%d
\n
"
,
pid
);
fprintf
(
logfile
,
"MagiskHide: Unable to change namespace for pid=%d
\n
"
,
pid
);
continue
;
continue
;
...
@@ -159,6 +163,9 @@ int hideMagisk() {
...
@@ -159,6 +163,9 @@ int hideMagisk() {
free
(
mount_list
[
i
]);
free
(
mount_list
[
i
]);
}
}
free
(
mount_list
);
free
(
mount_list
);
// Send resume signal
kill
(
pid
,
SIGCONT
);
}
}
// Should never go here
// Should never go here
...
@@ -220,6 +227,16 @@ void *monitor_list(void *path) {
...
@@ -220,6 +227,16 @@ void *monitor_list(void *path) {
return
NULL
;
return
NULL
;
}
}
void
terminate
(
int
sig
)
{
// Close the config list monitor
pthread_kill
(
list_monitor
,
SIGQUIT
);
pthread_mutex_destroy
(
&
mutex
);
// Terminate our children
i
=
-
1
;
write
(
pipefd
[
1
],
&
i
,
sizeof
(
i
));
}
void
run_as_daemon
()
{
void
run_as_daemon
()
{
switch
(
fork
())
{
switch
(
fork
())
{
case
-
1
:
case
-
1
:
...
@@ -242,6 +259,11 @@ int main(int argc, char **argv, char **envp) {
...
@@ -242,6 +259,11 @@ int main(int argc, char **argv, char **envp) {
run_as_daemon
();
run_as_daemon
();
// Handle all killing signals
signal
(
SIGINT
,
terminate
);
signal
(
SIGKILL
,
terminate
);
signal
(
SIGTERM
,
terminate
);
// Fork a child to handle namespace switches and unmounts
// Fork a child to handle namespace switches and unmounts
pipe
(
pipefd
);
pipe
(
pipefd
);
switch
(
fork
())
{
switch
(
fork
())
{
...
@@ -255,7 +277,6 @@ int main(int argc, char **argv, char **envp) {
...
@@ -255,7 +277,6 @@ int main(int argc, char **argv, char **envp) {
close
(
pipefd
[
0
]);
close
(
pipefd
[
0
]);
// Start a thread to constantly check the hide list
// Start a thread to constantly check the hide list
pthread_t
list_monitor
;
pthread_mutex_init
(
&
mutex
,
NULL
);
pthread_mutex_init
(
&
mutex
,
NULL
);
pthread_create
(
&
list_monitor
,
NULL
,
monitor_list
,
HIDELIST
);
pthread_create
(
&
list_monitor
,
NULL
,
monitor_list
,
HIDELIST
);
...
@@ -274,18 +295,18 @@ int main(int argc, char **argv, char **envp) {
...
@@ -274,18 +295,18 @@ int main(int argc, char **argv, char **envp) {
pos
[
0
]
=
' '
;
pos
[
0
]
=
' '
;
}
}
int
user
,
pid
,
uid
;
int
pid
;
char
processName
[
256
],
hostingType
[
16
],
hostingName
[
256
];
char
processName
[
256
];
int
ret
=
sscanf
(
buffer
,
"[%d %d %d %256s %16s %256s]"
,
int
ret
=
sscanf
(
buffer
,
"[%*d %d %*d %256s"
,
&
pid
,
processName
);
&
user
,
&
pid
,
&
uid
,
processName
,
hostingType
,
hostingName
);
if
(
ret
!=
6
)
if
(
ret
!=
2
)
continue
;
continue
;
for
(
i
=
0
;
i
<
list_size
;
++
i
)
{
for
(
i
=
0
;
i
<
list_size
;
++
i
)
{
if
(
strstr
(
processName
,
hide_list
[
i
]))
{
if
(
strstr
(
processName
,
hide_list
[
i
]))
{
fprintf
(
logfile
,
"MagiskHide: %s[PID=%d "
,
processName
,
pid
);
// Check PID exist
if
(
kill
(
pid
,
0
)
==
-
1
)
continue
;
fprintf
(
logfile
,
"MagiskHide: %s(PID=%d "
,
processName
,
pid
);
write
(
pipefd
[
1
],
&
pid
,
sizeof
(
pid
));
write
(
pipefd
[
1
],
&
pid
,
sizeof
(
pid
));
}
}
}
}
...
@@ -293,14 +314,7 @@ int main(int argc, char **argv, char **envp) {
...
@@ -293,14 +314,7 @@ int main(int argc, char **argv, char **envp) {
// Close the logcat monitor
// Close the logcat monitor
pclose
(
p
);
pclose
(
p
);
terminate
(
0
);
// Close the config list monitor
pthread_kill
(
list_monitor
,
SIGQUIT
);
pthread_mutex_destroy
(
&
mutex
);
// Terminate our children
i
=
-
1
;
write
(
pipefd
[
1
],
&
i
,
sizeof
(
i
));
fprintf
(
logfile
,
"MagiskHide: Cannot read from logcat, abort...
\n
"
);
fprintf
(
logfile
,
"MagiskHide: Cannot read from logcat, abort...
\n
"
);
fclose
(
logfile
);
fclose
(
logfile
);
...
...
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