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
7b25e744
Commit
7b25e744
authored
Sep 17, 2021
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Simplify get manager app info logic
parent
82f303e1
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
46 additions
and
45 deletions
+46
-45
bootstages.cpp
native/jni/core/bootstages.cpp
+4
-3
db.cpp
native/jni/core/db.cpp
+28
-30
db.hpp
native/jni/include/db.hpp
+2
-2
connect.cpp
native/jni/su/connect.cpp
+3
-3
su.hpp
native/jni/su/su.hpp
+1
-1
su_daemon.cpp
native/jni/su/su_daemon.cpp
+5
-6
misc.hpp
native/jni/utils/misc.hpp
+3
-0
No files found.
native/jni/core/bootstages.cpp
View file @
7b25e744
...
...
@@ -106,9 +106,10 @@ static bool magisk_env() {
LOGI
(
"* Initializing Magisk environment
\n
"
);
string
pkg
;
check
_manager
(
&
pkg
);
get
_manager
(
&
pkg
);
sprintf
(
buf
,
"%s/0/%s/install"
,
APP_DATA_DIR
,
pkg
.
data
());
sprintf
(
buf
,
"%s/0/%s/install"
,
APP_DATA_DIR
,
pkg
.
empty
()
?
"xxx"
/* Ensure non-exist path */
:
pkg
.
data
());
// Alternative binaries paths
const
char
*
alt_bin
[]
=
{
"/cache/data_adb/magisk"
,
"/data/magisk"
,
buf
};
...
...
@@ -354,7 +355,7 @@ void boot_complete(int client) {
if
(
access
(
SECURE_DIR
,
F_OK
)
!=
0
)
xmkdir
(
SECURE_DIR
,
0700
);
if
(
!
check
_manager
())
{
if
(
!
get
_manager
())
{
if
(
access
(
MANAGERAPK
,
F_OK
)
==
0
)
{
// Only try to install APK when no manager is installed
// Magisk Manager should be upgraded by itself, not through recovery installs
...
...
native/jni/core/db.cpp
View file @
7b25e744
...
...
@@ -341,41 +341,39 @@ int get_uid_policy(su_access &su, int uid) {
return
0
;
}
bool
check_manager
(
string
*
pkg
)
{
bool
get_manager
(
int
user_id
,
std
::
string
*
pkg
,
struct
stat
*
st
)
{
db_strings
str
;
get_db_strings
(
str
,
SU_MANAGER
);
bool
ret
=
validate_manager
(
str
[
SU_MANAGER
],
0
,
nullptr
);
if
(
pkg
)
{
if
(
ret
)
pkg
->
swap
(
str
[
SU_MANAGER
]);
else
*
pkg
=
"xxx"
;
/* Make sure the return pkg can never exist */
}
return
ret
;
}
bool
validate_manager
(
string
&
pkg
,
int
userid
,
struct
stat
*
st
)
{
struct
stat
tmp_st
;
if
(
st
==
nullptr
)
st
=
&
tmp_st
;
// Prefer DE storage
char
app_path
[
128
];
sprintf
(
app_path
,
"%s/%d/%s"
,
APP_DATA_DIR
,
userid
,
pkg
.
data
());
if
(
pkg
.
empty
()
||
stat
(
app_path
,
st
))
{
// Check the official package name
sprintf
(
app_path
,
"%s/%d/"
JAVA_PACKAGE_NAME
,
APP_DATA_DIR
,
userid
);
if
(
stat
(
app_path
,
st
))
{
LOGE
(
"su: cannot find manager
\n
"
);
memset
(
st
,
0
,
sizeof
(
*
st
));
pkg
.
clear
();
return
false
;
}
else
{
// Switch to official package if exists
pkg
=
JAVA_PACKAGE_NAME
;
if
(
!
str
[
SU_MANAGER
].
empty
())
{
// App is repackaged
sprintf
(
app_path
,
"%s/%d/%s"
,
APP_DATA_DIR
,
user_id
,
str
[
SU_MANAGER
].
data
());
if
(
stat
(
app_path
,
st
)
==
0
)
{
if
(
pkg
)
pkg
->
swap
(
str
[
SU_MANAGER
]);
return
true
;
}
}
return
true
;
// Check the official package name
sprintf
(
app_path
,
"%s/%d/"
JAVA_PACKAGE_NAME
,
APP_DATA_DIR
,
user_id
);
if
(
stat
(
app_path
,
st
)
==
0
)
{
if
(
pkg
)
*
pkg
=
JAVA_PACKAGE_NAME
;
return
true
;
}
else
{
LOGE
(
"su: cannot find manager
\n
"
);
memset
(
st
,
0
,
sizeof
(
*
st
));
if
(
pkg
)
pkg
->
clear
();
return
false
;
}
}
bool
get_manager
(
string
*
pkg
)
{
struct
stat
st
;
return
get_manager
(
0
,
pkg
,
&
st
);
}
void
exec_sql
(
int
client
)
{
...
...
native/jni/include/db.hpp
View file @
7b25e744
...
...
@@ -126,8 +126,8 @@ using db_row_cb = std::function<bool(db_row&)>;
int
get_db_settings
(
db_settings
&
cfg
,
int
key
=
-
1
);
int
get_db_strings
(
db_strings
&
str
,
int
key
=
-
1
);
int
get_uid_policy
(
su_access
&
su
,
int
uid
);
bool
check_manager
(
std
::
string
*
pkg
=
nullptr
);
bool
validate_manager
(
std
::
string
&
pkg
,
int
userid
,
struct
stat
*
st
);
bool
get_manager
(
int
user_id
,
std
::
string
*
pkg
,
struct
stat
*
st
);
bool
get_manager
(
std
::
string
*
pkg
=
nullptr
);
void
exec_sql
(
int
client
);
char
*
db_exec
(
const
char
*
sql
);
char
*
db_exec
(
const
char
*
sql
,
const
db_row_cb
&
fn
);
...
...
native/jni/su/connect.cpp
View file @
7b25e744
...
...
@@ -106,7 +106,7 @@ static void exec_cmd(const char *action, vector<Extra> &data,
// First try content provider call method
if
(
mode
>=
CONTENT_PROVIDER
)
{
sprintf
(
target
,
"content://%s.provider"
,
info
->
str
[
SU_MANAGER
]
.
data
());
sprintf
(
target
,
"content://%s.provider"
,
info
->
mgr_pkg
.
data
());
vector
<
const
char
*>
args
{
CALL_PROVIDER
};
for
(
auto
&
e
:
data
)
{
e
.
add_bind
(
args
);
...
...
@@ -137,7 +137,7 @@ static void exec_cmd(const char *action, vector<Extra> &data,
if
(
mode
>=
PKG_ACTIVITY
)
{
// Then try start activity without component name
strcpy
(
target
,
info
->
str
[
SU_MANAGER
]
.
data
());
strcpy
(
target
,
info
->
mgr_pkg
.
data
());
exec_command_sync
(
exec
);
if
(
check_no_error
(
exec
.
fd
))
return
;
...
...
@@ -145,7 +145,7 @@ static void exec_cmd(const char *action, vector<Extra> &data,
// Finally, fallback to start activity with component name
args
[
4
]
=
"-n"
;
sprintf
(
target
,
"%s/.ui.surequest.SuRequestActivity"
,
info
->
str
[
SU_MANAGER
]
.
data
());
sprintf
(
target
,
"%s/.ui.surequest.SuRequestActivity"
,
info
->
mgr_pkg
.
data
());
exec
.
fd
=
-
2
;
exec
.
fork
=
fork_dont_care
;
exec_command
(
exec
);
...
...
native/jni/su/su.hpp
View file @
7b25e744
...
...
@@ -20,8 +20,8 @@ public:
/* These should be guarded with internal lock */
db_settings
cfg
;
db_strings
str
;
su_access
access
;
std
::
string
mgr_pkg
;
struct
stat
mgr_st
;
/* This should be guarded with global cache lock */
...
...
native/jni/su/su_daemon.cpp
View file @
7b25e744
...
...
@@ -47,18 +47,17 @@ void su_info::refresh() {
static
void
database_check
(
const
shared_ptr
<
su_info
>
&
info
)
{
int
uid
=
info
->
uid
;
get_db_settings
(
info
->
cfg
);
get_db_strings
(
info
->
str
);
// Check multiuser settings
switch
(
info
->
cfg
[
SU_MULTIUSER_MODE
])
{
case
MULTIUSER_MODE_OWNER_ONLY
:
if
(
info
->
uid
/
10000
0
)
{
if
(
to_user_id
(
uid
)
!=
0
)
{
uid
=
-
1
;
info
->
access
=
NO_SU_ACCESS
;
}
break
;
case
MULTIUSER_MODE_OWNER_MANAGED
:
uid
=
info
->
uid
%
100000
;
uid
=
to_app_id
(
uid
)
;
break
;
case
MULTIUSER_MODE_USER
:
default
:
...
...
@@ -70,7 +69,7 @@ static void database_check(const shared_ptr<su_info> &info) {
// We need to check our manager
if
(
info
->
access
.
log
||
info
->
access
.
notify
)
validate_manager
(
info
->
str
[
SU_MANAGER
],
uid
/
100000
,
&
info
->
mgr_st
);
get_manager
(
to_user_id
(
uid
),
&
info
->
mgr_pkg
,
&
info
->
mgr_st
);
}
static
shared_ptr
<
su_info
>
get_su_info
(
unsigned
uid
)
{
...
...
@@ -93,7 +92,7 @@ static shared_ptr<su_info> get_su_info(unsigned uid) {
database_check
(
info
);
// If it's root or the manager, allow it silently
if
(
info
->
uid
==
UID_ROOT
||
(
info
->
uid
%
100000
)
==
(
info
->
mgr_st
.
st_uid
%
100000
))
{
if
(
info
->
uid
==
UID_ROOT
||
to_app_id
(
info
->
uid
)
==
to_app_id
(
info
->
mgr_st
.
st_uid
))
{
info
->
access
=
SILENT_SU_ACCESS
;
return
info
;
}
...
...
@@ -125,7 +124,7 @@ static shared_ptr<su_info> get_su_info(unsigned uid) {
return
info
;
// If still not determined, check if manager exists
if
(
info
->
str
[
SU_MANAGER
]
.
empty
())
{
if
(
info
->
mgr_pkg
.
empty
())
{
info
->
access
=
NO_SU_ACCESS
;
return
info
;
}
...
...
native/jni/utils/misc.hpp
View file @
7b25e744
...
...
@@ -12,6 +12,9 @@
clazz(const clazz &) = delete; \
clazz(clazz &&) = delete;
#define to_app_id(uid) (uid % 100000)
#define to_user_id(uid) (uid / 100000)
class
mutex_guard
{
DISALLOW_COPY_AND_MOVE
(
mutex_guard
)
public
:
...
...
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