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
351f0269
Commit
351f0269
authored
May 20, 2022
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Install stub if necessary
parent
a29ae15f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
46 additions
and
32 deletions
+46
-32
build.py
build.py
+4
-4
bootstages.cpp
native/jni/core/bootstages.cpp
+3
-19
package.cpp
native/jni/core/package.cpp
+34
-7
daemon.hpp
native/jni/include/daemon.hpp
+2
-1
su_daemon.cpp
native/jni/su/su_daemon.cpp
+1
-1
avd_magisk.sh
scripts/avd_magisk.sh
+2
-0
No files found.
build.py
View file @
351f0269
...
@@ -445,8 +445,8 @@ def setup_ndk(args):
...
@@ -445,8 +445,8 @@ def setup_ndk(args):
def
setup_avd
(
args
):
def
setup_avd
(
args
):
if
not
args
.
skip
:
if
not
args
.
skip
:
build_binary
(
args
)
args
.
release
=
False
build_a
pp
(
args
)
build_a
ll
(
args
)
header
(
'* Setting up emulator'
)
header
(
'* Setting up emulator'
)
...
@@ -463,8 +463,8 @@ def setup_avd(args):
...
@@ -463,8 +463,8 @@ def setup_avd(args):
def
patch_avd_ramdisk
(
args
):
def
patch_avd_ramdisk
(
args
):
if
not
args
.
skip
:
if
not
args
.
skip
:
build_binary
(
args
)
args
.
release
=
False
build_a
pp
(
args
)
build_a
ll
(
args
)
header
(
'* Patching emulator ramdisk.img'
)
header
(
'* Patching emulator ramdisk.img'
)
...
...
native/jni/core/bootstages.cpp
View file @
351f0269
...
@@ -18,7 +18,6 @@
...
@@ -18,7 +18,6 @@
using
namespace
std
;
using
namespace
std
;
static
bool
safe_mode
=
false
;
static
bool
safe_mode
=
false
;
static
int
stub_fd
=
-
1
;
bool
zygisk_enabled
=
false
;
bool
zygisk_enabled
=
false
;
/*********
/*********
...
@@ -123,10 +122,7 @@ static bool magisk_env() {
...
@@ -123,10 +122,7 @@ static bool magisk_env() {
LOGI
(
"* Initializing Magisk environment
\n
"
);
LOGI
(
"* Initializing Magisk environment
\n
"
);
string
stub_path
=
MAGISKTMP
+
"/stub.apk"
;
preserve_stub_apk
();
stub_fd
=
xopen
(
stub_path
.
data
(),
O_RDONLY
|
O_CLOEXEC
);
unlink
(
stub_path
.
data
());
string
pkg
;
string
pkg
;
get_manager
(
0
,
&
pkg
);
get_manager
(
0
,
&
pkg
);
...
@@ -375,18 +371,6 @@ void boot_complete(int client) {
...
@@ -375,18 +371,6 @@ void boot_complete(int client) {
if
(
access
(
SECURE_DIR
,
F_OK
)
!=
0
)
if
(
access
(
SECURE_DIR
,
F_OK
)
!=
0
)
xmkdir
(
SECURE_DIR
,
0700
);
xmkdir
(
SECURE_DIR
,
0700
);
if
(
stub_fd
>
0
)
{
// Ensure manager exists
if
(
get_manager
()
<
0
)
{
get_manager
(
0
,
nullptr
,
true
);
// Install stub
struct
stat
st
{};
fstat
(
stub_fd
,
&
st
);
char
apk
[]
=
"/data/stub.apk"
;
int
dfd
=
xopen
(
apk
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
|
O_CLOEXEC
,
0600
);
xsendfile
(
dfd
,
stub_fd
,
nullptr
,
st
.
st_size
);
close
(
dfd
);
install_apk
(
apk
);
}
close
(
stub_fd
);
stub_fd
=
-
1
;
}
}
}
native/jni/core/package.cpp
View file @
351f0269
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
#include <daemon.hpp>
#include <daemon.hpp>
#include <db.hpp>
#include <db.hpp>
#include "core.hpp"
using
namespace
std
;
using
namespace
std
;
// These functions will be called on every single zygote process specialization and su request,
// These functions will be called on every single zygote process specialization and su request,
...
@@ -10,11 +12,13 @@ using namespace std;
...
@@ -10,11 +12,13 @@ using namespace std;
// or simply skipped unless necessary.
// or simply skipped unless necessary.
static
atomic
<
ino_t
>
pkg_xml_ino
=
0
;
static
atomic
<
ino_t
>
pkg_xml_ino
=
0
;
static
atomic_flag
skip_check
;
// pkg_lock protects mgr_app_id and mgr_pkg
static
pthread_mutex_t
pkg_lock
=
PTHREAD_MUTEX_INITIALIZER
;
static
pthread_mutex_t
pkg_lock
=
PTHREAD_MUTEX_INITIALIZER
;
// pkg_lock protects all following variables
static
int
mgr_app_id
=
-
1
;
static
int
mgr_app_id
=
-
1
;
static
string
*
mgr_pkg
;
static
string
*
mgr_pkg
;
static
int
stub_apk_fd
=
-
1
;
bool
need_pkg_refresh
()
{
bool
need_pkg_refresh
()
{
struct
stat
st
{};
struct
stat
st
{};
...
@@ -24,8 +28,7 @@ bool need_pkg_refresh() {
...
@@ -24,8 +28,7 @@ bool need_pkg_refresh() {
// Packages have not changed
// Packages have not changed
return
false
;
return
false
;
}
else
{
}
else
{
mutex_guard
g
(
pkg_lock
);
skip_check
.
clear
();
mgr_app_id
=
-
1
;
return
true
;
return
true
;
}
}
}
}
...
@@ -62,7 +65,27 @@ vector<bool> get_app_no_list() {
...
@@ -62,7 +65,27 @@ vector<bool> get_app_no_list() {
return
list
;
return
list
;
}
}
int
get_manager
(
int
user_id
,
string
*
pkg
)
{
void
preserve_stub_apk
()
{
mutex_guard
g
(
pkg_lock
);
string
stub_path
=
MAGISKTMP
+
"/stub.apk"
;
stub_apk_fd
=
xopen
(
stub_path
.
data
(),
O_RDONLY
|
O_CLOEXEC
);
unlink
(
stub_path
.
data
());
}
static
void
install_stub
()
{
if
(
stub_apk_fd
<
0
)
return
;
struct
stat
st
{};
fstat
(
stub_apk_fd
,
&
st
);
char
apk
[]
=
"/data/stub.apk"
;
int
dfd
=
xopen
(
apk
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
|
O_CLOEXEC
,
0600
);
xsendfile
(
dfd
,
stub_apk_fd
,
nullptr
,
st
.
st_size
);
lseek
(
stub_apk_fd
,
0
,
SEEK_SET
);
close
(
dfd
);
install_apk
(
apk
);
}
int
get_manager
(
int
user_id
,
string
*
pkg
,
bool
install
)
{
mutex_guard
g
(
pkg_lock
);
mutex_guard
g
(
pkg_lock
);
char
app_path
[
128
];
char
app_path
[
128
];
...
@@ -70,14 +93,16 @@ int get_manager(int user_id, string *pkg) {
...
@@ -70,14 +93,16 @@ int get_manager(int user_id, string *pkg) {
if
(
mgr_pkg
==
nullptr
)
if
(
mgr_pkg
==
nullptr
)
default_new
(
mgr_pkg
);
default_new
(
mgr_pkg
);
int
app_id
=
mgr_app_id
;
if
(
skip_check
.
test_and_set
())
{
if
(
app_id
>
0
)
{
if
(
mgr_app_id
<
0
)
{
goto
not_found
;
}
// Just need to check whether the app is installed in the user
// Just need to check whether the app is installed in the user
const
char
*
name
=
mgr_pkg
->
empty
()
?
JAVA_PACKAGE_NAME
:
mgr_pkg
->
data
();
const
char
*
name
=
mgr_pkg
->
empty
()
?
JAVA_PACKAGE_NAME
:
mgr_pkg
->
data
();
snprintf
(
app_path
,
sizeof
(
app_path
),
"%s/%d/%s"
,
APP_DATA_DIR
,
user_id
,
name
);
snprintf
(
app_path
,
sizeof
(
app_path
),
"%s/%d/%s"
,
APP_DATA_DIR
,
user_id
,
name
);
if
(
access
(
app_path
,
F_OK
)
==
0
)
{
if
(
access
(
app_path
,
F_OK
)
==
0
)
{
if
(
pkg
)
*
pkg
=
name
;
if
(
pkg
)
*
pkg
=
name
;
return
user_id
*
AID_USER_OFFSET
+
app_id
;
return
user_id
*
AID_USER_OFFSET
+
mgr_
app_id
;
}
else
{
}
else
{
goto
not_found
;
goto
not_found
;
}
}
...
@@ -166,6 +191,8 @@ int get_manager(int user_id, string *pkg) {
...
@@ -166,6 +191,8 @@ int get_manager(int user_id, string *pkg) {
// No manager app is found, clear all cached value
// No manager app is found, clear all cached value
mgr_app_id
=
-
1
;
mgr_app_id
=
-
1
;
mgr_pkg
->
clear
();
mgr_pkg
->
clear
();
if
(
install
)
install_stub
();
}
}
not_found
:
not_found
:
...
...
native/jni/include/daemon.hpp
View file @
351f0269
...
@@ -86,9 +86,10 @@ void su_daemon_handler(int client, const sock_cred *cred);
...
@@ -86,9 +86,10 @@ void su_daemon_handler(int client, const sock_cred *cred);
void
zygisk_handler
(
int
client
,
const
sock_cred
*
cred
);
void
zygisk_handler
(
int
client
,
const
sock_cred
*
cred
);
// Package
// Package
void
preserve_stub_apk
();
bool
need_pkg_refresh
();
bool
need_pkg_refresh
();
std
::
vector
<
bool
>
get_app_no_list
();
std
::
vector
<
bool
>
get_app_no_list
();
int
get_manager
(
int
user_id
=
0
,
std
::
string
*
pkg
=
nullptr
);
int
get_manager
(
int
user_id
=
0
,
std
::
string
*
pkg
=
nullptr
,
bool
install
=
false
);
// Denylist
// Denylist
void
initialize_denylist
();
void
initialize_denylist
();
...
...
native/jni/su/su_daemon.cpp
View file @
351f0269
...
@@ -82,7 +82,7 @@ void su_info::check_db() {
...
@@ -82,7 +82,7 @@ void su_info::check_db() {
// We need to check our manager
// We need to check our manager
if
(
access
.
log
||
access
.
notify
)
if
(
access
.
log
||
access
.
notify
)
mgr_uid
=
get_manager
(
to_user_id
(
eval_uid
),
&
mgr_pkg
);
mgr_uid
=
get_manager
(
to_user_id
(
eval_uid
),
&
mgr_pkg
,
true
);
}
}
bool
uid_granted_root
(
int
uid
)
{
bool
uid_granted_root
(
int
uid
)
{
...
...
scripts/avd_magisk.sh
View file @
351f0269
...
@@ -139,6 +139,8 @@ ln -s ./magisk $MAGISKTMP/resetprop
...
@@ -139,6 +139,8 @@ ln -s ./magisk $MAGISKTMP/resetprop
ln
-s
./magisk
$MAGISKTMP
/magiskhide
ln
-s
./magisk
$MAGISKTMP
/magiskhide
ln
-s
./magiskpolicy
$MAGISKTMP
/supolicy
ln
-s
./magiskpolicy
$MAGISKTMP
/supolicy
./magiskinit
-x
manager
$MAGISKTMP
/stub.apk
mkdir
-p
$MAGISKTMP
/.magisk/mirror
mkdir
-p
$MAGISKTMP
/.magisk/mirror
mkdir
$MAGISKTMP
/.magisk/block
mkdir
$MAGISKTMP
/.magisk/block
touch
$MAGISKTMP
/.magisk/config
touch
$MAGISKTMP
/.magisk/config
...
...
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