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
c10b3765
Commit
c10b3765
authored
Apr 04, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support patching full ODIN firmware
parent
ceb21ced
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
119 additions
and
62 deletions
+119
-62
Const.java
app/src/main/java/com/topjohnwu/magisk/Const.java
+1
-6
FlashActivity.java
app/src/main/java/com/topjohnwu/magisk/FlashActivity.java
+5
-5
InstallMethodDialog.java
...ava/com/topjohnwu/magisk/dialogs/InstallMethodDialog.java
+1
-1
MagiskInstaller.java
...main/java/com/topjohnwu/magisk/tasks/MagiskInstaller.java
+112
-50
No files found.
app/src/main/java/com/topjohnwu/magisk/Const.java
View file @
c10b3765
...
@@ -25,14 +25,12 @@ public class Const {
...
@@ -25,14 +25,12 @@ public class Const {
EXTERNAL_PATH
.
mkdirs
();
EXTERNAL_PATH
.
mkdirs
();
}
}
public
static
final
String
BUSYBOX_PATH
=
"/sbin/.magisk/busybox"
;
public
static
final
String
TMP_FOLDER_PATH
=
"/dev/tmp"
;
public
static
final
String
TMP_FOLDER_PATH
=
"/dev/tmp"
;
public
static
final
String
MAGISK_LOG
=
"/cache/magisk.log"
;
public
static
final
String
MAGISK_LOG
=
"/cache/magisk.log"
;
public
static
final
String
MANAGER_CONFIGS
=
".tmp.magisk.config"
;
public
static
final
String
MANAGER_CONFIGS
=
".tmp.magisk.config"
;
// Versions
// Versions
public
static
final
int
UPDATE_SERVICE_VER
=
1
;
public
static
final
int
UPDATE_SERVICE_VER
=
1
;
public
static
final
int
MIN_MODULE_VER
=
1500
;
public
static
final
int
SNET_EXT_VER
=
12
;
public
static
final
int
SNET_EXT_VER
=
12
;
public
static
final
int
USER_ID
=
Process
.
myUid
()
/
100000
;
public
static
final
int
USER_ID
=
Process
.
myUid
()
/
100000
;
...
@@ -42,10 +40,8 @@ public class Const {
...
@@ -42,10 +40,8 @@ public class Const {
}
}
public
static
class
ID
{
public
static
class
ID
{
public
static
final
int
UPDATE_SERVICE_ID
=
1
;
public
static
final
int
FETCH_ZIP
=
2
;
public
static
final
int
FETCH_ZIP
=
2
;
public
static
final
int
SELECT_BOOT
=
3
;
public
static
final
int
SELECT_BOOT
=
3
;
public
static
final
int
ONBOOT_SERVICE_ID
=
6
;
// notifications
// notifications
public
static
final
int
MAGISK_UPDATE_NOTIFICATION_ID
=
4
;
public
static
final
int
MAGISK_UPDATE_NOTIFICATION_ID
=
4
;
...
@@ -88,14 +84,13 @@ public class Const {
...
@@ -88,14 +84,13 @@ public class Const {
public
static
final
String
INTENT_SET_NAME
=
"filename"
;
public
static
final
String
INTENT_SET_NAME
=
"filename"
;
public
static
final
String
INTENT_SET_LINK
=
"link"
;
public
static
final
String
INTENT_SET_LINK
=
"link"
;
public
static
final
String
FLASH_ACTION
=
"action"
;
public
static
final
String
FLASH_ACTION
=
"action"
;
public
static
final
String
FLASH_SET_BOOT
=
"boot"
;
public
static
final
String
BROADCAST_MANAGER_UPDATE
=
"manager_update"
;
public
static
final
String
BROADCAST_MANAGER_UPDATE
=
"manager_update"
;
public
static
final
String
BROADCAST_REBOOT
=
"reboot"
;
public
static
final
String
BROADCAST_REBOOT
=
"reboot"
;
}
}
public
static
class
Value
{
public
static
class
Value
{
public
static
final
String
FLASH_ZIP
=
"flash"
;
public
static
final
String
FLASH_ZIP
=
"flash"
;
public
static
final
String
PATCH_
BOOT
=
"patch"
;
public
static
final
String
PATCH_
FILE
=
"patch"
;
public
static
final
String
FLASH_MAGISK
=
"magisk"
;
public
static
final
String
FLASH_MAGISK
=
"magisk"
;
public
static
final
String
FLASH_INACTIVE_SLOT
=
"slot"
;
public
static
final
String
FLASH_INACTIVE_SLOT
=
"slot"
;
public
static
final
String
UNINSTALL
=
"uninstall"
;
public
static
final
String
UNINSTALL
=
"uninstall"
;
...
...
app/src/main/java/com/topjohnwu/magisk/FlashActivity.java
View file @
c10b3765
...
@@ -125,8 +125,8 @@ public class FlashActivity extends BaseActivity {
...
@@ -125,8 +125,8 @@ public class FlashActivity extends BaseActivity {
case
Const
.
Value
.
FLASH_INACTIVE_SLOT
:
case
Const
.
Value
.
FLASH_INACTIVE_SLOT
:
new
SecondSlot
().
exec
();
new
SecondSlot
().
exec
();
break
;
break
;
case
Const
.
Value
.
PATCH_
BOOT
:
case
Const
.
Value
.
PATCH_
FILE
:
new
Patch
Boot
(
uri
).
exec
();
new
Patch
File
(
uri
).
exec
();
break
;
break
;
}
}
}
}
...
@@ -254,17 +254,17 @@ public class FlashActivity extends BaseActivity {
...
@@ -254,17 +254,17 @@ public class FlashActivity extends BaseActivity {
}
}
}
}
private
class
Patch
Boot
extends
BaseInstaller
{
private
class
Patch
File
extends
BaseInstaller
{
private
Uri
uri
;
private
Uri
uri
;
Patch
Boot
(
Uri
u
)
{
Patch
File
(
Uri
u
)
{
uri
=
u
;
uri
=
u
;
}
}
@Override
@Override
protected
boolean
operations
()
{
protected
boolean
operations
()
{
return
copyBoot
(
uri
)
&&
extractZip
(
)
&&
patchBoot
()
&&
storeBoot
();
return
extractZip
()
&&
handleFile
(
uri
)
&&
patchBoot
()
&&
storeBoot
();
}
}
}
}
...
...
app/src/main/java/com/topjohnwu/magisk/dialogs/InstallMethodDialog.java
View file @
c10b3765
...
@@ -59,7 +59,7 @@ class InstallMethodDialog extends AlertDialog.Builder {
...
@@ -59,7 +59,7 @@ class InstallMethodDialog extends AlertDialog.Builder {
if
(
resultCode
==
Activity
.
RESULT_OK
&&
data
!=
null
)
{
if
(
resultCode
==
Activity
.
RESULT_OK
&&
data
!=
null
)
{
Intent
i
=
new
Intent
(
activity
,
ClassMap
.
get
(
FlashActivity
.
class
))
Intent
i
=
new
Intent
(
activity
,
ClassMap
.
get
(
FlashActivity
.
class
))
.
setData
(
data
.
getData
())
.
setData
(
data
.
getData
())
.
putExtra
(
Const
.
Key
.
FLASH_ACTION
,
Const
.
Value
.
PATCH_
BOOT
);
.
putExtra
(
Const
.
Key
.
FLASH_ACTION
,
Const
.
Value
.
PATCH_
FILE
);
activity
.
startActivity
(
i
);
activity
.
startActivity
(
i
);
}
}
});
});
...
...
app/src/main/java/com/topjohnwu/magisk/tasks/MagiskInstaller.java
View file @
c10b3765
...
@@ -23,6 +23,7 @@ import com.topjohnwu.superuser.io.SuFileInputStream;
...
@@ -23,6 +23,7 @@ import com.topjohnwu.superuser.io.SuFileInputStream;
import
com.topjohnwu.superuser.io.SuFileOutputStream
;
import
com.topjohnwu.superuser.io.SuFileOutputStream
;
import
org.kamranzafar.jtar.TarEntry
;
import
org.kamranzafar.jtar.TarEntry
;
import
org.kamranzafar.jtar.TarHeader
;
import
org.kamranzafar.jtar.TarInputStream
;
import
org.kamranzafar.jtar.TarInputStream
;
import
org.kamranzafar.jtar.TarOutputStream
;
import
org.kamranzafar.jtar.TarOutputStream
;
...
@@ -30,11 +31,11 @@ import java.io.BufferedInputStream;
...
@@ -30,11 +31,11 @@ import java.io.BufferedInputStream;
import
java.io.BufferedOutputStream
;
import
java.io.BufferedOutputStream
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileInputStream
;
import
java.io.FileInputStream
;
import
java.io.FileNotFoundException
;
import
java.io.FileOutputStream
;
import
java.io.FileOutputStream
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.io.InputStream
;
import
java.io.InputStream
;
import
java.io.OutputStream
;
import
java.io.OutputStream
;
import
java.nio.ByteBuffer
;
import
java.util.Arrays
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
import
java.util.zip.ZipEntry
;
import
java.util.zip.ZipEntry
;
...
@@ -42,10 +43,13 @@ import java.util.zip.ZipInputStream;
...
@@ -42,10 +43,13 @@ import java.util.zip.ZipInputStream;
public
abstract
class
MagiskInstaller
{
public
abstract
class
MagiskInstaller
{
private
List
<
String
>
console
,
logs
;
protected
String
srcBoot
;
protected
String
srcBoot
;
protected
File
destFile
;
protected
File
installDir
;
protected
File
installDir
;
private
List
<
String
>
console
,
logs
;
private
boolean
isTar
=
false
;
private
class
ProgressLog
implements
DownloadProgressListener
{
private
class
ProgressLog
implements
DownloadProgressListener
{
private
int
prev
=
-
1
;
private
int
prev
=
-
1
;
...
@@ -166,38 +170,101 @@ public abstract class MagiskInstaller {
...
@@ -166,38 +170,101 @@ public abstract class MagiskInstaller {
}
else
{
}
else
{
init64
.
delete
();
init64
.
delete
();
}
}
Shell
.
sh
(
"cd "
+
installDir
,
"chmod 755 *"
).
exec
();
return
true
;
return
true
;
}
}
protected
boolean
copyBoot
(
Uri
bootUri
)
{
private
TarEntry
newEntry
(
String
name
,
long
size
)
{
srcBoot
=
new
File
(
installDir
,
"boot.img"
).
getPath
();
console
.
add
(
"-- Writing: "
+
name
);
console
.
add
(
"- Copying image to cache"
);
return
new
TarEntry
(
TarHeader
.
createHeader
(
name
,
size
,
0
,
false
,
0644
));
// Copy boot image to local
}
try
(
InputStream
in
=
App
.
self
.
getContentResolver
().
openInputStream
(
bootUri
);
OutputStream
out
=
new
FileOutputStream
(
srcBoot
))
{
private
void
handleTar
(
InputStream
in
)
throws
IOException
{
if
(
in
==
null
)
console
.
add
(
"- Processing tar file"
);
throw
new
FileNotFoundException
();
boolean
vbmeta
=
false
;
try
(
TarInputStream
tarIn
=
new
TarInputStream
(
in
);
InputStream
src
;
TarOutputStream
tarOut
=
new
TarOutputStream
(
destFile
))
{
if
(
Utils
.
getNameFromUri
(
App
.
self
,
bootUri
).
endsWith
(
".tar"
))
{
TarEntry
entry
;
// Extract boot.img from tar
while
((
entry
=
tarIn
.
getNextEntry
())
!=
null
)
{
TarInputStream
tar
=
new
TarInputStream
(
new
BufferedInputStream
(
in
));
if
(
entry
.
getName
().
contains
(
"boot.img"
)
TarEntry
entry
;
||
entry
.
getName
().
contains
(
"recovery.img"
))
{
while
((
entry
=
tar
.
getNextEntry
())
!=
null
)
{
String
name
=
entry
.
getName
();
if
(
entry
.
getName
().
equals
(
"boot.img"
))
console
.
add
(
"-- Extracting: "
+
name
);
break
;
File
extract
=
new
File
(
installDir
,
name
);
try
(
FileOutputStream
fout
=
new
FileOutputStream
(
extract
))
{
ShellUtils
.
pump
(
tarIn
,
fout
);
}
if
(
name
.
contains
(
".lz4"
))
{
console
.
add
(
"-- Decompressing: "
+
name
);
Shell
.
sh
(
"./magiskboot --decompress "
+
extract
).
to
(
console
).
exec
();
}
}
else
if
(
entry
.
getName
().
contains
(
"vbmeta.img"
))
{
vbmeta
=
true
;
ByteBuffer
buf
=
ByteBuffer
.
allocate
(
256
);
buf
.
put
(
"AVB0"
.
getBytes
());
// magic
buf
.
putInt
(
1
);
// required_libavb_version_major
buf
.
putInt
(
120
,
2
);
// flags
buf
.
position
(
128
);
// release_string
buf
.
put
(
"avbtool 1.1.0"
.
getBytes
());
tarOut
.
putNextEntry
(
newEntry
(
"vbmeta.img"
,
256
));
tarOut
.
write
(
buf
.
array
());
}
else
{
console
.
add
(
"-- Writing: "
+
entry
.
getName
());
tarOut
.
putNextEntry
(
entry
);
ShellUtils
.
pump
(
tarIn
,
tarOut
);
}
}
SuFile
boot
=
new
SuFile
(
installDir
,
"boot.img"
);
SuFile
recovery
=
new
SuFile
(
installDir
,
"recovery.img"
);
if
(
vbmeta
&&
recovery
.
exists
()
&&
boot
.
exists
())
{
// Install Magisk to recovery
srcBoot
=
recovery
.
getPath
();
// Repack boot image to prevent restore
Shell
.
sh
(
"./magiskboot --unpack boot.img"
,
"./magiskboot --repack boot.img"
,
"./magiskboot --cleanup"
,
"mv new-boot.img boot.img"
).
exec
();
try
(
InputStream
sin
=
new
SuFileInputStream
(
boot
))
{
tarOut
.
putNextEntry
(
newEntry
(
"boot.img"
,
boot
.
length
()));
ShellUtils
.
pump
(
sin
,
tarOut
);
}
}
src
=
tar
;
boot
.
delete
()
;
}
else
{
}
else
{
// Direct copy raw image
if
(!
boot
.
exists
())
{
src
=
new
BufferedInputStream
(
in
);
console
.
add
(
"! No boot image found"
);
throw
new
IOException
();
}
srcBoot
=
boot
.
getPath
();
}
}
}
protected
boolean
handleFile
(
Uri
uri
)
{
try
(
InputStream
in
=
new
BufferedInputStream
(
App
.
self
.
getContentResolver
().
openInputStream
(
uri
)))
{
in
.
mark
(
500
);
byte
[]
magic
=
new
byte
[
5
];
if
(
in
.
skip
(
257
)
!=
257
||
in
.
read
(
magic
)
!=
magic
.
length
)
{
console
.
add
(
"! Invalid file"
);
return
false
;
}
in
.
reset
();
if
(
Arrays
.
equals
(
magic
,
"ustar"
.
getBytes
()))
{
isTar
=
true
;
destFile
=
new
File
(
Const
.
EXTERNAL_PATH
,
"magisk_patched.tar"
);
handleTar
(
in
);
}
else
{
// Raw image
srcBoot
=
new
File
(
installDir
,
"boot.img"
).
getPath
();
destFile
=
new
File
(
Const
.
EXTERNAL_PATH
,
"magisk_patched.img"
);
console
.
add
(
"- Copying image to cache"
);
try
(
OutputStream
out
=
new
FileOutputStream
(
srcBoot
))
{
ShellUtils
.
pump
(
in
,
out
);
}
}
}
ShellUtils
.
pump
(
src
,
out
);
}
catch
(
FileNotFoundException
e
)
{
console
.
add
(
"! Invalid Uri"
);
return
false
;
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
console
.
add
(
"! Copy failed"
);
console
.
add
(
"! Process error"
);
e
.
printStackTrace
();
return
false
;
return
false
;
}
}
return
true
;
return
true
;
...
@@ -215,7 +282,7 @@ public abstract class MagiskInstaller {
...
@@ -215,7 +282,7 @@ public abstract class MagiskInstaller {
return
false
;
return
false
;
}
}
if
(!
Shell
.
sh
(
"cd "
+
installDir
,
Utils
.
fmt
(
if
(!
Shell
.
sh
(
Utils
.
fmt
(
"KEEPFORCEENCRYPT=%b KEEPVERITY=%b RECOVERYMODE=%b "
+
"KEEPFORCEENCRYPT=%b KEEPVERITY=%b RECOVERYMODE=%b "
+
"sh update-binary sh boot_patch.sh %s"
,
"sh update-binary sh boot_patch.sh %s"
,
Config
.
keepEnc
,
Config
.
keepVerity
,
Config
.
recovery
,
srcBoot
))
Config
.
keepEnc
,
Config
.
keepVerity
,
Config
.
recovery
,
srcBoot
))
...
@@ -253,35 +320,30 @@ public abstract class MagiskInstaller {
...
@@ -253,35 +320,30 @@ public abstract class MagiskInstaller {
}
}
protected
boolean
storeBoot
()
{
protected
boolean
storeBoot
()
{
File
patched
=
new
File
(
installDir
,
"new-boot.img"
);
SuFile
patched
=
new
SuFile
(
installDir
,
"new-boot.img"
);
String
fmt
=
Config
.
get
(
Config
.
Key
.
BOOT_FORMAT
);
File
dest
=
new
File
(
Const
.
EXTERNAL_PATH
,
"patched_boot"
+
fmt
);
dest
.
getParentFile
().
mkdirs
();
OutputStream
os
;
try
{
try
{
switch
(
fmt
)
{
OutputStream
os
;
case
".img.tar"
:
if
(
isTar
)
{
os
=
new
TarOutputStream
(
new
BufferedOutputStream
(
new
FileOutputStream
(
dest
)));
os
=
new
TarOutputStream
(
destFile
,
true
);
((
TarOutputStream
)
os
).
putNextEntry
(
new
TarEntry
(
patched
,
"boot.img"
));
((
TarOutputStream
)
os
).
putNextEntry
(
newEntry
(
break
;
srcBoot
.
contains
(
"recovery"
)
?
"recovery.img"
:
"boot.img"
,
default
:
patched
.
length
()));
case
".img"
:
}
else
{
os
=
new
BufferedOutputStream
(
new
FileOutputStream
(
dest
));
os
=
new
BufferedOutputStream
(
new
FileOutputStream
(
destFile
));
break
;
}
}
try
(
InputStream
in
=
new
SuFileInputStream
(
patched
)
)
{
try
(
InputStream
in
=
new
SuFileInputStream
(
patched
)
;
ShellUtils
.
pump
(
in
,
os
);
OutputStream
out
=
os
)
{
os
.
close
(
);
ShellUtils
.
pump
(
in
,
out
);
}
}
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
console
.
add
(
"! Failed to
store boot to "
+
dest
);
console
.
add
(
"! Failed to
output to "
+
destFile
);
return
false
;
e
.
printStackTrace
()
;
}
}
Shell
.
sh
(
"rm -f "
+
patched
).
exec
();
patched
.
delete
();
console
.
add
(
""
);
console
.
add
(
""
);
console
.
add
(
"****************************"
);
console
.
add
(
"****************************"
);
console
.
add
(
"
Patched imag
e is placed in "
);
console
.
add
(
"
Output fil
e is placed in "
);
console
.
add
(
" "
+
dest
+
" "
);
console
.
add
(
" "
+
dest
File
+
" "
);
console
.
add
(
"****************************"
);
console
.
add
(
"****************************"
);
return
true
;
return
true
;
}
}
...
...
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