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
eca21686
Commit
eca21686
authored
May 17, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Guard magiskhide state with mutexes
parent
1bcef387
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
19 deletions
+26
-19
hide_utils.cpp
native/jni/magiskhide/hide_utils.cpp
+23
-14
magiskhide.cpp
native/jni/magiskhide/magiskhide.cpp
+2
-4
magiskhide.hpp
native/jni/magiskhide/magiskhide.hpp
+1
-1
No files found.
native/jni/magiskhide/hide_utils.cpp
View file @
eca21686
...
@@ -34,6 +34,14 @@ void crawl_procfs(DIR *dir, const function<bool (int)> &fn) {
...
@@ -34,6 +34,14 @@ void crawl_procfs(DIR *dir, const function<bool (int)> &fn) {
}
}
}
}
static
bool
hide_state
=
false
;
static
pthread_mutex_t
hide_state_lock
=
PTHREAD_MUTEX_INITIALIZER
;
bool
hide_enabled
()
{
mutex_guard
g
(
hide_state_lock
);
return
hide_state
;
}
static
bool
proc_name_match
(
int
pid
,
const
char
*
name
)
{
static
bool
proc_name_match
(
int
pid
,
const
char
*
name
)
{
char
buf
[
4019
];
char
buf
[
4019
];
sprintf
(
buf
,
"/proc/%d/cmdline"
,
pid
);
sprintf
(
buf
,
"/proc/%d/cmdline"
,
pid
);
...
@@ -206,39 +214,40 @@ void ls_list(int client) {
...
@@ -206,39 +214,40 @@ void ls_list(int client) {
static
void
set_hide_config
()
{
static
void
set_hide_config
()
{
char
sql
[
64
];
char
sql
[
64
];
sprintf
(
sql
,
"REPLACE INTO settings (key,value) VALUES('%s',%d)"
,
sprintf
(
sql
,
"REPLACE INTO settings (key,value) VALUES('%s',%d)"
,
DB_SETTING_KEYS
[
HIDE_CONFIG
],
hide_
enabled
);
DB_SETTING_KEYS
[
HIDE_CONFIG
],
hide_
state
);
char
*
err
=
db_exec
(
sql
);
char
*
err
=
db_exec
(
sql
);
db_err
(
err
);
db_err
(
err
);
}
}
[[
noreturn
]]
static
void
launch_err
(
int
client
,
int
code
=
DAEMON_ERROR
)
{
[[
noreturn
]]
static
void
launch_err
(
int
client
,
int
code
=
DAEMON_ERROR
)
{
if
(
code
!=
HIDE_IS_ENABLED
)
if
(
code
!=
HIDE_IS_ENABLED
)
hide_
enabled
=
false
;
hide_
state
=
false
;
if
(
client
>=
0
)
{
if
(
client
>=
0
)
{
write_int
(
client
,
code
);
write_int
(
client
,
code
);
close
(
client
);
close
(
client
);
}
}
pthread_mutex_unlock
(
&
hide_state_lock
);
pthread_exit
(
nullptr
);
pthread_exit
(
nullptr
);
}
}
#define LAUNCH_ERR launch_err(client)
void
launch_magiskhide
(
int
client
)
{
void
launch_magiskhide
(
int
client
)
{
pthread_mutex_lock
(
&
hide_state_lock
);
if
(
SDK_INT
<
19
)
if
(
SDK_INT
<
19
)
LAUNCH_ERR
;
launch_err
(
client
)
;
if
(
hide_
enabled
)
if
(
hide_
state
)
launch_err
(
client
,
HIDE_IS_ENABLED
);
launch_err
(
client
,
HIDE_IS_ENABLED
);
if
(
access
(
"/proc/1/ns/mnt"
,
F_OK
)
!=
0
)
if
(
access
(
"/proc/1/ns/mnt"
,
F_OK
)
!=
0
)
launch_err
(
client
,
HIDE_NO_NS
);
launch_err
(
client
,
HIDE_NO_NS
);
hide_
enabled
=
true
;
hide_
state
=
true
;
set_hide_config
();
set_hide_config
();
LOGI
(
"* Starting MagiskHide
\n
"
);
LOGI
(
"* Starting MagiskHide
\n
"
);
if
(
procfp
==
nullptr
&&
(
procfp
=
opendir
(
"/proc"
))
==
nullptr
)
if
(
procfp
==
nullptr
&&
(
procfp
=
opendir
(
"/proc"
))
==
nullptr
)
LAUNCH_ERR
;
launch_err
(
client
)
;
hide_sensitive_props
();
hide_sensitive_props
();
...
@@ -247,7 +256,7 @@ void launch_magiskhide(int client) {
...
@@ -247,7 +256,7 @@ void launch_magiskhide(int client) {
// Initialize the hide list
// Initialize the hide list
if
(
!
init_list
())
if
(
!
init_list
())
LAUNCH_ERR
;
launch_err
(
client
)
;
// Get thread reference
// Get thread reference
proc_monitor_thread
=
pthread_self
();
proc_monitor_thread
=
pthread_self
();
...
@@ -260,23 +269,23 @@ void launch_magiskhide(int client) {
...
@@ -260,23 +269,23 @@ void launch_magiskhide(int client) {
proc_monitor
();
proc_monitor
();
// proc_monitor should not return
// proc_monitor should not return
LAUNCH_ERR
;
launch_err
(
client
)
;
}
}
int
stop_magiskhide
()
{
int
stop_magiskhide
()
{
LOGI
(
"* Stopping MagiskHide
\n
"
);
LOGI
(
"* Stopping MagiskHide
\n
"
);
if
(
hide_enabled
)
mutex_guard
g
(
hide_state_lock
);
if
(
hide_state
)
pthread_kill
(
proc_monitor_thread
,
SIGTERMTHRD
);
pthread_kill
(
proc_monitor_thread
,
SIGTERMTHRD
);
hide_state
=
false
;
hide_enabled
=
false
;
set_hide_config
();
set_hide_config
();
return
DAEMON_SUCCESS
;
return
DAEMON_SUCCESS
;
}
}
void
auto_start_magiskhide
()
{
void
auto_start_magiskhide
()
{
if
(
hide_enabled
)
{
if
(
hide_enabled
()
)
{
pthread_kill
(
proc_monitor_thread
,
SIGZYGOTE
);
pthread_kill
(
proc_monitor_thread
,
SIGZYGOTE
);
}
else
if
(
SDK_INT
>=
19
)
{
}
else
if
(
SDK_INT
>=
19
)
{
db_settings
dbs
;
db_settings
dbs
;
...
...
native/jni/magiskhide/magiskhide.cpp
View file @
eca21686
...
@@ -16,8 +16,6 @@
...
@@ -16,8 +16,6 @@
using
namespace
std
::
literals
;
using
namespace
std
::
literals
;
bool
hide_enabled
=
false
;
[[
noreturn
]]
static
void
usage
(
char
*
arg0
)
{
[[
noreturn
]]
static
void
usage
(
char
*
arg0
)
{
fprintf
(
stderr
,
fprintf
(
stderr
,
NAME_WITH_VER
(
MagiskHide
)
"
\n\n
"
NAME_WITH_VER
(
MagiskHide
)
"
\n\n
"
...
@@ -47,7 +45,7 @@ void magiskhide_handler(int client) {
...
@@ -47,7 +45,7 @@ void magiskhide_handler(int client) {
case
ADD_HIDELIST
:
case
ADD_HIDELIST
:
case
RM_HIDELIST
:
case
RM_HIDELIST
:
case
LS_HIDELIST
:
case
LS_HIDELIST
:
if
(
!
hide_enabled
)
{
if
(
!
hide_enabled
()
)
{
write_int
(
client
,
HIDE_NOT_ENABLED
);
write_int
(
client
,
HIDE_NOT_ENABLED
);
close
(
client
);
close
(
client
);
return
;
return
;
...
@@ -72,7 +70,7 @@ void magiskhide_handler(int client) {
...
@@ -72,7 +70,7 @@ void magiskhide_handler(int client) {
client
=
-
1
;
client
=
-
1
;
break
;
break
;
case
HIDE_STATUS
:
case
HIDE_STATUS
:
res
=
hide_enabled
?
HIDE_IS_ENABLED
:
HIDE_NOT_ENABLED
;
res
=
hide_enabled
()
?
HIDE_IS_ENABLED
:
HIDE_NOT_ENABLED
;
break
;
break
;
}
}
...
...
native/jni/magiskhide/magiskhide.hpp
View file @
eca21686
...
@@ -30,13 +30,13 @@ void update_uid_map();
...
@@ -30,13 +30,13 @@ void update_uid_map();
// Utility functions
// Utility functions
void
crawl_procfs
(
const
std
::
function
<
bool
(
int
)
>
&
fn
);
void
crawl_procfs
(
const
std
::
function
<
bool
(
int
)
>
&
fn
);
void
crawl_procfs
(
DIR
*
dir
,
const
std
::
function
<
bool
(
int
)
>
&
fn
);
void
crawl_procfs
(
DIR
*
dir
,
const
std
::
function
<
bool
(
int
)
>
&
fn
);
bool
hide_enabled
();
// Hide policies
// Hide policies
void
hide_daemon
(
int
pid
);
void
hide_daemon
(
int
pid
);
void
hide_unmount
(
int
pid
=
getpid
());
void
hide_unmount
(
int
pid
=
getpid
());
void
hide_sensitive_props
();
void
hide_sensitive_props
();
extern
bool
hide_enabled
;
extern
pthread_mutex_t
monitor_lock
;
extern
pthread_mutex_t
monitor_lock
;
extern
std
::
set
<
std
::
pair
<
std
::
string
,
std
::
string
>>
hide_set
;
extern
std
::
set
<
std
::
pair
<
std
::
string
,
std
::
string
>>
hide_set
;
...
...
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