Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cfdbece

Browse files
committed
add get_inst.c
1 parent 52f25aa commit cfdbece

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

hello_kernel_module/get_inst.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <linux/init.h>
2+
#include <linux/module.h>
3+
#include <linux/kallsyms.h>
4+
#include <linux/kprobes.h>
5+
6+
static struct kprobe kp = {
7+
.symbol_name = "kallsyms_lookup_name"
8+
};
9+
10+
static int __init hello_init(void)
11+
{
12+
typedef unsigned long (*kallsyms_lookup_name_t)(const char *name);
13+
kallsyms_lookup_name_t kallsyms_lookup_name;
14+
int i = 0;
15+
register_kprobe(&kp);
16+
kallsyms_lookup_name = (kallsyms_lookup_name_t) kp.addr;
17+
unregister_kprobe(&kp);
18+
19+
char *func_addr = (char *)kallsyms_lookup_name("__do_sys_fork");
20+
21+
for (i = 0; i < 5; i++)
22+
{
23+
pr_info("fun addr 0x%02x ", (u8)func_addr[i]);
24+
}
25+
26+
pr_info("fun addr 0x%lx\n", func_addr);
27+
return 0;
28+
}
29+
module_init(hello_init);
30+
31+
32+
static void __exit hello_exit(void)
33+
{
34+
printk("Hello World Module Exit\n");
35+
}
36+
module_exit(hello_exit);
37+
38+
39+
MODULE_LICENSE("GPL");
40+
MODULE_AUTHOR("dwh0403");
41+
MODULE_DESCRIPTION("hello world module");
42+
MODULE_ALIAS("hello_module");
43+

0 commit comments

Comments
 (0)