Restructure native codebase

This commit is contained in:
topjohnwu 2022-05-12 02:03:42 -07:00
parent 7505599ea0
commit 622e09862a
78 changed files with 102 additions and 98 deletions

View File

@ -9,7 +9,7 @@ ifdef B_MAGISK
include $(CLEAR_VARS)
LOCAL_MODULE := magisk
LOCAL_STATIC_LIBRARIES := \
libutils \
libbase \
libnanopb \
libsystemproperties \
libphmap \
@ -23,6 +23,7 @@ LOCAL_SRC_FILES := \
core/bootstages.cpp \
core/socket.cpp \
core/db.cpp \
core/cert.cpp \
core/scripting.cpp \
core/restorecon.cpp \
core/module.cpp \
@ -33,7 +34,6 @@ LOCAL_SRC_FILES := \
su/su.cpp \
su/connect.cpp \
su/pts.cpp \
su/cert.cpp \
su/su_daemon.cpp \
zygisk/entry.cpp \
zygisk/main.cpp \
@ -64,7 +64,8 @@ ifdef B_INIT
include $(CLEAR_VARS)
LOCAL_MODULE := magiskinit
LOCAL_STATIC_LIBRARIES := \
libutilx \
libbase \
libcompat \
libpolicy \
libxz
@ -86,7 +87,8 @@ ifdef B_BOOT
include $(CLEAR_VARS)
LOCAL_MODULE := magiskboot
LOCAL_STATIC_LIBRARIES := \
libutilx \
libbase \
libcompat \
libmincrypt \
liblzma \
liblz4 \
@ -96,15 +98,15 @@ LOCAL_STATIC_LIBRARIES := \
libzopfli
LOCAL_SRC_FILES := \
magiskboot/main.cpp \
magiskboot/bootimg.cpp \
magiskboot/hexpatch.cpp \
magiskboot/compress.cpp \
magiskboot/format.cpp \
magiskboot/dtb.cpp \
magiskboot/ramdisk.cpp \
magiskboot/pattern.cpp \
magiskboot/cpio.cpp
boot/main.cpp \
boot/bootimg.cpp \
boot/hexpatch.cpp \
boot/compress.cpp \
boot/format.cpp \
boot/dtb.cpp \
boot/ramdisk.cpp \
boot/pattern.cpp \
boot/cpio.cpp
LOCAL_LDFLAGS := -static
include $(BUILD_EXECUTABLE)
@ -116,10 +118,11 @@ ifdef B_POLICY
include $(CLEAR_VARS)
LOCAL_MODULE := magiskpolicy
LOCAL_STATIC_LIBRARIES := \
libutils \
libbase \
libbase \
libpolicy
LOCAL_SRC_FILES := magiskpolicy/main.cpp
LOCAL_SRC_FILES := sepolicy/main.cpp
include $(BUILD_EXECUTABLE)
@ -130,7 +133,8 @@ ifdef B_PROP
include $(CLEAR_VARS)
LOCAL_MODULE := resetprop
LOCAL_STATIC_LIBRARIES := \
libutilx \
libbase \
libcompat \
libnanopb \
libsystemproperties
@ -151,7 +155,7 @@ ifneq (,$(wildcard jni/test.cpp))
include $(CLEAR_VARS)
LOCAL_MODULE := test
LOCAL_STATIC_LIBRARIES := \
libutils \
libbase \
libphmap
LOCAL_SRC_FILES := test.cpp
@ -167,19 +171,19 @@ endif
include $(CLEAR_VARS)
LOCAL_MODULE:= libpolicy
LOCAL_STATIC_LIBRARIES := \
libutils \
libbase \
libsepol
LOCAL_C_INCLUDES := jni/magiskpolicy jni/magiskpolicy/include
LOCAL_EXPORT_C_INCLUDES := jni/magiskpolicy/include
LOCAL_C_INCLUDES := jni/sepolicy/include
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
LOCAL_SRC_FILES := \
magiskpolicy/api.cpp \
magiskpolicy/sepolicy.cpp \
magiskpolicy/rules.cpp \
magiskpolicy/policydb.cpp \
magiskpolicy/statement.cpp
sepolicy/api.cpp \
sepolicy/sepolicy.cpp \
sepolicy/rules.cpp \
sepolicy/policydb.cpp \
sepolicy/statement.cpp
include $(BUILD_STATIC_LIBRARY)
include jni/utils/Android.mk
include jni/base/Android.mk
include jni/external/Android.mk
ifdef B_BB

