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
4cc7aced
Commit
4cc7aced
authored
Jun 23, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new util function
parent
1058aeb0
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
38 additions
and
33 deletions
+38
-33
bootstages.cpp
native/jni/core/bootstages.cpp
+9
-11
hide_policy.cpp
native/jni/magiskhide/hide_policy.cpp
+10
-16
file.cpp
native/jni/utils/file.cpp
+14
-3
utils.h
native/jni/utils/include/utils.h
+5
-3
No files found.
native/jni/core/bootstages.cpp
View file @
4cc7aced
...
@@ -307,13 +307,13 @@ static int bind_mount(const char *from, const char *to, bool log) {
...
@@ -307,13 +307,13 @@ static int bind_mount(const char *from, const char *to, bool log) {
#define MIRRMNT(part) MIRRDIR "/" #part
#define MIRRMNT(part) MIRRDIR "/" #part
#define PARTBLK(part) BLOCKDIR "/" #part
#define PARTBLK(part) BLOCKDIR "/" #part
#define DIR_IS(part) (me->mnt_dir == "/" #part ""sv)
#define mount_mirror(part, flag) { \
#define mount_mirror(part, flag) { \
sscanf(line.data(), "%s %*s %s", buf, buf2); \
xstat(me->mnt_fsname, &st); \
xstat(buf, &st); \
mknod(PARTBLK(part), (st.st_mode & S_IFMT) | 0600, st.st_rdev); \
mknod(PARTBLK(part), (st.st_mode & S_IFMT) | 0600, st.st_rdev); \
xmkdir(MIRRMNT(part), 0755); \
xmkdir(MIRRMNT(part), 0755); \
xmount(PARTBLK(part), MIRRMNT(part),
buf2
, flag, nullptr); \
xmount(PARTBLK(part), MIRRMNT(part),
me->mnt_type
, flag, nullptr); \
VLOGI("mount", PARTBLK(part), MIRRMNT(part)); \
VLOGI("mount", PARTBLK(part), MIRRMNT(part)); \
}
}
...
@@ -364,21 +364,19 @@ static bool magisk_env() {
...
@@ -364,21 +364,19 @@ static bool magisk_env() {
LOGI
(
"* Mounting mirrors"
);
LOGI
(
"* Mounting mirrors"
);
bool
system_as_root
=
false
;
bool
system_as_root
=
false
;
struct
stat
st
;
struct
stat
st
;
file_readline
(
"/proc/mounts"
,
[
&
](
string_view
line
)
->
bool
{
parse_mnt
(
"/proc/mounts"
,
[
&
](
mntent
*
me
)
{
if
(
str_contains
(
line
,
" /system_root "
))
{
if
(
DIR_IS
(
system_root
))
{
mount_mirror
(
system_root
,
MS_RDONLY
);
mount_mirror
(
system_root
,
MS_RDONLY
);
xsymlink
(
MIRRMNT
(
system_root
)
"/system"
,
MIRRMNT
(
system
));
xsymlink
(
MIRRMNT
(
system_root
)
"/system"
,
MIRRMNT
(
system
));
VLOGI
(
"link"
,
MIRRMNT
(
system_root
)
"/system"
,
MIRRMNT
(
system
));
VLOGI
(
"link"
,
MIRRMNT
(
system_root
)
"/system"
,
MIRRMNT
(
system
));
system_as_root
=
true
;
system_as_root
=
true
;
}
else
if
(
!
system_as_root
&&
str_contains
(
line
,
" /system "
))
{
}
else
if
(
!
system_as_root
&&
DIR_IS
(
system
))
{
mount_mirror
(
system
,
MS_RDONLY
);
mount_mirror
(
system
,
MS_RDONLY
);
}
else
if
(
str_contains
(
line
,
" /vendor "
))
{
}
else
if
(
DIR_IS
(
vendor
))
{
mount_mirror
(
vendor
,
MS_RDONLY
);
mount_mirror
(
vendor
,
MS_RDONLY
);
}
else
if
(
str_contains
(
line
,
" /data "
)
&&
!
str_contains
(
line
,
"tmpfs"
)
)
{
}
else
if
(
DIR_IS
(
data
)
&&
me
->
mnt_type
!=
"tmpfs"
sv
)
{
mount_mirror
(
data
,
0
);
mount_mirror
(
data
,
0
);
}
else
if
(
SDK_INT
>=
24
&&
}
else
if
(
SDK_INT
>=
24
&&
DIR_IS
(
proc
)
&&
!
strstr
(
me
->
mnt_opts
,
"hidepid=2"
))
{
str_contains
(
line
,
" /proc "
)
&&
!
str_contains
(
line
,
"hidepid=2"
))
{
// Enforce hidepid
xmount
(
nullptr
,
"/proc"
,
nullptr
,
MS_REMOUNT
,
"hidepid=2,gid=3009"
);
xmount
(
nullptr
,
"/proc"
,
nullptr
,
MS_REMOUNT
,
"hidepid=2,gid=3009"
);
}
}
return
true
;
return
true
;
...
...
native/jni/magiskhide/hide_policy.cpp
View file @
4cc7aced
...
@@ -44,6 +44,9 @@ void hide_daemon(int pid) {
...
@@ -44,6 +44,9 @@ void hide_daemon(int pid) {
hide_unmount
(
pid
);
hide_unmount
(
pid
);
}
}
#define TMPFS_MNT(dir) (mentry->mnt_type == "tmpfs"sv && \
strncmp(mentry->mnt_dir, "/" #dir, sizeof("/" #dir) - 1) == 0)
void
hide_unmount
(
int
pid
)
{
void
hide_unmount
(
int
pid
)
{
if
(
switch_mnt_ns
(
pid
))
if
(
switch_mnt_ns
(
pid
))
return
;
return
;
...
@@ -60,7 +63,7 @@ void hide_unmount(int pid) {
...
@@ -60,7 +63,7 @@ void hide_unmount(int pid) {
chmod
(
SELINUX_POLICY
,
0440
);
chmod
(
SELINUX_POLICY
,
0440
);
}
}
getprop
([](
const
char
*
name
,
auto
,
auto
)
->
void
{
getprop
([](
const
char
*
name
,
auto
,
auto
)
{
if
(
strstr
(
name
,
"magisk"
))
if
(
strstr
(
name
,
"magisk"
))
deleteprop
(
name
);
deleteprop
(
name
);
},
nullptr
,
false
);
},
nullptr
,
false
);
...
@@ -68,14 +71,9 @@ void hide_unmount(int pid) {
...
@@ -68,14 +71,9 @@ void hide_unmount(int pid) {
vector
<
string
>
targets
;
vector
<
string
>
targets
;
// Unmount dummy skeletons and /sbin links
// Unmount dummy skeletons and /sbin links
file_readline
(
"/proc/self/mounts"
,
[
&
](
string_view
s
)
->
bool
{
parse_mnt
(
"/proc/self/mounts"
,
[
&
](
mntent
*
mentry
)
{
if
(
str_contains
(
s
,
"tmpfs /system/"
)
||
str_contains
(
s
,
"tmpfs /vendor/"
)
||
if
(
TMPFS_MNT
(
system
)
||
TMPFS_MNT
(
vendor
)
||
TMPFS_MNT
(
sbin
))
str_contains
(
s
,
"tmpfs /sbin"
))
{
targets
.
emplace_back
(
mentry
->
mnt_dir
);
char
*
path
=
(
char
*
)
s
.
data
();
// Skip first token
strtok_r
(
nullptr
,
" "
,
&
path
);
targets
.
emplace_back
(
strtok_r
(
nullptr
,
" "
,
&
path
));
}
return
true
;
return
true
;
});
});
...
@@ -84,13 +82,9 @@ void hide_unmount(int pid) {
...
@@ -84,13 +82,9 @@ void hide_unmount(int pid) {
targets
.
clear
();
targets
.
clear
();
// Unmount all Magisk created mounts
// Unmount all Magisk created mounts
file_readline
(
"/proc/self/mounts"
,
[
&
](
string_view
s
)
->
bool
{
parse_mnt
(
"/proc/self/mounts"
,
[
&
](
mntent
*
mentry
)
{
if
(
str_contains
(
s
,
BLOCKDIR
))
{
if
(
strstr
(
mentry
->
mnt_fsname
,
BLOCKDIR
))
char
*
path
=
(
char
*
)
s
.
data
();
targets
.
emplace_back
(
mentry
->
mnt_dir
);
// Skip first token
strtok_r
(
nullptr
,
" "
,
&
path
);
targets
.
emplace_back
(
strtok_r
(
nullptr
,
" "
,
&
path
));
}
return
true
;
return
true
;
});
});
...
...
native/jni/utils/file.cpp
View file @
4cc7aced
/* file.cpp - Contains all files related utilities
/* file.cpp - Contains all files related utilities
*/
*/
#include <sys/sendfile.h>
#include <sys/mman.h>
#include <linux/fs.h>
#include <stdlib.h>
#include <stdlib.h>
#include <fcntl.h>
#include <fcntl.h>
#include <unistd.h>
#include <unistd.h>
#include <errno.h>
#include <errno.h>
#include <string.h>
#include <string.h>
#include <libgen.h>
#include <libgen.h>
#include <sys/sendfile.h>
#include <sys/mman.h>
#include <linux/fs.h>
#include <magisk.h>
#include <magisk.h>
#include <utils.h>
#include <utils.h>
...
@@ -396,3 +396,14 @@ void parse_prop_file(const char *file, const function<bool (string_view, string_
...
@@ -396,3 +396,14 @@ void parse_prop_file(const char *file, const function<bool (string_view, string_
return
fn
(
line
,
eql
+
1
);
return
fn
(
line
,
eql
+
1
);
},
true
);
},
true
);
}
}
void
parse_mnt
(
const
char
*
file
,
const
function
<
bool
(
mntent
*
)
>
&
fn
)
{
unique_ptr
<
FILE
,
decltype
(
&
fclose
)
>
fp
(
xfopen
(
file
,
"rce"
),
&
fclose
);
if
(
fp
)
{
mntent
*
mentry
;
while
((
mentry
=
getmntent
(
fp
.
get
()))
!=
nullptr
)
{
if
(
!
fn
(
mentry
))
break
;
}
}
}
native/jni/utils/include/utils.h
View file @
4cc7aced
...
@@ -3,13 +3,14 @@
...
@@ -3,13 +3,14 @@
#pragma once
#pragma once
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <stdio.h>
#include <stdio.h>
#include <dirent.h>
#include <dirent.h>
#include <pthread.h>
#include <pthread.h>
#include <poll.h>
#include <poll.h>
#include <sys/socket.h>
#include <mntent.h>
#include <sys/stat.h>
#include <sys/mman.h>
#ifdef __cplusplus
#ifdef __cplusplus
extern
"C"
{
extern
"C"
{
...
@@ -173,6 +174,7 @@ void parse_prop_file(const char *file, const std::function
...
@@ -173,6 +174,7 @@ void parse_prop_file(const char *file, const std::function
void
*
__mmap
(
const
char
*
filename
,
size_t
*
size
,
bool
rw
);
void
*
__mmap
(
const
char
*
filename
,
size_t
*
size
,
bool
rw
);
void
frm_rf
(
int
dirfd
,
std
::
initializer_list
<
const
char
*>
excl
=
std
::
initializer_list
<
const
char
*>
());
void
frm_rf
(
int
dirfd
,
std
::
initializer_list
<
const
char
*>
excl
=
std
::
initializer_list
<
const
char
*>
());
void
clone_dir
(
int
src
,
int
dest
,
bool
overwrite
=
true
);
void
clone_dir
(
int
src
,
int
dest
,
bool
overwrite
=
true
);
void
parse_mnt
(
const
char
*
file
,
const
std
::
function
<
bool
(
mntent
*
)
>
&
fn
);
template
<
typename
B
>
template
<
typename
B
>
void
mmap_ro
(
const
char
*
filename
,
B
&
buf
,
size_t
&
sz
)
{
void
mmap_ro
(
const
char
*
filename
,
B
&
buf
,
size_t
&
sz
)
{
...
...
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