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
f9fea265
Commit
f9fea265
authored
Jan 01, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small updates for MagiskHide
parent
668601ca
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
51 deletions
+68
-51
Android.mk
jni/magiskhide/Android.mk
+1
-1
hide.c
jni/magiskhide/hide.c
+4
-41
main.c
jni/magiskhide/main.c
+16
-3
proc_monitor.c
jni/magiskhide/proc_monitor.c
+47
-6
No files found.
jni/magiskhide/Android.mk
View file @
f9fea265
...
@@ -4,5 +4,5 @@ include $(CLEAR_VARS)
...
@@ -4,5 +4,5 @@ include $(CLEAR_VARS)
LOCAL_MODULE := magiskhide
LOCAL_MODULE := magiskhide
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := main.c hide.c list_monitor.c proc_monitor.c util.c
LOCAL_SRC_FILES := main.c hide.c list_monitor.c proc_monitor.c util.c
LOCAL_CFLAGS += -std=gnu11
LOCAL_CFLAGS += -std=gnu11
-O3
include $(BUILD_EXECUTABLE)
include $(BUILD_EXECUTABLE)
\ No newline at end of file
jni/magiskhide/hide.c
View file @
f9fea265
...
@@ -2,53 +2,16 @@
...
@@ -2,53 +2,16 @@
int
hideMagisk
()
{
int
hideMagisk
()
{
close
(
pipefd
[
1
]);
close
(
pipefd
[
1
]);
int
pid
,
zygote_num
=
0
;
int
pid
,
fd
;
char
cache_block
[
256
]
,
zygote_ns
[
2
][
32
]
;
char
cache_block
[
256
];
cache_block
[
0
]
=
'\0'
;
cache_block
[
0
]
=
'\0'
;
// Set to the top priority
setpriority
(
PRIO_PROCESS
,
0
,
-
20
);
// 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
)
{
while
(
1
)
{
read
(
pipefd
[
0
],
&
pid
,
sizeof
(
pid
));
read
(
pipefd
[
0
],
&
pid
,
sizeof
(
pid
));
// Termination called
// Termination called
if
(
pid
==
-
1
)
break
;
if
(
pid
==
-
1
)
break
;
int
badns
,
fd
;
while
(
1
)
{
badns
=
0
;
read_namespace
(
pid
,
buffer
,
32
);
printf
(
"%s
\n
"
,
buffer
);
for
(
i
=
0
;
i
<
zygote_num
;
++
i
)
{
if
(
strcmp
(
buffer
,
zygote_ns
[
i
])
==
0
)
{
usleep
(
500
);
badns
=
1
;
break
;
}
}
if
(
!
badns
)
break
;
}
// Send pause signal ASAP
if
(
kill
(
pid
,
SIGSTOP
)
==
-
1
)
continue
;
fprintf
(
logfile
,
"ns=%s)
\n
"
,
buffer
);
snprintf
(
buffer
,
sizeof
(
buffer
),
"/proc/%d/ns/mnt"
,
pid
);
snprintf
(
buffer
,
sizeof
(
buffer
),
"/proc/%d/ns/mnt"
,
pid
);
if
((
fd
=
open
(
buffer
,
O_RDONLY
))
==
-
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
)
{
...
@@ -79,7 +42,7 @@ int hideMagisk() {
...
@@ -79,7 +42,7 @@ int hideMagisk() {
// First unmount the dummy skeletons and the cache mounts
// First unmount the dummy skeletons and the cache mounts
for
(
i
=
mount_size
-
1
;
i
>=
0
;
--
i
)
{
for
(
i
=
mount_size
-
1
;
i
>=
0
;
--
i
)
{
if
(
strstr
(
mount_list
[
i
],
"tmpfs /system
/
"
)
||
strstr
(
mount_list
[
i
],
"tmpfs /vendor/"
)
if
(
strstr
(
mount_list
[
i
],
"tmpfs /system"
)
||
strstr
(
mount_list
[
i
],
"tmpfs /vendor/"
)
||
(
strstr
(
mount_list
[
i
],
cache_block
)
&&
strstr
(
mount_list
[
i
],
"/system"
))
)
{
||
(
strstr
(
mount_list
[
i
],
cache_block
)
&&
strstr
(
mount_list
[
i
],
"/system"
))
)
{
sscanf
(
mount_list
[
i
],
"%*s %512s"
,
buffer
);
sscanf
(
mount_list
[
i
],
"%*s %512s"
,
buffer
);
lazy_unmount
(
buffer
);
lazy_unmount
(
buffer
);
...
...
jni/magiskhide/main.c
View file @
f9fea265
...
@@ -14,15 +14,25 @@ static void terminate(int sig) {
...
@@ -14,15 +14,25 @@ static void terminate(int sig) {
// Terminate our children
// Terminate our children
i
=
-
1
;
i
=
-
1
;
write
(
pipefd
[
1
],
&
i
,
sizeof
(
i
));
write
(
pipefd
[
1
],
&
i
,
sizeof
(
i
));
exit
(
0
);
}
}
int
main
(
int
argc
,
char
**
argv
,
char
**
envp
)
{
int
main
(
int
argc
,
char
*
argv
[])
{
if
(
argc
>
0
)
{
if
(
strcmp
(
argv
[
1
],
"--daemon"
)
==
0
)
run_as_daemon
();
else
{
fprintf
(
stderr
,
"%s (with no options)
\n\t
Run magiskhide and output to stdout
\n
"
,
argv
[
0
]);
fprintf
(
stderr
,
"%s --daemon
\n\t
Run magiskhide as daemon, output to magisk.log
\n
"
,
argv
[
0
]);
return
1
;
}
}
else
logfile
=
stdout
;
run_as_daemon
();
// Handle all killing signals
// Handle all killing signals
signal
(
SIGINT
,
terminate
);
signal
(
SIGINT
,
terminate
);
signal
(
SIGKILL
,
terminate
);
signal
(
SIGTERM
,
terminate
);
signal
(
SIGTERM
,
terminate
);
// Fork a child to handle namespace switches and unmounts
// Fork a child to handle namespace switches and unmounts
...
@@ -41,6 +51,9 @@ int main(int argc, char **argv, char **envp) {
...
@@ -41,6 +51,9 @@ int main(int argc, char **argv, char **envp) {
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
);
// Set main process to the top priority
setpriority
(
PRIO_PROCESS
,
0
,
-
20
);
monitor_proc
();
monitor_proc
();
terminate
(
0
);
terminate
(
0
);
...
...
jni/magiskhide/proc_monitor.c
View file @
f9fea265
#include "magiskhide.h"
#include "magiskhide.h"
void
monitor_proc
()
{
void
monitor_proc
()
{
// Monitor am_proc_start in main thread
int
pid
,
badns
,
zygote_num
=
0
;
FILE
*
p
=
popen
(
"while true; do logcat -b events -v raw -s am_proc_start; sleep 1; done"
,
"r"
);
char
init_ns
[
32
],
zygote_ns
[
2
][
32
];
// Get the mount namespace of init
read_namespace
(
1
,
init_ns
,
32
);
// 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
);
do
{
usleep
(
500
);
read_namespace
(
pid
,
zygote_ns
[
zygote_num
],
32
);
}
while
(
strcmp
(
zygote_ns
[
zygote_num
],
init_ns
)
==
0
);
++
zygote_num
;
}
pclose
(
p
);
for
(
i
=
0
;
i
<
zygote_num
;
++
i
)
fprintf
(
logfile
,
"Zygote(%d) ns=%s "
,
i
,
zygote_ns
[
i
]);
fprintf
(
logfile
,
"
\n
"
);
// Monitor am_proc_start
p
=
popen
(
"while true; do logcat -b events -c; logcat -b events -v raw -s am_proc_start; sleep 1; done"
,
"r"
);
while
(
!
feof
(
p
))
{
while
(
!
feof
(
p
))
{
//Format of am_proc_start is (as of Android 5.1 and 6.0)
//Format of am_proc_start is (as of Android 5.1 and 6.0)
...
@@ -17,21 +40,39 @@ void monitor_proc() {
...
@@ -17,21 +40,39 @@ void monitor_proc() {
pos
[
0
]
=
' '
;
pos
[
0
]
=
' '
;
}
}
int
pid
;
char
processName
[
256
];
char
processName
[
256
];
int
ret
=
sscanf
(
buffer
,
"[%*d %d %*d %256s"
,
&
pid
,
processName
);
int
ret
=
sscanf
(
buffer
,
"[%*d %d %*d %256s"
,
&
pid
,
processName
);
if
(
ret
!=
2
)
if
(
ret
!=
2
)
continue
;
continue
;
pthread_mutex_lock
(
&
mutex
);
for
(
i
=
0
;
i
<
list_size
;
++
i
)
{
for
(
i
=
0
;
i
<
list_size
;
++
i
)
{
if
(
strcmp
(
processName
,
hide_list
[
i
])
==
0
)
{
if
(
strcmp
(
processName
,
hide_list
[
i
])
==
0
)
{
// Check PID exist
while
(
1
)
{
if
(
kill
(
pid
,
0
)
==
-
1
)
continue
;
badns
=
0
;
fprintf
(
logfile
,
"MagiskHide: %s(PID=%d "
,
processName
,
pid
);
read_namespace
(
pid
,
buffer
,
32
);
for
(
i
=
0
;
i
<
zygote_num
;
++
i
)
{
if
(
strcmp
(
buffer
,
zygote_ns
[
i
])
==
0
)
{
usleep
(
500
);
badns
=
1
;
break
;
}
}
if
(
!
badns
)
break
;
}
// Send pause signal ASAP
if
(
kill
(
pid
,
SIGSTOP
)
==
-
1
)
continue
;
fprintf
(
logfile
,
"MagiskHide: %s(PID=%d ns=%s)
\n
"
,
processName
,
pid
,
buffer
);
// Unmount start
write
(
pipefd
[
1
],
&
pid
,
sizeof
(
pid
));
write
(
pipefd
[
1
],
&
pid
,
sizeof
(
pid
));
break
;
}
}
}
}
pthread_mutex_unlock
(
&
mutex
);
}
}
// Close the logcat monitor
// Close the logcat monitor
...
...
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