-
Notifications
You must be signed in to change notification settings - Fork 22
/
DbgIsMyProcess.c
98 lines (80 loc) · 1.9 KB
/
DbgIsMyProcess.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
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
96
97
98
#include "ntddk.h"
typedef struct _DbgProcess
{
LIST_ENTRY64 DbgProcessList;
PEPROCESS DebugProcess;
PEPROCESS Process;
POBJECT_TYPE DebugObject;
HANDLE DbgHanle;
}DbgProcess, *PDbgProcess;
static LIST_ENTRY64 DbgList;
static KSPIN_LOCK d_lock;
VOID InitialzeDbgprocessList(){
KeInitializeSpinLock(&d_lock);
InitializeListHead(&DbgList);
}
PDbgProcess Debug_AddStructToList(PDbgProcess DbgStruct){
PDbgProcess pstruct = NULL;
if (MmIsAddressValid(DbgStruct)==TRUE)
{
pstruct = (PDbgProcess)ExAllocatePoolWithTag(NonPagedPool, sizeof(DbgProcess), "dbx");
if (!pstruct)
{
return FALSE;
}
RtlZeroMemory(pstruct, sizeof(DbgProcess));
pstruct->DbgHanle = DbgStruct->DbgHanle;
pstruct->DebugObject = DbgStruct->DebugObject;
pstruct->DebugProcess = DbgStruct->DebugProcess;
pstruct->Process = DbgStruct->Process;
ExInterlockedInsertTailList(&DbgList, &pstruct->DbgProcessList, &d_lock);
return pstruct;
}
return FALSE;
}
VOID NTAPI Debug_ExFreeItem(PDbgProcess Item)
{
KIRQL OldIrql;
KeAcquireSpinLock(&d_lock, &OldIrql);
RemoveEntryList(&Item->DbgProcessList);
KeReleaseSpinLock(&d_lock, OldIrql);
ExFreePool(Item);
return;
}
PDbgProcess Debug_FindMyNeedData(PDbgProcess DbgStruct){
DbgProcess*Temp = NULL;
DbgProcess*RetFind = NULL;
KIRQL irql;
PLIST_ENTRY64 Entry = NULL;
if (MmIsAddressValid(DbgStruct)==TRUE)
{
KeAcquireSpinLock(&d_lock, &irql);
Entry = DbgList.Flink;
while (Entry != &DbgList){
Temp = CONTAINING_RECORD(Entry, DbgProcess, DbgProcessList);
Entry= Entry->Flink;
if (Temp->DbgHanle==DbgStruct->DbgHanle)
{
RetFind = Temp;
break;
}
if (Temp->DebugObject == DbgStruct->DebugObject)
{
RetFind = Temp;
break;
}
if (Temp->DebugProcess == DbgStruct->DebugProcess)
{
RetFind = Temp;
break;
}
if (Temp->Process == DbgStruct->Process)
{
RetFind = Temp;
break;
}
}
KeReleaseSpinLock(&d_lock, irql);
}
return RetFind;
}