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
e92d77bb
Commit
e92d77bb
authored
Jan 25, 2021
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some optimizations
parent
07bd36c9
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
42 deletions
+44
-42
MagiskInstaller.kt
...n/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt
+43
-41
gradle.properties
gradle.properties
+1
-1
No files found.
app/src/main/java/com/topjohnwu/magisk/core/tasks/MagiskInstaller.kt
View file @
e92d77bb
...
@@ -52,19 +52,20 @@ abstract class MagiskInstallImpl protected constructor(
...
@@ -52,19 +52,20 @@ abstract class MagiskInstallImpl protected constructor(
)
:
KoinComponent
{
)
:
KoinComponent
{
protected
lateinit
var
installDir
:
File
protected
lateinit
var
installDir
:
File
private
lateinit
var
srcBoot
:
String
private
lateinit
var
srcBoot
:
File
private
var
tarOut
:
TarOutputStream
?
=
null
private
var
tarOut
:
TarOutputStream
?
=
null
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
)
private
fun
findImage
():
Boolean
{
private
fun
findImage
():
Boolean
{
srcBoot
=
"find_boot_image; echo \"\$BOOTIMAGE\""
.
fsh
()
val
bootPath
=
"find_boot_image; echo \"\$BOOTIMAGE\""
.
fsh
()
if
(
srcBoot
.
isEmpty
())
{
if
(
bootPath
.
isEmpty
())
{
console
.
add
(
"! Unable to detect target image"
)
console
.
add
(
"! Unable to detect target image"
)
return
false
return
false
}
}
console
.
add
(
"- Target image: $srcBoot"
)
srcBoot
=
SuFile
(
bootPath
)
console
.
add
(
"- Target image: $bootPath"
)
return
true
return
true
}
}
...
@@ -72,16 +73,17 @@ abstract class MagiskInstallImpl protected constructor(
...
@@ -72,16 +73,17 @@ abstract class MagiskInstallImpl protected constructor(
val
slot
=
"echo \$SLOT"
.
fsh
()
val
slot
=
"echo \$SLOT"
.
fsh
()
val
target
=
if
(
slot
==
"_a"
)
"_b"
else
"_a"
val
target
=
if
(
slot
==
"_a"
)
"_b"
else
"_a"
console
.
add
(
"- Target slot: $target"
)
console
.
add
(
"- Target slot: $target"
)
srcBoot
=
arrayOf
(
val
bootPath
=
arrayOf
(
"SLOT=$target"
,
"SLOT=$target"
,
"find_boot_image"
,
"find_boot_image"
,
"SLOT=$slot"
,
"SLOT=$slot"
,
"echo \"\$BOOTIMAGE\""
).
fsh
()
"echo \"\$BOOTIMAGE\""
).
fsh
()
if
(
srcBoot
.
isEmpty
())
{
if
(
bootPath
.
isEmpty
())
{
console
.
add
(
"! Unable to detect target image"
)
console
.
add
(
"! Unable to detect target image"
)
return
false
return
false
}
}
console
.
add
(
"- Target image: $srcBoot"
)
srcBoot
=
SuFile
(
bootPath
)
console
.
add
(
"- Target image: $bootPath"
)
return
true
return
true
}
}
...
@@ -213,11 +215,12 @@ abstract class MagiskInstallImpl protected constructor(
...
@@ -213,11 +215,12 @@ abstract class MagiskInstallImpl protected constructor(
tarIn
.
copyTo
(
tarOut
,
bufferSize
=
1024
*
1024
)
tarIn
.
copyTo
(
tarOut
,
bufferSize
=
1024
*
1024
)
}
}
}
}
}
val
boot
=
installDirFile
(
"boot.img"
)
val
boot
=
installDirFile
(
"boot.img"
)
val
recovery
=
installDirFile
(
"recovery.img"
)
val
recovery
=
installDirFile
(
"recovery.img"
)
if
(
Config
.
recovery
&&
recovery
.
exists
()
&&
boot
.
exists
())
{
if
(
Config
.
recovery
&&
recovery
.
exists
()
&&
boot
.
exists
())
{
// Install Magisk to recovery
// Install Magisk to recovery
srcBoot
=
recovery
.
path
srcBoot
=
recovery
// Repack boot image to prevent restore
// Repack boot image to prevent restore
arrayOf
(
arrayOf
(
"./magiskboot unpack boot.img"
,
"./magiskboot unpack boot.img"
,
...
@@ -234,8 +237,7 @@ abstract class MagiskInstallImpl protected constructor(
...
@@ -234,8 +237,7 @@ abstract class MagiskInstallImpl protected constructor(
console
.
add
(
"! No boot image found"
)
console
.
add
(
"! No boot image found"
)
throw
IOException
()
throw
IOException
()
}
}
srcBoot
=
boot
.
path
srcBoot
=
boot
}
}
}
return
tarOut
return
tarOut
}
}
...
@@ -258,21 +260,21 @@ abstract class MagiskInstallImpl protected constructor(
...
@@ -258,21 +260,21 @@ abstract class MagiskInstallImpl protected constructor(
val
alpha
=
"abcdefghijklmnopqrstuvwxyz"
val
alpha
=
"abcdefghijklmnopqrstuvwxyz"
val
alphaNum
=
"$alpha${alpha.toUpperCase(Locale.ROOT)}0123456789"
val
alphaNum
=
"$alpha${alpha.toUpperCase(Locale.ROOT)}0123456789"
val
random
=
SecureRandom
()
val
random
=
SecureRandom
()
val
suffix
=
StringBuilder
()
val
filename
=
StringBuilder
(
"magisk_patched_"
).
run
{
for
(
i
in
1
..
5
)
{
for
(
i
in
1
..
5
)
{
suffix
.
append
(
alphaNum
[
random
.
nextInt
(
alphaNum
.
length
)])
append
(
alphaNum
[
random
.
nextInt
(
alphaNum
.
length
)])
}
toString
()
}
}
val
filename
=
"magisk_patched_$suffix"
outStream
=
if
(
magic
.
contentEquals
(
"ustar"
.
toByteArray
()))
{
outStream
=
if
(
magic
.
contentEquals
(
"ustar"
.
toByteArray
()))
{
outFile
=
MediaStoreUtils
.
getFile
(
"$filename.tar"
,
true
)
outFile
=
MediaStoreUtils
.
getFile
(
"$filename.tar"
,
true
)
handleTar
(
src
,
outFile
!!
.
uri
.
outputStream
())
handleTar
(
src
,
outFile
!!
.
uri
.
outputStream
())
}
else
{
}
else
{
// Raw image
// Raw image
val
image
=
installDirFile
(
"boot.img"
)
srcBoot
=
installDirFile
(
"boot.img"
)
srcBoot
=
image
.
path
console
.
add
(
"- Copying image to cache"
)
console
.
add
(
"- Copying image to cache"
)
SuFileOutputStream
(
image
).
use
{
src
.
copyTo
(
it
)
}
SuFileOutputStream
(
srcBoot
).
use
{
src
.
copyTo
(
it
)
}
outFile
=
MediaStoreUtils
.
getFile
(
"$filename.img"
,
true
)
outFile
=
MediaStoreUtils
.
getFile
(
"$filename.img"
,
true
)
outFile
!!
.
uri
.
outputStream
()
outFile
!!
.
uri
.
outputStream
()
}
}
...
@@ -292,9 +294,9 @@ abstract class MagiskInstallImpl protected constructor(
...
@@ -292,9 +294,9 @@ abstract class MagiskInstallImpl protected constructor(
// Output file
// Output file
try
{
try
{
val
patched
=
SuFile
.
open
(
installDir
,
"new-boot.img"
)
val
patched
=
installDirFile
(
"new-boot.img"
)
if
(
outStream
is
TarOutputStream
)
{
if
(
outStream
is
TarOutputStream
)
{
val
name
=
if
(
srcBoot
.
contains
(
"recovery"
))
"recovery.img"
else
"boot.img"
val
name
=
if
(
srcBoot
.
path
.
contains
(
"recovery"
))
"recovery.img"
else
"boot.img"
outStream
.
putNextEntry
(
newEntry
(
name
,
patched
.
length
()))
outStream
.
putNextEntry
(
newEntry
(
name
,
patched
.
length
()))
}
}
withStreams
(
SuFileInputStream
(
patched
),
outStream
)
{
src
,
out
->
src
.
copyTo
(
out
)
}
withStreams
(
SuFileInputStream
(
patched
),
outStream
)
{
src
,
out
->
src
.
copyTo
(
out
)
}
...
@@ -325,10 +327,10 @@ abstract class MagiskInstallImpl protected constructor(
...
@@ -325,10 +327,10 @@ abstract class MagiskInstallImpl protected constructor(
private
fun
patchBoot
():
Boolean
{
private
fun
patchBoot
():
Boolean
{
"cd $installDir"
.
sh
()
"cd $installDir"
.
sh
()
var
srcNand
=
""
var
srcNand
:
File
?
=
null
if
(
"[ -c $srcBoot ] && nanddump -f boot.img $srcBoot"
.
sh
().
isSuccess
)
{
if
(
"[ -c $srcBoot ] && nanddump -f boot.img $srcBoot"
.
sh
().
isSuccess
)
{
srcNand
=
srcBoot
srcNand
=
srcBoot
srcBoot
=
File
(
installDir
,
"boot.img"
).
path
srcBoot
=
installDirFile
(
"boot.img"
)
}
}
var
isSigned
:
Boolean
var
isSigned
:
Boolean
...
@@ -352,7 +354,7 @@ abstract class MagiskInstallImpl protected constructor(
...
@@ -352,7 +354,7 @@ abstract class MagiskInstallImpl protected constructor(
if
(!
"$FLAGS sh boot_patch.sh $srcBoot"
.
sh
().
isSuccess
)
if
(!
"$FLAGS sh boot_patch.sh $srcBoot"
.
sh
().
isSuccess
)
return
false
return
false
if
(
srcNand
.
isNotEmpty
()
)
if
(
srcNand
!=
null
)
srcBoot
=
srcNand
srcBoot
=
srcNand
val
job
=
Shell
.
sh
(
"./magiskboot cleanup"
,
"cd /"
)
val
job
=
Shell
.
sh
(
"./magiskboot cleanup"
,
"cd /"
)
...
...
gradle.properties
View file @
e92d77bb
...
@@ -28,6 +28,6 @@ kapt.incremental.apt=true
...
@@ -28,6 +28,6 @@ kapt.incremental.apt=true
# Magisk
# Magisk
magisk.stubVersion
=
16
magisk.stubVersion
=
16
magisk.versionCode
=
2140
4
magisk.versionCode
=
2140
5
magisk.ndkVersion
=
21d
magisk.ndkVersion
=
21d
magisk.fullNdkVersion
=
21.3.6528147
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