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
79e89628
Commit
79e89628
authored
May 25, 2021
by
vvb2060
Committed by
John Wu
Aug 29, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support bootconfig
https://android-review.googlesource.com/c/platform/system/core/+/1615298
parent
34e5a7cd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
97 additions
and
39 deletions
+97
-39
getinfo.cpp
native/jni/init/getinfo.cpp
+71
-32
mount.cpp
native/jni/init/mount.cpp
+0
-7
misc.cpp
native/jni/utils/misc.cpp
+13
-0
misc.hpp
native/jni/utils/misc.hpp
+13
-0
No files found.
native/jni/init/getinfo.cpp
View file @
79e89628
...
@@ -13,33 +13,48 @@ using namespace std;
...
@@ -13,33 +13,48 @@ using namespace std;
vector
<
string
>
mount_list
;
vector
<
string
>
mount_list
;
template
<
typename
Func
>
static
vector
<
pair
<
string
,
string
>>
parse_cmdline
(
const
string
&
cmdline
)
{
static
void
parse_cmdline
(
const
Func
&
fn
)
{
vector
<
pair
<
string
,
string
>>
result
;
char
cmdline
[
4096
];
size_t
base
=
0
;
int
fd
=
xopen
(
"/proc/cmdline"
,
O_RDONLY
|
O_CLOEXEC
);
while
(
true
)
{
cmdline
[
read
(
fd
,
cmdline
,
sizeof
(
cmdline
))]
=
'\0'
;
auto
found
=
base
;
close
(
fd
);
while
(((
found
=
cmdline
.
find_first_of
(
"
\"
"
,
found
))
!=
string
::
npos
)
&&
(
cmdline
[
found
]
==
'"'
))
{
char
*
tok
,
*
eql
,
*
tmp
,
*
saveptr
;
if
((
found
=
cmdline
.
find
(
'"'
,
found
+
1
))
==
string
::
npos
)
saveptr
=
cmdline
;
break
;
while
((
tok
=
strtok_r
(
nullptr
,
"
\n
"
,
&
saveptr
))
!=
nullptr
)
{
found
++
;
eql
=
strchr
(
tok
,
'='
);
}
if
(
eql
)
{
string
piece
;
*
eql
=
'\0'
;
auto
source
=
cmdline
.
substr
(
base
,
found
-
base
);
if
(
eql
[
1
]
==
'"'
)
{
remove_copy
(
source
.
begin
(),
source
.
end
(),
back_insert_iterator
<
string
>
(
piece
),
'"'
);
tmp
=
strchr
(
saveptr
,
'"'
);
auto
equal_sign
=
piece
.
find
(
'='
);
if
(
tmp
!=
nullptr
)
{
if
(
equal_sign
==
string
::
npos
)
{
*
tmp
=
'\0'
;
if
(
!
piece
.
empty
())
saveptr
[
-
1
]
=
' '
;
result
.
emplace_back
(
std
::
move
(
piece
),
""
);
saveptr
=
tmp
+
1
;
}
else
{
eql
++
;
result
.
emplace_back
(
piece
.
substr
(
0
,
equal_sign
),
piece
.
substr
(
equal_sign
+
1
));
}
}
}
if
(
found
==
string
::
npos
)
fn
(
tok
,
eql
+
1
);
break
;
base
=
found
+
1
;
}
return
result
;
}
static
vector
<
pair
<
string
,
string
>>
parse_bootconfig
(
const
string
&
bootconfig
)
{
vector
<
pair
<
string
,
string
>>
result
;
for
(
auto
&
line
:
split
(
bootconfig
,
"
\n
"
))
{
line
.
erase
(
remove
(
line
.
begin
(),
line
.
end
(),
'"'
),
line
.
end
());
auto
equal_sign
=
line
.
find
(
'='
);
if
(
equal_sign
==
string
::
npos
)
{
if
(
!
line
.
empty
())
result
.
emplace_back
(
move
(
line
),
""
);
}
else
{
}
else
{
fn
(
tok
,
""
);
result
.
emplace_back
(
rtrim
(
line
.
substr
(
0
,
equal_sign
)),
ltrim
(
line
.
substr
(
equal_sign
+
1
)));
}
}
}
}
return
result
;
}
}
#define test_bit(bit, array) (array[bit / 8] & (1 << (bit % 8)))
#define test_bit(bit, array) (array[bit / 8] & (1 << (bit % 8)))
...
@@ -155,12 +170,12 @@ void load_kernel_info(cmdline *cmd) {
...
@@ -155,12 +170,12 @@ void load_kernel_info(cmdline *cmd) {
// Log to kernel
// Log to kernel
setup_klog
();
setup_klog
();
parse_cmdline
([
=
](
string_view
key
,
const
char
*
value
)
{
for
(
const
auto
&
[
key
,
value
]
:
parse_cmdline
(
full_read
(
"/proc/cmdline"
))
)
{
if
(
key
==
"androidboot.slot_suffix"
)
{
if
(
key
==
"androidboot.slot_suffix"
)
{
strcpy
(
cmd
->
slot
,
value
);
strcpy
(
cmd
->
slot
,
value
.
data
()
);
}
else
if
(
key
==
"androidboot.slot"
)
{
}
else
if
(
key
==
"androidboot.slot"
)
{
cmd
->
slot
[
0
]
=
'_'
;
cmd
->
slot
[
0
]
=
'_'
;
strcpy
(
cmd
->
slot
+
1
,
value
);
strcpy
(
cmd
->
slot
+
1
,
value
.
data
()
);
}
else
if
(
key
==
"skip_initramfs"
)
{
}
else
if
(
key
==
"skip_initramfs"
)
{
cmd
->
skip_initramfs
=
true
;
cmd
->
skip_initramfs
=
true
;
}
else
if
(
key
==
"androidboot.force_normal_boot"
)
{
}
else
if
(
key
==
"androidboot.force_normal_boot"
)
{
...
@@ -168,15 +183,15 @@ void load_kernel_info(cmdline *cmd) {
...
@@ -168,15 +183,15 @@ void load_kernel_info(cmdline *cmd) {
}
else
if
(
key
==
"rootwait"
)
{
}
else
if
(
key
==
"rootwait"
)
{
cmd
->
rootwait
=
true
;
cmd
->
rootwait
=
true
;
}
else
if
(
key
==
"androidboot.android_dt_dir"
)
{
}
else
if
(
key
==
"androidboot.android_dt_dir"
)
{
strcpy
(
cmd
->
dt_dir
,
value
);
strcpy
(
cmd
->
dt_dir
,
value
.
data
()
);
}
else
if
(
key
==
"androidboot.hardware"
)
{
}
else
if
(
key
==
"androidboot.hardware"
)
{
strcpy
(
cmd
->
hardware
,
value
);
strcpy
(
cmd
->
hardware
,
value
.
data
()
);
}
else
if
(
key
==
"androidboot.hardware.platform"
)
{
}
else
if
(
key
==
"androidboot.hardware.platform"
)
{
strcpy
(
cmd
->
hardware_plat
,
value
);
strcpy
(
cmd
->
hardware_plat
,
value
.
data
()
);
}
else
if
(
key
==
"androidboot.fstab_suffix"
)
{
}
else
if
(
key
==
"androidboot.fstab_suffix"
)
{
strcpy
(
cmd
->
fstab_suffix
,
value
);
strcpy
(
cmd
->
fstab_suffix
,
value
.
data
()
);
}
}
}
);
}
LOGD
(
"Kernel cmdline info:
\n
"
);
LOGD
(
"Kernel cmdline info:
\n
"
);
LOGD
(
"skip_initramfs=[%d]
\n
"
,
cmd
->
skip_initramfs
);
LOGD
(
"skip_initramfs=[%d]
\n
"
,
cmd
->
skip_initramfs
);
...
@@ -188,6 +203,30 @@ void load_kernel_info(cmdline *cmd) {
...
@@ -188,6 +203,30 @@ void load_kernel_info(cmdline *cmd) {
LOGD
(
"hardware=[%s]
\n
"
,
cmd
->
hardware
);
LOGD
(
"hardware=[%s]
\n
"
,
cmd
->
hardware
);
LOGD
(
"hardware.platform=[%s]
\n
"
,
cmd
->
hardware_plat
);
LOGD
(
"hardware.platform=[%s]
\n
"
,
cmd
->
hardware_plat
);
for
(
const
auto
&
[
key
,
value
]
:
parse_bootconfig
(
full_read
(
"/proc/bootconfig"
)))
{
if
(
key
==
"androidboot.slot_suffix"
)
{
strcpy
(
cmd
->
slot
,
value
.
data
());
}
else
if
(
key
==
"androidboot.force_normal_boot"
)
{
cmd
->
force_normal_boot
=
value
[
0
]
==
'1'
;
}
else
if
(
key
==
"androidboot.android_dt_dir"
)
{
strcpy
(
cmd
->
dt_dir
,
value
.
data
());
}
else
if
(
key
==
"androidboot.hardware"
)
{
strcpy
(
cmd
->
hardware
,
value
.
data
());
}
else
if
(
key
==
"androidboot.hardware.platform"
)
{
strcpy
(
cmd
->
hardware_plat
,
value
.
data
());
}
else
if
(
key
==
"androidboot.fstab_suffix"
)
{
strcpy
(
cmd
->
fstab_suffix
,
value
.
data
());
}
}
LOGD
(
"Boot config info:
\n
"
);
LOGD
(
"force_normal_boot=[%d]
\n
"
,
cmd
->
force_normal_boot
);
LOGD
(
"slot=[%s]
\n
"
,
cmd
->
slot
);
LOGD
(
"dt_dir=[%s]
\n
"
,
cmd
->
dt_dir
);
LOGD
(
"fstab_suffix=[%s]
\n
"
,
cmd
->
fstab_suffix
);
LOGD
(
"hardware=[%s]
\n
"
,
cmd
->
hardware
);
LOGD
(
"hardware.platform=[%s]
\n
"
,
cmd
->
hardware_plat
);
parse_prop_file
(
"/.backup/.magisk"
,
[
=
](
auto
key
,
auto
value
)
->
bool
{
parse_prop_file
(
"/.backup/.magisk"
,
[
=
](
auto
key
,
auto
value
)
->
bool
{
if
(
key
==
"RECOVERYMODE"
&&
value
==
"true"
)
{
if
(
key
==
"RECOVERYMODE"
&&
value
==
"true"
)
{
LOGD
(
"Running in recovery mode, waiting for key...
\n
"
);
LOGD
(
"Running in recovery mode, waiting for key...
\n
"
);
...
...
native/jni/init/mount.cpp
View file @
79e89628
...
@@ -10,13 +10,6 @@
...
@@ -10,13 +10,6 @@
using
namespace
std
;
using
namespace
std
;
static
string
rtrim
(
string
&&
str
)
{
// Trim space, newline, and null byte from end of string
while
(
memchr
(
"
\n\r
"
,
str
[
str
.
length
()
-
1
],
4
))
str
.
pop_back
();
return
std
::
move
(
str
);
}
struct
devinfo
{
struct
devinfo
{
int
major
;
int
major
;
int
minor
;
int
minor
;
...
...
native/jni/utils/misc.cpp
View file @
79e89628
...
@@ -188,3 +188,16 @@ string &replace_all(string &str, string_view from, string_view to) {
...
@@ -188,3 +188,16 @@ string &replace_all(string &str, string_view from, string_view to) {
}
}
return
str
;
return
str
;
}
}
vector
<
string
>
split
(
const
string
&
s
,
const
string
&
delimiters
)
{
vector
<
string
>
result
;
size_t
base
=
0
;
size_t
found
;
while
(
true
)
{
found
=
s
.
find_first_of
(
delimiters
,
base
);
result
.
push_back
(
s
.
substr
(
base
,
found
-
base
));
if
(
found
==
string
::
npos
)
break
;
base
=
found
+
1
;
}
return
result
;
}
native/jni/utils/misc.hpp
View file @
79e89628
...
@@ -92,6 +92,18 @@ static inline bool str_starts(std::string_view s, std::string_view ss) {
...
@@ -92,6 +92,18 @@ static inline bool str_starts(std::string_view s, std::string_view ss) {
static
inline
bool
str_ends
(
std
::
string_view
s
,
std
::
string_view
ss
)
{
static
inline
bool
str_ends
(
std
::
string_view
s
,
std
::
string_view
ss
)
{
return
s
.
size
()
>=
ss
.
size
()
&&
s
.
compare
(
s
.
size
()
-
ss
.
size
(),
std
::
string
::
npos
,
ss
)
==
0
;
return
s
.
size
()
>=
ss
.
size
()
&&
s
.
compare
(
s
.
size
()
-
ss
.
size
(),
std
::
string
::
npos
,
ss
)
==
0
;
}
}
static
inline
std
::
string
ltrim
(
std
::
string
&&
s
)
{
s
.
erase
(
s
.
begin
(),
std
::
find_if
(
s
.
begin
(),
s
.
end
(),
[](
unsigned
char
ch
)
{
return
!
std
::
isspace
(
ch
);
}));
return
std
::
move
(
s
);
}
static
inline
std
::
string
rtrim
(
std
::
string
&&
s
)
{
s
.
erase
(
std
::
find_if
(
s
.
rbegin
(),
s
.
rend
(),
[](
unsigned
char
ch
)
{
return
!
std
::
isspace
(
ch
)
&&
ch
!=
'\0'
;
}).
base
(),
s
.
end
());
return
std
::
move
(
s
);
}
int
fork_dont_care
();
int
fork_dont_care
();
int
fork_no_orphan
();
int
fork_no_orphan
();
...
@@ -101,6 +113,7 @@ uint32_t binary_gcd(uint32_t u, uint32_t v);
...
@@ -101,6 +113,7 @@ uint32_t binary_gcd(uint32_t u, uint32_t v);
int
switch_mnt_ns
(
int
pid
);
int
switch_mnt_ns
(
int
pid
);
int
gen_rand_str
(
char
*
buf
,
int
len
,
bool
varlen
=
true
);
int
gen_rand_str
(
char
*
buf
,
int
len
,
bool
varlen
=
true
);
std
::
string
&
replace_all
(
std
::
string
&
str
,
std
::
string_view
from
,
std
::
string_view
to
);
std
::
string
&
replace_all
(
std
::
string
&
str
,
std
::
string_view
from
,
std
::
string_view
to
);
std
::
vector
<
std
::
string
>
split
(
const
std
::
string
&
s
,
const
std
::
string
&
delimiters
);
struct
exec_t
{
struct
exec_t
{
bool
err
=
false
;
bool
err
=
false
;
...
...
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