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
Show 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/wait.h>
#include <stdlib.h>
...
...
@@ -718,10 +711,7 @@ void late_start(int client) {
if
(
access
(
SECURE_DIR
,
F_OK
)
!=
0
)
xmkdir
(
SECURE_DIR
,
0700
);
// And reboot to make proper setup possible
if
(
RECOVERY_MODE
)
exec_command_sync
(
"/system/bin/reboot"
,
"recovery"
);
else
exec_command_sync
(
"/system/bin/reboot"
);
reboot
();
}
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 <unistd.h>
#include <fcntl.h>
...
...
@@ -30,14 +24,20 @@ static void verify_client(int client, pid_t pid) {
// Verify caller is the same as server
char
path
[
32
];
sprintf
(
path
,
"/proc/%d/exe"
,
pid
);
struct
stat
st
{};
stat
(
path
,
&
st
);
if
(
st
.
st_dev
!=
SERVER_STAT
.
st_dev
||
st
.
st_ino
!=
SERVER_STAT
.
st_ino
)
{
struct
stat
st
;
if
(
stat
(
path
,
&
st
)
||
st
.
st_dev
!=
SERVER_STAT
.
st_dev
||
st
.
st_ino
!=
SERVER_STAT
.
st_ino
)
{
close
(
client
);
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
)
{
int
client
=
*
((
int
*
)
args
);
delete
(
int
*
)
args
;
...
...
@@ -95,6 +95,16 @@ static void *request_handler(void *args) {
LOGD
(
"* Use broadcasts for su logging and notify
\n
"
);
CONNECT_BROADCAST
=
true
;
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:
close
(
client
);
break
;
...
...
@@ -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
)
{
char
mnt
[
32
];
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;
[[
noreturn
]]
static
void
usage
()
{
fprintf
(
stderr
,
FULL_VER
(
Magisk
)
" multi-call binary
\n
"
"
\n
"
"Usage: magisk [applet [arguments]...]
\n
"
" or: magisk [options]...
\n
"
"
\n
"
"Options:
\n
"
" -c print current binary version
\n
"
" -v print running daemon version
\n
"
" -V print running daemon version code
\n
"
" --list list all available applets
\n
"
" --daemon manually start magisk daemon
\n
"
" --[init trigger] start service for init trigger
\n
"
"
\n
"
"Advanced Options (Internal APIs):
\n
"
" --unlock-blocks set BLKROSET flag to OFF for all block devices
\n
"
" --restorecon restore selinux context on Magisk files
\n
"
" --clone-attr SRC DEST clone permission, owner, and selinux context
\n
"
" --clone SRC DEST clone SRC to DEST
\n
"
" --sqlite SQL exec SQL to Magisk database
\n
"
" --use-broadcast use broadcast for su logging and notify
\n
"
"
\n
"
"Supported init triggers:
\n
"
" post-fs-data, service, boot-complete
\n
"
"
\n
"
"Supported applets:
\n
"
);
FULL_VER
(
Magisk
)
R"EOF( multi-call binary
Usage: magisk [applet [arguments]...]
or: magisk [options]...
Options:
-c print current binary version
-v print running daemon version
-V print running daemon version code
--list list all available applets
--daemon manually start magisk daemon
--remove-modules remove all modules and reboot
--[init trigger] start service for init trigger
Advanced Options (Internal APIs):
--unlock-blocks set BLKROSET flag to OFF for all block devices
--restorecon restore selinux context on Magisk files
--clone-attr SRC DEST clone permission, owner, and selinux context
--clone SRC DEST clone SRC to DEST
--sqlite SQL exec SQL commands to Magisk database
--use-broadcast use broadcast for su logging and notify
Supported init triggers:
post-fs-data, service, boot-complete
Supported applets:
)EOF"
);
for
(
int
i
=
0
;
applet_names
[
i
];
++
i
)
fprintf
(
stderr
,
i
?
", %s"
:
" %s"
,
applet_names
[
i
]);
...
...
@@ -117,6 +119,10 @@ int magisk_main(int argc, char *argv[]) {
int
fd
=
connect_daemon
();
write_int
(
fd
,
BROADCAST_ACK
);
return
0
;
}
else
if
(
argv
[
1
]
==
"--remove-modules"
sv
)
{
int
fd
=
connect_daemon
();
write_int
(
fd
,
REMOVE_MODULES
);
return
read_int
(
fd
);
}
#if 0
/* Entry point for testing stuffs */
...
...
native/jni/include/daemon.h
View file @
e31e6876
...
...
@@ -18,6 +18,7 @@ enum {
MAGISKHIDE
,
SQLITE_CMD
,
BROADCAST_ACK
,
REMOVE_MODULES
,
};
// Return codes for daemon
...
...
@@ -32,6 +33,7 @@ enum {
int
connect_daemon
(
bool
create
=
false
);
int
switch_mnt_ns
(
int
pid
);
void
reboot
();
// 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