*/
#include <ntddk.h>
-#include <stdlib.h>
#include "registry.h"
#include "assert.h"
#include "util.h"
-#define REGISTRY_POOL 'GERX'
+#define REGISTRY_TAG 'GERX'
static UNICODE_STRING RegistryPath;
IN ULONG Length
)
{
- return __AllocatePoolWithTag(NonPagedPool, Length, REGISTRY_POOL);
+ return __AllocatePoolWithTag(NonPagedPool, Length, REGISTRY_TAG);
}
static FORCEINLINE VOID
IN PVOID Buffer
)
{
- __FreePoolWithTag(Buffer, REGISTRY_POOL);
+ __FreePoolWithTag(Buffer, REGISTRY_TAG);
}
NTSTATUS
return status;
}
+NTSTATUS
+RegistryCreateKey(
+ IN HANDLE Parent,
+ IN PUNICODE_STRING Path,
+ IN ULONG Options,
+ OUT PHANDLE Key
+ )
+{
+ OBJECT_ATTRIBUTES Attributes;
+ NTSTATUS status;
+
+ InitializeObjectAttributes(&Attributes,
+ Path,
+ OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE,
+ Parent,
+ NULL);
+
+ status = ZwCreateKey(Key,
+ KEY_ALL_ACCESS,
+ &Attributes,
+ 0,
+ NULL,
+ Options,
+ NULL
+ );
+ if (!NT_SUCCESS(status))
+ goto fail1;
+
+ return STATUS_SUCCESS;
+
+fail1:
+ return status;
+}
+
NTSTATUS
RegistryOpenServiceKey(
IN ACCESS_MASK DesiredAccess,
return RegistryOpenKey(NULL, &RegistryPath, DesiredAccess, Key);
}
+NTSTATUS
+RegistryCreateServiceKey(
+ OUT PHANDLE Key
+ )
+{
+ return RegistryCreateKey(NULL, &RegistryPath, REG_OPTION_NON_VOLATILE, Key);
+}
+
NTSTATUS
RegistryOpenSoftwareKey(
IN PDEVICE_OBJECT DeviceObject,
ZwClose(SubKey);
+ (VOID) ZwFlushKey(Key);
+
RtlFreeUnicodeString(&Unicode);
return STATUS_SUCCESS;
RtlFreeUnicodeString(&Unicode);
+ (VOID) ZwFlushKey(Key);
+
return STATUS_SUCCESS;
fail2:
__RegistryFree(Partial);
+ (VOID) ZwFlushKey(Key);
+
RtlFreeUnicodeString(&Unicode);
return STATUS_SUCCESS;
if (!NT_SUCCESS(status))
goto fail4;
- *Buffer = NULL;
-
switch (Partial->Type) {
case REG_BINARY:
- *Length = Partial->DataLength;
-
- if (*Length == 0)
- break;
-
*Buffer = __RegistryAllocate(Partial->DataLength);
status = STATUS_NO_MEMORY;
if (*Buffer == NULL)
break;
+ *Length = Partial->DataLength;
RtlCopyMemory(*Buffer, Partial->Data, Partial->DataLength);
break;
default:
status = STATUS_INVALID_PARAMETER;
+ *Buffer = NULL;
break;
}
- if (!NT_SUCCESS(status))
+ if (*Buffer == NULL)
goto fail5;
__RegistryFree(Partial);
goto fail1;
Partial = __RegistryAllocate(FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data) +
- __min(Length, 1));
+ Length);
status = STATUS_NO_MEMORY;
if (Partial == NULL)
Partial->TitleIndex = 0;
Partial->Type = REG_BINARY;
-
- if (Length != 0) {
- Partial->DataLength = Length;
- RtlCopyMemory(Partial->Data, Buffer, Partial->DataLength);
- }
+ Partial->DataLength = Length;
+ RtlCopyMemory(Partial->Data, Buffer, Partial->DataLength);
status = ZwSetValueKey(Key,
&Unicode,
__RegistryFree(Partial);
+ (VOID) ZwFlushKey(Key);
+
RtlFreeUnicodeString(&Unicode);
return STATUS_SUCCESS;
__RegistryFree(Partial);
+ (VOID) ZwFlushKey(Key);
+
RtlFreeUnicodeString(&Unicode);
return STATUS_SUCCESS;