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
6add6827
Commit
6add6827
authored
Aug 09, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove high compression mode
parent
8b50d84a
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
72 additions
and
207 deletions
+72
-207
build.py
build.py
+15
-15
Android.mk
native/jni/Android.mk
+1
-1
magiskinit.c
native/jni/core/magiskinit.c
+6
-53
utils.h
native/jni/include/utils.h
+2
-2
bootimg.c
native/jni/magiskboot/bootimg.c
+5
-8
main.c
native/jni/magiskboot/main.c
+9
-14
ramdisk.c
native/jni/magiskboot/ramdisk.c
+10
-68
file.c
native/jni/utils/file.c
+5
-6
boot_patch.sh
scripts/boot_patch.sh
+13
-32
magisk_uninstaller.sh
scripts/magisk_uninstaller.sh
+6
-8
No files found.
build.py
View file @
6add6827
...
@@ -134,9 +134,9 @@ def build_binary(args):
...
@@ -134,9 +134,9 @@ def build_binary(args):
# Dump the binary to header
# Dump the binary to header
for
arch
in
archs
:
for
arch
in
archs
:
bin_file
=
os
.
path
.
join
(
'native'
,
'out'
,
arch
,
'magisk'
)
bin_file
=
os
.
path
.
join
(
'native'
,
'out'
,
arch
,
'magisk'
)
with
open
(
os
.
path
.
join
(
'native'
,
'out'
,
arch
,
'binaries_arch
_xz
.h'
),
'w'
)
as
out
:
with
open
(
os
.
path
.
join
(
'native'
,
'out'
,
arch
,
'binaries_arch.h'
),
'w'
)
as
out
:
with
open
(
bin_file
,
'rb'
)
as
src
:
with
open
(
bin_file
,
'rb'
)
as
src
:
xz_dump
(
src
,
out
,
'magisk_xz
'
)
binary_dump
(
src
,
out
,
'magisk_bin
'
)
old_plat
=
False
old_plat
=
False
flags
=
base_flags
flags
=
base_flags
...
@@ -146,9 +146,9 @@ def build_binary(args):
...
@@ -146,9 +146,9 @@ def build_binary(args):
old_plat
=
True
old_plat
=
True
if
'magiskinit'
in
targets
:
if
'magiskinit'
in
targets
:
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
'native'
,
'out'
,
'x86'
,
'binaries_arch
_xz
.h'
)):
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
'native'
,
'out'
,
'x86'
,
'binaries_arch.h'
)):
error
(
'Build "magisk" before building "magiskinit"'
)
error
(
'Build "magisk" before building "magiskinit"'
)
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
'native'
,
'out'
,
'binaries
_xz
.h'
)):
if
not
os
.
path
.
exists
(
os
.
path
.
join
(
'native'
,
'out'
,
'binaries.h'
)):
error
(
'Build release stub APK before building "magiskinit"'
)
error
(
'Build release stub APK before building "magiskinit"'
)
flags
+=
' B_INIT=1'
flags
+=
' B_INIT=1'
old_plat
=
True
old_plat
=
True
...
@@ -219,6 +219,15 @@ def sign_apk(source, target):
...
@@ -219,6 +219,15 @@ def sign_apk(source, target):
if
proc
.
returncode
!=
0
:
if
proc
.
returncode
!=
0
:
error
(
'Release sign Magisk Manager failed!'
)
error
(
'Release sign Magisk Manager failed!'
)
def
binary_dump
(
src
,
out
,
var_name
):
out
.
write
(
'const static unsigned char {}[] = {{'
.
format
(
var_name
))
for
i
,
c
in
enumerate
(
src
.
read
()):
if
i
%
16
==
0
:
out
.
write
(
'
\n
'
)
out
.
write
(
'0x{:02X},'
.
format
(
c
))
out
.
write
(
'
\n
};
\n
'
)
out
.
flush
()
def
build_apk
(
args
):
def
build_apk
(
args
):
header
(
'* Building Magisk Manager'
)
header
(
'* Building Magisk Manager'
)
...
@@ -244,9 +253,9 @@ def build_apk(args):
...
@@ -244,9 +253,9 @@ def build_apk(args):
rm
(
unsigned
)
rm
(
unsigned
)
# Dump the stub APK to header
# Dump the stub APK to header
mkdir
(
os
.
path
.
join
(
'native'
,
'out'
))
mkdir
(
os
.
path
.
join
(
'native'
,
'out'
))
with
open
(
os
.
path
.
join
(
'native'
,
'out'
,
'binaries
_xz
.h'
),
'w'
)
as
out
:
with
open
(
os
.
path
.
join
(
'native'
,
'out'
,
'binaries.h'
),
'w'
)
as
out
:
with
open
(
release
,
'rb'
)
as
src
:
with
open
(
release
,
'rb'
)
as
src
:
xz_dump
(
src
,
out
,
'manager_xz'
)
binary_dump
(
src
,
out
,
'manager_bin'
);
else
:
else
:
proc
=
execv
([
gradlew
,
'app:assembleDebug'
])
proc
=
execv
([
gradlew
,
'app:assembleDebug'
])
if
proc
.
returncode
!=
0
:
if
proc
.
returncode
!=
0
:
...
@@ -276,15 +285,6 @@ def build_snet(args):
...
@@ -276,15 +285,6 @@ def build_snet(args):
rm
(
source
)
rm
(
source
)
header
(
'Output: '
+
target
)
header
(
'Output: '
+
target
)
def
xz_dump
(
src
,
out
,
var_name
):
out
.
write
(
'const static unsigned char {}[] = {{'
.
format
(
var_name
))
for
i
,
c
in
enumerate
(
lzma
.
compress
(
src
.
read
(),
preset
=
9
)):
if
i
%
16
==
0
:
out
.
write
(
'
\n
'
)
out
.
write
(
'0x{:02X},'
.
format
(
c
))
out
.
write
(
'
\n
};
\n
'
)
out
.
flush
()
def
gen_update_binary
():
def
gen_update_binary
():
update_bin
=
[]
update_bin
=
[]
binary
=
os
.
path
.
join
(
'native'
,
'out'
,
'armeabi-v7a'
,
'b64xz'
)
binary
=
os
.
path
.
join
(
'native'
,
'out'
,
'armeabi-v7a'
,
'b64xz'
)
...
...
native/jni/Android.mk
View file @
6add6827
...
@@ -68,7 +68,7 @@ ifdef B_INIT
...
@@ -68,7 +68,7 @@ ifdef B_INIT
# magiskinit
# magiskinit
include $(CLEAR_VARS)
include $(CLEAR_VARS)
LOCAL_MODULE := magiskinit
LOCAL_MODULE := magiskinit
LOCAL_STATIC_LIBRARIES := libsepol
liblzma
LOCAL_STATIC_LIBRARIES := libsepol
LOCAL_C_INCLUDES := \
LOCAL_C_INCLUDES := \
jni/include \
jni/include \
jni/magiskpolicy \
jni/magiskpolicy \
...
...
native/jni/core/magiskinit.c
View file @
6add6827
...
@@ -36,16 +36,13 @@
...
@@ -36,16 +36,13 @@
#include <sys/sendfile.h>
#include <sys/sendfile.h>
#include <sys/sysmacros.h>
#include <sys/sysmacros.h>
#include <lzma.h>
#include "binaries.h"
#include "binaries_arch.h"
#include "binaries_xz.h"
#include "binaries_arch_xz.h"
#include "magiskrc.h"
#include "magiskrc.h"
#include "utils.h"
#include "utils.h"
#include "magiskpolicy.h"
#include "magiskpolicy.h"
#include "daemon.h"
#include "daemon.h"
#include "cpio.h"
#include "magisk.h"
#include "magisk.h"
#ifdef MAGISK_DEBUG
#ifdef MAGISK_DEBUG
...
@@ -246,45 +243,18 @@ static int patch_sepolicy() {
...
@@ -246,45 +243,18 @@ static int patch_sepolicy() {
return
0
;
return
0
;
}
}
#define BUFSIZE (1 << 20)
static
int
unxz
(
const
void
*
buf
,
size_t
size
,
int
fd
)
{
lzma_stream
strm
=
LZMA_STREAM_INIT
;
if
(
lzma_auto_decoder
(
&
strm
,
UINT64_MAX
,
0
)
!=
LZMA_OK
)
return
1
;
lzma_ret
ret
;
void
*
out
=
malloc
(
BUFSIZE
);
strm
.
next_in
=
buf
;
strm
.
avail_in
=
size
;
do
{
strm
.
next_out
=
out
;
strm
.
avail_out
=
BUFSIZE
;
ret
=
lzma_code
(
&
strm
,
LZMA_RUN
);
xwrite
(
fd
,
out
,
BUFSIZE
-
strm
.
avail_out
);
}
while
(
strm
.
avail_out
==
0
&&
ret
==
LZMA_OK
);
free
(
out
);
lzma_end
(
&
strm
);
if
(
ret
!=
LZMA_OK
&&
ret
!=
LZMA_STREAM_END
)
return
1
;
return
0
;
}
static
int
dump_magisk
(
const
char
*
path
,
mode_t
mode
)
{
static
int
dump_magisk
(
const
char
*
path
,
mode_t
mode
)
{
unlink
(
path
);
int
fd
=
creat
(
path
,
mode
);
int
fd
=
creat
(
path
,
mode
);
int
ret
=
unxz
(
magisk_xz
,
sizeof
(
magisk_xz
),
fd
);
xwrite
(
fd
,
magisk_bin
,
sizeof
(
magisk_bin
)
);
close
(
fd
);
close
(
fd
);
return
ret
;
return
0
;
}
}
static
int
dump_manager
(
const
char
*
path
,
mode_t
mode
)
{
static
int
dump_manager
(
const
char
*
path
,
mode_t
mode
)
{
unlink
(
path
);
int
fd
=
creat
(
path
,
mode
);
int
fd
=
creat
(
path
,
mode
);
int
ret
=
unxz
(
manager_xz
,
sizeof
(
manager_xz
),
fd
);
xwrite
(
fd
,
manager_bin
,
sizeof
(
manager_bin
)
);
close
(
fd
);
close
(
fd
);
return
ret
;
return
0
;
}
}
static
int
dump_magiskrc
(
const
char
*
path
,
mode_t
mode
)
{
static
int
dump_magiskrc
(
const
char
*
path
,
mode_t
mode
)
{
...
@@ -365,23 +335,6 @@ int main(int argc, char *argv[]) {
...
@@ -365,23 +335,6 @@ int main(int argc, char *argv[]) {
// Clear rootfs
// Clear rootfs
excl_list
=
(
char
*
[])
{
"overlay"
,
".backup"
,
"proc"
,
"sys"
,
"init.bak"
,
NULL
};
excl_list
=
(
char
*
[])
{
"overlay"
,
".backup"
,
"proc"
,
"sys"
,
"init.bak"
,
NULL
};
frm_rf
(
root
);
frm_rf
(
root
);
}
else
if
(
access
(
"/ramdisk.cpio.xz"
,
R_OK
)
==
0
)
{
// High compression mode
void
*
addr
;
size_t
size
;
mmap_ro
(
"/ramdisk.cpio.xz"
,
&
addr
,
&
size
);
int
fd
=
creat
(
"/ramdisk.cpio"
,
0
);
unxz
(
addr
,
size
,
fd
);
munmap
(
addr
,
size
);
close
(
fd
);
struct
vector
v
;
vec_init
(
&
v
);
parse_cpio
(
&
v
,
"/ramdisk.cpio"
);
excl_list
=
(
char
*
[])
{
"overlay"
,
".backup"
,
"proc"
,
"sys"
,
"init.bak"
,
NULL
};
frm_rf
(
root
);
chdir
(
"/"
);
cpio_extract_all
(
&
v
);
cpio_vec_destroy
(
&
v
);
}
else
{
}
else
{
// Revert original init binary
// Revert original init binary
link
(
"/.backup/init"
,
"/init"
);
link
(
"/.backup/init"
,
"/init"
);
...
...
native/jni/include/utils.h
View file @
6add6827
...
@@ -139,8 +139,8 @@ int fsetattr(int fd, struct file_attr *a);
...
@@ -139,8 +139,8 @@ int fsetattr(int fd, struct file_attr *a);
void
fclone_attr
(
const
int
sourcefd
,
const
int
targetfd
);
void
fclone_attr
(
const
int
sourcefd
,
const
int
targetfd
);
void
clone_attr
(
const
char
*
source
,
const
char
*
target
);
void
clone_attr
(
const
char
*
source
,
const
char
*
target
);
void
restorecon
();
void
restorecon
();
int
mmap_ro
(
const
char
*
filename
,
void
**
buf
,
size_t
*
size
);
void
mmap_ro
(
const
char
*
filename
,
void
**
buf
,
size_t
*
size
);
int
mmap_rw
(
const
char
*
filename
,
void
**
buf
,
size_t
*
size
);
void
mmap_rw
(
const
char
*
filename
,
void
**
buf
,
size_t
*
size
);
void
fd_full_read
(
int
fd
,
void
**
buf
,
size_t
*
size
);
void
fd_full_read
(
int
fd
,
void
**
buf
,
size_t
*
size
);
void
full_read
(
const
char
*
filename
,
void
**
buf
,
size_t
*
size
);
void
full_read
(
const
char
*
filename
,
void
**
buf
,
size_t
*
size
);
void
full_read_at
(
int
dirfd
,
const
char
*
filename
,
void
**
buf
,
size_t
*
size
);
void
full_read_at
(
int
dirfd
,
const
char
*
filename
,
void
**
buf
,
size_t
*
size
);
...
...
native/jni/magiskboot/bootimg.c
View file @
6add6827
...
@@ -11,11 +11,6 @@
...
@@ -11,11 +11,6 @@
#include "mincrypt/sha.h"
#include "mincrypt/sha.h"
#include "mincrypt/sha256.h"
#include "mincrypt/sha256.h"
#define INSUF_BLOCK_RET 2
#define CHROMEOS_RET 3
#define ELF32_RET 4
#define ELF64_RET 5
// Macros to determine header on-the-go
// Macros to determine header on-the-go
#define lheader(b, e, o) \
#define lheader(b, e, o) \
((b)->flags & PXA_FLAG) ? \
((b)->flags & PXA_FLAG) ? \
...
@@ -88,10 +83,13 @@ static void clean_boot(boot_img *boot) {
...
@@ -88,10 +83,13 @@ static void clean_boot(boot_img *boot) {
memset
(
boot
,
0
,
sizeof
(
*
boot
));
memset
(
boot
,
0
,
sizeof
(
*
boot
));
}
}
#define CHROMEOS_RET 2
#define ELF32_RET 3
#define ELF64_RET 4
#define pos_align() pos = align(pos, header(boot, page_size))
#define pos_align() pos = align(pos, header(boot, page_size))
int
parse_img
(
const
char
*
image
,
boot_img
*
boot
)
{
int
parse_img
(
const
char
*
image
,
boot_img
*
boot
)
{
memset
(
boot
,
0
,
sizeof
(
*
boot
));
memset
(
boot
,
0
,
sizeof
(
*
boot
));
int
is_blk
=
mmap_ro
(
image
,
&
boot
->
map_addr
,
&
boot
->
map_size
);
mmap_ro
(
image
,
&
boot
->
map_addr
,
&
boot
->
map_size
);
// Parse image
// Parse image
fprintf
(
stderr
,
"Parsing boot image: [%s]
\n
"
,
image
);
fprintf
(
stderr
,
"Parsing boot image: [%s]
\n
"
,
image
);
...
@@ -246,8 +244,7 @@ int parse_img(const char *image, boot_img *boot) {
...
@@ -246,8 +244,7 @@ int parse_img(const char *image, boot_img *boot) {
get_fmt_name
(
boot
->
r_fmt
,
fmt
);
get_fmt_name
(
boot
->
r_fmt
,
fmt
);
fprintf
(
stderr
,
"RAMDISK_FMT [%s]
\n
"
,
fmt
);
fprintf
(
stderr
,
"RAMDISK_FMT [%s]
\n
"
,
fmt
);
return
boot
->
flags
&
CHROMEOS_FLAG
?
CHROMEOS_RET
:
return
boot
->
flags
&
CHROMEOS_FLAG
?
CHROMEOS_RET
:
0
;
((
is_blk
&&
boot
->
tail_size
<
500
*
1024
)
?
INSUF_BLOCK_RET
:
0
);
default:
default:
continue
;
continue
;
}
}
...
...
native/jni/magiskboot/main.c
View file @
6add6827
...
@@ -17,14 +17,10 @@ static void usage(char *arg0) {
...
@@ -17,14 +17,10 @@ static void usage(char *arg0) {
"Usage: %s <action> [args...]
\n
"
"Usage: %s <action> [args...]
\n
"
"
\n
"
"
\n
"
"Supported actions:
\n
"
"Supported actions:
\n
"
" --parse <bootimg>
\n
"
" Parse <bootimg> only, do not unpack. Return values:
\n
"
" 0:OK 1:error 2:insufficient boot partition size
\n
"
" 3:chromeos 4:ELF32 5:ELF64
\n
"
"
\n
"
" --unpack <bootimg>
\n
"
" --unpack <bootimg>
\n
"
" Unpack <bootimg> to kernel, ramdisk.cpio, (second), (dtb), (extra) into
\n
"
" Unpack <bootimg> to kernel, ramdisk.cpio, and if available, second, dtb,
\n
"
" the current directory. Return value is the same as --parse
\n
"
" and extra into the current directory. Return values:
\n
"
" 0:valid 1:error 2:chromeos 3:ELF32 4:ELF64
\n
"
"
\n
"
"
\n
"
" --repack <origbootimg> [outbootimg]
\n
"
" --repack <origbootimg> [outbootimg]
\n
"
" Repack kernel, ramdisk.cpio[.ext], second, dtb... from current directory
\n
"
" Repack kernel, ramdisk.cpio[.ext], second, dtb... from current directory
\n
"
...
@@ -54,7 +50,8 @@ static void usage(char *arg0) {
...
@@ -54,7 +50,8 @@ static void usage(char *arg0) {
" Extract ENTRY to OUT, or extract all entries to current directory
\n
"
" Extract ENTRY to OUT, or extract all entries to current directory
\n
"
" test
\n
"
" test
\n
"
" Test the current cpio's patch status
\n
"
" Test the current cpio's patch status
\n
"
" Return value: 0/stock 1/Magisk 2/other (phh, SuperSU, Xposed)
\n
"
" Return values:
\n
"
" 0:stock 1:Magisk 2:unsupported (phh, SuperSU, Xposed)
\n
"
" patch KEEPVERITY KEEPFORCEENCRYPT
\n
"
" patch KEEPVERITY KEEPFORCEENCRYPT
\n
"
" Ramdisk patches. KEEP**** are boolean values
\n
"
" Ramdisk patches. KEEP**** are boolean values
\n
"
" backup ORIG [SHA1]
\n
"
" backup ORIG [SHA1]
\n
"
...
@@ -62,10 +59,10 @@ static void usage(char *arg0) {
...
@@ -62,10 +59,10 @@ static void usage(char *arg0) {
" SHA1 of stock boot image is optional
\n
"
" SHA1 of stock boot image is optional
\n
"
" restore
\n
"
" restore
\n
"
" Restore ramdisk from ramdisk backup stored within incpio
\n
"
" Restore ramdisk from ramdisk backup stored within incpio
\n
"
" magisk ORIG
HIGHCOMP
KEEPVERITY KEEPFORCEENCRYPT [SHA1]
\n
"
" magisk ORIG KEEPVERITY KEEPFORCEENCRYPT [SHA1]
\n
"
" Do Magisk patches and backups all in one step
\n
"
" Do Magisk patches and backups all in one step
\n
"
" Create ramdisk backups from ORIG
\n
"
" Create ramdisk backups from ORIG
\n
"
"
HIGHCOMP,
KEEP**** are boolean values
\n
"
" KEEP**** are boolean values
\n
"
" SHA1 of stock boot image is optional
\n
"
" SHA1 of stock boot image is optional
\n
"
" sha1
\n
"
" sha1
\n
"
" Print stock boot SHA1 if previously stored
\n
"
" Print stock boot SHA1 if previously stored
\n
"
...
@@ -77,7 +74,8 @@ static void usage(char *arg0) {
...
@@ -77,7 +74,8 @@ static void usage(char *arg0) {
" Dump all contents from dtb for debugging
\n
"
" Dump all contents from dtb for debugging
\n
"
" test
\n
"
" test
\n
"
" Check if fstab has verity/avb flags
\n
"
" Check if fstab has verity/avb flags
\n
"
" Return value: 0/no flags 1/flag exists
\n
"
" Return values:
\n
"
" 0:no flags 1:flag exists
\n
"
" patch
\n
"
" patch
\n
"
" Search for fstab and remove verity/avb
\n
"
" Search for fstab and remove verity/avb
\n
"
"
\n
"
"
\n
"
...
@@ -135,9 +133,6 @@ int main(int argc, char *argv[]) {
...
@@ -135,9 +133,6 @@ int main(int argc, char *argv[]) {
printf
(
"%02x"
,
sha1
[
i
]);
printf
(
"%02x"
,
sha1
[
i
]);
printf
(
"
\n
"
);
printf
(
"
\n
"
);
munmap
(
buf
,
size
);
munmap
(
buf
,
size
);
}
else
if
(
argc
>
2
&&
strcmp
(
argv
[
1
],
"--parse"
)
==
0
)
{
boot_img
boot
;
return
parse_img
(
argv
[
2
],
&
boot
);
}
else
if
(
argc
>
2
&&
strcmp
(
argv
[
1
],
"--unpack"
)
==
0
)
{
}
else
if
(
argc
>
2
&&
strcmp
(
argv
[
1
],
"--unpack"
)
==
0
)
{
return
unpack
(
argv
[
2
]);
return
unpack
(
argv
[
2
]);
}
else
if
(
argc
>
2
&&
strcmp
(
argv
[
1
],
"--repack"
)
==
0
)
{
}
else
if
(
argc
>
2
&&
strcmp
(
argv
[
1
],
"--repack"
)
==
0
)
{
...
...
native/jni/magiskboot/ramdisk.c
View file @
6add6827
...
@@ -32,21 +32,17 @@ static void cpio_patch(struct vector *v, int keepverity, int keepforceencrypt) {
...
@@ -32,21 +32,17 @@ static void cpio_patch(struct vector *v, int keepverity, int keepforceencrypt) {
}
}
}
}
#define STOCK_BOOT 0x0
#define STOCK_BOOT 0x0
#define MAGISK_PATCH 0x1
#define MAGISK_PATCH 0x1
#define HIGH_COMPRESS 0x2
#define UNSUPPORT_PATCH 0x2
#define OTHER_PATCH 0x3
static
int
cpio_test
(
struct
vector
*
v
)
{
static
int
cpio_test
(
struct
vector
*
v
)
{
const
char
*
OTHER
_LIST
[]
=
{
"sbin/launch_daemonsu.sh"
,
"sbin/su"
,
"init.xposed.rc"
,
"boot/sbin/launch_daemonsu.sh"
,
NULL
};
const
char
*
UNSUPPORT
_LIST
[]
=
{
"sbin/launch_daemonsu.sh"
,
"sbin/su"
,
"init.xposed.rc"
,
"boot/sbin/launch_daemonsu.sh"
,
NULL
};
const
char
*
MAGISK_LIST
[]
=
{
".backup/.magisk"
,
"init.magisk.rc"
,
"overlay/init.magisk.rc"
,
NULL
};
const
char
*
MAGISK_LIST
[]
=
{
".backup/.magisk"
,
"init.magisk.rc"
,
"overlay/init.magisk.rc"
,
NULL
};
for
(
int
i
=
0
;
OTHER_LIST
[
i
];
++
i
)
for
(
int
i
=
0
;
UNSUPPORT_LIST
[
i
];
++
i
)
if
(
cpio_find
(
v
,
OTHER_LIST
[
i
])
>=
0
)
if
(
cpio_find
(
v
,
UNSUPPORT_LIST
[
i
])
>=
0
)
return
OTHER_PATCH
;
return
UNSUPPORT_PATCH
;
if
(
cpio_find
(
v
,
"ramdisk.cpio.xz"
)
>=
0
)
return
HIGH_COMPRESS
;
for
(
int
i
=
0
;
MAGISK_LIST
[
i
];
++
i
)
for
(
int
i
=
0
;
MAGISK_LIST
[
i
];
++
i
)
if
(
cpio_find
(
v
,
MAGISK_LIST
[
i
])
>=
0
)
if
(
cpio_find
(
v
,
MAGISK_LIST
[
i
])
>=
0
)
...
@@ -196,55 +192,6 @@ static void cpio_restore(struct vector *v) {
...
@@ -196,55 +192,6 @@ static void cpio_restore(struct vector *v) {
cpio_rm
(
v
,
0
,
"sbin/magic_mask.sh"
);
cpio_rm
(
v
,
0
,
"sbin/magic_mask.sh"
);
cpio_rm
(
v
,
0
,
"init.magisk.rc"
);
cpio_rm
(
v
,
0
,
"init.magisk.rc"
);
cpio_rm
(
v
,
0
,
"magisk"
);
cpio_rm
(
v
,
0
,
"magisk"
);
cpio_rm
(
v
,
0
,
"ramdisk-recovery.xz"
);
}
static
void
restore_high_compress
(
struct
vector
*
v
,
const
char
*
incpio
)
{
// Check if the ramdisk is in high compression mode
if
(
cpio_extract
(
v
,
"ramdisk.cpio.xz"
,
incpio
)
==
0
)
{
void
*
xz
;
size_t
size
;
full_read
(
incpio
,
&
xz
,
&
size
);
int
fd
=
creat
(
incpio
,
0644
);
lzma
(
0
,
fd
,
xz
,
size
);
close
(
fd
);
free
(
xz
);
cpio_rm
(
v
,
0
,
"ramdisk.cpio.xz"
);
cpio_rm
(
v
,
0
,
"init"
);
struct
vector
vv
;
vec_init
(
&
vv
);
parse_cpio
(
&
vv
,
incpio
);
cpio_entry
*
e
;
vec_for_each
(
&
vv
,
e
)
vec_push_back
(
v
,
e
);
vec_destroy
(
&
vv
);
}
}
static
void
enable_high_compress
(
struct
vector
*
v
,
struct
vector
*
b
,
const
char
*
incpio
)
{
cpio_entry
*
init
,
*
magiskinit
;
// Swap magiskinit with original init
int
i
=
cpio_find
(
b
,
".backup/init"
),
j
=
cpio_find
(
v
,
"init"
);
init
=
vec_entry
(
b
)[
i
];
magiskinit
=
vec_entry
(
v
)[
j
];
free
(
init
->
filename
);
init
->
filename
=
strdup
(
"init"
);
vec_entry
(
v
)[
j
]
=
init
;
vec_entry
(
b
)[
i
]
=
NULL
;
dump_cpio
(
v
,
incpio
);
cpio_vec_destroy
(
v
);
void
*
cpio
;
size_t
size
;
full_read
(
incpio
,
&
cpio
,
&
size
);
int
fd
=
creat
(
incpio
,
0644
);
lzma
(
1
,
fd
,
cpio
,
size
);
close
(
fd
);
free
(
cpio
);
vec_init
(
v
);
vec_push_back
(
v
,
magiskinit
);
cpio_add
(
v
,
0
,
"ramdisk.cpio.xz"
,
incpio
);
}
}
int
cpio_commands
(
int
argc
,
char
*
argv
[])
{
int
cpio_commands
(
int
argc
,
char
*
argv
[])
{
...
@@ -267,7 +214,6 @@ int cpio_commands(int argc, char *argv[]) {
...
@@ -267,7 +214,6 @@ int cpio_commands(int argc, char *argv[]) {
if
(
strcmp
(
cmdv
[
0
],
"test"
)
==
0
)
{
if
(
strcmp
(
cmdv
[
0
],
"test"
)
==
0
)
{
exit
(
cpio_test
(
&
v
));
exit
(
cpio_test
(
&
v
));
}
else
if
(
strcmp
(
cmdv
[
0
],
"restore"
)
==
0
)
{
}
else
if
(
strcmp
(
cmdv
[
0
],
"restore"
)
==
0
)
{
restore_high_compress
(
&
v
,
incpio
);
cpio_restore
(
&
v
);
cpio_restore
(
&
v
);
}
else
if
(
strcmp
(
cmdv
[
0
],
"sha1"
)
==
0
)
{
}
else
if
(
strcmp
(
cmdv
[
0
],
"sha1"
)
==
0
)
{
char
*
sha1
=
cpio_sha1
(
&
v
);
char
*
sha1
=
cpio_sha1
(
&
v
);
...
@@ -282,12 +228,12 @@ int cpio_commands(int argc, char *argv[]) {
...
@@ -282,12 +228,12 @@ int cpio_commands(int argc, char *argv[]) {
vec_for_each
(
&
back
,
e
)
vec_for_each
(
&
back
,
e
)
if
(
e
)
vec_push_back
(
&
v
,
e
);
if
(
e
)
vec_push_back
(
&
v
,
e
);
vec_destroy
(
&
back
);
vec_destroy
(
&
back
);
}
else
if
(
cmdc
>=
5
&&
strcmp
(
cmdv
[
0
],
"magisk"
)
==
0
)
{
}
else
if
(
cmdc
>=
4
&&
strcmp
(
cmdv
[
0
],
"magisk"
)
==
0
)
{
cpio_patch
(
&
v
,
strcmp
(
cmdv
[
3
],
"true"
)
==
0
,
strcmp
(
cmdv
[
4
],
"true"
)
==
0
);
cpio_patch
(
&
v
,
strcmp
(
cmdv
[
2
],
"true"
)
==
0
,
strcmp
(
cmdv
[
3
],
"true"
)
==
0
);
struct
vector
back
;
struct
vector
back
;
vec_init
(
&
back
);
vec_init
(
&
back
);
cpio_backup
(
&
v
,
&
back
,
cmdv
[
1
],
cmdc
>
5
?
cmdv
[
5
]
:
NULL
);
cpio_backup
(
&
v
,
&
back
,
cmdv
[
1
],
cmdc
>
4
?
cmdv
[
4
]
:
NULL
);
cpio_entry
*
e
;
cpio_entry
*
e
;
e
=
xcalloc
(
sizeof
(
*
e
),
1
);
e
=
xcalloc
(
sizeof
(
*
e
),
1
);
...
@@ -298,10 +244,6 @@ int cpio_commands(int argc, char *argv[]) {
...
@@ -298,10 +244,6 @@ int cpio_commands(int argc, char *argv[]) {
e
->
filesize
=
strlen
(
e
->
data
)
+
1
;
e
->
filesize
=
strlen
(
e
->
data
)
+
1
;
vec_push_back
(
&
back
,
e
);
vec_push_back
(
&
back
,
e
);
// Enable high compression mode
if
(
strcmp
(
cmdv
[
2
],
"true"
)
==
0
)
enable_high_compress
(
&
v
,
&
back
,
incpio
);
vec_for_each
(
&
back
,
e
)
vec_for_each
(
&
back
,
e
)
if
(
e
)
vec_push_back
(
&
v
,
e
);
if
(
e
)
vec_push_back
(
&
v
,
e
);
vec_destroy
(
&
back
);
vec_destroy
(
&
back
);
...
...
native/jni/utils/file.c
View file @
6add6827
...
@@ -425,7 +425,7 @@ void restorecon() {
...
@@ -425,7 +425,7 @@ void restorecon() {
#endif // SELINUX
#endif // SELINUX
static
int
_mmap
(
int
rw
,
const
char
*
filename
,
void
**
buf
,
size_t
*
size
)
{
static
void
_mmap
(
int
rw
,
const
char
*
filename
,
void
**
buf
,
size_t
*
size
)
{
struct
stat
st
;
struct
stat
st
;
int
fd
=
xopen
(
filename
,
(
rw
?
O_RDWR
:
O_RDONLY
)
|
O_CLOEXEC
);
int
fd
=
xopen
(
filename
,
(
rw
?
O_RDWR
:
O_RDONLY
)
|
O_CLOEXEC
);
fstat
(
fd
,
&
st
);
fstat
(
fd
,
&
st
);
...
@@ -435,15 +435,14 @@ static int _mmap(int rw, const char *filename, void **buf, size_t *size) {
...
@@ -435,15 +435,14 @@ static int _mmap(int rw, const char *filename, void **buf, size_t *size) {
*
size
=
st
.
st_size
;
*
size
=
st
.
st_size
;
*
buf
=
*
size
>
0
?
xmmap
(
NULL
,
*
size
,
PROT_READ
|
(
rw
?
PROT_WRITE
:
0
),
MAP_SHARED
,
fd
,
0
)
:
NULL
;
*
buf
=
*
size
>
0
?
xmmap
(
NULL
,
*
size
,
PROT_READ
|
(
rw
?
PROT_WRITE
:
0
),
MAP_SHARED
,
fd
,
0
)
:
NULL
;
close
(
fd
);
close
(
fd
);
return
S_ISBLK
(
st
.
st_mode
);
}
}
int
mmap_ro
(
const
char
*
filename
,
void
**
buf
,
size_t
*
size
)
{
void
mmap_ro
(
const
char
*
filename
,
void
**
buf
,
size_t
*
size
)
{
return
_mmap
(
0
,
filename
,
buf
,
size
);
_mmap
(
0
,
filename
,
buf
,
size
);
}
}
int
mmap_rw
(
const
char
*
filename
,
void
**
buf
,
size_t
*
size
)
{
void
mmap_rw
(
const
char
*
filename
,
void
**
buf
,
size_t
*
size
)
{
return
_mmap
(
1
,
filename
,
buf
,
size
);
_mmap
(
1
,
filename
,
buf
,
size
);
}
}
void
fd_full_read
(
int
fd
,
void
**
buf
,
size_t
*
size
)
{
void
fd_full_read
(
int
fd
,
void
**
buf
,
size_t
*
size
)
{
...
...
scripts/boot_patch.sh
View file @
6add6827
...
@@ -4,10 +4,10 @@
...
@@ -4,10 +4,10 @@
# Magisk Boot Image Patcher
# Magisk Boot Image Patcher
# by topjohnwu
# by topjohnwu
#
#
# Usage:
sh
boot_patch.sh <bootimage>
# Usage: boot_patch.sh <bootimage>
#
#
# The following
additional
flags can be set in environment variables:
# The following flags can be set in environment variables:
# KEEPVERITY, KEEPFORCEENCRYPT
, HIGHCOMP
# KEEPVERITY, KEEPFORCEENCRYPT
#
#
# This script should be placed in a directory with the following files:
# This script should be placed in a directory with the following files:
#
#
...
@@ -58,7 +58,6 @@ BOOTIMAGE="$1"
...
@@ -58,7 +58,6 @@ BOOTIMAGE="$1"
# Flags
# Flags
[
-z
$KEEPVERITY
]
&&
KEEPVERITY
=
false
[
-z
$KEEPVERITY
]
&&
KEEPVERITY
=
false
[
-z
$KEEPFORCEENCRYPT
]
&&
KEEPFORCEENCRYPT
=
false
[
-z
$KEEPFORCEENCRYPT
]
&&
KEEPFORCEENCRYPT
=
false
[
-z
$HIGHCOMP
]
&&
HIGHCOMP
=
false
chmod
-R
755
.
chmod
-R
755
.
...
@@ -79,17 +78,14 @@ case $? in
...
@@ -79,17 +78,14 @@ case $? in
abort
"! Unable to unpack boot image"
abort
"! Unable to unpack boot image"
;;
;;
2
)
2
)
HIGHCOMP
=
true
;;
3
)
ui_print
"- ChromeOS boot image detected"
ui_print
"- ChromeOS boot image detected"
CHROMEOS
=
true
CHROMEOS
=
true
;;
;;
4
)
3
)
ui_print
"! Sony ELF32 format detected"
ui_print
"! Sony ELF32 format detected"
abort
"! Please use BootBridge from @AdrianDC to flash Magisk"
abort
"! Please use BootBridge from @AdrianDC to flash Magisk"
;;
;;
5
)
4
)
ui_print
"! Sony ELF64 format detected"
ui_print
"! Sony ELF64 format detected"
abort
"! Stock kernel cannot be patched, please use a custom kernel"
abort
"! Stock kernel cannot be patched, please use a custom kernel"
esac
esac
...
@@ -100,7 +96,6 @@ esac
...
@@ -100,7 +96,6 @@ 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"
MAGISK_PATCHED
=
false
./magiskboot
--cpio
ramdisk.cpio
test
./magiskboot
--cpio
ramdisk.cpio
test
case
$?
in
case
$?
in
0
)
# Stock boot
0
)
# Stock boot
...
@@ -112,32 +107,18 @@ case $? in
...
@@ -112,32 +107,18 @@ case $? in
cp
-af
ramdisk.cpio ramdisk.cpio.orig
cp
-af
ramdisk.cpio ramdisk.cpio.orig
;;
;;
1
)
# Magisk patched
1
)
# Magisk patched
MAGISK_PATCHED
=
true
ui_print
"- Magisk patched boot image detected"
HIGHCOMP
=
false
# Find SHA1 of stock boot image
;;
[
-z
$SHA1
]
&&
SHA1
=
`
./magiskboot
--cpio
ramdisk.cpio sha1 2>/dev/null
`
2
)
# High compression mode
./magiskboot
--cpio
ramdisk.cpio restore
MAGISK_PATCHED
=
true
cp
-af
ramdisk.cpio ramdisk.cpio.orig
HIGHCOMP
=
true
;;
;;
3
)
# Other patched
2
)
# Other patched
ui_print
"! Boot image patched by
other
programs"
ui_print
"! Boot image patched by
unsupported
programs"
abort
"! Please restore stock boot image"
abort
"! Please restore stock boot image"
;;
;;
esac
esac
if
$MAGISK_PATCHED
;
then
ui_print
"- Magisk patched image detected"
# Find SHA1 of stock boot image
[
-z
$SHA1
]
&&
SHA1
=
`
./magiskboot
--cpio
ramdisk.cpio sha1 2>/dev/null
`
./magiskboot
--cpio
ramdisk.cpio restore
cp
-af
ramdisk.cpio ramdisk.cpio.orig
fi
if
$HIGHCOMP
;
then
ui_print
"! Insufficient boot partition size detected"
ui_print
"- Enable high compression mode"
fi
##########################################################################################
##########################################################################################
# Ramdisk patches
# Ramdisk patches
##########################################################################################
##########################################################################################
...
@@ -146,7 +127,7 @@ ui_print "- Patching ramdisk"
...
@@ -146,7 +127,7 @@ ui_print "- Patching ramdisk"
./magiskboot
--cpio
ramdisk.cpio
\
./magiskboot
--cpio
ramdisk.cpio
\
"add 750 init magiskinit"
\
"add 750 init magiskinit"
\
"magisk ramdisk.cpio.orig
$
HIGHCOMP
$
KEEPVERITY
$KEEPFORCEENCRYPT
$SHA1
"
"magisk ramdisk.cpio.orig
$KEEPVERITY
$KEEPFORCEENCRYPT
$SHA1
"
rm
-f
ramdisk.cpio.orig
rm
-f
ramdisk.cpio.orig
...
...
scripts/magisk_uninstaller.sh
View file @
6add6827
#MAGISK
#MAGISK
##########################################################################################
##########################################################################################
#
#
# Magisk Uninstaller
(used in recovery)
# Magisk Uninstaller
# by topjohnwu
# by topjohnwu
#
#
# This script will load the real uninstaller in a flashable zip
#
##########################################################################################
##########################################################################################
##########################################################################################
##########################################################################################
...
@@ -75,15 +73,15 @@ case $? in
...
@@ -75,15 +73,15 @@ case $? in
1
)
1
)
abort
"! Unable to unpack boot image"
abort
"! Unable to unpack boot image"
;;
;;
3
)
2
)
ui_print
"- ChromeOS boot image detected"
ui_print
"- ChromeOS boot image detected"
CHROMEOS
=
true
CHROMEOS
=
true
;;
;;
4
)
3
)
ui_print
"! Sony ELF32 format detected"
ui_print
"! Sony ELF32 format detected"
abort
"! Please use BootBridge from @AdrianDC"
abort
"! Please use BootBridge from @AdrianDC"
;;
;;
5
)
4
)
ui_print
"! Sony ELF64 format detected"
ui_print
"! Sony ELF64 format detected"
abort
"! Stock kernel cannot be patched, please use a custom kernel"
abort
"! Stock kernel cannot be patched, please use a custom kernel"
esac
esac
...
@@ -95,7 +93,7 @@ case $? in
...
@@ -95,7 +93,7 @@ case $? in
0
)
# Stock boot
0
)
# Stock boot
ui_print
"- Stock boot image detected"
ui_print
"- Stock boot image detected"
;;
;;
1
|2
)
# Magisk patched
1
)
# Magisk patched
ui_print
"- Magisk patched image detected"
ui_print
"- Magisk patched image detected"
./magisk
--unlock-blocks
2>/dev/null
./magisk
--unlock-blocks
2>/dev/null
# Find SHA1 of stock boot image
# Find SHA1 of stock boot image
...
@@ -119,7 +117,7 @@ case $? in
...
@@ -119,7 +117,7 @@ case $? in
flash_boot_image new-boot.img
$BOOTIMAGE
flash_boot_image new-boot.img
$BOOTIMAGE
fi
fi
;;
;;
3
)
# Other patched
2
)
# Other patched
ui_print
"! Boot image patched by other programs"
ui_print
"! Boot image patched by other programs"
abort
"! Cannot uninstall"
abort
"! Cannot uninstall"
;;
;;
...
...
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