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
aaaaa3d0
Commit
aaaaa3d0
authored
Oct 15, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Minor refactoring
parent
1edc4449
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
41 deletions
+36
-41
bootimg.cpp
native/jni/magiskboot/bootimg.cpp
+36
-40
bootimg.hpp
native/jni/magiskboot/bootimg.hpp
+0
-1
No files found.
native/jni/magiskboot/bootimg.cpp
View file @
aaaaa3d0
...
@@ -193,16 +193,42 @@ boot_img::~boot_img() {
...
@@ -193,16 +193,42 @@ boot_img::~boot_img() {
delete
hdr
;
delete
hdr
;
}
}
static
format_t
check_fmt_lg
(
uint8_t
*
buf
,
unsigned
size
)
{
static
int
find_dtb_offset
(
uint8_t
*
buf
,
unsigned
sz
)
{
format_t
fmt
=
check_fmt
(
buf
,
size
);
for
(
int
off
=
0
;
off
+
sizeof
(
fdt_header
)
<
sz
;
++
off
)
{
auto
fdt_hdr
=
reinterpret_cast
<
fdt_header
*>
(
buf
+
off
);
if
(
fdt32_to_cpu
(
fdt_hdr
->
magic
)
!=
FDT_MAGIC
)
continue
;
// Check that fdt_header.totalsize does not overflow kernel image size
uint32_t
totalsize
=
fdt32_to_cpu
(
fdt_hdr
->
totalsize
);
if
(
totalsize
+
off
>
sz
)
continue
;
// Check that fdt_header.off_dt_struct does not overflow kernel image size
uint32_t
off_dt_struct
=
fdt32_to_cpu
(
fdt_hdr
->
off_dt_struct
);
if
(
off_dt_struct
+
off
>
sz
)
continue
;
// Check that fdt_node_header.tag of first node is FDT_BEGIN_NODE
auto
fdt_node_hdr
=
reinterpret_cast
<
fdt_node_header
*>
(
buf
+
off
+
off_dt_struct
);
if
(
fdt32_to_cpu
(
fdt_node_hdr
->
tag
)
!=
FDT_BEGIN_NODE
)
continue
;
return
off
;
}
return
-
1
;
}
static
format_t
check_fmt_lg
(
uint8_t
*
buf
,
unsigned
sz
)
{
format_t
fmt
=
check_fmt
(
buf
,
sz
);
if
(
fmt
==
LZ4_LEGACY
)
{
if
(
fmt
==
LZ4_LEGACY
)
{
// We need to check if it is LZ4_LG
// We need to check if it is LZ4_LG
unsigned
off
=
4
;
unsigned
off
=
4
;
unsigned
block_sz
;
unsigned
block_sz
;
while
(
off
+
sizeof
(
block_sz
)
<=
s
ize
)
{
while
(
off
+
sizeof
(
block_sz
)
<=
s
z
)
{
memcpy
(
&
block_sz
,
buf
+
off
,
sizeof
(
block_sz
));
memcpy
(
&
block_sz
,
buf
+
off
,
sizeof
(
block_sz
));
off
+=
sizeof
(
block_sz
);
off
+=
sizeof
(
block_sz
);
if
(
off
+
block_sz
>
s
ize
)
if
(
off
+
block_sz
>
s
z
)
return
LZ4_LG
;
return
LZ4_LG
;
off
+=
block_sz
;
off
+=
block_sz
;
}
}
...
@@ -284,7 +310,12 @@ void boot_img::parse_image(uint8_t *addr) {
...
@@ -284,7 +310,12 @@ void boot_img::parse_image(uint8_t *addr) {
flags
|=
LG_BUMP_FLAG
;
flags
|=
LG_BUMP_FLAG
;
}
}
find_kernel_dtb
();
if
(
int
dtb_off
=
find_dtb_offset
(
kernel
,
hdr
->
kernel_size
());
dtb_off
>
0
)
{
kernel_dtb
=
kernel
+
dtb_off
;
kernel_dt_size
=
hdr
->
kernel_size
()
-
dtb_off
;
hdr
->
kernel_size
()
=
dtb_off
;
fprintf
(
stderr
,
"%-*s [%u]
\n
"
,
PADDING
,
"KERNEL_DTB"
,
kernel_dt_size
);
}
if
(
auto
size
=
hdr
->
kernel_size
())
{
if
(
auto
size
=
hdr
->
kernel_size
())
{
k_fmt
=
check_fmt_lg
(
kernel
,
size
);
k_fmt
=
check_fmt_lg
(
kernel
,
size
);
...
@@ -320,41 +351,6 @@ void boot_img::parse_image(uint8_t *addr) {
...
@@ -320,41 +351,6 @@ void boot_img::parse_image(uint8_t *addr) {
}
}
}
}
static
int
find_dtb_offset
(
uint8_t
*
buf
,
int
sz
)
{
for
(
int
off
=
0
;
off
<
sz
-
(
int
)
sizeof
(
fdt_header
);
++
off
)
{
auto
fdt_hdr
=
reinterpret_cast
<
fdt_header
*>
(
buf
+
off
);
if
(
fdt32_to_cpu
(
fdt_hdr
->
magic
)
!=
FDT_MAGIC
)
continue
;
// Check that fdt_header.totalsize does not overflow kernel image size
uint32_t
totalsize
=
fdt32_to_cpu
(
fdt_hdr
->
totalsize
);
if
(
totalsize
+
off
>
sz
)
continue
;
// Check that fdt_header.off_dt_struct does not overflow kernel image size
uint32_t
off_dt_struct
=
fdt32_to_cpu
(
fdt_hdr
->
off_dt_struct
);
if
(
off_dt_struct
+
off
>
sz
)
continue
;
// Check that fdt_node_header.tag of first node is FDT_BEGIN_NODE
auto
fdt_node_hdr
=
reinterpret_cast
<
fdt_node_header
*>
(
buf
+
off
+
off_dt_struct
);
if
(
fdt32_to_cpu
(
fdt_node_hdr
->
tag
)
!=
FDT_BEGIN_NODE
)
continue
;
return
off
;
}
return
-
1
;
}
void
boot_img
::
find_kernel_dtb
()
{
if
(
int
off
=
find_dtb_offset
(
kernel
,
hdr
->
kernel_size
());
off
>
0
)
{
kernel_dtb
=
kernel
+
off
;
kernel_dt_size
=
hdr
->
kernel_size
()
-
off
;
hdr
->
kernel_size
()
=
off
;
fprintf
(
stderr
,
"%-*s [%u]
\n
"
,
PADDING
,
"KERNEL_DTB"
,
kernel_dt_size
);
}
}
int
split_image_dtb
(
const
char
*
filename
)
{
int
split_image_dtb
(
const
char
*
filename
)
{
uint8_t
*
buf
;
uint8_t
*
buf
;
size_t
sz
;
size_t
sz
;
...
...
native/jni/magiskboot/bootimg.hpp
View file @
aaaaa3d0
...
@@ -384,5 +384,4 @@ struct boot_img {
...
@@ -384,5 +384,4 @@ struct boot_img {
~
boot_img
();
~
boot_img
();
void
parse_image
(
uint8_t
*
addr
);
void
parse_image
(
uint8_t
*
addr
);
void
find_kernel_dtb
();
};
};
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