-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathutility.c
136 lines (102 loc) · 2.79 KB
/
utility.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#pragma warning(disable: 4267 6385 6386 6011 4242 4244)
#include "utility.h"
/*************************************************************************
Definitions
*************************************************************************/
#define PTDEF_UTIL_TAG_SPLIT 'PSTU'
#define PTDEF_UTIL_TAG_RETAR 'ARTU'
VOID
PtUtilSplitString(
_In_ PUNICODE_STRING InputString,
_Out_ PUNICODE_STRING Paths[128],
_Out_opt_ PULONG RetSize
)
/*++
Routine Description:
Takes a W3WProtect config string and splits it on semi colons.
Arguments:
InputString - W3WProtect config string that is item deliminated by a
semi colon.
RetArray - An array of the config strings. This should be placed
witin the `globals` structure.
RetSize - The size of retArray.
Returns:
STATUS_SUCCESS - Successfully split the string.
--*/
{
ULONG count = 0; // Counter for how many arrays we have.
WCHAR* buffer = InputString->Buffer;
WCHAR* bufferStart = InputString->Buffer;
// Zero the memory to ensure that there's no garbage data.
//RtlZeroMemory(RetArray, sizeof(InputString->Length));
//RetArray[*RetSize]->Buffer = InputString->Buffer;
while (buffer < InputString->Buffer + InputString->Length)
{
if (*buffer == ';')
{
Paths[count] = (PUNICODE_STRING)ExAllocatePoolWithTag(
PagedPool,
sizeof(UNICODE_STRING),
PTDEF_UTIL_TAG_RETAR
);
// Update the size of the string based on start of string minus current location.
Paths[count]->Length = (buffer - bufferStart) *sizeof(WCHAR);
Paths[count]->MaximumLength = Paths[count]->Length;
Paths[count]->Buffer = (PWCH)ExAllocatePoolWithTag(
PagedPool,
(buffer - bufferStart) * sizeof(WCHAR),
PTDEF_UTIL_TAG_RETAR
);
RtlCopyMemory(
Paths[count]->Buffer,
bufferStart,
Paths[count]->Length
);
count += 1;
// Add one to the existing buffer to skip the semi-colon if we're not at the
// end of the string. .
if (buffer + 1 < InputString->Buffer + InputString->Length)
bufferStart = buffer + 1;
}
buffer++;
}
*RetSize = count;
return;
}
BOOLEAN
PtContainsUnicodeString
(
_In_ PCUNICODE_STRING uString,
_In_ PWSTR cString
)
/*++
Routine Description:
Takes a UNICODE_STRING and sees if the PWSTR is within.
Arguments:
uString - UNICODE_STRING to compare against.
cString - String to comapare.
Returns:
TRUE - String was found.
FALSE - String wasn't found.
--*/
{
ULONG cLen = wcslen(cString);
PWCHAR buffer = uString->Buffer;
PWCHAR bufferEnd = uString->Buffer + (uString->Length / sizeof(WCHAR));
while (buffer < bufferEnd)
{
if (*buffer == *cString)
{
for (ULONG i = 0; i < cLen; i++)
{
if (*(buffer + i) != *(cString + i))
goto Increment;
}
return TRUE;
}
// Increment lets out break out of multiple loops.
Increment:
buffer++;
}
return FALSE;
}