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
e31e6876
Commit
e31e6876
authored
Sep 13, 2019
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow ADB shell to remove modules and reboot
parent
86bfb22d
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
60 additions
and
45 deletions
+60
-45
bootstages.cpp
native/jni/core/bootstages.cpp
+1
-11
daemon.cpp
native/jni/core/daemon.cpp
+26
-9
magisk.cpp
native/jni/core/magisk.cpp
+31
-25
daemon.h
native/jni/include/daemon.h
+2
-0
No files found.
native/jni/core/bootstages.cpp
View file @
e31e6876
/* bootstages.c - Core bootstage operations
*
* All bootstage operations, including simple mount in post-fs,
* magisk mount in post-fs-data, various image handling, script
* execution, load modules, install Magisk Manager etc.
*/
#include <sys/mount.h>
#include <sys/mount.h>
#include <sys/wait.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <stdlib.h>
...
@@ -718,10 +711,7 @@ void late_start(int client) {
...
@@ -718,10 +711,7 @@ void late_start(int client) {
if
(
access
(
SECURE_DIR
,
F_OK
)
!=
0
)
if
(
access
(
SECURE_DIR
,
F_OK
)
!=
0
)
xmkdir
(
SECURE_DIR
,
0700
);
xmkdir
(
SECURE_DIR
,
0700
);
// And reboot to make proper setup possible
// And reboot to make proper setup possible
if
(
RECOVERY_MODE
)
reboot
();
exec_command_sync
(
"/system/bin/reboot"
,
"recovery"
);
else
exec_command_sync
(
"/system/bin/reboot"
);
}
}
if
(
access
(
BBPATH
,
F_OK
)
!=
0
){
if
(
access
(
BBPATH
,
F_OK
)
!=
0
){
...
...
native/jni/core/daemon.cpp
View file @
e31e6876
/* daemon.c - Magisk Daemon
*
* Start the daemon and wait for requests
* Connect the daemon and send requests through sockets
*/
#include <stdlib.h>
#include <stdlib.h>
#include <unistd.h>
#include <unistd.h>
#include <fcntl.h>
#include <fcntl.h>
...
@@ -30,14 +24,20 @@ static void verify_client(int client, pid_t pid) {
...
@@ -30,14 +24,20 @@ static void verify_client(int client, pid_t pid) {
// Verify caller is the same as server
// Verify caller is the same as server
char
path
[
32
];
char
path
[
32
];
sprintf
(
path
,
"/proc/%d/exe"
,
pid
);
sprintf
(
path
,
"/proc/%d/exe"
,
pid
);
struct
stat
st
{};
struct
stat
st
;
stat
(
path
,
&
st
);
if
(
stat
(
path
,
&
st
)
||
st
.
st_dev
!=
SERVER_STAT
.
st_dev
||
st
.
st_ino
!=
SERVER_STAT
.
st_ino
)
{
if
(
st
.
st_dev
!=
SERVER_STAT
.
st_dev
||
st
.
st_ino
!=
SERVER_STAT
.
st_ino
)
{
close
(
client
);
close
(
client
);
pthread_exit
(
nullptr
);
pthread_exit
(
nullptr
);
}
}
}
}
static
void
remove_modules
()
{
LOGI
(
"* Remove all modules and reboot"
);
rm_rf
(
MODULEROOT
);
rm_rf
(
MODULEUPGRADE
);
reboot
();
}
static
void
*
request_handler
(
void
*
args
)
{
static
void
*
request_handler
(
void
*
args
)
{
int
client
=
*
((
int
*
)
args
);
int
client
=
*
((
int
*
)
args
);
delete
(
int
*
)
args
;
delete
(
int
*
)
args
;
...
@@ -95,6 +95,16 @@ static void *request_handler(void *args) {
...
@@ -95,6 +95,16 @@ static void *request_handler(void *args) {
LOGD
(
"* Use broadcasts for su logging and notify
\n
"
);
LOGD
(
"* Use broadcasts for su logging and notify
\n
"
);
CONNECT_BROADCAST
=
true
;
CONNECT_BROADCAST
=
true
;
close
(
client
);
close
(
client
);
break
;
case
REMOVE_MODULES
:
if
(
credential
.
uid
==
UID_SHELL
||
credential
.
uid
==
UID_ROOT
)
{
remove_modules
();
write_int
(
client
,
0
);
}
else
{
write_int
(
client
,
1
);
}
close
(
client
);
break
;
default:
default:
close
(
client
);
close
(
client
);
break
;
break
;
...
@@ -169,6 +179,13 @@ static void main_daemon() {
...
@@ -169,6 +179,13 @@ static void main_daemon() {
}
}
}
}
void
reboot
()
{
if
(
RECOVERY_MODE
)
exec_command_sync
(
"/system/bin/reboot"
,
"recovery"
);
else
exec_command_sync
(
"/system/bin/reboot"
);
}
int
switch_mnt_ns
(
int
pid
)
{
int
switch_mnt_ns
(
int
pid
)
{
char
mnt
[
32
];
char
mnt
[
32
];
snprintf
(
mnt
,
sizeof
(
mnt
),
"/proc/%d/ns/mnt"
,
pid
);
snprintf
(
mnt
,
sizeof
(
mnt
),
"/proc/%d/ns/mnt"
,
pid
);
...
...
native/jni/core/magisk.cpp
View file @
e31e6876
...
@@ -16,31 +16,33 @@ using namespace std::literals;
...
@@ -16,31 +16,33 @@ using namespace std::literals;
[[
noreturn
]]
static
void
usage
()
{
[[
noreturn
]]
static
void
usage
()
{
fprintf
(
stderr
,
fprintf
(
stderr
,
FULL_VER
(
Magisk
)
" multi-call binary
\n
"
FULL_VER
(
Magisk
)
R"EOF( multi-call binary
"
\n
"
"Usage: magisk [applet [arguments]...]
\n
"
Usage: magisk [applet [arguments]...]
" or: magisk [options]...
\n
"
or: magisk [options]...
"
\n
"
"Options:
\n
"
Options:
" -c print current binary version
\n
"
-c print current binary version
" -v print running daemon version
\n
"
-v print running daemon version
" -V print running daemon version code
\n
"
-V print running daemon version code
" --list list all available applets
\n
"
--list list all available applets
" --daemon manually start magisk daemon
\n
"
--daemon manually start magisk daemon
" --[init trigger] start service for init trigger
\n
"
--remove-modules remove all modules and reboot
"
\n
"
--[init trigger] start service for init trigger
"Advanced Options (Internal APIs):
\n
"
" --unlock-blocks set BLKROSET flag to OFF for all block devices
\n
"
Advanced Options (Internal APIs):
" --restorecon restore selinux context on Magisk files
\n
"
--unlock-blocks set BLKROSET flag to OFF for all block devices
" --clone-attr SRC DEST clone permission, owner, and selinux context
\n
"
--restorecon restore selinux context on Magisk files
" --clone SRC DEST clone SRC to DEST
\n
"
--clone-attr SRC DEST clone permission, owner, and selinux context
" --sqlite SQL exec SQL to Magisk database
\n
"
--clone SRC DEST clone SRC to DEST
" --use-broadcast use broadcast for su logging and notify
\n
"
--sqlite SQL exec SQL commands to Magisk database
"
\n
"
--use-broadcast use broadcast for su logging and notify
"Supported init triggers:
\n
"
" post-fs-data, service, boot-complete
\n
"
Supported init triggers:
"
\n
"
post-fs-data, service, boot-complete
"Supported applets:
\n
"
);
Supported applets:
)EOF"
);
for
(
int
i
=
0
;
applet_names
[
i
];
++
i
)
for
(
int
i
=
0
;
applet_names
[
i
];
++
i
)
fprintf
(
stderr
,
i
?
", %s"
:
" %s"
,
applet_names
[
i
]);
fprintf
(
stderr
,
i
?
", %s"
:
" %s"
,
applet_names
[
i
]);
...
@@ -117,6 +119,10 @@ int magisk_main(int argc, char *argv[]) {
...
@@ -117,6 +119,10 @@ int magisk_main(int argc, char *argv[]) {
int
fd
=
connect_daemon
();
int
fd
=
connect_daemon
();
write_int
(
fd
,
BROADCAST_ACK
);
write_int
(
fd
,
BROADCAST_ACK
);
return
0
;
return
0
;
}
else
if
(
argv
[
1
]
==
"--remove-modules"
sv
)
{
int
fd
=
connect_daemon
();
write_int
(
fd
,
REMOVE_MODULES
);
return
read_int
(
fd
);
}
}
#if 0
#if 0
/* Entry point for testing stuffs */
/* Entry point for testing stuffs */
...
...
native/jni/include/daemon.h
View file @
e31e6876
...
@@ -18,6 +18,7 @@ enum {
...
@@ -18,6 +18,7 @@ enum {
MAGISKHIDE
,
MAGISKHIDE
,
SQLITE_CMD
,
SQLITE_CMD
,
BROADCAST_ACK
,
BROADCAST_ACK
,
REMOVE_MODULES
,
};
};
// Return codes for daemon
// Return codes for daemon
...
@@ -32,6 +33,7 @@ enum {
...
@@ -32,6 +33,7 @@ enum {
int
connect_daemon
(
bool
create
=
false
);
int
connect_daemon
(
bool
create
=
false
);
int
switch_mnt_ns
(
int
pid
);
int
switch_mnt_ns
(
int
pid
);
void
reboot
();
// socket.c
// socket.c
...
...
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