View File

@ -3,7 +3,7 @@ LOCAL_PATH := $(call my-dir)
# Magisk project-wide common code
include $(CLEAR_VARS)
LOCAL_MODULE:= libutils
LOCAL_MODULE:= libbase
LOCAL_C_INCLUDES := jni/include $(LOCAL_PATH)/include out/generated
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_INCLUDES)
LOCAL_EXPORT_STATIC_LIBRARIES := libcxx
@ -18,15 +18,10 @@ LOCAL_SRC_FILES := \
stream.cpp
include $(BUILD_STATIC_LIBRARY)
# libutils + "hacky" libc.a missing symbols
# To build Magisk with vanilla NDK, simply
# remove compat.cpp from sources, or replace
# all usage of libutilx to libutils
# Workaround "hacky" libc.a missing symbols
# To build Magisk with vanilla NDK, remove all usage of libcompat
include $(CLEAR_VARS)
LOCAL_MODULE:= libutilx
LOCAL_EXPORT_STATIC_LIBRARIES := libutils
LOCAL_STATIC_LIBRARIES := libutils
LOCAL_MODULE:= libcompat
LOCAL_SRC_FILES := compat/compat.cpp
include $(BUILD_STATIC_LIBRARY)

View File

@ -1,9 +1,9 @@
// This file implements all missing symbols that should exist in normal API 21
// libc.a but missing in our extremely lean libc.a replacements.
#include <cstdlib>
#include <cstring>
#include <cerrno>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <mntent.h>
#include <unistd.h>
#include <fcntl.h>

View File

@ -4,14 +4,14 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <logging.hpp>
#undef _FORTIFY_SOURCE
extern int __vloge(const char* fmt, va_list ap);
static inline __noreturn __printflike(1, 2) void __fortify_fatal(const char* fmt, ...) {
va_list args;
va_start(args, fmt);
log_cb.e(fmt, args);
__vloge(fmt, args);
va_end(args);
abort();
}

View File

@ -4,7 +4,7 @@
#include <unistd.h>
#include <libgen.h>
#include <utils.hpp>
#include <base.hpp>
#include <selinux.hpp>
using namespace std;

View File

@ -55,3 +55,8 @@ void LOGD(const char *fmt, ...) {}
void LOGI(const char *fmt, ...) { LOG_BODY(i) }
void LOGW(const char *fmt, ...) { LOG_BODY(w) }
void LOGE(const char *fmt, ...) { LOG_BODY(e); log_cb.ex(EXIT_FAILURE); }
// Export raw symbol to fortify compat
extern "C" int __vloge(const char* fmt, va_list ap) {
return log_cb.e(fmt, ap);
}

View File

@ -9,7 +9,7 @@
#include <random>
#include <string>
#include <utils.hpp>
#include <base.hpp>
using namespace std;

View File

@ -2,7 +2,7 @@
#include <sys/syscall.h>
#include <sys/xattr.h>
#include <utils.hpp>
#include <base.hpp>
#include <selinux.hpp>
using namespace std;

View File

@ -1,7 +1,7 @@
#include <unistd.h>
#include <cstddef>
#include <utils.hpp>
#include <base.hpp>
#include <stream.hpp>
using namespace std;

View File

@ -10,7 +10,7 @@
#include <sys/ptrace.h>
#include <sys/inotify.h>
#include <utils.hpp>
#include <base.hpp>
using namespace std;

View File

@ -4,7 +4,7 @@
#include <libfdt.h>
#include <mincrypt/sha.h>
#include <mincrypt/sha256.h>
#include <utils.hpp>
#include <base.hpp>
#include "bootimg.hpp"
#include "magiskboot.hpp"

View File

@ -10,7 +10,7 @@
#include <zopfli/util.h>
#include <zopfli/deflate.h>
#include <utils.hpp>
#include <base.hpp>
#include "magiskboot.hpp"
#include "compress.hpp"

View File

@ -2,7 +2,7 @@
#include <fcntl.h>
#include <algorithm>
#include <utils.hpp>
#include <base.hpp>
#include "cpio.hpp"

View File

@ -3,7 +3,7 @@
#include <map>
#include <libfdt.h>
#include <utils.hpp>
#include <base.hpp>
#include "magiskboot.hpp"
#include "dtb.hpp"

