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
df8b047b
Commit
df8b047b
authored
Sep 27, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Generalize logging interface
parent
12ced520
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
173 additions
and
86 deletions
+173
-86
Android.mk
native/jni/Android.mk
+2
-2
Application.mk
native/jni/Application.mk
+2
-2
daemon.c
native/jni/core/daemon.c
+4
-0
log_daemon.c
native/jni/core/log_daemon.c
+2
-0
magisk.c
native/jni/core/magisk.c
+1
-0
magiskinit.c
native/jni/core/magiskinit.c
+7
-9
socket.c
native/jni/core/socket.c
+2
-0
logging.h
native/jni/include/logging.h
+30
-54
bootimg.c
native/jni/magiskboot/bootimg.c
+1
-0
compress.c
native/jni/magiskboot/compress.c
+2
-0
cpio.c
native/jni/magiskboot/cpio.c
+2
-0
ramdisk.c
native/jni/magiskboot/ramdisk.c
+3
-1
magiskhide.c
native/jni/magiskhide/magiskhide.c
+1
-0
magiskpolicy.c
native/jni/magiskpolicy/magiskpolicy.c
+1
-0
_resetprop.h
native/jni/resetprop/_resetprop.h
+0
-3
persist_properties.c
native/jni/resetprop/persist_properties.c
+4
-4
resetprop.c
native/jni/resetprop/resetprop.c
+17
-10
img.c
native/jni/utils/img.c
+3
-0
logging.c
native/jni/utils/logging.c
+88
-0
selinux.c
native/jni/utils/selinux.c
+1
-1
No files found.
native/jni/Android.mk
View file @
df8b047b
...
@@ -17,6 +17,7 @@ COMMON_UTILS := \
...
@@ -17,6 +17,7 @@ COMMON_UTILS := \
utils/misc.c \
utils/misc.c \
utils/vector.c \
utils/vector.c \
utils/selinux.c \
utils/selinux.c \
utils/logging.c \
utils/xwrap.c
utils/xwrap.c
########################
########################
...
@@ -32,7 +33,6 @@ LOCAL_SHARED_LIBRARIES := libsqlite
...
@@ -32,7 +33,6 @@ LOCAL_SHARED_LIBRARIES := libsqlite
LOCAL_STATIC_LIBRARIES := libnanopb libsystemproperties
LOCAL_STATIC_LIBRARIES := libnanopb libsystemproperties
LOCAL_C_INCLUDES := \
LOCAL_C_INCLUDES := \
jni/include \
jni/include \
jni/magiskpolicy \
$(EXT_PATH)/include \
$(EXT_PATH)/include \
$(LIBNANOPB) \
$(LIBNANOPB) \
$(LIBSYSTEMPROPERTIES)
$(LIBSYSTEMPROPERTIES)
...
@@ -144,7 +144,7 @@ include jni/external/busybox/Android.mk
...
@@ -144,7 +144,7 @@ include jni/external/busybox/Android.mk
endif
endif
########################
########################
#
External
s
#
Librarie
s
########################
########################
include jni/external/Android.mk
include jni/external/Android.mk
include jni/resetprop/libsystemproperties/Android.mk
include jni/resetprop/libsystemproperties/Android.mk
native/jni/Application.mk
View file @
df8b047b
APP_ABI := armeabi-v7a x86
APP_ABI := armeabi-v7a x86
APP_CFLAGS := -std=gnu
99
${MAGISK_DEBUG} \
APP_CFLAGS := -std=gnu
11
${MAGISK_DEBUG} \
-DMAGISK_VERSION="${MAGISK_VERSION}" -DMAGISK_VER_CODE=${MAGISK_VER_CODE}
-DMAGISK_VERSION="${MAGISK_VERSION}" -DMAGISK_VER_CODE=${MAGISK_VER_CODE}
APP_CPPFLAGS := -std=c++14
APP_CPPFLAGS := -std=c++14
APP_STL := system
APP_STL := system
APP_PLATFORM := android-16
APP_PLATFORM := android-16
APP_CFLAGS += -Wno-implicit-function-declaration
# Busybox require some additional settings
# Busybox require some additional settings
ifdef B_BB
ifdef B_BB
APP_SHORT_COMMANDS := true
APP_SHORT_COMMANDS := true
NDK_TOOLCHAIN_VERSION := 4.9
NDK_TOOLCHAIN_VERSION := 4.9
APP_PLATFORM := android-21
APP_PLATFORM := android-21
APP_CFLAGS += -Wno-implicit-function-declaration
endif
endif
native/jni/core/daemon.c
View file @
df8b047b
...
@@ -96,6 +96,10 @@ static void *request_handler(void *args) {
...
@@ -96,6 +96,10 @@ static void *request_handler(void *args) {
}
}
void
main_daemon
()
{
void
main_daemon
()
{
android_logging
();
#ifndef MAGISK_DEBUG
log_cb
.
d
=
nop_log
;
#endif
setsid
();
setsid
();
setcon
(
"u:r:"
SEPOL_PROC_DOMAIN
":s0"
);
setcon
(
"u:r:"
SEPOL_PROC_DOMAIN
":s0"
);
int
fd
=
xopen
(
"/dev/null"
,
O_RDWR
|
O_CLOEXEC
);
int
fd
=
xopen
(
"/dev/null"
,
O_RDWR
|
O_CLOEXEC
);
...
...
native/jni/core/log_daemon.c
View file @
df8b047b
...
@@ -8,6 +8,8 @@
...
@@ -8,6 +8,8 @@
#include <stdio.h>
#include <stdio.h>
#include <pthread.h>
#include <pthread.h>
#include <unistd.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/wait.h>
#include <sys/wait.h>
#include <fcntl.h>
#include <fcntl.h>
...
...
native/jni/core/magisk.c
View file @
df8b047b
...
@@ -5,6 +5,7 @@
...
@@ -5,6 +5,7 @@
#include <stdio.h>
#include <stdio.h>
#include <unistd.h>
#include <unistd.h>
#include <libgen.h>
#include <libgen.h>
#include <string.h>
#include "utils.h"
#include "utils.h"
#include "magisk.h"
#include "magisk.h"
...
...
native/jni/core/magiskinit.c
View file @
df8b047b
...
@@ -46,12 +46,6 @@
...
@@ -46,12 +46,6 @@
#include "daemon.h"
#include "daemon.h"
#include "magisk.h"
#include "magisk.h"
#ifdef MAGISK_DEBUG
#define VLOG(fmt, ...) fprintf(stderr, fmt, __VA_ARGS__)
#else
#define VLOG(fmt, ...)
#endif
#define DEFAULT_DT_DIR "/proc/device-tree/firmware/android"
#define DEFAULT_DT_DIR "/proc/device-tree/firmware/android"
int
(
*
init_applet_main
[])
(
int
,
char
*
[])
=
{
magiskpolicy_main
,
magiskpolicy_main
,
NULL
};
int
(
*
init_applet_main
[])
(
int
,
char
*
[])
=
{
magiskpolicy_main
,
magiskpolicy_main
,
NULL
};
...
@@ -94,7 +88,7 @@ static void parse_cmdline(struct cmdline *cmd) {
...
@@ -94,7 +88,7 @@ static void parse_cmdline(struct cmdline *cmd) {
if
(
cmd
->
dt_dir
[
0
]
==
'\0'
)
if
(
cmd
->
dt_dir
[
0
]
==
'\0'
)
strcpy
(
cmd
->
dt_dir
,
DEFAULT_DT_DIR
);
strcpy
(
cmd
->
dt_dir
,
DEFAULT_DT_DIR
);
VLOG
(
"cmdline: skip_initramfs[%d] slot[%s] dt_dir[%s]
\n
"
,
cmd
->
skip_initramfs
,
cmd
->
slot
,
cmd
->
dt_dir
);
LOGD
(
"cmdline: skip_initramfs[%d] slot[%s] dt_dir[%s]
\n
"
,
cmd
->
skip_initramfs
,
cmd
->
slot
,
cmd
->
dt_dir
);
}
}
static
void
parse_device
(
struct
device
*
dev
,
const
char
*
uevent
)
{
static
void
parse_device
(
struct
device
*
dev
,
const
char
*
uevent
)
{
...
@@ -113,7 +107,7 @@ static void parse_device(struct device *dev, const char *uevent) {
...
@@ -113,7 +107,7 @@ static void parse_device(struct device *dev, const char *uevent) {
}
}
}
}
fclose
(
fp
);
fclose
(
fp
);
VLOG
(
"%s [%s] (%u, %u)
\n
"
,
dev
->
devname
,
dev
->
partname
,
(
unsigned
)
dev
->
major
,
(
unsigned
)
dev
->
minor
);
LOGD
(
"%s [%s] (%u, %u)
\n
"
,
dev
->
devname
,
dev
->
partname
,
(
unsigned
)
dev
->
major
,
(
unsigned
)
dev
->
minor
);
}
}
static
int
setup_block
(
struct
device
*
dev
,
const
char
*
partname
)
{
static
int
setup_block
(
struct
device
*
dev
,
const
char
*
partname
)
{
...
@@ -199,7 +193,7 @@ static int verify_precompiled() {
...
@@ -199,7 +193,7 @@ static int verify_precompiled() {
}
}
}
}
closedir
(
dir
);
closedir
(
dir
);
VLOG
(
"sys_sha[%.*s]
\n
ven_sha[%.*s]
\n
"
,
sizeof
(
sys_sha
),
sys_sha
,
sizeof
(
ven_sha
),
ven_sha
);
LOGD
(
"sys_sha[%.*s]
\n
ven_sha[%.*s]
\n
"
,
sizeof
(
sys_sha
),
sys_sha
,
sizeof
(
ven_sha
),
ven_sha
);
return
memcmp
(
sys_sha
,
ven_sha
,
sizeof
(
sys_sha
))
==
0
;
return
memcmp
(
sys_sha
,
ven_sha
,
sizeof
(
sys_sha
))
==
0
;
}
}
...
@@ -339,6 +333,10 @@ int main(int argc, char *argv[]) {
...
@@ -339,6 +333,10 @@ int main(int argc, char *argv[]) {
return
dump_magiskrc
(
argv
[
3
],
0755
);
return
dump_magiskrc
(
argv
[
3
],
0755
);
}
}
#ifdef MAGISK_DEBUG
log_cb
.
d
=
vprintf
;
#endif
// Prevent file descriptor confusion
// Prevent file descriptor confusion
mknod
(
"/null"
,
S_IFCHR
|
0666
,
makedev
(
1
,
3
));
mknod
(
"/null"
,
S_IFCHR
|
0666
,
makedev
(
1
,
3
));
int
null
=
open
(
"/null"
,
O_RDWR
|
O_CLOEXEC
);
int
null
=
open
(
"/null"
,
O_RDWR
|
O_CLOEXEC
);
...
...
native/jni/core/socket.c
View file @
df8b047b
/* socket.c - All socket related operations
/* socket.c - All socket related operations
*/
*/
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>
#include <fcntl.h>
#include <endian.h>
#include <endian.h>
...
...
native/jni/include/logging.h
View file @
df8b047b
/* logging.h - Error handling and logging
/* logging.h - Error handling and logging
*/
*/
#ifndef _LOGGING_H_
#pragma once
#define _LOGGING_H_
#include <string.h>
#include <errno.h>
#include <errno.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#define str(a) #a
#define str(a) #a
#define xstr(a) str(a)
#define xstr(a) str(a)
/**************
typedef
enum
{
* No logging *
L_DEBUG
,
**************/
L_INFO
,
L_WARN
,
#define LOGD(...)
L_ERR
#define LOGI(...)
}
log_type
;
#define LOGW(...)
#define LOGE(...)
struct
log_callback
{
#define PLOGE(...)
int
(
*
d
)(
const
char
*
fmt
,
va_list
ap
);
int
(
*
i
)(
const
char
*
fmt
,
va_list
ap
);
/******************
int
(
*
w
)(
const
char
*
fmt
,
va_list
ap
);
* Daemon logging *
int
(
*
e
)(
const
char
*
fmt
,
va_list
ap
);
******************/
void
(
*
ex
)(
int
code
);
};
#ifdef IS_DAEMON
extern
struct
log_callback
log_cb
;
#undef LOGI
#undef LOGW
#define LOGD(...) log_handler(L_DEBUG, __VA_ARGS__)
#undef LOGE
#define LOGI(...) log_handler(L_INFO, __VA_ARGS__)
#undef PLOGE
#define LOGW(...) log_handler(L_WARN, __VA_ARGS__)
#define LOGE(...) log_handler(L_ERR, __VA_ARGS__)
#include <pthread.h>
#include <android/log.h>
#define LOG_TAG "Magisk"
#ifdef MAGISK_DEBUG
#undef LOGD
#define LOGD(...) __android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)
#endif
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)
#define LOGW(...) __android_log_print(ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)
#define PLOGE(fmt, args...) LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno))
#define PLOGE(fmt, args...) LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno))
#endif
int
nop_log
(
const
char
*
fmt
,
va_list
ap
);
void
nop_ex
(
int
i
);
/********************
* Tools Log & Exit *
********************/
#ifdef XWRAP_EXIT
#undef LOGE
#undef PLOGE
#include <stdio.h>
#define LOGE(...) { fprintf(stderr, __VA_ARGS__); exit(1); }
#define PLOGE(fmt, args...) { fprintf(stderr, fmt " failed with %d: %s\n\n", ##args, errno, strerror(errno)); exit(1); }
#endif
void
no_logging
();
void
android_logging
();
void
cmdline_logging
();
int
log_handler
(
log_type
t
,
const
char
*
fmt
,
...);
#endif // _LOGGING_H_
native/jni/magiskboot/bootimg.c
View file @
df8b047b
...
@@ -250,6 +250,7 @@ int parse_img(const char *image, boot_img *boot) {
...
@@ -250,6 +250,7 @@ int parse_img(const char *image, boot_img *boot) {
}
}
}
}
LOGE
(
"No boot image magic found!
\n
"
);
LOGE
(
"No boot image magic found!
\n
"
);
exit
(
1
);
}
}
int
unpack
(
const
char
*
image
)
{
int
unpack
(
const
char
*
image
)
{
...
...
native/jni/magiskboot/compress.c
View file @
df8b047b
#include <unistd.h>
#include <unistd.h>
#include <fcntl.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/mman.h>
#include <zlib.h>
#include <zlib.h>
...
...
native/jni/magiskboot/cpio.c
View file @
df8b047b
#include <stdio.h>
#include <stdio.h>
#include <unistd.h>
#include <unistd.h>
#include <fcntl.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
#include "cpio.h"
#include "cpio.h"
#include "logging.h"
#include "logging.h"
...
...
native/jni/magiskboot/ramdisk.c
View file @
df8b047b
#include <stdio.h>
#include <stdio.h>
#include <unistd.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <utils.h>
#include <sys/mman.h>
#include <sys/mman.h>
#include <fcntl.h>
#include <fcntl.h>
#include "magiskboot.h"
#include "magiskboot.h"
#include "cpio.h"
#include "cpio.h"
#include "utils.h"
static
void
cpio_patch
(
struct
vector
*
v
,
int
keepverity
,
int
keepforceencrypt
)
{
static
void
cpio_patch
(
struct
vector
*
v
,
int
keepverity
,
int
keepforceencrypt
)
{
fprintf
(
stderr
,
"Patch with flag KEEPVERITY=[%s] KEEPFORCEENCRYPT=[%s]
\n
"
,
fprintf
(
stderr
,
"Patch with flag KEEPVERITY=[%s] KEEPFORCEENCRYPT=[%s]
\n
"
,
...
...
native/jni/magiskhide/magiskhide.c
View file @
df8b047b
...
@@ -114,6 +114,7 @@ void stop_magiskhide(int client) {
...
@@ -114,6 +114,7 @@ void stop_magiskhide(int client) {
}
}
int
magiskhide_main
(
int
argc
,
char
*
argv
[])
{
int
magiskhide_main
(
int
argc
,
char
*
argv
[])
{
cmdline_logging
();
if
(
argc
<
2
)
{
if
(
argc
<
2
)
{
usage
(
argv
[
0
]);
usage
(
argv
[
0
]);
}
}
...
...
native/jni/magiskpolicy/magiskpolicy.c
View file @
df8b047b
...
@@ -391,6 +391,7 @@ static void syntax_error_msg() {
...
@@ -391,6 +391,7 @@ static void syntax_error_msg() {
}
}
int
magiskpolicy_main
(
int
argc
,
char
*
argv
[])
{
int
magiskpolicy_main
(
int
argc
,
char
*
argv
[])
{
cmdline_logging
();
char
*
outfile
=
NULL
,
*
tok
,
*
saveptr
;
char
*
outfile
=
NULL
,
*
tok
,
*
saveptr
;
int
magisk
=
0
;
int
magisk
=
0
;
struct
vector
rules
;
struct
vector
rules
;
...
...
native/jni/resetprop/_resetprop.h
View file @
df8b047b
...
@@ -10,9 +10,6 @@
...
@@ -10,9 +10,6 @@
extern
int
prop_verbose
;
extern
int
prop_verbose
;
#define PRINT_D(...) { LOGD(__VA_ARGS__); if (prop_verbose) fprintf(stderr, __VA_ARGS__); }
#define PRINT_E(...) { LOGE(__VA_ARGS__); fprintf(stderr, __VA_ARGS__); }
struct
prop_t
{
struct
prop_t
{
char
*
name
;
char
*
name
;
char
value
[
PROP_VALUE_MAX
];
char
value
[
PROP_VALUE_MAX
];
...
...
native/jni/resetprop/persist_properties.c
View file @
df8b047b
...
@@ -153,7 +153,7 @@ static void pb_getprop_cb(const char *name, const char *value, void *v) {
...
@@ -153,7 +153,7 @@ static void pb_getprop_cb(const char *name, const char *value, void *v) {
void
persist_getprop_all
(
struct
read_cb_t
*
read_cb
)
{
void
persist_getprop_all
(
struct
read_cb_t
*
read_cb
)
{
if
(
access
(
PERSISTENT_PROPERTY_DIR
"/persistent_properties"
,
R_OK
)
==
0
)
{
if
(
access
(
PERSISTENT_PROPERTY_DIR
"/persistent_properties"
,
R_OK
)
==
0
)
{
PRINT_
D
(
"resetprop: decode with protobuf from ["
PERSISTENT_PROPERTY_DIR
"/persistent_properties]
\n
"
);
LOG
D
(
"resetprop: decode with protobuf from ["
PERSISTENT_PROPERTY_DIR
"/persistent_properties]
\n
"
);
PersistentProperties
props
=
PersistentProperties_init_zero
;
PersistentProperties
props
=
PersistentProperties_init_zero
;
props
.
properties
.
funcs
.
decode
=
prop_decode
;
props
.
properties
.
funcs
.
decode
=
prop_decode
;
props
.
properties
.
arg
=
read_cb
;
props
.
properties
.
arg
=
read_cb
;
...
@@ -196,7 +196,7 @@ char *persist_getprop(const char *name) {
...
@@ -196,7 +196,7 @@ char *persist_getprop(const char *name) {
int
fd
=
open
(
path
,
O_RDONLY
|
O_CLOEXEC
);
int
fd
=
open
(
path
,
O_RDONLY
|
O_CLOEXEC
);
if
(
fd
<
0
)
if
(
fd
<
0
)
return
NULL
;
return
NULL
;
PRINT_
D
(
"resetprop: read prop from [%s]
\n
"
,
path
);
LOG
D
(
"resetprop: read prop from [%s]
\n
"
,
path
);
prop
.
value
[
read
(
fd
,
prop
.
value
,
sizeof
(
PROP_VALUE_MAX
))]
=
'\0'
;
// Null terminate the read value
prop
.
value
[
read
(
fd
,
prop
.
value
,
sizeof
(
PROP_VALUE_MAX
))]
=
'\0'
;
// Null terminate the read value
close
(
fd
);
close
(
fd
);
}
}
...
@@ -231,7 +231,7 @@ bool persist_deleteprop(const char *name) {
...
@@ -231,7 +231,7 @@ bool persist_deleteprop(const char *name) {
pb_ostream_t
ostream
=
create_ostream
(
PERSISTENT_PROPERTY_DIR
"/persistent_properties.tmp"
);
pb_ostream_t
ostream
=
create_ostream
(
PERSISTENT_PROPERTY_DIR
"/persistent_properties.tmp"
);
props
.
properties
.
funcs
.
encode
=
prop_encode
;
props
.
properties
.
funcs
.
encode
=
prop_encode
;
props
.
properties
.
arg
=
&
v
;
props
.
properties
.
arg
=
&
v
;
PRINT_
D
(
"resetprop: encode with protobuf to ["
PERSISTENT_PROPERTY_DIR
"/persistent_properties.tmp]
\n
"
);
LOG
D
(
"resetprop: encode with protobuf to ["
PERSISTENT_PROPERTY_DIR
"/persistent_properties.tmp]
\n
"
);
if
(
!
pb_encode
(
&
ostream
,
PersistentProperties_fields
,
&
props
))
if
(
!
pb_encode
(
&
ostream
,
PersistentProperties_fields
,
&
props
))
return
false
;
return
false
;
clone_attr
(
PERSISTENT_PROPERTY_DIR
"/persistent_properties"
,
PERSISTENT_PROPERTY_DIR
"/persistent_properties.tmp"
);
clone_attr
(
PERSISTENT_PROPERTY_DIR
"/persistent_properties"
,
PERSISTENT_PROPERTY_DIR
"/persistent_properties.tmp"
);
...
@@ -244,7 +244,7 @@ bool persist_deleteprop(const char *name) {
...
@@ -244,7 +244,7 @@ bool persist_deleteprop(const char *name) {
char
path
[
PATH_MAX
];
char
path
[
PATH_MAX
];
snprintf
(
path
,
sizeof
(
path
),
PERSISTENT_PROPERTY_DIR
"/%s"
,
name
);
snprintf
(
path
,
sizeof
(
path
),
PERSISTENT_PROPERTY_DIR
"/%s"
,
name
);
if
(
unlink
(
path
)
==
0
)
{
if
(
unlink
(
path
)
==
0
)
{
PRINT_
D
(
"resetprop: unlink [%s]
\n
"
,
path
);
LOG
D
(
"resetprop: unlink [%s]
\n
"
,
path
);
return
true
;
return
true
;
}
}
}
}
...
...
native/jni/resetprop/resetprop.c
View file @
df8b047b
...
@@ -50,7 +50,7 @@ static int check_legal_property_name(const char *name) {
...
@@ -50,7 +50,7 @@ static int check_legal_property_name(const char *name) {
return
0
;
return
0
;
illegal:
illegal:
PRINT_
E
(
"Illegal property name: [%s]
\n
"
,
name
);
LOG
E
(
"Illegal property name: [%s]
\n
"
,
name
);
return
1
;
return
1
;
}
}
...
@@ -124,7 +124,7 @@ static int prop_cmp(const void *p1, const void *p2) {
...
@@ -124,7 +124,7 @@ static int prop_cmp(const void *p1, const void *p2) {
static
int
init_resetprop
()
{
static
int
init_resetprop
()
{
if
(
__system_properties_init
())
{
if
(
__system_properties_init
())
{
PRINT_
E
(
"resetprop: Initialize error
\n
"
);
LOG
E
(
"resetprop: Initialize error
\n
"
);
return
-
1
;
return
-
1
;
}
}
return
0
;
return
0
;
...
@@ -176,7 +176,7 @@ char *getprop2(const char *name, int persist) {
...
@@ -176,7 +176,7 @@ char *getprop2(const char *name, int persist) {
if
(
value
)
if
(
value
)
return
value
;
return
value
;
}
}
PRINT_
D
(
"resetprop: prop [%s] does not exist
\n
"
,
name
);
LOG
D
(
"resetprop: prop [%s] does not exist
\n
"
,
name
);
return
NULL
;
return
NULL
;
}
else
{
}
else
{
char
value
[
PROP_VALUE_MAX
];
char
value
[
PROP_VALUE_MAX
];
...
@@ -185,7 +185,7 @@ char *getprop2(const char *name, int persist) {
...
@@ -185,7 +185,7 @@ char *getprop2(const char *name, int persist) {
.
cookie
=
value
.
cookie
=
value
};
};
__system_property_read_callback
(
pi
,
callback_wrapper
,
&
read_cb
);
__system_property_read_callback
(
pi
,
callback_wrapper
,
&
read_cb
);
PRINT_
D
(
"resetprop: getprop [%s]: [%s]
\n
"
,
name
,
value
);
LOG
D
(
"resetprop: getprop [%s]: [%s]
\n
"
,
name
,
value
);
return
strdup
(
value
);
return
strdup
(
value
);
}
}
}
}
...
@@ -218,7 +218,7 @@ int setprop2(const char *name, const char *value, const int trigger) {
...
@@ -218,7 +218,7 @@ int setprop2(const char *name, const char *value, const int trigger) {
ret
=
__system_property_update
(
pi
,
value
,
strlen
(
value
));
ret
=
__system_property_update
(
pi
,
value
,
strlen
(
value
));
}
}
}
else
{
}
else
{
PRINT_
D
(
"resetprop: New prop [%s]
\n
"
,
name
);
LOG
D
(
"resetprop: New prop [%s]
\n
"
,
name
);
if
(
trigger
)
{
if
(
trigger
)
{
ret
=
__system_property_set
(
name
,
value
);
ret
=
__system_property_set
(
name
,
value
);
}
else
{
}
else
{
...
@@ -226,11 +226,11 @@ int setprop2(const char *name, const char *value, const int trigger) {
...
@@ -226,11 +226,11 @@ int setprop2(const char *name, const char *value, const int trigger) {
}
}
}
}
PRINT_
D
(
"resetprop: setprop [%s]: [%s] by %s
\n
"
,
name
,
value
,
LOG
D
(
"resetprop: setprop [%s]: [%s] by %s
\n
"
,
name
,
value
,
trigger
?
"property_service"
:
"modifing prop data structure"
);
trigger
?
"property_service"
:
"modifing prop data structure"
);
if
(
ret
)
if
(
ret
)
PRINT_
E
(
"resetprop: setprop error
\n
"
);
LOG
E
(
"resetprop: setprop error
\n
"
);
return
ret
;
return
ret
;
}
}
...
@@ -245,7 +245,7 @@ int deleteprop2(const char *name, int persist) {
...
@@ -245,7 +245,7 @@ int deleteprop2(const char *name, int persist) {
if
(
init_resetprop
())
return
-
1
;
if
(
init_resetprop
())
return
-
1
;
char
path
[
PATH_MAX
];
char
path
[
PATH_MAX
];
path
[
0
]
=
'\0'
;
path
[
0
]
=
'\0'
;
PRINT_
D
(
"resetprop: deleteprop [%s]
\n
"
,
name
);
LOG
D
(
"resetprop: deleteprop [%s]
\n
"
,
name
);
if
(
persist
&&
strncmp
(
name
,
"persist."
,
8
)
==
0
)
if
(
persist
&&
strncmp
(
name
,
"persist."
,
8
)
==
0
)
persist
=
persist_deleteprop
(
name
);
persist
=
persist_deleteprop
(
name
);
return
__system_property_del
(
name
)
&&
!
(
persist
&&
strncmp
(
name
,
"persist."
,
8
)
==
0
);
return
__system_property_del
(
name
)
&&
!
(
persist
&&
strncmp
(
name
,
"persist."
,
8
)
==
0
);
...
@@ -253,10 +253,10 @@ int deleteprop2(const char *name, int persist) {
...
@@ -253,10 +253,10 @@ int deleteprop2(const char *name, int persist) {
int
read_prop_file
(
const
char
*
filename
,
const
int
trigger
)
{
int
read_prop_file
(
const
char
*
filename
,
const
int
trigger
)
{
if
(
init_resetprop
())
return
-
1
;
if
(
init_resetprop
())
return
-
1
;
PRINT_
D
(
"resetprop: Load prop file [%s]
\n
"
,
filename
);
LOG
D
(
"resetprop: Load prop file [%s]
\n
"
,
filename
);
FILE
*
fp
=
fopen
(
filename
,
"r"
);
FILE
*
fp
=
fopen
(
filename
,
"r"
);
if
(
fp
==
NULL
)
{
if
(
fp
==
NULL
)
{
PRINT_
E
(
"Cannot open [%s]
\n
"
,
filename
);
LOG
E
(
"Cannot open [%s]
\n
"
,
filename
);
return
1
;
return
1
;
}
}
char
*
line
=
NULL
,
*
pch
;
char
*
line
=
NULL
,
*
pch
;
...
@@ -292,7 +292,14 @@ int read_prop_file(const char* filename, const int trigger) {
...
@@ -292,7 +292,14 @@ int read_prop_file(const char* filename, const int trigger) {
return
0
;
return
0
;
}
}
static
int
verbose_logging
(
const
char
*
fmt
,
va_list
ap
)
{
return
prop_verbose
?
vfprintf
(
stderr
,
fmt
,
ap
)
:
0
;
}
int
resetprop_main
(
int
argc
,
char
*
argv
[])
{
int
resetprop_main
(
int
argc
,
char
*
argv
[])
{
cmdline_logging
();
log_cb
.
d
=
verbose_logging
;
int
trigger
=
1
,
persist
=
0
;
int
trigger
=
1
,
persist
=
0
;
char
*
argv0
=
argv
[
0
],
*
prop
;
char
*
argv0
=
argv
[
0
],
*
prop
;
...
...
native/jni/utils/img.c
View file @
df8b047b
...
@@ -4,6 +4,8 @@
...
@@ -4,6 +4,8 @@
#include <unistd.h>
#include <unistd.h>
#include <libgen.h>
#include <libgen.h>
#include <fcntl.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <sys/wait.h>
#include <sys/mount.h>
#include <sys/mount.h>
...
@@ -97,6 +99,7 @@ static void usage() {
...
@@ -97,6 +99,7 @@ static void usage() {
}
}
int
imgtool_main
(
int
argc
,
char
*
argv
[])
{
int
imgtool_main
(
int
argc
,
char
*
argv
[])
{
cmdline_logging
();
if
(
argc
<
2
)
if
(
argc
<
2
)
usage
();
usage
();
if
(
strcmp
(
argv
[
1
],
"create"
)
==
0
)
{
if
(
strcmp
(
argv
[
1
],
"create"
)
==
0
)
{
...
...
native/jni/utils/logging.c
0 → 100644
View file @
df8b047b
#include <stdio.h>
#include <stdlib.h>
#include <android/log.h>
#include "logging.h"
int
nop_log
(
const
char
*
fmt
,
va_list
ap
)
{
return
0
;
}
void
nop_ex
(
int
i
)
{}
struct
log_callback
log_cb
=
{
.
d
=
nop_log
,
.
i
=
nop_log
,
.
w
=
nop_log
,
.
e
=
nop_log
,
.
ex
=
nop_ex
};
void
no_logging
()
{
log_cb
.
d
=
nop_log
;
log_cb
.
i
=
nop_log
;
log_cb
.
w
=
nop_log
;
log_cb
.
e
=
nop_log
;
log_cb
.
ex
=
nop_ex
;
}
#define LOG_TAG "Magisk"
static
int
log_d
(
const
char
*
fmt
,
va_list
ap
)
{
return
__android_log_vprint
(
ANDROID_LOG_DEBUG
,
LOG_TAG
,
fmt
,
ap
);
}
static
int
log_i
(
const
char
*
fmt
,
va_list
ap
)
{
return
__android_log_vprint
(
ANDROID_LOG_INFO
,
LOG_TAG
,
fmt
,
ap
);
}
static
int
log_w
(
const
char
*
fmt
,
va_list
ap
)
{
return
__android_log_vprint
(
ANDROID_LOG_WARN
,
LOG_TAG
,
fmt
,
ap
);
}
static
int
log_e
(
const
char
*
fmt
,
va_list
ap
)
{
return
__android_log_vprint
(
ANDROID_LOG_ERROR
,
LOG_TAG
,
fmt
,
ap
);
}
void
android_logging
()
{
log_cb
.
d
=
log_d
;
log_cb
.
i
=
log_i
;
log_cb
.
w
=
log_w
;
log_cb
.
e
=
log_e
;
log_cb
.
ex
=
nop_ex
;
}
static
int
vprinte
(
const
char
*
fmt
,
va_list
ap
)
{
return
vfprintf
(
stderr
,
fmt
,
ap
);
}
void
cmdline_logging
()
{
log_cb
.
d
=
vprinte
;
log_cb
.
i
=
vprintf
;
log_cb
.
w
=
vprinte
;
log_cb
.
e
=
vprinte
;
log_cb
.
ex
=
exit
;
}
int
log_handler
(
log_type
t
,
const
char
*
fmt
,
...)
{
va_list
argv
;
int
ret
=
0
;
va_start
(
argv
,
fmt
);
switch
(
t
)
{
case
L_DEBUG
:
ret
=
log_cb
.
d
(
fmt
,
argv
);
break
;
case
L_INFO
:
ret
=
log_cb
.
i
(
fmt
,
argv
);
break
;
case
L_WARN
:
ret
=
log_cb
.
w
(
fmt
,
argv
);
break
;
case
L_ERR
:
ret
=
log_cb
.
e
(
fmt
,
argv
);
log_cb
.
ex
(
1
);
break
;
}
va_end
(
argv
);
return
ret
;
}
native/jni/utils/selinux.c
View file @
df8b047b
#include <dlfcn.h>
#include <dlfcn.h>
#include <unistd.h>
#include <unistd.h>
#include <string.h>
#include "magisk.h"
#include "magisk.h"
#include "utils.h"
#include "utils.h"
#include "logging.h"
#include "selinux.h"
#include "selinux.h"
#define UNLABEL_CON "u:object_r:unlabeled:s0"
#define UNLABEL_CON "u:object_r:unlabeled:s0"
...
...
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