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
04ef1e64
Commit
04ef1e64
authored
Mar 06, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make parse prop file a util function
parent
b278d07b
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
35 additions
and
59 deletions
+35
-59
bootstages.cpp
native/jni/core/bootstages.cpp
+2
-2
daemon.cpp
native/jni/core/daemon.cpp
+3
-3
resetprop.h
native/jni/include/resetprop.h
+1
-2
hide_utils.cpp
native/jni/magiskhide/hide_utils.cpp
+1
-1
proc_monitor.cpp
native/jni/magiskhide/proc_monitor.cpp
+3
-3
resetprop.cpp
native/jni/resetprop/resetprop.cpp
+6
-43
file.cpp
native/jni/utils/file.cpp
+16
-4
utils.h
native/jni/utils/include/utils.h
+3
-1
No files found.
native/jni/core/bootstages.cpp
View file @
04ef1e64
...
...
@@ -380,7 +380,7 @@ static bool magisk_env() {
LOGI
(
"* Mounting mirrors"
);
bool
system_as_root
=
false
;
file_readline
(
"/proc/mounts"
,
[
&
](
string_view
&
line
)
->
bool
{
file_readline
(
"/proc/mounts"
,
[
&
](
string_view
line
)
->
bool
{
if
(
str_contains
(
line
,
" /system_root "
))
{
bind_mount
(
"/system_root/system"
,
MIRRDIR
"/system"
);
sscanf
(
line
.
data
(),
"%s"
,
buf
);
...
...
@@ -494,7 +494,7 @@ static void collect_modules() {
static
bool
check_data
()
{
bool
mnt
=
false
;
bool
data
=
false
;
file_readline
(
"/proc/mounts"
,
[
&
](
string_view
&
s
)
->
bool
{
file_readline
(
"/proc/mounts"
,
[
&
](
string_view
s
)
->
bool
{
if
(
str_contains
(
s
,
" /data "
)
&&
!
str_contains
(
s
,
"tmpfs"
))
mnt
=
true
;
return
true
;
...
...
native/jni/core/daemon.cpp
View file @
04ef1e64
...
...
@@ -118,9 +118,9 @@ static void main_daemon() {
// Get API level
parse_prop_file
(
"/system/build.prop"
,
[](
auto
key
,
auto
val
)
->
bool
{
if
(
strcmp
(
key
,
"ro.build.version.sdk"
)
==
0
)
{
LOGI
(
"* Device API level: %s
\n
"
,
val
);
SDK_INT
=
atoi
(
val
);
if
(
key
==
"ro.build.version.sdk"
)
{
LOGI
(
"* Device API level: %s
\n
"
,
val
.
data
()
);
SDK_INT
=
atoi
(
val
.
data
()
);
return
false
;
}
return
true
;
...
...
native/jni/include/resetprop.h
View file @
04ef1e64
...
...
@@ -11,5 +11,4 @@ int setprop(const char *name, const char *value, bool trigger = true);
std
::
string
getprop
(
const
char
*
name
,
bool
persist
=
false
);
void
getprop
(
void
(
*
callback
)(
const
char
*
,
const
char
*
,
void
*
),
void
*
cookie
,
bool
persist
=
false
);
int
deleteprop
(
const
char
*
name
,
bool
persist
=
false
);
int
parse_prop_file
(
const
char
*
filename
,
const
std
::
function
<
bool
(
const
char
*
,
const
char
*
)
>
&
cb
);
int
load_prop_file
(
const
char
*
filename
,
bool
trigger
=
true
);
void
load_prop_file
(
const
char
*
filename
,
bool
trigger
=
true
);
native/jni/magiskhide/hide_utils.cpp
View file @
04ef1e64
...
...
@@ -233,7 +233,7 @@ bool init_list() {
// Migrate old hide list into database
if
(
access
(
LEGACY_LIST
,
R_OK
)
==
0
)
{
file_readline
(
LEGACY_LIST
,
[](
string_view
&
s
)
->
bool
{
file_readline
(
LEGACY_LIST
,
[](
string_view
s
)
->
bool
{
add_list
(
s
.
data
());
return
true
;
});
...
...
native/jni/magiskhide/proc_monitor.cpp
View file @
04ef1e64
...
...
@@ -79,7 +79,7 @@ static long xptrace(int request, pid_t pid, void *addr = nullptr, intptr_t data
return
xptrace
(
true
,
request
,
pid
,
addr
,
reinterpret_cast
<
void
*>
(
data
));
}
static
bool
parse_packages_xml
(
string_view
&
s
)
{
static
bool
parse_packages_xml
(
string_view
s
)
{
if
(
!
str_starts
(
s
,
"<package "
))
return
true
;
/* <package key1="value1" key2="value2"....> */
...
...
@@ -144,7 +144,7 @@ static void hide_daemon(int pid) {
vector
<
string
>
targets
;
// Unmount dummy skeletons and /sbin links
file_readline
(
"/proc/self/mounts"
,
[
&
](
string_view
&
s
)
->
bool
{
file_readline
(
"/proc/self/mounts"
,
[
&
](
string_view
s
)
->
bool
{
if
(
str_contains
(
s
,
"tmpfs /system/"
)
||
str_contains
(
s
,
"tmpfs /vendor/"
)
||
str_contains
(
s
,
"tmpfs /sbin"
))
{
char
*
path
=
(
char
*
)
s
.
data
();
...
...
@@ -160,7 +160,7 @@ static void hide_daemon(int pid) {
targets
.
clear
();
// Unmount everything under /system, /vendor, and data mounts
file_readline
(
"/proc/self/mounts"
,
[
&
](
string_view
&
s
)
->
bool
{
file_readline
(
"/proc/self/mounts"
,
[
&
](
string_view
s
)
->
bool
{
if
((
str_contains
(
s
,
" /system/"
)
||
str_contains
(
s
,
" /vendor/"
))
&&
(
str_contains
(
s
,
system_block
)
||
str_contains
(
s
,
vendor_block
)
||
str_contains
(
s
,
data_block
)))
{
...
...
native/jni/resetprop/resetprop.cpp
View file @
04ef1e64
...
...
@@ -206,49 +206,11 @@ int deleteprop(const char *name, bool persist) {
return
__system_property_del
(
name
)
&&
!
(
persist
&&
strncmp
(
name
,
"persist."
,
8
)
==
0
);
}
int
parse_prop_file
(
const
char
*
filename
,
const
function
<
bool
(
const
char
*
,
const
char
*
)
>
&
cb
)
{
void
load_prop_file
(
const
char
*
filename
,
bool
trigger
)
{
if
(
init_resetprop
())
return
;
LOGD
(
"resetprop: Parse prop file [%s]
\n
"
,
filename
);
FILE
*
fp
=
xfopen
(
filename
,
"re"
);
if
(
fp
==
nullptr
)
{
LOGE
(
"Cannot open [%s]
\n
"
,
filename
);
return
1
;
}
char
*
line
=
nullptr
,
*
eql
;
size_t
len
;
ssize_t
read
;
int
i
;
while
((
read
=
getline
(
&
line
,
&
len
,
fp
))
!=
-
1
)
{
// Remove the trailing newline
if
(
line
[
read
-
1
]
==
'\n'
)
{
line
[
--
read
]
=
'\0'
;
}
bool
comment
=
false
;
for
(
i
=
0
;
i
<
read
;
++
i
)
{
// Ignore starting spaces
if
(
line
[
i
]
==
' '
)
continue
;
// A line starting with # is ignored
if
(
line
[
i
]
==
'#'
)
comment
=
true
;
break
;
}
if
(
comment
)
continue
;
eql
=
strchr
(
line
,
'='
);
// Ignore invalid formats
if
(
((
eql
==
nullptr
)
||
(
i
>=
(
eql
-
line
)))
||
(
eql
>=
line
+
read
-
1
)
)
continue
;
// Separate the string
*
eql
=
'\0'
;
if
(
!
cb
(
line
+
i
,
eql
+
1
))
break
;
}
free
(
line
);
fclose
(
fp
);
return
0
;
}
int
load_prop_file
(
const
char
*
filename
,
bool
trigger
)
{
if
(
init_resetprop
())
return
-
1
;
return
parse_prop_file
(
filename
,
[
=
](
auto
key
,
auto
val
)
->
bool
{
setprop
(
key
,
val
,
trigger
);
parse_prop_file
(
filename
,
[
=
](
auto
key
,
auto
val
)
->
bool
{
setprop
(
key
.
data
(),
val
.
data
(),
trigger
);
return
true
;
});
}
...
...
@@ -269,7 +231,8 @@ int resetprop_main(int argc, char *argv[]) {
switch
(
argv
[
0
][
idx
])
{
case
'-'
:
if
(
strcmp
(
argv
[
0
],
"--file"
)
==
0
&&
argc
==
2
)
{
return
load_prop_file
(
argv
[
1
],
trigger
);
load_prop_file
(
argv
[
1
],
trigger
);
return
0
;
}
else
if
(
strcmp
(
argv
[
0
],
"--delete"
)
==
0
&&
argc
==
2
)
{
return
deleteprop
(
argv
[
1
],
persist
);
}
else
if
(
strcmp
(
argv
[
0
],
"--help"
)
==
0
)
{
...
...
native/jni/utils/file.cpp
View file @
04ef1e64
...
...
@@ -367,8 +367,8 @@ void write_zero(int fd, size_t size) {
}
}
void
file_readline
(
const
char
*
file
name
,
const
function
<
bool
(
string_view
&
)
>
&
fn
,
bool
trim
)
{
FILE
*
fp
=
xfopen
(
file
name
,
"re"
);
void
file_readline
(
const
char
*
file
,
const
function
<
bool
(
string_view
)
>
&
fn
,
bool
trim
)
{
FILE
*
fp
=
xfopen
(
file
,
"re"
);
if
(
fp
==
nullptr
)
return
;
size_t
len
=
1024
;
...
...
@@ -383,10 +383,22 @@ void file_readline(const char *filename, const function<bool (string_view&)> &fn
while
(
*
start
==
' '
)
++
start
;
}
string_view
s
(
start
);
if
(
!
fn
(
s
))
if
(
!
fn
(
start
))
break
;
}
fclose
(
fp
);
free
(
buf
);
}
void
parse_prop_file
(
const
char
*
file
,
const
function
<
bool
(
string_view
,
string_view
)
>
&
fn
)
{
file_readline
(
file
,
[
&
](
string_view
line_view
)
->
bool
{
char
*
line
=
(
char
*
)
line_view
.
data
();
if
(
line
[
0
]
==
'#'
)
return
true
;
char
*
eql
=
strchr
(
line
,
'='
);
if
(
eql
==
nullptr
||
eql
==
line
)
return
true
;
*
eql
=
'\0'
;
return
fn
(
line
,
eql
+
1
);
},
true
);
}
native/jni/utils/include/utils.h
View file @
04ef1e64
...
...
@@ -172,7 +172,9 @@ private:
// file.cpp
void
file_readline
(
const
char
*
filename
,
const
std
::
function
<
bool
(
std
::
string_view
&
)
>
&
fn
,
bool
trim
=
false
);
void
file_readline
(
const
char
*
file
,
const
std
::
function
<
bool
(
std
::
string_view
)
>
&
fn
,
bool
trim
=
false
);
void
parse_prop_file
(
const
char
*
file
,
const
std
::
function
<
bool
(
std
::
string_view
,
std
::
string_view
)
>
&
fn
);
void
*
__mmap
(
const
char
*
filename
,
size_t
*
size
,
bool
rw
);
template
<
typename
B
>
...
...
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