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
bec5edca
Commit
bec5edca
authored
Jan 29, 2021
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoiding using shell I/O
parent
6fb20b3e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
192 additions
and
132 deletions
+192
-132
App.kt
app/src/main/java/com/topjohnwu/magisk/core/App.kt
+3
-2
Info.kt
app/src/main/java/com/topjohnwu/magisk/core/Info.kt
+3
-1
MagiskInstaller.kt
...n/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt
+127
-104
ShellInit.kt
...rc/main/java/com/topjohnwu/magisk/core/utils/ShellInit.kt
+46
-17
manager.sh
app/src/main/res/raw/manager.sh
+12
-7
gradle.properties
gradle.properties
+1
-1
No files found.
app/src/main/java/com/topjohnwu/magisk/core/App.kt
View file @
bec5edca
...
...
@@ -10,8 +10,9 @@ import androidx.multidex.MultiDex
import
androidx.work.WorkManager
import
com.topjohnwu.magisk.BuildConfig
import
com.topjohnwu.magisk.DynAPK
import
com.topjohnwu.magisk.core.utils.AppShellInit
import
com.topjohnwu.magisk.core.utils.BusyBoxInit
import
com.topjohnwu.magisk.core.utils.IODispatcherExecutor
import
com.topjohnwu.magisk.core.utils.RootInit
import
com.topjohnwu.magisk.core.utils.updateConfig
import
com.topjohnwu.magisk.di.koinModules
import
com.topjohnwu.magisk.ktx.unwrap
...
...
@@ -32,7 +33,7 @@ open class App() : Application() {
AppCompatDelegate
.
setCompatVectorFromResourcesEnabled
(
true
)
Shell
.
setDefaultBuilder
(
Shell
.
Builder
.
create
()
.
setFlags
(
Shell
.
FLAG_MOUNT_MASTER
)
.
setInitializers
(
Root
Init
::
class
.
java
)
.
setInitializers
(
BusyBoxInit
::
class
.
java
,
AppShell
Init
::
class
.
java
)
.
setTimeout
(
2
))
Shell
.
EXECUTOR
=
IODispatcherExecutor
()
...
...
app/src/main/java/com/topjohnwu/magisk/core/Info.kt
View file @
bec5edca
package
com.topjohnwu.magisk.core
import
android.os.Build
import
androidx.databinding.ObservableBoolean
import
com.topjohnwu.magisk.DynAPK
import
com.topjohnwu.magisk.core.model.UpdateInfo
...
...
@@ -34,9 +35,10 @@ object Info {
@JvmStatic
val
isFDE
get
()
=
crypto
==
"block"
@JvmField
var
ramdisk
=
false
@JvmField
var
hasGMS
=
true
@JvmField
va
r
isPixel
=
false
@JvmField
va
l
isPixel
=
Build
.
BRAND
==
"google"
@JvmField
val
isEmulator
=
getProperty
(
"ro.kernel.qemu"
,
"0"
)
==
"1"
var
crypto
=
""
var
noDataExec
=
false
val
isConnected
by
lazy
{
ObservableBoolean
(
false
).
also
{
field
->
...
...
app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt
View file @
bec5edca
This diff is collapsed.
Click to expand it.
app/src/main/java/com/topjohnwu/magisk/core/utils/
Root
Init.kt
→
app/src/main/java/com/topjohnwu/magisk/core/utils/
Shell
Init.kt
View file @
bec5edca
...
...
@@ -14,20 +14,19 @@ import com.topjohnwu.superuser.ShellUtils
import
java.io.File
import
java.util.jar.JarFile
class
RootInit
:
Shell
.
Initializer
()
{
override
fun
onInit
(
context
:
Context
,
shell
:
Shell
):
Boolean
{
abstract
class
BaseShellInit
:
Shell
.
Initializer
()
{
final
override
fun
onInit
(
context
:
Context
,
shell
:
Shell
):
Boolean
{
return
init
(
context
.
wrap
(),
shell
)
}
private
fun
init
(
context
:
Context
,
shell
:
Shell
):
Boolean
{
abstract
fun
init
(
context
:
Context
,
shell
:
Shell
):
Boolean
}
fun
fastCmd
(
cmd
:
String
)
=
ShellUtils
.
fastCmd
(
shell
,
cmd
)
fun
getVar
(
name
:
String
)
=
fastCmd
(
"echo \$$name"
)
fun
getBool
(
name
:
String
)
=
getVar
(
name
).
toBoolean
()
class
BusyBoxInit
:
BaseShellInit
()
{
override
fun
init
(
context
:
Context
,
shell
:
Shell
):
Boolean
{
shell
.
newJob
().
apply
{
add
(
"export SDK_INT=${Build.VERSION.SDK_INT}"
)
add
(
"export ASH_STANDALONE=1"
)
val
localBB
:
File
...
...
@@ -41,27 +40,58 @@ class RootInit : Shell.Initializer() {
localBB
=
File
(
Const
.
NATIVE_LIB_DIR
,
"libbusybox.so"
)
}
if
(!
shell
.
isRoot
)
{
// Directly execute the file
add
(
"exec $localBB sh"
)
}
else
{
// Copy it out of /data to workaround Samsung BS
if
(
shell
.
isRoot
)
{
add
(
"export MAGISKTMP=\$(magisk --path)/.magisk"
)
// Test if we can properly execute stuff in /data
Info
.
noDataExec
=
!
shell
.
newJob
().
add
(
"$localBB true"
).
exec
().
isSuccess
}
if
(
Info
.
noDataExec
)
{
// Copy it out of /data to workaround Samsung bullshit
add
(
"export MAGISKTMP=\$(magisk --path)/.magisk"
,
"if [ -x \$MAGISKTMP/busybox/busybox ]; then"
,
" cp -af $localBB \$MAGISKTMP/busybox/busybox"
,
" exec \$MAGISKTMP/busybox/busybox sh"
,
"else"
,
" exec $localBB sh"
,
" cp -af $localBB /dev/.busybox"
,
" exec /dev/.busybox sh"
,
"fi"
)
}
else
{
// Directly execute the file
add
(
"exec $localBB sh"
)
}
}.
exec
()
return
true
}
}
class
LightShellInit
:
BaseShellInit
()
{
override
fun
init
(
context
:
Context
,
shell
:
Shell
):
Boolean
{
shell
.
newJob
().
apply
{
add
(
"export SDK_INT=${Build.VERSION.SDK_INT}"
)
add
(
context
.
rawResource
(
R
.
raw
.
manager
))
}.
exec
()
return
true
}
}
class
AppShellInit
:
BaseShellInit
()
{
override
fun
init
(
context
:
Context
,
shell
:
Shell
):
Boolean
{
fun
fastCmd
(
cmd
:
String
)
=
ShellUtils
.
fastCmd
(
shell
,
cmd
)
fun
getVar
(
name
:
String
)
=
fastCmd
(
"echo \$$name"
)
fun
getBool
(
name
:
String
)
=
getVar
(
name
).
toBoolean
()
shell
.
newJob
().
apply
{
add
(
"export SDK_INT=${Build.VERSION.SDK_INT}"
)
add
(
context
.
rawResource
(
R
.
raw
.
manager
))
if
(
shell
.
isRoot
)
{
add
(
context
.
assets
.
open
(
"util_functions.sh"
))
}
add
(
"
mm
_init"
)
add
(
"
app
_init"
)
}.
exec
()
Const
.
MAGISKTMP
=
getVar
(
"MAGISKTMP"
)
...
...
@@ -69,7 +99,6 @@ class RootInit : Shell.Initializer() {
Info
.
ramdisk
=
getBool
(
"RAMDISKEXIST"
)
Info
.
isAB
=
getBool
(
"ISAB"
)
Info
.
crypto
=
getVar
(
"CRYPTOTYPE"
)
Info
.
isPixel
=
fastCmd
(
"getprop ro.product.brand"
)
==
"google"
// Default presets
Config
.
recovery
=
getBool
(
"RECOVERYMODE"
)
...
...
app/src/main/res/raw/manager.sh
View file @
bec5edca
...
...
@@ -36,7 +36,7 @@ fix_env() {
rm
-rf
$MAGISKBIN
/
*
mkdir
-p
$MAGISKBIN
2>/dev/null
chmod
700
$NVBASE
cp
-af
$1
/.
$MAGISKBIN
cp
_readlink
$1
$MAGISKBIN
rm
-rf
$1
chown
-R
0:0
$MAGISKBIN
}
...
...
@@ -57,6 +57,8 @@ direct_install() {
rm
-f
$1
/new-boot.img
fix_env
$1
run_migrations
copy_sepolicy_rules
return
0
}
...
...
@@ -87,15 +89,17 @@ restore_imgs() {
}
post_ota
()
{
cd
$1
cd
/data/adb
cp
-f
$1
bootctl
rm
-f
$1
chmod
755 bootctl
./bootctl hal-info
||
return
[
$(
./bootctl get-current-slot
)
-eq
0
]
&&
SLOT_NUM
=
1
||
SLOT_NUM
=
0
./bootctl set-active-boot-slot
$SLOT_NUM
cat
<<
EOF
> post-fs-data.d/post_ota.sh
${
1
}
/bootctl mark-boot-successful
rm -f
${
1
}
/bootctl
rm -f
${
1
}
/post-fs-data.d/post_ota.sh
/data/adb
/bootctl mark-boot-successful
rm -f
/data/adb
/bootctl
rm -f
/data/adb
/post-fs-data.d/post_ota.sh
EOF
chmod
755 post-fs-data.d/post_ota.sh
cd
/
...
...
@@ -196,8 +200,7 @@ grep_prop() { return; }
# Initialize
#############
mm_init
()
{
export
BOOTMODE
=
true
app_init
()
{
mount_partitions
get_flags
run_migrations
...
...
@@ -207,3 +210,5 @@ mm_init() {
# Make sure RECOVERYMODE has value
[
-z
$RECOVERYMODE
]
&&
RECOVERYMODE
=
false
}
export
BOOTMODE
=
true
gradle.properties
View file @
bec5edca
...
...
@@ -28,6 +28,6 @@ kapt.incremental.apt=true
# Magisk
magisk.stubVersion
=
17
magisk.versionCode
=
2140
5
magisk.versionCode
=
2140
6
magisk.ndkVersion
=
21d
magisk.fullNdkVersion
=
21.3.6528147
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