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
be758613
Commit
be758613
authored
Mar 01, 2022
by
topjohnwu
Committed by
John Wu
Mar 01, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce C++ wizardry
parent
7999b66c
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
100 additions
and
146 deletions
+100
-146
bootstages.cpp
native/jni/core/bootstages.cpp
+1
-1
daemon.cpp
native/jni/core/daemon.cpp
+41
-54
magisk.cpp
native/jni/core/magisk.cpp
+10
-11
daemon.hpp
native/jni/include/daemon.hpp
+8
-4
su.cpp
native/jni/su/su.cpp
+1
-1
misc.hpp
native/jni/utils/misc.hpp
+0
-31
cli.cpp
native/jni/zygisk/deny/cli.cpp
+14
-15
deny.hpp
native/jni/zygisk/deny/deny.hpp
+10
-13
utils.cpp
native/jni/zygisk/deny/utils.cpp
+6
-6
entry.cpp
native/jni/zygisk/entry.cpp
+3
-5
zygisk.hpp
native/jni/zygisk/zygisk.hpp
+6
-5
No files found.
native/jni/core/bootstages.cpp
View file @
be758613
...
@@ -14,7 +14,6 @@
...
@@ -14,7 +14,6 @@
#include <selinux.hpp>
#include <selinux.hpp>
#include "core.hpp"
#include "core.hpp"
#include "zygisk/deny/deny.hpp"
using
namespace
std
;
using
namespace
std
;
...
@@ -264,6 +263,7 @@ static bool check_key_combo() {
...
@@ -264,6 +263,7 @@ static bool check_key_combo() {
***********************/
***********************/
static
pthread_mutex_t
stage_lock
=
PTHREAD_MUTEX_INITIALIZER
;
static
pthread_mutex_t
stage_lock
=
PTHREAD_MUTEX_INITIALIZER
;
extern
int
disable_deny
();
void
post_fs_data
(
int
client
)
{
void
post_fs_data
(
int
client
)
{
// ack
// ack
...
...
native/jni/core/daemon.cpp
View file @
be758613
...
@@ -133,34 +133,33 @@ static void poll_ctrl_handler(pollfd *pfd) {
...
@@ -133,34 +133,33 @@ static void poll_ctrl_handler(pollfd *pfd) {
}
}
}
}
static
void
handle_request_async
(
int
client
,
DaemonRequest
code
,
const
sock_cred
&
cred
)
{
static
void
handle_request_async
(
int
client
,
int
code
,
const
sock_cred
&
cred
)
{
// using enum DAEMON_REQUEST;
switch
(
code
)
{
switch
(
code
)
{
case
Daemo
nRequest
:
:
DENYLIST
:
case
Mai
nRequest
:
:
DENYLIST
:
denylist_handler
(
client
,
&
cred
);
denylist_handler
(
client
,
&
cred
);
break
;
break
;
case
Daemo
nRequest
:
:
SUPERUSER
:
case
Mai
nRequest
:
:
SUPERUSER
:
su_daemon_handler
(
client
,
&
cred
);
su_daemon_handler
(
client
,
&
cred
);
break
;
break
;
case
Daemo
nRequest
:
:
POST_FS_DATA
:
case
Mai
nRequest
:
:
POST_FS_DATA
:
post_fs_data
(
client
);
post_fs_data
(
client
);
break
;
break
;
case
Daemo
nRequest
:
:
LATE_START
:
case
Mai
nRequest
:
:
LATE_START
:
late_start
(
client
);
late_start
(
client
);
break
;
break
;
case
Daemo
nRequest
:
:
BOOT_COMPLETE
:
case
Mai
nRequest
:
:
BOOT_COMPLETE
:
boot_complete
(
client
);
boot_complete
(
client
);
break
;
break
;
case
Daemo
nRequest
:
:
SQLITE_CMD
:
case
Mai
nRequest
:
:
SQLITE_CMD
:
exec_sql
(
client
);
exec_sql
(
client
);
break
;
break
;
case
Daemo
nRequest
:
:
REMOVE_MODULES
:
case
Mai
nRequest
:
:
REMOVE_MODULES
:
remove_modules
();
remove_modules
();
write_int
(
client
,
0
);
write_int
(
client
,
0
);
close
(
client
);
close
(
client
);
reboot
();
reboot
();
break
;
break
;
case
DaemonRequest
:
:
ZYGISK_REQUEST
:
case
MainRequest
:
:
ZYGISK
:
zygisk_handler
(
client
,
&
cred
);
zygisk_handler
(
client
,
&
cred
);
break
;
break
;
default
:
default
:
...
@@ -168,22 +167,21 @@ static void handle_request_async(int client, DaemonRequest code, const sock_cred
...
@@ -168,22 +167,21 @@ static void handle_request_async(int client, DaemonRequest code, const sock_cred
}
}
}
}
static
void
handle_request_sync
(
int
client
,
DaemonRequest
code
)
{
static
void
handle_request_sync
(
int
client
,
int
code
)
{
// using enum DAEMON_REQUEST;
switch
(
code
)
{
switch
(
code
)
{
case
Daemo
nRequest
:
:
CHECK_VERSION
:
case
Mai
nRequest
:
:
CHECK_VERSION
:
write_string
(
client
,
MAGISK_VERSION
":MAGISK"
);
write_string
(
client
,
MAGISK_VERSION
":MAGISK"
);
break
;
break
;
case
Daemo
nRequest
:
:
CHECK_VERSION_CODE
:
case
Mai
nRequest
:
:
CHECK_VERSION_CODE
:
write_int
(
client
,
MAGISK_VER_CODE
);
write_int
(
client
,
MAGISK_VER_CODE
);
break
;
break
;
case
Daemo
nRequest
:
:
GET_PATH
:
case
Mai
nRequest
:
:
GET_PATH
:
write_string
(
client
,
MAGISKTMP
.
data
());
write_string
(
client
,
MAGISKTMP
.
data
());
break
;
break
;
case
Daemo
nRequest
:
:
START_DAEMON
:
case
Mai
nRequest
:
:
START_DAEMON
:
setup_logfile
(
true
);
setup_logfile
(
true
);
break
;
break
;
case
Daemo
nRequest
:
:
STOP_DAEMON
:
case
Mai
nRequest
:
:
STOP_DAEMON
:
denylist_handler
(
-
1
,
nullptr
);
denylist_handler
(
-
1
,
nullptr
);
write_int
(
client
,
0
);
write_int
(
client
,
0
);
// Terminate the daemon!
// Terminate the daemon!
...
@@ -201,13 +199,7 @@ static bool is_client(pid_t pid) {
...
@@ -201,13 +199,7 @@ static bool is_client(pid_t pid) {
return
!
(
stat
(
path
,
&
st
)
||
st
.
st_dev
!=
self_st
.
st_dev
||
st
.
st_ino
!=
self_st
.
st_ino
);
return
!
(
stat
(
path
,
&
st
)
||
st
.
st_dev
!=
self_st
.
st_dev
||
st
.
st_ino
!=
self_st
.
st_ino
);
}
}
inline
static
void
write_response
(
int
client
,
DaemonResponse
res
)
{
write_int
(
client
,
static_cast
<
std
::
underlying_type_t
<
DaemonResponse
>>
(
res
));
}
static
void
handle_request
(
pollfd
*
pfd
)
{
static
void
handle_request
(
pollfd
*
pfd
)
{
// using enum DAEMON_REQUEST;
// using enum DAEMON_RESPONSE;
int
client
=
xaccept4
(
pfd
->
fd
,
nullptr
,
nullptr
,
SOCK_CLOEXEC
);
int
client
=
xaccept4
(
pfd
->
fd
,
nullptr
,
nullptr
,
SOCK_CLOEXEC
);
// Verify client credentials
// Verify client credentials
...
@@ -215,7 +207,6 @@ static void handle_request(pollfd *pfd) {
...
@@ -215,7 +207,6 @@ static void handle_request(pollfd *pfd) {
bool
is_root
;
bool
is_root
;
bool
is_zygote
;
bool
is_zygote
;
int
code
;
int
code
;
DaemonRequest
req
;
if
(
!
get_client_cred
(
client
,
&
cred
))
if
(
!
get_client_cred
(
client
,
&
cred
))
goto
done
;
goto
done
;
...
@@ -226,30 +217,27 @@ static void handle_request(pollfd *pfd) {
...
@@ -226,30 +217,27 @@ static void handle_request(pollfd *pfd) {
goto
done
;
goto
done
;
code
=
read_int
(
client
);
code
=
read_int
(
client
);
static_assert
(
is_scoped_enum_v
<
DaemonRequest
>
);
if
(
code
<
0
||
code
>=
DaemonRequest
::
END
||
code
==
Daemo
nRequest
::
_SYNC_BARRIER_
)
if
(
code
<
0
||
code
>=
MainRequest
::
END
||
code
==
Mai
nRequest
::
_SYNC_BARRIER_
)
goto
done
;
goto
done
;
req
=
static_cast
<
DaemonRequest
>
(
code
);
// Check client permissions
// Check client permissions
switch
(
req
)
{
switch
(
code
)
{
case
Daemo
nRequest
:
:
POST_FS_DATA
:
case
Mai
nRequest
:
:
POST_FS_DATA
:
case
Daemo
nRequest
:
:
LATE_START
:
case
Mai
nRequest
:
:
LATE_START
:
case
Daemo
nRequest
:
:
BOOT_COMPLETE
:
case
Mai
nRequest
:
:
BOOT_COMPLETE
:
case
Daemo
nRequest
:
:
SQLITE_CMD
:
case
Mai
nRequest
:
:
SQLITE_CMD
:
case
Daemo
nRequest
:
:
GET_PATH
:
case
Mai
nRequest
:
:
GET_PATH
:
case
Daemo
nRequest
:
:
DENYLIST
:
case
Mai
nRequest
:
:
DENYLIST
:
case
Daemo
nRequest
:
:
STOP_DAEMON
:
case
Mai
nRequest
:
:
STOP_DAEMON
:
if
(
!
is_root
)
{
if
(
!
is_root
)
{
write_
response
(
client
,
Daemo
nResponse
::
ROOT_REQUIRED
);
write_
int
(
client
,
Mai
nResponse
::
ROOT_REQUIRED
);
goto
done
;
goto
done
;
}
}
break
;
break
;
case
Daemo
nRequest
:
:
REMOVE_MODULES
:
case
Mai
nRequest
:
:
REMOVE_MODULES
:
if
(
!
is_root
&&
cred
.
uid
!=
UID_SHELL
)
{
if
(
!
is_root
&&
cred
.
uid
!=
UID_SHELL
)
{
write_
response
(
client
,
Daemo
nResponse
::
ROOT_REQUIRED
);
write_
int
(
client
,
Mai
nResponse
::
ROOT_REQUIRED
);
goto
done
;
goto
done
;
}
}
break
;
break
;
...
@@ -257,15 +245,15 @@ static void handle_request(pollfd *pfd) {
...
@@ -257,15 +245,15 @@ static void handle_request(pollfd *pfd) {
break
;
break
;
}
}
write_
response
(
client
,
Daemo
nResponse
::
OK
);
write_
int
(
client
,
Mai
nResponse
::
OK
);
if
(
req
<
Daemo
nRequest
::
_SYNC_BARRIER_
)
{
if
(
code
<
Mai
nRequest
::
_SYNC_BARRIER_
)
{
handle_request_sync
(
client
,
req
);
handle_request_sync
(
client
,
code
);
goto
done
;
goto
done
;
}
}
// Handle complex requests in another thread
// Handle complex requests in another thread
exec_task
([
=
]
{
handle_request_async
(
client
,
req
,
cred
);
});
exec_task
([
=
]
{
handle_request_async
(
client
,
code
,
cred
);
});
return
;
return
;
done
:
done
:
...
@@ -402,8 +390,7 @@ static void daemon_entry() {
...
@@ -402,8 +390,7 @@ static void daemon_entry() {
poll_loop
();
poll_loop
();
}
}
int
connect_daemon
(
DaemonRequest
req
,
bool
create
)
{
int
connect_daemon
(
int
req
,
bool
create
)
{
// using enum DAEMON_RESPONSE;
sockaddr_un
sun
{};
sockaddr_un
sun
{};
socklen_t
len
=
setup_sockaddr
(
&
sun
,
MAIN_SOCKET
);
socklen_t
len
=
setup_sockaddr
(
&
sun
,
MAIN_SOCKET
);
int
fd
=
xsocket
(
AF_UNIX
,
SOCK_STREAM
|
SOCK_CLOEXEC
,
0
);
int
fd
=
xsocket
(
AF_UNIX
,
SOCK_STREAM
|
SOCK_CLOEXEC
,
0
);
...
@@ -422,23 +409,23 @@ int connect_daemon(DaemonRequest req, bool create) {
...
@@ -422,23 +409,23 @@ int connect_daemon(DaemonRequest req, bool create) {
while
(
connect
(
fd
,
(
struct
sockaddr
*
)
&
sun
,
len
))
while
(
connect
(
fd
,
(
struct
sockaddr
*
)
&
sun
,
len
))
usleep
(
10000
);
usleep
(
10000
);
}
}
write_int
(
fd
,
static_cast
<
int
>
(
req
)
);
write_int
(
fd
,
req
);
int
re
t
=
read_int
(
fd
);
int
re
s
=
read_int
(
fd
);
auto
res
=
(
ret
<
DaemonResponse
::
ERROR
||
ret
>=
DaemonResponse
::
END
)
?
DaemonResponse
::
ERROR
if
(
res
<
MainResponse
::
ERROR
||
res
>=
MainResponse
::
END
)
:
static_cast
<
DaemonResponse
>
(
ret
)
;
res
=
MainResponse
::
ERROR
;
switch
(
res
)
{
switch
(
res
)
{
case
Daemo
nResponse
:
:
OK
:
case
Mai
nResponse
:
:
OK
:
break
;
break
;
case
Daemo
nResponse
:
:
ERROR
:
case
Mai
nResponse
:
:
ERROR
:
LOGE
(
"Daemon error
\n
"
);
LOGE
(
"Daemon error
\n
"
);
exit
(
-
1
);
exit
(
-
1
);
case
Daemo
nResponse
:
:
ROOT_REQUIRED
:
case
Mai
nResponse
:
:
ROOT_REQUIRED
:
LOGE
(
"Root is required for this operation
\n
"
);
LOGE
(
"Root is required for this operation
\n
"
);
exit
(
-
1
);
exit
(
-
1
);
case
Daemo
nResponse
:
:
INVALID_REQUEST
:
case
Mai
nResponse
:
:
INVALID_REQUEST
:
LOGE
(
"Invalid request
\n
"
);
LOGE
(
"Invalid request
\n
"
);
exit
(
-
1
);
exit
(
-
1
);
case
DaemonResponse
:
:
END
:
default
:
__builtin_unreachable
();
__builtin_unreachable
();
}
}
return
fd
;
return
fd
;
...
...
native/jni/core/magisk.cpp
View file @
be758613
...
@@ -50,19 +50,18 @@ Available applets:
...
@@ -50,19 +50,18 @@ Available applets:
}
}
int
magisk_main
(
int
argc
,
char
*
argv
[])
{
int
magisk_main
(
int
argc
,
char
*
argv
[])
{
// using enum DAEMON_REQUEST;
if
(
argc
<
2
)
if
(
argc
<
2
)
usage
();
usage
();
if
(
argv
[
1
]
==
"-c"
sv
)
{
if
(
argv
[
1
]
==
"-c"
sv
)
{
printf
(
MAGISK_VERSION
":MAGISK ("
str
(
MAGISK_VER_CODE
)
")
\n
"
);
printf
(
MAGISK_VERSION
":MAGISK ("
str
(
MAGISK_VER_CODE
)
")
\n
"
);
return
0
;
return
0
;
}
else
if
(
argv
[
1
]
==
"-v"
sv
)
{
}
else
if
(
argv
[
1
]
==
"-v"
sv
)
{
int
fd
=
connect_daemon
(
Daemo
nRequest
::
CHECK_VERSION
);
int
fd
=
connect_daemon
(
Mai
nRequest
::
CHECK_VERSION
);
string
v
=
read_string
(
fd
);
string
v
=
read_string
(
fd
);
printf
(
"%s
\n
"
,
v
.
data
());
printf
(
"%s
\n
"
,
v
.
data
());
return
0
;
return
0
;
}
else
if
(
argv
[
1
]
==
"-V"
sv
)
{
}
else
if
(
argv
[
1
]
==
"-V"
sv
)
{
int
fd
=
connect_daemon
(
Daemo
nRequest
::
CHECK_VERSION_CODE
);
int
fd
=
connect_daemon
(
Mai
nRequest
::
CHECK_VERSION_CODE
);
printf
(
"%d
\n
"
,
read_int
(
fd
));
printf
(
"%d
\n
"
,
read_int
(
fd
));
return
0
;
return
0
;
}
else
if
(
argv
[
1
]
==
"--list"
sv
)
{
}
else
if
(
argv
[
1
]
==
"--list"
sv
)
{
...
@@ -82,25 +81,25 @@ int magisk_main(int argc, char *argv[]) {
...
@@ -82,25 +81,25 @@ int magisk_main(int argc, char *argv[]) {
cp_afc
(
argv
[
2
],
argv
[
3
]);
cp_afc
(
argv
[
2
],
argv
[
3
]);
return
0
;
return
0
;
}
else
if
(
argv
[
1
]
==
"--daemon"
sv
)
{
}
else
if
(
argv
[
1
]
==
"--daemon"
sv
)
{
int
fd
=
connect_daemon
(
Daemo
nRequest
::
START_DAEMON
,
true
);
int
fd
=
connect_daemon
(
Mai
nRequest
::
START_DAEMON
,
true
);
close
(
fd
);
close
(
fd
);
return
0
;
return
0
;
}
else
if
(
argv
[
1
]
==
"--stop"
sv
)
{
}
else
if
(
argv
[
1
]
==
"--stop"
sv
)
{
int
fd
=
connect_daemon
(
Daemo
nRequest
::
STOP_DAEMON
);
int
fd
=
connect_daemon
(
Mai
nRequest
::
STOP_DAEMON
);
return
read_int
(
fd
);
return
read_int
(
fd
);
}
else
if
(
argv
[
1
]
==
"--post-fs-data"
sv
)
{
}
else
if
(
argv
[
1
]
==
"--post-fs-data"
sv
)
{
int
fd
=
connect_daemon
(
Daemo
nRequest
::
POST_FS_DATA
,
true
);
int
fd
=
connect_daemon
(
Mai
nRequest
::
POST_FS_DATA
,
true
);
return
read_int
(
fd
);
return
read_int
(
fd
);
}
else
if
(
argv
[
1
]
==
"--service"
sv
)
{
}
else
if
(
argv
[
1
]
==
"--service"
sv
)
{
int
fd
=
connect_daemon
(
Daemo
nRequest
::
LATE_START
,
true
);
int
fd
=
connect_daemon
(
Mai
nRequest
::
LATE_START
,
true
);
return
read_int
(
fd
);
return
read_int
(
fd
);
}
else
if
(
argv
[
1
]
==
"--boot-complete"
sv
)
{
}
else
if
(
argv
[
1
]
==
"--boot-complete"
sv
)
{
int
fd
=
connect_daemon
(
Daemo
nRequest
::
BOOT_COMPLETE
,
true
);
int
fd
=
connect_daemon
(
Mai
nRequest
::
BOOT_COMPLETE
,
true
);
return
read_int
(
fd
);
return
read_int
(
fd
);
}
else
if
(
argv
[
1
]
==
"--denylist"
sv
)
{
}
else
if
(
argv
[
1
]
==
"--denylist"
sv
)
{
return
denylist_cli
(
argc
-
1
,
argv
+
1
);
return
denylist_cli
(
argc
-
1
,
argv
+
1
);
}
else
if
(
argc
>=
3
&&
argv
[
1
]
==
"--sqlite"
sv
)
{
}
else
if
(
argc
>=
3
&&
argv
[
1
]
==
"--sqlite"
sv
)
{
int
fd
=
connect_daemon
(
Daemo
nRequest
::
SQLITE_CMD
);
int
fd
=
connect_daemon
(
Mai
nRequest
::
SQLITE_CMD
);
write_string
(
fd
,
argv
[
2
]);
write_string
(
fd
,
argv
[
2
]);
string
res
;
string
res
;
for
(;;)
{
for
(;;)
{
...
@@ -110,10 +109,10 @@ int magisk_main(int argc, char *argv[]) {
...
@@ -110,10 +109,10 @@ int magisk_main(int argc, char *argv[]) {
printf
(
"%s
\n
"
,
res
.
data
());
printf
(
"%s
\n
"
,
res
.
data
());
}
}
}
else
if
(
argv
[
1
]
==
"--remove-modules"
sv
)
{
}
else
if
(
argv
[
1
]
==
"--remove-modules"
sv
)
{
int
fd
=
connect_daemon
(
Daemo
nRequest
::
REMOVE_MODULES
);
int
fd
=
connect_daemon
(
Mai
nRequest
::
REMOVE_MODULES
);
return
read_int
(
fd
);
return
read_int
(
fd
);
}
else
if
(
argv
[
1
]
==
"--path"
sv
)
{
}
else
if
(
argv
[
1
]
==
"--path"
sv
)
{
int
fd
=
connect_daemon
(
Daemo
nRequest
::
GET_PATH
);
int
fd
=
connect_daemon
(
Mai
nRequest
::
GET_PATH
);
string
path
=
read_string
(
fd
);
string
path
=
read_string
(
fd
);
printf
(
"%s
\n
"
,
path
.
data
());
printf
(
"%s
\n
"
,
path
.
data
());
return
0
;
return
0
;
...
...
native/jni/include/daemon.hpp
View file @
be758613
...
@@ -10,7 +10,8 @@
...
@@ -10,7 +10,8 @@
#include <socket.hpp>
#include <socket.hpp>
// Daemon command codes
// Daemon command codes
enum
class
DaemonRequest
:
int
{
namespace
MainRequest
{
enum
:
int
{
START_DAEMON
,
START_DAEMON
,
CHECK_VERSION
,
CHECK_VERSION
,
CHECK_VERSION_CODE
,
CHECK_VERSION_CODE
,
...
@@ -26,18 +27,21 @@ enum class DaemonRequest: int {
...
@@ -26,18 +27,21 @@ enum class DaemonRequest: int {
DENYLIST
,
DENYLIST
,
SQLITE_CMD
,
SQLITE_CMD
,
REMOVE_MODULES
,
REMOVE_MODULES
,
ZYGISK
_REQUEST
,
ZYGISK
,
END
,
END
,
};
};
}
// Return codes for daemon
// Return codes for daemon
enum
class
DaemonResponse
:
int
{
namespace
MainResponse
{
enum
:
int
{
ERROR
=
-
1
,
ERROR
=
-
1
,
OK
=
0
,
OK
=
0
,
ROOT_REQUIRED
,
ROOT_REQUIRED
,
INVALID_REQUEST
,
INVALID_REQUEST
,
END
END
};
};
}
struct
module_info
{
struct
module_info
{
std
::
string
name
;
std
::
string
name
;
...
@@ -52,7 +56,7 @@ extern int app_process_32;
...
@@ -52,7 +56,7 @@ extern int app_process_32;
extern
int
app_process_64
;
extern
int
app_process_64
;
extern
std
::
vector
<
module_info
>
*
module_list
;
extern
std
::
vector
<
module_info
>
*
module_list
;
int
connect_daemon
(
DaemonReques
t
req
,
bool
create
=
false
);
int
connect_daemon
(
in
t
req
,
bool
create
=
false
);
// Poll control
// Poll control
using
poll_callback
=
void
(
*
)(
pollfd
*
);
using
poll_callback
=
void
(
*
)(
pollfd
*
);
...
...
native/jni/su/su.cpp
View file @
be758613
...
@@ -159,7 +159,7 @@ int su_client_main(int argc, char *argv[]) {
...
@@ -159,7 +159,7 @@ int su_client_main(int argc, char *argv[]) {
int
ptmx
,
fd
;
int
ptmx
,
fd
;
// Connect to client
// Connect to client
fd
=
connect_daemon
(
Daemo
nRequest
::
SUPERUSER
);
fd
=
connect_daemon
(
Mai
nRequest
::
SUPERUSER
);
// Send su_request
// Send su_request
xwrite
(
fd
,
&
su_req
,
sizeof
(
su_req_base
));
xwrite
(
fd
,
&
su_req
,
sizeof
(
su_req_base
));
...
...
native/jni/utils/misc.hpp
View file @
be758613
...
@@ -5,8 +5,6 @@
...
@@ -5,8 +5,6 @@
#include <functional>
#include <functional>
#include <string_view>
#include <string_view>
#include <bitset>
#include <bitset>
#include <compare>
#include "xwrap.hpp"
#define UID_ROOT 0
#define UID_ROOT 0
#define UID_SHELL 2000
#define UID_SHELL 2000
...
@@ -199,32 +197,3 @@ void exec_command_async(Args &&...args) {
...
@@ -199,32 +197,3 @@ void exec_command_async(Args &&...args) {
};
};
exec_command
(
exec
);
exec_command
(
exec
);
}
}
template
<
class
_Tp
,
bool
=
std
::
is_enum_v
<
_Tp
>
>
struct
__is_scoped_enum_helper
:
std
::
false_type
{};
template
<
class
_Tp
>
struct
__is_scoped_enum_helper
<
_Tp
,
true
>
:
public
std
::
bool_constant
<!
std
::
is_convertible_v
<
_Tp
,
std
::
underlying_type_t
<
_Tp
>
>
>
{};
template
<
class
_Tp
>
struct
is_scoped_enum
:
public
__is_scoped_enum_helper
<
_Tp
>
{};
template
<
class
_Tp
>
inline
constexpr
bool
is_scoped_enum_v
=
is_scoped_enum
<
_Tp
>::
value
;
template
<
typename
Enum
>
requires
(
is_scoped_enum_v
<
Enum
>
)
constexpr
inline
auto
operator
<=>
(
std
::
underlying_type_t
<
Enum
>
a
,
Enum
b
)
{
return
a
<=>
static_cast
<
std
::
underlying_type_t
<
Enum
>>
(
b
);
}
template
<
typename
Enum
>
requires
(
is_scoped_enum_v
<
Enum
>
)
constexpr
inline
auto
operator
!=
(
std
::
underlying_type_t
<
Enum
>
a
,
Enum
b
)
{
return
a
!=
static_cast
<
std
::
underlying_type_t
<
Enum
>>
(
b
);
}
template
<
typename
Enum
>
requires
(
is_scoped_enum_v
<
Enum
>
)
constexpr
inline
auto
operator
==
(
std
::
underlying_type_t
<
Enum
>
a
,
Enum
b
)
{
return
a
==
static_cast
<
std
::
underlying_type_t
<
Enum
>>
(
b
);
}
native/jni/zygisk/deny/cli.cpp
View file @
be758613
...
@@ -32,12 +32,10 @@ void denylist_handler(int client, const sock_cred *cred) {
...
@@ -32,12 +32,10 @@ void denylist_handler(int client, const sock_cred *cred) {
return
;
return
;
}
}
DenyResponse
res
=
DenyResponse
::
ERROR
;
int
req
=
read_int
(
client
);
int
res
=
DenyResponse
::
ERROR
;
int
code
=
read_int
(
client
);
if
(
req
<
0
||
req
>=
DenyRequest
::
END
)
{
auto
req
=
static_cast
<
DenyRequest
>
(
code
);
if
(
code
<
0
||
code
>=
DenyRequest
::
END
)
{
goto
done
;
goto
done
;
}
}
...
@@ -58,14 +56,14 @@ void denylist_handler(int client, const sock_cred *cred) {
...
@@ -58,14 +56,14 @@ void denylist_handler(int client, const sock_cred *cred) {
ls_list
(
client
);
ls_list
(
client
);
return
;
return
;
case
DenyRequest
:
:
STATUS
:
case
DenyRequest
:
:
STATUS
:
res
=
(
zygisk_enabled
&&
denylist_enforced
)
?
DenyResponse
::
ENFORCED
res
=
(
zygisk_enabled
&&
denylist_enforced
)
:
DenyResponse
::
NOT_ENFORCED
;
?
DenyResponse
::
ENFORCED
:
DenyResponse
::
NOT_ENFORCED
;
break
;
break
;
case
DenyRequest
:
:
END
:
default
:
__builtin_unreachable
();
__builtin_unreachable
();
}
}
done
:
done
:
write_int
(
client
,
static_cast
<
int
>
(
res
)
);
write_int
(
client
,
res
);
close
(
client
);
close
(
client
);
}
}
...
@@ -73,7 +71,7 @@ int denylist_cli(int argc, char **argv) {
...
@@ -73,7 +71,7 @@ int denylist_cli(int argc, char **argv) {
if
(
argc
<
2
)
if
(
argc
<
2
)
usage
();
usage
();
DenyReques
t
req
;
in
t
req
;
if
(
argv
[
1
]
==
"enable"
sv
)
if
(
argv
[
1
]
==
"enable"
sv
)
req
=
DenyRequest
::
ENFORCE
;
req
=
DenyRequest
::
ENFORCE
;
else
if
(
argv
[
1
]
==
"disable"
sv
)
else
if
(
argv
[
1
]
==
"disable"
sv
)
...
@@ -97,16 +95,17 @@ int denylist_cli(int argc, char **argv) {
...
@@ -97,16 +95,17 @@ int denylist_cli(int argc, char **argv) {
}
}
// Send request
// Send request
int
fd
=
deny_request
(
req
);
int
fd
=
connect_daemon
(
MainRequest
::
DENYLIST
);
write_int
(
fd
,
req
);
if
(
req
==
DenyRequest
::
ADD
||
req
==
DenyRequest
::
REMOVE
)
{
if
(
req
==
DenyRequest
::
ADD
||
req
==
DenyRequest
::
REMOVE
)
{
write_string
(
fd
,
argv
[
2
]);
write_string
(
fd
,
argv
[
2
]);
write_string
(
fd
,
argv
[
3
]
?
argv
[
3
]
:
""
);
write_string
(
fd
,
argv
[
3
]
?
argv
[
3
]
:
""
);
}
}
// Get response
// Get response
int
code
=
read_int
(
fd
);
int
res
=
read_int
(
fd
);
auto
res
=
(
code
<
0
||
code
>=
DenyResponse
::
END
)
?
DenyResponse
::
ERROR
if
(
res
<
0
||
res
>=
DenyResponse
::
END
)
:
static_cast
<
DenyResponse
>
(
code
)
;
res
=
DenyResponse
::
ERROR
;
switch
(
res
)
{
switch
(
res
)
{
case
DenyResponse
:
:
NOT_ENFORCED
:
case
DenyResponse
:
:
NOT_ENFORCED
:
fprintf
(
stderr
,
"Denylist is not enforced
\n
"
);
fprintf
(
stderr
,
"Denylist is not enforced
\n
"
);
...
@@ -131,7 +130,7 @@ int denylist_cli(int argc, char **argv) {
...
@@ -131,7 +130,7 @@ int denylist_cli(int argc, char **argv) {
return
-
1
;
return
-
1
;
case
DenyResponse
:
:
OK
:
case
DenyResponse
:
:
OK
:
break
;
break
;
case
DenyResponse
:
:
END
:
default
:
__builtin_unreachable
();
__builtin_unreachable
();
}
}
...
...
native/jni/zygisk/deny/deny.hpp
View file @
be758613
...
@@ -10,7 +10,8 @@
...
@@ -10,7 +10,8 @@
#define ISOLATED_MAGIC "isolated"
#define ISOLATED_MAGIC "isolated"
enum
class
DenyRequest
:
int
{
namespace
DenyRequest
{
enum
:
int
{
ENFORCE
,
ENFORCE
,
DISABLE
,
DISABLE
,
ADD
,
ADD
,
...
@@ -20,8 +21,10 @@ enum class DenyRequest : int {
...
@@ -20,8 +21,10 @@ enum class DenyRequest : int {
END
END
};
};
}
enum
class
DenyResponse
:
int
{
namespace
DenyResponse
{
enum
:
int
{
OK
,
OK
,
ENFORCED
,
ENFORCED
,
NOT_ENFORCED
,
NOT_ENFORCED
,
...
@@ -33,13 +36,13 @@ enum class DenyResponse: int {
...
@@ -33,13 +36,13 @@ enum class DenyResponse: int {
END
END
};
};
}
// CLI entries
// CLI entries
DenyResponse
enable_deny
();
int
enable_deny
();
DenyResponse
disable_deny
();
int
disable_deny
();
DenyResponse
add_list
(
int
client
);
int
add_list
(
int
client
);
DenyResponse
rm_list
(
int
client
);
int
rm_list
(
int
client
);
void
ls_list
(
int
client
);
void
ls_list
(
int
client
);
// Utility functions
// Utility functions
...
@@ -49,9 +52,3 @@ void revert_unmount();
...
@@ -49,9 +52,3 @@ void revert_unmount();
extern
std
::
atomic
<
bool
>
denylist_enforced
;
extern
std
::
atomic
<
bool
>
denylist_enforced
;
extern
std
::
atomic
<
int
>
cached_manager_app_id
;
extern
std
::
atomic
<
int
>
cached_manager_app_id
;
inline
int
deny_request
(
DenyRequest
req
)
{
int
fd
=
connect_daemon
(
DaemonRequest
::
DENYLIST
);
write_int
(
fd
,
static_cast
<
std
::
underlying_type_t
<
DenyRequest
>>
(
req
));
return
fd
;
}
native/jni/zygisk/deny/utils.cpp
View file @
be758613
...
@@ -226,7 +226,7 @@ error:
...
@@ -226,7 +226,7 @@ error:
return
false
;
return
false
;
}
}
static
DenyResponse
add_list
(
const
char
*
pkg
,
const
char
*
proc
)
{
static
int
add_list
(
const
char
*
pkg
,
const
char
*
proc
)
{
if
(
proc
[
0
]
==
'\0'
)
if
(
proc
[
0
]
==
'\0'
)
proc
=
pkg
;
proc
=
pkg
;
...
@@ -252,13 +252,13 @@ static DenyResponse add_list(const char *pkg, const char *proc) {
...
@@ -252,13 +252,13 @@ static DenyResponse add_list(const char *pkg, const char *proc) {
return
DenyResponse
::
OK
;
return
DenyResponse
::
OK
;
}
}
DenyResponse
add_list
(
int
client
)
{
int
add_list
(
int
client
)
{
string
pkg
=
read_string
(
client
);
string
pkg
=
read_string
(
client
);
string
proc
=
read_string
(
client
);
string
proc
=
read_string
(
client
);
return
add_list
(
pkg
.
data
(),
proc
.
data
());
return
add_list
(
pkg
.
data
(),
proc
.
data
());
}
}
static
DenyResponse
rm_list
(
const
char
*
pkg
,
const
char
*
proc
)
{
static
int
rm_list
(
const
char
*
pkg
,
const
char
*
proc
)
{
{
{
mutex_guard
lock
(
data_lock
);
mutex_guard
lock
(
data_lock
);
if
(
!
ensure_data
())
if
(
!
ensure_data
())
...
@@ -298,7 +298,7 @@ static DenyResponse rm_list(const char *pkg, const char *proc) {
...
@@ -298,7 +298,7 @@ static DenyResponse rm_list(const char *pkg, const char *proc) {
return
DenyResponse
::
OK
;
return
DenyResponse
::
OK
;
}
}
DenyResponse
rm_list
(
int
client
)
{
int
rm_list
(
int
client
)
{
string
pkg
=
read_string
(
client
);
string
pkg
=
read_string
(
client
);
string
proc
=
read_string
(
client
);
string
proc
=
read_string
(
client
);
return
rm_list
(
pkg
.
data
(),
proc
.
data
());
return
rm_list
(
pkg
.
data
(),
proc
.
data
());
...
@@ -342,7 +342,7 @@ static void update_deny_config() {
...
@@ -342,7 +342,7 @@ static void update_deny_config() {
db_err
(
err
);
db_err
(
err
);
}
}
DenyResponse
enable_deny
()
{
int
enable_deny
()
{
if
(
denylist_enforced
)
{
if
(
denylist_enforced
)
{
return
DenyResponse
::
OK
;
return
DenyResponse
::
OK
;
}
else
{
}
else
{
...
@@ -377,7 +377,7 @@ DenyResponse enable_deny() {
...
@@ -377,7 +377,7 @@ DenyResponse enable_deny() {
return
DenyResponse
::
OK
;
return
DenyResponse
::
OK
;
}
}
DenyResponse
disable_deny
()
{
int
disable_deny
()
{
if
(
denylist_enforced
)
{
if
(
denylist_enforced
)
{
denylist_enforced
=
false
;
denylist_enforced
=
false
;
LOGI
(
"* Disable DenyList
\n
"
);
LOGI
(
"* Disable DenyList
\n
"
);
...
...
native/jni/zygisk/entry.cpp
View file @
be758613
...
@@ -399,18 +399,16 @@ static void get_moddir(int client) {
...
@@ -399,18 +399,16 @@ static void get_moddir(int client) {
}
}
void
zygisk_handler
(
int
client
,
const
sock_cred
*
cred
)
{
void
zygisk_handler
(
int
client
,
const
sock_cred
*
cred
)
{
// using enum ZYGISK_REQUEST;
int
code
=
read_int
(
client
);
int
code
=
read_int
(
client
);
char
buf
[
256
];
char
buf
[
256
];
if
(
code
<
ZygiskRequest
::
SETUP
||
code
>=
ZygiskRequest
::
END
)
{
if
(
code
<
ZygiskRequest
::
SETUP
||
code
>=
ZygiskRequest
::
END
)
{
write_int
(
client
,
-
1
);
write_int
(
client
,
-
1
);
return
;
return
;
}
}
auto
req
=
static_cast
<
ZygiskRequest
>
(
code
);
if
(
code
!=
ZygiskRequest
::
PASSTHROUGH
&&
cred
->
context
!=
"u:r:zygote:s0"
)
{
if
(
req
!=
ZygiskRequest
::
PASSTHROUGH
&&
cred
->
context
!=
"u:r:zygote:s0"
)
{
return
;
return
;
}
}
switch
(
req
)
{
switch
(
code
)
{
case
ZygiskRequest
:
:
SETUP
:
case
ZygiskRequest
:
:
SETUP
:
setup_files
(
client
,
cred
);
setup_files
(
client
,
cred
);
break
;
break
;
...
@@ -430,7 +428,7 @@ void zygisk_handler(int client, const sock_cred *cred) {
...
@@ -430,7 +428,7 @@ void zygisk_handler(int client, const sock_cred *cred) {
case
ZygiskRequest
:
:
GET_MODDIR
:
case
ZygiskRequest
:
:
GET_MODDIR
:
get_moddir
(
client
);
get_moddir
(
client
);
break
;
break
;
case
ZygiskRequest
:
:
END
:
default
:
__builtin_unreachable
();
__builtin_unreachable
();
}
}
close
(
client
);
close
(
client
);
...
...
native/jni/zygisk/zygisk.hpp
View file @
be758613
...
@@ -10,7 +10,8 @@
...
@@ -10,7 +10,8 @@
#define MAGISKFD_ENV "MAGISKFD"
#define MAGISKFD_ENV "MAGISKFD"
#define MAGISKTMP_ENV "MAGISKTMP"
#define MAGISKTMP_ENV "MAGISKTMP"
enum
class
ZygiskRequest
:
int
{
namespace
ZygiskRequest
{
enum
:
int
{
SETUP
,
SETUP
,
GET_INFO
,
GET_INFO
,
GET_LOG_PIPE
,
GET_LOG_PIPE
,
...
@@ -19,6 +20,7 @@ enum class ZygiskRequest : int {
...
@@ -19,6 +20,7 @@ enum class ZygiskRequest : int {
PASSTHROUGH
,
PASSTHROUGH
,
END
END
};
};
}
#if defined(__LP64__)
#if defined(__LP64__)
#define ZLOGD(...) LOGD("zygisk64: " __VA_ARGS__)
#define ZLOGD(...) LOGD("zygisk64: " __VA_ARGS__)
...
@@ -51,9 +53,8 @@ void hook_functions();
...
@@ -51,9 +53,8 @@ void hook_functions();
int
remote_get_info
(
int
uid
,
const
char
*
process
,
uint32_t
*
flags
,
std
::
vector
<
int
>
&
fds
);
int
remote_get_info
(
int
uid
,
const
char
*
process
,
uint32_t
*
flags
,
std
::
vector
<
int
>
&
fds
);
int
remote_request_unmount
();
int
remote_request_unmount
();
inline
int
zygisk_request
(
int
req
)
{
inline
int
zygisk_request
(
ZygiskRequest
req
)
{
int
fd
=
connect_daemon
(
MainRequest
::
ZYGISK
);
int
fd
=
connect_daemon
(
DaemonRequest
::
ZYGISK_REQUEST
,
false
);
write_int
(
fd
,
req
);
write_int
(
fd
,
static_cast
<
int
>
(
req
));
return
fd
;
return
fd
;
}
}
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