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
eb21c8b4
Commit
eb21c8b4
authored
Jan 11, 2021
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code cleanups
parent
541bb535
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
60 additions
and
81 deletions
+60
-81
applets.cpp
native/jni/core/applets.cpp
+0
-2
bootstages.cpp
native/jni/core/bootstages.cpp
+4
-2
core.hpp
native/jni/core/core.hpp
+26
-0
daemon.cpp
native/jni/core/daemon.cpp
+5
-2
db.cpp
native/jni/core/db.cpp
+1
-5
magisk.cpp
native/jni/core/magisk.cpp
+2
-0
module.cpp
native/jni/core/module.cpp
+2
-1
restorecon.cpp
native/jni/core/restorecon.cpp
+0
-1
scripting.cpp
native/jni/core/scripting.cpp
+2
-0
socket.cpp
native/jni/core/socket.cpp
+0
-2
daemon.hpp
native/jni/include/daemon.hpp
+2
-26
magisk.hpp
native/jni/include/magisk.hpp
+3
-0
hide_utils.cpp
native/jni/magiskhide/hide_utils.cpp
+4
-4
magiskhide.cpp
native/jni/magiskhide/magiskhide.cpp
+1
-9
magiskhide.hpp
native/jni/magiskhide/magiskhide.hpp
+1
-1
connect.cpp
native/jni/su/connect.cpp
+0
-1
pts.cpp
native/jni/su/pts.cpp
+4
-8
su.cpp
native/jni/su/su.cpp
+2
-9
su.hpp
native/jni/su/su.hpp
+0
-1
su_daemon.cpp
native/jni/su/su_daemon.cpp
+1
-7
No files found.
native/jni/core/applets.cpp
View file @
eb21c8b4
#include <libgen.h>
#include <libgen.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/stat.h>
...
...
native/jni/core/bootstages.cpp
View file @
eb21c8b4
...
@@ -13,6 +13,8 @@
...
@@ -13,6 +13,8 @@
#include <resetprop.hpp>
#include <resetprop.hpp>
#include <selinux.hpp>
#include <selinux.hpp>
#include "core.hpp"
using
namespace
std
;
using
namespace
std
;
static
bool
safe_mode
=
false
;
static
bool
safe_mode
=
false
;
...
@@ -320,7 +322,7 @@ void post_fs_data(int client) {
...
@@ -320,7 +322,7 @@ void post_fs_data(int client) {
stop_magiskhide
();
stop_magiskhide
();
}
else
{
}
else
{
exec_common_scripts
(
"post-fs-data"
);
exec_common_scripts
(
"post-fs-data"
);
auto_start_magiskhide
();
auto_start_magiskhide
(
false
);
handle_modules
();
handle_modules
();
}
}
...
@@ -369,7 +371,7 @@ void boot_complete(int client) {
...
@@ -369,7 +371,7 @@ void boot_complete(int client) {
if
(
access
(
SECURE_DIR
,
F_OK
)
!=
0
)
if
(
access
(
SECURE_DIR
,
F_OK
)
!=
0
)
xmkdir
(
SECURE_DIR
,
0700
);
xmkdir
(
SECURE_DIR
,
0700
);
auto_start_magiskhide
();
auto_start_magiskhide
(
true
);
if
(
!
check_manager
())
{
if
(
!
check_manager
())
{
if
(
access
(
MANAGERAPK
,
F_OK
)
==
0
)
{
if
(
access
(
MANAGERAPK
,
F_OK
)
==
0
)
{
...
...
native/jni/core/core.hpp
0 → 100644
View file @
eb21c8b4
#pragma once
#include <string>
#include <vector>
extern
bool
RECOVERY_MODE
;
extern
int
DAEMON_STATE
;
void
unlock_blocks
();
void
reboot
();
void
setup_logfile
(
bool
reset
);
// Module stuffs
void
handle_modules
();
void
magic_mount
();
void
disable_modules
();
void
remove_modules
();
void
exec_module_scripts
(
const
char
*
stage
);
// Scripting
void
exec_script
(
const
char
*
script
);
void
exec_common_scripts
(
const
char
*
stage
);
void
exec_module_scripts
(
const
char
*
stage
,
const
std
::
vector
<
std
::
string
>
&
module_list
);
void
install_apk
(
const
char
*
apk
);
[[
noreturn
]]
void
install_module
(
const
char
*
file
);
native/jni/core/daemon.cpp
View file @
eb21c8b4
#include <fcntl.h>
#include <fcntl.h>
#include <pthread.h>
#include <pthread.h>
#include <
signal.h
>
#include <
csignal
>
#include <libgen.h>
#include <libgen.h>
#include <sys/un.h>
#include <sys/un.h>
#include <sys/types.h>
#include <sys/types.h>
...
@@ -16,11 +16,14 @@
...
@@ -16,11 +16,14 @@
#include <flags.hpp>
#include <flags.hpp>
#include <stream.hpp>
#include <stream.hpp>
#include "core.hpp"
using
namespace
std
;
using
namespace
std
;
int
SDK_INT
=
-
1
;
int
SDK_INT
=
-
1
;
bool
RECOVERY_MODE
=
false
;
string
MAGISKTMP
;
string
MAGISKTMP
;
bool
RECOVERY_MODE
=
false
;
int
DAEMON_STATE
=
STATE_NONE
;
int
DAEMON_STATE
=
STATE_NONE
;
static
struct
stat
self_st
;
static
struct
stat
self_st
;
...
...
native/jni/core/db.cpp
View file @
eb21c8b4
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <unistd.h>
#include <dlfcn.h>
#include <dlfcn.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <magisk.hpp>
#include <magisk.hpp>
#include <db.hpp>
#include <db.hpp>
#include <
daemon
.hpp>
#include <
socket
.hpp>
#include <utils.hpp>
#include <utils.hpp>
#define DB_VERSION 10
#define DB_VERSION 10
...
...
native/jni/core/magisk.cpp
View file @
eb21c8b4
...
@@ -7,6 +7,8 @@
...
@@ -7,6 +7,8 @@
#include <selinux.hpp>
#include <selinux.hpp>
#include <flags.hpp>
#include <flags.hpp>
#include "core.hpp"
using
namespace
std
;
using
namespace
std
;
[[
noreturn
]]
static
void
usage
()
{
[[
noreturn
]]
static
void
usage
()
{
...
...
native/jni/core/module.cpp
View file @
eb21c8b4
...
@@ -5,9 +5,10 @@
...
@@ -5,9 +5,10 @@
#include <utils.hpp>
#include <utils.hpp>
#include <magisk.hpp>
#include <magisk.hpp>
#include <selinux.hpp>
#include <selinux.hpp>
#include <daemon.hpp>
#include <resetprop.hpp>
#include <resetprop.hpp>
#include "core.hpp"
using
namespace
std
;
using
namespace
std
;
#define VLOGD(tag, from, to) LOGD("%-8s: %s <- %s\n", tag, to, from)
#define VLOGD(tag, from, to) LOGD("%-8s: %s <- %s\n", tag, to, from)
...
...
native/jni/core/restorecon.cpp
View file @
eb21c8b4
#include <string_view>
#include <string_view>
#include <magisk.hpp>
#include <magisk.hpp>
#include <daemon.hpp>
#include <selinux.hpp>
#include <selinux.hpp>
#include <utils.hpp>
#include <utils.hpp>
...
...
native/jni/core/scripting.cpp
View file @
eb21c8b4
...
@@ -6,6 +6,8 @@
...
@@ -6,6 +6,8 @@
#include <utils.hpp>
#include <utils.hpp>
#include <selinux.hpp>
#include <selinux.hpp>
#include "core.hpp"
using
namespace
std
;
using
namespace
std
;
#define BBEXEC_CMD bbpath(), "sh"
#define BBEXEC_CMD bbpath(), "sh"
...
...
native/jni/core/socket.cpp
View file @
eb21c8b4
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <fcntl.h>
#include <endian.h>
#include <endian.h>
...
...
native/jni/include/daemon.hpp
View file @
eb21c8b4
...
@@ -2,7 +2,6 @@
...
@@ -2,7 +2,6 @@
#include <pthread.h>
#include <pthread.h>
#include <string>
#include <string>
#include <vector>
#include <socket.hpp>
#include <socket.hpp>
...
@@ -39,10 +38,7 @@ enum {
...
@@ -39,10 +38,7 @@ enum {
STATE_BOOT_COMPLETE
STATE_BOOT_COMPLETE
};
};
extern
int
SDK_INT
;
int
connect_daemon
(
bool
create
=
false
);
extern
bool
RECOVERY_MODE
;
extern
int
DAEMON_STATE
;
#define APP_DATA_DIR (SDK_INT >= 24 ? "/data/user_de" : "/data/user")
// Daemon handlers
// Daemon handlers
void
post_fs_data
(
int
client
);
void
post_fs_data
(
int
client
);
...
@@ -51,26 +47,6 @@ void boot_complete(int client);
...
@@ -51,26 +47,6 @@ void boot_complete(int client);
void
magiskhide_handler
(
int
client
);
void
magiskhide_handler
(
int
client
);
void
su_daemon_handler
(
int
client
,
ucred
*
credential
);
void
su_daemon_handler
(
int
client
,
ucred
*
credential
);
// Misc
int
connect_daemon
(
bool
create
=
false
);
void
unlock_blocks
();
void
reboot
();
void
setup_logfile
(
bool
reset
);
// Module stuffs
void
handle_modules
();
void
magic_mount
();
void
disable_modules
();
void
remove_modules
();
void
exec_module_scripts
(
const
char
*
stage
);
// MagiskHide
// MagiskHide
void
auto_start_magiskhide
();
void
auto_start_magiskhide
(
bool
late_props
);
int
stop_magiskhide
();
int
stop_magiskhide
();
// Scripting
void
exec_script
(
const
char
*
script
);
void
exec_common_scripts
(
const
char
*
stage
);
void
exec_module_scripts
(
const
char
*
stage
,
const
std
::
vector
<
std
::
string
>
&
module_list
);
void
install_apk
(
const
char
*
apk
);
[[
noreturn
]]
void
install_module
(
const
char
*
file
);
native/jni/include/magisk.hpp
View file @
eb21c8b4
...
@@ -30,6 +30,9 @@ constexpr const char *init_applet[] = { "magiskpolicy", "supolicy", nullptr };
...
@@ -30,6 +30,9 @@ constexpr const char *init_applet[] = { "magiskpolicy", "supolicy", nullptr };
#define POST_FS_DATA_WAIT_TIME 40
#define POST_FS_DATA_WAIT_TIME 40
#define POST_FS_DATA_SCRIPT_MAX_TIME 35
#define POST_FS_DATA_SCRIPT_MAX_TIME 35
extern
int
SDK_INT
;
#define APP_DATA_DIR (SDK_INT >= 24 ? "/data/user_de" : "/data/user")
// Multi-call entrypoints
// Multi-call entrypoints
int
magisk_main
(
int
argc
,
char
*
argv
[]);
int
magisk_main
(
int
argc
,
char
*
argv
[]);
int
magiskhide_main
(
int
argc
,
char
*
argv
[]);
int
magiskhide_main
(
int
argc
,
char
*
argv
[]);
...
...
native/jni/magiskhide/hide_utils.cpp
View file @
eb21c8b4
...
@@ -267,7 +267,7 @@ static void update_hide_config() {
...
@@ -267,7 +267,7 @@ static void update_hide_config() {
db_err
(
err
);
db_err
(
err
);
}
}
int
launch_magiskhide
()
{
int
launch_magiskhide
(
bool
late_props
)
{
mutex_guard
g
(
hide_state_lock
);
mutex_guard
g
(
hide_state_lock
);
if
(
SDK_INT
<
19
)
if
(
SDK_INT
<
19
)
...
@@ -289,7 +289,7 @@ int launch_magiskhide() {
...
@@ -289,7 +289,7 @@ int launch_magiskhide() {
return
DAEMON_ERROR
;
return
DAEMON_ERROR
;
hide_sensitive_props
();
hide_sensitive_props
();
if
(
DAEMON_STATE
>=
STATE_BOOT_COMPLETE
||
DAEMON_STATE
==
STATE_NONE
)
if
(
late_props
)
hide_late_sensitive_props
();
hide_late_sensitive_props
();
#if ENABLE_PTRACE_MONITOR
#if ENABLE_PTRACE_MONITOR
...
@@ -320,7 +320,7 @@ int stop_magiskhide() {
...
@@ -320,7 +320,7 @@ int stop_magiskhide() {
return
DAEMON_SUCCESS
;
return
DAEMON_SUCCESS
;
}
}
void
auto_start_magiskhide
()
{
void
auto_start_magiskhide
(
bool
late_props
)
{
if
(
hide_enabled
())
{
if
(
hide_enabled
())
{
#if ENABLE_PTRACE_MONITOR
#if ENABLE_PTRACE_MONITOR
pthread_kill
(
monitor_thread
,
SIGALRM
);
pthread_kill
(
monitor_thread
,
SIGALRM
);
...
@@ -330,7 +330,7 @@ void auto_start_magiskhide() {
...
@@ -330,7 +330,7 @@ void auto_start_magiskhide() {
db_settings
dbs
;
db_settings
dbs
;
get_db_settings
(
dbs
,
HIDE_CONFIG
);
get_db_settings
(
dbs
,
HIDE_CONFIG
);
if
(
dbs
[
HIDE_CONFIG
])
if
(
dbs
[
HIDE_CONFIG
])
launch_magiskhide
();
launch_magiskhide
(
late_props
);
}
}
}
}
...
...
native/jni/magiskhide/magiskhide.cpp
View file @
eb21c8b4
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>
#include <signal.h>
#include <string.h>
#include <sys/wait.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/mount.h>
#include <sys/mount.h>
#include <daemon.hpp>
#include <utils.hpp>
#include <utils.hpp>
#include "magiskhide.hpp"
#include "magiskhide.hpp"
...
@@ -53,7 +45,7 @@ void magiskhide_handler(int client) {
...
@@ -53,7 +45,7 @@ void magiskhide_handler(int client) {
switch
(
req
)
{
switch
(
req
)
{
case
LAUNCH_MAGISKHIDE
:
case
LAUNCH_MAGISKHIDE
:
res
=
launch_magiskhide
();
res
=
launch_magiskhide
(
true
);
break
;
break
;
case
STOP_MAGISKHIDE
:
case
STOP_MAGISKHIDE
:
res
=
stop_magiskhide
();
res
=
stop_magiskhide
();
...
...
native/jni/magiskhide/magiskhide.hpp
View file @
eb21c8b4
...
@@ -18,7 +18,7 @@
...
@@ -18,7 +18,7 @@
#define ENABLE_PTRACE_MONITOR 1
#define ENABLE_PTRACE_MONITOR 1
// CLI entries
// CLI entries
int
launch_magiskhide
();
int
launch_magiskhide
(
bool
late_props
);
int
stop_magiskhide
();
int
stop_magiskhide
();
int
add_list
(
int
client
);
int
add_list
(
int
client
);
int
rm_list
(
int
client
);
int
rm_list
(
int
client
);
...
...
native/jni/su/connect.cpp
View file @
eb21c8b4
#include <sys/types.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/wait.h>
#include <daemon.hpp>
#include <utils.hpp>
#include <utils.hpp>
#include <selinux.hpp>
#include <selinux.hpp>
...
...
native/jni/su/pts.cpp
View file @
eb21c8b4
...
@@ -9,13 +9,9 @@
...
@@ -9,13 +9,9 @@
* helper functions to handle raw input mode and terminal window resizing
* helper functions to handle raw input mode and terminal window resizing
*/
*/
#include <stdlib.h>
#include <unistd.h>
#include <unistd.h>
#include <fcntl.h>
#include <fcntl.h>
#include <signal.h>
#include <termios.h>
#include <termios.h>
#include <errno.h>
#include <pthread.h>
#include <utils.hpp>
#include <utils.hpp>
...
@@ -116,7 +112,7 @@ static int stdin_is_raw = 0;
...
@@ -116,7 +112,7 @@ static int stdin_is_raw = 0;
/**
/**
* set_stdin_raw
* set_stdin_raw
*
*
* Changes stdin to raw unbuffered mode, disables echo,
* Changes stdin to raw unbuffered mode, disables echo,
* auto carriage return, etc.
* auto carriage return, etc.
*
*
* Return Value
* Return Value
...
@@ -180,7 +176,7 @@ int restore_stdin(void) {
...
@@ -180,7 +176,7 @@ int restore_stdin(void) {
static
volatile
bool
close_sigwinch_watcher
=
false
;
static
volatile
bool
close_sigwinch_watcher
=
false
;
/**
/**
* Thread process. Wait for a SIGWINCH to be received, then update
* Thread process. Wait for a SIGWINCH to be received, then update
* the terminal size.
* the terminal size.
*/
*/
static
void
*
watch_sigwinch
(
void
*
data
)
{
static
void
*
watch_sigwinch
(
void
*
data
)
{
...
@@ -214,7 +210,7 @@ static void *watch_sigwinch(void *data) {
...
@@ -214,7 +210,7 @@ static void *watch_sigwinch(void *data) {
* watch_sigwinch_async
* watch_sigwinch_async
*
*
* After calling this function, if the application receives
* After calling this function, if the application receives
* SIGWINCH, the terminal window size will be read from
* SIGWINCH, the terminal window size will be read from
* "input" and set on "output".
* "input" and set on "output".
*
*
* NOTE: This function blocks SIGWINCH and spawns a thread.
* NOTE: This function blocks SIGWINCH and spawns a thread.
...
@@ -228,7 +224,7 @@ static void *watch_sigwinch(void *data) {
...
@@ -228,7 +224,7 @@ static void *watch_sigwinch(void *data) {
*
*
* Return Value
* Return Value
* on failure, -1 and errno will be set. In this case, no
* on failure, -1 and errno will be set. In this case, no
* thread has been spawned and SIGWINCH will not be
* thread has been spawned and SIGWINCH will not be
* blocked.
* blocked.
* on success, 0
* on success, 0
*/
*/
...
...
native/jni/su/su.cpp
View file @
eb21c8b4
/*
/*
* Copyright 2017, John Wu (@topjohnwu)
* Copyright 2017
- 2021
, John Wu (@topjohnwu)
* Copyright 2015, Pierre-Hugues Husson <phh@phh.me>
* Copyright 2015, Pierre-Hugues Husson <phh@phh.me>
* Copyright 2010, Adam Shanks (@ChainsDD)
* Copyright 2010, Adam Shanks (@ChainsDD)
* Copyright 2008, Zinx Verituse (@zinxv)
* Copyright 2008, Zinx Verituse (@zinxv)
*/
*/
/* su.c - The main function running in the daemon
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <unistd.h>
#include <getopt.h>
#include <getopt.h>
#include <fcntl.h>
#include <fcntl.h>
#include <pwd.h>
#include <pwd.h>
#include <errno.h>
#include <signal.h>
#include <sched.h>
#include <sched.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <magisk.hpp>
#include <daemon.hpp>
#include <daemon.hpp>
#include <utils.hpp>
#include <utils.hpp>
#include <flags.hpp>
#include <flags.hpp>
...
...
native/jni/su/su.hpp
View file @
eb21c8b4
...
@@ -5,7 +5,6 @@
...
@@ -5,7 +5,6 @@
#include <memory>
#include <memory>
#include <db.hpp>
#include <db.hpp>
#include <utils.hpp>
#define DEFAULT_SHELL "/system/bin/sh"
#define DEFAULT_SHELL "/system/bin/sh"
...
...
native/jni/su/su_daemon.cpp
View file @
eb21c8b4
#include <unistd.h>
#include <unistd.h>
#include <pthread.h>
#include <stdlib.h>
#include <fcntl.h>
#include <fcntl.h>
#include <string.h>
#include <signal.h>
#include <pwd.h>
#include <pwd.h>
#include <time.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/wait.h>
#include <sys/mount.h>
#include <sys/mount.h>
#include <daemon.hpp>
#include <daemon.hpp>
#include <utils.hpp>
#include <utils.hpp>
#include <selinux.hpp>
#include <selinux.hpp>
#include <db.hpp>
#include "su.hpp"
#include "su.hpp"
#include "pts.hpp"
#include "pts.hpp"
...
...
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