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
d7d76f54
Commit
d7d76f54
authored
Jun 13, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Install stub APK when needed
parent
970a2e87
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
48 additions
and
26 deletions
+48
-26
app
app
+1
-1
bootstages.c
native/jni/core/bootstages.c
+37
-22
db.c
native/jni/core/db.c
+9
-3
db.h
native/jni/include/db.h
+1
-0
No files found.
app
@
e6c1dd53
Subproject commit
499a157946f0063aea0795b204a1f2858591d8d3
Subproject commit
e6c1dd532d2910285d503f271183839446495360
native/jni/core/bootstages.c
View file @
d7d76f54
...
...
@@ -16,6 +16,7 @@
#include <selinux/selinux.h>
#include "magisk.h"
#include "db.h"
#include "utils.h"
#include "daemon.h"
#include "resetprop.h"
...
...
@@ -454,6 +455,30 @@ static int prepare_img() {
return
0
;
}
void
install_apk
(
const
char
*
apk
)
{
setfilecon
(
apk
,
"u:object_r:"
SEPOL_FILE_DOMAIN
":s0"
);
while
(
1
)
{
sleep
(
5
);
LOGD
(
"apk_install: attempting to install APK"
);
int
apk_res
=
-
1
,
pid
;
pid
=
exec_command
(
1
,
&
apk_res
,
NULL
,
"/system/bin/pm"
,
"install"
,
"-r"
,
apk
,
NULL
);
if
(
pid
!=
-
1
)
{
int
err
=
0
;
while
(
fdgets
(
buf
,
PATH_MAX
,
apk_res
)
>
0
)
{
LOGD
(
"apk_install: %s"
,
buf
);
err
|=
strstr
(
buf
,
"Error:"
)
!=
NULL
;
}
waitpid
(
pid
,
NULL
,
0
);
close
(
apk_res
);
// Keep trying until pm is started
if
(
err
)
continue
;
break
;
}
}
unlink
(
apk
);
}
/****************
* Entry points *
****************/
...
...
@@ -806,31 +831,21 @@ void late_start(int client) {
exec_module_script
(
"service"
);
core_only:
// Install Magisk Manager if exists
if
(
access
(
MANAGERAPK
,
F_OK
)
==
0
)
{
// Install Magisk Manager if exists
rename
(
MANAGERAPK
,
"/data/magisk.apk"
);
setfilecon
(
"/data/magisk.apk"
,
"u:object_r:"
SEPOL_FILE_DOMAIN
":s0"
);
while
(
1
)
{
sleep
(
5
);
LOGD
(
"apk_install: attempting to install APK"
);
int
apk_res
=
-
1
,
pid
;
pid
=
exec_command
(
1
,
&
apk_res
,
NULL
,
"/system/bin/pm"
,
"install"
,
"-r"
,
"/data/magisk.apk"
,
NULL
);
if
(
pid
!=
-
1
)
{
int
err
=
0
;
while
(
fdgets
(
buf
,
PATH_MAX
,
apk_res
)
>
0
)
{
LOGD
(
"apk_install: %s"
,
buf
);
err
|=
strstr
(
buf
,
"Error:"
)
!=
NULL
;
}
waitpid
(
pid
,
NULL
,
0
);
close
(
apk_res
);
// Keep trying until pm is started
if
(
err
)
continue
;
break
;
}
install_apk
(
"/data/magisk.apk"
);
}
else
{
// Check whether we have a valid manager installed
sqlite3
*
db
=
get_magiskdb
();
struct
db_strings
str
;
INIT_DB_STRINGS
(
&
str
);
get_db_strings
(
db
,
SU_MANAGER
,
&
str
);
if
(
validate_manager
(
str
.
s
[
SU_MANAGER
],
0
,
NULL
))
{
// There is no manager installed, install the stub
exec_command_sync
(
"/sbin/magiskinit"
,
"-x"
,
"manager"
,
"/data/magisk.apk"
,
NULL
);
install_apk
(
"/data/magisk.apk"
);
}
unlink
(
"/data/magisk.apk"
);
}
// All boot stage done, cleanup everything
...
...
native/jni/core/db.c
View file @
d7d76f54
...
...
@@ -23,7 +23,7 @@ static int policy_cb(void *v, int col_num, char **data, char **col_name) {
else
if
(
strcmp
(
col_name
[
i
],
"notification"
)
==
0
)
su
->
notify
=
atoi
(
data
[
i
]);
}
LOGD
(
"
su_
db: query policy=[%d] log=[%d] notify=[%d]
\n
"
,
su
->
policy
,
su
->
log
,
su
->
notify
);
LOGD
(
"
magisk
db: query policy=[%d] log=[%d] notify=[%d]
\n
"
,
su
->
policy
,
su
->
log
,
su
->
notify
);
return
0
;
}
...
...
@@ -42,7 +42,7 @@ static int settings_cb(void *v, int col_num, char **data, char **col_name) {
}
if
(
key
>=
0
)
{
dbs
->
v
[
key
]
=
value
;
LOGD
(
"
su_
db: query %s=[%d]
\n
"
,
DB_SETTING_KEYS
[
key
],
value
);
LOGD
(
"
magisk
db: query %s=[%d]
\n
"
,
DB_SETTING_KEYS
[
key
],
value
);
}
return
0
;
}
...
...
@@ -63,7 +63,7 @@ static int strings_cb(void *v, int col_num, char **data, char **col_name) {
}
if
(
key
>=
0
)
{
strcpy
(
dbs
->
s
[
key
],
value
);
LOGD
(
"
su_
db: query %s=[%s]
\n
"
,
DB_STRING_KEYS
[
key
],
value
);
LOGD
(
"
magisk
db: query %s=[%s]
\n
"
,
DB_STRING_KEYS
[
key
],
value
);
}
return
0
;
}
...
...
@@ -83,6 +83,8 @@ sqlite3 *get_magiskdb() {
}
int
get_db_settings
(
sqlite3
*
db
,
int
key
,
struct
db_settings
*
dbs
)
{
if
(
db
==
NULL
)
return
1
;
char
*
err
;
if
(
key
>
0
)
{
char
query
[
128
];
...
...
@@ -99,6 +101,8 @@ int get_db_settings(sqlite3 *db, int key, struct db_settings *dbs) {
}
int
get_db_strings
(
sqlite3
*
db
,
int
key
,
struct
db_strings
*
str
)
{
if
(
db
==
NULL
)
return
1
;
char
*
err
;
if
(
key
>
0
)
{
char
query
[
128
];
...
...
@@ -115,6 +119,8 @@ int get_db_strings(sqlite3 *db, int key, struct db_strings *str) {
}
int
get_uid_policy
(
sqlite3
*
db
,
int
uid
,
struct
su_access
*
su
)
{
if
(
db
==
NULL
)
return
1
;
char
query
[
256
],
*
err
;
sprintf
(
query
,
"SELECT policy, logging, notification FROM policies "
"WHERE uid=%d AND (until=0 OR until>%li)"
,
uid
,
time
(
NULL
));
...
...
native/jni/include/db.h
View file @
d7d76f54
...
...
@@ -2,6 +2,7 @@
#define DB_H
#include <sqlite3.h>
#include <sys/stat.h>
/***************
* DB Settings *
...
...
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