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
e16d604d
Commit
e16d604d
authored
Apr 30, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement Magic Mount
parent
d3d5703f
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
580 additions
and
202 deletions
+580
-202
Android.mk
jni/Android.mk
+1
-3
bootstages.c
jni/daemon/bootstages.c
+494
-0
daemon.c
jni/daemon/daemon.c
+7
-10
late_start.c
jni/daemon/late_start.c
+0
-23
post_fs.c
jni/daemon/post_fs.c
+0
-21
post_fs_data.c
jni/daemon/post_fs_data.c
+0
-84
magisk.h
jni/magisk.h
+5
-6
cpio.c
jni/magiskboot/cpio.c
+1
-1
magiskhide.c
jni/magiskhide/magiskhide.c
+4
-2
magiskhide.h
jni/magiskhide/magiskhide.h
+0
-2
pre_process.c
jni/magiskhide/pre_process.c
+3
-3
magiskpolicy
jni/magiskpolicy
+1
-1
main.c
jni/main.c
+12
-8
resetprop.cpp
jni/resetprop/resetprop.cpp
+5
-5
resetprop.h
jni/resetprop/resetprop.h
+2
-1
misc.c
jni/utils/misc.c
+30
-26
utils.h
jni/utils/utils.h
+4
-1
vector.h
jni/utils/vector.h
+4
-4
xwrap.c
jni/utils/xwrap.c
+7
-1
No files found.
jni/Android.mk
View file @
e16d604d
...
@@ -22,9 +22,7 @@ LOCAL_SRC_FILES := \
...
@@ -22,9 +22,7 @@ LOCAL_SRC_FILES := \
daemon/daemon.c \
daemon/daemon.c \
daemon/socket_trans.c \
daemon/socket_trans.c \
daemon/log_monitor.c \
daemon/log_monitor.c \
daemon/post_fs.c \
daemon/bootstages.c \
daemon/post_fs_data.c \
daemon/late_start.c \
magiskhide/magiskhide.c \
magiskhide/magiskhide.c \
magiskhide/hide_daemon.c \
magiskhide/hide_daemon.c \
magiskhide/proc_monitor.c \
magiskhide/proc_monitor.c \
...
...
jni/daemon/bootstages.c
0 → 100644
View file @
e16d604d
This diff is collapsed.
Click to expand it.
jni/daemon/daemon.c
View file @
e16d604d
...
@@ -31,8 +31,6 @@ static void *request_handler(void *args) {
...
@@ -31,8 +31,6 @@ static void *request_handler(void *args) {
int
client
=
*
((
int
*
)
args
);
int
client
=
*
((
int
*
)
args
);
free
(
args
);
free
(
args
);
client_request
req
=
read_int
(
client
);
client_request
req
=
read_int
(
client
);
char
*
s
;
int
pid
,
status
,
code
;
switch
(
req
)
{
switch
(
req
)
{
case
LAUNCH_MAGISKHIDE
:
case
LAUNCH_MAGISKHIDE
:
launch_magiskhide
(
client
);
launch_magiskhide
(
client
);
...
@@ -67,11 +65,7 @@ static void *request_handler(void *args) {
...
@@ -67,11 +65,7 @@ static void *request_handler(void *args) {
late_start
(
client
);
late_start
(
client
);
break
;
break
;
case
TEST
:
case
TEST
:
s
=
read_string
(
client
);
// test(client);
LOGI
(
"%s
\n
"
,
s
);
free
(
s
);
write_int
(
client
,
0
);
close
(
client
);
break
;
break
;
}
}
return
NULL
;
return
NULL
;
...
@@ -94,7 +88,7 @@ static void *large_sepol_patch(void *args) {
...
@@ -94,7 +88,7 @@ static void *large_sepol_patch(void *args) {
LOGD
(
"sepol: Starting large patch thread
\n
"
);
LOGD
(
"sepol: Starting large patch thread
\n
"
);
// Patch su to everything
// Patch su to everything
sepol_allow
(
"su"
,
ALL
,
ALL
,
ALL
);
sepol_allow
(
"su"
,
ALL
,
ALL
,
ALL
);
dump_policydb
(
"/sys/fs/selinux/load"
);
dump_policydb
(
SELINUX_LOAD
);
LOGD
(
"sepol: Large patch done
\n
"
);
LOGD
(
"sepol: Large patch done
\n
"
);
destroy_policydb
();
destroy_policydb
();
return
NULL
;
return
NULL
;
...
@@ -117,11 +111,14 @@ void start_daemon() {
...
@@ -117,11 +111,14 @@ void start_daemon() {
xsetsid
();
xsetsid
();
setcon
(
"u:r:su:s0"
);
setcon
(
"u:r:su:s0"
);
umask
(
022
);
umask
(
022
);
close
(
STDIN_FILENO
);
close
(
STDOUT_FILENO
);
close
(
STDERR_FILENO
);
// Patch selinux with medium patch before we do anything
// Patch selinux with medium patch before we do anything
load_policydb
(
"/sys/fs/selinux/policy"
);
load_policydb
(
SELINUX_POLICY
);
sepol_med_rules
();
sepol_med_rules
();
dump_policydb
(
"/sys/fs/selinux/load"
);
dump_policydb
(
SELINUX_LOAD
);
// Continue the larger patch in another thread, we will need to join later
// Continue the larger patch in another thread, we will need to join later
pthread_create
(
&
sepol_patch
,
NULL
,
large_sepol_patch
,
NULL
);
pthread_create
(
&
sepol_patch
,
NULL
,
large_sepol_patch
,
NULL
);
...
...
jni/daemon/late_start.c
deleted
100644 → 0
View file @
d3d5703f
/* late_start.c - late_start service actions
*/
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include "magisk.h"
#include "daemon.h"
#include "utils.h"
void
late_start
(
int
client
)
{
LOGI
(
"** late_start service mode running
\n
"
);
// ack
write_int
(
client
,
0
);
close
(
client
);
// Wait till the full patch is done
pthread_join
(
sepol_patch
,
NULL
);
// Run scripts after full patch, most reliable way to run scripts
exec_common_script
(
"service"
);
}
jni/daemon/post_fs.c
deleted
100644 → 0
View file @
d3d5703f
/* post_fs.c - post-fs actions
*/
#include <unistd.h>
#include "magisk.h"
#include "utils.h"
#include "daemon.h"
void
post_fs
(
int
client
)
{
LOGI
(
"** post-fs mode running
\n
"
);
// ack
write_int
(
client
,
0
);
// TODO: Simple bind mounts
close
(
client
);
unblock:
unblock_boot_process
();
}
jni/daemon/post_fs_data.c
deleted
100644 → 0
View file @
d3d5703f
/* post_fs_data.c - post-fs-data actions
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <linux/loop.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include "magisk.h"
#include "utils.h"
#include "daemon.h"
#include "resetprop.h"
static
char
*
loopsetup
(
const
char
*
img
)
{
char
device
[
20
];
struct
loop_info64
info
;
int
i
,
lfd
,
ffd
;
memset
(
&
info
,
0
,
sizeof
(
info
));
// First get an empty loop device
for
(
i
=
0
;
i
<=
7
;
++
i
)
{
sprintf
(
device
,
"/dev/block/loop%d"
,
i
);
lfd
=
xopen
(
device
,
O_RDWR
);
if
(
ioctl
(
lfd
,
LOOP_GET_STATUS64
,
&
info
)
==
-
1
)
break
;
close
(
lfd
);
}
if
(
i
==
8
)
return
NULL
;
ffd
=
xopen
(
img
,
O_RDWR
);
if
(
ioctl
(
lfd
,
LOOP_SET_FD
,
ffd
)
==
-
1
)
return
NULL
;
strcpy
((
char
*
)
info
.
lo_file_name
,
img
);
ioctl
(
lfd
,
LOOP_SET_STATUS64
,
&
info
);
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
*
device
=
loopsetup
(
img
);
if
(
device
)
xmount
(
device
,
target
,
"ext4"
,
0
,
NULL
);
return
device
;
}
void
post_fs_data
(
int
client
)
{
// ack
write_int
(
client
,
0
);
close
(
client
);
if
(
!
check_data
())
goto
unblock
;
LOGI
(
"** post-fs-data mode running
\n
"
);
LOGI
(
"* Mounting magisk.img
\n
"
);
// Mounting magisk image
char
*
magiskimg
=
mount_image
(
"/data/magisk.img"
,
"/magisk"
);
free
(
magiskimg
);
// TODO: Magic Mounts, modules etc.
// Run common scripts
exec_common_script
(
"post-fs-data"
);
// Start magiskhide if enabled
char
*
hide_prop
=
getprop
(
"persist.magisk.hide"
);
if
(
hide_prop
)
{
if
(
strcmp
(
hide_prop
,
"1"
)
==
0
)
{
pthread_t
thread
;
xpthread_create
(
&
thread
,
NULL
,
start_magisk_hide
,
NULL
);
}
free
(
hide_prop
);
}
unblock:
unblock_boot_process
();
}
jni/magisk.h
View file @
e16d604d
...
@@ -10,12 +10,6 @@
...
@@ -10,12 +10,6 @@
#include <pthread.h>
#include <pthread.h>
#include <android/log.h>
#include <android/log.h>
#ifndef MAGISK_VER_CODE
#define MAGISK_VER_CODE 99999
#endif
#ifndef MAGISK_VERSION
#define MAGISK_VERSION VER_DEBUG
#endif
#define MAGISK_VER_STR xstr(MAGISK_VERSION) ":MAGISK"
#define MAGISK_VER_STR xstr(MAGISK_VERSION) ":MAGISK"
#define str(a) #a
#define str(a) #a
...
@@ -30,6 +24,11 @@
...
@@ -30,6 +24,11 @@
#define ARG_MAX 4096
#define ARG_MAX 4096
#endif
#endif
#define SELINUX_PATH "/sys/fs/selinux/"
#define SELINUX_ENFORCE SELINUX_PATH "enforce"
#define SELINUX_POLICY SELINUX_PATH "policy"
#define SELINUX_LOAD SELINUX_PATH "load"
// Global handler for PLOGE
// Global handler for PLOGE
extern
__thread
void
(
*
err_handler
)(
void
);
extern
__thread
void
(
*
err_handler
)(
void
);
...
...
jni/magiskboot/cpio.c
View file @
e16d604d
...
@@ -283,7 +283,7 @@ static void cpio_extract(const char *entry, const char *filename, struct vector
...
@@ -283,7 +283,7 @@ static void cpio_extract(const char *entry, const char *filename, struct vector
static
void
cpio_backup
(
const
char
*
orig
,
struct
vector
*
v
)
{
static
void
cpio_backup
(
const
char
*
orig
,
struct
vector
*
v
)
{
struct
vector
o_body
,
*
o
=
&
o_body
,
bak
;
struct
vector
o_body
,
*
o
=
&
o_body
,
bak
;
cpio_file
*
m
,
*
n
,
*
dir
,
*
rem
;
cpio_file
*
m
,
*
n
,
*
dir
,
*
rem
;
char
chk1
[
21
],
chk2
[
21
],
buf
[
PATH_MAX
];
char
buf
[
PATH_MAX
];
int
res
,
doBak
;
int
res
,
doBak
;
dir
=
xcalloc
(
sizeof
(
*
dir
),
1
);
dir
=
xcalloc
(
sizeof
(
*
dir
),
1
);
...
...
jni/magiskhide/magiskhide.c
View file @
e16d604d
...
@@ -60,8 +60,10 @@ void launch_magiskhide(int client) {
...
@@ -60,8 +60,10 @@ void launch_magiskhide(int client) {
if
(
init_resetprop
())
if
(
init_resetprop
())
goto
error
;
goto
error
;
if
(
setprop2
(
"persist.magisk.hide"
,
"1"
,
0
))
if
(
client
!=
-
1
)
{
if
(
setprop
(
"persist.magisk.hide"
,
"1"
))
goto
error
;
goto
error
;
}
hide_sensitive_props
();
hide_sensitive_props
();
...
...
jni/magiskhide/magiskhide.h
View file @
e16d604d
...
@@ -5,8 +5,6 @@
...
@@ -5,8 +5,6 @@
#define HIDELIST "/magisk/.core/magiskhide/hidelist"
#define HIDELIST "/magisk/.core/magiskhide/hidelist"
#define DUMMYPATH "/dev/magisk/dummy"
#define DUMMYPATH "/dev/magisk/dummy"
#define ENFORCE_FILE "/sys/fs/selinux/enforce"
#define POLICY_FILE "/sys/fs/selinux/policy"
typedef
enum
{
typedef
enum
{
HIDE_ERROR
=
-
1
,
HIDE_ERROR
=
-
1
,
...
...
jni/magiskhide/pre_process.c
View file @
e16d604d
...
@@ -29,15 +29,15 @@ static int isMocked = 0;
...
@@ -29,15 +29,15 @@ static int isMocked = 0;
void
manage_selinux
()
{
void
manage_selinux
()
{
if
(
isMocked
)
return
;
if
(
isMocked
)
return
;
char
val
[
1
];
char
val
[
1
];
int
fd
=
xopen
(
ENFORCE_FIL
E
,
O_RDONLY
);
int
fd
=
xopen
(
SELINUX_ENFORC
E
,
O_RDONLY
);
xxread
(
fd
,
val
,
1
);
xxread
(
fd
,
val
,
1
);
close
(
fd
);
close
(
fd
);
// Permissive
// Permissive
if
(
val
[
0
]
==
'0'
)
{
if
(
val
[
0
]
==
'0'
)
{
LOGI
(
"hide_daemon: Permissive detected, hide the state
\n
"
);
LOGI
(
"hide_daemon: Permissive detected, hide the state
\n
"
);
chmod
(
ENFORCE_FIL
E
,
0640
);
chmod
(
SELINUX_ENFORC
E
,
0640
);
chmod
(
POLICY_FILE
,
0440
);
chmod
(
SELINUX_POLICY
,
0440
);
isMocked
=
1
;
isMocked
=
1
;
}
}
}
}
...
...
magiskpolicy
@
feec3e82
Subproject commit
3e106a9dc53400b2dde2e80cff277a5552a447ac
Subproject commit
feec3e82558b1640e2deb88fde19e50fe589bbcb
jni/main.c
View file @
e16d604d
...
@@ -35,7 +35,8 @@ static void usage() {
...
@@ -35,7 +35,8 @@ static void usage() {
" post-fs, post-fs-data, service
\n
"
" post-fs, post-fs-data, service
\n
"
"
\n
"
"
\n
"
"Options:
\n
"
"Options:
\n
"
" -v print client and daemon version
\n
"
" -c print client version
\n
"
" -v print daemon version
\n
"
" -V print daemon version code
\n
"
" -V print daemon version code
\n
"
"
\n
"
"
\n
"
"Supported applets:
\n
"
"Supported applets:
\n
"
...
@@ -57,12 +58,14 @@ int main(int argc, char *argv[]) {
...
@@ -57,12 +58,14 @@ int main(int argc, char *argv[]) {
else
arg
=
argv
[
0
];
else
arg
=
argv
[
0
];
if
(
strcmp
(
arg
,
"magisk"
)
==
0
)
{
if
(
strcmp
(
arg
,
"magisk"
)
==
0
)
{
if
(
argc
<
2
)
usage
();
if
(
argc
<
2
)
usage
();
if
(
strcmp
(
argv
[
1
],
"-v"
)
==
0
)
{
if
(
strcmp
(
argv
[
1
],
"-c"
)
==
0
)
{
printf
(
"Client: %s
\n
"
,
MAGISK_VER_STR
);
printf
(
"%s
\n
"
,
MAGISK_VER_STR
);
return
0
;
}
else
if
(
strcmp
(
argv
[
1
],
"-v"
)
==
0
)
{
int
fd
=
connect_daemon
();
int
fd
=
connect_daemon
();
write_int
(
fd
,
CHECK_VERSION
);
write_int
(
fd
,
CHECK_VERSION
);
char
*
v
=
read_string
(
fd
);
char
*
v
=
read_string
(
fd
);
printf
(
"
Daemon:
%s
\n
"
,
v
);
printf
(
"%s
\n
"
,
v
);
free
(
v
);
free
(
v
);
return
0
;
return
0
;
}
else
if
(
strcmp
(
argv
[
1
],
"-V"
)
==
0
)
{
}
else
if
(
strcmp
(
argv
[
1
],
"-V"
)
==
0
)
{
...
@@ -92,10 +95,11 @@ int main(int argc, char *argv[]) {
...
@@ -92,10 +95,11 @@ int main(int argc, char *argv[]) {
return
read_int
(
fd
);
return
read_int
(
fd
);
}
else
if
(
strcmp
(
argv
[
1
],
"--test"
)
==
0
)
{
}
else
if
(
strcmp
(
argv
[
1
],
"--test"
)
==
0
)
{
// Temporary testing entry
// Temporary testing entry
int
fd
=
connect_daemon
();
// int fd = connect_daemon();
write_int
(
fd
,
TEST
);
// write_int(fd, TEST);
write_string
(
fd
,
argv
[
2
]);
// return read_int(fd);
return
read_int
(
fd
);
// test();
return
0
;
}
else
{
}
else
{
// It's calling applets
// It's calling applets
--
argc
;
--
argc
;
...
...
jni/resetprop/resetprop.cpp
View file @
e16d604d
...
@@ -151,7 +151,7 @@ int setprop(const char *name, const char *value) {
...
@@ -151,7 +151,7 @@ int setprop(const char *name, const char *value) {
return
setprop2
(
name
,
value
,
1
);
return
setprop2
(
name
,
value
,
1
);
}
}
int
setprop2
(
const
char
*
name
,
const
char
*
value
,
int
trigger
)
{
int
setprop2
(
const
char
*
name
,
const
char
*
value
,
const
int
trigger
)
{
int
ret
;
int
ret
;
char
*
check
=
getprop
(
name
);
char
*
check
=
getprop
(
name
);
...
@@ -190,7 +190,7 @@ int deleteprop(const char *name) {
...
@@ -190,7 +190,7 @@ int deleteprop(const char *name) {
return
0
;
return
0
;
}
}
int
read_prop_file
(
const
char
*
filename
)
{
int
read_prop_file
(
const
char
*
filename
,
const
int
trigger
)
{
PRINT_D
(
"resetprop: Load prop file [%s]
\n
"
,
filename
);
PRINT_D
(
"resetprop: Load prop file [%s]
\n
"
,
filename
);
FILE
*
fp
=
fopen
(
filename
,
"r"
);
FILE
*
fp
=
fopen
(
filename
,
"r"
);
if
(
fp
==
NULL
)
{
if
(
fp
==
NULL
)
{
...
@@ -223,7 +223,7 @@ int read_prop_file(const char* filename) {
...
@@ -223,7 +223,7 @@ int read_prop_file(const char* filename) {
if
(
((
pch
==
NULL
)
||
(
i
>=
(
pch
-
line
)))
||
(
pch
>=
line
+
read
-
1
)
)
continue
;
if
(
((
pch
==
NULL
)
||
(
i
>=
(
pch
-
line
)))
||
(
pch
>=
line
+
read
-
1
)
)
continue
;
// Separate the string
// Separate the string
*
pch
=
'\0'
;
*
pch
=
'\0'
;
setprop
(
line
+
i
,
pch
+
1
);
setprop
2
(
line
+
i
,
pch
+
1
,
trigger
);
}
}
free
(
line
);
free
(
line
);
fclose
(
fp
);
fclose
(
fp
);
...
@@ -234,7 +234,7 @@ int resetprop_main(int argc, char *argv[]) {
...
@@ -234,7 +234,7 @@ int resetprop_main(int argc, char *argv[]) {
int
del
=
0
,
file
=
0
,
trigger
=
1
;
int
del
=
0
,
file
=
0
,
trigger
=
1
;
int
exp_arg
=
2
,
stdout_bak
,
null
;
int
exp_arg
=
2
;
char
*
name
,
*
value
,
*
filename
;
char
*
name
,
*
value
,
*
filename
;
if
(
argc
<
3
)
{
if
(
argc
<
3
)
{
...
@@ -283,7 +283,7 @@ int resetprop_main(int argc, char *argv[]) {
...
@@ -283,7 +283,7 @@ int resetprop_main(int argc, char *argv[]) {
return
-
1
;
return
-
1
;
if
(
file
)
{
if
(
file
)
{
return
read_prop_file
(
filename
);
return
read_prop_file
(
filename
,
trigger
);
}
else
if
(
del
)
{
}
else
if
(
del
)
{
return
deleteprop
(
name
);
return
deleteprop
(
name
);
}
else
{
}
else
{
...
...
jni/resetprop/resetprop.h
View file @
e16d604d
...
@@ -10,9 +10,10 @@ extern "C" {
...
@@ -10,9 +10,10 @@ extern "C" {
int
init_resetprop
();
int
init_resetprop
();
int
setprop
(
const
char
*
name
,
const
char
*
value
);
int
setprop
(
const
char
*
name
,
const
char
*
value
);
int
setprop2
(
const
char
*
name
,
const
char
*
value
,
int
trigger
);
int
setprop2
(
const
char
*
name
,
const
char
*
value
,
const
int
trigger
);
char
*
getprop
(
const
char
*
name
);
char
*
getprop
(
const
char
*
name
);
int
deleteprop
(
const
char
*
name
);
int
deleteprop
(
const
char
*
name
);
int
read_prop_file
(
const
char
*
filename
,
const
int
trigger
);
#ifdef __cplusplus
#ifdef __cplusplus
}
}
...
...
jni/utils/misc.c
View file @
e16d604d
...
@@ -9,6 +9,7 @@
...
@@ -9,6 +9,7 @@
#include <fcntl.h>
#include <fcntl.h>
#include <pwd.h>
#include <pwd.h>
#include <signal.h>
#include <signal.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/ioctl.h>
#include <sys/mount.h>
#include <sys/mount.h>
...
@@ -238,10 +239,9 @@ int run_command(int *fd, const char *path, char *const argv[]) {
...
@@ -238,10 +239,9 @@ int run_command(int *fd, const char *path, char *const argv[]) {
xdup2
(
sv
[
0
],
STDOUT_FILENO
);
xdup2
(
sv
[
0
],
STDOUT_FILENO
);
xdup2
(
sv
[
0
],
STDERR_FILENO
);
xdup2
(
sv
[
0
],
STDERR_FILENO
);
}
else
{
}
else
{
int
null
=
open
(
"/dev/null"
,
O_RDWR
);
close
(
STDIN_FILENO
);
xdup2
(
null
,
STDIN_FILENO
);
close
(
STDOUT_FILENO
);
xdup2
(
null
,
STDOUT_FILENO
);
close
(
STDERR_FILENO
);
xdup2
(
null
,
STDERR_FILENO
);
}
}
execv
(
path
,
argv
);
execv
(
path
,
argv
);
...
@@ -249,29 +249,33 @@ int run_command(int *fd, const char *path, char *const argv[]) {
...
@@ -249,29 +249,33 @@ int run_command(int *fd, const char *path, char *const argv[]) {
return
-
1
;
return
-
1
;
}
}
#define MAGISK_CORE "/magisk/.core/"
int
mkdir_p
(
const
char
*
pathname
,
mode_t
mode
)
{
char
*
path
=
strdup
(
pathname
),
*
p
;
void
exec_common_script
(
const
char
*
stage
)
{
errno
=
0
;
DIR
*
dir
;
for
(
p
=
path
+
1
;
*
p
;
++
p
)
{
struct
dirent
*
entry
;
if
(
*
p
==
'/'
)
{
char
buf
[
PATH_MAX
];
*
p
=
'\0'
;
snprintf
(
buf
,
sizeof
(
buf
),
MAGISK_CORE
"%s.d"
,
stage
);
if
(
mkdir
(
path
,
mode
)
==
-
1
)
{
if
(
errno
!=
EEXIST
)
if
(
!
(
dir
=
opendir
(
buf
)))
return
-
1
;
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
);
}
}
*
p
=
'/'
;
}
}
}
if
(
mkdir
(
path
,
mode
)
==
-
1
)
{
if
(
errno
!=
EEXIST
)
return
-
1
;
}
free
(
path
);
return
0
;
}
closedir
(
dir
);
int
bind_mount
(
const
char
*
from
,
const
char
*
to
)
{
int
ret
=
xmount
(
from
,
to
,
NULL
,
MS_BIND
,
NULL
);
LOGD
(
"bind_mount: %s -> %s
\n
"
,
from
,
to
);
return
ret
;
}
int
open_new
(
const
char
*
filename
)
{
return
xopen
(
filename
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0644
);
}
}
jni/utils/utils.h
View file @
e16d604d
...
@@ -61,6 +61,7 @@ int xmkdir(const char *pathname, mode_t mode);
...
@@ -61,6 +61,7 @@ int xmkdir(const char *pathname, mode_t mode);
void
*
xmmap
(
void
*
addr
,
size_t
length
,
int
prot
,
int
flags
,
void
*
xmmap
(
void
*
addr
,
size_t
length
,
int
prot
,
int
flags
,
int
fd
,
off_t
offset
);
int
fd
,
off_t
offset
);
ssize_t
xsendfile
(
int
out_fd
,
int
in_fd
,
off_t
*
offset
,
size_t
count
);
ssize_t
xsendfile
(
int
out_fd
,
int
in_fd
,
off_t
*
offset
,
size_t
count
);
int
xmkdir_p
(
const
char
*
pathname
,
mode_t
mode
);
// misc.c
// misc.c
...
@@ -79,6 +80,8 @@ void unlock_blocks();
...
@@ -79,6 +80,8 @@ 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
);
int
mkdir_p
(
const
char
*
pathname
,
mode_t
mode
);
int
bind_mount
(
const
char
*
from
,
const
char
*
to
);
int
open_new
(
const
char
*
filename
);
#endif
#endif
jni/utils/vector.h
View file @
e16d604d
...
@@ -21,11 +21,11 @@ void vec_deep_destroy(struct vector *v);
...
@@ -21,11 +21,11 @@ void vec_deep_destroy(struct vector *v);
#define vec_entry(v) (v)->data
#define vec_entry(v) (v)->data
/* Usage: vec_for_each(vector *v, void *e) */
/* Usage: vec_for_each(vector *v, void *e) */
#define vec_for_each(v, e) \
#define vec_for_each(v, e) \
e =
(v)->data[0]
; \
e =
v ? (v)->data[0] : NULL
; \
for (size_t _ = 0; _ < (v)->size; ++_, e = (v)->data[_])
for (size_t _ = 0;
v &&
_ < (v)->size; ++_, e = (v)->data[_])
#define vec_for_each_r(v, e) \
#define vec_for_each_r(v, e) \
e =
(v)->data[(v)->size - 1]
; \
e =
v ? (v)->data[(v)->size - 1] : NULL
; \
for (size_t _ = (v)->size; _ > 0; --_, e = (v)->data[_ - 1])
for (size_t _ = (v)->size;
v &&
_ > 0; --_, e = (v)->data[_ - 1])
#endif
#endif
\ No newline at end of file
jni/utils/xwrap.c
View file @
e16d604d
...
@@ -298,4 +298,10 @@ ssize_t xsendfile(int out_fd, int in_fd, off_t *offset, size_t count) {
...
@@ -298,4 +298,10 @@ ssize_t xsendfile(int out_fd, int in_fd, off_t *offset, size_t count) {
return
ret
;
return
ret
;
}
}
int
xmkdir_p
(
const
char
*
pathname
,
mode_t
mode
)
{
int
ret
=
mkdir_p
(
pathname
,
mode
);
if
(
ret
==
-
1
)
{
PLOGE
(
"mkdir_p %s"
,
pathname
);
}
return
ret
;
}
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