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
2b3b087c
Commit
2b3b087c
authored
Mar 01, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add bzip2 support
parent
e08d46aa
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
80 additions
and
8 deletions
+80
-8
Android.mk
jni/magiskboot/Android.mk
+4
-2
compress.c
jni/magiskboot/compress.c
+70
-1
magiskboot.h
jni/magiskboot/magiskboot.h
+1
-0
repack.c
jni/magiskboot/repack.c
+1
-1
unpack.c
jni/magiskboot/unpack.c
+3
-3
ndk-compression
jni/ndk-compression
+1
-1
No files found.
jni/magiskboot/Android.mk
View file @
2b3b087c
...
...
@@ -2,10 +2,11 @@ LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := magiskboot
LOCAL_STATIC_LIBRARIES := liblzma liblz4
LOCAL_STATIC_LIBRARIES := liblzma liblz4
libbz2
LOCAL_C_INCLUDES := \
jni/ndk-compression/xz/src/liblzma/api/ \
jni/ndk-compression/lz4/lib/
jni/ndk-compression/lz4/lib/ \
jni/ndk-compression/bzip2
LOCAL_SRC_FILES := main.c unpack.c repack.c hexpatch.c parseimg.c compress.c
LOCAL_LDLIBS += -lz
...
...
@@ -13,3 +14,4 @@ include $(BUILD_EXECUTABLE)
include jni/ndk-compression/xz/src/liblzma/Android.mk
include jni/ndk-compression/lz4/lib/Android.mk
include jni/ndk-compression/bzip2/Android.mk
jni/magiskboot/compress.c
View file @
2b3b087c
#include <zlib.h>
#include <lzma.h>
#include <lz4frame.h>
#include <bzlib.h>
#include "magiskboot.h"
...
...
@@ -11,7 +12,7 @@ static int open_new(const char *filename) {
return
fd
;
}
static
void
write_file
(
const
int
fd
,
const
unsigned
char
*
buf
,
const
size_t
size
,
const
char
*
filename
)
{
static
void
write_file
(
const
int
fd
,
const
void
*
buf
,
const
size_t
size
,
const
char
*
filename
)
{
if
(
write
(
fd
,
buf
,
size
)
!=
size
)
error
(
1
,
"Error in writing %s"
,
filename
);
}
...
...
@@ -272,3 +273,71 @@ void lz4(int mode, const char* filename, unsigned char* buf, size_t size) {
free
(
out
);
}
// Mode: 0 = decode; 1 = encode
void
bzip2
(
int
mode
,
const
char
*
filename
,
unsigned
char
*
buf
,
size_t
size
)
{
size_t
ret
=
0
,
action
,
have
,
pos
=
0
;
bz_stream
strm
;
char
out
[
CHUNK
];
report
(
mode
,
filename
);
int
fd
=
open_new
(
filename
);
strm
.
bzalloc
=
NULL
;
strm
.
bzfree
=
NULL
;
strm
.
opaque
=
NULL
;
switch
(
mode
)
{
case
0
:
ret
=
BZ2_bzDecompressInit
(
&
strm
,
0
,
0
);
break
;
case
1
:
ret
=
BZ2_bzCompressInit
(
&
strm
,
9
,
0
,
0
);
break
;
default:
error
(
1
,
"Unsupported bzip2 mode!"
);
}
if
(
ret
!=
BZ_OK
)
error
(
1
,
"Unable to init bzlib stream"
);
do
{
strm
.
next_in
=
(
char
*
)
buf
+
pos
;
if
(
pos
+
CHUNK
>=
size
)
{
strm
.
avail_in
=
size
-
pos
;
action
=
BZ_FINISH
;
}
else
{
strm
.
avail_in
=
CHUNK
;
action
=
BZ_RUN
;
}
pos
+=
strm
.
avail_in
;
do
{
strm
.
avail_out
=
CHUNK
;
strm
.
next_out
=
out
;
switch
(
mode
)
{
case
0
:
ret
=
BZ2_bzDecompress
(
&
strm
);
break
;
case
1
:
ret
=
BZ2_bzCompress
(
&
strm
,
action
);
break
;
}
have
=
CHUNK
-
strm
.
avail_out
;
write_file
(
fd
,
out
,
have
,
filename
);
}
while
(
strm
.
avail_out
==
0
);
}
while
(
pos
<
size
);
switch
(
mode
)
{
case
0
:
BZ2_bzDecompressEnd
(
&
strm
);
break
;
case
1
:
BZ2_bzCompressEnd
(
&
strm
);
break
;
}
close
(
fd
);
}
jni/magiskboot/magiskboot.h
View file @
2b3b087c
...
...
@@ -60,5 +60,6 @@ void parse_img(unsigned char *orig, size_t size);
void
gzip
(
int
mode
,
const
char
*
filename
,
unsigned
char
*
buf
,
size_t
size
);
void
lzma
(
int
mode
,
const
char
*
filename
,
unsigned
char
*
buf
,
size_t
size
);
void
lz4
(
int
mode
,
const
char
*
filename
,
unsigned
char
*
buf
,
size_t
size
);
void
bzip2
(
int
mode
,
const
char
*
filename
,
unsigned
char
*
buf
,
size_t
size
);
#endif
jni/magiskboot/repack.c
View file @
2b3b087c
...
...
@@ -110,7 +110,7 @@ void repack(const char* image) {
break
;
case
BZIP2
:
sprintf
(
name
,
"%s.%s"
,
RAMDISK_FILE
,
"bz2"
);
error
(
1
,
"Unsupported format! Please compress manually!"
);
bzip2
(
1
,
name
,
cpio
,
cpio_size
);
break
;
case
LZ4
:
sprintf
(
name
,
"%s.%s"
,
RAMDISK_FILE
,
"lz4"
);
...
...
jni/magiskboot/unpack.c
View file @
2b3b087c
...
...
@@ -49,6 +49,8 @@ void unpack(const char* image) {
case
LZOP
:
sprintf
(
name
,
"%s.%s"
,
RAMDISK_FILE
,
"lzo"
);
printf
(
"Unsupported format! Please decompress manually!
\n
"
);
// Dump the compressed ramdisk
dump
(
ramdisk
,
hdr
.
ramdisk_size
,
name
);
break
;
case
XZ
:
sprintf
(
name
,
"%s.%s"
,
RAMDISK_FILE
,
"xz"
);
...
...
@@ -60,7 +62,7 @@ void unpack(const char* image) {
break
;
case
BZIP2
:
sprintf
(
name
,
"%s.%s"
,
RAMDISK_FILE
,
"bz2"
);
printf
(
"Unsupported format! Please decompress manually!
\n
"
);
bzip2
(
0
,
RAMDISK_FILE
,
ramdisk
,
hdr
.
ramdisk_size
);
break
;
case
LZ4
:
sprintf
(
name
,
"%s.%s"
,
RAMDISK_FILE
,
"lz4"
);
...
...
@@ -70,8 +72,6 @@ void unpack(const char* image) {
// Never happens
break
;
}
// Dump the compressed ramdisk, just in case
dump
(
ramdisk
,
hdr
.
ramdisk_size
,
name
);
if
(
hdr
.
second_size
)
{
// Dump second
...
...
ndk-compression
@
ca5279de
Subproject commit
602750457f2383f9a726eb12d2907f4ed282be91
Subproject commit
ca5279deaa9de6ac695af1c710353d616428e229
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