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
d4568aa0
Commit
d4568aa0
authored
Aug 09, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Compress binaries and use xz-embedded in magiskinit
parent
97588408
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
9 deletions
+37
-9
build.py
build.py
+8
-5
Android.mk
native/jni/Android.mk
+2
-1
b64xz.c
native/jni/b64xz.c
+1
-1
magiskinit.c
native/jni/core/magiskinit.c
+26
-2
No files found.
build.py
View file @
d4568aa0
...
@@ -106,6 +106,9 @@ def execv(cmd, redirect=None):
...
@@ -106,6 +106,9 @@ def execv(cmd, redirect=None):
def
system
(
cmd
,
redirect
=
None
):
def
system
(
cmd
,
redirect
=
None
):
return
subprocess
.
run
(
cmd
,
shell
=
True
,
stdout
=
redirect
if
redirect
!=
None
else
STDOUT
)
return
subprocess
.
run
(
cmd
,
shell
=
True
,
stdout
=
redirect
if
redirect
!=
None
else
STDOUT
)
def
xz
(
data
):
return
lzma
.
compress
(
data
,
preset
=
9
,
check
=
lzma
.
CHECK_NONE
)
def
sign_zip
(
unsigned
,
output
,
release
):
def
sign_zip
(
unsigned
,
output
,
release
):
signer_name
=
'zipsigner-3.0.jar'
signer_name
=
'zipsigner-3.0.jar'
zipsigner
=
os
.
path
.
join
(
'utils'
,
'build'
,
'libs'
,
signer_name
)
zipsigner
=
os
.
path
.
join
(
'utils'
,
'build'
,
'libs'
,
signer_name
)
...
@@ -151,7 +154,7 @@ def sign_apk(source, target):
...
@@ -151,7 +154,7 @@ def sign_apk(source, target):
def
binary_dump
(
src
,
out
,
var_name
):
def
binary_dump
(
src
,
out
,
var_name
):
out
.
write
(
'const static unsigned char {}[] = {{'
.
format
(
var_name
))
out
.
write
(
'const static unsigned char {}[] = {{'
.
format
(
var_name
))
for
i
,
c
in
enumerate
(
src
.
read
(
)):
for
i
,
c
in
enumerate
(
xz
(
src
.
read
()
)):
if
i
%
16
==
0
:
if
i
%
16
==
0
:
out
.
write
(
'
\n
'
)
out
.
write
(
'
\n
'
)
out
.
write
(
'0x{:02X},'
.
format
(
c
))
out
.
write
(
'0x{:02X},'
.
format
(
c
))
...
@@ -173,11 +176,11 @@ def gen_update_binary():
...
@@ -173,11 +176,11 @@ def gen_update_binary():
binary
=
os
.
path
.
join
(
'native'
,
'out'
,
'armeabi-v7a'
,
'busybox'
)
binary
=
os
.
path
.
join
(
'native'
,
'out'
,
'armeabi-v7a'
,
'busybox'
)
with
open
(
binary
,
'rb'
)
as
busybox
:
with
open
(
binary
,
'rb'
)
as
busybox
:
update_bin
.
append
(
'
\'\n
BB_ARM='
)
update_bin
.
append
(
'
\'\n
BB_ARM='
)
update_bin
.
append
(
base64
.
b64encode
(
lzma
.
compress
(
busybox
.
read
(),
preset
=
9
,
check
=
lzma
.
CHECK_NONE
))
.
decode
(
'ascii'
))
update_bin
.
append
(
base64
.
b64encode
(
xz
(
busybox
.
read
()
))
.
decode
(
'ascii'
))
binary
=
os
.
path
.
join
(
'native'
,
'out'
,
'x86'
,
'busybox'
)
binary
=
os
.
path
.
join
(
'native'
,
'out'
,
'x86'
,
'busybox'
)
with
open
(
binary
,
'rb'
)
as
busybox
:
with
open
(
binary
,
'rb'
)
as
busybox
:
update_bin
.
append
(
'
\n
BB_X86='
)
update_bin
.
append
(
'
\n
BB_X86='
)
update_bin
.
append
(
base64
.
b64encode
(
lzma
.
compress
(
busybox
.
read
(),
preset
=
9
,
check
=
lzma
.
CHECK_NONE
))
.
decode
(
'ascii'
))
update_bin
.
append
(
base64
.
b64encode
(
xz
(
busybox
.
read
()
))
.
decode
(
'ascii'
))
update_bin
.
append
(
'
\n
'
)
update_bin
.
append
(
'
\n
'
)
with
open
(
os
.
path
.
join
(
'scripts'
,
'update_binary.sh'
),
'r'
)
as
script
:
with
open
(
os
.
path
.
join
(
'scripts'
,
'update_binary.sh'
),
'r'
)
as
script
:
update_bin
.
append
(
script
.
read
())
update_bin
.
append
(
script
.
read
())
...
@@ -213,7 +216,7 @@ def build_binary(args):
...
@@ -213,7 +216,7 @@ def build_binary(args):
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.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
:
binary_dump
(
src
,
out
,
'magisk_
bin
'
)
binary_dump
(
src
,
out
,
'magisk_
xz
'
)
old_plat
=
False
old_plat
=
False
flags
=
base_flags
flags
=
base_flags
...
@@ -280,7 +283,7 @@ def build_apk(args):
...
@@ -280,7 +283,7 @@ def build_apk(args):
mkdir
(
os
.
path
.
join
(
'native'
,
'out'
))
mkdir
(
os
.
path
.
join
(
'native'
,
'out'
))
with
open
(
os
.
path
.
join
(
'native'
,
'out'
,
'binaries.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
:
binary_dump
(
src
,
out
,
'manager_
bin
'
);
binary_dump
(
src
,
out
,
'manager_
xz
'
);
else
:
else
:
proc
=
execv
([
gradlew
,
'app:assembleDebug'
])
proc
=
execv
([
gradlew
,
'app:assembleDebug'
])
if
proc
.
returncode
!=
0
:
if
proc
.
returncode
!=
0
:
...
...
native/jni/Android.mk
View file @
d4568aa0
...
@@ -67,10 +67,11 @@ ifdef B_INIT
...
@@ -67,10 +67,11 @@ ifdef B_INIT
# magiskinit
# magiskinit
include $(CLEAR_VARS)
include $(CLEAR_VARS)
LOCAL_MODULE := magiskinit
LOCAL_MODULE := magiskinit
LOCAL_STATIC_LIBRARIES := libsepol
LOCAL_STATIC_LIBRARIES := libsepol
libxz
LOCAL_C_INCLUDES := \
LOCAL_C_INCLUDES := \
jni/include \
jni/include \
jni/magiskpolicy \
jni/magiskpolicy \
$(EXT_PATH)/include \
out \
out \
out/$(TARGET_ARCH_ABI) \
out/$(TARGET_ARCH_ABI) \
$(LIBSEPOL)
$(LIBSEPOL)
...
...
native/jni/b64xz.c
View file @
d4568aa0
...
@@ -22,7 +22,7 @@ static void decodeblock(uint8_t* in, uint8_t* out) {
...
@@ -22,7 +22,7 @@ static void decodeblock(uint8_t* in, uint8_t* out) {
out
[
2
]
=
(
uint8_t
)(((
in
[
2
]
<<
6
)
&
0xc0
)
|
in
[
3
]);
out
[
2
]
=
(
uint8_t
)(((
in
[
2
]
<<
6
)
&
0xc0
)
|
in
[
3
]);
}
}
static
int
unxz
(
struct
xz_dec
*
dec
,
void
*
buf
,
unsigned
size
)
{
static
int
unxz
(
struct
xz_dec
*
dec
,
const
void
*
buf
,
unsigned
size
)
{
uint8_t
out
[
8192
];
uint8_t
out
[
8192
];
struct
xz_buf
b
=
{
struct
xz_buf
b
=
{
.
in
=
buf
,
.
in
=
buf
,
...
...
native/jni/core/magiskinit.c
View file @
d4568aa0
...
@@ -36,6 +36,8 @@
...
@@ -36,6 +36,8 @@
#include <sys/sendfile.h>
#include <sys/sendfile.h>
#include <sys/sysmacros.h>
#include <sys/sysmacros.h>
#include <xz.h>
#include "binaries.h"
#include "binaries.h"
#include "binaries_arch.h"
#include "binaries_arch.h"
...
@@ -243,16 +245,38 @@ static int patch_sepolicy() {
...
@@ -243,16 +245,38 @@ static int patch_sepolicy() {
return
0
;
return
0
;
}
}
static
int
unxz
(
int
fd
,
const
void
*
buf
,
size_t
size
)
{
uint8_t
out
[
8192
];
struct
xz_dec
*
dec
=
xz_dec_init
(
XZ_DYNALLOC
,
1
<<
26
);
struct
xz_buf
b
=
{
.
in
=
buf
,
.
in_pos
=
0
,
.
in_size
=
size
,
.
out
=
out
,
.
out_pos
=
0
,
.
out_size
=
sizeof
(
out
)
};
enum
xz_ret
ret
;
do
{
ret
=
xz_dec_run
(
dec
,
&
b
);
if
(
ret
!=
XZ_OK
&&
ret
!=
XZ_STREAM_END
)
return
1
;
write
(
fd
,
out
,
b
.
out_pos
);
b
.
out_pos
=
0
;
}
while
(
b
.
in_pos
!=
size
);
return
0
;
}
static
int
dump_magisk
(
const
char
*
path
,
mode_t
mode
)
{
static
int
dump_magisk
(
const
char
*
path
,
mode_t
mode
)
{
int
fd
=
creat
(
path
,
mode
);
int
fd
=
creat
(
path
,
mode
);
xwrite
(
fd
,
magisk_bin
,
sizeof
(
magisk_bin
));
unxz
(
fd
,
magisk_xz
,
sizeof
(
magisk_xz
));
close
(
fd
);
close
(
fd
);
return
0
;
return
0
;
}
}
static
int
dump_manager
(
const
char
*
path
,
mode_t
mode
)
{
static
int
dump_manager
(
const
char
*
path
,
mode_t
mode
)
{
int
fd
=
creat
(
path
,
mode
);
int
fd
=
creat
(
path
,
mode
);
xwrite
(
fd
,
manager_bin
,
sizeof
(
manager_bin
));
unxz
(
fd
,
manager_xz
,
sizeof
(
manager_xz
));
close
(
fd
);
close
(
fd
);
return
0
;
return
0
;
}
}
...
...
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