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
b4c2a9f4
Commit
b4c2a9f4
authored
Feb 21, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More macro magic
parent
7cee77f5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
27 deletions
+30
-27
bootimg.cpp
native/jni/magiskboot/bootimg.cpp
+7
-4
bootimg.h
native/jni/magiskboot/bootimg.h
+23
-23
No files found.
native/jni/magiskboot/bootimg.cpp
View file @
b4c2a9f4
...
@@ -13,6 +13,9 @@
...
@@ -13,6 +13,9 @@
#include "magiskboot.h"
#include "magiskboot.h"
#include "compress.h"
#include "compress.h"
uint32_t
dyn_img_hdr
::
j32
=
0
;
uint64_t
dyn_img_hdr
::
j64
=
0
;
static
void
dump
(
void
*
buf
,
size_t
size
,
const
char
*
filename
)
{
static
void
dump
(
void
*
buf
,
size_t
size
,
const
char
*
filename
)
{
if
(
size
==
0
)
if
(
size
==
0
)
return
;
return
;
...
@@ -371,14 +374,14 @@ void repack(const char* orig_image, const char* out_image) {
...
@@ -371,14 +374,14 @@ void repack(const char* orig_image, const char* out_image) {
// extra
// extra
extra_off
=
lseek
(
fd
,
0
,
SEEK_CUR
);
extra_off
=
lseek
(
fd
,
0
,
SEEK_CUR
);
if
(
access
(
EXTRA_FILE
,
R_OK
)
==
0
)
{
if
(
access
(
EXTRA_FILE
,
R_OK
)
==
0
)
{
boot
.
hdr
.
extra_size
(
restore
(
EXTRA_FILE
,
fd
)
);
boot
.
hdr
.
extra_size
(
)
=
restore
(
EXTRA_FILE
,
fd
);
file_align
();
file_align
();
}
}
// recovery_dtbo
// recovery_dtbo
if
(
access
(
RECV_DTBO_FILE
,
R_OK
)
==
0
)
{
if
(
access
(
RECV_DTBO_FILE
,
R_OK
)
==
0
)
{
boot
.
hdr
.
recovery_dtbo_offset
(
lseek
(
fd
,
0
,
SEEK_CUR
)
);
boot
.
hdr
.
recovery_dtbo_offset
(
)
=
lseek
(
fd
,
0
,
SEEK_CUR
);
boot
.
hdr
.
recovery_dtbo_size
(
restore
(
RECV_DTBO_FILE
,
fd
)
);
boot
.
hdr
.
recovery_dtbo_size
(
)
=
restore
(
RECV_DTBO_FILE
,
fd
);
file_align
();
file_align
();
}
}
...
@@ -439,7 +442,7 @@ void repack(const char* orig_image, const char* out_image) {
...
@@ -439,7 +442,7 @@ void repack(const char* orig_image, const char* out_image) {
// Try to fix the header
// Try to fix the header
if
(
boot
.
hdr
.
header_version
()
&&
boot
.
hdr
.
header_size
()
==
0
)
if
(
boot
.
hdr
.
header_version
()
&&
boot
.
hdr
.
header_size
()
==
0
)
boot
.
hdr
.
header_size
(
sizeof
(
boot_img_hdr
)
);
boot
.
hdr
.
header_size
(
)
=
sizeof
(
boot_img_hdr
);
// Main header
// Main header
memcpy
(
boot
.
map_addr
+
header_off
,
*
boot
.
hdr
,
boot
.
hdr
.
hdr_size
());
memcpy
(
boot
.
map_addr
+
header_off
,
*
boot
.
hdr
,
boot
.
hdr
.
hdr_size
());
...
...
native/jni/magiskboot/bootimg.h
View file @
b4c2a9f4
...
@@ -147,28 +147,24 @@ struct blob_hdr {
...
@@ -147,28 +147,24 @@ struct blob_hdr {
struct
dyn_img_hdr
{
struct
dyn_img_hdr
{
#define dyn_access(x) (pxa ? hdr_pxa->x : v1_hdr->x)
#define dyn_access(x) (pxa ? hdr_pxa->x : v1_hdr->x)
#define dyn_get(name, type) type name() const { return dyn_access(name); }
#define dyn_set(name, type) void name(type v) { dyn_access(name) = v; }
#define dyn_func(name, type) \
#define dyn_get(name, type) \
dyn_get(name, type) \
type name() const { return dyn_access(name); }
dyn_set(name, type)
#define dyn_ref(name, type) \
type &name() { return dyn_access(name); }
#define v1_ref(name, type, alt) \
type &name() { if (pxa) { alt = 0; return alt; } return v1_hdr->name; }
#define v1_func(name, type) \
dyn_ref
(
page_size
,
uint32_t
);
type name() const { return pxa ? 0 : v1_hdr->name; } \
void name(type v) { if (!pxa) v1_hdr->name = v; }
dyn_func
(
extra_size
,
uint32_t
);
dyn_func
(
page_size
,
uint32_t
);
dyn_get
(
name
,
char
*
);
dyn_get
(
name
,
char
*
);
dyn_get
(
cmdline
,
char
*
);
dyn_get
(
cmdline
,
char
*
);
dyn_get
(
id
,
char
*
);
dyn_get
(
id
,
char
*
);
dyn_get
(
extra_cmdline
,
char
*
);
dyn_get
(
extra_cmdline
,
char
*
);
v1_
func
(
os_version
,
uint32_t
);
v1_
ref
(
os_version
,
uint32_t
,
j32
);
v1_
func
(
recovery_dtbo_size
,
uint32_t
);
v1_
ref
(
recovery_dtbo_size
,
uint32_t
,
j32
);
v1_
func
(
recovery_dtbo_offset
,
uint32_t
);
v1_
ref
(
recovery_dtbo_offset
,
uint64_t
,
j64
);
v1_
func
(
header_size
,
uint32_t
);
v1_
ref
(
header_size
,
uint32_t
,
j32
);
dyn_img_hdr
()
:
pxa
(
false
),
img_hdr
(
nullptr
)
{}
dyn_img_hdr
()
:
pxa
(
false
),
img_hdr
(
nullptr
)
{}
~
dyn_img_hdr
()
{
~
dyn_img_hdr
()
{
...
@@ -179,17 +175,18 @@ void name(type v) { if (!pxa) v1_hdr->name = v; }
...
@@ -179,17 +175,18 @@ void name(type v) { if (!pxa) v1_hdr->name = v; }
}
}
uint32_t
header_version
()
{
uint32_t
header_version
()
{
if
(
pxa
)
return
0
;
uint32_t
ver
=
v1_hdr
->
header_version
;
// There won't be v4 header any time soon...
// There won't be v4 header any time soon...
// If larger than 4, assume this field will be treated as extra_size
// If larger than 4, assume this field will be treated as extra_size
return
ver
>
4
?
0
:
ver
;
return
pxa
||
v1_hdr
->
header_version
>
4
?
0
:
v1_hdr
->
header_version
;
}
}
uint32_t
extra_size
()
{
uint32_t
&
extra_size
()
{
// If header version > 0, we should treat this field as header_version
// If header version > 0, we should treat this field as header_version
return
header_version
()
?
0
:
dyn_access
(
extra_size
);
if
(
header_version
())
{
j32
=
0
;
return
j32
;
}
return
dyn_access
(
extra_size
);
}
}
size_t
hdr_size
()
{
size_t
hdr_size
()
{
...
@@ -216,13 +213,16 @@ void name(type v) { if (!pxa) v1_hdr->name = v; }
...
@@ -216,13 +213,16 @@ void name(type v) { if (!pxa) v1_hdr->name = v; }
private
:
private
:
bool
pxa
;
bool
pxa
;
union
{
union
{
/* Main header
is either AOSP or PXA
/* Main header
could be either AOSP or PXA,
* but both of them is a base header
* but both of them is a base header
.
* Same address can be interpreted in 3 ways */
* Same address can be interpreted in 3 ways */
boot_img_hdr_base
*
img_hdr
;
/* Common base header */
boot_img_hdr_base
*
img_hdr
;
/* Common base header */
boot_img_hdr
*
v1_hdr
;
/* AOSP v1 header */
boot_img_hdr
*
v1_hdr
;
/* AOSP v1 header */
boot_img_hdr_pxa
*
hdr_pxa
;
/* Samsung PXA header */
boot_img_hdr_pxa
*
hdr_pxa
;
/* Samsung PXA header */
};
};
static
uint32_t
j32
;
static
uint64_t
j64
;
};
};
struct
boot_img
{
struct
boot_img
{
...
...
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