1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
|
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/sched.h>
#include <linux/sched/signal.h>
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Biswa Kalyan Bhuyan");
MODULE_DESCRIPTION("Process explorer");
MODULE_VERSION("0.1");
// Find processes matching a name or PID
static int find_process(const char *name, unsigned int target_pid)
{
struct task_struct *task;
int process_count = 0;
int hidden_count = 0;
printk(KERN_INFO "Process Explorer: Enumerating all processes\n");
// Loop through all processes in the system
for_each_process(task) {
process_count++;
// If we're searching for a specific PID or name
if (target_pid > 0 && task->pid == target_pid) {
printk(KERN_INFO "Process Explorer: Found PID %d, Name: %s\n",
task->pid, task->comm);
// Print parent process info
if (task->parent) {
printk(KERN_INFO "Process Explorer: Parent PID %d, Name: %s\n",
task->parent->pid, task->parent->comm);
}
// Print additional info
printk(KERN_INFO "Process Explorer: User ID: %d, Group ID: %d\n",
task->cred->uid.val, task->cred->gid.val);
hidden_count++;
}
else if (name && strncmp(task->comm, name, TASK_COMM_LEN) == 0) {
printk(KERN_INFO "Process Explorer: Found PID %d with name %s\n",
task->pid, task->comm);
hidden_count++;
}
}
printk(KERN_INFO "Process Explorer: Total processes: %d\n", process_count);
if (target_pid > 0 || name) {
printk(KERN_INFO "Process Explorer: Found %d matching processes\n", hidden_count);
}
return 0;
}
// Module parameters
static unsigned int target_pid = 0;
module_param(target_pid, uint, 0644);
MODULE_PARM_DESC(target_pid, "Target process ID to search for");
static char *target_name = NULL;
module_param(target_name, charp, 0644);
MODULE_PARM_DESC(target_name, "Target process name to search for");
// Module initialization
static int __init proc_explorer_init(void)
{
printk(KERN_INFO "Process Explorer: Module loaded\n");
// Search for a specific process if provided
if (target_pid > 0) {
printk(KERN_INFO "Process Explorer: Searching for PID %u\n", target_pid);
} else if (target_name) {
printk(KERN_INFO "Process Explorer: Searching for processes named '%s'\n", target_name);
} else {
printk(KERN_INFO "Process Explorer: No search criteria provided. Use 'target_pid' or 'target_name' parameters.\n");
return 0;
}
// Find and print process info
find_process(target_name, target_pid);
return 0;
}
// Module cleanup
static void __exit proc_explorer_exit(void)
{
printk(KERN_INFO "Process Explorer: Module unloaded\n");
}
module_init(proc_explorer_init);
module_exit(proc_explorer_exit);
|