Add a filter to the linked list of filters. @param MatchString - The string to filter with. @param OperationFlag - Specifies what operations this filter should be used for. @param SaveFilters - Whether or not to save filters. @return A random identifier required for future operations with the new filter. */
| 101 | @return A random identifier required for future operations with the new filter. |
| 102 | */ |
| 103 | ULONG |
| 104 | StringFilters::AddFilter ( |
| 105 | _In_ WCHAR* MatchString, |
| 106 | _In_ ULONG OperationFlag, |
| 107 | _In_ BOOLEAN SaveFilters |
| 108 | ) |
| 109 | { |
| 110 | PFILTER_INFO_LINKED newFilter; |
| 111 | LARGE_INTEGER currentTime; |
| 112 | ULONG epochSeconds; |
| 113 | |
| 114 | if (this == NULL || this->destroying) |
| 115 | { |
| 116 | return NULL; |
| 117 | } |
| 118 | |
| 119 | // |
| 120 | // Get an exclusive lock because we're modifying the filters linked list. |
| 121 | // |
| 122 | FltAcquirePushLockExclusive(&this->filtersLock); |
| 123 | |
| 124 | // |
| 125 | // Allocate space for the new filter. |
| 126 | // |
| 127 | newFilter = RCAST<PFILTER_INFO_LINKED>(ExAllocatePoolWithTag(NonPagedPool, sizeof(FILTER_INFO_LINKED), FILTER_INFO_TAG)); |
| 128 | if (newFilter == NULL) |
| 129 | { |
| 130 | DBGPRINT("Failed to allocate space for filter info."); |
| 131 | goto Exit; |
| 132 | } |
| 133 | |
| 134 | memset(RCAST<PVOID>(newFilter), 0, sizeof(FILTER_INFO_LINKED)); |
| 135 | |
| 136 | InsertTailList(RCAST<PLIST_ENTRY>(this->filtersHead), RCAST<PLIST_ENTRY>(newFilter)); |
| 137 | |
| 138 | this->filtersCount++; |
| 139 | |
| 140 | // |
| 141 | // Generate a pseudo-random ID for the filter using the system time. |
| 142 | // |
| 143 | KeQuerySystemTime(¤tTime); |
| 144 | RtlTimeToSecondsSince1970(¤tTime, &epochSeconds); |
| 145 | newFilter->Filter.Id = RtlRandomEx(&epochSeconds); |
| 146 | newFilter->Filter.Type = this->filterType; |
| 147 | |
| 148 | // |
| 149 | // Copy the filter string to the new filter. |
| 150 | // |
| 151 | wcsncpy_s(newFilter->Filter.MatchString, MatchString, MAX_PATH); |
| 152 | |
| 153 | // |
| 154 | // Set the operation flags for this filter. |
| 155 | // |
| 156 | newFilter->Filter.Flags = OperationFlag; |
| 157 | Exit: |
| 158 | // |
| 159 | // New filter has been initialized, release the lock. |
| 160 | // |
no test coverage detected