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
3d4081d0
Commit
3d4081d0
authored
Sep 26, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix patch verity and forceencrypt
parent
b763b81f
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
29 deletions
+26
-29
magiskboot.h
native/jni/magiskboot/magiskboot.h
+2
-2
pattern.cpp
native/jni/magiskboot/pattern.cpp
+22
-21
ramdisk.cpp
native/jni/magiskboot/ramdisk.cpp
+2
-6
No files found.
native/jni/magiskboot/magiskboot.h
View file @
3d4081d0
...
...
@@ -18,6 +18,6 @@ int hexpatch(const char *image, const char *from, const char *to);
int
cpio_commands
(
int
argc
,
char
*
argv
[]);
int
dtb_commands
(
int
argc
,
char
*
argv
[]);
char
*
patch_verity
(
const
void
*
buf
,
uint32_t
&
size
);
void
patch_encryption
(
void
*
*
buf
,
uint32_t
*
size
);
char
*
patch_verity
(
const
void
*
buf
,
uint32_t
&
size
,
bool
inplace
=
false
);
void
patch_encryption
(
void
*
&
buf
,
uint32_t
&
size
);
bool
check_env
(
const
char
*
name
);
native/jni/magiskboot/pattern.cpp
View file @
3d4081d0
...
...
@@ -22,20 +22,20 @@ static int check_verity_pattern(const char *s) {
}
static
int
check_encryption_pattern
(
const
char
*
s
)
{
const
char
*
encrypt_list
[]
=
{
"forceencrypt"
,
"forcefdeorfbe"
,
nullptr
};
for
(
int
i
=
0
;
encrypt_list
[
i
];
++
i
)
{
int
len
=
strlen
(
enc
rypt_list
[
i
]
);
if
(
strncmp
(
s
,
enc
rypt_list
[
i
]
,
len
)
==
0
)
static
const
char
*
encrypt_list
[]
=
{
"forceencrypt"
,
"forcefdeorfbe"
};
for
(
auto
enc
:
encrypt_list
)
{
int
len
=
strlen
(
enc
);
if
(
strncmp
(
s
,
enc
,
len
)
==
0
)
return
len
;
}
return
-
1
;
}
char
*
patch_verity
(
const
void
*
buf
,
uint32_t
&
size
)
{
char
*
patch_verity
(
const
void
*
buf
,
uint32_t
&
size
,
bool
inplace
)
{
auto
src
=
static_cast
<
const
char
*>
(
buf
);
int
src_size
=
size
;
bool
found
=
false
;
char
patched
[
4096
]
;
auto
patched
=
(
char
*
)(
inplace
?
buf
:
xmalloc
(
size
))
;
int
write
=
0
;
for
(
int
read
=
0
;
read
<
src_size
;
++
read
,
++
write
)
{
if
(
int
skip
;
(
skip
=
check_verity_pattern
(
src
+
read
))
>
0
)
{
...
...
@@ -47,24 +47,25 @@ char *patch_verity(const void *buf, uint32_t &size) {
patched
[
write
]
=
src
[
read
];
}
patched
[
write
]
=
'\0'
;
return
found
?
strdup
(
patched
)
:
nullptr
;
if
(
!
found
)
{
if
(
!
inplace
)
free
(
patched
);
return
nullptr
;
}
return
patched
;
}
void
patch_encryption
(
void
**
buf
,
uint32_t
*
size
)
{
int
skip
,
src_size
=
*
size
;
char
*
src
=
(
char
*
)
*
buf
,
*
patched
=
(
char
*
)
xcalloc
(
src_size
,
1
);
for
(
int
read
=
0
,
write
=
0
;
read
<
src_size
;
++
read
,
++
write
)
{
if
((
skip
=
check_encryption_pattern
(
src
+
read
))
>
0
)
{
fprintf
(
stderr
,
"Replace pattern [%.*s] with [encryptable]
\n
"
,
skip
,
src
+
read
);
memcpy
(
patched
+
read
,
"encryptable"
,
11
);
void
patch_encryption
(
void
*&
buf
,
uint32_t
&
size
)
{
auto
src
=
static_cast
<
char
*>
(
buf
);
int
src_size
=
size
;
int
write
=
0
;
for
(
int
read
=
0
;
read
<
src_size
;
++
read
,
++
write
)
{
if
(
int
skip
;
(
skip
=
check_encryption_pattern
(
src
+
read
))
>
0
)
{
fprintf
(
stderr
,
"Found pattern [%.*s]
\n
"
,
skip
,
src
+
read
);
size
-=
skip
;
read
+=
skip
;
write
+=
11
;
*
size
-=
(
skip
-
11
);
}
patched
[
write
]
=
src
[
read
];
src
[
write
]
=
src
[
read
];
}
free
(
*
buf
);
*
buf
=
patched
;
src
[
write
]
=
'\0'
;
}
native/jni/magiskboot/ramdisk.cpp
View file @
3d4081d0
...
...
@@ -52,11 +52,7 @@ void magisk_cpio::patch() {
if
(
!
keepverity
)
{
if
(
fstab
)
{
fprintf
(
stderr
,
"Found fstab file [%s]
\n
"
,
cur
->
first
.
data
());
auto
buf
=
patch_verity
(
cur
->
second
->
data
,
cur
->
second
->
filesize
);
if
(
buf
)
{
free
(
cur
->
second
->
data
);
cur
->
second
->
data
=
buf
;
}
patch_verity
(
cur
->
second
->
data
,
cur
->
second
->
filesize
,
true
);
}
else
if
(
cur
->
first
==
"verity_key"
)
{
rm
(
cur
);
continue
;
...
...
@@ -64,7 +60,7 @@ void magisk_cpio::patch() {
}
if
(
!
keepforceencrypt
)
{
if
(
fstab
)
{
patch_encryption
(
&
cur
->
second
->
data
,
&
cur
->
second
->
filesize
);
patch_encryption
(
cur
->
second
->
data
,
cur
->
second
->
filesize
);
}
}
}
...
...
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