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
9bc8f6e9
Commit
9bc8f6e9
authored
Apr 21, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add common script support
parent
e00e6509
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
89 additions
and
18 deletions
+89
-18
daemon.c
jni/daemon/daemon.c
+3
-0
late_start.c
jni/daemon/late_start.c
+5
-1
log_monitor.c
jni/daemon/log_monitor.c
+4
-1
post_fs.c
jni/daemon/post_fs.c
+5
-1
post_fs_data.c
jni/daemon/post_fs_data.c
+19
-3
magiskhide.c
jni/magiskhide/magiskhide.c
+2
-1
pre_process.c
jni/magiskhide/pre_process.c
+0
-1
misc.c
jni/utils/misc.c
+50
-10
utils.h
jni/utils/utils.h
+1
-0
No files found.
jni/daemon/daemon.c
View file @
9bc8f6e9
...
@@ -24,6 +24,9 @@
...
@@ -24,6 +24,9 @@
pthread_t
sepol_patch
;
pthread_t
sepol_patch
;
static
void
*
request_handler
(
void
*
args
)
{
static
void
*
request_handler
(
void
*
args
)
{
// Setup the default error handler for threads
err_handler
=
exit_thread
;
int
client
=
*
((
int
*
)
args
);
int
client
=
*
((
int
*
)
args
);
free
(
args
);
free
(
args
);
client_request
req
=
read_int
(
client
);
client_request
req
=
read_int
(
client
);
...
...
jni/daemon/late_start.c
View file @
9bc8f6e9
/* late_start.c - late_start service actions
/* late_start.c - late_start service actions
*/
*/
#include <stdlib.h>
#include <unistd.h>
#include <unistd.h>
#include <pthread.h>
#include <pthread.h>
#include "magisk.h"
#include "magisk.h"
#include "daemon.h"
#include "daemon.h"
#include "utils.h"
void
late_start
(
int
client
)
{
void
late_start
(
int
client
)
{
LOGI
(
"** late_start service mode running
\n
"
);
LOGI
(
"** late_start service mode running
\n
"
);
// ack
// ack
write_int
(
client
,
0
);
write_int
(
client
,
0
);
// TODO: Do something
close
(
client
);
close
(
client
);
// Wait till the full patch is done
// Wait till the full patch is done
pthread_join
(
sepol_patch
,
NULL
);
pthread_join
(
sepol_patch
,
NULL
);
// Run scripts after full patch, most reliable way to run scripts
exec_common_script
(
"service"
);
}
}
jni/daemon/log_monitor.c
View file @
9bc8f6e9
...
@@ -14,8 +14,11 @@
...
@@ -14,8 +14,11 @@
#include "daemon.h"
#include "daemon.h"
static
void
*
logger_thread
(
void
*
args
)
{
static
void
*
logger_thread
(
void
*
args
)
{
// Setup error handler
err_handler
=
exit_thread
;
char
buffer
[
PATH_MAX
];
char
buffer
[
PATH_MAX
];
x
rename
(
"/cache/magisk.log"
,
"/cache/last_magisk.log"
);
rename
(
"/cache/magisk.log"
,
"/cache/last_magisk.log"
);
FILE
*
logfile
=
xfopen
(
"/cache/magisk.log"
,
"w"
);
FILE
*
logfile
=
xfopen
(
"/cache/magisk.log"
,
"w"
);
// Disable buffering
// Disable buffering
setbuf
(
logfile
,
NULL
);
setbuf
(
logfile
,
NULL
);
...
...
jni/daemon/post_fs.c
View file @
9bc8f6e9
...
@@ -11,7 +11,11 @@ void post_fs(int client) {
...
@@ -11,7 +11,11 @@ void post_fs(int client) {
LOGI
(
"** post-fs mode running
\n
"
);
LOGI
(
"** post-fs mode running
\n
"
);
// ack
// ack
write_int
(
client
,
0
);
write_int
(
client
,
0
);
// TODO: Do something
// TODO: Simple bind mounts
close
(
client
);
close
(
client
);
unblock:
unblock_boot_process
();
unblock_boot_process
();
}
}
jni/daemon/post_fs_data.c
View file @
9bc8f6e9
...
@@ -19,6 +19,7 @@ static char *loopsetup(const char *img) {
...
@@ -19,6 +19,7 @@ static char *loopsetup(const char *img) {
char
device
[
20
];
char
device
[
20
];
struct
loop_info64
info
;
struct
loop_info64
info
;
int
i
,
lfd
,
ffd
;
int
i
,
lfd
,
ffd
;
memset
(
&
info
,
0
,
sizeof
(
info
));
// First get an empty loop device
// First get an empty loop device
for
(
i
=
0
;
i
<=
7
;
++
i
)
{
for
(
i
=
0
;
i
<=
7
;
++
i
)
{
sprintf
(
device
,
"/dev/block/loop%d"
,
i
);
sprintf
(
device
,
"/dev/block/loop%d"
,
i
);
...
@@ -31,9 +32,18 @@ static char *loopsetup(const char *img) {
...
@@ -31,9 +32,18 @@ static char *loopsetup(const char *img) {
ffd
=
xopen
(
img
,
O_RDWR
);
ffd
=
xopen
(
img
,
O_RDWR
);
if
(
ioctl
(
lfd
,
LOOP_SET_FD
,
ffd
)
==
-
1
)
if
(
ioctl
(
lfd
,
LOOP_SET_FD
,
ffd
)
==
-
1
)
return
NULL
;
return
NULL
;
strcpy
((
char
*
)
info
.
lo_file_name
,
img
);
ioctl
(
lfd
,
LOOP_SET_STATUS64
,
&
info
);
return
strdup
(
device
);
return
strdup
(
device
);
}
}
static
void
*
start_magisk_hide
(
void
*
args
)
{
// Setup default error handler for thread
err_handler
=
exit_thread
;
launch_magiskhide
(
-
1
);
return
NULL
;
}
char
*
mount_image
(
const
char
*
img
,
const
char
*
target
)
{
char
*
mount_image
(
const
char
*
img
,
const
char
*
target
)
{
char
*
device
=
loopsetup
(
img
);
char
*
device
=
loopsetup
(
img
);
if
(
device
)
if
(
device
)
...
@@ -54,15 +64,21 @@ void post_fs_data(int client) {
...
@@ -54,15 +64,21 @@ void post_fs_data(int client) {
char
*
magiskimg
=
mount_image
(
"/data/magisk.img"
,
"/magisk"
);
char
*
magiskimg
=
mount_image
(
"/data/magisk.img"
,
"/magisk"
);
free
(
magiskimg
);
free
(
magiskimg
);
// TODO: Magic Mounts, modules etc.
// Run common scripts
exec_common_script
(
"post-fs-data"
);
// Start magiskhide if enabled
// Start magiskhide if enabled
char
*
hide_prop
=
getprop
(
"persist.magisk.hide"
);
char
*
hide_prop
=
getprop
(
"persist.magisk.hide"
);
if
(
hide_prop
)
{
if
(
hide_prop
)
{
if
(
strcmp
(
hide_prop
,
"1"
)
==
0
)
if
(
strcmp
(
hide_prop
,
"1"
)
==
0
)
{
launch_magiskhide
(
-
1
);
pthread_t
thread
;
xpthread_create
(
&
thread
,
NULL
,
start_magisk_hide
,
NULL
);
}
free
(
hide_prop
);
free
(
hide_prop
);
}
}
unblock:
unblock:
unblock_boot_process
();
unblock_boot_process
();
return
;
}
}
jni/magiskhide/magiskhide.c
View file @
9bc8f6e9
...
@@ -52,7 +52,8 @@ void launch_magiskhide(int client) {
...
@@ -52,7 +52,8 @@ void launch_magiskhide(int client) {
LOGI
(
"* Starting MagiskHide
\n
"
);
LOGI
(
"* Starting MagiskHide
\n
"
);
hideEnabled
=
1
;
hideEnabled
=
1
;
setprop
(
"persist.magisk.hide"
,
"1"
);
init_resetprop
();
setprop2
(
"persist.magisk.hide"
,
"1"
,
0
);
hide_sensitive_props
();
hide_sensitive_props
();
...
...
jni/magiskhide/pre_process.c
View file @
9bc8f6e9
...
@@ -46,7 +46,6 @@ void hide_sensitive_props() {
...
@@ -46,7 +46,6 @@ void hide_sensitive_props() {
LOGI
(
"hide_pre_proc: Hiding sensitive props
\n
"
);
LOGI
(
"hide_pre_proc: Hiding sensitive props
\n
"
);
// Hide all sensitive props
// Hide all sensitive props
init_resetprop
();
char
*
value
;
char
*
value
;
for
(
int
i
=
0
;
prop_key
[
i
];
++
i
)
{
for
(
int
i
=
0
;
prop_key
[
i
];
++
i
)
{
value
=
getprop
(
prop_key
[
i
]);
value
=
getprop
(
prop_key
[
i
]);
...
...
jni/utils/misc.c
View file @
9bc8f6e9
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
#include <sys/types.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/mount.h>
#include <sys/wait.h>
#include "magisk.h"
#include "magisk.h"
#include "utils.h"
#include "utils.h"
...
@@ -117,7 +118,8 @@ void ps(void (*func)(int)) {
...
@@ -117,7 +118,8 @@ void ps(void (*func)(int)) {
DIR
*
dir
;
DIR
*
dir
;
struct
dirent
*
entry
;
struct
dirent
*
entry
;
dir
=
xopendir
(
"/proc"
);
if
(
!
(
dir
=
xopendir
(
"/proc"
)))
return
;
while
((
entry
=
xreaddir
(
dir
)))
{
while
((
entry
=
xreaddir
(
dir
)))
{
if
(
entry
->
d_type
==
DT_DIR
)
{
if
(
entry
->
d_type
==
DT_DIR
)
{
...
@@ -216,22 +218,60 @@ void setup_sighandlers(void (*handler)(int)) {
...
@@ -216,22 +218,60 @@ void setup_sighandlers(void (*handler)(int)) {
int
run_command
(
int
*
fd
,
const
char
*
path
,
char
*
const
argv
[])
{
int
run_command
(
int
*
fd
,
const
char
*
path
,
char
*
const
argv
[])
{
int
sv
[
2
];
int
sv
[
2
];
if
(
fd
)
{
if
(
socketpair
(
AF_LOCAL
,
SOCK_STREAM
,
0
,
sv
)
==
-
1
)
if
(
socketpair
(
AF_LOCAL
,
SOCK_STREAM
,
0
,
sv
)
==
-
1
)
return
-
1
;
return
-
1
;
// We use sv[0], give them sv[1] for communication
// We use sv[0], give them sv[1] for communication
*
fd
=
sv
[
1
];
*
fd
=
sv
[
1
];
}
int
pid
=
fork
();
int
pid
=
fork
();
if
(
pid
!=
0
)
{
if
(
pid
!=
0
)
{
close
(
sv
[
0
]);
if
(
fd
)
close
(
sv
[
0
]);
return
pid
;
return
pid
;
}
}
if
(
fd
)
{
close
(
sv
[
1
]);
close
(
sv
[
1
]);
dup2
(
sv
[
0
],
STDIN_FILENO
);
xdup2
(
sv
[
0
],
STDIN_FILENO
);
dup2
(
sv
[
0
],
STDOUT_FILENO
);
xdup2
(
sv
[
0
],
STDOUT_FILENO
);
dup2
(
sv
[
0
],
STDERR_FILENO
);
xdup2
(
sv
[
0
],
STDERR_FILENO
);
}
else
{
int
null
=
open
(
"/dev/null"
,
O_RDWR
);
xdup2
(
null
,
STDIN_FILENO
);
xdup2
(
null
,
STDOUT_FILENO
);
xdup2
(
null
,
STDERR_FILENO
);
}
execv
(
path
,
argv
);
execv
(
path
,
argv
);
PLOGE
(
"execv"
);
PLOGE
(
"execv"
);
return
-
1
;
return
-
1
;
}
}
#define MAGISK_CORE "/magisk/.core/"
void
exec_common_script
(
const
char
*
stage
)
{
DIR
*
dir
;
struct
dirent
*
entry
;
char
buf
[
PATH_MAX
];
snprintf
(
buf
,
sizeof
(
buf
),
MAGISK_CORE
"%s.d"
,
stage
);
if
(
!
(
dir
=
opendir
(
buf
)))
return
;
while
((
entry
=
xreaddir
(
dir
)))
{
if
(
entry
->
d_type
==
DT_REG
)
{
snprintf
(
buf
,
sizeof
(
buf
),
MAGISK_CORE
"%s.d/%s"
,
stage
,
entry
->
d_name
);
if
(
access
(
buf
,
X_OK
)
==
-
1
)
continue
;
LOGI
(
"%s.d: exec [%s]
\n
"
,
stage
,
entry
->
d_name
);
char
*
const
command
[]
=
{
"sh"
,
buf
,
NULL
};
int
pid
=
run_command
(
NULL
,
"/system/bin/sh"
,
command
);
if
(
pid
!=
-
1
)
waitpid
(
pid
,
NULL
,
0
);
}
}
closedir
(
dir
);
}
jni/utils/utils.h
View file @
9bc8f6e9
...
@@ -74,5 +74,6 @@ void unlock_blocks();
...
@@ -74,5 +74,6 @@ void unlock_blocks();
void
unblock_boot_process
();
void
unblock_boot_process
();
void
setup_sighandlers
(
void
(
*
handler
)(
int
));
void
setup_sighandlers
(
void
(
*
handler
)(
int
));
int
run_command
(
int
*
fd
,
const
char
*
path
,
char
*
const
argv
[]);
int
run_command
(
int
*
fd
,
const
char
*
path
,
char
*
const
argv
[]);
void
exec_common_script
(
const
char
*
stage
);
#endif
#endif
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