From cfdbecef5b657aec18179bc7651ad5f19b393f80 Mon Sep 17 00:00:00 2001 From: DavadDi Date: Sun, 10 Apr 2022 19:42:05 +0800 Subject: [PATCH] add get_inst.c --- hello_kernel_module/get_inst.c | 43 ++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 hello_kernel_module/get_inst.c diff --git a/hello_kernel_module/get_inst.c b/hello_kernel_module/get_inst.c new file mode 100644 index 0000000..ad3ff06 --- /dev/null +++ b/hello_kernel_module/get_inst.c @@ -0,0 +1,43 @@ +#include +#include +#include +#include + +static struct kprobe kp = { + .symbol_name = "kallsyms_lookup_name" +}; + +static int __init hello_init(void) +{ + typedef unsigned long (*kallsyms_lookup_name_t)(const char *name); + kallsyms_lookup_name_t kallsyms_lookup_name; + int i = 0; + register_kprobe(&kp); + kallsyms_lookup_name = (kallsyms_lookup_name_t) kp.addr; + unregister_kprobe(&kp); + + char *func_addr = (char *)kallsyms_lookup_name("__do_sys_fork"); + + for (i = 0; i < 5; i++) + { + pr_info("fun addr 0x%02x ", (u8)func_addr[i]); + } + + pr_info("fun addr 0x%lx\n", func_addr); + return 0; +} +module_init(hello_init); + + +static void __exit hello_exit(void) +{ + printk("Hello World Module Exit\n"); +} +module_exit(hello_exit); + + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("dwh0403"); +MODULE_DESCRIPTION("hello world module"); +MODULE_ALIAS("hello_module"); +