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
63b18246
Commit
63b18246
authored
Feb 25, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add compressed ramdisk support
parent
16ec37a2
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
63 additions
and
14 deletions
+63
-14
MagiskInstaller.java
...main/java/com/topjohnwu/magisk/tasks/MagiskInstaller.java
+2
-1
init.cpp
native/jni/core/init.cpp
+21
-1
ramdisk.cpp
native/jni/magiskboot/ramdisk.cpp
+17
-6
OutStream.h
native/jni/utils/include/OutStream.h
+2
-0
boot_patch.sh
scripts/boot_patch.sh
+9
-2
flash_script.sh
scripts/flash_script.sh
+9
-1
util_functions.sh
scripts/util_functions.sh
+3
-3
No files found.
app-core/src/main/java/com/topjohnwu/magisk/tasks/MagiskInstaller.java
View file @
63b18246
...
@@ -222,7 +222,8 @@ public abstract class MagiskInstaller {
...
@@ -222,7 +222,8 @@ public abstract class MagiskInstaller {
Config
.
keepEnc
,
Config
.
keepVerity
,
srcBoot
)).
to
(
console
,
logs
).
exec
().
isSuccess
())
Config
.
keepEnc
,
Config
.
keepVerity
,
srcBoot
)).
to
(
console
,
logs
).
exec
().
isSuccess
())
return
false
;
return
false
;
job
=
Shell
.
sh
(
"mv bin/busybox busybox"
,
job
=
Shell
.
sh
(
"./magiskboot --cleanup"
,
"mv bin/busybox busybox"
,
"rm -rf magisk.apk bin boot.img update-binary"
,
"rm -rf magisk.apk bin boot.img update-binary"
,
"cd /"
);
"cd /"
);
...
...
native/jni/core/init.cpp
View file @
63b18246
...
@@ -30,7 +30,6 @@
...
@@ -30,7 +30,6 @@
#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/mount.h>
#include <sys/mount.h>
#include <sys/mman.h>
#include <sys/sendfile.h>
#include <sys/sendfile.h>
#include <sys/sysmacros.h>
#include <sys/sysmacros.h>
#include <functional>
#include <functional>
...
@@ -40,6 +39,7 @@
...
@@ -40,6 +39,7 @@
#include <magisk.h>
#include <magisk.h>
#include <magiskpolicy.h>
#include <magiskpolicy.h>
#include <selinux.h>
#include <selinux.h>
#include <cpio.h>
#include <utils.h>
#include <utils.h>
#include <flags.h>
#include <flags.h>
...
@@ -320,6 +320,24 @@ static bool unxz(int fd, const uint8_t *buf, size_t size) {
...
@@ -320,6 +320,24 @@ static bool unxz(int fd, const uint8_t *buf, size_t size) {
return
true
;
return
true
;
}
}
static
void
decompress_ramdisk
()
{
constexpr
char
tmp
[]
=
"tmp.cpio"
;
constexpr
char
ramdisk_xz
[]
=
"ramdisk.cpio.xz"
;
if
(
access
(
ramdisk_xz
,
F_OK
))
return
;
uint8_t
*
buf
;
size_t
sz
;
mmap_ro
(
ramdisk_xz
,
(
void
**
)
&
buf
,
&
sz
);
int
fd
=
open
(
tmp
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
|
O_CLOEXEC
);
unxz
(
fd
,
buf
,
sz
);
munmap
(
buf
,
sz
);
close
(
fd
);
cpio_mmap
cpio
(
tmp
);
cpio
.
extract
();
unlink
(
tmp
);
unlink
(
ramdisk_xz
);
}
static
int
dump_magisk
(
const
char
*
path
,
mode_t
mode
)
{
static
int
dump_magisk
(
const
char
*
path
,
mode_t
mode
)
{
int
fd
=
open
(
path
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
|
O_CLOEXEC
,
mode
);
int
fd
=
open
(
path
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
|
O_CLOEXEC
,
mode
);
if
(
fd
<
0
)
if
(
fd
<
0
)
...
@@ -496,6 +514,8 @@ int main(int argc, char *argv[]) {
...
@@ -496,6 +514,8 @@ int main(int argc, char *argv[]) {
frm_rf
(
root
);
frm_rf
(
root
);
excl_list
=
nullptr
;
excl_list
=
nullptr
;
}
else
{
}
else
{
decompress_ramdisk
();
// Revert original init binary
// Revert original init binary
rename
(
"/.backup/init"
,
"/init"
);
rename
(
"/.backup/init"
,
"/init"
);
rm_rf
(
"/.backup"
);
rm_rf
(
"/.backup"
);
...
...
native/jni/magiskboot/ramdisk.cpp
View file @
63b18246
...
@@ -18,7 +18,7 @@ static const char *UNSUPPORT_LIST[] =
...
@@ -18,7 +18,7 @@ static const char *UNSUPPORT_LIST[] =
static
const
char
*
MAGISK_LIST
[]
=
static
const
char
*
MAGISK_LIST
[]
=
{
".backup/.magisk"
,
"init.magisk.rc"
,
{
".backup/.magisk"
,
"init.magisk.rc"
,
"overlay/init.magisk.rc"
,
ramdisk_xz
};
"overlay/init.magisk.rc"
};
class
magisk_cpio
:
public
cpio_rw
{
class
magisk_cpio
:
public
cpio_rw
{
public
:
public
:
...
@@ -59,17 +59,21 @@ void magisk_cpio::patch(bool keepverity, bool keepforceencrypt) {
...
@@ -59,17 +59,21 @@ void magisk_cpio::patch(bool keepverity, bool keepforceencrypt) {
}
}
}
}
#define STOCK_BOOT 0x0
#define STOCK_BOOT 0
#define MAGISK_PATCH 0x1
#define MAGISK_PATCHED 1 << 0
#define UNSUPPORT_PATCH 0x2
#define UNSUPPORTED_CPIO 1 << 1
#define COMPRESSED_CPIO 1 << 2
int
magisk_cpio
::
test
()
{
int
magisk_cpio
::
test
()
{
if
(
exists
(
ramdisk_xz
))
return
MAGISK_PATCHED
|
COMPRESSED_CPIO
;
for
(
auto
file
:
UNSUPPORT_LIST
)
for
(
auto
file
:
UNSUPPORT_LIST
)
if
(
exists
(
file
))
if
(
exists
(
file
))
return
UNSUPPORT
_PATCH
;
return
UNSUPPORT
ED_CPIO
;
for
(
auto
file
:
MAGISK_LIST
)
for
(
auto
file
:
MAGISK_LIST
)
if
(
exists
(
file
))
if
(
exists
(
file
))
return
MAGISK_PATCH
;
return
MAGISK_PATCH
ED
;
return
STOCK_BOOT
;
return
STOCK_BOOT
;
}
}
...
@@ -108,6 +112,7 @@ char *magisk_cpio::sha1() {
...
@@ -108,6 +112,7 @@ char *magisk_cpio::sha1() {
for (str = (char *) buf; str < (char *) buf + size; str = str += strlen(str) + 1)
for (str = (char *) buf; str < (char *) buf + size; str = str += strlen(str) + 1)
void
magisk_cpio
::
restore
()
{
void
magisk_cpio
::
restore
()
{
decompress
();
char
*
file
;
char
*
file
;
auto
next
=
entries
.
begin
();
auto
next
=
entries
.
begin
();
decltype
(
next
)
cur
;
decltype
(
next
)
cur
;
...
@@ -218,8 +223,12 @@ void magisk_cpio::compress() {
...
@@ -218,8 +223,12 @@ void magisk_cpio::compress() {
encoder
.
set_out
(
make_unique
<
BufOutStream
>
());
encoder
.
set_out
(
make_unique
<
BufOutStream
>
());
output
(
encoder
);
output
(
encoder
);
encoder
.
finalize
();
encoder
.
finalize
();
auto
backup
=
entries
.
extract
(
".backup"
);
auto
config
=
entries
.
extract
(
".backup/.magisk"
);
entries
.
clear
();
entries
.
clear
();
entries
.
insert
(
std
::
move
(
init
));
entries
.
insert
(
std
::
move
(
init
));
entries
.
insert
(
std
::
move
(
backup
));
entries
.
insert
(
std
::
move
(
config
));
auto
xz
=
new
cpio_entry
(
ramdisk_xz
,
S_IFREG
);
auto
xz
=
new
cpio_entry
(
ramdisk_xz
,
S_IFREG
);
static_cast
<
BufOutStream
*>
(
encoder
.
get_out
())
->
release
(
xz
->
data
,
xz
->
filesize
);
static_cast
<
BufOutStream
*>
(
encoder
.
get_out
())
->
release
(
xz
->
data
,
xz
->
filesize
);
insert
(
xz
);
insert
(
xz
);
...
@@ -230,6 +239,8 @@ void magisk_cpio::decompress() {
...
@@ -230,6 +239,8 @@ void magisk_cpio::decompress() {
if
(
it
==
entries
.
end
())
if
(
it
==
entries
.
end
())
return
;
return
;
fprintf
(
stderr
,
"Decompressing cpio [%s]
\n
"
,
ramdisk_xz
);
fprintf
(
stderr
,
"Decompressing cpio [%s]
\n
"
,
ramdisk_xz
);
entries
.
erase
(
".backup"
);
entries
.
erase
(
".backup/.magisk"
);
LZMADecoder
decoder
;
LZMADecoder
decoder
;
decoder
.
set_out
(
make_unique
<
BufOutStream
>
());
decoder
.
set_out
(
make_unique
<
BufOutStream
>
());
decoder
.
write
(
it
->
second
->
data
,
it
->
second
->
filesize
);
decoder
.
write
(
it
->
second
->
data
,
it
->
second
->
filesize
);
...
...
native/jni/utils/include/OutStream.h
View file @
63b18246
...
@@ -3,6 +3,8 @@
...
@@ -3,6 +3,8 @@
#include <unistd.h>
#include <unistd.h>
#include <memory>
#include <memory>
#include "utils.h"
class
OutStream
{
class
OutStream
{
public
:
public
:
virtual
bool
write
(
const
void
*
buf
,
size_t
len
)
=
0
;
virtual
bool
write
(
const
void
*
buf
,
size_t
len
)
=
0
;
...
...
scripts/boot_patch.sh
View file @
63b18246
...
@@ -90,7 +90,8 @@ esac
...
@@ -90,7 +90,8 @@ esac
# Test patch status and do restore, after this section, ramdisk.cpio.orig is guaranteed to exist
# Test patch status and do restore, after this section, ramdisk.cpio.orig is guaranteed to exist
ui_print
"- Checking ramdisk status"
ui_print
"- Checking ramdisk status"
./magiskboot
--cpio
ramdisk.cpio
test
./magiskboot
--cpio
ramdisk.cpio
test
case
$?
in
STATUS
=
$?
case
$((
STATUS
&
3
))
in
0
)
# Stock boot
0
)
# Stock boot
ui_print
"- Stock boot image detected"
ui_print
"- Stock boot image detected"
ui_print
"- Backing up stock boot image"
ui_print
"- Backing up stock boot image"
...
@@ -128,6 +129,11 @@ echo "KEEPFORCEENCRYPT=$KEEPFORCEENCRYPT" >> config
...
@@ -128,6 +129,11 @@ echo "KEEPFORCEENCRYPT=$KEEPFORCEENCRYPT" >> config
"backup ramdisk.cpio.orig"
\
"backup ramdisk.cpio.orig"
\
"add 000 .backup/.magisk config"
"add 000 .backup/.magisk config"
if
[
$((
STATUS
&
4
))
-ne
0
]
;
then
ui_print
"- Compressing ramdisk"
./magiskboot
--cpio
ramdisk.cpio compress
fi
rm
-f
ramdisk.cpio.orig config
rm
-f
ramdisk.cpio.orig config
##########################################################################################
##########################################################################################
...
@@ -167,4 +173,5 @@ ui_print "- Repacking boot image"
...
@@ -167,4 +173,5 @@ ui_print "- Repacking boot image"
# Sign chromeos boot
# Sign chromeos boot
$CHROMEOS
&&
sign_chromeos
$CHROMEOS
&&
sign_chromeos
./magiskboot
--cleanup
# Reset any error code
true
scripts/flash_script.sh
View file @
63b18246
...
@@ -106,7 +106,15 @@ $IS64BIT && mv -f magiskinit64 magiskinit || rm -f magiskinit64
...
@@ -106,7 +106,15 @@ $IS64BIT && mv -f magiskinit64 magiskinit || rm -f magiskinit64
.
./boot_patch.sh
"
$BOOTIMAGE
"
.
./boot_patch.sh
"
$BOOTIMAGE
"
ui_print
"- Flashing new boot image"
ui_print
"- Flashing new boot image"
flash_image new-boot.img
"
$BOOTIMAGE
"
||
abort
"! Insufficient partition size"
if
!
flash_image new-boot.img
"
$BOOTIMAGE
"
;
then
ui_print
"- Compressing ramdisk to fit in partition"
./magiskboot
--cpio
ramdisk.cpio compress
./magiskboot
--repack
"
$BOOTIMAGE
"
flash_image new-boot.img
"
$BOOTIMAGE
"
||
abort
"! Insufficient partition size"
fi
./magiskboot
--cleanup
rm
-f
new-boot.img
rm
-f
new-boot.img
if
[
-f
stock_boot
*
]
;
then
if
[
-f
stock_boot
*
]
;
then
...
...
scripts/util_functions.sh
View file @
63b18246
...
@@ -256,9 +256,9 @@ flash_image() {
...
@@ -256,9 +256,9 @@ flash_image() {
CMD2
=
"cat -"
CMD2
=
"cat -"
fi
fi
if
[
-b
"
$2
"
]
;
then
if
[
-b
"
$2
"
]
;
then
local
s_size
=
`
stat
-c
'%s'
"
$1
"
`
local
img_sz
=
`
stat
-c
'%s'
"
$1
"
`
local
t_size
=
`
blockdev
--getsize64
"
$2
"
`
local
blk_sz
=
`
blockdev
--getsize64
"
$2
"
`
[
$
s_size
-gt
$t_size
]
&&
return
1
[
$
img_sz
-gt
$blk_sz
]
&&
return
1
eval
$CMD1
|
eval
$CMD2
|
cat
- /dev/zero
>
"
$2
"
2>/dev/null
eval
$CMD1
|
eval
$CMD2
|
cat
- /dev/zero
>
"
$2
"
2>/dev/null
else
else
ui_print
"- Not block device, storing image"
ui_print
"- Not block device, storing image"
...
...
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