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
7eed9c4a
Commit
7eed9c4a
authored
Jul 02, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Several improvements
parent
bf42fce1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
80 additions
and
67 deletions
+80
-67
log_monitor.c
jni/daemon/log_monitor.c
+2
-2
magiskhide.c
jni/magiskhide/magiskhide.c
+6
-5
proc_monitor.c
jni/magiskhide/proc_monitor.c
+7
-2
img.c
jni/utils/img.c
+60
-53
misc.c
jni/utils/misc.c
+5
-4
utils.h
jni/utils/utils.h
+0
-1
No files found.
jni/daemon/log_monitor.c
View file @
7eed9c4a
...
...
@@ -28,13 +28,13 @@ static void *logger_thread(void *args) {
// Start logcat
char
*
const
command
[]
=
{
"logcat"
,
"-s"
,
"Magisk"
,
"-v"
,
"thread"
,
NULL
};
log_pid
=
run_command
(
0
,
&
log_fd
,
"/system/bin/logcat"
,
command
);
waitpid
(
log_pid
,
NULL
,
0
);
if
(
log_pid
>
0
)
waitpid
(
log_pid
,
NULL
,
0
);
// For some reason it went here, clear buffer and restart
system
(
"logcat -c"
);
}
// Should never be here, but well...
close
(
log_fd
);
return
NULL
;
}
...
...
jni/magiskhide/magiskhide.c
View file @
7eed9c4a
...
...
@@ -46,16 +46,17 @@ void launch_magiskhide(int client) {
err_handler
=
do_nothing
;
if
(
hideEnabled
)
{
write_int
(
client
,
HIDE_IS_ENABLED
);
close
(
client
);
if
(
client
>
0
)
{
write_int
(
client
,
HIDE_IS_ENABLED
);
close
(
client
);
}
return
;
}
LOGI
(
"* Starting MagiskHide
\n
"
);
hideEnabled
=
1
;
LOGI
(
"* Starting MagiskHide
\n
"
);
if
(
client
!=
-
1
)
{
if
(
client
>
0
)
{
if
(
setprop
(
MAGISKHIDE_PROP
,
"1"
))
goto
error
;
}
...
...
jni/magiskhide/proc_monitor.c
View file @
7eed9c4a
...
...
@@ -17,9 +17,9 @@
#include "utils.h"
#include "magiskhide.h"
static
int
zygote_num
=
0
;
static
int
zygote_num
;
static
char
init_ns
[
32
],
zygote_ns
[
2
][
32
];
static
int
log_pid
=
0
,
log_fd
=
0
;
static
int
log_pid
,
log_fd
;
static
char
*
buffer
;
static
void
read_namespace
(
const
int
pid
,
char
*
target
,
const
size_t
size
)
{
...
...
@@ -85,6 +85,7 @@ void proc_monitor() {
LOGI
(
"proc_monitor: init ns=%s
\n
"
,
init_ns
);
// Get the mount namespace of zygote
zygote_num
=
0
;
while
(
!
zygote_num
)
{
// Check zygote every 2 secs
sleep
(
2
);
...
...
@@ -107,8 +108,12 @@ void proc_monitor() {
// Monitor am_proc_start
char
*
const
command
[]
=
{
"logcat"
,
"-b"
,
"events"
,
"-v"
,
"raw"
,
"-s"
,
"am_proc_start"
,
NULL
};
log_fd
=
0
;
log_pid
=
run_command
(
0
,
&
log_fd
,
"/system/bin/logcat"
,
command
);
if
(
log_pid
<
0
)
continue
;
if
(
kill
(
log_pid
,
0
))
continue
;
while
(
fdgets
(
buffer
,
PATH_MAX
,
log_fd
))
{
int
ret
,
comma
=
0
;
char
*
pos
=
buffer
,
*
line
,
processName
[
256
];
...
...
jni/utils/img.c
View file @
7eed9c4a
...
...
@@ -10,6 +10,45 @@
#include "magisk.h"
#include "utils.h"
static
int
e2fsck
(
const
char
*
img
)
{
// Check and repair ext4 image
char
buffer
[
128
];
int
pid
,
fd
=
0
;
char
*
const
command
[]
=
{
"e2fsck"
,
"-yf"
,
(
char
*
)
img
,
NULL
};
pid
=
run_command
(
1
,
&
fd
,
"/system/bin/e2fsck"
,
command
);
if
(
pid
<
0
)
return
1
;
while
(
fdgets
(
buffer
,
sizeof
(
buffer
),
fd
))
LOGD
(
"magisk_img: %s"
,
buffer
);
waitpid
(
pid
,
NULL
,
0
);
close
(
fd
);
return
0
;
}
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
);
close
(
lfd
);
close
(
ffd
);
return
strdup
(
device
);
}
int
create_img
(
const
char
*
img
,
int
size
)
{
unlink
(
img
);
LOGI
(
"Create %s with size %dM
\n
"
,
img
,
size
);
...
...
@@ -17,17 +56,15 @@ int create_img(const char *img, int size) {
char
file_contexts
[]
=
"/magisk(/.*)? u:object_r:system_file:s0
\n
"
;
// If not root, attempt to create in current diretory
char
*
filename
=
getuid
()
==
UID_ROOT
?
"/dev/file_contexts_image"
:
"file_contexts_image"
;
int
fd
=
xopen
(
filename
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0644
);
int
pid
,
status
,
fd
=
xopen
(
filename
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
,
0644
);
xwrite
(
fd
,
file_contexts
,
sizeof
(
file_contexts
));
close
(
fd
);
char
buffer
[
PATH_MAX
];
snprintf
(
buffer
,
sizeof
(
buffer
),
"make_ext4fs -l %dM -a /magisk -S %s %s; e2fsck -yf %s;"
,
size
,
filename
,
img
,
img
);
char
*
const
command
[]
=
{
"sh"
,
"-c"
,
buffer
,
NULL
};
int
pid
,
status
;
pid
=
run_command
(
0
,
NULL
,
"/system/bin/sh"
,
command
);
if
(
pid
==
-
1
)
char
buffer
[
16
];
snprintf
(
buffer
,
sizeof
(
buffer
),
"%dM"
,
size
);
char
*
const
command
[]
=
{
"make_ext4fs"
,
"-l"
,
buffer
,
"-a"
,
"/magisk"
,
"-S"
,
filename
,
(
char
*
)
img
,
NULL
};
pid
=
run_command
(
0
,
NULL
,
"/system/bin/make_ext4fs"
,
command
);
if
(
pid
<
0
)
return
1
;
waitpid
(
pid
,
&
status
,
0
);
unlink
(
filename
);
...
...
@@ -38,14 +75,12 @@ int get_img_size(const char *img, int *used, int *total) {
if
(
access
(
img
,
R_OK
)
==
-
1
)
return
1
;
char
buffer
[
PATH_MAX
];
snprintf
(
buffer
,
sizeof
(
buffer
),
"e2fsck -n %s"
,
img
);
char
*
const
command
[]
=
{
"sh"
,
"-c"
,
buffer
,
NULL
};
int
pid
,
fd
=
0
,
status
=
1
;
pid
=
run_command
(
1
,
&
fd
,
"/system/bin/sh"
,
command
);
if
(
pid
==
-
1
)
char
*
const
command
[]
=
{
"e2fsck"
,
"-n"
,
(
char
*
)
img
,
NULL
};
pid
=
run_command
(
1
,
&
fd
,
"/system/bin/e2fsck"
,
command
);
if
(
pid
<
0
)
return
1
;
while
(
fdgets
(
buffer
,
sizeof
(
buffer
),
fd
))
{
// LOGD("magisk_img: %s", buffer);
if
(
strstr
(
buffer
,
img
))
{
char
*
tok
=
strtok
(
buffer
,
","
);
while
(
tok
!=
NULL
)
{
...
...
@@ -63,18 +98,20 @@ int get_img_size(const char *img, int *used, int *total) {
}
}
close
(
fd
);
waitpid
(
pid
,
&
status
,
0
);
return
WEXITSTATUS
(
status
)
;
waitpid
(
pid
,
NULL
,
0
);
return
0
;
}
int
resize_img
(
const
char
*
img
,
int
size
)
{
LOGI
(
"Resize %s to %dM
\n
"
,
img
,
size
);
char
buffer
[
PATH_MAX
];
snprintf
(
buffer
,
sizeof
(
buffer
),
"e2fsck -yf %s; resize2fs %s %dM;"
,
img
,
img
,
size
)
;
char
*
const
command
[]
=
{
"sh"
,
"-c"
,
buffer
,
NULL
}
;
if
(
e2fsck
(
img
))
return
1
;
char
buffer
[
128
]
;
int
pid
,
status
,
fd
=
0
;
pid
=
run_command
(
1
,
&
fd
,
"/system/bin/sh"
,
command
);
if
(
pid
==
-
1
)
snprintf
(
buffer
,
sizeof
(
buffer
),
"%dM"
,
size
);
char
*
const
command
[]
=
{
"resize2fs"
,
(
char
*
)
img
,
buffer
,
NULL
};
pid
=
run_command
(
1
,
&
fd
,
"/system/bin/resize2fs"
,
command
);
if
(
pid
<
0
)
return
1
;
while
(
fdgets
(
buffer
,
sizeof
(
buffer
),
fd
))
LOGD
(
"magisk_img: %s"
,
buffer
);
...
...
@@ -83,30 +120,6 @@ int resize_img(const char *img, int size) {
return
WEXITSTATUS
(
status
);
}
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
);
close
(
lfd
);
close
(
ffd
);
return
strdup
(
device
);
}
char
*
mount_image
(
const
char
*
img
,
const
char
*
target
)
{
if
(
access
(
img
,
F_OK
)
==
-
1
)
return
NULL
;
...
...
@@ -117,16 +130,10 @@ char *mount_image(const char *img, const char *target) {
xmount
(
NULL
,
"/"
,
NULL
,
MS_REMOUNT
|
MS_RDONLY
,
NULL
);
}
}
// Check and repair ext4 image
char
buffer
[
PATH_MAX
];
snprintf
(
buffer
,
sizeof
(
buffer
),
"e2fsck -yf %s"
,
img
);
int
fd
=
0
;
char
*
const
command
[]
=
{
"sh"
,
"-c"
,
buffer
,
NULL
};
if
(
run_command
(
1
,
&
fd
,
"/system/bin/sh"
,
command
)
==
-
1
)
if
(
e2fsck
(
img
))
return
NULL
;
while
(
fdgets
(
buffer
,
sizeof
(
buffer
),
fd
))
LOGD
(
"magisk_img: %s"
,
buffer
);
close
(
fd
);
char
*
device
=
loopsetup
(
img
);
if
(
device
)
xmount
(
device
,
target
,
"ext4"
,
0
,
NULL
);
...
...
jni/utils/misc.c
View file @
7eed9c4a
...
...
@@ -225,10 +225,12 @@ void setup_sighandlers(void (*handler)(int)) {
*fd != 0 -> STDOUT (or STDERR) will be redirected to *fd
*/
int
run_command
(
int
err
,
int
*
fd
,
const
char
*
path
,
char
*
const
argv
[])
{
int
pipefd
[
2
],
writeEnd
=
0
;
int
pipefd
[
2
],
writeEnd
=
-
1
;
if
(
fd
)
{
if
(
*
fd
==
0
)
{
if
(
*
fd
)
{
writeEnd
=
*
fd
;
}
else
{
if
(
pipe
(
pipefd
)
==
-
1
)
return
-
1
;
writeEnd
=
pipefd
[
1
];
...
...
@@ -239,12 +241,11 @@ int run_command(int err, int *fd, const char *path, char *const argv[]) {
int
pid
=
fork
();
if
(
pid
!=
0
)
{
if
(
writeEnd
)
close
(
writeEnd
);
close
(
writeEnd
);
return
pid
;
}
if
(
fd
)
{
if
(
writeEnd
==
0
)
writeEnd
=
*
fd
;
xdup2
(
writeEnd
,
STDOUT_FILENO
);
if
(
err
)
xdup2
(
writeEnd
,
STDERR_FILENO
);
}
...
...
jni/utils/utils.h
View file @
7eed9c4a
...
...
@@ -98,7 +98,6 @@ int switch_mnt_ns(int pid);
int
create_img
(
const
char
*
img
,
int
size
);
int
get_img_size
(
const
char
*
img
,
int
*
used
,
int
*
total
);
int
resize_img
(
const
char
*
img
,
int
size
);
char
*
loopsetup
(
const
char
*
img
);
char
*
mount_image
(
const
char
*
img
,
const
char
*
target
);
void
umount_image
(
const
char
*
target
,
const
char
*
device
);
...
...
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