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
dfee9954
Commit
dfee9954
authored
Jan 28, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Small refactor of magiskboot
parent
eed86c76
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
37 additions
and
56 deletions
+37
-56
Android.mk
native/jni/Android.mk
+1
-1
bootimg.c
native/jni/magiskboot/bootimg.c
+16
-17
bootimg.h
native/jni/magiskboot/bootimg.h
+3
-22
compress.c
native/jni/magiskboot/compress.c
+4
-4
format.c
native/jni/magiskboot/format.c
+4
-4
format.h
native/jni/magiskboot/format.h
+7
-6
magiskboot.h
native/jni/magiskboot/magiskboot.h
+2
-2
No files found.
native/jni/Android.mk
View file @
dfee9954
...
@@ -102,7 +102,7 @@ LOCAL_SRC_FILES := \
...
@@ -102,7 +102,7 @@ LOCAL_SRC_FILES := \
magiskboot/bootimg.c \
magiskboot/bootimg.c \
magiskboot/hexpatch.c \
magiskboot/hexpatch.c \
magiskboot/compress.c \
magiskboot/compress.c \
magiskboot/
types
.c \
magiskboot/
format
.c \
magiskboot/dtb.c \
magiskboot/dtb.c \
magiskboot/ramdisk.c \
magiskboot/ramdisk.c \
$(UTIL_SRC)
$(UTIL_SRC)
...
...
native/jni/magiskboot/bootimg.c
View file @
dfee9954
...
@@ -87,7 +87,7 @@ int parse_img(const char *image, boot_img *boot) {
...
@@ -87,7 +87,7 @@ int parse_img(const char *image, boot_img *boot) {
for
(
void
*
head
=
boot
->
map_addr
;
head
<
boot
->
map_addr
+
boot
->
map_size
;
head
+=
256
)
{
for
(
void
*
head
=
boot
->
map_addr
;
head
<
boot
->
map_addr
+
boot
->
map_size
;
head
+=
256
)
{
size_t
pos
=
0
;
size_t
pos
=
0
;
switch
(
check_
type
(
head
))
{
switch
(
check_
fmt
(
head
))
{
case
CHROMEOS
:
case
CHROMEOS
:
// The caller should know it's chromeos, as it needs additional signing
// The caller should know it's chromeos, as it needs additional signing
boot
->
flags
|=
CHROMEOS_FLAG
;
boot
->
flags
|=
CHROMEOS_FLAG
;
...
@@ -147,11 +147,11 @@ int parse_img(const char *image, boot_img *boot) {
...
@@ -147,11 +147,11 @@ int parse_img(const char *image, boot_img *boot) {
}
}
}
}
boot
->
k
ernel_type
=
check_type
(
boot
->
kernel
);
boot
->
k
_fmt
=
check_fmt
(
boot
->
kernel
);
boot
->
r
amdisk_type
=
check_type
(
boot
->
ramdisk
);
boot
->
r
_fmt
=
check_fmt
(
boot
->
ramdisk
);
// Check MTK
// Check MTK
if
(
boot
->
k
ernel_type
==
MTK
)
{
if
(
boot
->
k
_fmt
==
MTK
)
{
fprintf
(
stderr
,
"MTK_KERNEL_HDR
\n
"
);
fprintf
(
stderr
,
"MTK_KERNEL_HDR
\n
"
);
boot
->
flags
|=
MTK_KERNEL
;
boot
->
flags
|=
MTK_KERNEL
;
boot
->
k_hdr
=
malloc
(
sizeof
(
mtk_hdr
));
boot
->
k_hdr
=
malloc
(
sizeof
(
mtk_hdr
));
...
@@ -160,9 +160,9 @@ int parse_img(const char *image, boot_img *boot) {
...
@@ -160,9 +160,9 @@ int parse_img(const char *image, boot_img *boot) {
fprintf
(
stderr
,
"NAME [%s]
\n
"
,
boot
->
k_hdr
->
name
);
fprintf
(
stderr
,
"NAME [%s]
\n
"
,
boot
->
k_hdr
->
name
);
boot
->
kernel
+=
512
;
boot
->
kernel
+=
512
;
lheader
(
boot
,
kernel_size
,
-=
512
);
lheader
(
boot
,
kernel_size
,
-=
512
);
boot
->
k
ernel_type
=
check_type
(
boot
->
kernel
);
boot
->
k
_fmt
=
check_fmt
(
boot
->
kernel
);
}
}
if
(
boot
->
r
amdisk_type
==
MTK
)
{
if
(
boot
->
r
_fmt
==
MTK
)
{
fprintf
(
stderr
,
"MTK_RAMDISK_HDR
\n
"
);
fprintf
(
stderr
,
"MTK_RAMDISK_HDR
\n
"
);
boot
->
flags
|=
MTK_RAMDISK
;
boot
->
flags
|=
MTK_RAMDISK
;
boot
->
r_hdr
=
malloc
(
sizeof
(
mtk_hdr
));
boot
->
r_hdr
=
malloc
(
sizeof
(
mtk_hdr
));
...
@@ -171,14 +171,13 @@ int parse_img(const char *image, boot_img *boot) {
...
@@ -171,14 +171,13 @@ int parse_img(const char *image, boot_img *boot) {
fprintf
(
stderr
,
"NAME [%s]
\n
"
,
boot
->
r_hdr
->
name
);
fprintf
(
stderr
,
"NAME [%s]
\n
"
,
boot
->
r_hdr
->
name
);
boot
->
ramdisk
+=
512
;
boot
->
ramdisk
+=
512
;
lheader
(
boot
,
ramdisk_size
,
-=
512
);
lheader
(
boot
,
ramdisk_size
,
-=
512
);
boot
->
r
amdisk_type
=
check_type
(
boot
->
ramdisk
);
boot
->
r
_fmt
=
check_fmt
(
boot
->
ramdisk
);
}
}
char
fmt
[
16
];
char
fmt
[
16
];
get_fmt_name
(
boot
->
k_fmt
,
fmt
);
get_type_name
(
boot
->
kernel_type
,
fmt
);
fprintf
(
stderr
,
"KERNEL_FMT [%s]
\n
"
,
fmt
);
fprintf
(
stderr
,
"KERNEL_FMT [%s]
\n
"
,
fmt
);
get_
type_name
(
boot
->
ramdisk_type
,
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
:
...
@@ -196,9 +195,9 @@ int unpack(const char *image) {
...
@@ -196,9 +195,9 @@ int unpack(const char *image) {
int
fd
;
int
fd
;
// Dump kernel
// Dump kernel
if
(
COMPRESSED
(
boot
.
k
ernel_type
))
{
if
(
COMPRESSED
(
boot
.
k
_fmt
))
{
fd
=
creat
(
KERNEL_FILE
,
0644
);
fd
=
creat
(
KERNEL_FILE
,
0644
);
decomp
(
boot
.
k
ernel_type
,
fd
,
boot
.
kernel
,
header
(
&
boot
,
kernel_size
));
decomp
(
boot
.
k
_fmt
,
fd
,
boot
.
kernel
,
header
(
&
boot
,
kernel_size
));
close
(
fd
);
close
(
fd
);
}
else
{
}
else
{
dump
(
boot
.
kernel
,
header
(
&
boot
,
kernel_size
),
KERNEL_FILE
);
dump
(
boot
.
kernel
,
header
(
&
boot
,
kernel_size
),
KERNEL_FILE
);
...
@@ -210,9 +209,9 @@ int unpack(const char *image) {
...
@@ -210,9 +209,9 @@ int unpack(const char *image) {
}
}
// Dump ramdisk
// Dump ramdisk
if
(
COMPRESSED
(
boot
.
r
amdisk_type
))
{
if
(
COMPRESSED
(
boot
.
r
_fmt
))
{
fd
=
creat
(
RAMDISK_FILE
,
0644
);
fd
=
creat
(
RAMDISK_FILE
,
0644
);
decomp
(
boot
.
r
amdisk_type
,
fd
,
boot
.
ramdisk
,
header
(
&
boot
,
ramdisk_size
));
decomp
(
boot
.
r
_fmt
,
fd
,
boot
.
ramdisk
,
header
(
&
boot
,
ramdisk_size
));
close
(
fd
);
close
(
fd
);
}
else
{
}
else
{
dump
(
boot
.
ramdisk
,
header
(
&
boot
,
ramdisk_size
),
RAMDISK_FILE
".raw"
);
dump
(
boot
.
ramdisk
,
header
(
&
boot
,
ramdisk_size
),
RAMDISK_FILE
".raw"
);
...
@@ -255,11 +254,11 @@ void repack(const char* orig_image, const char* out_image) {
...
@@ -255,11 +254,11 @@ void repack(const char* orig_image, const char* out_image) {
mtk_kernel_off
=
lseek
(
fd
,
0
,
SEEK_CUR
);
mtk_kernel_off
=
lseek
(
fd
,
0
,
SEEK_CUR
);
write_zero
(
fd
,
512
);
write_zero
(
fd
,
512
);
}
}
if
(
COMPRESSED
(
boot
.
k
ernel_type
))
{
if
(
COMPRESSED
(
boot
.
k
_fmt
))
{
size_t
raw_size
;
size_t
raw_size
;
void
*
kernel_raw
;
void
*
kernel_raw
;
mmap_ro
(
KERNEL_FILE
,
&
kernel_raw
,
&
raw_size
);
mmap_ro
(
KERNEL_FILE
,
&
kernel_raw
,
&
raw_size
);
lheader
(
&
boot
,
kernel_size
,
=
comp
(
boot
.
k
ernel_type
,
fd
,
kernel_raw
,
raw_size
));
lheader
(
&
boot
,
kernel_size
,
=
comp
(
boot
.
k
_fmt
,
fd
,
kernel_raw
,
raw_size
));
munmap
(
kernel_raw
,
raw_size
);
munmap
(
kernel_raw
,
raw_size
);
}
else
{
}
else
{
lheader
(
&
boot
,
kernel_size
,
=
restore
(
KERNEL_FILE
,
fd
));
lheader
(
&
boot
,
kernel_size
,
=
restore
(
KERNEL_FILE
,
fd
));
...
@@ -280,7 +279,7 @@ void repack(const char* orig_image, const char* out_image) {
...
@@ -280,7 +279,7 @@ void repack(const char* orig_image, const char* out_image) {
size_t
cpio_size
;
size_t
cpio_size
;
void
*
cpio
;
void
*
cpio
;
mmap_ro
(
RAMDISK_FILE
,
&
cpio
,
&
cpio_size
);
mmap_ro
(
RAMDISK_FILE
,
&
cpio
,
&
cpio_size
);
lheader
(
&
boot
,
ramdisk_size
,
=
comp
(
boot
.
r
amdisk_type
,
fd
,
cpio
,
cpio_size
));
lheader
(
&
boot
,
ramdisk_size
,
=
comp
(
boot
.
r
_fmt
,
fd
,
cpio
,
cpio_size
));
munmap
(
cpio
,
cpio_size
);
munmap
(
cpio
,
cpio_size
);
}
else
{
}
else
{
// Find compressed ramdisk
// Find compressed ramdisk
...
...
native/jni/magiskboot/bootimg.h
View file @
dfee9954
/* tools/mkbootimg/bootimg.h
**
** Copyright 2007, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
#include <stdint.h>
#include <stdint.h>
#include "
types
.h"
#include "
format
.h"
#ifndef _BOOT_IMAGE_H_
#ifndef _BOOT_IMAGE_H_
#define _BOOT_IMAGE_H_
#define _BOOT_IMAGE_H_
#define BOOT_MAGIC "ANDROID!"
typedef
struct
boot_img_hdr
{
typedef
struct
boot_img_hdr
{
char
magic
[
8
];
char
magic
[
8
];
...
@@ -141,8 +122,8 @@ typedef struct boot_img {
...
@@ -141,8 +122,8 @@ typedef struct boot_img {
uint8_t
flags
;
uint8_t
flags
;
// The format of kernel and ramdisk
// The format of kernel and ramdisk
f
ile_t
kernel_type
;
f
ormat_t
k_fmt
;
f
ile_t
ramdisk_type
;
f
ormat_t
r_fmt
;
// Pointer to dtb that is appended after kernel
// Pointer to dtb that is appended after kernel
void
*
dtb
;
void
*
dtb
;
...
...
native/jni/magiskboot/compress.c
View file @
dfee9954
...
@@ -343,7 +343,7 @@ done:
...
@@ -343,7 +343,7 @@ done:
return
total
;
return
total
;
}
}
long
long
decomp
(
f
ile
_t
type
,
int
to
,
const
void
*
from
,
size_t
size
)
{
long
long
decomp
(
f
ormat
_t
type
,
int
to
,
const
void
*
from
,
size_t
size
)
{
switch
(
type
)
{
switch
(
type
)
{
case
GZIP
:
case
GZIP
:
return
gzip
(
0
,
to
,
from
,
size
);
return
gzip
(
0
,
to
,
from
,
size
);
...
@@ -363,7 +363,7 @@ long long decomp(file_t type, int to, const void *from, size_t size) {
...
@@ -363,7 +363,7 @@ long long decomp(file_t type, int to, const void *from, size_t size) {
}
}
}
}
long
long
comp
(
f
ile
_t
type
,
int
to
,
const
void
*
from
,
size_t
size
)
{
long
long
comp
(
f
ormat
_t
type
,
int
to
,
const
void
*
from
,
size_t
size
)
{
switch
(
type
)
{
switch
(
type
)
{
case
GZIP
:
case
GZIP
:
return
gzip
(
1
,
to
,
from
,
size
);
return
gzip
(
1
,
to
,
from
,
size
);
...
@@ -395,7 +395,7 @@ void decomp_file(char *from, const char *to) {
...
@@ -395,7 +395,7 @@ void decomp_file(char *from, const char *to) {
stream_full_read
(
STDIN_FILENO
,
&
file
,
&
size
);
stream_full_read
(
STDIN_FILENO
,
&
file
,
&
size
);
else
else
mmap_ro
(
from
,
&
file
,
&
size
);
mmap_ro
(
from
,
&
file
,
&
size
);
f
ile_t
type
=
check_type
(
file
);
f
ormat_t
type
=
check_fmt
(
file
);
char
*
ext
;
char
*
ext
;
ext
=
strrchr
(
from
,
'.'
);
ext
=
strrchr
(
from
,
'.'
);
if
(
to
==
NULL
)
if
(
to
==
NULL
)
...
@@ -453,7 +453,7 @@ void decomp_file(char *from, const char *to) {
...
@@ -453,7 +453,7 @@ void decomp_file(char *from, const char *to) {
}
}
void
comp_file
(
const
char
*
method
,
const
char
*
from
,
const
char
*
to
)
{
void
comp_file
(
const
char
*
method
,
const
char
*
from
,
const
char
*
to
)
{
f
ile
_t
type
;
f
ormat
_t
type
;
char
*
ext
,
dest
[
PATH_MAX
];
char
*
ext
,
dest
[
PATH_MAX
];
if
(
strcmp
(
method
,
"gzip"
)
==
0
)
{
if
(
strcmp
(
method
,
"gzip"
)
==
0
)
{
type
=
GZIP
;
type
=
GZIP
;
...
...
native/jni/magiskboot/
types
.c
→
native/jni/magiskboot/
format
.c
View file @
dfee9954
#include <string.h>
#include <string.h>
#include "bootimg.h"
#include "bootimg.h"
#include "
types
.h"
#include "
format
.h"
f
ile_t
check_type
(
const
void
*
buf
)
{
f
ormat_t
check_fmt
(
const
void
*
buf
)
{
if
(
memcmp
(
buf
,
CHROMEOS_MAGIC
,
8
)
==
0
)
{
if
(
memcmp
(
buf
,
CHROMEOS_MAGIC
,
8
)
==
0
)
{
return
CHROMEOS
;
return
CHROMEOS
;
}
else
if
(
memcmp
(
buf
,
BOOT_MAGIC
,
8
)
==
0
)
{
}
else
if
(
memcmp
(
buf
,
BOOT_MAGIC
,
8
)
==
0
)
{
...
@@ -36,9 +36,9 @@ file_t check_type(const void *buf) {
...
@@ -36,9 +36,9 @@ file_t check_type(const void *buf) {
}
}
}
}
void
get_
type_name
(
file_t
type
,
char
*
name
)
{
void
get_
fmt_name
(
format_t
fmt
,
char
*
name
)
{
char
*
s
;
char
*
s
;
switch
(
type
)
{
switch
(
fmt
)
{
case
CHROMEOS
:
case
CHROMEOS
:
s
=
"chromeos"
;
s
=
"chromeos"
;
break
;
break
;
...
...
native/jni/magiskboot/
types
.h
→
native/jni/magiskboot/
format
.h
View file @
dfee9954
#ifndef _
TYPES
_H_
#ifndef _
FORMAT
_H_
#define _
TYPES
_H_
#define _
FORMAT
_H_
typedef
enum
{
typedef
enum
{
UNKNOWN
,
UNKNOWN
,
...
@@ -16,10 +16,11 @@ typedef enum {
...
@@ -16,10 +16,11 @@ typedef enum {
LZ4_LEGACY
,
LZ4_LEGACY
,
MTK
,
MTK
,
DTB
DTB
}
f
ile
_t
;
}
f
ormat
_t
;
#define COMPRESSED(
type) (type >= GZIP && type
<= LZ4_LEGACY)
#define COMPRESSED(
fmt) (fmt >= GZIP && fmt
<= LZ4_LEGACY)
#define BOOT_MAGIC "ANDROID!"
#define CHROMEOS_MAGIC "CHROMEOS"
#define CHROMEOS_MAGIC "CHROMEOS"
#define ELF32_MAGIC "\x7f""ELF\x01"
#define ELF32_MAGIC "\x7f""ELF\x01"
#define ELF64_MAGIC "\x7f""ELF\x02"
#define ELF64_MAGIC "\x7f""ELF\x02"
...
@@ -36,7 +37,7 @@ typedef enum {
...
@@ -36,7 +37,7 @@ typedef enum {
#define SUP_LIST ((char *[]) { "gzip", "xz", "lzma", "bzip2", "lz4", "lz4_legacy", NULL })
#define SUP_LIST ((char *[]) { "gzip", "xz", "lzma", "bzip2", "lz4", "lz4_legacy", NULL })
#define SUP_EXT_LIST ((char *[]) { "gz", "xz", "lzma", "bz2", "lz4", "lz4", NULL })
#define SUP_EXT_LIST ((char *[]) { "gz", "xz", "lzma", "bz2", "lz4", "lz4", NULL })
f
ile_t
check_type
(
const
void
*
buf
);
f
ormat_t
check_fmt
(
const
void
*
buf
);
void
get_
type_name
(
file_t
type
,
char
*
name
);
void
get_
fmt_name
(
format_t
fmt
,
char
*
name
);
#endif
#endif
native/jni/magiskboot/magiskboot.h
View file @
dfee9954
...
@@ -29,7 +29,7 @@ size_t lzma(int mode, int fd, const void *buf, size_t size);
...
@@ -29,7 +29,7 @@ size_t lzma(int mode, int fd, const void *buf, size_t size);
size_t
lz4
(
int
mode
,
int
fd
,
const
void
*
buf
,
size_t
size
);
size_t
lz4
(
int
mode
,
int
fd
,
const
void
*
buf
,
size_t
size
);
size_t
bzip2
(
int
mode
,
int
fd
,
const
void
*
buf
,
size_t
size
);
size_t
bzip2
(
int
mode
,
int
fd
,
const
void
*
buf
,
size_t
size
);
size_t
lz4_legacy
(
int
mode
,
int
fd
,
const
void
*
buf
,
size_t
size
);
size_t
lz4_legacy
(
int
mode
,
int
fd
,
const
void
*
buf
,
size_t
size
);
long
long
comp
(
f
ile
_t
type
,
int
to
,
const
void
*
from
,
size_t
size
);
long
long
comp
(
f
ormat
_t
type
,
int
to
,
const
void
*
from
,
size_t
size
);
long
long
decomp
(
f
ile
_t
type
,
int
to
,
const
void
*
from
,
size_t
size
);
long
long
decomp
(
f
ormat
_t
type
,
int
to
,
const
void
*
from
,
size_t
size
);
#endif
#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