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
e21a7816
Commit
e21a7816
authored
Nov 04, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Properly handle factory resets
Close #3345
parent
1e0f96d0
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
60 additions
and
57 deletions
+60
-57
bootstages.cpp
native/jni/core/bootstages.cpp
+59
-57
module.cpp
native/jni/core/module.cpp
+1
-0
No files found.
native/jni/core/bootstages.cpp
View file @
e21a7816
...
@@ -57,51 +57,10 @@ else if (MNT_DIR_IS(dir) && me->mnt_type != "tmpfs"sv) { \
...
@@ -57,51 +57,10 @@ else if (MNT_DIR_IS(dir) && me->mnt_type != "tmpfs"sv) { \
#define link_orig(part) link_orig_dir("/" #part, part)
#define link_orig(part) link_orig_dir("/" #part, part)
static
bool
magisk_env
()
{
static
void
mount_mirrors
()
{
LOGI
(
"* Initializing Magisk environment
\n
"
);
string
pkg
;
check_manager
(
&
pkg
);
char
buf1
[
4096
];
char
buf1
[
4096
];
char
buf2
[
4096
];
char
buf2
[
4096
];
sprintf
(
buf1
,
"%s/0/%s/install"
,
APP_DATA_DIR
,
pkg
.
data
());
// Alternative binaries paths
const
char
*
alt_bin
[]
=
{
"/cache/data_adb/magisk"
,
"/data/magisk"
,
buf1
};
for
(
auto
alt
:
alt_bin
)
{
struct
stat
st
;
if
(
lstat
(
alt
,
&
st
)
==
0
)
{
if
(
S_ISLNK
(
st
.
st_mode
))
{
unlink
(
alt
);
continue
;
}
rm_rf
(
DATABIN
);
cp_afc
(
alt
,
DATABIN
);
rm_rf
(
alt
);
break
;
}
}
// Remove stuffs
rm_rf
(
"/cache/data_adb"
);
rm_rf
(
"/data/adb/modules/.core"
);
unlink
(
"/data/adb/magisk.img"
);
unlink
(
"/data/adb/magisk_merge.img"
);
unlink
(
"/data/magisk.img"
);
unlink
(
"/data/magisk_merge.img"
);
unlink
(
"/data/magisk_debug.log"
);
sprintf
(
buf1
,
"%s/"
MODULEMNT
,
MAGISKTMP
.
data
());
xmkdir
(
buf1
,
0755
);
// Directories in /data/adb
xmkdir
(
DATABIN
,
0755
);
xmkdir
(
MODULEROOT
,
0755
);
xmkdir
(
SECURE_DIR
"/post-fs-data.d"
,
0755
);
xmkdir
(
SECURE_DIR
"/service.d"
,
0755
);
LOGI
(
"* Mounting mirrors"
);
LOGI
(
"* Mounting mirrors"
);
parse_mnt
(
"/proc/mounts"
,
[
&
](
mntent
*
me
)
{
parse_mnt
(
"/proc/mounts"
,
[
&
](
mntent
*
me
)
{
...
@@ -137,6 +96,48 @@ static bool magisk_env() {
...
@@ -137,6 +96,48 @@ static bool magisk_env() {
link_mirror
(
vendor
)
link_mirror
(
vendor
)
link_mirror
(
product
)
link_mirror
(
product
)
link_mirror
(
system_ext
)
link_mirror
(
system_ext
)
}
static
bool
magisk_env
()
{
char
buf
[
4096
];
LOGI
(
"* Initializing Magisk environment
\n
"
);
string
pkg
;
check_manager
(
&
pkg
);
sprintf
(
buf
,
"%s/0/%s/install"
,
APP_DATA_DIR
,
pkg
.
data
());
// Alternative binaries paths
const
char
*
alt_bin
[]
=
{
"/cache/data_adb/magisk"
,
"/data/magisk"
,
buf
};
for
(
auto
alt
:
alt_bin
)
{
struct
stat
st
;
if
(
lstat
(
alt
,
&
st
)
==
0
)
{
if
(
S_ISLNK
(
st
.
st_mode
))
{
unlink
(
alt
);
continue
;
}
rm_rf
(
DATABIN
);
cp_afc
(
alt
,
DATABIN
);
rm_rf
(
alt
);
break
;
}
}
// Remove stuffs
rm_rf
(
"/cache/data_adb"
);
rm_rf
(
"/data/adb/modules/.core"
);
unlink
(
"/data/adb/magisk.img"
);
unlink
(
"/data/adb/magisk_merge.img"
);
unlink
(
"/data/magisk.img"
);
unlink
(
"/data/magisk_merge.img"
);
unlink
(
"/data/magisk_debug.log"
);
// Directories in /data/adb
xmkdir
(
DATABIN
,
0755
);
xmkdir
(
MODULEROOT
,
0755
);
xmkdir
(
SECURE_DIR
"/post-fs-data.d"
,
0755
);
xmkdir
(
SECURE_DIR
"/service.d"
,
0755
);
// Disable/remove magiskhide, resetprop
// Disable/remove magiskhide, resetprop
if
(
SDK_INT
<
19
)
{
if
(
SDK_INT
<
19
)
{
...
@@ -149,10 +150,10 @@ static bool magisk_env() {
...
@@ -149,10 +150,10 @@ static bool magisk_env() {
// TODO: Remove. Backwards compatibility for old manager
// TODO: Remove. Backwards compatibility for old manager
LOGI
(
"* Setting up internal busybox
\n
"
);
LOGI
(
"* Setting up internal busybox
\n
"
);
sprintf
(
buf
1
,
"%s/"
BBPATH
"/busybox"
,
MAGISKTMP
.
data
());
sprintf
(
buf
,
"%s/"
BBPATH
"/busybox"
,
MAGISKTMP
.
data
());
mkdir
(
dirname
(
buf
1
),
0755
);
mkdir
(
dirname
(
buf
),
0755
);
cp_afc
(
DATABIN
"/busybox"
,
buf
1
);
cp_afc
(
DATABIN
"/busybox"
,
buf
);
exec_command_sync
(
buf
1
,
"--install"
,
"-s"
,
dirname
(
buf1
));
exec_command_sync
(
buf
,
"--install"
,
"-s"
,
dirname
(
buf
));
return
true
;
return
true
;
}
}
...
@@ -307,25 +308,25 @@ void post_fs_data(int client) {
...
@@ -307,25 +308,25 @@ void post_fs_data(int client) {
LOGI
(
"** post-fs-data mode running
\n
"
);
LOGI
(
"** post-fs-data mode running
\n
"
);
// Unlock all blocks for rw
unlock_blocks
();
unlock_blocks
();
mount_mirrors
();
if
(
access
(
SECURE_DIR
,
F_OK
)
!=
0
)
{
if
(
access
(
SECURE_DIR
,
F_OK
)
!=
0
)
{
if
(
SDK_INT
<
24
)
{
if
(
SDK_INT
<
24
)
{
// There is no FBE pre 7.0, we can directly create the folder without issues
// There is no FBE pre 7.0, we can directly create the folder without issues
xmkdir
(
SECURE_DIR
,
0700
);
xmkdir
(
SECURE_DIR
,
0700
);
}
else
{
}
else
{
/
*
If the folder is not automatically created by Android,
/
/
If the folder is not automatically created by Android,
*
do NOT proceed further. Manual creation of the folder
//
do NOT proceed further. Manual creation of the folder
* will cause bootloops on FBE devices. */
// will cause bootloops on FBE devices.
LOGE
(
SECURE_DIR
" is not present, abort
...
\n
"
);
LOGE
(
SECURE_DIR
" is not present, abort
\n
"
);
goto
unblock_ini
t
;
goto
early_abor
t
;
}
}
}
}
if
(
!
magisk_env
())
{
if
(
!
magisk_env
())
{
LOGE
(
"* Magisk environment
setup
incomplete, abort
\n
"
);
LOGE
(
"* Magisk environment incomplete, abort
\n
"
);
goto
unblock_ini
t
;
goto
early_abor
t
;
}
}
if
(
getprop
(
"persist.sys.safemode"
,
true
)
==
"1"
||
check_key_combo
())
{
if
(
getprop
(
"persist.sys.safemode"
,
true
)
==
"1"
||
check_key_combo
())
{
...
@@ -339,9 +340,11 @@ void post_fs_data(int client) {
...
@@ -339,9 +340,11 @@ void post_fs_data(int client) {
handle_modules
();
handle_modules
();
}
}
pfs_done
=
true
;
early_abort:
// We still do magic mount because root itself might need it
// We still do magic mount because root itself might need it
magic_mount
();
magic_mount
();
pfs_done
=
true
;
unblock_init:
unblock_init:
close
(
xopen
(
UNBLOCKFILE
,
O_RDONLY
|
O_CREAT
,
0
));
close
(
xopen
(
UNBLOCKFILE
,
O_RDONLY
|
O_CREAT
,
0
));
...
@@ -373,8 +376,7 @@ void boot_complete(int client) {
...
@@ -373,8 +376,7 @@ void boot_complete(int client) {
if
(
safe_mode
)
if
(
safe_mode
)
return
;
return
;
/* It's safe to create the folder at this point if the system didn't create it
// At this point it's safe to create the folder
* Magisk Manager should finish up the remaining environment setup */
if
(
access
(
SECURE_DIR
,
F_OK
)
!=
0
)
if
(
access
(
SECURE_DIR
,
F_OK
)
!=
0
)
xmkdir
(
SECURE_DIR
,
0700
);
xmkdir
(
SECURE_DIR
,
0700
);
...
...
native/jni/core/module.cpp
View file @
e21a7816
...
@@ -636,6 +636,7 @@ static void prepare_modules() {
...
@@ -636,6 +636,7 @@ static void prepare_modules() {
// Setup module mount (workaround nosuid selabel issue)
// Setup module mount (workaround nosuid selabel issue)
auto
src
=
MAGISKTMP
+
"/"
MIRRDIR
MODULEROOT
;
auto
src
=
MAGISKTMP
+
"/"
MIRRDIR
MODULEROOT
;
auto
dest
=
MAGISKTMP
+
"/"
MODULEMNT
;
auto
dest
=
MAGISKTMP
+
"/"
MODULEMNT
;
xmkdir
(
dest
.
data
(),
0755
);
bind_mount
(
src
.
data
(),
dest
.
data
());
bind_mount
(
src
.
data
(),
dest
.
data
());
restorecon
();
restorecon
();
...
...
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