├── Develop ├── README.md └── sample │ ├── java │ ├── netlink │ │ ├── IoUtils.java │ │ ├── NetlinkSocketAddress.java │ │ └── NetlinkClient.java │ └── ReKernel.java │ └── c │ └── main.c ├── .github └── workflows │ └── kernel_builder.yml ├── Integrate ├── rekernel │ ├── Makefile │ ├── Kconfig │ ├── rekernel.h │ └── rekernel.c ├── patches.sh ├── README_CN.md └── README.md ├── LKM-Source ├── Makefile ├── README.md ├── Kconfig ├── rekernel.h └── rekernel.c ├── magisk ├── 5.10 │ ├── update.md │ ├── update.json │ └── update_lite.json ├── 5.15 │ ├── update.md │ ├── update.json │ └── update_lite.json ├── 6.1 │ ├── update.md │ ├── update.json │ └── update_lite.json ├── 6.12 │ ├── update.md │ ├── update.json │ └── update_lite.json └── 6.6 │ ├── update.md │ ├── update.json │ └── update_lite.json ├── Supports ├── README.md ├── Tombstones.md └── Kernels.md ├── README_CN.md ├── README.md └── LICENSE /Develop/README.md: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /.github/workflows/kernel_builder.yml: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /Integrate/rekernel/Makefile: -------------------------------------------------------------------------------- 1 | obj-$(CONFIG_REKERNEL) += rekernel.o 2 | -------------------------------------------------------------------------------- /LKM-Source/Makefile: -------------------------------------------------------------------------------- 1 | obj-m := rekernel.o 2 | ccflags-$(CONFIG_REKERNEL_NETWORK) += -DNETWORK_FILTER -------------------------------------------------------------------------------- /LKM-Source/README.md: -------------------------------------------------------------------------------- 1 | # LKM Source 2 | 3 | This page contains the source code for Re:Kernel LKM 4 | -------------------------------------------------------------------------------- /magisk/5.10/update.md: -------------------------------------------------------------------------------- 1 | 移除消息计数,增加netlink消息处理,支持通过消息移除/proc/rekernel 2 | 用户空间通过消息移除/proc/rekernel,预防被作为特征检测root -------------------------------------------------------------------------------- /magisk/5.15/update.md: -------------------------------------------------------------------------------- 1 | 移除消息计数,增加netlink消息处理,支持通过消息移除/proc/rekernel 2 | 用户空间通过消息移除/proc/rekernel,预防被作为特征检测root -------------------------------------------------------------------------------- /magisk/6.1/update.md: -------------------------------------------------------------------------------- 1 | 移除消息计数,增加netlink消息处理,支持通过消息移除/proc/rekernel 2 | 用户空间通过消息移除/proc/rekernel,预防被作为特征检测root -------------------------------------------------------------------------------- /magisk/6.12/update.md: -------------------------------------------------------------------------------- 1 | 移除消息计数,增加netlink消息处理,支持通过消息移除/proc/rekernel 2 | 用户空间通过消息移除/proc/rekernel,预防被作为特征检测root -------------------------------------------------------------------------------- /magisk/6.6/update.md: -------------------------------------------------------------------------------- 1 | 移除消息计数,增加netlink消息处理,支持通过消息移除/proc/rekernel 2 | 用户空间通过消息移除/proc/rekernel,预防被作为特征检测root -------------------------------------------------------------------------------- /Supports/README.md: -------------------------------------------------------------------------------- 1 | [已受到支持的内核 / Supported kernels](Kernels.md) 2 | 3 | [已受到支持的墓碑 / Supported tombstones](Tombstones.md) 4 | -------------------------------------------------------------------------------- /magisk/6.1/update.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "v8.5", 3 | "versionCode": 85, 4 | "zipUrl": "https://github.com/Sakion-Team/Re-Kernel/releases/download/releases/Re-Kernel-v8.5-6.1.zip", 5 | "changelog": "https://raw.githubusercontent.com/Sakion-Team/Re-Kernel/main/magisk/6.1/update.md" 6 | } 7 | -------------------------------------------------------------------------------- /magisk/6.6/update.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "v8.5", 3 | "versionCode": 85, 4 | "zipUrl": "https://github.com/Sakion-Team/Re-Kernel/releases/download/releases/Re-Kernel-v8.5-6.6.zip", 5 | "changelog": "https://raw.githubusercontent.com/Sakion-Team/Re-Kernel/main/magisk/6.6/update.md" 6 | } 7 | -------------------------------------------------------------------------------- /magisk/5.10/update.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "v8.5", 3 | "versionCode": 85, 4 | "zipUrl": "https://github.com/Sakion-Team/Re-Kernel/releases/download/releases/Re-Kernel-v8.5-5.10.zip", 5 | "changelog": "https://raw.githubusercontent.com/Sakion-Team/Re-Kernel/main/magisk/5.10/update.md" 6 | } 7 | -------------------------------------------------------------------------------- /magisk/5.15/update.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "v8.5", 3 | "versionCode": 85, 4 | "zipUrl": "https://github.com/Sakion-Team/Re-Kernel/releases/download/releases/Re-Kernel-v8.5-5.15.zip", 5 | "changelog": "https://raw.githubusercontent.com/Sakion-Team/Re-Kernel/main/magisk/5.15/update.md" 6 | } 7 | -------------------------------------------------------------------------------- /magisk/6.12/update.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "v8.5", 3 | "versionCode": 85, 4 | "zipUrl": "https://github.com/Sakion-Team/Re-Kernel/releases/download/releases/Re-Kernel-v8.5-6.12.zip", 5 | "changelog": "https://raw.githubusercontent.com/Sakion-Team/Re-Kernel/main/magisk/6.12/update.md" 6 | } 7 | -------------------------------------------------------------------------------- /magisk/6.1/update_lite.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "v8.5", 3 | "versionCode": 85, 4 | "zipUrl": "https://github.com/Sakion-Team/Re-Kernel/releases/download/releases/Re-Kernel-Lite-v8.5-6.1.zip", 5 | "changelog": "https://raw.githubusercontent.com/Sakion-Team/Re-Kernel/main/magisk/6.1/update.md" 6 | } 7 | -------------------------------------------------------------------------------- /magisk/6.6/update_lite.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "v8.5", 3 | "versionCode": 85, 4 | "zipUrl": "https://github.com/Sakion-Team/Re-Kernel/releases/download/releases/Re-Kernel-Lite-v8.5-6.6.zip", 5 | "changelog": "https://raw.githubusercontent.com/Sakion-Team/Re-Kernel/main/magisk/6.6/update.md" 6 | } 7 | -------------------------------------------------------------------------------- /magisk/5.10/update_lite.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "v8.5", 3 | "versionCode": 85, 4 | "zipUrl": "https://github.com/Sakion-Team/Re-Kernel/releases/download/releases/Re-Kernel-Lite-v8.5-5.10.zip", 5 | "changelog": "https://raw.githubusercontent.com/Sakion-Team/Re-Kernel/main/magisk/5.10/update.md" 6 | } 7 | -------------------------------------------------------------------------------- /magisk/5.15/update_lite.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "v8.5", 3 | "versionCode": 85, 4 | "zipUrl": "https://github.com/Sakion-Team/Re-Kernel/releases/download/releases/Re-Kernel-Lite-v8.5-5.15.zip", 5 | "changelog": "https://raw.githubusercontent.com/Sakion-Team/Re-Kernel/main/magisk/5.15/update.md" 6 | } 7 | -------------------------------------------------------------------------------- /magisk/6.12/update_lite.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "v8.5", 3 | "versionCode": 85, 4 | "zipUrl": "https://github.com/Sakion-Team/Re-Kernel/releases/download/releases/Re-Kernel-Lite-v8.5-6.12.zip", 5 | "changelog": "https://raw.githubusercontent.com/Sakion-Team/Re-Kernel/main/magisk/6.12/update.md" 6 | } 7 | -------------------------------------------------------------------------------- /Integrate/rekernel/Kconfig: -------------------------------------------------------------------------------- 1 | menu "Re:Kernel" 2 | 3 | config REKERNEL 4 | bool "Re:Kernel support" 5 | default y 6 | help 7 | Make tombstone users get a better experience. 8 | 9 | config REKERNEL_NETWORK 10 | bool "Re:Kernel NetReceive unfreeze support" 11 | depends on REKERNEL 12 | default n 13 | help 14 | Make tombstone users get a better experience. 15 | endmenu 16 | -------------------------------------------------------------------------------- /LKM-Source/Kconfig: -------------------------------------------------------------------------------- 1 | menu "Re:Kernel" 2 | 3 | config REKERNEL 4 | bool "Re:Kernel module" 5 | depends on MODULES 6 | default n 7 | help 8 | Make tombstone users get a better experience. 9 | Tips: Enabling this will build Re-Kernel as a module 10 | 11 | config REKERNEL_NETWORK 12 | bool "Re:Kernel NetReceive unfreeze support" 13 | depends on REKERNEL 14 | default n 15 | help 16 | Allow ReKernel to listen to network activity then send signal to tombstone. 17 | endmenu 18 | -------------------------------------------------------------------------------- /Supports/Tombstones.md: -------------------------------------------------------------------------------- 1 | ## 已兼容Re:Kernel的墓碑列表 | List of tombstones compatible with Re:Kernel 2 | | Tombstone | Tombstone version | Request Re:Kernel version | Developer | Link | Source code | 3 | | :-: | :-: | :-: | :-: | :-: | :-: | 4 | | Freezer | After Next(250) | ANY | Timeline | [Link](https://docs.sakion.top) | N/A | 5 | | NoActive | After Pro(55) | ANY | myflavor | [Link](https://app.myflv.cn) | N/A | 6 | | FreezeIt | After 3.1 Alpha | 3.0+ | JARK006 | [Link](https://jark006.gitee.io/i/freezeit/) | [Module](https://github.com/jark006/freezeitVS) [Manager](https://github.com/jark006/freezeitapp) | 7 | | Cirno | ANY | ANY | Timeline | [Link](https://github.com/Nep-Timeline/Cirno) | [Module](https://github.com/Nep-Timeline/Cirno) | 8 | -------------------------------------------------------------------------------- /LKM-Source/rekernel.h: -------------------------------------------------------------------------------- 1 | #ifndef REKERNEL_H 2 | #define REKERNEL_H 3 | 4 | // define on your own 5 | // #define KERNEL_5_10 6 | // #define KERNEL_5_15 7 | // #define KERNEL_6_1 8 | // #define KERNEL_6_6 9 | // #define KERNEL_6_12 10 | 11 | // #define NETWORK_FILTER 12 | #define CLEAN_UP_ASYNC_BINDER 13 | 14 | #define MIN_USERAPP_UID (10000) 15 | #define MAX_SYSTEM_UID (2000) 16 | #define SYSTEM_APP_UID (1000) 17 | #define RESERVE_ORDER 17 18 | #define WARN_AHEAD_SPACE (1 << RESERVE_ORDER) 19 | #define INTERFACETOKEN_BUFF_SIZE (140) 20 | #define PARCEL_OFFSET (16) /* sync with the writeInterfaceToken */ 21 | #define LINE_ERROR (-1) 22 | #define LINE_SUCCESS (0) 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /Develop/sample/java/netlink/IoUtils.java: -------------------------------------------------------------------------------- 1 | package nep.timeline.freezer.core.kernel.netlink; 2 | 3 | import java.io.FileDescriptor; 4 | 5 | import de.robv.android.xposed.XposedHelpers; 6 | 7 | public class IoUtils { 8 | public static ClassLoader classLoader; // Assign your own value 9 | 10 | public static void closeQuietly(FileDescriptor fileDescriptor) { 11 | XposedHelpers.callStaticMethod(XposedHelpers.findClass("libcore.io.IoUtils", classLoader), "closeQuietly", fileDescriptor); 12 | } 13 | 14 | public static void setsockoptInt(FileDescriptor fileDescriptor, int level, int option, int value) { 15 | Class libcore = XposedHelpers.findClass("libcore.io.Libcore", classLoader); 16 | Object os = XposedHelpers.getStaticObjectField(libcore, "os"); 17 | XposedHelpers.callMethod(os, "setsockoptInt", fileDescriptor, level, option, value); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /Integrate/rekernel/rekernel.h: -------------------------------------------------------------------------------- 1 | #ifndef __REKERNEL_H 2 | #define __REKERNEL_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | enum report_type { 10 | BINDER, 11 | SIGNAL, 12 | #ifdef CONFIG_REKERNEL_NETWORK 13 | NETWORK, 14 | #endif /* CONFIG_REKERNEL_NETWORK */ 15 | }; 16 | enum binder_type { 17 | REPLY, 18 | TRANSACTION, 19 | OVERFLOW, 20 | }; 21 | 22 | static inline bool jobctl_frozen(struct task_struct* task) { 23 | return ((task->jobctl & JOBCTL_TRAP_FREEZE) != 0); 24 | } 25 | static inline bool frozen_task_group(struct task_struct* task) { 26 | return (jobctl_frozen(task) || cgroup_freezing(task)); 27 | } 28 | 29 | extern void rekernel_report(int reporttype, int type, pid_t src_pid, struct task_struct* src, pid_t dst_pid, struct task_struct* dst, bool oneway, struct binder_transaction_data* tr); 30 | extern void binder_reply_handler(pid_t src_pid, struct task_struct* src, pid_t dst_pid, struct task_struct* dst, bool oneway, struct binder_transaction_data* tr); 31 | extern void binder_trans_handler(pid_t src_pid, struct task_struct* src, pid_t dst_pid, struct task_struct* dst, bool oneway, struct binder_transaction_data* tr); 32 | extern void binder_overflow_handler(pid_t src_pid, struct task_struct* src, pid_t dst_pid, struct task_struct* dst, bool oneway, struct binder_transaction_data* tr); 33 | 34 | #endif /* __REKERNEL_H */ 35 | -------------------------------------------------------------------------------- /README_CN.md: -------------------------------------------------------------------------------- 1 | # Re-Kernel 2 | [![C](https://img.shields.io/badge/language-C-%23f34b7d.svg?style=plastic)](https://en.wikipedia.org/wiki/C_(programming_language)) 3 | [![Android](https://img.shields.io/badge/platform-Android-0078d7.svg?style=plastic)](https://en.wikipedia.org/wiki/Android_(operating_system)) 4 | [![AArch64](https://img.shields.io/badge/arch-AArch64-red.svg?style=plastic)](https://en.wikipedia.org/wiki/AArch64) 5 | 6 | 使墓碑用户获得更好的使用体验。 7 | 8 | ## 许可 9 | 此项目正在使用 [GPL 许可证](LICENSE), 如果需要对此项目进行修改或二次分发,请同样保持开源。 10 | 11 | ## 下载内核 12 | 在 [Re:Kernel已适配机型列表](https://github.com/Sakion-Team/Re-Kernel/tree/main/Supports) 中寻找你设备的内核并下载 13 | 14 | ### 警告 15 | 请确保你对 设备变砖 有所了解 如果你不会救砖 请谨慎使用方法一及方法三! 16 | 17 | 使用方法一时 请确保你身边有电脑 或你的Magisk/KernelSU可以使用救砖功能 否则可能会无法开机! 18 | 19 | 使用方法三时 请确保你身边有电脑 否则可能会无法开机! 20 | 21 | ### 特殊准备 22 | 如果你需要使用Re:Kernel的话 你需要一台已经被Root的设备 目前有三种方法可以安装Re:Kernel到你的设备当中 23 | 24 | #### 方法一: 推荐: Magisk模块(内核版本大于等于5.10) 25 | 刷入Re:Kernel模块到你的设备 这样Re:Kernel将会在每次开机后自动挂载 26 | 27 | #### 方法二: 手动挂载(内核版本大于等于5.10) 28 | 从Re:Kernel模块中提取re-kernel.ko,然后将它放入根目录下的data文件夹 并使用`insmod re-kernel.ko`命令挂载内核模块(重启后失效 也就是说每次开机后都得挂载一遍) 建议使用方法一前 使用此方法确保内核模块不会导致你的设备出现问题! 29 | 30 | #### 方法三: 刷写内核(仅内核版本小于等于5.4) 31 | 从 [Re:Kernel已适配机型列表](https://github.com/Sakion-Team/Re-Kernel/tree/main/Supports) 中寻找你设备的内核 并将手机进入fastboot模式 然后使用`fastboot flash boot `命令或使用其他内核刷写器将内核刷入你的手机 32 | 33 | ## 为墓碑接入Re:Kernel 34 | Re:Kernel内核开放了一个Netlink服务器 允许所有墓碑开发者将其接入自己的墓碑当中 详情请前往仓库的 [Develop](https://github.com/Sakion-Team/Re-Kernel/tree/main/Develop) 文件夹中查看 35 | 36 | ## 为内核提供Re:Kernel支持 37 | 对于内核版本小于等于5.4的用户 我们提供方法让用户可以自行将Re:Kernel代码插入你的设备内核当中 让其内核支持Re:Kernel (查看 [集成](https://github.com/Sakion-Team/Re-Kernel/blob/main/Integrate/README_CN.md)) 但前提是 你必须有能力从你设备的内核源码编译出一个可以开机并且能正常使用的内核 如果内核不开源的话 这几乎是不可能的 38 | 39 | 当然 如果你的内核开源 也可以尝试在 [Issues](https://github.com/Sakion-Team/Re-Kernel/issues) 中创建内核适配请求 开发者可能会为你的内核适配Re:Kernel 40 | 41 | ## Q / A 42 | Q: 这个模块会泄露Root吗? 43 | 44 | A: 不会,内核模块是无法被检测到的 45 | -------------------------------------------------------------------------------- /Develop/sample/java/netlink/NetlinkSocketAddress.java: -------------------------------------------------------------------------------- 1 | package nep.timeline.freezer.core.kernel.netlink; 2 | 3 | import java.net.SocketAddress; 4 | import java.util.Objects; 5 | 6 | import de.robv.android.xposed.XposedHelpers; 7 | 8 | public final class NetlinkSocketAddress extends SocketAddress { 9 | /** 10 | * port ID 11 | * 12 | * @hide 13 | */ 14 | private final int nlPortId; 15 | 16 | /** 17 | * multicast groups mask 18 | * 19 | * @hide 20 | */ 21 | private final int nlGroupsMask; 22 | 23 | /** 24 | * @hide 25 | */ 26 | // VisibleForTesting 27 | public NetlinkSocketAddress() { 28 | this(0, 0); 29 | } 30 | /** 31 | * @hide 32 | */ 33 | // VisibleForTesting 34 | public NetlinkSocketAddress(int nlPortId) { 35 | this(nlPortId, 0); 36 | } 37 | 38 | /** 39 | * Constructs an instance with the given port id and groups mask. 40 | * 41 | * @param nlPortId port id 42 | * @param nlGroupsMask groups mask 43 | * 44 | * @hide 45 | */ 46 | public NetlinkSocketAddress(int nlPortId, int nlGroupsMask) { 47 | this.nlPortId = nlPortId; 48 | this.nlGroupsMask = nlGroupsMask; 49 | } 50 | 51 | /** 52 | * Returns this address's port id. 53 | * 54 | * @return port id 55 | * 56 | * @hide 57 | */ 58 | public int getPortId() { 59 | return nlPortId; 60 | } 61 | 62 | /** 63 | * Returns this address's groups multicast mask. 64 | * 65 | * @return groups mask 66 | * 67 | * @hide 68 | */ 69 | public int getGroupsMask() { 70 | return nlGroupsMask; 71 | } 72 | 73 | /** 74 | * @hide 75 | */ 76 | @Override public String toString() { 77 | return Objects.toString(this); 78 | } 79 | 80 | public Object toInstance() { 81 | return XposedHelpers.newInstance(XposedHelpers.findClass("android.system.NetlinkSocketAddress", IoUtils.classLoader), nlPortId, nlGroupsMask); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Develop/sample/c/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #define PACKET_SIZE 256 9 | #define NETLINK_UNIT 22 10 | #define USER_PORT 100 11 | #define MAX_PLOAD 125 12 | #define MSG_LEN 125 13 | 14 | int main(int argc, char **argv) 15 | { 16 | int skfd; 17 | int ret; 18 | user_msg_info u_info; 19 | socklen_t len; 20 | struct nlmsghdr *nlh = NULL; 21 | struct sockaddr_nl saddr, daddr; 22 | char *umsg = "Hello! Re:Kernel!"; 23 | 24 | skfd = socket(AF_NETLINK, SOCK_RAW, NETLINK_UNIT); 25 | if (skfd == -1) 26 | { 27 | perror("Create connection error\n"); 28 | return -1; 29 | } 30 | 31 | memset(&saddr, 0, sizeof(saddr)); 32 | saddr.nl_family = AF_NETLINK; 33 | saddr.nl_pid = USER_PORT; 34 | saddr.nl_groups = 0; 35 | if (bind(skfd, (struct sockaddr *)&saddr, sizeof(saddr)) != 0) 36 | { 37 | perror("Failed bind to connection\n"); 38 | close(skfd); 39 | return -1; 40 | } 41 | 42 | memset(&daddr, 0, sizeof(daddr)); 43 | daddr.nl_family = AF_NETLINK; 44 | daddr.nl_pid = 0; 45 | daddr.nl_groups = 0; 46 | 47 | nlh = (struct nlmsghdr *)malloc(NLMSG_SPACE(MAX_PLOAD)); 48 | memset(nlh, 0, sizeof(struct nlmsghdr)); 49 | nlh->nlmsg_len = NLMSG_SPACE(MAX_PLOAD); 50 | nlh->nlmsg_flags = 0; 51 | nlh->nlmsg_type = 0; 52 | nlh->nlmsg_seq = 0; 53 | nlh->nlmsg_pid = saddr.nl_pid; 54 | 55 | memcpy(NLMSG_DATA(nlh), umsg, strlen(umsg)); 56 | printf("Send msg to kernel:%s\n", umsg); 57 | ret = sendto(skfd, nlh, nlh->nlmsg_len, 0, (struct sockaddr *)&daddr, sizeof(struct sockaddr_nl)); 58 | if (!ret) { 59 | perror("Failed send msg to kernel!\n"); 60 | close(skfd); 61 | return -1; 62 | } 63 | 64 | while (1) { 65 | memset(&u_info, 0, sizeof(u_info)); 66 | len = sizeof(struct sockaddr_nl); 67 | ret = recvfrom(skfd, &u_info, sizeof(user_msg_info), 0, (struct sockaddr *)&daddr, &len); 68 | if (!ret) { 69 | perror("Failed recv msg from kernel!\n"); 70 | close(skfd); 71 | return -1; 72 | } 73 | 74 | printf("Message from kernel:%s\n", u_info.msg); 75 | } 76 | 77 | close(skfd); 78 | free((void *)nlh); 79 | return 0; 80 | } 81 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Re-Kernel 2 | [![C](https://img.shields.io/badge/language-C-%23f34b7d.svg?style=plastic)](https://en.wikipedia.org/wiki/C_(programming_language)) 3 | [![Android](https://img.shields.io/badge/platform-Android-0078d7.svg?style=plastic)](https://en.wikipedia.org/wiki/Android_(operating_system)) 4 | 5 | Make tombstone users get a better experience. ([简体中文](README_CN.md)) 6 | 7 | ## License 8 | This project is using a [GPL License](LICENSE), If you need to modify or redistribute this project, please also keep it open source. 9 | 10 | ## Downloading 11 | Find your device kernel from the [list of supported devices](https://github.com/Sakion-Team/Re-Kernel/tree/main/Supports), and download it. 12 | 13 | ### Warning 14 | If you cannot to recover the device after it bootloop, please use methods 1 and 3 with caution! 15 | 16 | When using method 1, Please make sure you have a computer or your Magisk/KernelSU that can use the rescue function, otherwise it may bootlooppppp! 17 | 18 | When using method 3, please make sure you have a computer nearby, otherwise it may bootlooppppp! 19 | 20 | ### Prerequisites 21 | If you need to use Re: Kernel, you need a device that has already been rooted. There are currently three ways to install Re:Kernel into your device. 22 | 23 | #### Method 1: Recommendation: Magisk Module(Need your kernel version >= 5.10) 24 | Flash in the Re:Kernel module to your device so that Re:Kernel will automatically mount after each boot up. 25 | 26 | #### Method 2: Manual mounting(Need your kernel version >= 5.10) 27 | Get re-kernel.ko from magisk module, then place it in the data folder in the root directory and use the `insmod re-kernel.ko` command to mount the kernel module (it will stop working after rebooting, which means it needs to be mounted again every time it when your device boot) Suggest using this method first to ensure that the kernel module does not cause problems with your device! 28 | 29 | ### Method 3: Flashing Kernel(Only your kernel version <= 5.4) 30 | Find your device kernel from the [list of supported devices](https://github.com/Sakion-Team/Re-Kernel/tree/main/Supports), and enter the fastboot mode of the phone, then use the `fastboot flash boot ` command or use another kernel flasher to flash the kernel into your phone. 31 | 32 | ## Connecting the tombstone to Re:Kernel 33 | Re:Kernel has opened a Netlink server that allows all tombstone developers to integrate it into their own tombstones. For details, please go to the [Develop](https://github.com/Sakion-Team/Re-Kernel/tree/main/Develop) folder in the repository to view. 34 | 35 | ## Integrate Re:Kernel for non GKI or QGKI kernels 36 | For users with kernel versions less than or equal to 5.4, we provide a method for users to insert Re:Kernel code into their device's kernel to support Re:Kernel (Check [Integrate](https://github.com/Sakion-Team/Re-Kernel/blob/main/Integrate/README.md)). However, you should be able to build a bootable kernel from your kernel source code. If the kernel is not open source, this is almost impossible. 37 | 38 | ## Q / A 39 | Q: Will this module leak Root? 40 | 41 | A: No, the kernel module cannot be detected. 42 | -------------------------------------------------------------------------------- /Supports/Kernels.md: -------------------------------------------------------------------------------- 1 | ## 由咲音团队编译的内核文件 | Kernel files compiled by Sakion Team 2 | | Device | Kernel android version | Kernel version | Re:Kernel version | Link | Source code | Binder | Signal | 3 | | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | 4 | | GKI | VANILLA_ICE_CREAM | 6.6.x | 7.5 | [Download](https://github.com/Sakion-Team/Re-Kernel/releases/tag/releases) | [Link](https://github.com/Sakion-Team/Re-Kernel/tree/main/LKM-Source) | ✔ | ✔ | 5 | | GKI | UPSIDE_DOWN_CAKE | 6.1.x | 7.5 | [Download](https://github.com/Sakion-Team/Re-Kernel/releases/tag/releases) | [Link](https://github.com/Sakion-Team/Re-Kernel/tree/main/LKM-Source) | ✔ | ✔ | 6 | | GKI | TIRAMISU | 5.15.x | 7.5 | [Download](https://github.com/Sakion-Team/Re-Kernel/releases/tag/releases) | [Link](https://github.com/Sakion-Team/Re-Kernel/tree/main/LKM-Source) | ✔ | ✔ | 7 | | GKI | Android S | 5.10.x | 7.5 | [Download](https://github.com/Sakion-Team/Re-Kernel/releases/tag/releases) | [Link](https://github.com/Sakion-Team/Re-Kernel/tree/main/LKM-Source) | ✔ | ✔ | 8 | ## 由第三方开发者编译的内核文件 | Kernel files compiled by third-party developers 9 | ### 警告: 内核被收录并不代表内核源代码受到咲音团队审查,出现任何问题由用户自行承担。 10 | ### WARNING: The inclusion of the kernel does not mean that the kernel source code has been reviewed by the Sakion Team, any issues arising shall be borne by the user. 11 | | Device | Kernel android version | Kernel version | Re:Kernel version | Link | Source code | Binder | Signal | 12 | | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | 13 | | Kernel Patch | N/A | 4.4-6.1 | 7.5 | [Download](https://github.com/lzghzr/APatch_kpm/releases/download/2024081800/re_kernel_6.0.10_network.kpm) | [Link](https://github.com/lzghzr/APatch_kpm/tree/main/re_kernel) | ✔ | ✔ | 14 | 15 | ## 内核兼容性追踪 | Kernel compatibility tracking 16 | (✘) - 可能永远不会兼容 | Maybe never be compatible 17 | 18 | (?) - 未知 | Unknown 19 | 20 | (✔) - 兼容 | Compatible 21 | | Device | Kernel android version | Kernel | Kernel version | Developer | Compatibility | Link | Kernel source code | 22 | | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | 23 | | GKI | VANILLA_ICE_CREAM | ETO | 6.6.x | [ETO-妖刀](http://www.coolapk.com/u/2749672) | (✔) | N/A | N/A | 24 | | GKI | UPSIDE_DOWN_CAKE | ETO | 6.1.x | [ETO-妖刀](http://www.coolapk.com/u/2749672) | (✔) | N/A | N/A | 25 | | GKI | TIRAMISU | ETO | 5.15.x | [ETO-妖刀](http://www.coolapk.com/u/2749672) | (✔) | N/A | N/A | 26 | | GKI | Android S | ETO | 5.10.x | [ETO-妖刀](http://www.coolapk.com/u/2749672) | (✔) | N/A | N/A | 27 | | GKI | Android S | Marisa | 5.10.x | [Laulan56](https://github.com/Laulan56) | (✓) VER ≥ R5 | [Link](https://gitea.com/Laulan56/MarisaKernel_Marble-release) | N/A | 28 | | GKI | Android S | Pixel Kernel | 5.10.x | Google Team | (✘) | N/A | N/A | 29 | | GKI | Android S | VIVO Kernel | 5.10.x - 6.6.x | VIVO TEAM | (✘) | N/A | N/A | 30 | | GKI | Android S | HarmonyOS Kernel | 5.10.x | HUAWEI TEAM | (✘) | N/A | N/A | 31 | | GKI | TIRAMISU | ZTC | 5.15.x | [ztc1997](https://github.com/ztc1997) | (✔) | N/A | [Link](https://github.com/ztc1997/android_gki_kernel_5.15_common) | 32 | | GKI | Android S | ZTC | 5.10.x | [ztc1997](https://github.com/ztc1997) | (✔) | N/A | [Link](https://github.com/ztc1997/android_gki_kernel_5.10_common) | 33 | | GKI | VANILLA_ICE_CREAM | Haruhi | 6.6.x | [hamjin](https://github.com/hamjin) | (✔) | [Link](https://t.me/pandora_kernel_release) | N/A | 34 | | GKI | UPSIDE_DOWN_CAKE | AngelBeats | 6.1.x | [hamjin](https://github.com/hamjin) | (✔) | [Link](https://t.me/pandora_kernel_release) | N/A | 35 | | GKI | TIRAMISU | Yuni | 5.15.x | [hamjin](https://github.com/hamjin) | (✔) | [Link](https://t.me/pandora_kernel_release) | N/A | 36 | | GKI | Android S | Pandora | 5.10.x | [hamjin](https://github.com/hamjin) | (✔) VER > 24.03.30 | [Link](https://t.me/pandora_kernel_release) | N/A | 37 | | GKI | UPSIDE_DOWN_CAKE | Voyager | 6.1.x | [The Voyager](https://github.com/TheVoyager0777) | (✔) | N/A | N/A | 38 | | GKI | TIRAMISU | Voyager | 5.15.x | [The Voyager](https://github.com/TheVoyager0777) | (✔) | N/A | N/A | 39 | | GKI | Android S | Voyager | 5.10.x | [The Voyager](https://github.com/TheVoyager0777) | (✔) | N/A | N/A | 40 | | ONLY XIAOMI/REDMI | N/A | Voyager | 4.x | [The Voyager](https://github.com/TheVoyager0777) | (✔) | N/A | N/A | 41 | 42 | 如果你的GKI内核与Re-Kernel不兼容 说明开发者对内核进行了破坏性修改 43 | 44 | 若你正在使用与Re-Kernel不兼容的GKI内核 你应当与内核开发者进行联系 而不是Re-Kernel开发者 或者使用官方内核而不是第三方内核 45 | -------------------------------------------------------------------------------- /Develop/sample/java/netlink/NetlinkClient.java: -------------------------------------------------------------------------------- 1 | package nep.timeline.freezer.core.kernel.netlink; 2 | 3 | import android.system.ErrnoException; 4 | import android.system.Os; 5 | import android.system.OsConstants; 6 | import android.system.StructTimeval; 7 | 8 | import java.io.Closeable; 9 | import java.io.FileDescriptor; 10 | import java.io.InterruptedIOException; 11 | import java.net.SocketAddress; 12 | import java.net.SocketException; 13 | import java.nio.ByteBuffer; 14 | import java.nio.ByteOrder; 15 | 16 | import nep.timeline.freezer.core.log.Log; 17 | 18 | public class NetlinkClient implements Closeable { 19 | private static final String TAG = "NetlinkSocket"; 20 | private static final int SOCKET_RECV_BUFSIZE = 64 * 1024; 21 | private static final int DEFAULT_RECV_BUFSIZE = 8 * 1024; 22 | final private FileDescriptor mDescriptor; 23 | private NetlinkSocketAddress mAddr; 24 | private long mLastRecvTimeoutMs; 25 | private long mLastSendTimeoutMs; 26 | 27 | public FileDescriptor getmDescriptor() { 28 | return mDescriptor; 29 | } 30 | 31 | public NetlinkClient(int nlProto) throws ErrnoException { 32 | mDescriptor = Os.socket( 33 | OsConstants.AF_NETLINK, OsConstants.SOCK_DGRAM, nlProto); 34 | IoUtils.setsockoptInt( 35 | mDescriptor, OsConstants.SOL_SOCKET, 36 | OsConstants.SO_RCVBUF, SOCKET_RECV_BUFSIZE); 37 | } 38 | 39 | public NetlinkSocketAddress getLocalAddress() throws ErrnoException { 40 | return (NetlinkSocketAddress) Os.getsockname(mDescriptor); 41 | } 42 | public void bind(NetlinkSocketAddress localAddr) throws ErrnoException, SocketException { 43 | Os.bind(mDescriptor, localAddr); 44 | } 45 | public void bind(SocketAddress localAddr) throws ErrnoException, SocketException { 46 | Os.bind(mDescriptor, localAddr); 47 | } 48 | public void connectTo(NetlinkSocketAddress peerAddr) 49 | throws ErrnoException, SocketException { 50 | Os.connect(mDescriptor, peerAddr); 51 | } 52 | public void connectToKernel() throws ErrnoException, SocketException { 53 | connectTo(new NetlinkSocketAddress(0, 0)); 54 | } 55 | /** 56 | * Wait indefinitely (or until underlying socket error) for a 57 | * netlink message of at most DEFAULT_RECV_BUFSIZE size. 58 | */ 59 | public ByteBuffer recvMessage() 60 | throws ErrnoException, InterruptedIOException { 61 | return recvMessage(DEFAULT_RECV_BUFSIZE, 0); 62 | } 63 | /** 64 | * Wait up to |timeoutMs| (or until underlying socket error) for a 65 | * netlink message of at most DEFAULT_RECV_BUFSIZE size. 66 | */ 67 | public ByteBuffer recvMessage(long timeoutMs) throws ErrnoException, InterruptedIOException { 68 | return recvMessage(DEFAULT_RECV_BUFSIZE, timeoutMs); 69 | } 70 | private void checkTimeout(long timeoutMs) { 71 | if (timeoutMs < 0) { 72 | throw new IllegalArgumentException("Negative timeouts not permitted"); 73 | } 74 | } 75 | /** 76 | * Wait up to |timeoutMs| (or until underlying socket error) for a 77 | * netlink message of at most |bufsize| size. 78 | * 79 | * Multi-threaded calls with different timeouts will cause unexpected results. 80 | */ 81 | public ByteBuffer recvMessage(int bufsize, long timeoutMs) 82 | throws ErrnoException, IllegalArgumentException, InterruptedIOException { 83 | checkTimeout(timeoutMs); 84 | synchronized (mDescriptor) { 85 | if (mLastRecvTimeoutMs != timeoutMs) { 86 | Os.setsockoptTimeval(mDescriptor, 87 | OsConstants.SOL_SOCKET, OsConstants.SO_RCVTIMEO, 88 | StructTimeval.fromMillis(timeoutMs)); 89 | mLastRecvTimeoutMs = timeoutMs; 90 | } 91 | } 92 | ByteBuffer byteBuffer = ByteBuffer.allocate(bufsize); 93 | int length = Os.read(mDescriptor, byteBuffer); 94 | if (length == bufsize) { 95 | Log.w("maximum read"); 96 | } 97 | byteBuffer.position(0); 98 | byteBuffer.limit(length); 99 | byteBuffer.order(ByteOrder.nativeOrder()); 100 | return byteBuffer; 101 | } 102 | 103 | /** 104 | * Send a message to a peer to which this socket has previously connected. 105 | * 106 | * This blocks until completion or an error occurs. 107 | */ 108 | public boolean sendMessage(byte[] bytes, int offset, int count) 109 | throws ErrnoException, InterruptedIOException { 110 | return sendMessage(bytes, offset, count, 0); 111 | } 112 | /** 113 | * Send a message to a peer to which this socket has previously connected, 114 | * waiting at most |timeoutMs| milliseconds for the send to complete. 115 | * 116 | * Multi-threaded calls with different timeouts will cause unexpected results. 117 | */ 118 | public boolean sendMessage(byte[] bytes, int offset, int count, long timeoutMs) 119 | throws ErrnoException, IllegalArgumentException, InterruptedIOException { 120 | checkTimeout(timeoutMs); 121 | synchronized (mDescriptor) { 122 | if (mLastSendTimeoutMs != timeoutMs) { 123 | Os.setsockoptTimeval(mDescriptor, 124 | OsConstants.SOL_SOCKET, OsConstants.SO_SNDTIMEO, 125 | StructTimeval.fromMillis(timeoutMs)); 126 | mLastSendTimeoutMs = timeoutMs; 127 | } 128 | } 129 | return (count == Os.write(mDescriptor, bytes, offset, count)); 130 | } 131 | 132 | @Override 133 | public void close() { 134 | IoUtils.closeQuietly(mDescriptor); 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /Develop/sample/java/ReKernel.java: -------------------------------------------------------------------------------- 1 | public class ReKernel { 2 | private static boolean isRunning = false; 3 | private static final int NETLINK_UNIT_DEFAULT = 22; 4 | private static final int NETLINK_UNIT_MAX = 26; 5 | private static final Handler rekernel = new Handler(new HandlerThread("ReKernel").getLooper()); 6 | private static final ExecutorService executorService = Executors.newSingleThreadExecutor(); 7 | 8 | private static Map parseParams(String message) { 9 | Map map = new HashMap<>(); 10 | for (String keyValue : message.split(",")) { 11 | String[] split = keyValue.split("="); 12 | if (split.length == 2) 13 | map.put(split[0].trim(), split[1].trim()); 14 | } 15 | return map; 16 | } 17 | 18 | private static int StringToInteger(String str) { 19 | String data = str.trim(); 20 | StringBuilder result = new StringBuilder(); 21 | for (int i = 0; i < data.length(); i++) { 22 | char c = data.charAt(i); 23 | if (Character.isDigit(c)) 24 | result.append(c); 25 | } 26 | 27 | try { 28 | return Integer.parseInt(result.toString()); 29 | } catch (NumberFormatException ignored) { 30 | return -1; 31 | } 32 | } 33 | 34 | public static void start() { 35 | if (isRunning) 36 | return; 37 | 38 | executorService.execute(() -> { 39 | try { 40 | int netlinkUnit; 41 | int configNetlinkUnit = Settings.netlinkUnit; 42 | if (configNetlinkUnit >= NETLINK_UNIT_DEFAULT && configNetlinkUnit <= NETLINK_UNIT_MAX) { 43 | netlinkUnit = configNetlinkUnit; 44 | } else { 45 | File dir = new File("/proc/rekernel"); 46 | if (dir.exists()) { 47 | File[] files = dir.listFiles(); 48 | if (files == null) { 49 | // 找不到ReKernel单元 50 | return; 51 | } 52 | File unitFile = files[0]; 53 | netlinkUnit = StringToInteger(unitFile.getName()); 54 | } else netlinkUnit = NETLINK_UNIT_DEFAULT; 55 | } 56 | 57 | try (NetlinkClient netlinkClient = new NetlinkClient(netlinkUnit)) { 58 | if (!netlinkClient.getMDescriptor().valid()) { 59 | // 连接失败 60 | return; 61 | } 62 | 63 | netlinkClient.bind((SocketAddress) new NetlinkSocketAddress(100).toInstance()); 64 | 65 | isRunning = true; 66 | 67 | // 连接成功 68 | 69 | while (true) { 70 | try { 71 | ByteBuffer byteBuffer = netlinkClient.recvMessage(); 72 | String data = new String(byteBuffer.array(), byteBuffer.position(), byteBuffer.limit(), StandardCharsets.UTF_8); 73 | if (!data.isEmpty()) { 74 | Map params = parseParams(data.substring(data.indexOf("type"), data.lastIndexOf(";"))); 75 | rekernel.post(() -> { 76 | String type = params.get("type"); 77 | if (type.equals("Binder")) { 78 | String bindertype = params.get("bindertype"); 79 | int oneway = StringToInteger(params.get("oneway")); 80 | int fromPid = StringToInteger(params.get("from_pid")); 81 | int fromUid = StringToInteger(params.get("from")); 82 | int targetPid = StringToInteger(params.get("target_pid")); 83 | int targetUid = StringToInteger(params.get("target")); 84 | int rpcName = params.get("rpc_name"); 85 | int code = StringToInteger(params.get("code")); 86 | // 你的代码 87 | } else if (type.equals("Signal")) { 88 | int targetPid = StringToInteger(params.get("dst_pid")); 89 | int targetUid = StringToInteger(params.get("dst")); 90 | int killerPid = StringToInteger(params.get("killer_pid")); 91 | int killerUid = StringToInteger(params.get("killer")); 92 | int signal = StringToInteger(params.get("signal")); 93 | // 你的代码 94 | } else if (type.equals("Network")) { 95 | int targetUid = StringToInteger(params.get("target")); 96 | String proto = params.get("proto"); 97 | // 你的代码 98 | } 99 | }); 100 | } 101 | } catch (ErrnoException | InterruptedIOException | NumberFormatException ignored) { 102 | 103 | } catch (Exception e) { 104 | // 出现异常 105 | } 106 | } 107 | } 108 | } catch (ErrnoException | IOException e) { 109 | // 无法连接至ReKernel服务器 110 | } catch (Throwable ignored) { 111 | 112 | } 113 | }); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /Integrate/patches.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PATCHDIR=${0%/*} 4 | 5 | [ -d drivers/rekernel ] || mkdir -p drivers/rekernel 6 | cp -rp $PATCHDIR/rekernel/* drivers/rekernel/ 7 | 8 | rekernel_file=drivers/rekernel/rekernel.c 9 | if grep -q 'struct proc_ops' include/linux/proc_fs.h; then 10 | sed -i 's/file_operations/proc_ops/' $rekernel_file 11 | sed -i 's/\.open/\.proc_open/' $rekernel_file 12 | sed -i 's/\.read/\.proc_read/' $rekernel_file 13 | sed -i 's/\.llseek/\.proc_lseek/' $rekernel_file 14 | sed -i 's/\.release/\.proc_release/' $rekernel_file 15 | fi 16 | 17 | patch_files=( 18 | arch/arm64/configs/defconfig 19 | drivers/Kconfig 20 | drivers/Makefile 21 | drivers/android/binder.c 22 | kernel/signal.c 23 | ) 24 | for i in "${patch_files[@]}"; do 25 | 26 | if grep -iq "rekernel" $i; then 27 | echo "Warning: $i contains Re:Kernel" 28 | continue 29 | fi 30 | 31 | case $i in 32 | # Makefile 33 | arch/arm64/configs/defconfig) 34 | sed -i '$a\ 35 | CONFIG_REKERNEL=y\ 36 | CONFIG_REKERNEL_NETWORK=n' $i 37 | ;; 38 | drivers/Kconfig) 39 | sed -i '/endmenu/i\ 40 | \ 41 | source "drivers/rekernel/Kconfig"' $i 42 | ;; 43 | drivers/Makefile) 44 | sed -i '$a\ 45 | obj-$(CONFIG_REKERNEL) += rekernel/' $i 46 | ;; 47 | 48 | # binder.c 49 | drivers/android/binder.c) 50 | if ! grep -q 'binder_proc_transaction() - sends a transaction to a process and wakes it up' $i; then 51 | echo "Error: Could not find 'binder_proc_transaction()' in $i" 52 | continue 53 | fi 54 | if ! grep -q 'binder_enqueue_work_ilocked(&t->work, &proc->todo)' $i; then 55 | echo "Error: Could not find 'binder_enqueue_work_ilocked(&t->work, &proc->todo);' in $i" 56 | continue 57 | fi 58 | sed -i '/#include /i\ 59 | #ifdef CONFIG_REKERNEL\ 60 | #include <../rekernel/rekernel.h>\ 61 | #endif /* CONFIG_REKERNEL */' $i 62 | 63 | if grep -q 'binder_find_outdated_transaction_ilocked' $i; then 64 | sed -i '/if ((t1->flags & t2->flags & (TF_ONE_WAY | TF_UPDATE_TXN)) !=/i\ 65 | #ifdef CONFIG_REKERNEL\ 66 | if ((t1->flags & t2->flags & TF_ONE_WAY) != TF_ONE_WAY || !t1->to_proc || !t2->to_proc)\ 67 | #else' $i 68 | sed -i '/(TF_ONE_WAY | TF_UPDATE_TXN) || !t1->to_proc || !t2->to_proc)/a\ 69 | #endif /* CONFIG_REKERNEL */' $i 70 | 71 | sed -i '/if ((t->flags & TF_UPDATE_TXN) && proc->is_frozen) {/i\ 72 | #ifdef CONFIG_REKERNEL\ 73 | if (frozen_task_group(proc->tsk)) {\ 74 | #else' $i 75 | sed -i '/if ((t->flags & TF_UPDATE_TXN) && proc->is_frozen) {/a\ 76 | #endif /* CONFIG_REKERNEL */' $i 77 | else 78 | binder_proc_transaction_line=$(awk '/binder_proc_transaction\(\) - sends a transaction to a process and wakes it up/{print NR}' $i) 79 | sed -i ''"$((binder_proc_transaction_line - 1))"'i\ 80 | #ifdef CONFIG_REKERNEL\ 81 | /**\ 82 | * binder_can_update_transaction() - Can a txn be superseded by an updated one?\ 83 | * @t1: the pending async txn in the frozen process\ 84 | * @t2: the new async txn to supersede the outdated pending one\ 85 | *\ 86 | * Return: true if t2 can supersede t1\ 87 | * false if t2 can not supersede t1\ 88 | */\ 89 | static bool binder_can_update_transaction(struct binder_transaction *t1,\ 90 | struct binder_transaction *t2)\ 91 | {\ 92 | if ((t1->flags & t2->flags & TF_ONE_WAY) != TF_ONE_WAY || !t1->to_proc || !t2->to_proc)\ 93 | return false;\ 94 | if (t1->to_proc->tsk == t2->to_proc->tsk && t1->code == t2->code &&\ 95 | t1->flags == t2->flags && t1->buffer->pid == t2->buffer->pid &&\ 96 | t1->buffer->target_node->ptr == t2->buffer->target_node->ptr &&\ 97 | t1->buffer->target_node->cookie == t2->buffer->target_node->cookie)\ 98 | return true;\ 99 | return false;\ 100 | }\ 101 | \ 102 | /**\ 103 | * binder_find_outdated_transaction_ilocked() - Find the outdated transaction\ 104 | * @t: new async transaction\ 105 | * @target_list: list to find outdated transaction\ 106 | *\ 107 | * Return: the outdated transaction if found\ 108 | * NULL if no outdated transacton can be found\ 109 | *\ 110 | * Requires the proc->inner_lock to be held.\ 111 | */\ 112 | static struct binder_transaction *\ 113 | binder_find_outdated_transaction_ilocked(struct binder_transaction *t,\ 114 | struct list_head *target_list)\ 115 | {\ 116 | struct binder_work *w;\ 117 | \ 118 | list_for_each_entry(w, target_list, entry) {\ 119 | struct binder_transaction *t_queued;\ 120 | \ 121 | if (w->type != BINDER_WORK_TRANSACTION)\ 122 | continue;\ 123 | t_queued = container_of(w, struct binder_transaction, work);\ 124 | if (binder_can_update_transaction(t_queued, t))\ 125 | return t_queued;\ 126 | }\ 127 | return NULL;\ 128 | }\ 129 | #endif /* CONFIG_REKERNEL */\ 130 | ' $i 131 | if ! grep -q 'pid to attribute the buffer to (caller)' drivers/android/binder_alloc.h; then 132 | sed -i 's/t1->flags == t2->flags && t1->buffer->pid == t2->buffer->pid &&/t1->flags == t2->flags \&\&/' $i 133 | fi 134 | 135 | sed -i '/bool pending_async = false;/a\ 136 | #ifdef CONFIG_REKERNEL\ 137 | struct binder_transaction *t_outdated = NULL;\ 138 | #endif /* CONFIG_REKERNEL */' $i 139 | 140 | binder_enqueue_work_ilocked_line=$(awk '/binder_enqueue_work_ilocked\(&t->work, &proc->todo\);/{print NR}' $i) 141 | sed -i ''"$((binder_enqueue_work_ilocked_line + 1))"'a\ 142 | #ifdef CONFIG_REKERNEL\ 143 | if (frozen_task_group(proc->tsk)) {\ 144 | t_outdated = binder_find_outdated_transaction_ilocked(t,\ 145 | &node->async_todo);\ 146 | if (t_outdated) {\ 147 | list_del_init(&t_outdated->work.entry);\ 148 | proc->outstanding_txns--;\ 149 | }\ 150 | }\ 151 | #endif /* CONFIG_REKERNEL */' $i 152 | if ! grep -q 'proc->outstanding_txns++;' $i; then 153 | sed -i '/proc->outstanding_txns--;/d' $i 154 | fi 155 | 156 | binder_enqueue_work_ilocked_line=$(awk '/binder_enqueue_work_ilocked\(&t->work, &proc->todo\);/{print NR}' $i) 157 | binder_node_unlock_line=$(awk 'NR >= '"$binder_enqueue_work_ilocked_line"' && /binder_node_unlock\(node\);/{print NR; exit}' $i) 158 | sed -i ''"$binder_node_unlock_line"'a\ 159 | \ 160 | #ifdef CONFIG_REKERNEL\ 161 | /*\ 162 | * To reduce potential contention, free the outdated transaction and\ 163 | * buffer after releasing the locks.\ 164 | */\ 165 | if (t_outdated) {\ 166 | struct binder_buffer *buffer = t_outdated->buffer;\ 167 | \ 168 | t_outdated->buffer = NULL;\ 169 | buffer->transaction = NULL;\ 170 | binder_release_entire_buffer(proc, NULL, buffer, false);\ 171 | binder_alloc_free_buf(&proc->alloc, buffer);\ 172 | kfree(t_outdated);\ 173 | binder_stats_deleted(BINDER_STAT_TRANSACTION);\ 174 | }\ 175 | #endif /* CONFIG_REKERNEL */' $i 176 | if ! grep -q 'static inline void binder_release_entire_buffer' $i; then 177 | if grep -q 'binder_transaction_buffer_release(proc, buffer, 0, false);' $i; then 178 | sed -i 's/binder_release_entire_buffer(proc, NULL, buffer, false);/binder_transaction_buffer_release(proc, buffer, 0, false);/' $i 179 | elif grep -q 'binder_transaction_buffer_release(proc, buffer, NULL);' $i; then 180 | sed -i 's/binder_release_entire_buffer(proc, NULL, buffer, false);/binder_transaction_buffer_release(proc, buffer, NULL);/' $i 181 | else 182 | echo "Error: Could not find 'binder_transaction_buffer_release' in $i" 183 | fi 184 | fi 185 | fi 186 | 187 | binder_proc_transaction_line=$(awk '/binder_proc_transaction\(\) - sends a transaction to a process and wakes it up/{print NR}' $i) 188 | sed -i ''"$((binder_proc_transaction_line - 1))"'i\ 189 | #ifdef CONFIG_REKERNEL\ 190 | void rekernel_binder_transaction(bool reply, struct binder_transaction *t,\ 191 | struct binder_node *target_node, struct binder_transaction_data *tr) {\ 192 | struct binder_proc *to_proc;\ 193 | struct binder_alloc *target_alloc;\ 194 | if (!t->to_proc)\ 195 | return;\ 196 | to_proc = t->to_proc;\ 197 | \ 198 | if (reply) {\ 199 | binder_reply_handler(task_tgid_nr(current), current, to_proc->pid, to_proc->tsk, false, tr);\ 200 | } else if (t->from) {\ 201 | if (t->from->proc) {\ 202 | binder_trans_handler(t->from->proc->pid, t->from->proc->tsk, to_proc->pid, to_proc->tsk, false, tr);\ 203 | }\ 204 | } else { // oneway=1\ 205 | binder_trans_handler(task_tgid_nr(current), current, to_proc->pid, to_proc->tsk, true, tr);\ 206 | \ 207 | target_alloc = &to_proc->alloc;\ 208 | if (target_alloc->free_async_space < (target_alloc->buffer_size / 10 + 0x300)) {\ 209 | binder_overflow_handler(task_tgid_nr(current), current, to_proc->pid, to_proc->tsk, true, tr);\ 210 | }\ 211 | }\ 212 | }\ 213 | #endif /* CONFIG_REKERNEL */\ 214 | ' $i 215 | sed -i '/trace_binder_transaction(reply, t, target_node);/i\ 216 | #ifdef CONFIG_REKERNEL\ 217 | rekernel_binder_transaction(reply, t, target_node, tr);\ 218 | #endif /* CONFIG_REKERNEL */' $i 219 | ;; 220 | 221 | # signal.c 222 | kernel/signal.c) 223 | sed -i '/#include /a\ 224 | #ifdef CONFIG_REKERNEL\ 225 | #include \ 226 | #include <../drivers/rekernel/rekernel.h>\ 227 | #endif /* CONFIG_REKERNEL */' $i 228 | 229 | sed -i '/int ret = -ESRCH;/a\ 230 | #ifdef CONFIG_REKERNEL\ 231 | if (sig == SIGKILL || sig == SIGTERM || sig == SIGABRT || sig == SIGQUIT)\ 232 | rekernel_report(SIGNAL, sig, task_tgid_nr(current), current, task_tgid_nr(p), p, false, NULL);\ 233 | #endif /* CONFIG_REKERNEL */' $i 234 | ;; 235 | esac 236 | done 237 | -------------------------------------------------------------------------------- /Integrate/rekernel/rekernel.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #if IS_ENABLED(CONFIG_IPV6) 7 | #include 8 | #endif /* IS_ENABLED(CONFIG_IPV6) */ 9 | #include 10 | #include 11 | #include 12 | #if IS_ENABLED(CONFIG_IPV6) 13 | #include 14 | #endif /* IS_ENABLED(CONFIG_IPV6) */ 15 | 16 | #include 17 | #include 18 | #include "rekernel.h" 19 | 20 | #define MIN_USERAPP_UID 10000 21 | #define MAX_SYSTEM_UID 2000 22 | #define SYSTEM_APP_UID 1000 23 | #define INTERFACETOKEN_BUFF_SIZE 140 24 | #define PARCEL_OFFSET 16 25 | #define LINE_ERROR 1 26 | #define LINE_SUCCESS 0 27 | 28 | #define NETLINK_REKERNEL_MAX 26 29 | #define NETLINK_REKERNEL_MIN 22 30 | #define USER_PORT 100 31 | #define PACKET_SIZE 256 32 | 33 | static const char* binder_type[] = { 34 | "reply", 35 | "transaction", 36 | "free_buffer_full", 37 | }; 38 | static const char* rpc_type[] = { 39 | "SYNC_BINDER_REPLY", 40 | "SYNC_BINDER", 41 | "FREE_BUFFER_FULL", 42 | }; 43 | static struct sock* netlink_socket; 44 | extern struct net init_net; 45 | static unsigned long netlink_unit = 0; 46 | #ifdef CONFIG_PROC_FS 47 | static struct proc_dir_entry* rekernel_dir, * rekernel_unit_entry; 48 | #endif /* CONFIG_PROC_FS */ 49 | 50 | static int sendMessage(char* packet_buffer, uint16_t len) { 51 | struct sk_buff* socket_buffer; 52 | struct nlmsghdr* netlink_hdr; 53 | 54 | socket_buffer = nlmsg_new(len, GFP_ATOMIC); 55 | if (!socket_buffer) { 56 | pr_err("netlink alloc failure.\n"); 57 | return -LINE_ERROR; 58 | } 59 | 60 | netlink_hdr = nlmsg_put(socket_buffer, 0, 0, netlink_unit, len, 0); 61 | if (!netlink_hdr) { 62 | pr_err("nlmsg_put failaure.\n"); 63 | nlmsg_free(socket_buffer); 64 | return -LINE_ERROR; 65 | } 66 | 67 | memcpy(nlmsg_data(netlink_hdr), packet_buffer, len); 68 | return netlink_unicast(netlink_socket, socket_buffer, USER_PORT, MSG_DONTWAIT); 69 | } 70 | static void netlink_rcv_msg(struct sk_buff* socket_buffer) { 71 | struct nlmsghdr* nlhdr = NULL; 72 | char* umsg = NULL; 73 | 74 | if (socket_buffer->len >= nlmsg_total_size(0)) { 75 | nlhdr = nlmsg_hdr(socket_buffer); 76 | umsg = nlmsg_data(nlhdr); 77 | if (umsg) { 78 | #ifdef CONFIG_PROC_FS 79 | if (!memcmp(umsg, "#proc_remove", nlmsg_len(nlhdr))) { 80 | if (rekernel_dir) { 81 | proc_remove(rekernel_dir); 82 | } 83 | } 84 | #endif /* CONFIG_PROC_FS */ 85 | } 86 | } 87 | } 88 | #ifdef CONFIG_REKERNEL_NETWORK 89 | static unsigned int rekernel_pkg_ipv4_ipv6_in(void* priv, struct sk_buff* socket_buffer, 90 | const struct nf_hook_state* state) { 91 | struct sock* sk; 92 | unsigned int thoff = 0; 93 | unsigned short frag_off = 0; 94 | uid_t uid; 95 | uint hook; 96 | struct net_device* dev = NULL; 97 | 98 | if (!socket_buffer || !socket_buffer->len || !state) 99 | return NF_ACCEPT; 100 | 101 | hook = state->hook; 102 | if (NF_INET_LOCAL_IN == hook) 103 | dev = state->in; 104 | 105 | if (NULL == dev) 106 | return NF_ACCEPT; 107 | 108 | if (ip_hdr(socket_buffer)->version == 4) { 109 | if (ip_hdr(socket_buffer)->protocol != IPPROTO_TCP) 110 | return NF_ACCEPT; 111 | #if IS_ENABLED(CONFIG_IPV6) 112 | } else if (ip_hdr(socket_buffer)->version == 6) { 113 | if (ipv6_find_hdr(socket_buffer, &thoff, -1, &frag_off, NULL) != IPPROTO_TCP) 114 | return NF_ACCEPT; 115 | #endif 116 | } else { 117 | return NF_ACCEPT; 118 | } 119 | 120 | sk = skb_to_full_sk(socket_buffer); 121 | if (sk == NULL || !sk_fullsock(sk)) 122 | return NF_ACCEPT; 123 | 124 | uid = sock_i_uid(sk).val; 125 | if (uid < MIN_USERAPP_UID) 126 | return NF_ACCEPT; 127 | 128 | rekernel_report(NETWORK, 0, ip_hdr(socket_buffer)->version, NULL, uid, NULL, true, NULL); 129 | return NF_ACCEPT; 130 | } 131 | /* Only monitor input network packages */ 132 | static struct nf_hook_ops rekernel_nf_ops[] = { 133 | { 134 | .hook = rekernel_pkg_ipv4_ipv6_in, 135 | .pf = NFPROTO_IPV4, 136 | .hooknum = NF_INET_LOCAL_IN, 137 | .priority = NF_IP_PRI_SELINUX_LAST + 1, 138 | }, 139 | #if IS_ENABLED(CONFIG_IPV6) 140 | { 141 | .hook = rekernel_pkg_ipv4_ipv6_in, 142 | .pf = NFPROTO_IPV6, 143 | .hooknum = NF_INET_LOCAL_IN, 144 | .priority = NF_IP6_PRI_SELINUX_LAST + 1, 145 | } 146 | #endif 147 | }; 148 | 149 | int register_netfilter(void) { 150 | int rc; 151 | struct net* net = NULL; 152 | for_each_net(net) { 153 | rc = nf_register_net_hooks(net, rekernel_nf_ops, ARRAY_SIZE(rekernel_nf_ops)); 154 | if (rc) { 155 | pr_err("register netfilter hooks failed, rc=%d\n", rc); 156 | break; 157 | } 158 | } 159 | if (rc) { 160 | for_each_net(net) { 161 | nf_unregister_net_hooks(net, rekernel_nf_ops, ARRAY_SIZE(rekernel_nf_ops)); 162 | } 163 | return -1; 164 | } 165 | 166 | return LINE_SUCCESS; 167 | } 168 | #endif /* CONFIG_REKERNEL_NETWORK */ 169 | struct netlink_kernel_cfg cfg = { 170 | .input = netlink_rcv_msg, // set recv callback 171 | }; 172 | #ifdef CONFIG_PROC_FS 173 | static int rekernel_unit_show(struct seq_file* m, void* v) { 174 | seq_printf(m, "%d\n", netlink_unit); 175 | return LINE_SUCCESS; 176 | } 177 | static int rekernel_unit_open(struct inode* inode, struct file* file) { 178 | return single_open(file, rekernel_unit_show, NULL); 179 | } 180 | static const struct file_operations rekernel_unit_fops = { 181 | .open = rekernel_unit_open, 182 | .read = seq_read, 183 | .llseek = seq_lseek, 184 | .release = single_release 185 | }; 186 | #endif /* CONFIG_PROC_FS */ 187 | // init 188 | static int start_rekernel(void) { 189 | if (netlink_unit) 190 | return 0; 191 | 192 | pr_info("Thank you for choosing Re:Kernel!\n"); 193 | #ifdef CONFIG_REKERNEL_NETWORK 194 | pr_info("NetFilter is enabled!\n"); 195 | #endif 196 | pr_info("Re:Kernel v8.5 | DEVELOPER: Sakion Team | Timeline | USER PORT: %d\n", USER_PORT); 197 | pr_info("Trying to create Re:Kernel Server......\n"); 198 | 199 | for (netlink_unit = NETLINK_REKERNEL_MIN; netlink_unit < NETLINK_REKERNEL_MAX; netlink_unit++) { 200 | netlink_socket = netlink_kernel_create(&init_net, netlink_unit, &cfg); 201 | if (netlink_socket != NULL) 202 | break; 203 | } 204 | if (netlink_socket == NULL) { 205 | netlink_unit = 0; 206 | pr_err("Failed to create Re:Kernel server!\n"); 207 | return -LINE_ERROR; 208 | } 209 | pr_info("Created Re:Kernel server! NETLINK UNIT: %d\n", netlink_unit); 210 | 211 | #ifdef CONFIG_PROC_FS 212 | rekernel_dir = proc_mkdir("rekernel", NULL); 213 | if (!rekernel_dir) { 214 | pr_err("create /proc/rekernel failed!\n"); 215 | } else { 216 | char buff[32]; 217 | sprintf(buff, "%d", netlink_unit); 218 | rekernel_unit_entry = proc_create(buff, 0644, rekernel_dir, &rekernel_unit_fops); 219 | if (!rekernel_unit_entry) { 220 | pr_err("create rekernel unit failed!\n"); 221 | } 222 | } 223 | #endif /* CONFIG_PROC_FS */ 224 | #ifdef CONFIG_REKERNEL_NETWORK 225 | if (register_netfilter()) { 226 | pr_err("%s: Failed to hook netfilter!\n", __func__); 227 | return -LINE_ERROR; 228 | } 229 | #endif /* CONFIG_REKERNEL_NETWORK */ 230 | return LINE_SUCCESS; 231 | } 232 | 233 | void rekernel_report(int reporttype, int type, pid_t src_pid, struct task_struct* src, pid_t dst_pid, struct task_struct* dst, bool oneway, struct binder_transaction_data* tr) { 234 | char binder_kmsg[PACKET_SIZE]; 235 | char buf_data[INTERFACETOKEN_BUFF_SIZE]; 236 | size_t buf_data_size; 237 | char buf[INTERFACETOKEN_BUFF_SIZE] = { 0 }; 238 | char* p; 239 | int i = 0; 240 | int j = 0; 241 | 242 | if (start_rekernel()) 243 | return; 244 | 245 | #ifdef CONFIG_REKERNEL_NETWORK 246 | if (reporttype == NETWORK) { 247 | char binder_kmsg[PACKET_SIZE]; 248 | snprintf(binder_kmsg, sizeof(binder_kmsg), "type=Network,target=%d,proto=ipv%d;", dst_pid, src_pid); 249 | sendMessage(binder_kmsg, strlen(binder_kmsg)); 250 | return; 251 | } 252 | #endif /* CONFIG_REKERNEL_NETWORK */ 253 | 254 | if (!frozen_task_group(dst)) 255 | return; 256 | 257 | if (task_uid(src).val == task_uid(dst).val) 258 | return; 259 | 260 | switch (reporttype) { 261 | case BINDER: 262 | if (oneway && type == TRANSACTION) { 263 | if (tr->code < 29 || tr->code > 32) 264 | return; 265 | buf_data_size = tr->data_size > INTERFACETOKEN_BUFF_SIZE ? INTERFACETOKEN_BUFF_SIZE : tr->data_size; 266 | if (copy_from_user(buf_data, (char*)tr->data.ptr.buffer, buf_data_size)) 267 | return; 268 | j = PARCEL_OFFSET + 1; 269 | p = (char*)(buf_data)+PARCEL_OFFSET; 270 | while (i < INTERFACETOKEN_BUFF_SIZE && j < buf_data_size && *p != '\0') { 271 | buf[i++] = *p; 272 | j += 2; 273 | p += 2; 274 | } 275 | if (i == INTERFACETOKEN_BUFF_SIZE) { 276 | buf[i - 1] = '\0'; 277 | } 278 | snprintf(binder_kmsg, sizeof(binder_kmsg), "type=Binder,bindertype=%s,oneway=%d,from_pid=%d,from=%d,target_pid=%d,target=%d,rpc_name=%s,code=%d;", binder_type[type], oneway, src_pid, task_uid(src).val, dst_pid, task_uid(dst).val, buf, tr->code); 279 | } else { 280 | snprintf(binder_kmsg, sizeof(binder_kmsg), "type=Binder,bindertype=%s,oneway=%d,from_pid=%d,from=%d,target_pid=%d,target=%d;", binder_type[type], oneway, src_pid, task_uid(src).val, dst_pid, task_uid(dst).val, rpc_type[type], -1); 281 | } 282 | break; 283 | case SIGNAL: 284 | snprintf(binder_kmsg, sizeof(binder_kmsg), "type=Signal,signal=%d,killer_pid=%d,killer=%d,dst_pid=%d,dst=%d;", type, src_pid, task_uid(src).val, dst_pid, task_uid(dst).val); 285 | break; 286 | default: 287 | return; 288 | } 289 | sendMessage(binder_kmsg, strlen(binder_kmsg)); 290 | } 291 | 292 | void binder_reply_handler(pid_t src_pid, struct task_struct* src, pid_t dst_pid, struct task_struct* dst, bool oneway, struct binder_transaction_data* tr) { 293 | if (unlikely(!dst)) 294 | return; 295 | if (task_uid(dst).val > MAX_SYSTEM_UID || src_pid == dst_pid) 296 | return; 297 | 298 | // oneway=0 299 | rekernel_report(BINDER, REPLY, src_pid, src, dst_pid, dst, oneway, tr); 300 | } 301 | 302 | void binder_trans_handler(pid_t src_pid, struct task_struct* src, pid_t dst_pid, struct task_struct* dst, bool oneway, struct binder_transaction_data* tr) { 303 | if (unlikely(!dst)) 304 | return; 305 | if ((task_uid(dst).val <= MIN_USERAPP_UID) || src_pid == dst_pid) 306 | return; 307 | 308 | rekernel_report(BINDER, TRANSACTION, src_pid, src, dst_pid, dst, oneway, tr); 309 | } 310 | 311 | void binder_overflow_handler(pid_t src_pid, struct task_struct* src, pid_t dst_pid, struct task_struct* dst, bool oneway, struct binder_transaction_data* tr) { 312 | if (unlikely(!dst)) 313 | return; 314 | 315 | // oneway=1 316 | rekernel_report(BINDER, OVERFLOW, src_pid, src, dst_pid, dst, oneway, tr); 317 | } 318 | -------------------------------------------------------------------------------- /Integrate/README_CN.md: -------------------------------------------------------------------------------- 1 | # 为非GKI或QGKI内核集成Re:Kernel 2 | 在开始前,你必须有能力从你设备的内核源码编译出一个可以开机并且能正常使用的内核,如果内核不开源,这通常难以做到。 3 | 4 | 如果你已经做好了上述准备,那么你这里有两种方法可以将Re:Kernel集成到你的内核当中 5 | 6 | ## 使用Kernel Modifier自动修改 7 | 首先 你需要下载并将Kernel Modifier放入内核源代码的根目录中 然后使用17及以上版本的Java运行Kernel Modifier, 不出意外的话 Modifier 会自动修改内核源码并将ReKernel插入到你的内核当中 接下来你只需要重新编译一次内核即可 8 | 9 | ## 手动修改 10 | 首先 你应该创建一个头或源文件 里面存放NETLINK的代码 其UNIT应为26 用户端口为100 包体大小为128 11 | ```C++ 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #define NETLINK_REKERNEL_MAX 26 20 | #define NETLINK_REKERNEL_MIN 22 21 | #define USER_PORT 100 22 | #define PACKET_SIZE 128 23 | #define MIN_USERAPP_UID (10000) 24 | #define MAX_SYSTEM_UID (2000) 25 | #define RESERVE_ORDER 17 26 | #define WARN_AHEAD_SPACE (1 << RESERVE_ORDER) 27 | 28 | static struct sock *rekernel_netlink = NULL; 29 | extern struct net init_net; 30 | static int netlink_unit = NETLINK_REKERNEL_MIN; 31 | 32 | static inline bool line_is_frozen(struct task_struct *task) 33 | { 34 | return frozen(task->group_leader) || freezing(task->group_leader); 35 | } 36 | 37 | static int send_netlink_message(char *msg, uint16_t len) { 38 | struct sk_buff *skbuffer; 39 | struct nlmsghdr *nlhdr; 40 | 41 | skbuffer = nlmsg_new(len, GFP_ATOMIC); 42 | if (!skbuffer) { 43 | printk("netlink alloc failure.\n"); 44 | return -1; 45 | } 46 | 47 | nlhdr = nlmsg_put(skbuffer, 0, 0, netlink_unit, len, 0); 48 | if (!nlhdr) { 49 | printk("nlmsg_put failaure.\n"); 50 | nlmsg_free(skbuffer); 51 | return -1; 52 | } 53 | 54 | memcpy(nlmsg_data(nlhdr), msg, len); 55 | return netlink_unicast(rekernel_netlink, skbuffer, USER_PORT, MSG_DONTWAIT); 56 | } 57 | 58 | static void netlink_rcv_msg(struct sk_buff *skbuffer) { // Ignore recv msg. 59 | } 60 | 61 | static struct netlink_kernel_cfg rekernel_cfg = { 62 | .input = netlink_rcv_msg, 63 | }; 64 | 65 | static int rekernel_unit_show(struct seq_file *m, void *v) 66 | { 67 | seq_printf(m, "%d\n", netlink_unit); 68 | return 0; 69 | } 70 | 71 | static int rekernel_unit_open(struct inode *inode, struct file *file) 72 | { 73 | return single_open(file, rekernel_unit_show, NULL); 74 | } 75 | 76 | static const struct file_operations rekernel_unit_fops = { 77 | .open = rekernel_unit_open, 78 | .read = seq_read, 79 | .llseek = seq_lseek, 80 | .release = single_release, 81 | .owner = THIS_MODULE, 82 | }; 83 | 84 | static struct proc_dir_entry *rekernel_dir, *rekernel_unit_entry; 85 | 86 | static int start_rekernel_server(void) { 87 | if (rekernel_netlink != NULL) 88 | return 0; 89 | for (netlink_unit = NETLINK_REKERNEL_MIN; netlink_unit < NETLINK_REKERNEL_MAX; netlink_unit++) { 90 | rekernel_netlink = (struct sock *)netlink_kernel_create(&init_net, netlink_unit, &rekernel_cfg); 91 | if (rekernel_netlink != NULL) 92 | break; 93 | } 94 | if (rekernel_netlink == NULL) { 95 | printk("Failed to create Re:Kernel server!\n"); 96 | return -1; 97 | } 98 | printk("Created Re:Kernel server! NETLINK UNIT: %d\n", netlink_unit); 99 | rekernel_dir = proc_mkdir("rekernel", NULL); 100 | if (!rekernel_dir) 101 | printk("create /proc/rekernel failed!\n"); 102 | else { 103 | char buff[32]; 104 | sprintf(buff, "%d", netlink_unit); 105 | rekernel_unit_entry = proc_create(buff, 0644, rekernel_dir, &rekernel_unit_fops); 106 | if (!rekernel_unit_entry) 107 | printk("create rekernel unit failed!\n"); 108 | } 109 | return 0; 110 | } 111 | ``` 112 | 然后,将调用添加到内核源代码中,如下: 113 | ```C++ 114 | // drivers/android/binder.c 115 | static void binder_transaction(struct binder_proc *proc, 116 | struct binder_thread *thread, 117 | struct binder_transaction_data *tr, int reply, 118 | binder_size_t extra_buffers_size) 119 | { 120 | ........ 121 | if (target_thread->transaction_stack != in_reply_to) { 122 | binder_user_error("%d:%d got reply transaction with bad target transaction stack %d, expected %d\n", 123 | proc->pid, thread->pid, 124 | target_thread->transaction_stack ? 125 | target_thread->transaction_stack->debug_id : 0, 126 | in_reply_to->debug_id); 127 | binder_inner_proc_unlock(target_thread->proc); 128 | return_error = BR_FAILED_REPLY; 129 | return_error_param = -EPROTO; 130 | return_error_line = __LINE__; 131 | in_reply_to = NULL; 132 | target_thread = NULL; 133 | goto err_dead_binder; 134 | } 135 | target_proc = target_thread->proc; 136 | target_proc->tmp_ref++; 137 | binder_inner_proc_unlock(target_thread->proc); 138 | + if (start_rekernel_server() == 0) { 139 | + if (target_proc 140 | + && (NULL != target_proc->tsk) 141 | + && (NULL != proc->tsk) 142 | + && (task_uid(target_proc->tsk).val <= MAX_SYSTEM_UID) 143 | + && (proc->pid != target_proc->pid) 144 | + && line_is_frozen(target_proc->tsk)) { 145 | + char binder_kmsg[PACKET_SIZE]; 146 | + snprintf(binder_kmsg, sizeof(binder_kmsg), "type=Binder,bindertype=reply,oneway=0,from_pid=%d,from=%d,target_pid=%d,target=%d;", proc->pid, task_uid(proc->tsk).val, target_proc->pid, task_uid(target_proc->tsk).val); 147 | + send_netlink_message(binder_kmsg, strlen(binder_kmsg)); 148 | + } 149 | + } 150 | } else { 151 | if (tr->target.handle) { 152 | struct binder_ref *ref; 153 | 154 | /* 155 | * There must already be a strong ref 156 | * on this node. If so, do a strong 157 | * increment on the node to ensure it 158 | * stays alive until the transaction is 159 | * done. 160 | */ 161 | binder_proc_lock(proc); 162 | ref = binder_get_ref_olocked(proc, tr->target.handle, 163 | true); 164 | if (ref) { 165 | target_node = binder_get_node_refs_for_txn( 166 | ref->node, &target_proc, 167 | &return_error); 168 | } else { 169 | binder_user_error("%d:%d got transaction to invalid handle\n", 170 | proc->pid, thread->pid); 171 | return_error = BR_FAILED_REPLY; 172 | } 173 | binder_proc_unlock(proc); 174 | } else { 175 | mutex_lock(&context->context_mgr_node_lock); 176 | target_node = context->binder_context_mgr_node; 177 | if (target_node) 178 | target_node = binder_get_node_refs_for_txn( 179 | target_node, &target_proc, 180 | &return_error); 181 | else 182 | return_error = BR_DEAD_REPLY; 183 | mutex_unlock(&context->context_mgr_node_lock); 184 | if (target_node && target_proc->pid == proc->pid) { 185 | binder_user_error("%d:%d got transaction to context manager from process owning it\n", 186 | proc->pid, thread->pid); 187 | return_error = BR_FAILED_REPLY; 188 | return_error_param = -EINVAL; 189 | return_error_line = __LINE__; 190 | goto err_invalid_target_handle; 191 | } 192 | } 193 | if (!target_node) { 194 | /* 195 | * return_error is set above 196 | */ 197 | return_error_param = -EINVAL; 198 | return_error_line = __LINE__; 199 | goto err_dead_binder; 200 | } 201 | e->to_node = target_node->debug_id; 202 | + if (start_rekernel_server() == 0) { 203 | + if (target_proc 204 | + && (NULL != target_proc->tsk) 205 | + && (NULL != proc->tsk) 206 | + && (task_uid(target_proc->tsk).val > MIN_USERAPP_UID) 207 | + && (proc->pid != target_proc->pid) 208 | + && line_is_frozen(target_proc->tsk)) { 209 | + char binder_kmsg[PACKET_SIZE]; 210 | + snprintf(binder_kmsg, sizeof(binder_kmsg), "type=Binder,bindertype=transaction,oneway=%d,from_pid=%d,from=%d,target_pid=%d,target=%d;", tr->flags & TF_ONE_WAY, proc->pid, task_uid(proc->tsk).val, target_proc->pid, task_uid(target_proc->tsk).val); 211 | + send_netlink_message(binder_kmsg, strlen(binder_kmsg)); 212 | + } 213 | + } 214 | if (security_binder_transaction(proc->cred, 215 | target_proc->cred) < 0) { 216 | return_error = BR_FAILED_REPLY; 217 | return_error_param = -EPERM; 218 | return_error_line = __LINE__; 219 | goto err_invalid_target_handle; 220 | } 221 | binder_inner_proc_lock(proc); 222 | ........ 223 | } 224 | ``` 225 | ```C++ 226 | // drivers/android/binder_alloc.c 227 | static struct binder_buffer *binder_alloc_new_buf_locked( 228 | struct binder_alloc *alloc, 229 | size_t data_size, 230 | size_t offsets_size, 231 | size_t extra_buffers_size, 232 | int is_async, 233 | int pid) 234 | { 235 | + struct task_struct *proc_task = NULL; 236 | struct rb_node *n = alloc->free_buffers.rb_node; 237 | struct binder_buffer *buffer; 238 | size_t buffer_size; 239 | struct rb_node *best_fit = NULL; 240 | void __user *has_page_addr; 241 | void __user *end_page_addr; 242 | size_t size, data_offsets_size; 243 | int ret; 244 | 245 | mmap_read_lock(alloc->vma_vm_mm); 246 | if (!binder_alloc_get_vma(alloc)) { 247 | mmap_read_unlock(alloc->vma_vm_mm); 248 | binder_alloc_debug(BINDER_DEBUG_USER_ERROR, 249 | "%d: binder_alloc_buf, no vma\n", 250 | alloc->pid); 251 | return ERR_PTR(-ESRCH); 252 | } 253 | mmap_read_unlock(alloc->vma_vm_mm); 254 | 255 | data_offsets_size = ALIGN(data_size, sizeof(void *)) + 256 | ALIGN(offsets_size, sizeof(void *)); 257 | 258 | if (data_offsets_size < data_size || data_offsets_size < offsets_size) { 259 | binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC, 260 | "%d: got transaction with invalid size %zd-%zd\n", 261 | alloc->pid, data_size, offsets_size); 262 | return ERR_PTR(-EINVAL); 263 | } 264 | size = data_offsets_size + ALIGN(extra_buffers_size, sizeof(void *)); 265 | if (size < data_offsets_size || size < extra_buffers_size) { 266 | binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC, 267 | "%d: got transaction with invalid extra_buffers_size %zd\n", 268 | alloc->pid, extra_buffers_size); 269 | return ERR_PTR(-EINVAL); 270 | } 271 | + if (is_async 272 | + && (alloc->free_async_space < 3 * (size + sizeof(struct binder_buffer)) 273 | + || (alloc->free_async_space < WARN_AHEAD_SPACE))) { 274 | + rcu_read_lock(); 275 | + proc_task = find_task_by_vpid(alloc->pid); 276 | + rcu_read_unlock(); 277 | + if (proc_task != NULL && start_rekernel_server() == 0) { 278 | + if (line_is_frozen(proc_task)) { 279 | + char binder_kmsg[PACKET_SIZE]; 280 | + snprintf(binder_kmsg, sizeof(binder_kmsg), "type=Binder,bindertype=free_buffer_full,oneway=1,from_pid=%d,from=%d,target_pid=%d,target=%d;", current->pid, task_uid(current).val, proc_task->pid, task_uid(proc_task).val); 281 | + send_netlink_message(binder_kmsg, strlen(binder_kmsg)); 282 | + } 283 | + } 284 | + } 285 | if (is_async && 286 | alloc->free_async_space < size + sizeof(struct binder_buffer)) { 287 | binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC, 288 | "%d: binder_alloc_buf size %zd failed, no async space left\n", 289 | alloc->pid, size); 290 | return ERR_PTR(-ENOSPC); 291 | } 292 | 293 | /* Pad 0-size buffers so they get assigned unique addresses */ 294 | size = max(size, sizeof(void *)); 295 | 296 | while (n) { 297 | buffer = rb_entry(n, struct binder_buffer, rb_node); 298 | BUG_ON(!buffer->free); 299 | buffer_size = binder_alloc_buffer_size(alloc, buffer); 300 | 301 | if (size < buffer_size) { 302 | best_fit = n; 303 | n = n->rb_left; 304 | } else if (size > buffer_size) 305 | n = n->rb_right; 306 | else { 307 | best_fit = n; 308 | break; 309 | } 310 | } 311 | if (best_fit == NULL) { 312 | size_t allocated_buffers = 0; 313 | size_t largest_alloc_size = 0; 314 | size_t total_alloc_size = 0; 315 | size_t free_buffers = 0; 316 | size_t largest_free_size = 0; 317 | size_t total_free_size = 0; 318 | 319 | for (n = rb_first(&alloc->allocated_buffers); n != NULL; 320 | n = rb_next(n)) { 321 | buffer = rb_entry(n, struct binder_buffer, rb_node); 322 | buffer_size = binder_alloc_buffer_size(alloc, buffer); 323 | allocated_buffers++; 324 | total_alloc_size += buffer_size; 325 | if (buffer_size > largest_alloc_size) 326 | largest_alloc_size = buffer_size; 327 | } 328 | ........ 329 | } 330 | ``` 331 | ```C++ 332 | // kernel/signal.c 333 | int do_send_sig_info(int sig, struct siginfo *info, struct task_struct *p, 334 | bool group) 335 | { 336 | unsigned long flags; 337 | int ret = -ESRCH; 338 | + if (start_rekernel_server() == 0) { 339 | + if (line_is_frozen(current) && (sig == SIGKILL || sig == SIGTERM || sig == SIGABRT || sig == SIGQUIT)) { 340 | + char binder_kmsg[PACKET_SIZE]; 341 | + snprintf(binder_kmsg, sizeof(binder_kmsg), "type=Signal,signal=%d,killer_pid=%d,killer=%d,dst_pid=%d,dst=%d;", sig, task_tgid_nr(p), task_uid(p).val, task_tgid_nr(current), task_uid(current).val); 342 | + send_netlink_message(binder_kmsg, strlen(binder_kmsg)); 343 | + } 344 | + } 345 | if (lock_task_sighand(p, &flags)) { 346 | ret = send_signal(sig, info, p, group); 347 | unlock_task_sighand(p, &flags); 348 | } 349 | 350 | return ret; 351 | } 352 | ``` 353 | 主要修改两个地方: 354 | 355 | binder_transaction,通常位于 `drivers/android/binder.c` 356 | 357 | binder_alloc_new_buf_locked,通常位于 `drivers/android/binder_alloc.c` 358 | 359 | do_send_sig_info,通常位于 `kernel/signal.c` 360 | 361 | 改完之后重新编译内核,Re:Kernel将会融入你的内核当中。 362 | -------------------------------------------------------------------------------- /Integrate/README.md: -------------------------------------------------------------------------------- 1 | # Integrate Re:Kernel for non GKI or QGKI kernels 2 | First, you should be able to build a bootable kernel from your kernel source code. If the kernel is not open source, this is almost impossible. 3 | 4 | If you have made the above preparations, you can integrate Re:Kernel into your kernel as follows 5 | 6 | ## Automatically modify with Kernel Modifier 7 | Firstly, you need to download and place the Kernel Modifier in the root directory of the kernel source code, Then run the Kernel modifier using Java version 17 and above. If nothing unexpected happens, the modifier will automatically modify the kernel source code and insert ReKernel into your kernel. Next, you only need to recompile the kernel once. 8 | 9 | ## Modification 10 | Firstly, you should create a header or source file to store the NETLINK code, with a UNIT of 26, a port of 100, and a packet size of 128 11 | ```C++ 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | 19 | #define NETLINK_REKERNEL_MAX 26 20 | #define NETLINK_REKERNEL_MIN 22 21 | #define USER_PORT 100 22 | #define PACKET_SIZE 128 23 | #define MIN_USERAPP_UID (10000) 24 | #define MAX_SYSTEM_UID (2000) 25 | #define RESERVE_ORDER 17 26 | #define WARN_AHEAD_SPACE (1 << RESERVE_ORDER) 27 | 28 | static struct sock *rekernel_netlink = NULL; 29 | extern struct net init_net; 30 | static int netlink_unit = NETLINK_REKERNEL_MIN; 31 | 32 | static inline bool line_is_frozen(struct task_struct *task) 33 | { 34 | return frozen(task->group_leader) || freezing(task->group_leader); 35 | } 36 | 37 | static int send_netlink_message(char *msg, uint16_t len) { 38 | struct sk_buff *skbuffer; 39 | struct nlmsghdr *nlhdr; 40 | 41 | skbuffer = nlmsg_new(len, GFP_ATOMIC); 42 | if (!skbuffer) { 43 | printk("netlink alloc failure.\n"); 44 | return -1; 45 | } 46 | 47 | nlhdr = nlmsg_put(skbuffer, 0, 0, netlink_unit, len, 0); 48 | if (!nlhdr) { 49 | printk("nlmsg_put failaure.\n"); 50 | nlmsg_free(skbuffer); 51 | return -1; 52 | } 53 | 54 | memcpy(nlmsg_data(nlhdr), msg, len); 55 | return netlink_unicast(rekernel_netlink, skbuffer, USER_PORT, MSG_DONTWAIT); 56 | } 57 | 58 | static void netlink_rcv_msg(struct sk_buff *skbuffer) { // Ignore recv msg. 59 | } 60 | 61 | static struct netlink_kernel_cfg rekernel_cfg = { 62 | .input = netlink_rcv_msg, 63 | }; 64 | 65 | static int rekernel_unit_show(struct seq_file *m, void *v) 66 | { 67 | seq_printf(m, "%d\n", netlink_unit); 68 | return 0; 69 | } 70 | 71 | static int rekernel_unit_open(struct inode *inode, struct file *file) 72 | { 73 | return single_open(file, rekernel_unit_show, NULL); 74 | } 75 | 76 | static const struct file_operations rekernel_unit_fops = { 77 | .open = rekernel_unit_open, 78 | .read = seq_read, 79 | .llseek = seq_lseek, 80 | .release = single_release, 81 | .owner = THIS_MODULE, 82 | }; 83 | 84 | static struct proc_dir_entry *rekernel_dir, *rekernel_unit_entry; 85 | 86 | static int start_rekernel_server(void) { 87 | if (rekernel_netlink != NULL) 88 | return 0; 89 | for (netlink_unit = NETLINK_REKERNEL_MIN; netlink_unit < NETLINK_REKERNEL_MAX; netlink_unit++) { 90 | rekernel_netlink = (struct sock *)netlink_kernel_create(&init_net, netlink_unit, &rekernel_cfg); 91 | if (rekernel_netlink != NULL) 92 | break; 93 | } 94 | if (rekernel_netlink == NULL) { 95 | printk("Failed to create Re:Kernel server!\n"); 96 | return -1; 97 | } 98 | printk("Created Re:Kernel server! NETLINK UNIT: %d\n", netlink_unit); 99 | rekernel_dir = proc_mkdir("rekernel", NULL); 100 | if (!rekernel_dir) 101 | printk("create /proc/rekernel failed!\n"); 102 | else { 103 | char buff[32]; 104 | sprintf(buff, "%d", netlink_unit); 105 | rekernel_unit_entry = proc_create(buff, 0644, rekernel_dir, &rekernel_unit_fops); 106 | if (!rekernel_unit_entry) 107 | printk("create rekernel unit failed!\n"); 108 | } 109 | return 0; 110 | } 111 | ``` 112 | Then, add the calls to the kernel source code as follows: 113 | ```C++ 114 | // drivers/android/binder.c 115 | static void binder_transaction(struct binder_proc *proc, 116 | struct binder_thread *thread, 117 | struct binder_transaction_data *tr, int reply, 118 | binder_size_t extra_buffers_size) 119 | { 120 | ........ 121 | if (target_thread->transaction_stack != in_reply_to) { 122 | binder_user_error("%d:%d got reply transaction with bad target transaction stack %d, expected %d\n", 123 | proc->pid, thread->pid, 124 | target_thread->transaction_stack ? 125 | target_thread->transaction_stack->debug_id : 0, 126 | in_reply_to->debug_id); 127 | binder_inner_proc_unlock(target_thread->proc); 128 | return_error = BR_FAILED_REPLY; 129 | return_error_param = -EPROTO; 130 | return_error_line = __LINE__; 131 | in_reply_to = NULL; 132 | target_thread = NULL; 133 | goto err_dead_binder; 134 | } 135 | target_proc = target_thread->proc; 136 | target_proc->tmp_ref++; 137 | binder_inner_proc_unlock(target_thread->proc); 138 | + if (start_rekernel_server() == 0) { 139 | + if (target_proc 140 | + && (NULL != target_proc->tsk) 141 | + && (NULL != proc->tsk) 142 | + && (task_uid(target_proc->tsk).val <= MAX_SYSTEM_UID) 143 | + && (proc->pid != target_proc->pid) 144 | + && line_is_frozen(target_proc->tsk)) { 145 | + char binder_kmsg[PACKET_SIZE]; 146 | + snprintf(binder_kmsg, sizeof(binder_kmsg), "type=Binder,bindertype=reply,oneway=0,from_pid=%d,from=%d,target_pid=%d,target=%d;", proc->pid, task_uid(proc->tsk).val, target_proc->pid, task_uid(target_proc->tsk).val); 147 | + send_netlink_message(binder_kmsg, strlen(binder_kmsg)); 148 | + } 149 | + } 150 | } else { 151 | if (tr->target.handle) { 152 | struct binder_ref *ref; 153 | 154 | /* 155 | * There must already be a strong ref 156 | * on this node. If so, do a strong 157 | * increment on the node to ensure it 158 | * stays alive until the transaction is 159 | * done. 160 | */ 161 | binder_proc_lock(proc); 162 | ref = binder_get_ref_olocked(proc, tr->target.handle, 163 | true); 164 | if (ref) { 165 | target_node = binder_get_node_refs_for_txn( 166 | ref->node, &target_proc, 167 | &return_error); 168 | } else { 169 | binder_user_error("%d:%d got transaction to invalid handle\n", 170 | proc->pid, thread->pid); 171 | return_error = BR_FAILED_REPLY; 172 | } 173 | binder_proc_unlock(proc); 174 | } else { 175 | mutex_lock(&context->context_mgr_node_lock); 176 | target_node = context->binder_context_mgr_node; 177 | if (target_node) 178 | target_node = binder_get_node_refs_for_txn( 179 | target_node, &target_proc, 180 | &return_error); 181 | else 182 | return_error = BR_DEAD_REPLY; 183 | mutex_unlock(&context->context_mgr_node_lock); 184 | if (target_node && target_proc->pid == proc->pid) { 185 | binder_user_error("%d:%d got transaction to context manager from process owning it\n", 186 | proc->pid, thread->pid); 187 | return_error = BR_FAILED_REPLY; 188 | return_error_param = -EINVAL; 189 | return_error_line = __LINE__; 190 | goto err_invalid_target_handle; 191 | } 192 | } 193 | if (!target_node) { 194 | /* 195 | * return_error is set above 196 | */ 197 | return_error_param = -EINVAL; 198 | return_error_line = __LINE__; 199 | goto err_dead_binder; 200 | } 201 | e->to_node = target_node->debug_id; 202 | + if (start_rekernel_server() == 0) { 203 | + if (target_proc 204 | + && (NULL != target_proc->tsk) 205 | + && (NULL != proc->tsk) 206 | + && (task_uid(target_proc->tsk).val > MIN_USERAPP_UID) 207 | + && (proc->pid != target_proc->pid) 208 | + && line_is_frozen(target_proc->tsk)) { 209 | + char binder_kmsg[PACKET_SIZE]; 210 | + snprintf(binder_kmsg, sizeof(binder_kmsg), "type=Binder,bindertype=transaction,oneway=%d,from_pid=%d,from=%d,target_pid=%d,target=%d;", tr->flags & TF_ONE_WAY, proc->pid, task_uid(proc->tsk).val, target_proc->pid, task_uid(target_proc->tsk).val); 211 | + send_netlink_message(binder_kmsg, strlen(binder_kmsg)); 212 | + } 213 | + } 214 | if (security_binder_transaction(proc->cred, 215 | target_proc->cred) < 0) { 216 | return_error = BR_FAILED_REPLY; 217 | return_error_param = -EPERM; 218 | return_error_line = __LINE__; 219 | goto err_invalid_target_handle; 220 | } 221 | binder_inner_proc_lock(proc); 222 | ........ 223 | } 224 | ``` 225 | ```C++ 226 | // drivers/android/binder_alloc.c 227 | static struct binder_buffer *binder_alloc_new_buf_locked( 228 | struct binder_alloc *alloc, 229 | size_t data_size, 230 | size_t offsets_size, 231 | size_t extra_buffers_size, 232 | int is_async, 233 | int pid) 234 | { 235 | + struct task_struct *proc_task = NULL; 236 | struct rb_node *n = alloc->free_buffers.rb_node; 237 | struct binder_buffer *buffer; 238 | size_t buffer_size; 239 | struct rb_node *best_fit = NULL; 240 | void __user *has_page_addr; 241 | void __user *end_page_addr; 242 | size_t size, data_offsets_size; 243 | int ret; 244 | 245 | mmap_read_lock(alloc->vma_vm_mm); 246 | if (!binder_alloc_get_vma(alloc)) { 247 | mmap_read_unlock(alloc->vma_vm_mm); 248 | binder_alloc_debug(BINDER_DEBUG_USER_ERROR, 249 | "%d: binder_alloc_buf, no vma\n", 250 | alloc->pid); 251 | return ERR_PTR(-ESRCH); 252 | } 253 | mmap_read_unlock(alloc->vma_vm_mm); 254 | 255 | data_offsets_size = ALIGN(data_size, sizeof(void *)) + 256 | ALIGN(offsets_size, sizeof(void *)); 257 | 258 | if (data_offsets_size < data_size || data_offsets_size < offsets_size) { 259 | binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC, 260 | "%d: got transaction with invalid size %zd-%zd\n", 261 | alloc->pid, data_size, offsets_size); 262 | return ERR_PTR(-EINVAL); 263 | } 264 | size = data_offsets_size + ALIGN(extra_buffers_size, sizeof(void *)); 265 | if (size < data_offsets_size || size < extra_buffers_size) { 266 | binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC, 267 | "%d: got transaction with invalid extra_buffers_size %zd\n", 268 | alloc->pid, extra_buffers_size); 269 | return ERR_PTR(-EINVAL); 270 | } 271 | + if (is_async 272 | + && (alloc->free_async_space < 3 * (size + sizeof(struct binder_buffer)) 273 | + || (alloc->free_async_space < WARN_AHEAD_SPACE))) { 274 | + rcu_read_lock(); 275 | + proc_task = find_task_by_vpid(alloc->pid); 276 | + rcu_read_unlock(); 277 | + if (proc_task != NULL && start_rekernel_server() == 0) { 278 | + if (line_is_frozen(proc_task)) { 279 | + char binder_kmsg[PACKET_SIZE]; 280 | + snprintf(binder_kmsg, sizeof(binder_kmsg), "type=Binder,bindertype=free_buffer_full,oneway=1,from_pid=%d,from=%d,target_pid=%d,target=%d;", current->pid, task_uid(current).val, proc_task->pid, task_uid(proc_task).val); 281 | + send_netlink_message(binder_kmsg, strlen(binder_kmsg)); 282 | + } 283 | + } 284 | + } 285 | if (is_async && 286 | alloc->free_async_space < size + sizeof(struct binder_buffer)) { 287 | binder_alloc_debug(BINDER_DEBUG_BUFFER_ALLOC, 288 | "%d: binder_alloc_buf size %zd failed, no async space left\n", 289 | alloc->pid, size); 290 | return ERR_PTR(-ENOSPC); 291 | } 292 | 293 | /* Pad 0-size buffers so they get assigned unique addresses */ 294 | size = max(size, sizeof(void *)); 295 | 296 | while (n) { 297 | buffer = rb_entry(n, struct binder_buffer, rb_node); 298 | BUG_ON(!buffer->free); 299 | buffer_size = binder_alloc_buffer_size(alloc, buffer); 300 | 301 | if (size < buffer_size) { 302 | best_fit = n; 303 | n = n->rb_left; 304 | } else if (size > buffer_size) 305 | n = n->rb_right; 306 | else { 307 | best_fit = n; 308 | break; 309 | } 310 | } 311 | if (best_fit == NULL) { 312 | size_t allocated_buffers = 0; 313 | size_t largest_alloc_size = 0; 314 | size_t total_alloc_size = 0; 315 | size_t free_buffers = 0; 316 | size_t largest_free_size = 0; 317 | size_t total_free_size = 0; 318 | 319 | for (n = rb_first(&alloc->allocated_buffers); n != NULL; 320 | n = rb_next(n)) { 321 | buffer = rb_entry(n, struct binder_buffer, rb_node); 322 | buffer_size = binder_alloc_buffer_size(alloc, buffer); 323 | allocated_buffers++; 324 | total_alloc_size += buffer_size; 325 | if (buffer_size > largest_alloc_size) 326 | largest_alloc_size = buffer_size; 327 | } 328 | ........ 329 | } 330 | ``` 331 | ```C++ 332 | // kernel/signal.c 333 | int do_send_sig_info(int sig, struct siginfo *info, struct task_struct *p, 334 | bool group) 335 | { 336 | unsigned long flags; 337 | int ret = -ESRCH; 338 | + if (start_rekernel_server() == 0) { 339 | + if (line_is_frozen(current) && (sig == SIGKILL || sig == SIGTERM || sig == SIGABRT || sig == SIGQUIT)) { 340 | + char binder_kmsg[PACKET_SIZE]; 341 | + snprintf(binder_kmsg, sizeof(binder_kmsg), "type=Signal,signal=%d,killer_pid=%d,killer=%d,dst_pid=%d,dst=%d;", sig, task_tgid_nr(p), task_uid(p).val, task_tgid_nr(current), task_uid(current).val); 342 | + send_netlink_message(binder_kmsg, strlen(binder_kmsg)); 343 | + } 344 | + } 345 | if (lock_task_sighand(p, &flags)) { 346 | ret = send_signal(sig, info, p, group); 347 | unlock_task_sighand(p, &flags); 348 | } 349 | 350 | return ret; 351 | } 352 | ``` 353 | You should find the two functions in kernel source: 354 | 355 | binder_transaction, usually in `drivers/android/binder.c` 356 | 357 | binder_alloc_new_buf_locked, usually in `drivers/android/binder_alloc.c` 358 | 359 | do_send_sig_info, usually in `kernel/signal.c` 360 | 361 | Finally, build your kernel again, Re:Kernel will be integrated into your kernel. 362 | -------------------------------------------------------------------------------- /LKM-Source/rekernel.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) Sakion Team. All rights reserved. 3 | * 4 | * File name: rekernel.c 5 | * Description: rekernel module 6 | * Author: nep_timeline@outlook.com 7 | * Last Modification: 2025/12/03 8 | */ 9 | #include "linux/printk.h" 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "rekernel.h" 21 | #include 22 | #include 23 | #include <../android/binder_internal.h> 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | 39 | #include 40 | #include 41 | #include 42 | #include 43 | 44 | #include 45 | 46 | #define NETLINK_REKERNEL_MAX 26 47 | #define NETLINK_REKERNEL_MIN 22 48 | #define USER_PORT 100 49 | #define PACKET_SIZE 256 50 | 51 | char netlink_kmsg[PACKET_SIZE]; 52 | struct sock *netlink_socket = NULL; 53 | extern struct net init_net; 54 | int netlink_unit = NETLINK_REKERNEL_MIN; 55 | 56 | static unsigned long (*re_kallsyms_lookup_name)(const char* name); 57 | static void (*re_binder_transaction_buffer_release)(struct binder_proc* proc, struct binder_thread* thread, struct binder_buffer* buffer, binder_size_t off_end_offset, bool is_failure); 58 | static void (*re_binder_alloc_free_buf)(struct binder_alloc* alloc, struct binder_buffer* buffer); 59 | static struct binder_stats(*re_binder_stats); 60 | static struct proc_dir_entry *rekernel_dir, *rekernel_unit_entry; 61 | 62 | /* hashmap for monitored uids */ 63 | #define REKERNEL_UID_HASH_BITS 6 64 | static DEFINE_HASHTABLE(rekernel_uid_map, REKERNEL_UID_HASH_BITS); 65 | struct uid_info { 66 | uid_t uid; 67 | struct hlist_node hnode; 68 | }; 69 | 70 | /* hashmap for persitent uids */ 71 | #define REKERNEL_P_UID_HASH_BITS 5 72 | static DEFINE_HASHTABLE(rekernel_p_uid_map, REKERNEL_P_UID_HASH_BITS); 73 | struct p_uid_info { 74 | uid_t uid; 75 | unsigned long last_arrival_time; /* jiffies */ 76 | struct hlist_node hnode; 77 | }; 78 | 79 | spinlock_t rekernel_map_lock; /* two maps use the same spinlock */ 80 | 81 | static inline bool rekernel_is_frozen_state_compatible(struct task_struct *task) 82 | { 83 | #if defined(KERNEL_5_10) || defined(KERNEL_5_15) 84 | return frozen(task); 85 | #else 86 | return READ_ONCE(task->__state) & TASK_FROZEN; 87 | #endif 88 | } 89 | 90 | static inline bool rekernel_is_jobctl_frozen_compatible(struct task_struct *task) 91 | { 92 | #ifdef KERNEL_5_10 93 | return cgroup_task_freeze(task); 94 | #else 95 | return ((task->jobctl & JOBCTL_TRAP_FREEZE) != 0); 96 | #endif 97 | } 98 | 99 | static inline bool line_is_frozen(struct task_struct *task) 100 | { 101 | return (cgroup_task_frozen(task) || rekernel_is_jobctl_frozen_compatible(task) || rekernel_is_frozen_state_compatible(task->group_leader) || freezing(task->group_leader)); 102 | } 103 | 104 | static int sendMessage(char *packet_buffer, uint16_t len) 105 | { 106 | struct sk_buff *socket_buffer; 107 | struct nlmsghdr *netlink_hdr; 108 | 109 | socket_buffer = nlmsg_new(len, GFP_ATOMIC); 110 | if (!socket_buffer) { 111 | pr_err("netlink alloc failure!\n"); 112 | return LINE_ERROR; 113 | } 114 | 115 | netlink_hdr = nlmsg_put(socket_buffer, 0, 0, netlink_unit, len, 0); 116 | if (netlink_hdr == NULL) { 117 | pr_err("nlmsg_put failaure!\n"); 118 | nlmsg_free(socket_buffer); 119 | return LINE_ERROR; 120 | } 121 | 122 | memcpy(nlmsg_data(netlink_hdr), packet_buffer, len); 123 | return netlink_unicast(netlink_socket, socket_buffer, USER_PORT, MSG_DONTWAIT); 124 | } 125 | 126 | #if defined(KERNEL_5_15) || defined(KERNEL_6_1) 127 | void line_binder_alloc_new_buf_locked(void *data, size_t size, size_t *free_async_space, int is_async) 128 | #elif defined(KERNEL_5_10) 129 | void line_binder_alloc_new_buf_locked(void *data, size_t size, struct binder_alloc *alloc, int is_async) 130 | #else 131 | void line_binder_alloc_new_buf_locked(void *data, size_t size, size_t *free_async_space, int is_async, bool *should_fail) 132 | #endif 133 | { 134 | struct task_struct *p = NULL; 135 | #ifndef KERNEL_5_10 136 | struct binder_alloc *alloc = NULL; 137 | 138 | alloc = container_of(free_async_space, struct binder_alloc, free_async_space); 139 | if (alloc == NULL) { 140 | return; 141 | } 142 | #endif 143 | if (is_async 144 | && (alloc->free_async_space < 3 * (size + sizeof(struct binder_buffer)) 145 | || (alloc->free_async_space < WARN_AHEAD_SPACE))) { 146 | rcu_read_lock(); 147 | p = find_task_by_vpid(alloc->pid); 148 | rcu_read_unlock(); 149 | if (p != NULL && line_is_frozen(p)) { 150 | #ifdef DEBUG 151 | pr_info("[Re-Kernel LKM] Binder Free buffer full! from=%d | target=%d\n", task_uid(current).val, task_uid(p).val); 152 | #endif 153 | if (netlink_socket != NULL) { 154 | char binder_kmsg[PACKET_SIZE]; 155 | snprintf(binder_kmsg, sizeof(binder_kmsg), "type=Binder,bindertype=free_buffer_full,oneway=1,from_pid=%d,from=%d,target_pid=%d,target=%d,rpc_name=%s,code=%d;", task_tgid_nr(current), task_uid(current).val, task_tgid_nr(p), task_uid(p).val, "FREE_BUFFER_FULL", -1); 156 | sendMessage(binder_kmsg, strlen(binder_kmsg)); 157 | } 158 | } 159 | } 160 | } 161 | 162 | struct hlist_head *binder_procs = NULL; 163 | struct mutex *binder_procs_lock = NULL; 164 | 165 | #if defined(KERNEL_5_10) || defined(KERNEL_5_15) || defined(KERNEL_6_1) 166 | void line_binder_preset(void *data, struct hlist_head *hhead, 167 | struct mutex *lock) 168 | #else 169 | void line_binder_preset(void *data, struct hlist_head *hhead, 170 | struct mutex *lock, struct binder_proc *proc) 171 | #endif 172 | { 173 | if (binder_procs == NULL) 174 | binder_procs = hhead; 175 | 176 | if (binder_procs_lock == NULL) 177 | binder_procs_lock = lock; 178 | } 179 | 180 | void line_binder_reply(void *data, struct binder_proc *target_proc, struct binder_proc *proc, 181 | struct binder_thread *thread, struct binder_transaction_data *tr) 182 | { 183 | if (target_proc 184 | && (NULL != target_proc->tsk) 185 | && (NULL != proc->tsk) 186 | && (task_uid(target_proc->tsk).val <= MAX_SYSTEM_UID) 187 | && (proc->pid != target_proc->pid) 188 | && line_is_frozen(target_proc->tsk)) { 189 | #ifdef DEBUG 190 | pr_info("[Re-Kernel LKM] Sync Binder Reply! from=%d | target=%d\n", task_uid(proc->tsk).val, task_uid(target_proc->tsk).val); 191 | #endif 192 | if (netlink_socket != NULL) { 193 | char binder_kmsg[PACKET_SIZE]; 194 | snprintf(binder_kmsg, sizeof(binder_kmsg), "type=Binder,bindertype=reply,oneway=0,from_pid=%d,from=%d,target_pid=%d,target=%d,rpc_name=%s,code=%d;", task_tgid_nr(proc->tsk), task_uid(proc->tsk).val, task_tgid_nr(target_proc->tsk), task_uid(target_proc->tsk).val, "SYNC_BINDER_REPLY", -1); 195 | sendMessage(binder_kmsg, strlen(binder_kmsg)); 196 | } 197 | } 198 | } 199 | 200 | #if defined(KERNEL_6_1) || defined(KERNEL_6_6) || defined(KERNEL_6_12) 201 | static long line_copy_from_user_nofault(void *dst, const void __user *src, size_t size) 202 | { 203 | long ret = -EFAULT; 204 | if (access_ok(src, size)) { 205 | pagefault_disable(); 206 | ret = __copy_from_user_inatomic(dst, src, size); 207 | pagefault_enable(); 208 | } 209 | if (ret) 210 | return -EFAULT; 211 | return 0; 212 | } 213 | #endif 214 | 215 | static long line_copy_from_user_compatible(void *dst, const void __user *src, size_t size) 216 | { 217 | #if defined(KERNEL_5_10) || defined(KERNEL_5_15) 218 | return copy_from_user(dst, src, size); 219 | #else 220 | return line_copy_from_user_nofault(dst, src, size); 221 | #endif 222 | } 223 | 224 | void line_binder_transaction(void *data, struct binder_proc *target_proc, struct binder_proc *proc, 225 | struct binder_thread *thread, struct binder_transaction_data *tr) 226 | { 227 | char buf_data[INTERFACETOKEN_BUFF_SIZE]; 228 | size_t buf_data_size; 229 | char buf[INTERFACETOKEN_BUFF_SIZE] = {0}; 230 | int i = 0; 231 | int j = 0; 232 | 233 | if (!(tr->flags & TF_ONE_WAY) /* sync binder */ 234 | && target_proc 235 | && (NULL != target_proc->tsk) 236 | && (NULL != proc->tsk) 237 | && (task_uid(target_proc->tsk).val > MIN_USERAPP_UID) 238 | && (proc->pid != target_proc->pid) 239 | && line_is_frozen(target_proc->tsk)) { 240 | #ifdef DEBUG 241 | pr_info("[Re-Kernel LKM] Sync Binder Transaction! from=%d | target=%d\n", task_uid(proc->tsk).val, task_uid(target_proc->tsk).val); 242 | #endif 243 | if (netlink_socket != NULL) { 244 | char binder_kmsg[PACKET_SIZE]; 245 | snprintf(binder_kmsg, sizeof(binder_kmsg), "type=Binder,bindertype=transaction,oneway=0,from_pid=%d,from=%d,target_pid=%d,target=%d,rpc_name=%s,code=%d;", task_tgid_nr(proc->tsk), task_uid(proc->tsk).val, task_tgid_nr(target_proc->tsk), task_uid(target_proc->tsk).val, "SYNC_BINDER", -1); 246 | sendMessage(binder_kmsg, strlen(binder_kmsg)); 247 | } 248 | } 249 | 250 | if ((tr->flags & TF_ONE_WAY) /* async binder */ 251 | && target_proc 252 | && (NULL != target_proc->tsk) 253 | && (NULL != proc->tsk) 254 | && (task_uid(target_proc->tsk).val > MIN_USERAPP_UID) 255 | && (proc->pid != target_proc->pid) 256 | && line_is_frozen(target_proc->tsk)) { 257 | buf_data_size = tr->data_size > INTERFACETOKEN_BUFF_SIZE ? INTERFACETOKEN_BUFF_SIZE : tr->data_size; 258 | if (!line_copy_from_user_compatible(buf_data, (char*)tr->data.ptr.buffer, buf_data_size)) { 259 | if (buf_data_size > PARCEL_OFFSET) { 260 | char *p = (char *)(buf_data) + PARCEL_OFFSET; 261 | j = PARCEL_OFFSET + 1; 262 | while (i < INTERFACETOKEN_BUFF_SIZE && j < buf_data_size && *p != '\0') { 263 | buf[i++] = *p; 264 | j += 2; 265 | p += 2; 266 | } 267 | if (i == INTERFACETOKEN_BUFF_SIZE) buf[i-1] = '\0'; 268 | } 269 | #ifdef DEBUG 270 | pr_info("[Re-Kernel LKM] ASync Binder Transaction! from=%d | target=%d\n", task_uid(proc->tsk).val, task_uid(target_proc->tsk).val); 271 | #endif 272 | if (netlink_socket != NULL) { 273 | char binder_kmsg[PACKET_SIZE]; 274 | snprintf(binder_kmsg, sizeof(binder_kmsg), "type=Binder,bindertype=transaction,oneway=1,from_pid=%d,from=%d,target_pid=%d,target=%d,rpc_name=%s,code=%d;", task_tgid_nr(proc->tsk), task_uid(proc->tsk).val, task_tgid_nr(target_proc->tsk), task_uid(target_proc->tsk).val, buf, tr->code); 275 | sendMessage(binder_kmsg, strlen(binder_kmsg)); 276 | } 277 | } 278 | } 279 | } 280 | 281 | static inline void binder_inner_proc_lock(struct binder_proc* proc) 282 | __acquires(&proc->inner_lock) 283 | { 284 | spin_lock(&proc->inner_lock); 285 | } 286 | 287 | static inline void binder_inner_proc_unlock(struct binder_proc* proc) 288 | __releases(&proc->inner_lock) 289 | { 290 | spin_unlock(&proc->inner_lock); 291 | } 292 | 293 | static inline void binder_node_lock(struct binder_node* node) 294 | __acquires(&node->lock) 295 | { 296 | spin_lock(&node->lock); 297 | } 298 | 299 | static inline void binder_node_unlock(struct binder_node* node) 300 | __releases(&node->lock) 301 | { 302 | spin_unlock(&node->lock); 303 | } 304 | 305 | static bool binder_can_update_transaction(struct binder_transaction* t1, struct binder_transaction* t2) 306 | { 307 | if ((t1->flags & t2->flags & TF_ONE_WAY) != TF_ONE_WAY || !t1->to_proc || !t2->to_proc) 308 | return false; 309 | if (t1->to_proc->tsk == t2->to_proc->tsk && t1->code == t2->code && 310 | t1->flags == t2->flags && t1->buffer->pid == t2->buffer->pid && 311 | t1->buffer->target_node->ptr == t2->buffer->target_node->ptr && 312 | t1->buffer->target_node->cookie == t2->buffer->target_node->cookie) 313 | return true; 314 | return false; 315 | } 316 | 317 | static struct binder_transaction* binder_find_outdated_transaction_ilocked(struct binder_transaction* t, 318 | struct list_head* target_list) 319 | { 320 | struct binder_work* w; 321 | bool second = false; 322 | 323 | list_for_each_entry(w, target_list, entry) { 324 | struct binder_transaction* t_queued; 325 | 326 | if (w->type != BINDER_WORK_TRANSACTION) 327 | continue; 328 | t_queued = container_of(w, struct binder_transaction, work); 329 | if (binder_can_update_transaction(t_queued, t)) { 330 | if (second) 331 | return t_queued; 332 | else 333 | second = true; 334 | } 335 | } 336 | return NULL; 337 | } 338 | 339 | static inline void __nocfi binder_release_entire_buffer(struct binder_proc* proc, 340 | struct binder_thread* thread, struct binder_buffer* buffer, bool is_failure) 341 | { 342 | binder_size_t off_end_offset; 343 | 344 | off_end_offset = ALIGN(buffer->data_size, sizeof(void*)); 345 | off_end_offset += buffer->offsets_size; 346 | 347 | re_binder_transaction_buffer_release(proc, thread, buffer, 348 | off_end_offset, is_failure); 349 | } 350 | 351 | static inline void binder_stats_deleted(enum binder_stat_types type) 352 | { 353 | atomic_inc(&re_binder_stats->obj_deleted[type]); 354 | } 355 | 356 | static int __nocfi binder_proc_transaction_pre(struct kprobe* p, struct pt_regs* regs) 357 | { 358 | struct binder_transaction* t = (struct binder_transaction*)regs->regs[0]; 359 | struct binder_proc* proc = (struct binder_proc*)regs->regs[1]; 360 | 361 | struct binder_node* node = t->buffer->target_node; 362 | struct binder_transaction* t_outdated = NULL; 363 | 364 | if (!node || !proc || proc->is_frozen || !(t->flags & TF_ONE_WAY)) 365 | return 0; 366 | 367 | if (line_is_frozen(proc->tsk)) { 368 | binder_node_lock(node); 369 | if (!node->has_async_transaction) { 370 | binder_node_unlock(node); 371 | return 0; 372 | } 373 | binder_inner_proc_lock(proc); 374 | t_outdated = binder_find_outdated_transaction_ilocked(t, &node->async_todo); 375 | if (t_outdated) { 376 | list_del_init(&t_outdated->work.entry); 377 | proc->outstanding_txns--; 378 | } 379 | binder_inner_proc_unlock(proc); 380 | binder_node_unlock(node); 381 | 382 | if (t_outdated) { 383 | struct binder_buffer* buffer = t_outdated->buffer; 384 | #ifdef DEBUG 385 | pr_info("[Re-Kernel LKM] free_outdated txn %d supersedes %d\n", t->debug_id, t_outdated->debug_id); 386 | #endif 387 | t_outdated->buffer = NULL; 388 | buffer->transaction = NULL; 389 | binder_release_entire_buffer(proc, NULL, buffer, false); 390 | re_binder_alloc_free_buf(&proc->alloc, buffer); 391 | kfree(t_outdated); 392 | binder_stats_deleted(BINDER_STAT_TRANSACTION); 393 | } 394 | } 395 | return 0; 396 | } 397 | 398 | void line_signal(void *data, int sig, struct task_struct *killer, struct task_struct *dst) 399 | { 400 | if (!dst || !killer) 401 | return; 402 | 403 | if (line_is_frozen(dst) && 404 | (sig == SIGKILL 405 | || sig == SIGTERM 406 | || sig == SIGABRT 407 | || sig == SIGQUIT)) { 408 | #ifdef DEBUG 409 | pr_info("[Re-Kernel LKM] Process Signal! signal=%d\n", sig); 410 | #endif 411 | if (netlink_socket != NULL) { 412 | char binder_kmsg[PACKET_SIZE]; 413 | snprintf(binder_kmsg, sizeof(binder_kmsg), "type=Signal,signal=%d,killer_pid=%d,killer=%d,dst_pid=%d,dst=%d;", sig, task_tgid_nr(killer), task_uid(killer).val, task_tgid_nr(dst), task_uid(dst).val); 414 | sendMessage(binder_kmsg, strlen(binder_kmsg)); 415 | } 416 | } 417 | } 418 | 419 | int register_binder(void) 420 | { 421 | int rc = LINE_SUCCESS; 422 | rc = register_trace_android_vh_binder_alloc_new_buf_locked(line_binder_alloc_new_buf_locked, NULL); 423 | if (rc != LINE_SUCCESS) { 424 | pr_err("register_trace_android_vh_binder_alloc_new_buf_locked failed, rc=%d\n", rc); 425 | return rc; 426 | } 427 | rc = register_trace_android_vh_binder_preset(line_binder_preset, NULL); 428 | if (rc != LINE_SUCCESS) { 429 | pr_err("register_trace_android_vh_binder_preset failed, rc=%d\n", rc); 430 | return rc; 431 | } 432 | rc = register_trace_android_vh_binder_reply(line_binder_reply, NULL); 433 | if (rc != LINE_SUCCESS) { 434 | pr_err("register_trace_android_vh_binder_reply failed, rc=%d\n", rc); 435 | return rc; 436 | } 437 | rc = register_trace_android_vh_binder_trans(line_binder_transaction, NULL); 438 | if (rc != LINE_SUCCESS) { 439 | pr_err("register_trace_android_vh_binder_trans failed, rc=%d\n", rc); 440 | return rc; 441 | } 442 | return LINE_SUCCESS; 443 | } 444 | 445 | void unregister_binder(void) 446 | { 447 | unregister_trace_android_vh_binder_alloc_new_buf_locked(line_binder_alloc_new_buf_locked, NULL); 448 | unregister_trace_android_vh_binder_preset(line_binder_preset, NULL); 449 | unregister_trace_android_vh_binder_reply(line_binder_reply, NULL); 450 | unregister_trace_android_vh_binder_trans(line_binder_transaction, NULL); 451 | } 452 | 453 | int register_signal(void) 454 | { 455 | int rc = LINE_SUCCESS; 456 | 457 | rc = register_trace_android_vh_do_send_sig_info(line_signal, NULL); 458 | if (rc != LINE_SUCCESS) { 459 | pr_err("register_trace_android_vh_do_send_sig_info failed, rc=%d\n", rc); 460 | return rc; 461 | } 462 | 463 | return LINE_SUCCESS; 464 | } 465 | 466 | static inline uid_t line_sock2uid(struct sock *sk) 467 | { 468 | if (sk && sk->sk_socket) 469 | return SOCK_INODE(sk->sk_socket)->i_uid.val; 470 | else 471 | return 0; 472 | } 473 | 474 | static unsigned int rekernel_pkg_ipv4_ipv6_in(void *priv, struct sk_buff *socket_buffer, 475 | const struct nf_hook_state *state) 476 | { 477 | struct sock *sk; 478 | unsigned int thoff = 0; 479 | unsigned short frag_off = 0; 480 | uid_t uid; 481 | uint hook; 482 | struct net_device *dev = NULL; 483 | 484 | if (!socket_buffer || !socket_buffer->len || !state) 485 | return NF_ACCEPT; 486 | 487 | hook = state->hook; 488 | if (NF_INET_LOCAL_IN == hook) 489 | dev = state->in; 490 | 491 | if (NULL == dev) 492 | return NF_ACCEPT; 493 | 494 | if (ip_hdr(socket_buffer)->version == 4) { 495 | if (ip_hdr(socket_buffer)->protocol != IPPROTO_TCP) 496 | return NF_ACCEPT; 497 | #if IS_ENABLED(CONFIG_IPV6) 498 | } else if (ip_hdr(socket_buffer)->version == 6) { 499 | if (ipv6_find_hdr(socket_buffer, &thoff, -1, &frag_off, NULL) != IPPROTO_TCP) 500 | return NF_ACCEPT; 501 | #endif 502 | } else { 503 | return NF_ACCEPT; 504 | } 505 | 506 | sk = skb_to_full_sk(socket_buffer); 507 | if (sk == NULL || !sk_fullsock(sk)) 508 | return NF_ACCEPT; 509 | 510 | uid = line_sock2uid(sk); 511 | if (uid < MIN_USERAPP_UID) 512 | return NF_ACCEPT; 513 | 514 | #ifdef DEBUG 515 | pr_info("[Re-Kernel LKM] Receive net data! target=%d\n", uid); 516 | #endif 517 | if (netlink_socket != NULL) { 518 | char binder_kmsg[PACKET_SIZE]; 519 | if (ip_hdr(socket_buffer)->version == 4) { 520 | snprintf(binder_kmsg, sizeof(binder_kmsg), "type=Network,target=%d,proto=ipv4;", uid); 521 | #if IS_ENABLED(CONFIG_IPV6) 522 | } else if (ip_hdr(socket_buffer)->version == 6) { 523 | snprintf(binder_kmsg, sizeof(binder_kmsg), "type=Network,target=%d,proto=ipv6;", uid); 524 | #endif 525 | } else { 526 | return NF_ACCEPT; 527 | } 528 | sendMessage(binder_kmsg, strlen(binder_kmsg)); 529 | } 530 | 531 | return NF_ACCEPT; 532 | } 533 | 534 | /* Only monitor input network packages */ 535 | static struct nf_hook_ops rekernel_nf_ops[] = { 536 | { 537 | .hook = rekernel_pkg_ipv4_ipv6_in, 538 | .pf = NFPROTO_IPV4, 539 | .hooknum = NF_INET_LOCAL_IN, 540 | .priority = NF_IP_PRI_SELINUX_LAST + 1, 541 | }, 542 | #if IS_ENABLED(CONFIG_IPV6) 543 | { 544 | .hook = rekernel_pkg_ipv4_ipv6_in, 545 | .pf = NFPROTO_IPV6, 546 | .hooknum = NF_INET_LOCAL_IN, 547 | .priority = NF_IP6_PRI_SELINUX_LAST + 1, 548 | } 549 | #endif 550 | }; 551 | 552 | void unregister_signal(void) 553 | { 554 | unregister_trace_android_vh_do_send_sig_info(line_signal, NULL); 555 | } 556 | 557 | void unregister_netfilter(void) 558 | { 559 | struct net *net; 560 | 561 | rtnl_lock(); 562 | for_each_net(net) { 563 | nf_unregister_net_hooks(net, rekernel_nf_ops, ARRAY_SIZE(rekernel_nf_ops)); 564 | } 565 | rtnl_unlock(); 566 | } 567 | 568 | int register_netfilter(void) 569 | { 570 | int rc = LINE_SUCCESS; 571 | struct net *net = NULL; 572 | 573 | spin_lock_init(&rekernel_map_lock); 574 | hash_init(rekernel_uid_map); 575 | hash_init(rekernel_p_uid_map); 576 | 577 | rtnl_lock(); 578 | for_each_net(net) { 579 | rc = nf_register_net_hooks(net, rekernel_nf_ops, ARRAY_SIZE(rekernel_nf_ops)); 580 | if (rc != LINE_SUCCESS) { 581 | pr_err("register netfilter hooks failed, rc=%d\n", rc); 582 | break; 583 | } 584 | } 585 | rtnl_unlock(); 586 | 587 | if (rc != LINE_SUCCESS) { 588 | unregister_netfilter(); 589 | return LINE_ERROR; 590 | } 591 | 592 | return LINE_SUCCESS; 593 | } 594 | 595 | static void netlink_rcv_msg(struct sk_buff *socket_buffer) 596 | { 597 | struct nlmsghdr *nlhdr = NULL; 598 | char *umsg = NULL; 599 | if (socket_buffer->len >= nlmsg_total_size(0)) { 600 | nlhdr = nlmsg_hdr(socket_buffer); 601 | umsg = NLMSG_DATA(nlhdr); 602 | if (umsg) { 603 | #ifdef DEBUG 604 | pr_info("Re-Kernel_netlink recv_from_user: %s\n", umsg); 605 | #endif 606 | if (strcmp(umsg, "#proc_remove") == 0) { 607 | if (rekernel_unit_entry) { 608 | proc_remove(rekernel_unit_entry); 609 | rekernel_unit_entry = NULL; 610 | } 611 | if (rekernel_dir) { 612 | proc_remove(rekernel_dir); 613 | rekernel_dir = NULL; 614 | } 615 | } 616 | } 617 | } 618 | } 619 | 620 | struct netlink_kernel_cfg cfg = { 621 | .input = netlink_rcv_msg, // set recv callback 622 | }; 623 | 624 | static int rekernel_unit_show(struct seq_file *m, void *v) 625 | { 626 | seq_printf(m, "%d\n", netlink_unit); 627 | return 0; 628 | } 629 | 630 | static int rekernel_unit_open(struct inode *inode, struct file *file) 631 | { 632 | return single_open(file, rekernel_unit_show, NULL); 633 | } 634 | 635 | static const struct proc_ops rekernel_unit_fops = { 636 | .proc_open = rekernel_unit_open, 637 | .proc_read = seq_read, 638 | .proc_lseek = seq_lseek, 639 | .proc_release = single_release, 640 | }; 641 | 642 | static struct kprobe kp_kallsyms_lookup_name = { 643 | .symbol_name = "kallsyms_lookup_name" 644 | }; 645 | static struct kprobe kp_binder_proc_transaction = { 646 | .symbol_name = "binder_proc_transaction", 647 | .pre_handler = binder_proc_transaction_pre 648 | }; 649 | 650 | int __nocfi register_kp(void) { 651 | int rc = LINE_SUCCESS; 652 | 653 | rc = register_kprobe(&kp_kallsyms_lookup_name); 654 | if (rc != LINE_SUCCESS) { 655 | pr_err("register kprobe hooks failed, rc=%d\n", rc); 656 | return rc; 657 | } 658 | re_kallsyms_lookup_name = (void*)kp_kallsyms_lookup_name.addr; 659 | unregister_kprobe(&kp_kallsyms_lookup_name); 660 | 661 | re_binder_transaction_buffer_release = (void*)re_kallsyms_lookup_name("binder_transaction_buffer_release"); 662 | re_binder_alloc_free_buf = (void*)re_kallsyms_lookup_name("binder_alloc_free_buf"); 663 | re_binder_stats = (void*)re_kallsyms_lookup_name("binder_stats"); 664 | 665 | if (re_binder_transaction_buffer_release == NULL || re_binder_alloc_free_buf == NULL || re_binder_stats == NULL) { 666 | rc = -EINVAL; 667 | pr_err("register kprobe kallsyms_lookup_name failed, rc=%d\n", rc); 668 | return rc; 669 | } 670 | 671 | register_kprobe(&kp_binder_proc_transaction); 672 | if (rc != LINE_SUCCESS) { 673 | pr_err("register binder_proc_transaction hooks failed, rc=%d\n", rc); 674 | return rc; 675 | } 676 | 677 | return LINE_SUCCESS; 678 | } 679 | 680 | void unregister_kp(void) { 681 | unregister_kprobe(&kp_binder_proc_transaction); 682 | } 683 | 684 | static int __init start_rekernel(void) 685 | { 686 | pr_info("Thank you for choosing Re:Kernel!\n"); 687 | #ifdef DEBUG 688 | pr_info("Debug mode is enabled!\n"); 689 | #endif 690 | #ifdef NETWORK_FILTER 691 | pr_info("NetFilter is enabled!\n"); 692 | #endif 693 | pr_info("Re:Kernel v8.5 | DEVELOPER: Sakion Team | Timeline | USER PORT: %d\n", USER_PORT); 694 | pr_info("Trying to create Re:Kernel Server......\n"); 695 | 696 | for (netlink_unit = NETLINK_REKERNEL_MIN; netlink_unit < NETLINK_REKERNEL_MAX; netlink_unit++) { 697 | netlink_socket = (struct sock *)netlink_kernel_create(&init_net, netlink_unit, &cfg); 698 | if (netlink_socket != NULL) 699 | break; 700 | } 701 | 702 | if (netlink_socket == NULL) { 703 | pr_err("Failed to create Re:Kernel server!\n"); 704 | return LINE_ERROR; 705 | } 706 | 707 | pr_info("Created Re:Kernel server! NETLINK UNIT: %d\n", netlink_unit); 708 | 709 | rekernel_dir = proc_mkdir("rekernel", NULL); 710 | if (!rekernel_dir) 711 | pr_err("create /proc/rekernel failed!\n"); 712 | else { 713 | char buff[32]; 714 | sprintf(buff, "%d", netlink_unit); 715 | rekernel_unit_entry = proc_create(buff, 716 | 0644, rekernel_dir, &rekernel_unit_fops); 717 | if (!rekernel_unit_entry) 718 | pr_err("create rekernel unit failed!\n"); 719 | } 720 | 721 | pr_info("Re-Kernel start hooking!\n"); 722 | 723 | if (register_binder() != LINE_SUCCESS) { 724 | pr_err("%s: Failed to hook binder!\n", __func__); 725 | return LINE_ERROR; 726 | } 727 | 728 | if (register_signal() != LINE_SUCCESS) { 729 | pr_err("%s: Failed to hook signal!\n", __func__); 730 | return LINE_ERROR; 731 | } 732 | 733 | #ifdef NETWORK_FILTER 734 | if (register_netfilter() != LINE_SUCCESS) { 735 | pr_err("%s: Failed to hook netfilter!\n", __func__); 736 | return LINE_ERROR; 737 | } 738 | #endif 739 | 740 | #ifdef CLEAN_UP_ASYNC_BINDER 741 | if (register_kp() != LINE_SUCCESS) { 742 | pr_err("%s: Failed to hook kprobe!\n", __func__); 743 | return LINE_ERROR; 744 | } 745 | #endif 746 | 747 | pr_info("Re-Kernel hooked!\n"); 748 | return LINE_SUCCESS; 749 | } 750 | 751 | static void __exit exit_rekernel(void) 752 | { 753 | pr_info("Re-Kernel closing...\n"); 754 | unregister_binder(); 755 | unregister_signal(); 756 | #ifdef NETWORK_FILTER 757 | unregister_netfilter(); 758 | #endif 759 | unregister_kp(); 760 | netlink_kernel_release(netlink_socket); 761 | } 762 | 763 | module_init(start_rekernel); 764 | module_exit(exit_rekernel); 765 | 766 | MODULE_LICENSE("GPL"); 767 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------