View File

@ -1,6 +1,6 @@
#include <sys/mman.h>
#include <utils.hpp>
#include <base.hpp>
#include "magiskboot.hpp"

View File

@ -1,5 +1,5 @@
#include <mincrypt/sha.h>
#include <utils.hpp>
#include <base.hpp>
#include "magiskboot.hpp"
#include "compress.hpp"

View File

@ -1,4 +1,4 @@
#include <utils.hpp>
#include <base.hpp>
#include "magiskboot.hpp"

View File

@ -1,4 +1,4 @@
#include <utils.hpp>
#include <base.hpp>
#include "cpio.hpp"
#include "magiskboot.hpp"

View File

@ -1,7 +1,7 @@
#include <sys/stat.h>
#include <magisk.hpp>
#include <utils.hpp>
#include <base.hpp>
int main(int argc, char *argv[]) {
umask(0);

View File

@ -4,7 +4,7 @@
#include <magisk.hpp>
#include <selinux.hpp>
#include <utils.hpp>
#include <base.hpp>
using namespace std;

View File

@ -8,7 +8,7 @@
#include <magisk.hpp>
#include <db.hpp>
#include <utils.hpp>
#include <base.hpp>
#include <daemon.hpp>
#include <resetprop.hpp>
#include <selinux.hpp>

View File

@ -1,4 +1,4 @@
#include <utils.hpp>
#include <base.hpp>
using namespace std;

View File

@ -4,7 +4,7 @@
#include <sys/mount.h>
#include <magisk.hpp>
#include <utils.hpp>
#include <base.hpp>
#include <daemon.hpp>
#include <selinux.hpp>
#include <db.hpp>

View File

@ -5,7 +5,7 @@
#include <magisk.hpp>
#include <db.hpp>
#include <socket.hpp>
#include <utils.hpp>
#include <base.hpp>
#define DB_VERSION 12

View File

@ -2,7 +2,7 @@
#include <android/log.h>
#include <magisk.hpp>
#include <utils.hpp>
#include <base.hpp>
#include <daemon.hpp>
#include <stream.hpp>

View File

@ -1,7 +1,7 @@
#include <sys/mount.h>
#include <libgen.h>
#include <utils.hpp>
#include <base.hpp>
#include <magisk.hpp>
#include <daemon.hpp>
#include <selinux.hpp>

View File

@ -2,7 +2,7 @@
#include <map>
#include <utility>
#include <utils.hpp>
#include <base.hpp>
#include <magisk.hpp>
#include <daemon.hpp>
#include <selinux.hpp>

View File

@ -2,7 +2,7 @@
#include <magisk.hpp>
#include <selinux.hpp>
#include <utils.hpp>
#include <base.hpp>
using namespace std;

View File

@ -3,7 +3,7 @@
#include <sys/wait.h>
#include <magisk.hpp>
#include <utils.hpp>
#include <base.hpp>
#include <selinux.hpp>
#include <daemon.hpp>

View File

@ -2,7 +2,7 @@
#include <endian.h>
#include <socket.hpp>
#include <utils.hpp>
#include <base.hpp>
using namespace std;

View File

@ -1,6 +1,6 @@
// Cached thread pool implementation
#include <utils.hpp>
#include <base.hpp>
#include <daemon.hpp>

View File

@ -5,7 +5,7 @@
#include <fcntl.h>
#include <vector>
#include <utils.hpp>
#include <base.hpp>
#include "init.hpp"

View File

@ -5,7 +5,7 @@
#include <xz.h>
#include <utils.hpp>
#include <base.hpp>
#include <binaries.h>
#if defined(__arm__)

View File

@ -1,4 +1,4 @@
#include <utils.hpp>
#include <base.hpp>
using kv_pairs = std::vector<std::pair<std::string, std::string>>;

View File

@ -2,7 +2,7 @@
#include <sys/sysmacros.h>
#include <libgen.h>
#include <utils.hpp>
#include <base.hpp>
#include <selinux.hpp>
#include <magisk.hpp>

View File

@ -2,7 +2,7 @@
#include <libgen.h>
#include <magisk.hpp>
#include <utils.hpp>
#include <base.hpp>
#include "init.hpp"
#include "magiskrc.inc"

View File

@ -2,7 +2,7 @@
#include <magisk.hpp>
#include <sepolicy.hpp>
#include <utils.hpp>
#include <base.hpp>
#include "init.hpp"

View File

@ -1,7 +1,7 @@
#include <sys/mount.h>
#include <magisk.hpp>
#include <utils.hpp>
#include <base.hpp>
#include <socket.hpp>
#include "init.hpp"

View File

@ -2,9 +2,9 @@
#include <pb_decode.h>
#include <pb_encode.h>
#include <utils.hpp>
#include <base.hpp>
#include "_resetprop.hpp"
#include "prop.hpp"
using namespace std;

View File

@ -4,12 +4,12 @@
#include <map>
#include <resetprop.hpp>
#include <utils.hpp>
#include <base.hpp>
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include <_system_properties.h>
#include "_resetprop.hpp"
#include "prop.hpp"
using namespace std;

View File

@ -1,4 +1,4 @@
#include <utils.hpp>
#include <base.hpp>
#include "policy.hpp"

View File

@ -1,4 +1,4 @@
#include <utils.hpp>
#include <base.hpp>
#include <vector>
#include "policy.hpp"

View File

@ -1,6 +1,6 @@
#pragma once
// libse internal APIs, do not use directly
// Internal APIs, do not use directly
#include <sepol/policydb/policydb.h>
#include <sepolicy.hpp>

View File

@ -5,7 +5,7 @@
#include <cil/cil.h>
#include <utils.hpp>
#include <base.hpp>
#include <stream.hpp>
#include "policy.hpp"

View File

@ -1,4 +1,4 @@
#include <utils.hpp>
#include <base.hpp>
#include "policy.hpp"

View File

@ -1,4 +1,4 @@
#include <utils.hpp>
#include <base.hpp>
#include "policy.hpp"

View File

@ -2,7 +2,7 @@
#include <vector>
#include <string>
#include <utils.hpp>
#include <base.hpp>
#include "policy.hpp"

View File

@ -1,7 +1,7 @@
#include <sys/types.h>
#include <sys/wait.h>
#include <utils.hpp>
#include <base.hpp>
#include <selinux.hpp>
#include "su.hpp"

View File

@ -13,7 +13,7 @@
#include <fcntl.h>
#include <termios.h>
#include <utils.hpp>
#include <base.hpp>
#include "pts.hpp"

View File

@ -15,7 +15,7 @@
#include <magisk.hpp>
#include <daemon.hpp>
#include <utils.hpp>
#include <base.hpp>
#include <flags.h>
#include "su.hpp"

View File

@ -7,7 +7,7 @@
#include <daemon.hpp>
#include <magisk.hpp>
#include <utils.hpp>
#include <base.hpp>
#include <selinux.hpp>
#include <db.hpp>

View File

@ -2,7 +2,7 @@
#include <sys/mount.h>
#include <magisk.hpp>
#include <utils.hpp>
#include <base.hpp>
#include "deny.hpp"

View File

@ -1,7 +1,7 @@
#include <sys/mount.h>
#include <magisk.hpp>
#include <utils.hpp>
#include <base.hpp>
#include "deny.hpp"

View File

@ -7,7 +7,7 @@
#include <set>
#include <magisk.hpp>
#include <utils.hpp>
#include <base.hpp>
#include <db.hpp>
#include "deny.hpp"

View File

@ -4,7 +4,7 @@
#include <android/log.h>
#include <android/dlext.h>
#include <utils.hpp>
#include <base.hpp>
#include <daemon.hpp>
#include <magisk.hpp>
#include <db.hpp>

View File

@ -5,7 +5,7 @@
#include <xhook.h>
#include <utils.hpp>
#include <base.hpp>
#include <flags.h>
#include <daemon.hpp>

View File

@ -3,7 +3,7 @@
#include <dlfcn.h>
#include <magisk.hpp>
#include <utils.hpp>
#include <base.hpp>
#include <socket.hpp>
#include <daemon.hpp>

View File

@ -3,7 +3,7 @@
#include <map>
#include <parallel_hashmap/phmap.h>
#include <utils.hpp>
#include <base.hpp>
namespace jni_hook {

View File

@ -22,7 +22,7 @@
#include <sys/ptrace.h>
#include <sys/wait.h>
#include <utils.hpp>
#include <base.hpp>
#include "zygisk.hpp"
#include "ptrace.hpp"

View File

@ -1,5 +1,5 @@
#include <cinttypes>
#include <utils.hpp>
#include <base.hpp>
#include "zygisk.hpp"