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
b570b363
Commit
b570b363
authored
Jul 08, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup file descriptors and add more info
parent
b9968aa1
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
41 additions
and
53 deletions
+41
-53
daemon.c
jni/daemon/daemon.c
+9
-17
magisk.h
jni/magisk.h
+0
-1
main.c
jni/magiskboot/main.c
+1
-1
hide_daemon.c
jni/magiskhide/hide_daemon.c
+1
-0
magiskhide.c
jni/magiskhide/magiskhide.c
+8
-26
proc_monitor.c
jni/magiskhide/proc_monitor.c
+15
-1
magiskpolicy
jni/magiskpolicy
+1
-1
main.c
jni/main.c
+1
-1
resetprop.cpp
jni/resetprop/resetprop.cpp
+1
-1
su
jni/su
+1
-1
utils.h
jni/utils/utils.h
+1
-1
xwrap.c
jni/utils/xwrap.c
+2
-2
No files found.
jni/daemon/daemon.c
View file @
b570b363
...
...
@@ -23,7 +23,6 @@
#include "magiskpolicy.h"
pthread_t
sepol_patch
;
int
null_fd
;
static
void
*
request_handler
(
void
*
args
)
{
// Setup the default error handler for threads
...
...
@@ -89,17 +88,12 @@ static void *request_handler(void *args) {
default:
break
;
}
// Just in case
close
(
client
);
return
NULL
;
}
/* Setup the address and return socket fd */
static
int
setup_socket
(
struct
sockaddr_un
*
sun
)
{
int
fd
=
xsocket
(
AF_LOCAL
,
SOCK_STREAM
,
0
);
if
(
fcntl
(
fd
,
F_SETFD
,
FD_CLOEXEC
))
PLOGE
(
"fcntl FD_CLOEXEC"
);
int
fd
=
xsocket
(
AF_LOCAL
,
SOCK_STREAM
|
SOCK_CLOEXEC
,
0
);
memset
(
sun
,
0
,
sizeof
(
*
sun
));
sun
->
sun_family
=
AF_LOCAL
;
memcpy
(
sun
->
sun_path
,
REQUESTOR_DAEMON_PATH
,
REQUESTOR_DAEMON_PATH_LEN
);
...
...
@@ -137,10 +131,11 @@ void start_daemon(int client) {
xsetsid
();
setcon
(
"u:r:su:s0"
);
umask
(
022
);
null_fd
=
xopen
(
"/dev/null"
,
O_RDWR
|
O_CLOEXEC
);
xdup2
(
null_fd
,
STDIN_FILENO
);
xdup2
(
null_fd
,
STDOUT_FILENO
);
xdup2
(
null_fd
,
STDERR_FILENO
);
int
fd
=
xopen
(
"/dev/null"
,
O_RDWR
|
O_CLOEXEC
);
xdup2
(
fd
,
STDIN_FILENO
);
xdup2
(
fd
,
STDOUT_FILENO
);
xdup2
(
fd
,
STDERR_FILENO
);
close
(
fd
);
// Patch selinux with medium patch before we do anything
load_policydb
(
SELINUX_POLICY
);
...
...
@@ -151,7 +146,7 @@ void start_daemon(int client) {
pthread_create
(
&
sepol_patch
,
NULL
,
large_sepol_patch
,
NULL
);
struct
sockaddr_un
sun
;
int
fd
=
setup_socket
(
&
sun
);
fd
=
setup_socket
(
&
sun
);
xbind
(
fd
,
(
struct
sockaddr
*
)
&
sun
,
sizeof
(
sun
));
xlisten
(
fd
,
10
);
...
...
@@ -162,7 +157,7 @@ void start_daemon(int client) {
// It should stay intact under any circumstances
err_handler
=
do_nothing
;
LOGI
(
"Magisk v"
xstr
(
MAGISK_VERSION
)
" daemon started
\n
"
);
LOGI
(
"Magisk v"
xstr
(
MAGISK_VERSION
)
"
("
xstr
(
MAGISK_VER_CODE
)
")
daemon started
\n
"
);
// Unlock all blocks for rw
unlock_blocks
();
...
...
@@ -178,9 +173,7 @@ void start_daemon(int client) {
// Loop forever to listen for requests
while
(
1
)
{
int
*
client
=
xmalloc
(
sizeof
(
int
));
*
client
=
xaccept
(
fd
,
NULL
,
NULL
);
// Just in case, set to close on exec
fcntl
(
*
client
,
F_SETFD
,
FD_CLOEXEC
);
*
client
=
xaccept4
(
fd
,
NULL
,
NULL
,
SOCK_CLOEXEC
);
pthread_t
thread
;
xpthread_create
(
&
thread
,
NULL
,
request_handler
,
client
);
// Detach the thread, we will never join it
...
...
@@ -192,7 +185,6 @@ void start_daemon(int client) {
int
connect_daemon
()
{
struct
sockaddr_un
sun
;
int
fd
=
setup_socket
(
&
sun
);
// LOGD("client: trying to connect socket\n");
if
(
connect
(
fd
,
(
struct
sockaddr
*
)
&
sun
,
sizeof
(
sun
)))
{
/* If we cannot access the daemon, we start the daemon
* since there is no clear entry point when the daemon should be started
...
...
jni/magisk.h
View file @
b570b363
...
...
@@ -75,7 +75,6 @@ extern char *argv0; /* For changing process name */
extern
char
*
applet
[];
extern
int
(
*
applet_main
[])
(
int
,
char
*
[]);
extern
int
null_fd
;
// Multi-call entrypoints
int
magiskhide_main
(
int
argc
,
char
*
argv
[]);
...
...
jni/magiskboot/main.c
View file @
b570b363
...
...
@@ -58,7 +58,7 @@ static void usage(char *arg0) {
}
int
main
(
int
argc
,
char
*
argv
[])
{
printf
(
"MagiskBoot v"
xstr
(
MAGISK_VERSION
)
" (by topjohnwu) - Boot Image Modification Tool
\n\n
"
);
printf
(
"MagiskBoot v"
xstr
(
MAGISK_VERSION
)
"
("
xstr
(
MAGISK_VER_CODE
)
")
(by topjohnwu) - Boot Image Modification Tool
\n\n
"
);
if
(
argc
>
1
&&
strcmp
(
argv
[
1
],
"--cleanup"
)
==
0
)
{
cleanup
();
...
...
jni/magiskhide/hide_daemon.c
View file @
b570b363
...
...
@@ -53,6 +53,7 @@ int hide_daemon() {
// Set the process name
strcpy
(
argv0
,
"magiskhide_daemon"
);
LOGD
(
"hide_daemon: listening for hide requests"
);
// When an error occurs, report its failure to main process
err_handler
=
hide_daemon_err
;
...
...
jni/magiskhide/magiskhide.c
View file @
b570b363
...
...
@@ -16,7 +16,6 @@
#include "daemon.h"
#include "resetprop.h"
int
sv
[
2
],
hide_pid
=
-
1
;
struct
vector
*
hide_list
=
NULL
;
int
hideEnabled
=
0
;
...
...
@@ -29,7 +28,7 @@ void kill_proc(int pid) {
static
void
usage
(
char
*
arg0
)
{
fprintf
(
stderr
,
"MagiskHide v"
xstr
(
MAGISK_VERSION
)
" (by topjohnwu) - Hide Magisk!
\n\n
"
"MagiskHide v"
xstr
(
MAGISK_VERSION
)
"
("
xstr
(
MAGISK_VER_CODE
)
")
(by topjohnwu) - Hide Magisk!
\n\n
"
"%s [--options [arguments...] ]
\n\n
"
"Options:
\n
"
" --enable: Start the magiskhide daemon
\n
"
...
...
@@ -63,19 +62,6 @@ void launch_magiskhide(int client) {
hide_sensitive_props
();
if
(
socketpair
(
AF_LOCAL
,
SOCK_STREAM
,
0
,
sv
)
==
-
1
)
goto
error
;
/*
* The setns system call do not support multithread processes
* We have to fork a new process, and communicate with sockets
*/
if
(
hide_daemon
())
goto
error
;
close
(
sv
[
1
]);
// Initialize the mutex lock
pthread_mutex_init
(
&
hide_lock
,
NULL
);
pthread_mutex_init
(
&
file_lock
,
NULL
);
...
...
@@ -87,8 +73,10 @@ void launch_magiskhide(int client) {
// Add SafetyNet by default
add_list
(
strdup
(
"com.google.android.gms.unstable"
));
if
(
client
>
0
)
{
write_int
(
client
,
DAEMON_SUCCESS
);
close
(
client
);
}
// Get thread reference
proc_monitor_thread
=
pthread_self
();
...
...
@@ -98,15 +86,9 @@ void launch_magiskhide(int client) {
error:
hideEnabled
=
0
;
if
(
client
>
0
)
{
write_int
(
client
,
DAEMON_ERROR
);
close
(
client
);
if
(
hide_pid
!=
-
1
)
{
int
kill
=
-
1
;
// Kill hide daemon
write
(
sv
[
0
],
&
kill
,
sizeof
(
kill
));
close
(
sv
[
0
]);
waitpid
(
hide_pid
,
NULL
,
0
);
hide_pid
=
-
1
;
}
return
;
}
...
...
jni/magiskhide/proc_monitor.c
View file @
b570b363
...
...
@@ -22,6 +22,8 @@ static char init_ns[32], zygote_ns[2][32];
static
int
log_pid
,
log_fd
;
static
char
*
buffer
;
int
sv
[
2
],
hide_pid
=
-
1
;
// Workaround for the lack of pthread_cancel
static
void
quit_pthread
(
int
sig
)
{
err_handler
=
do_nothing
;
...
...
@@ -103,10 +105,22 @@ void proc_monitor() {
LOGI
(
"proc_monitor: zygote ns=%s
\n
"
,
zygote_ns
[
0
]);
break
;
case
2
:
LOGI
(
"proc_monitor: zygote
(32-bit) ns=%s (64-bit)
ns=%s
\n
"
,
zygote_ns
[
0
],
zygote_ns
[
1
]);
LOGI
(
"proc_monitor: zygote
ns=%s zygote64
ns=%s
\n
"
,
zygote_ns
[
0
],
zygote_ns
[
1
]);
break
;
}
if
(
socketpair
(
AF_LOCAL
,
SOCK_STREAM
|
SOCK_CLOEXEC
,
0
,
sv
)
==
-
1
)
quit_pthread
(
SIGUSR1
);
/*
* The setns system call do not support multithread processes
* We have to fork a new process, and communicate with sockets
*/
if
(
hide_daemon
())
quit_pthread
(
SIGUSR1
);
close
(
sv
[
1
]);
while
(
1
)
{
// Clear previous buffer
system
(
"logcat -b events -c"
);
...
...
magiskpolicy
@
5529dab8
Subproject commit
193d160bed24f75d2dd440063bfc00d7920cf789
Subproject commit
5529dab84e44856679406edd6560d26c61e1e715
jni/main.c
View file @
b570b363
...
...
@@ -22,7 +22,7 @@ __thread void (*err_handler)(void);
static
void
usage
()
{
fprintf
(
stderr
,
"Magisk v"
xstr
(
MAGISK_VERSION
)
" multi-call binary
\n
"
"Magisk v"
xstr
(
MAGISK_VERSION
)
"
("
xstr
(
MAGISK_VER_CODE
)
") (by topjohnwu)
multi-call binary
\n
"
"
\n
"
"Usage: %s [applet [arguments]...]
\n
"
" or: %s --install [SOURCE] <DIR>
\n
"
...
...
jni/resetprop/resetprop.cpp
View file @
b570b363
...
...
@@ -108,7 +108,7 @@ static bool is_legal_property_name(const char* name, size_t namelen) {
static
int
usage
(
char
*
arg0
)
{
fprintf
(
stderr
,
"resetprop v"
xstr
(
MAGISK_VERSION
)
" (by topjohnwu & nkk71) - System Props Modification Tool
\n\n
"
"resetprop v"
xstr
(
MAGISK_VERSION
)
"
("
xstr
(
MAGISK_VER_CODE
)
")
(by topjohnwu & nkk71) - System Props Modification Tool
\n\n
"
"Usage: %s [options] [args...]
\n
"
"%s <name> <value>: Set property entry <name> with <value>
\n
"
"%s --file <prop file>: Load props from <prop file>
\n
"
...
...
su
@
e2821025
Subproject commit
91ea6801679ddd0b05c893065520acb29f713e6
f
Subproject commit
e2821025ef7348085958ac8f76e51b08b0e9647
f
jni/utils/utils.h
View file @
b570b363
...
...
@@ -40,7 +40,7 @@ int xsocket(int domain, int type, int protocol);
int
xbind
(
int
sockfd
,
const
struct
sockaddr
*
addr
,
socklen_t
addrlen
);
int
xconnect
(
int
sockfd
,
const
struct
sockaddr
*
addr
,
socklen_t
addrlen
);
int
xlisten
(
int
sockfd
,
int
backlog
);
int
xaccept
(
int
sockfd
,
struct
sockaddr
*
addr
,
socklen_t
*
addrlen
);
int
xaccept
4
(
int
sockfd
,
struct
sockaddr
*
addr
,
socklen_t
*
addrlen
,
int
flags
);
void
*
xmalloc
(
size_t
size
);
void
*
xcalloc
(
size_t
nmemb
,
size_t
size
);
void
*
xrealloc
(
void
*
ptr
,
size_t
size
);
...
...
jni/utils/xwrap.c
View file @
b570b363
...
...
@@ -155,8 +155,8 @@ int xlisten(int sockfd, int backlog) {
return
ret
;
}
int
xaccept
(
int
sockfd
,
struct
sockaddr
*
addr
,
socklen_t
*
addrlen
)
{
int
fd
=
accept
(
sockfd
,
addr
,
addrlen
);
int
xaccept
4
(
int
sockfd
,
struct
sockaddr
*
addr
,
socklen_t
*
addrlen
,
int
flags
)
{
int
fd
=
accept
4
(
sockfd
,
addr
,
addrlen
,
flags
);
if
(
fd
==
-
1
)
{
PLOGE
(
"accept"
);
}
...
...
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