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
c11ccbae
Commit
c11ccbae
authored
May 13, 2022
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract vbmeta from footer
Do not scan manually, extract properly from footer like libavb
parent
6ef86d8d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
19 deletions
+25
-19
bootimg.cpp
native/jni/boot/bootimg.cpp
+24
-18
bootimg.hpp
native/jni/boot/bootimg.hpp
+1
-1
No files found.
native/jni/boot/bootimg.cpp
View file @
c11ccbae
...
@@ -423,16 +423,16 @@ void boot_img::parse_image(uint8_t *addr, format_t type) {
...
@@ -423,16 +423,16 @@ void boot_img::parse_image(uint8_t *addr, format_t type) {
flags
[
LG_BUMP_FLAG
]
=
true
;
flags
[
LG_BUMP_FLAG
]
=
true
;
}
}
// Find AVB structures
// Find AVB footer
void
*
meta
=
memmem
(
tail
,
tail_size
,
AVB_MAGIC
,
AVB_MAGIC_LEN
);
void
*
footer
=
tail
+
tail_size
-
sizeof
(
AvbFooter
);
if
(
meta
)
{
if
(
BUFFER_MATCH
(
footer
,
AVB_FOOTER_MAGIC
))
{
// Double check if footer exists
avb_footer
=
reinterpret_cast
<
AvbFooter
*>
(
footer
);
void
*
footer
=
tail
+
tail_size
-
sizeof
(
AvbFooter
);
// Double check if meta header exists
if
(
BUFFER_MATCH
(
footer
,
AVB_FOOTER_MAGIC
))
{
void
*
meta
=
hdr_addr
+
__builtin_bswap64
(
avb_footer
->
vbmeta_offset
);
if
(
BUFFER_MATCH
(
meta
,
AVB_MAGIC
))
{
fprintf
(
stderr
,
"VBMETA
\n
"
);
fprintf
(
stderr
,
"VBMETA
\n
"
);
flags
[
AVB_FLAG
]
=
true
;
flags
[
AVB_FLAG
]
=
true
;
avb_meta
=
reinterpret_cast
<
AvbVBMetaImageHeader
*>
(
meta
);
vbmeta
=
reinterpret_cast
<
AvbVBMetaImageHeader
*>
(
meta
);
avb_footer
=
reinterpret_cast
<
AvbFooter
*>
(
footer
);
}
}
}
}
}
}
...
@@ -466,9 +466,11 @@ int unpack(const char *image, bool skip_decomp, bool hdr) {
...
@@ -466,9 +466,11 @@ int unpack(const char *image, bool skip_decomp, bool hdr) {
// Dump kernel
// Dump kernel
if
(
!
skip_decomp
&&
COMPRESSED
(
boot
.
k_fmt
))
{
if
(
!
skip_decomp
&&
COMPRESSED
(
boot
.
k_fmt
))
{
int
fd
=
creat
(
KERNEL_FILE
,
0644
);
if
(
boot
.
hdr
->
kernel_size
()
!=
0
)
{
decompress
(
boot
.
k_fmt
,
fd
,
boot
.
kernel
,
boot
.
hdr
->
kernel_size
());
int
fd
=
creat
(
KERNEL_FILE
,
0644
);
close
(
fd
);
decompress
(
boot
.
k_fmt
,
fd
,
boot
.
kernel
,
boot
.
hdr
->
kernel_size
());
close
(
fd
);
}
}
else
{
}
else
{
dump
(
boot
.
kernel
,
boot
.
hdr
->
kernel_size
(),
KERNEL_FILE
);
dump
(
boot
.
kernel
,
boot
.
hdr
->
kernel_size
(),
KERNEL_FILE
);
}
}
...
@@ -478,9 +480,11 @@ int unpack(const char *image, bool skip_decomp, bool hdr) {
...
@@ -478,9 +480,11 @@ int unpack(const char *image, bool skip_decomp, bool hdr) {
// Dump ramdisk
// Dump ramdisk
if
(
!
skip_decomp
&&
COMPRESSED
(
boot
.
r_fmt
))
{
if
(
!
skip_decomp
&&
COMPRESSED
(
boot
.
r_fmt
))
{
int
fd
=
creat
(
RAMDISK_FILE
,
0644
);
if
(
boot
.
hdr
->
ramdisk_size
()
!=
0
)
{
decompress
(
boot
.
r_fmt
,
fd
,
boot
.
ramdisk
,
boot
.
hdr
->
ramdisk_size
());
int
fd
=
creat
(
RAMDISK_FILE
,
0644
);
close
(
fd
);
decompress
(
boot
.
r_fmt
,
fd
,
boot
.
ramdisk
,
boot
.
hdr
->
ramdisk_size
());
close
(
fd
);
}
}
else
{
}
else
{
dump
(
boot
.
ramdisk
,
boot
.
hdr
->
ramdisk_size
(),
RAMDISK_FILE
);
dump
(
boot
.
ramdisk
,
boot
.
hdr
->
ramdisk_size
(),
RAMDISK_FILE
);
}
}
...
@@ -490,9 +494,11 @@ int unpack(const char *image, bool skip_decomp, bool hdr) {
...
@@ -490,9 +494,11 @@ int unpack(const char *image, bool skip_decomp, bool hdr) {
// Dump extra
// Dump extra
if
(
!
skip_decomp
&&
COMPRESSED
(
boot
.
e_fmt
))
{
if
(
!
skip_decomp
&&
COMPRESSED
(
boot
.
e_fmt
))
{
int
fd
=
creat
(
EXTRA_FILE
,
0644
);
if
(
boot
.
hdr
->
extra_size
()
!=
0
)
{
decompress
(
boot
.
e_fmt
,
fd
,
boot
.
extra
,
boot
.
hdr
->
extra_size
());
int
fd
=
creat
(
EXTRA_FILE
,
0644
);
close
(
fd
);
decompress
(
boot
.
e_fmt
,
fd
,
boot
.
extra
,
boot
.
hdr
->
extra_size
());
close
(
fd
);
}
}
else
{
}
else
{
dump
(
boot
.
extra
,
boot
.
hdr
->
extra_size
(),
EXTRA_FILE
);
dump
(
boot
.
extra
,
boot
.
hdr
->
extra_size
(),
EXTRA_FILE
);
}
}
...
@@ -682,7 +688,7 @@ void repack(const char *src_img, const char *out_img, bool skip_comp) {
...
@@ -682,7 +688,7 @@ void repack(const char *src_img, const char *out_img, bool skip_comp) {
file_align_with
(
4096
);
file_align_with
(
4096
);
off
.
vbmeta
=
lseek
(
fd
,
0
,
SEEK_CUR
);
off
.
vbmeta
=
lseek
(
fd
,
0
,
SEEK_CUR
);
uint64_t
vbmeta_size
=
__builtin_bswap64
(
boot
.
avb_footer
->
vbmeta_size
);
uint64_t
vbmeta_size
=
__builtin_bswap64
(
boot
.
avb_footer
->
vbmeta_size
);
xwrite
(
fd
,
boot
.
avb_
meta
,
vbmeta_size
);
xwrite
(
fd
,
boot
.
vb
meta
,
vbmeta_size
);
}
}
// Pad image to original size if not chromeos (as it requires post processing)
// Pad image to original size if not chromeos (as it requires post processing)
...
...
native/jni/boot/bootimg.hpp
View file @
c11ccbae
...
@@ -608,7 +608,7 @@ struct boot_img {
...
@@ -608,7 +608,7 @@ struct boot_img {
// AVB structs
// AVB structs
AvbFooter
*
avb_footer
;
AvbFooter
*
avb_footer
;
AvbVBMetaImageHeader
*
avb_
meta
;
AvbVBMetaImageHeader
*
vb
meta
;
// Pointers to blocks defined in header
// Pointers to blocks defined in header
uint8_t
*
hdr_addr
;
uint8_t
*
hdr_addr
;
...
...
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