-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
366 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,50 @@ | ||
ifndef TARGET_COMPILE | ||
$(error TARGET_COMPILE not set) | ||
endif | ||
HR_VERSION := 1.2.0 | ||
|
||
ifndef KP_DIR | ||
KP_DIR = ../KernelPatch | ||
endif | ||
|
||
OS_NAME = $(shell uname | tr A-Z a-z) | ||
MACHINE = $(shell uname -m) | ||
NDK_BIN_DIR := toolchains/llvm/prebuilt/$(OS_NAME)-$(MACHINE)/bin | ||
ifdef ANDROID_NDK_LATEST_HOME | ||
NDK_PATH ?= $(ANDROID_NDK_LATEST_HOME)/$(NDK_BIN_DIR) | ||
else ifdef ANDROID_NDK | ||
NDK_PATH ?= $(ANDROID_NDK)/$(NDK_BIN_DIR) | ||
endif | ||
|
||
ifdef TARGET_COMPILE | ||
CC := $(TARGET_COMPILE)gcc | ||
LD := $(TARGET_COMPILE)ld | ||
else ifdef NDK_PATH | ||
CC := $(NDK_PATH)/aarch64-linux-android31-clang | ||
LD := $(NDK_PATH)/ld.lld | ||
endif | ||
|
||
CC = $(TARGET_COMPILE)gcc | ||
LD = $(TARGET_COMPILE)ld | ||
CFLAGS = -Wall -O2 -fno-PIC -fno-asynchronous-unwind-tables -fno-stack-protector -fno-common -DHR_VERSION=\"$(HR_VERSION)$(HR_VER)\" | ||
|
||
INCLUDE_DIRS := . include patch/include linux/include linux/arch/arm64/include linux/tools/arch/arm64/include | ||
|
||
INCLUDE_FLAGS := $(foreach dir,$(INCLUDE_DIRS),-I$(KP_DIR)/kernel/$(dir)) | ||
|
||
objs := hosts_redirect.o | ||
|
||
all: hosts_redirect.kpm | ||
all: hosts_redirect_$(HR_VERSION).kpm | ||
|
||
debug: CFLAGS += -DDEBUG | ||
debug: HR_VER := _d | ||
debug: hosts_redirect_$(HR_VERSION)_debug.kpm | ||
|
||
hosts_redirect_$(HR_VERSION).kpm: ${objs} | ||
${CC} -r -o $@ $^ | ||
|
||
hosts_redirect.kpm: ${objs} | ||
hosts_redirect_$(HR_VERSION)_debug.kpm: ${objs} | ||
${CC} -r -o $@ $^ | ||
|
||
%.o: %.c | ||
${CC} $(CFLAGS) $(INCLUDE_FLAGS) -T../demo.lds -c -O2 -o $@ $< | ||
${CC} $(CFLAGS) $(INCLUDE_FLAGS) -c -o $@ $< | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf *.kpm | ||
find . -name "*.o" | xargs rm -f | ||
find . -name "*.o" | xargs rm -f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
#ifndef __HR_HOSTS_REDIRECT_H | ||
#define __HR_HOSTS_REDIRECT_H | ||
|
||
#include <ktypes.h> | ||
#include <linux/llist.h> | ||
#include <linux/spinlock.h> | ||
|
||
#define HASH_LEN_DECLARE u32 hash; u32 len | ||
#define DNAME_INLINE_LEN 32 | ||
#define LOOKUP_FOLLOW 0x0001 | ||
|
||
struct vfsmount { | ||
struct dentry* mnt_root; | ||
struct super_block* mnt_sb; | ||
int mnt_flags; | ||
struct user_namespace* mnt_userns; | ||
// unknow | ||
}; | ||
struct hlist_bl_node { | ||
struct hlist_bl_node* next, ** pprev; | ||
}; | ||
struct qstr { | ||
union { | ||
struct { | ||
HASH_LEN_DECLARE; | ||
}; | ||
u64 hash_len; | ||
}; | ||
const unsigned char* name; | ||
}; | ||
struct dentry { | ||
unsigned int d_flags; | ||
spinlock_t d_seq; | ||
struct hlist_bl_node d_hash; | ||
struct dentry* d_parent; | ||
struct qstr d_name; | ||
struct inode* d_inode; | ||
unsigned char d_iname[DNAME_INLINE_LEN]; | ||
// unknow | ||
}; | ||
|
||
struct path { | ||
struct vfsmount* mnt; | ||
struct dentry* dentry; | ||
}; | ||
|
||
struct file { | ||
union { | ||
struct llist_node fu_llist; | ||
struct rcu_head fu_rcuhead; | ||
} f_u; | ||
struct path f_path; | ||
struct inode* f_inode; | ||
// unknow | ||
}; | ||
|
||
struct fs_struct { | ||
int users; | ||
spinlock_t lock; | ||
spinlock_t seq; | ||
int umask; | ||
int in_exec; | ||
struct path root, pwd; | ||
}; | ||
|
||
struct open_flags { | ||
int open_flag; | ||
umode_t mode; | ||
int acc_mode; | ||
int intent; | ||
int lookup_flags; | ||
}; | ||
|
||
#endif /* __HR_HOSTS_REDIRECT_H */ |
Oops, something went wrong.