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
1def9b30
Commit
1def9b30
authored
Aug 09, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use xz-embedded for b64xz
parent
5bac442b
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
2976 additions
and
45 deletions
+2976
-45
build.py
build.py
+2
-2
build.gradle
native/build.gradle
+1
-1
Android.mk
native/jni/Android.mk
+3
-4
b64xz.c
native/jni/b64xz.c
+33
-38
Android.mk
native/jni/external/Android.mk
+10
-0
xz.h
native/jni/external/include/xz.h
+304
-0
xz_config.h
native/jni/external/xz-embedded/xz_config.h
+124
-0
xz_crc32.c
native/jni/external/xz-embedded/xz_crc32.c
+59
-0
xz_dec_lzma2.c
native/jni/external/xz-embedded/xz_dec_lzma2.c
+1171
-0
xz_dec_stream.c
native/jni/external/xz-embedded/xz_dec_stream.c
+847
-0
xz_lzma2.h
native/jni/external/xz-embedded/xz_lzma2.h
+204
-0
xz_private.h
native/jni/external/xz-embedded/xz_private.h
+156
-0
xz_stream.h
native/jni/external/xz-embedded/xz_stream.h
+62
-0
No files found.
build.py
View file @
1def9b30
...
...
@@ -300,11 +300,11 @@ def gen_update_binary():
binary
=
os
.
path
.
join
(
'native'
,
'out'
,
'armeabi-v7a'
,
'busybox'
)
with
open
(
binary
,
'rb'
)
as
busybox
:
update_bin
.
append
(
'
\'\n
BB_ARM='
)
update_bin
.
append
(
base64
.
b64encode
(
lzma
.
compress
(
busybox
.
read
(),
preset
=
9
))
.
decode
(
'ascii'
))
update_bin
.
append
(
base64
.
b64encode
(
lzma
.
compress
(
busybox
.
read
(),
preset
=
9
,
check
=
lzma
.
CHECK_NONE
))
.
decode
(
'ascii'
))
binary
=
os
.
path
.
join
(
'native'
,
'out'
,
'x86'
,
'busybox'
)
with
open
(
binary
,
'rb'
)
as
busybox
:
update_bin
.
append
(
'
\n
BB_X86='
)
update_bin
.
append
(
base64
.
b64encode
(
lzma
.
compress
(
busybox
.
read
(),
preset
=
9
))
.
decode
(
'ascii'
))
update_bin
.
append
(
base64
.
b64encode
(
lzma
.
compress
(
busybox
.
read
(),
preset
=
9
,
check
=
lzma
.
CHECK_NONE
))
.
decode
(
'ascii'
))
update_bin
.
append
(
'
\n
'
)
with
open
(
os
.
path
.
join
(
'scripts'
,
'update_binary.sh'
),
'r'
)
as
script
:
update_bin
.
append
(
script
.
read
())
...
...
native/build.gradle
View file @
1def9b30
...
...
@@ -14,7 +14,7 @@ android {
externalNativeBuild
{
ndkBuild
{
// Pass arguments to ndk-build.
arguments
(
'B_MAGISK=1'
,
'B_INIT=1'
,
'B_BOOT=1'
,
'MAGISK_VERSION=debug'
,
arguments
(
'B_MAGISK=1'
,
'B_INIT=1'
,
'B_BOOT=1'
,
'
B_BXZ=1'
,
'
MAGISK_VERSION=debug'
,
'MAGISK_VER_CODE=99999'
,
'MAGISK_DEBUG=-DMAGISK_DEBUG'
)
}
}
...
...
native/jni/Android.mk
View file @
1def9b30
...
...
@@ -73,8 +73,7 @@ LOCAL_C_INCLUDES := \
jni/magiskpolicy \
out \
out/$(TARGET_ARCH_ABI) \
$(LIBSEPOL) \
$(LIBLZMA)
$(LIBSEPOL)
LOCAL_SRC_FILES := \
core/magiskinit.c \
...
...
@@ -126,8 +125,8 @@ ifdef B_BXZ
# b64xz
include $(CLEAR_VARS)
LOCAL_MODULE := b64xz
LOCAL_STATIC_LIBRARIES := lib
lzma
LOCAL_C_INCLUDES := $(
LIBLZMA)
LOCAL_STATIC_LIBRARIES := lib
xz
LOCAL_C_INCLUDES := $(
EXT_PATH)/include
LOCAL_SRC_FILES := b64xz.c
LOCAL_LDFLAGS := -static
include $(BUILD_EXECUTABLE)
...
...
native/jni/b64xz.c
View file @
1def9b30
/* b64xz.c - Base64-XZ Extractor
*
* This program expects data from stdin. The data should be compressed with xz and
* then encoded into base64 format. What b64xz does is basically the reverse of the
* mentioned process: decode base64 to uint8_ts, decompress xz, then dump to stdout
* This program converts data from stdin to stdout.
* The input should be compressed with xz (integrity check only support CRC32 or none) and then
* encoded into base64 format. What b64xz does is basically the reverse of the
* mentioned process: decode base64 to bytes, decompress xz, then dump to stdout
*
* The compiled binary will be hex-dumped into update-binary
* Busybox will be xz-compressed, base64 encoded and dumped into update-binary
* This program is to recover busybox for Magisk installation environment
*
* I intentionally removed stdio. This will result in a smaller binary size because
* all I/O are handled by system calls (read/write) instead of libc wrappers
*/
#include <unistd.h>
#include <lzma.h>
#define BUFSIZE 8192
#include <xz.h>
static
const
char
trans_tbl
[]
=
"|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[
\\
]^_`abcdefghijklmnopq"
;
...
...
@@ -26,37 +22,39 @@ static void decodeblock(uint8_t* in, uint8_t* out) {
out
[
2
]
=
(
uint8_t
)(((
in
[
2
]
<<
6
)
&
0xc0
)
|
in
[
3
]);
}
static
int
unxz
(
lzma_stream
*
strm
,
void
*
buf
,
size_t
size
)
{
lzma_ret
ret
=
0
;
uint8_t
out
[
BUFSIZE
];
strm
->
next_in
=
buf
;
strm
->
avail_in
=
size
;
static
int
unxz
(
struct
xz_dec
*
dec
,
void
*
buf
,
unsigned
size
)
{
uint8_t
out
[
8192
];
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
{
strm
->
next_out
=
out
;
strm
->
avail_out
=
sizeof
(
out
);
ret
=
lzma_code
(
strm
,
LZMA_RUN
);
write
(
STDOUT_FILENO
,
out
,
sizeof
(
out
)
-
strm
->
avail_out
);
}
while
(
strm
->
avail_out
==
0
&&
ret
==
LZMA_OK
);
if
(
ret
!=
LZMA_OK
&&
ret
!=
LZMA_STREAM_END
)
write
(
STDERR_FILENO
,
"LZMA error!
\n
"
,
13
);
return
ret
;
ret
=
xz_dec_run
(
dec
,
&
b
);
if
(
ret
!=
XZ_OK
&&
ret
!=
XZ_STREAM_END
)
return
1
;
write
(
STDOUT_FILENO
,
out
,
b
.
out_pos
);
b
.
out_pos
=
0
;
}
while
(
b
.
in_pos
!=
size
);
return
0
;
}
int
main
(
int
argc
,
char
const
*
argv
[])
{
if
(
argc
>
1
)
return
0
;
uint8_t
in
[
4
],
buf
[
BUFSIZE
];
int
len
=
0
,
pos
=
0
;
uint8_t
in
[
4
],
buf
[
6144
];
unsigned
len
=
0
,
pos
=
0
;
char
c
;
// Setup lzma stream
lzma_stream
strm
=
LZMA_STREAM_INIT
;
if
(
lzma_auto_decoder
(
&
strm
,
UINT64_MAX
,
0
)
!=
LZMA_OK
)
{
write
(
STDERR_FILENO
,
"Unable to init lzma stream
\n
"
,
28
);
xz_crc32_init
();
struct
xz_dec
*
dec
=
xz_dec_init
(
XZ_DYNALLOC
,
1
<<
26
);
if
(
dec
==
NULL
)
return
1
;
}
while
(
read
(
STDIN_FILENO
,
&
c
,
sizeof
(
c
))
==
1
)
{
c
=
((
c
<
43
||
c
>
122
)
?
-
1
:
(
trans_tbl
[
c
-
43
]
==
'$'
?
-
1
:
trans_tbl
[
c
-
43
]
-
62
));
...
...
@@ -67,17 +65,14 @@ int main(int argc, char const* argv[]) {
len
=
0
;
decodeblock
(
in
,
buf
+
pos
);
pos
+=
3
;
if
(
pos
>
sizeof
(
buf
)
-
3
)
{
// Buffer is full, unxz
if
(
unxz
(
&
strm
,
buf
,
pos
))
if
(
pos
==
sizeof
(
buf
))
{
if
(
unxz
(
dec
,
buf
,
pos
))
return
1
;
pos
=
0
;
}
}
if
(
pos
)
{
if
(
unxz
(
&
strm
,
buf
,
pos
))
if
(
pos
&&
unxz
(
dec
,
buf
,
pos
))
return
1
;
}
lzma_end
(
&
strm
);
xz_dec_end
(
dec
);
return
0
;
}
native/jni/external/Android.mk
View file @
1def9b30
...
...
@@ -14,6 +14,16 @@ LOCAL_C_INCLUDES := $(LIBSELINUX)
LOCAL_SRC_FILES := stubs/selinux_stub.c
include $(BUILD_SHARED_LIBRARY)
# libxz.a
include $(CLEAR_VARS)
LOCAL_MODULE:= libxz
LOCAL_C_INCLUDES := $(EXT_PATH)/include
LOCAL_SRC_FILES := \
xz-embedded/xz_crc32.c \
xz-embedded/xz_dec_lzma2.c \
xz-embedded/xz_dec_stream.c
include $(BUILD_STATIC_LIBRARY)
# libmincrypt.a
include $(CLEAR_VARS)
LOCAL_MODULE:= libmincrypt
...
...
native/jni/external/include/xz.h
0 → 100644
View file @
1def9b30
This diff is collapsed.
Click to expand it.
native/jni/external/xz-embedded/xz_config.h
0 → 100644
View file @
1def9b30
/*
* Private includes and definitions for userspace use of XZ Embedded
*
* Author: Lasse Collin <lasse.collin@tukaani.org>
*
* This file has been put into the public domain.
* You can do whatever you want with this file.
*/
#ifndef XZ_CONFIG_H
#define XZ_CONFIG_H
/* Uncomment to enable CRC64 support. */
/* #define XZ_USE_CRC64 */
/* Uncomment as needed to enable BCJ filter decoders. */
/* #define XZ_DEC_X86 */
/* #define XZ_DEC_POWERPC */
/* #define XZ_DEC_IA64 */
/* #define XZ_DEC_ARM */
/* #define XZ_DEC_ARMTHUMB */
/* #define XZ_DEC_SPARC */
/*
* MSVC doesn't support modern C but XZ Embedded is mostly C89
* so these are enough.
*/
#ifdef _MSC_VER
typedef
unsigned
char
bool
;
# define true 1
# define false 0
# define inline __inline
#else
# include <stdbool.h>
#endif
#include <stdlib.h>
#include <string.h>
#include "xz.h"
#define kmalloc(size, flags) malloc(size)
#define kfree(ptr) free(ptr)
#define vmalloc(size) malloc(size)
#define vfree(ptr) free(ptr)
#define memeq(a, b, size) (memcmp(a, b, size) == 0)
#define memzero(buf, size) memset(buf, 0, size)
#ifndef min
# define min(x, y) ((x) < (y) ? (x) : (y))
#endif
#define min_t(type, x, y) min(x, y)
/*
* Some functions have been marked with __always_inline to keep the
* performance reasonable even when the compiler is optimizing for
* small code size. You may be able to save a few bytes by #defining
* __always_inline to plain inline, but don't complain if the code
* becomes slow.
*
* NOTE: System headers on GNU/Linux may #define this macro already,
* so if you want to change it, you need to #undef it first.
*/
#ifndef __always_inline
# ifdef __GNUC__
# define __always_inline \
inline __attribute__((__always_inline__))
# else
# define __always_inline inline
# endif
#endif
/* Inline functions to access unaligned unsigned 32-bit integers */
#ifndef get_unaligned_le32
static
inline
uint32_t
get_unaligned_le32
(
const
uint8_t
*
buf
)
{
return
(
uint32_t
)
buf
[
0
]
|
((
uint32_t
)
buf
[
1
]
<<
8
)
|
((
uint32_t
)
buf
[
2
]
<<
16
)
|
((
uint32_t
)
buf
[
3
]
<<
24
);
}
#endif
#ifndef get_unaligned_be32
static
inline
uint32_t
get_unaligned_be32
(
const
uint8_t
*
buf
)
{
return
(
uint32_t
)(
buf
[
0
]
<<
24
)
|
((
uint32_t
)
buf
[
1
]
<<
16
)
|
((
uint32_t
)
buf
[
2
]
<<
8
)
|
(
uint32_t
)
buf
[
3
];
}
#endif
#ifndef put_unaligned_le32
static
inline
void
put_unaligned_le32
(
uint32_t
val
,
uint8_t
*
buf
)
{
buf
[
0
]
=
(
uint8_t
)
val
;
buf
[
1
]
=
(
uint8_t
)(
val
>>
8
);
buf
[
2
]
=
(
uint8_t
)(
val
>>
16
);
buf
[
3
]
=
(
uint8_t
)(
val
>>
24
);
}
#endif
#ifndef put_unaligned_be32
static
inline
void
put_unaligned_be32
(
uint32_t
val
,
uint8_t
*
buf
)
{
buf
[
0
]
=
(
uint8_t
)(
val
>>
24
);
buf
[
1
]
=
(
uint8_t
)(
val
>>
16
);
buf
[
2
]
=
(
uint8_t
)(
val
>>
8
);
buf
[
3
]
=
(
uint8_t
)
val
;
}
#endif
/*
* Use get_unaligned_le32() also for aligned access for simplicity. On
* little endian systems, #define get_le32(ptr) (*(const uint32_t *)(ptr))
* could save a few bytes in code size.
*/
#ifndef get_le32
# define get_le32 get_unaligned_le32
#endif
#endif
native/jni/external/xz-embedded/xz_crc32.c
0 → 100644
View file @
1def9b30
/*
* CRC32 using the polynomial from IEEE-802.3
*
* Authors: Lasse Collin <lasse.collin@tukaani.org>
* Igor Pavlov <http://7-zip.org/>
*
* This file has been put into the public domain.
* You can do whatever you want with this file.
*/
/*
* This is not the fastest implementation, but it is pretty compact.
* The fastest versions of xz_crc32() on modern CPUs without hardware
* accelerated CRC instruction are 3-5 times as fast as this version,
* but they are bigger and use more memory for the lookup table.
*/
#include "xz_private.h"
/*
* STATIC_RW_DATA is used in the pre-boot environment on some architectures.
* See <linux/decompress/mm.h> for details.
*/
#ifndef STATIC_RW_DATA
# define STATIC_RW_DATA static
#endif
STATIC_RW_DATA
uint32_t
xz_crc32_table
[
256
];
XZ_EXTERN
void
xz_crc32_init
(
void
)
{
const
uint32_t
poly
=
0xEDB88320
;
uint32_t
i
;
uint32_t
j
;
uint32_t
r
;
for
(
i
=
0
;
i
<
256
;
++
i
)
{
r
=
i
;
for
(
j
=
0
;
j
<
8
;
++
j
)
r
=
(
r
>>
1
)
^
(
poly
&
~
((
r
&
1
)
-
1
));
xz_crc32_table
[
i
]
=
r
;
}
return
;
}
XZ_EXTERN
uint32_t
xz_crc32
(
const
uint8_t
*
buf
,
size_t
size
,
uint32_t
crc
)
{
crc
=
~
crc
;
while
(
size
!=
0
)
{
crc
=
xz_crc32_table
[
*
buf
++
^
(
crc
&
0xFF
)]
^
(
crc
>>
8
);
--
size
;
}
return
~
crc
;
}
native/jni/external/xz-embedded/xz_dec_lzma2.c
0 → 100644
View file @
1def9b30
This diff is collapsed.
Click to expand it.
native/jni/external/xz-embedded/xz_dec_stream.c
0 → 100644
View file @
1def9b30
This diff is collapsed.
Click to expand it.
native/jni/external/xz-embedded/xz_lzma2.h
0 → 100644
View file @
1def9b30
/*
* LZMA2 definitions
*
* Authors: Lasse Collin <lasse.collin@tukaani.org>
* Igor Pavlov <http://7-zip.org/>
*
* This file has been put into the public domain.
* You can do whatever you want with this file.
*/
#ifndef XZ_LZMA2_H
#define XZ_LZMA2_H
/* Range coder constants */
#define RC_SHIFT_BITS 8
#define RC_TOP_BITS 24
#define RC_TOP_VALUE (1 << RC_TOP_BITS)
#define RC_BIT_MODEL_TOTAL_BITS 11
#define RC_BIT_MODEL_TOTAL (1 << RC_BIT_MODEL_TOTAL_BITS)
#define RC_MOVE_BITS 5
/*
* Maximum number of position states. A position state is the lowest pb
* number of bits of the current uncompressed offset. In some places there
* are different sets of probabilities for different position states.
*/
#define POS_STATES_MAX (1 << 4)
/*
* This enum is used to track which LZMA symbols have occurred most recently
* and in which order. This information is used to predict the next symbol.
*
* Symbols:
* - Literal: One 8-bit byte
* - Match: Repeat a chunk of data at some distance
* - Long repeat: Multi-byte match at a recently seen distance
* - Short repeat: One-byte repeat at a recently seen distance
*
* The symbol names are in from STATE_oldest_older_previous. REP means
* either short or long repeated match, and NONLIT means any non-literal.
*/
enum
lzma_state
{
STATE_LIT_LIT
,
STATE_MATCH_LIT_LIT
,
STATE_REP_LIT_LIT
,
STATE_SHORTREP_LIT_LIT
,
STATE_MATCH_LIT
,
STATE_REP_LIT
,
STATE_SHORTREP_LIT
,
STATE_LIT_MATCH
,
STATE_LIT_LONGREP
,
STATE_LIT_SHORTREP
,
STATE_NONLIT_MATCH
,
STATE_NONLIT_REP
};
/* Total number of states */
#define STATES 12
/* The lowest 7 states indicate that the previous state was a literal. */
#define LIT_STATES 7
/* Indicate that the latest symbol was a literal. */
static
inline
void
lzma_state_literal
(
enum
lzma_state
*
state
)
{
if
(
*
state
<=
STATE_SHORTREP_LIT_LIT
)
*
state
=
STATE_LIT_LIT
;
else
if
(
*
state
<=
STATE_LIT_SHORTREP
)
*
state
-=
3
;
else
*
state
-=
6
;
}
/* Indicate that the latest symbol was a match. */
static
inline
void
lzma_state_match
(
enum
lzma_state
*
state
)
{
*
state
=
*
state
<
LIT_STATES
?
STATE_LIT_MATCH
:
STATE_NONLIT_MATCH
;
}
/* Indicate that the latest state was a long repeated match. */
static
inline
void
lzma_state_long_rep
(
enum
lzma_state
*
state
)
{
*
state
=
*
state
<
LIT_STATES
?
STATE_LIT_LONGREP
:
STATE_NONLIT_REP
;
}
/* Indicate that the latest symbol was a short match. */
static
inline
void
lzma_state_short_rep
(
enum
lzma_state
*
state
)
{
*
state
=
*
state
<
LIT_STATES
?
STATE_LIT_SHORTREP
:
STATE_NONLIT_REP
;
}
/* Test if the previous symbol was a literal. */
static
inline
bool
lzma_state_is_literal
(
enum
lzma_state
state
)
{
return
state
<
LIT_STATES
;
}
/* Each literal coder is divided in three sections:
* - 0x001-0x0FF: Without match byte
* - 0x101-0x1FF: With match byte; match bit is 0
* - 0x201-0x2FF: With match byte; match bit is 1
*
* Match byte is used when the previous LZMA symbol was something else than
* a literal (that is, it was some kind of match).
*/
#define LITERAL_CODER_SIZE 0x300
/* Maximum number of literal coders */
#define LITERAL_CODERS_MAX (1 << 4)
/* Minimum length of a match is two bytes. */
#define MATCH_LEN_MIN 2
/* Match length is encoded with 4, 5, or 10 bits.
*
* Length Bits
* 2-9 4 = Choice=0 + 3 bits
* 10-17 5 = Choice=1 + Choice2=0 + 3 bits
* 18-273 10 = Choice=1 + Choice2=1 + 8 bits
*/
#define LEN_LOW_BITS 3
#define LEN_LOW_SYMBOLS (1 << LEN_LOW_BITS)
#define LEN_MID_BITS 3
#define LEN_MID_SYMBOLS (1 << LEN_MID_BITS)
#define LEN_HIGH_BITS 8
#define LEN_HIGH_SYMBOLS (1 << LEN_HIGH_BITS)
#define LEN_SYMBOLS (LEN_LOW_SYMBOLS + LEN_MID_SYMBOLS + LEN_HIGH_SYMBOLS)
/*
* Maximum length of a match is 273 which is a result of the encoding
* described above.
*/
#define MATCH_LEN_MAX (MATCH_LEN_MIN + LEN_SYMBOLS - 1)
/*
* Different sets of probabilities are used for match distances that have
* very short match length: Lengths of 2, 3, and 4 bytes have a separate
* set of probabilities for each length. The matches with longer length
* use a shared set of probabilities.
*/
#define DIST_STATES 4
/*
* Get the index of the appropriate probability array for decoding
* the distance slot.
*/
static
inline
uint32_t
lzma_get_dist_state
(
uint32_t
len
)
{
return
len
<
DIST_STATES
+
MATCH_LEN_MIN
?
len
-
MATCH_LEN_MIN
:
DIST_STATES
-
1
;
}
/*
* The highest two bits of a 32-bit match distance are encoded using six bits.
* This six-bit value is called a distance slot. This way encoding a 32-bit
* value takes 6-36 bits, larger values taking more bits.
*/
#define DIST_SLOT_BITS 6
#define DIST_SLOTS (1 << DIST_SLOT_BITS)
/* Match distances up to 127 are fully encoded using probabilities. Since
* the highest two bits (distance slot) are always encoded using six bits,
* the distances 0-3 don't need any additional bits to encode, since the
* distance slot itself is the same as the actual distance. DIST_MODEL_START
* indicates the first distance slot where at least one additional bit is
* needed.
*/
#define DIST_MODEL_START 4
/*
* Match distances greater than 127 are encoded in three pieces:
* - distance slot: the highest two bits
* - direct bits: 2-26 bits below the highest two bits
* - alignment bits: four lowest bits
*
* Direct bits don't use any probabilities.
*
* The distance slot value of 14 is for distances 128-191.
*/
#define DIST_MODEL_END 14
/* Distance slots that indicate a distance <= 127. */
#define FULL_DISTANCES_BITS (DIST_MODEL_END / 2)
#define FULL_DISTANCES (1 << FULL_DISTANCES_BITS)
/*
* For match distances greater than 127, only the highest two bits and the
* lowest four bits (alignment) is encoded using probabilities.
*/
#define ALIGN_BITS 4
#define ALIGN_SIZE (1 << ALIGN_BITS)
#define ALIGN_MASK (ALIGN_SIZE - 1)
/* Total number of all probability variables */
#define PROBS_TOTAL (1846 + LITERAL_CODERS_MAX * LITERAL_CODER_SIZE)
/*
* LZMA remembers the four most recent match distances. Reusing these
* distances tends to take less space than re-encoding the actual
* distance value.
*/
#define REPS 4
#endif
native/jni/external/xz-embedded/xz_private.h
0 → 100644
View file @
1def9b30
/*
* Private includes and definitions
*
* Author: Lasse Collin <lasse.collin@tukaani.org>
*
* This file has been put into the public domain.
* You can do whatever you want with this file.
*/
#ifndef XZ_PRIVATE_H
#define XZ_PRIVATE_H
#ifdef __KERNEL__
# include <linux/xz.h>
# include <linux/kernel.h>
# include <asm/unaligned.h>
/* XZ_PREBOOT may be defined only via decompress_unxz.c. */
# ifndef XZ_PREBOOT
# include <linux/slab.h>
# include <linux/vmalloc.h>
# include <linux/string.h>
# ifdef CONFIG_XZ_DEC_X86
# define XZ_DEC_X86
# endif
# ifdef CONFIG_XZ_DEC_POWERPC
# define XZ_DEC_POWERPC
# endif
# ifdef CONFIG_XZ_DEC_IA64
# define XZ_DEC_IA64
# endif
# ifdef CONFIG_XZ_DEC_ARM
# define XZ_DEC_ARM
# endif
# ifdef CONFIG_XZ_DEC_ARMTHUMB
# define XZ_DEC_ARMTHUMB
# endif
# ifdef CONFIG_XZ_DEC_SPARC
# define XZ_DEC_SPARC
# endif
# define memeq(a, b, size) (memcmp(a, b, size) == 0)
# define memzero(buf, size) memset(buf, 0, size)
# endif
# define get_le32(p) le32_to_cpup((const uint32_t *)(p))
#else
/*
* For userspace builds, use a separate header to define the required
* macros and functions. This makes it easier to adapt the code into
* different environments and avoids clutter in the Linux kernel tree.
*/
# include "xz_config.h"
#endif
/* If no specific decoding mode is requested, enable support for all modes. */
#if !defined(XZ_DEC_SINGLE) && !defined(XZ_DEC_PREALLOC) \
&& !defined(XZ_DEC_DYNALLOC)
# define XZ_DEC_SINGLE
# define XZ_DEC_PREALLOC
# define XZ_DEC_DYNALLOC
#endif
/*
* The DEC_IS_foo(mode) macros are used in "if" statements. If only some
* of the supported modes are enabled, these macros will evaluate to true or
* false at compile time and thus allow the compiler to omit unneeded code.
*/
#ifdef XZ_DEC_SINGLE
# define DEC_IS_SINGLE(mode) ((mode) == XZ_SINGLE)
#else
# define DEC_IS_SINGLE(mode) (false)
#endif
#ifdef XZ_DEC_PREALLOC
# define DEC_IS_PREALLOC(mode) ((mode) == XZ_PREALLOC)
#else
# define DEC_IS_PREALLOC(mode) (false)
#endif
#ifdef XZ_DEC_DYNALLOC
# define DEC_IS_DYNALLOC(mode) ((mode) == XZ_DYNALLOC)
#else
# define DEC_IS_DYNALLOC(mode) (false)
#endif
#if !defined(XZ_DEC_SINGLE)
# define DEC_IS_MULTI(mode) (true)
#elif defined(XZ_DEC_PREALLOC) || defined(XZ_DEC_DYNALLOC)
# define DEC_IS_MULTI(mode) ((mode) != XZ_SINGLE)
#else
# define DEC_IS_MULTI(mode) (false)
#endif
/*
* If any of the BCJ filter decoders are wanted, define XZ_DEC_BCJ.
* XZ_DEC_BCJ is used to enable generic support for BCJ decoders.
*/
#ifndef XZ_DEC_BCJ
# if defined(XZ_DEC_X86) || defined(XZ_DEC_POWERPC) \
|| defined(XZ_DEC_IA64) || defined(XZ_DEC_ARM) \
|| defined(XZ_DEC_ARM) || defined(XZ_DEC_ARMTHUMB) \
|| defined(XZ_DEC_SPARC)
# define XZ_DEC_BCJ
# endif
#endif
/*
* Allocate memory for LZMA2 decoder. xz_dec_lzma2_reset() must be used
* before calling xz_dec_lzma2_run().
*/
XZ_EXTERN
struct
xz_dec_lzma2
*
xz_dec_lzma2_create
(
enum
xz_mode
mode
,
uint32_t
dict_max
);
/*
* Decode the LZMA2 properties (one byte) and reset the decoder. Return
* XZ_OK on success, XZ_MEMLIMIT_ERROR if the preallocated dictionary is not
* big enough, and XZ_OPTIONS_ERROR if props indicates something that this
* decoder doesn't support.
*/
XZ_EXTERN
enum
xz_ret
xz_dec_lzma2_reset
(
struct
xz_dec_lzma2
*
s
,
uint8_t
props
);
/* Decode raw LZMA2 stream from b->in to b->out. */
XZ_EXTERN
enum
xz_ret
xz_dec_lzma2_run
(
struct
xz_dec_lzma2
*
s
,
struct
xz_buf
*
b
);
/* Free the memory allocated for the LZMA2 decoder. */
XZ_EXTERN
void
xz_dec_lzma2_end
(
struct
xz_dec_lzma2
*
s
);
#ifdef XZ_DEC_BCJ
/*
* Allocate memory for BCJ decoders. xz_dec_bcj_reset() must be used before
* calling xz_dec_bcj_run().
*/
XZ_EXTERN
struct
xz_dec_bcj
*
xz_dec_bcj_create
(
bool
single_call
);
/*
* Decode the Filter ID of a BCJ filter. This implementation doesn't
* support custom start offsets, so no decoding of Filter Properties
* is needed. Returns XZ_OK if the given Filter ID is supported.
* Otherwise XZ_OPTIONS_ERROR is returned.
*/
XZ_EXTERN
enum
xz_ret
xz_dec_bcj_reset
(
struct
xz_dec_bcj
*
s
,
uint8_t
id
);
/*
* Decode raw BCJ + LZMA2 stream. This must be used only if there actually is
* a BCJ filter in the chain. If the chain has only LZMA2, xz_dec_lzma2_run()
* must be called directly.
*/
XZ_EXTERN
enum
xz_ret
xz_dec_bcj_run
(
struct
xz_dec_bcj
*
s
,
struct
xz_dec_lzma2
*
lzma2
,
struct
xz_buf
*
b
);
/* Free the memory allocated for the BCJ filters. */
#define xz_dec_bcj_end(s) kfree(s)
#endif
#endif
native/jni/external/xz-embedded/xz_stream.h
0 → 100644
View file @
1def9b30
/*
* Definitions for handling the .xz file format
*
* Author: Lasse Collin <lasse.collin@tukaani.org>
*
* This file has been put into the public domain.
* You can do whatever you want with this file.
*/
#ifndef XZ_STREAM_H
#define XZ_STREAM_H
#if defined(__KERNEL__) && !XZ_INTERNAL_CRC32
# include <linux/crc32.h>
# undef crc32
# define xz_crc32(buf, size, crc) \
(~crc32_le(~(uint32_t)(crc), buf, size))
#endif
/*
* See the .xz file format specification at
* http://tukaani.org/xz/xz-file-format.txt
* to understand the container format.
*/
#define STREAM_HEADER_SIZE 12
#define HEADER_MAGIC "\3757zXZ"
#define HEADER_MAGIC_SIZE 6
#define FOOTER_MAGIC "YZ"
#define FOOTER_MAGIC_SIZE 2
/*
* Variable-length integer can hold a 63-bit unsigned integer or a special
* value indicating that the value is unknown.
*
* Experimental: vli_type can be defined to uint32_t to save a few bytes
* in code size (no effect on speed). Doing so limits the uncompressed and
* compressed size of the file to less than 256 MiB and may also weaken
* error detection slightly.
*/
typedef
uint64_t
vli_type
;
#define VLI_MAX ((vli_type)-1 / 2)
#define VLI_UNKNOWN ((vli_type)-1)
/* Maximum encoded size of a VLI */
#define VLI_BYTES_MAX (sizeof(vli_type) * 8 / 7)
/* Integrity Check types */
enum
xz_check
{
XZ_CHECK_NONE
=
0
,
XZ_CHECK_CRC32
=
1
,
XZ_CHECK_CRC64
=
4
,
XZ_CHECK_SHA256
=
10
};
/* Maximum possible Check ID */
#define XZ_CHECK_MAX 15
#endif
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