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
f37e8f4c
Commit
f37e8f4c
authored
Feb 07, 2021
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix boot image patching
parent
594c2acc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
17 additions
and
48 deletions
+17
-48
MagiskInstaller.kt
...n/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt
+15
-37
ShellInit.kt
...rc/main/java/com/topjohnwu/magisk/core/utils/ShellInit.kt
+1
-11
boot_patch.sh
scripts/boot_patch.sh
+1
-0
No files found.
app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt
View file @
f37e8f4c
...
@@ -9,8 +9,6 @@ import com.topjohnwu.magisk.BuildConfig
...
@@ -9,8 +9,6 @@ import com.topjohnwu.magisk.BuildConfig
import
com.topjohnwu.magisk.DynAPK
import
com.topjohnwu.magisk.DynAPK
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.R
import
com.topjohnwu.magisk.core.*
import
com.topjohnwu.magisk.core.*
import
com.topjohnwu.magisk.core.utils.BusyBoxInit
import
com.topjohnwu.magisk.core.utils.LightShellInit
import
com.topjohnwu.magisk.core.utils.MediaStoreUtils
import
com.topjohnwu.magisk.core.utils.MediaStoreUtils
import
com.topjohnwu.magisk.core.utils.MediaStoreUtils.inputStream
import
com.topjohnwu.magisk.core.utils.MediaStoreUtils.inputStream
import
com.topjohnwu.magisk.core.utils.MediaStoreUtils.outputStream
import
com.topjohnwu.magisk.core.utils.MediaStoreUtils.outputStream
...
@@ -52,9 +50,7 @@ abstract class MagiskInstallImpl protected constructor(
...
@@ -52,9 +50,7 @@ abstract class MagiskInstallImpl protected constructor(
protected
var
installDir
=
File
(
"xxx"
)
protected
var
installDir
=
File
(
"xxx"
)
private
lateinit
var
srcBoot
:
File
private
lateinit
var
srcBoot
:
File
private
lateinit
var
shell
:
Shell
private
val
shell
=
Shell
.
getShell
()
private
var
closeShell
=
false
private
val
service
:
NetworkService
by
inject
()
private
val
service
:
NetworkService
by
inject
()
protected
val
context
:
Context
by
inject
(
Protected
)
protected
val
context
:
Context
by
inject
(
Protected
)
...
@@ -298,7 +294,7 @@ abstract class MagiskInstallImpl protected constructor(
...
@@ -298,7 +294,7 @@ abstract class MagiskInstallImpl protected constructor(
val
newBootImg
:
File
val
newBootImg
:
File
if
(
inRootDir
)
{
if
(
inRootDir
)
{
// M
igrat
e everything to tmpfs to workaround Samsung bullshit
// M
ov
e everything to tmpfs to workaround Samsung bullshit
SuFile
(
"${Const.TMPDIR}/install"
).
also
{
SuFile
(
"${Const.TMPDIR}/install"
).
also
{
arrayOf
(
arrayOf
(
"rm -rf $it"
,
"rm -rf $it"
,
...
@@ -311,8 +307,9 @@ abstract class MagiskInstallImpl protected constructor(
...
@@ -311,8 +307,9 @@ abstract class MagiskInstallImpl protected constructor(
newBootImg
=
SuFile
(
installDir
,
"new-boot.img"
)
newBootImg
=
SuFile
(
installDir
,
"new-boot.img"
)
}
else
{
}
else
{
newBootImg
=
File
(
installDir
,
"new-boot.img"
)
newBootImg
=
File
(
installDir
,
"new-boot.img"
)
// Create
the output file
before hand
// Create
output files
before hand
newBootImg
.
createNewFile
()
newBootImg
.
createNewFile
()
File
(
installDir
,
"stock_boot.img"
).
createNewFile
()
}
}
var
isSigned
=
false
var
isSigned
=
false
...
@@ -330,12 +327,14 @@ abstract class MagiskInstallImpl protected constructor(
...
@@ -330,12 +327,14 @@ abstract class MagiskInstallImpl protected constructor(
}
}
}
}
val
flags
=
val
cmds
=
arrayOf
(
"cd $installDir"
,
"KEEPFORCEENCRYPT=${Config.keepEnc} "
+
"KEEPFORCEENCRYPT=${Config.keepEnc} "
+
"KEEPVERITY=${Config.keepVerity} "
+
"KEEPVERITY=${Config.keepVerity} "
+
"RECOVERYMODE=${Config.recovery}"
"RECOVERYMODE=${Config.recovery} "
+
"sh boot_patch.sh $srcBoot"
)
if
(!
"cd $installDir; $flags sh boot_patch.sh $srcBoot"
.
sh
().
isSuccess
)
if
(!
cmds
.
sh
().
isSuccess
)
return
false
return
false
val
job
=
shell
.
newJob
().
add
(
"./magiskboot cleanup"
,
"cd /"
)
val
job
=
shell
.
newJob
().
add
(
"./magiskboot cleanup"
,
"cd /"
)
...
@@ -383,47 +382,26 @@ abstract class MagiskInstallImpl protected constructor(
...
@@ -383,47 +382,26 @@ abstract class MagiskInstallImpl protected constructor(
return
true
return
true
}
}
private
fun
setupShell
(
forceNonRoot
:
Boolean
=
false
):
Boolean
{
shell
=
Shell
.
getShell
()
if
(
forceNonRoot
&&
shell
.
isRoot
)
{
shell
=
Shell
.
Builder
.
create
()
.
setFlags
(
Shell
.
FLAG_NON_ROOT_SHELL
)
.
setInitializers
(
BusyBoxInit
::
class
.
java
,
LightShellInit
::
class
.
java
)
.
build
()
closeShell
=
true
}
return
true
}
private
fun
String
.
sh
()
=
shell
.
newJob
().
add
(
this
).
to
(
console
,
logs
).
exec
()
private
fun
String
.
sh
()
=
shell
.
newJob
().
add
(
this
).
to
(
console
,
logs
).
exec
()
private
fun
Array
<
String
>.
sh
()
=
shell
.
newJob
().
add
(*
this
).
to
(
console
,
logs
).
exec
()
private
fun
Array
<
String
>.
sh
()
=
shell
.
newJob
().
add
(*
this
).
to
(
console
,
logs
).
exec
()
private
fun
String
.
fsh
()
=
ShellUtils
.
fastCmd
(
shell
,
this
)
private
fun
String
.
fsh
()
=
ShellUtils
.
fastCmd
(
shell
,
this
)
private
fun
Array
<
String
>.
fsh
()
=
ShellUtils
.
fastCmd
(
shell
,
*
this
)
private
fun
Array
<
String
>.
fsh
()
=
ShellUtils
.
fastCmd
(
shell
,
*
this
)
protected
fun
doPatchFile
(
patchFile
:
Uri
)
=
protected
fun
doPatchFile
(
patchFile
:
Uri
)
=
extractFiles
()
&&
handleFile
(
patchFile
)
setupShell
(
true
)
&&
extractFiles
()
&&
handleFile
(
patchFile
)
protected
fun
direct
()
=
protected
fun
direct
()
=
findImage
()
&&
extractFiles
()
&&
patchBoot
()
&&
flashBoot
()
setupShell
()
&&
findImage
()
&&
extractFiles
()
&&
patchBoot
()
&&
flashBoot
()
protected
suspend
fun
secondSlot
()
=
protected
suspend
fun
secondSlot
()
=
setupShell
()
&&
findSecondary
()
&&
extractFiles
()
&&
patchBoot
()
&&
flashBoot
()
&&
postOTA
()
findSecondary
()
&&
extractFiles
()
&&
patchBoot
()
&&
flashBoot
()
&&
postOTA
()
protected
fun
fixEnv
()
=
protected
fun
fixEnv
()
=
extractFiles
()
&&
"fix_env $installDir"
.
sh
().
isSuccess
setupShell
()
&&
extractFiles
()
&&
"fix_env $installDir"
.
sh
().
isSuccess
protected
fun
uninstall
()
=
protected
fun
uninstall
()
=
"run_uninstaller ${AssetHack.apk}"
.
sh
().
isSuccess
setupShell
()
&&
"run_uninstaller ${AssetHack.apk}"
.
sh
().
isSuccess
@WorkerThread
@WorkerThread
protected
abstract
suspend
fun
operations
():
Boolean
protected
abstract
suspend
fun
operations
():
Boolean
open
suspend
fun
exec
()
=
withContext
(
Dispatchers
.
IO
)
{
open
suspend
fun
exec
()
=
withContext
(
Dispatchers
.
IO
)
{
operations
()
}
val
result
=
operations
()
if
(
closeShell
)
shell
.
close
()
result
}
}
}
abstract
class
MagiskInstaller
(
abstract
class
MagiskInstaller
(
...
...
app/src/main/java/com/topjohnwu/magisk/core/utils/ShellInit.kt
View file @
f37e8f4c
...
@@ -34,6 +34,7 @@ class BusyBoxInit : BaseShellInit() {
...
@@ -34,6 +34,7 @@ class BusyBoxInit : BaseShellInit() {
val
jar
=
JarFile
(
DynAPK
.
current
(
context
))
val
jar
=
JarFile
(
DynAPK
.
current
(
context
))
val
bb
=
jar
.
getJarEntry
(
"lib/${Const.CPU_ABI_32}/libbusybox.so"
)
val
bb
=
jar
.
getJarEntry
(
"lib/${Const.CPU_ABI_32}/libbusybox.so"
)
localBB
=
context
.
deviceProtectedContext
.
cachedFile
(
"busybox"
)
localBB
=
context
.
deviceProtectedContext
.
cachedFile
(
"busybox"
)
localBB
.
delete
()
jar
.
getInputStream
(
bb
).
writeTo
(
localBB
)
jar
.
getInputStream
(
bb
).
writeTo
(
localBB
)
localBB
.
setExecutable
(
true
)
localBB
.
setExecutable
(
true
)
}
else
{
}
else
{
...
@@ -66,17 +67,6 @@ class BusyBoxInit : BaseShellInit() {
...
@@ -66,17 +67,6 @@ class BusyBoxInit : BaseShellInit() {
}
}
}
}
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
()
{
class
AppShellInit
:
BaseShellInit
()
{
override
fun
init
(
context
:
Context
,
shell
:
Shell
):
Boolean
{
override
fun
init
(
context
:
Context
,
shell
:
Shell
):
Boolean
{
...
...
scripts/boot_patch.sh
View file @
f37e8f4c
...
@@ -123,6 +123,7 @@ case $((STATUS & 3)) in
...
@@ -123,6 +123,7 @@ case $((STATUS & 3)) in
[
-z
$SHA1
]
&&
SHA1
=
$(
./magiskboot cpio ramdisk.cpio sha1 2>/dev/null
)
[
-z
$SHA1
]
&&
SHA1
=
$(
./magiskboot cpio ramdisk.cpio sha1 2>/dev/null
)
./magiskboot cpio ramdisk.cpio restore
./magiskboot cpio ramdisk.cpio restore
cp
-af
ramdisk.cpio ramdisk.cpio.orig
cp
-af
ramdisk.cpio ramdisk.cpio.orig
rm
-f
stock_boot.img
;;
;;
2
)
# Unsupported
2
)
# Unsupported
ui_print
"! Boot image patched by unsupported programs"
ui_print
"! Boot image patched by unsupported programs"
...
...
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