添加 KPM 模块支持,包括 KPM 配置选项、核心功能实现及相关头文件
This commit is contained in:
2
kernel/kpm/Makefile
Normal file
2
kernel/kpm/Makefile
Normal file
@@ -0,0 +1,2 @@
|
||||
obj-y += kpm.o
|
||||
obj-y += compact.o
|
||||
100
kernel/kpm/compact.c
Normal file
100
kernel/kpm/compact.c
Normal file
@@ -0,0 +1,100 @@
|
||||
#include <linux/export.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/kernel.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/kernfs.h>
|
||||
#include <linux/file.h>
|
||||
#include <linux/slab.h>
|
||||
#include <linux/vmalloc.h>
|
||||
#include <linux/uaccess.h>
|
||||
#include <linux/elf.h>
|
||||
#include <linux/kallsyms.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/rcupdate.h>
|
||||
#include <asm/elf.h> /* 包含 ARM64 重定位类型定义 */
|
||||
#include <linux/vmalloc.h>
|
||||
#include <linux/mm.h>
|
||||
#include <linux/string.h>
|
||||
#include <asm/cacheflush.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/vmalloc.h>
|
||||
#include <linux/set_memory.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/export.h>
|
||||
#include <linux/slab.h>
|
||||
#include "kpm.h"
|
||||
#include "compact.h"
|
||||
|
||||
unsigned long sukisu_compact_find_symbol(const char* name);
|
||||
|
||||
// ======================================================================
|
||||
|
||||
const char* kpver = "0.10";
|
||||
|
||||
struct CompactAddressSymbol {
|
||||
const char* symbol_name;
|
||||
void* addr;
|
||||
};
|
||||
|
||||
struct CompactAliasSymbol {
|
||||
const char* symbol_name;
|
||||
const char* compact_symbol_name;
|
||||
};
|
||||
|
||||
struct CompactAddressSymbol address_symbol [] = {
|
||||
{ "kallsyms_lookup_name", &kallsyms_lookup_name },
|
||||
{ "compact_find_symbol", &sukisu_compact_find_symbol },
|
||||
{ "compat_copy_to_user", ©_to_user },
|
||||
{ "compat_strncpy_from_user", &strncpy_from_user },
|
||||
{ "kpver", &kpver },
|
||||
{ "is_run_in_sukisu_ultra", (void*)1 }
|
||||
};
|
||||
|
||||
struct CompactAliasSymbol alias_symbol[] = {
|
||||
{"kf_strncat", "strncat"},
|
||||
{"kf_strlen", "strlen" },
|
||||
{"kf_strcpy", "strcpy"},
|
||||
{"compat_copy_to_user", "__arch_copy_to_user"}
|
||||
};
|
||||
|
||||
unsigned long sukisu_compact_find_symbol(const char* name) {
|
||||
int i;
|
||||
unsigned long addr;
|
||||
|
||||
// 先自己在地址表部分查出来
|
||||
for(i = 0; i < (sizeof(address_symbol) / sizeof(struct CompactAddressSymbol)); i++) {
|
||||
struct CompactAddressSymbol* symbol = &address_symbol[i];
|
||||
if(strcmp(name, symbol->symbol_name) == 0) {
|
||||
return (unsigned long) symbol->addr;
|
||||
}
|
||||
}
|
||||
|
||||
/* 如果符号名以 "kf__" 开头,尝试解析去掉前缀的部分 */
|
||||
if (strncmp(name, "kf__", 4) == 0) {
|
||||
const char *real_name = name + 4; // 去掉 "kf__"
|
||||
addr = (unsigned long)kallsyms_lookup_name(real_name);
|
||||
if (addr) {
|
||||
return addr;
|
||||
}
|
||||
}
|
||||
|
||||
// 通过内核来查
|
||||
addr = kallsyms_lookup_name(name);
|
||||
if(addr) {
|
||||
return addr;
|
||||
}
|
||||
|
||||
// 查不到就查查兼容的符号
|
||||
for(i = 0; i < (sizeof(alias_symbol) / sizeof(struct CompactAliasSymbol)); i++) {
|
||||
struct CompactAliasSymbol* symbol = &alias_symbol[i];
|
||||
if(strcmp(name, symbol->symbol_name) == 0) {
|
||||
addr = kallsyms_lookup_name(symbol->compact_symbol_name);
|
||||
if(addr)
|
||||
return addr;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
6
kernel/kpm/compact.h
Normal file
6
kernel/kpm/compact.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef ___SUKISU_KPM_COMPACT_H
|
||||
#define ___SUKISU_KPM_COMPACT_H
|
||||
|
||||
unsigned long sukisu_compact_find_symbol(const char* name);
|
||||
|
||||
#endif
|
||||
1340
kernel/kpm/kpm.c
Normal file
1340
kernel/kpm/kpm.c
Normal file
File diff suppressed because it is too large
Load Diff
44
kernel/kpm/kpm.h
Normal file
44
kernel/kpm/kpm.h
Normal file
@@ -0,0 +1,44 @@
|
||||
#ifndef ___SUKISU_KPM_H
|
||||
#define ___SUKISU_KPM_H
|
||||
|
||||
int sukisu_handle_kpm(unsigned long arg3, unsigned long arg4, unsigned long arg5);
|
||||
int sukisu_is_kpm_control_code(unsigned long arg2);
|
||||
|
||||
// KPM控制代码
|
||||
#define CMD_KPM_CONTROL 28
|
||||
#define CMD_KPM_CONTROL_MAX 34
|
||||
|
||||
// 控制代码
|
||||
|
||||
// prctl(xxx, xxx, 1, "PATH", "ARGS")
|
||||
// success return 0, error return -N
|
||||
#define SUKISU_KPM_LOAD 28
|
||||
|
||||
// prctl(xxx, xxx, 2, "NAME")
|
||||
// success return 0, error return -N
|
||||
#define SUKISU_KPM_UNLOAD 29
|
||||
|
||||
// num = prctl(xxx, xxx, 3)
|
||||
// error return -N
|
||||
// success return +num or 0
|
||||
#define SUKISU_KPM_NUM 30
|
||||
|
||||
// prctl(xxx, xxx, 4, Buffer, BufferSize)
|
||||
// success return +out, error return -N
|
||||
#define SUKISU_KPM_LIST 31
|
||||
|
||||
// prctl(xxx, xxx, 5, "NAME", Buffer[256])
|
||||
// success return +out, error return -N
|
||||
#define SUKISU_KPM_INFO 32
|
||||
|
||||
// prctl(xxx, xxx, 6, "NAME", "ARGS")
|
||||
// success return KPM's result value
|
||||
// error return -N
|
||||
#define SUKISU_KPM_CONTROL 33
|
||||
|
||||
// prctl(xxx, xxx, 7)
|
||||
// success will printf to stdout and return 0
|
||||
// error will return -1
|
||||
#define SUKISU_KPM_PRINT 34
|
||||
|
||||
#endif
|
||||
0
kernel/kpm/super_access.c
Normal file
0
kernel/kpm/super_access.c
Normal file
0
kernel/kpm/super_access.h
Normal file
0
kernel/kpm/super_access.h
Normal file
Reference in New Issue
Block a user