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
1ff45ac5
Commit
1ff45ac5
authored
Mar 09, 2021
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Proper pattern matching
Fix #3998
parent
48bde737
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
20 deletions
+23
-20
pattern.cpp
native/jni/magiskboot/pattern.cpp
+23
-20
No files found.
native/jni/magiskboot/pattern.cpp
View file @
1ff45ac5
#include <malloc.h>
#include <malloc.h>
#include <string.h>
#include <utils.hpp>
#include <utils.hpp>
#include "magiskboot.hpp"
#include "magiskboot.hpp"
#define
CHECKED_
MATCH(p) else if (strncmp(s + skip, p, sizeof(p) - 1) == 0) skip += (sizeof(p) - 1)
#define MATCH(p) else if (strncmp(s + skip, p, sizeof(p) - 1) == 0) skip += (sizeof(p) - 1)
static
int
check
_verity_pattern
(
const
char
*
s
)
{
static
int
skip
_verity_pattern
(
const
char
*
s
)
{
int
skip
=
s
[
0
]
==
','
;
int
skip
=
s
[
0
]
==
','
;
if
(
0
)
{}
if
(
0
)
{}
CHECKED_
MATCH
(
"verifyatboot"
);
MATCH
(
"verifyatboot"
);
CHECKED_
MATCH
(
"verify"
);
MATCH
(
"verify"
);
CHECKED_
MATCH
(
"avb_keys"
);
MATCH
(
"avb_keys"
);
CHECKED_
MATCH
(
"avb"
);
MATCH
(
"avb"
);
CHECKED_
MATCH
(
"support_scfs"
);
MATCH
(
"support_scfs"
);
CHECKED_
MATCH
(
"fsverity"
);
MATCH
(
"fsverity"
);
else
return
-
1
;
else
return
-
1
;
if
(
s
[
skip
]
==
'='
)
{
if
(
s
[
skip
]
==
'='
)
{
while
(
s
[
skip
]
!=
'\0'
&&
s
[
skip
]
!=
' '
&&
s
[
skip
]
!=
'\n'
&&
s
[
skip
]
!=
','
)
while
(
!
strchr
(
"
\n
,"
,
s
[
skip
])
)
++
skip
;
++
skip
;
}
}
return
skip
;
return
skip
;
}
}
#undef CHECKED_MATCH
static
int
skip_encryption_pattern
(
const
char
*
s
)
{
#define CHECKED_MATCH(p) else if (strncmp(s, p, sizeof(p) - 1) == 0) return (sizeof(p) - 1)
int
skip
=
s
[
0
]
==
','
;
static
int
check_encryption_pattern
(
const
char
*
s
)
{
if
(
0
)
{}
if
(
0
)
{}
CHECKED_
MATCH
(
"forceencrypt"
);
MATCH
(
"forceencrypt"
);
CHECKED_
MATCH
(
"forcefdeorfbe"
);
MATCH
(
"forcefdeorfbe"
);
CHECKED_
MATCH
(
"fileencryption"
);
MATCH
(
"fileencryption"
);
else
return
-
1
;
else
return
-
1
;
if
(
s
[
skip
]
==
'='
)
{
while
(
!
strchr
(
"
\n
,"
,
s
[
skip
]))
++
skip
;
}
return
skip
;
}
}
static
uint32_t
remove_pattern
(
void
*
buf
,
uint32_t
size
,
int
(
*
pattern_skip
)(
const
char
*
))
{
static
uint32_t
remove_pattern
(
char
*
src
,
uint32_t
size
,
int
(
*
pattern_skip
)(
const
char
*
))
{
auto
src
=
static_cast
<
char
*>
(
buf
);
int
orig_sz
=
size
;
int
orig_sz
=
size
;
int
write
=
0
;
int
write
=
0
;
for
(
int
read
=
0
;
read
<
orig_sz
;)
{
for
(
int
read
=
0
;
read
<
orig_sz
;)
{
...
@@ -55,9 +58,9 @@ static uint32_t remove_pattern(void *buf, uint32_t size, int(*pattern_skip)(cons
...
@@ -55,9 +58,9 @@ static uint32_t remove_pattern(void *buf, uint32_t size, int(*pattern_skip)(cons
}
}
uint32_t
patch_verity
(
void
*
buf
,
uint32_t
size
)
{
uint32_t
patch_verity
(
void
*
buf
,
uint32_t
size
)
{
return
remove_pattern
(
buf
,
size
,
check
_verity_pattern
);
return
remove_pattern
(
static_cast
<
char
*>
(
buf
),
size
,
skip
_verity_pattern
);
}
}
uint32_t
patch_encryption
(
void
*
buf
,
uint32_t
size
)
{
uint32_t
patch_encryption
(
void
*
buf
,
uint32_t
size
)
{
return
remove_pattern
(
buf
,
size
,
check
_encryption_pattern
);
return
remove_pattern
(
static_cast
<
char
*>
(
buf
),
size
,
skip
_encryption_pattern
);
}
}
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