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
8b5652ce
Commit
8b5652ce
authored
Sep 29, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Skip image padding on Pixel C
parent
d6dbab53
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
15 deletions
+19
-15
bootimg.cpp
native/jni/magiskboot/bootimg.cpp
+19
-15
No files found.
native/jni/magiskboot/bootimg.cpp
View file @
8b5652ce
...
@@ -395,6 +395,8 @@ write_zero(fd, align_off(lseek(fd, 0, SEEK_CUR) - off.header, boot.hdr->page_siz
...
@@ -395,6 +395,8 @@ write_zero(fd, align_off(lseek(fd, 0, SEEK_CUR) - off.header, boot.hdr->page_siz
void
repack
(
const
char
*
src_img
,
const
char
*
out_img
,
bool
nocomp
)
{
void
repack
(
const
char
*
src_img
,
const
char
*
out_img
,
bool
nocomp
)
{
boot_img
boot
(
src_img
);
boot_img
boot
(
src_img
);
auto
is_flag
=
[
&
](
unsigned
flag
)
->
bool
{
return
(
boot
.
flags
&
flag
);
};
struct
{
struct
{
uint32_t
header
;
uint32_t
header
;
uint32_t
kernel
;
uint32_t
kernel
;
...
@@ -423,7 +425,7 @@ void repack(const char* src_img, const char* out_img, bool nocomp) {
...
@@ -423,7 +425,7 @@ void repack(const char* src_img, const char* out_img, bool nocomp) {
// Create new image
// Create new image
int
fd
=
creat
(
out_img
,
0644
);
int
fd
=
creat
(
out_img
,
0644
);
if
(
boot
.
flags
&
DHTB_FLAG
)
{
if
(
is_flag
(
DHTB_FLAG
)
)
{
// Skip DHTB header
// Skip DHTB header
write_zero
(
fd
,
sizeof
(
dhtb_hdr
));
write_zero
(
fd
,
sizeof
(
dhtb_hdr
));
}
else
if
(
boot
.
flags
&
BLOB_FLAG
)
{
}
else
if
(
boot
.
flags
&
BLOB_FLAG
)
{
...
@@ -440,7 +442,7 @@ void repack(const char* src_img, const char* out_img, bool nocomp) {
...
@@ -440,7 +442,7 @@ void repack(const char* src_img, const char* out_img, bool nocomp) {
// kernel
// kernel
off
.
kernel
=
lseek
(
fd
,
0
,
SEEK_CUR
);
off
.
kernel
=
lseek
(
fd
,
0
,
SEEK_CUR
);
if
(
boot
.
flags
&
MTK_KERNEL
)
{
if
(
is_flag
(
MTK_KERNEL
)
)
{
// Copy MTK headers
// Copy MTK headers
restore_buf
(
fd
,
boot
.
k_hdr
,
sizeof
(
mtk_hdr
));
restore_buf
(
fd
,
boot
.
k_hdr
,
sizeof
(
mtk_hdr
));
}
}
...
@@ -463,7 +465,7 @@ void repack(const char* src_img, const char* out_img, bool nocomp) {
...
@@ -463,7 +465,7 @@ void repack(const char* src_img, const char* out_img, bool nocomp) {
// ramdisk
// ramdisk
off
.
ramdisk
=
lseek
(
fd
,
0
,
SEEK_CUR
);
off
.
ramdisk
=
lseek
(
fd
,
0
,
SEEK_CUR
);
if
(
boot
.
flags
&
MTK_RAMDISK
)
{
if
(
is_flag
(
MTK_RAMDISK
)
)
{
// Copy MTK headers
// Copy MTK headers
restore_buf
(
fd
,
boot
.
r_hdr
,
sizeof
(
mtk_hdr
));
restore_buf
(
fd
,
boot
.
r_hdr
,
sizeof
(
mtk_hdr
));
}
}
...
@@ -517,18 +519,20 @@ void repack(const char* src_img, const char* out_img, bool nocomp) {
...
@@ -517,18 +519,20 @@ void repack(const char* src_img, const char* out_img, bool nocomp) {
}
}
// Append tail info
// Append tail info
if
(
boot
.
flags
&
SEANDROID_FLAG
)
{
if
(
is_flag
(
SEANDROID_FLAG
)
)
{
restore_buf
(
fd
,
SEANDROID_MAGIC
"
\xFF\xFF\xFF\xFF
"
,
20
);
restore_buf
(
fd
,
SEANDROID_MAGIC
"
\xFF\xFF\xFF\xFF
"
,
20
);
}
}
if
(
boot
.
flags
&
LG_BUMP_FLAG
)
{
if
(
is_flag
(
LG_BUMP_FLAG
)
)
{
restore_buf
(
fd
,
LG_BUMP_MAGIC
,
16
);
restore_buf
(
fd
,
LG_BUMP_MAGIC
,
16
);
}
}
// Pad image to at least original size
// Pad image to at least original size if not chromeos (as it requires post processing)
auto
current_sz
=
lseek
(
fd
,
0
,
SEEK_CUR
);
if
(
!
is_flag
(
CHROMEOS_FLAG
))
{
if
(
current_sz
<
boot
.
map_size
)
{
auto
current_sz
=
lseek
(
fd
,
0
,
SEEK_CUR
);
int
padding
=
boot
.
map_size
-
current_sz
;
if
(
current_sz
<
boot
.
map_size
)
{
write_zero
(
fd
,
padding
);
int
padding
=
boot
.
map_size
-
current_sz
;
write_zero
(
fd
,
padding
);
}
}
}
close
(
fd
);
close
(
fd
);
...
@@ -542,12 +546,12 @@ void repack(const char* src_img, const char* out_img, bool nocomp) {
...
@@ -542,12 +546,12 @@ void repack(const char* src_img, const char* out_img, bool nocomp) {
mmap_rw
(
out_img
,
boot
.
map_addr
,
boot
.
map_size
);
mmap_rw
(
out_img
,
boot
.
map_addr
,
boot
.
map_size
);
// MTK headers
// MTK headers
if
(
boot
.
flags
&
MTK_KERNEL
)
{
if
(
is_flag
(
MTK_KERNEL
)
)
{
auto
hdr
=
reinterpret_cast
<
mtk_hdr
*>
(
boot
.
map_addr
+
off
.
kernel
);
auto
hdr
=
reinterpret_cast
<
mtk_hdr
*>
(
boot
.
map_addr
+
off
.
kernel
);
hdr
->
size
=
boot
.
hdr
->
kernel_size
();
hdr
->
size
=
boot
.
hdr
->
kernel_size
();
boot
.
hdr
->
kernel_size
()
+=
sizeof
(
*
hdr
);
boot
.
hdr
->
kernel_size
()
+=
sizeof
(
*
hdr
);
}
}
if
(
boot
.
flags
&
MTK_RAMDISK
)
{
if
(
is_flag
(
MTK_RAMDISK
)
)
{
auto
hdr
=
reinterpret_cast
<
mtk_hdr
*>
(
boot
.
map_addr
+
off
.
ramdisk
);
auto
hdr
=
reinterpret_cast
<
mtk_hdr
*>
(
boot
.
map_addr
+
off
.
ramdisk
);
hdr
->
size
=
boot
.
hdr
->
ramdisk_size
();
hdr
->
size
=
boot
.
hdr
->
ramdisk_size
();
boot
.
hdr
->
ramdisk_size
()
+=
sizeof
(
*
hdr
);
boot
.
hdr
->
ramdisk_size
()
+=
sizeof
(
*
hdr
);
...
@@ -555,7 +559,7 @@ void repack(const char* src_img, const char* out_img, bool nocomp) {
...
@@ -555,7 +559,7 @@ void repack(const char* src_img, const char* out_img, bool nocomp) {
// Update checksum
// Update checksum
HASH_CTX
ctx
;
HASH_CTX
ctx
;
(
boot
.
flags
&
SHA256_FLAG
)
?
SHA256_init
(
&
ctx
)
:
SHA_init
(
&
ctx
);
is_flag
(
SHA256_FLAG
)
?
SHA256_init
(
&
ctx
)
:
SHA_init
(
&
ctx
);
uint32_t
size
=
boot
.
hdr
->
kernel_size
();
uint32_t
size
=
boot
.
hdr
->
kernel_size
();
HASH_update
(
&
ctx
,
boot
.
map_addr
+
off
.
kernel
,
size
);
HASH_update
(
&
ctx
,
boot
.
map_addr
+
off
.
kernel
,
size
);
HASH_update
(
&
ctx
,
&
size
,
sizeof
(
size
));
HASH_update
(
&
ctx
,
&
size
,
sizeof
(
size
));
...
@@ -591,13 +595,13 @@ void repack(const char* src_img, const char* out_img, bool nocomp) {
...
@@ -591,13 +595,13 @@ void repack(const char* src_img, const char* out_img, bool nocomp) {
// Main header
// Main header
memcpy
(
boot
.
map_addr
+
off
.
header
,
**
boot
.
hdr
,
boot
.
hdr
->
hdr_size
());
memcpy
(
boot
.
map_addr
+
off
.
header
,
**
boot
.
hdr
,
boot
.
hdr
->
hdr_size
());
if
(
boot
.
flags
&
DHTB_FLAG
)
{
if
(
is_flag
(
DHTB_FLAG
)
)
{
// DHTB header
// DHTB header
auto
hdr
=
reinterpret_cast
<
dhtb_hdr
*>
(
boot
.
map_addr
);
auto
hdr
=
reinterpret_cast
<
dhtb_hdr
*>
(
boot
.
map_addr
);
memcpy
(
hdr
,
DHTB_MAGIC
,
8
);
memcpy
(
hdr
,
DHTB_MAGIC
,
8
);
hdr
->
size
=
boot
.
map_size
-
sizeof
(
dhtb_hdr
);
hdr
->
size
=
boot
.
map_size
-
sizeof
(
dhtb_hdr
);
SHA256_hash
(
boot
.
map_addr
+
sizeof
(
dhtb_hdr
),
hdr
->
size
,
hdr
->
checksum
);
SHA256_hash
(
boot
.
map_addr
+
sizeof
(
dhtb_hdr
),
hdr
->
size
,
hdr
->
checksum
);
}
else
if
(
boot
.
flags
&
BLOB_FLAG
)
{
}
else
if
(
is_flag
(
BLOB_FLAG
)
)
{
// Blob header
// Blob header
auto
hdr
=
reinterpret_cast
<
blob_hdr
*>
(
boot
.
map_addr
);
auto
hdr
=
reinterpret_cast
<
blob_hdr
*>
(
boot
.
map_addr
);
hdr
->
size
=
boot
.
map_size
-
sizeof
(
blob_hdr
);
hdr
->
size
=
boot
.
map_size
-
sizeof
(
blob_hdr
);
...
...
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