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
74379150
Commit
74379150
authored
Feb 18, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use scripts to setup sudb
parent
c840a30c
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
37 additions
and
37 deletions
+37
-37
.gitignore
.gitignore
+1
-1
MagiskManager.java
src/main/java/com/topjohnwu/magisk/MagiskManager.java
+6
-3
HideManager.java
src/main/java/com/topjohnwu/magisk/asyncs/HideManager.java
+0
-1
SuDatabaseHelper.java
.../java/com/topjohnwu/magisk/database/SuDatabaseHelper.java
+8
-30
Utils.java
src/main/java/com/topjohnwu/magisk/utils/Utils.java
+1
-2
sudb.sh
src/main/res/raw/sudb.sh
+21
-0
No files found.
.gitignore
View file @
74379150
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
app/release
app/release
*.hprof
*.hprof
.externalNativeBuild/
.externalNativeBuild/
*.sh
src/main/assets/
*.sh
public.certificate.x509.pem
public.certificate.x509.pem
private.key.pk8
private.key.pk8
*.apk
*.apk
src/main/java/com/topjohnwu/magisk/MagiskManager.java
View file @
74379150
...
@@ -101,8 +101,10 @@ public class MagiskManager extends Shell.ContainerApp {
...
@@ -101,8 +101,10 @@ public class MagiskManager extends Shell.ContainerApp {
Shell
.
setInitializer
(
new
Shell
.
Initializer
()
{
Shell
.
setInitializer
(
new
Shell
.
Initializer
()
{
@Override
@Override
public
void
onRootShellInit
(
@NonNull
Shell
shell
)
{
public
void
onRootShellInit
(
@NonNull
Shell
shell
)
{
try
(
InputStream
in
=
MagiskManager
.
get
().
getAssets
().
open
(
Const
.
UTIL_FUNCTIONS
))
{
try
(
InputStream
utils
=
MagiskManager
.
get
().
getAssets
().
open
(
Const
.
UTIL_FUNCTIONS
);
shell
.
loadInputStream
(
null
,
null
,
in
);
InputStream
sudb
=
getResources
().
openRawResource
(
R
.
raw
.
sudb
))
{
shell
.
loadInputStream
(
null
,
null
,
utils
);
shell
.
loadInputStream
(
null
,
null
,
sudb
);
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
...
@@ -205,7 +207,8 @@ public class MagiskManager extends Shell.ContainerApp {
...
@@ -205,7 +207,8 @@ public class MagiskManager extends Shell.ContainerApp {
try
{
try
{
magiskVersionString
=
Utils
.
cmd
(
"magisk -v"
).
split
(
":"
)[
0
];
magiskVersionString
=
Utils
.
cmd
(
"magisk -v"
).
split
(
":"
)[
0
];
magiskVersionCode
=
Integer
.
parseInt
(
Utils
.
cmd
(
"magisk -V"
));
magiskVersionCode
=
Integer
.
parseInt
(
Utils
.
cmd
(
"magisk -V"
));
String
s
=
Utils
.
cmd
((
magiskVersionCode
>
1435
?
"resetprop -p "
:
"getprop "
)
+
Const
.
MAGISKHIDE_PROP
);
String
s
=
Utils
.
cmd
((
magiskVersionCode
>
1435
?
"resetprop -p "
:
"getprop "
)
+
Const
.
MAGISKHIDE_PROP
);
magiskHide
=
s
==
null
||
Integer
.
parseInt
(
s
)
!=
0
;
magiskHide
=
s
==
null
||
Integer
.
parseInt
(
s
)
!=
0
;
}
catch
(
Exception
ignored
)
{}
}
catch
(
Exception
ignored
)
{}
...
...
src/main/java/com/topjohnwu/magisk/asyncs/HideManager.java
View file @
74379150
...
@@ -136,7 +136,6 @@ public class HideManager extends ParallelTask<Void, Void, Boolean> {
...
@@ -136,7 +136,6 @@ public class HideManager extends ParallelTask<Void, Void, Boolean> {
repack
.
delete
();
repack
.
delete
();
mm
.
suDB
.
setStrings
(
Const
.
Key
.
SU_REQUESTER
,
pkg
);
mm
.
suDB
.
setStrings
(
Const
.
Key
.
SU_REQUESTER
,
pkg
);
mm
.
suDB
.
flush
();
Utils
.
dumpPrefs
();
Utils
.
dumpPrefs
();
Utils
.
uninstallPkg
(
Const
.
ORIG_PKG_NAME
);
Utils
.
uninstallPkg
(
Const
.
ORIG_PKG_NAME
);
...
...
src/main/java/com/topjohnwu/magisk/database/SuDatabaseHelper.java
View file @
74379150
...
@@ -42,22 +42,11 @@ public class SuDatabaseHelper {
...
@@ -42,22 +42,11 @@ public class SuDatabaseHelper {
return
new
SuDatabaseHelper
(
mm
);
return
new
SuDatabaseHelper
(
mm
);
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
// Let's cleanup everything and try again
// Let's cleanup everything and try again
cleanup
(
"*
"
);
Shell
.
Sync
.
su
(
"sudb_clean '*'
"
);
return
new
SuDatabaseHelper
(
mm
);
return
new
SuDatabaseHelper
(
mm
);
}
}
}
}
public
static
void
cleanup
()
{
cleanup
(
String
.
valueOf
(
Const
.
USER_ID
));
}
public
static
void
cleanup
(
String
s
)
{
Shell
.
Sync
.
su
(
"umount -l /data/user*/*/*/databases/su.db"
,
"umount -l /sbin/.core/db-"
+
s
+
"/magisk.db"
,
"rm -rf /sbin/.core/db-"
+
s
);
}
private
SuDatabaseHelper
(
MagiskManager
mm
)
{
private
SuDatabaseHelper
(
MagiskManager
mm
)
{
pm
=
mm
.
getPackageManager
();
pm
=
mm
.
getPackageManager
();
mDb
=
openDatabase
(
mm
);
mDb
=
openDatabase
(
mm
);
...
@@ -76,7 +65,7 @@ public class SuDatabaseHelper {
...
@@ -76,7 +65,7 @@ public class SuDatabaseHelper {
DB_FILE
=
new
File
(
Utils
.
fmt
(
"/sbin/.core/db-%d/magisk.db"
,
Const
.
USER_ID
));
DB_FILE
=
new
File
(
Utils
.
fmt
(
"/sbin/.core/db-%d/magisk.db"
,
Const
.
USER_ID
));
Context
de
=
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
N
Context
de
=
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
N
?
mm
.
createDeviceProtectedStorageContext
()
:
mm
;
?
mm
.
createDeviceProtectedStorageContext
()
:
mm
;
if
(!
DB_FILE
.
exists
())
{
if
(!
DB_FILE
.
canWrite
())
{
if
(!
Shell
.
rootAccess
())
{
if
(!
Shell
.
rootAccess
())
{
// We don't want the app to crash, create a db and return
// We don't want the app to crash, create a db and return
DB_FILE
=
mm
.
getDatabasePath
(
"su.db"
);
DB_FILE
=
mm
.
getDatabasePath
(
"su.db"
);
...
@@ -84,7 +73,7 @@ public class SuDatabaseHelper {
...
@@ -84,7 +73,7 @@ public class SuDatabaseHelper {
}
}
mm
.
loadMagiskInfo
();
mm
.
loadMagiskInfo
();
// Cleanup
// Cleanup
cleanup
(
);
Shell
.
Sync
.
su
(
"sudb_clean "
+
Const
.
USER_ID
);
if
(
mm
.
magiskVersionCode
<
1410
)
{
if
(
mm
.
magiskVersionCode
<
1410
)
{
// Super old legacy mode
// Super old legacy mode
DB_FILE
=
mm
.
getDatabasePath
(
"su.db"
);
DB_FILE
=
mm
.
getDatabasePath
(
"su.db"
);
...
@@ -103,19 +92,13 @@ public class SuDatabaseHelper {
...
@@ -103,19 +92,13 @@ public class SuDatabaseHelper {
// v14.5 global DB location
// v14.5 global DB location
GLOBAL_DB
=
new
File
(
de
.
getFilesDir
().
getParentFile
().
getParentFile
(),
GLOBAL_DB
=
new
File
(
de
.
getFilesDir
().
getParentFile
().
getParentFile
(),
"magisk.db"
).
getPath
();
"magisk.db"
).
getPath
();
}
if
(
mm
.
magiskVersionCode
<
1550
)
{
// We need some additional policies on old versions
// We need some additional policies on old versions
Shell
.
Sync
.
su
(
"magiskpolicy --live 'create su_file' 'allow * su_file file *'"
);
Shell
.
Sync
.
su
(
"magiskpolicy --live "
+
"'create su_file' 'allow * su_file file *' 'allow * su_file dir *'"
);
}
}
// Touch global DB and setup db in tmpfs
Shell
.
Sync
.
su
(
"sudb_setup "
+
Process
.
myUid
()
+
" "
+
GLOBAL_DB
);
Shell
.
Sync
.
su
(
Utils
.
fmt
(
"touch %s; mkdir -p %s; touch %s; touch %s-journal;"
+
"mount -o bind %s %s;"
+
"chcon u:object_r:su_file:s0 %s/*; chown %d.%d %s;"
+
"chmod 666 %s/*; chmod 700 %s;"
,
GLOBAL_DB
,
DB_FILE
.
getParent
(),
DB_FILE
,
DB_FILE
,
GLOBAL_DB
,
DB_FILE
,
DB_FILE
.
getParent
(),
Process
.
myUid
(),
Process
.
myUid
(),
DB_FILE
.
getParent
(),
DB_FILE
.
getParent
(),
DB_FILE
.
getParent
()
));
}
}
}
}
// Not using legacy mode, open the mounted global DB
// Not using legacy mode, open the mounted global DB
...
@@ -320,9 +303,4 @@ public class SuDatabaseHelper {
...
@@ -320,9 +303,4 @@ public class SuDatabaseHelper {
}
}
return
value
;
return
value
;
}
}
public
void
flush
()
{
mDb
.
close
();
mDb
=
SQLiteDatabase
.
openOrCreateDatabase
(
DB_FILE
,
null
);
}
}
}
src/main/java/com/topjohnwu/magisk/utils/Utils.java
View file @
74379150
...
@@ -50,8 +50,7 @@ public class Utils {
...
@@ -50,8 +50,7 @@ public class Utils {
}
}
public
static
void
uninstallPkg
(
String
pkg
)
{
public
static
void
uninstallPkg
(
String
pkg
)
{
SuDatabaseHelper
.
cleanup
();
Shell
.
Sync
.
su
(
"sudb_clean "
+
Const
.
USER_ID
,
"pm uninstall "
+
pkg
);
Shell
.
Sync
.
su
(
"pm uninstall "
+
pkg
);
}
}
public
static
void
dlAndReceive
(
Context
context
,
DownloadReceiver
receiver
,
String
link
,
String
filename
)
{
public
static
void
dlAndReceive
(
Context
context
,
DownloadReceiver
receiver
,
String
link
,
String
filename
)
{
...
...
src/main/res/raw/sudb.sh
0 → 100644
View file @
74379150
sudb_clean
()
{
local
USERID
=
$1
local
DIR
=
"/sbin/.core/db-
${
USERID
}
"
umount
-l
/data/user
*
/
*
/
*
/databases/su.db
$DIR
$DIR
/
*
rm
-rf
$DIR
}
sudb_setup
()
{
local
USER
=
$1
local
GLOBAL_DB
=
$2
local
USERID
=
$((
$USER
/
100000
))
local
DIR
=
/sbin/.core/db-
${
USERID
}
touch
$GLOBAL_DB
mkdir
-p
$DIR
touch
$DIR
/magisk.db
mount
-o
bind
$GLOBAL_DB
$DIR
/magisk.db
chcon
u:object_r:su_file:s0
$DIR
$DIR
/
*
chmod
700
$DIR
chown
$USER
.
$USER
$DIR
chmod
666
$DIR
/
*
}
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