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
a29ae15f
Commit
a29ae15f
authored
May 19, 2022
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Proper get_manager implementation
parent
34dded3b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
20 deletions
+90
-20
db.cpp
native/jni/core/db.cpp
+8
-0
package.cpp
native/jni/core/package.cpp
+81
-20
db.hpp
native/jni/include/db.hpp
+1
-0
No files found.
native/jni/core/db.cpp
View file @
a29ae15f
...
@@ -359,6 +359,14 @@ int get_db_strings(db_strings &str, int key) {
...
@@ -359,6 +359,14 @@ int get_db_strings(db_strings &str, int key) {
return
0
;
return
0
;
}
}
void
rm_db_strings
(
int
key
)
{
char
*
err
;
char
query
[
128
];
snprintf
(
query
,
sizeof
(
query
),
"DELETE FROM strings WHERE key == '%s'"
,
DB_STRING_KEYS
[
key
]);
err
=
db_exec
(
query
);
db_err_cmd
(
err
,
return
);
}
void
exec_sql
(
int
client
)
{
void
exec_sql
(
int
client
)
{
run_finally
f
([
=
]{
close
(
client
);
});
run_finally
f
([
=
]{
close
(
client
);
});
string
sql
=
read_string
(
client
);
string
sql
=
read_string
(
client
);
...
...
native/jni/core/package.cpp
View file @
a29ae15f
...
@@ -62,7 +62,7 @@ vector<bool> get_app_no_list() {
...
@@ -62,7 +62,7 @@ vector<bool> get_app_no_list() {
return
list
;
return
list
;
}
}
int
get_manager
(
int
user_id
,
st
d
::
st
ring
*
pkg
)
{
int
get_manager
(
int
user_id
,
string
*
pkg
)
{
mutex_guard
g
(
pkg_lock
);
mutex_guard
g
(
pkg_lock
);
char
app_path
[
128
];
char
app_path
[
128
];
...
@@ -73,42 +73,103 @@ int get_manager(int user_id, std::string *pkg) {
...
@@ -73,42 +73,103 @@ int get_manager(int user_id, std::string *pkg) {
int
app_id
=
mgr_app_id
;
int
app_id
=
mgr_app_id
;
if
(
app_id
>
0
)
{
if
(
app_id
>
0
)
{
// Just need to check whether the app is installed in the user
// Just need to check whether the app is installed in the user
snprintf
(
app_path
,
sizeof
(
app_path
),
"%s/%d/%s"
,
APP_DATA_DIR
,
user_id
,
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
);
if
(
access
(
app_path
,
F_OK
)
==
0
)
{
if
(
access
(
app_path
,
F_OK
)
==
0
)
{
if
(
pkg
)
*
pkg
=
*
mgr_pkg
;
if
(
pkg
)
*
pkg
=
name
;
return
user_id
*
AID_USER_OFFSET
+
app_id
;
return
user_id
*
AID_USER_OFFSET
+
app_id
;
}
else
{
}
else
{
goto
not_found
;
goto
not_found
;
}
}
}
else
{
}
else
{
// Here, we want to actually find the manager app and cache the results.
// This means that we check all users, not just the requested user.
// We also do a validation on whether the repackaged APK is still installed.
db_strings
str
;
db_strings
str
;
get_db_strings
(
str
,
SU_MANAGER
);
get_db_strings
(
str
,
SU_MANAGER
);
vector
<
int
>
users
;
bool
collected
=
false
;
auto
collect_users
=
[
&
]
{
if
(
collected
)
return
;
collected
=
true
;
auto
data_dir
=
xopen_dir
(
APP_DATA_DIR
);
if
(
!
data_dir
)
return
;
dirent
*
entry
;
while
((
entry
=
xreaddir
(
data_dir
.
get
())))
{
// Only collect users not requested as we've already checked it
if
(
int
u
=
parse_int
(
entry
->
d_name
);
u
>=
0
&&
u
!=
user_id
)
users
.
push_back
(
parse_int
(
entry
->
d_name
));
}
};
if
(
!
str
[
SU_MANAGER
].
empty
())
{
if
(
!
str
[
SU_MANAGER
].
empty
())
{
// App is repackaged
// Check the repackaged package name
snprintf
(
app_path
,
sizeof
(
app_path
),
"%s/%d/%s"
,
APP_DATA_DIR
,
user_id
,
str
[
SU_MANAGER
].
data
());
auto
check_pkg
=
[
&
](
int
u
)
->
bool
{
if
(
stat
(
app_path
,
&
st
)
==
0
)
{
snprintf
(
app_path
,
sizeof
(
app_path
),
mgr_pkg
->
swap
(
str
[
SU_MANAGER
]);
"%s/%d/%s"
,
APP_DATA_DIR
,
u
,
str
[
SU_MANAGER
].
data
());
if
(
stat
(
app_path
,
&
st
)
==
0
)
{
mgr_pkg
->
swap
(
str
[
SU_MANAGER
]);
mgr_app_id
=
to_app_id
(
st
.
st_uid
);
return
true
;
}
return
false
;
};
if
(
check_pkg
(
user_id
))
{
if
(
pkg
)
*
pkg
=
*
mgr_pkg
;
return
st
.
st_uid
;
}
}
}
else
{
collect_users
();
// Check the original package name
for
(
int
u
:
users
)
{
snprintf
(
app_path
,
sizeof
(
app_path
),
"%s/%d/"
JAVA_PACKAGE_NAME
,
APP_DATA_DIR
,
user_id
);
if
(
check_pkg
(
u
))
{
// Found repackaged app, but not installed in the requested user
goto
not_found
;
}
}
// Repackaged app not found, remove package from db
rm_db_strings
(
SU_MANAGER
);
// Fallthrough
}
// Check the original package name
auto
check_pkg
=
[
&
](
int
u
)
->
bool
{
snprintf
(
app_path
,
sizeof
(
app_path
),
"%s/%d/"
JAVA_PACKAGE_NAME
,
APP_DATA_DIR
,
u
);
if
(
stat
(
app_path
,
&
st
)
==
0
)
{
if
(
stat
(
app_path
,
&
st
)
==
0
)
{
*
mgr_pkg
=
JAVA_PACKAGE_NAME
;
mgr_pkg
->
clear
();
}
else
{
mgr_app_id
=
to_app_id
(
st
.
st_uid
);
return
true
;
}
return
false
;
};
if
(
check_pkg
(
user_id
))
{
if
(
pkg
)
*
pkg
=
JAVA_PACKAGE_NAME
;
return
st
.
st_uid
;
}
collect_users
();
for
(
int
u
:
users
)
{
if
(
check_pkg
(
u
))
{
// Found app, but not installed in the requested user
goto
not_found
;
goto
not_found
;
}
}
}
}
}
mgr_app_id
=
to_app_id
(
st
.
st_uid
);
// No manager app is found, clear all cached value
if
(
pkg
)
*
pkg
=
*
mgr_pkg
;
mgr_app_id
=
-
1
;
return
st
.
st_uid
;
mgr_pkg
->
clear
();
}
not_found
:
not_found
:
LOGE
(
"su: cannot find manager
\n
"
);
LOGE
(
"su: cannot find manager for user=[%d]
\n
"
,
user_id
);
if
(
pkg
)
if
(
pkg
)
pkg
->
clear
();
pkg
->
clear
();
return
-
1
;
return
-
1
;
}
}
native/jni/include/db.hpp
View file @
a29ae15f
...
@@ -125,6 +125,7 @@ using db_row_cb = std::function<bool(db_row&)>;
...
@@ -125,6 +125,7 @@ using db_row_cb = std::function<bool(db_row&)>;
int
get_db_settings
(
db_settings
&
cfg
,
int
key
=
-
1
);
int
get_db_settings
(
db_settings
&
cfg
,
int
key
=
-
1
);
int
get_db_strings
(
db_strings
&
str
,
int
key
=
-
1
);
int
get_db_strings
(
db_strings
&
str
,
int
key
=
-
1
);
void
rm_db_strings
(
int
key
);
void
exec_sql
(
int
client
);
void
exec_sql
(
int
client
);
char
*
db_exec
(
const
char
*
sql
);
char
*
db_exec
(
const
char
*
sql
);
char
*
db_exec
(
const
char
*
sql
,
const
db_row_cb
&
fn
);
char
*
db_exec
(
const
char
*
sql
,
const
db_row_cb
&
fn
);
...
...
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