Simplified NtDll API importing

This commit is contained in:
PatrickvL 2016-11-24 00:18:55 +01:00
parent a0e9bc9724
commit 51fdab2139
2 changed files with 117 additions and 100 deletions

View File

@ -49,53 +49,57 @@ namespace NtDll
// ******************************************************************
static HMODULE hNtDll = GetModuleHandle("ntdll");
NtDll::FPTR_RtlInitAnsiString NtDll::RtlInitAnsiString = (NtDll::FPTR_RtlInitAnsiString)GetProcAddress(hNtDll, "RtlInitAnsiString");
NtDll::FPTR_RtlInitUnicodeString NtDll::RtlInitUnicodeString = (NtDll::FPTR_RtlInitUnicodeString)GetProcAddress(hNtDll, "RtlInitUnicodeString");
NtDll::FPTR_RtlAnsiStringToUnicodeString NtDll::RtlAnsiStringToUnicodeString = (NtDll::FPTR_RtlAnsiStringToUnicodeString)GetProcAddress(hNtDll, "RtlAnsiStringToUnicodeString");
NtDll::FPTR_RtlAppendStringToString NtDll::RtlAppendStringToString = (NtDll::FPTR_RtlAppendStringToString)GetProcAddress(hNtDll, "RtlAppendStringToString");
NtDll::FPTR_RtlUnicodeStringToAnsiString NtDll::RtlUnicodeStringToAnsiString = (NtDll::FPTR_RtlUnicodeStringToAnsiString)GetProcAddress(hNtDll, "RtlUnicodeStringToAnsiString");
NtDll::FPTR_RtlFreeAnsiString NtDll::RtlFreeAnsiString = (NtDll::FPTR_RtlFreeAnsiString)GetProcAddress(hNtDll, "RtlFreeAnsiString");
NtDll::FPTR_RtlNtStatusToDosError NtDll::RtlNtStatusToDosError = (NtDll::FPTR_RtlNtStatusToDosError)GetProcAddress(hNtDll, "RtlNtStatusToDosError");
NtDll::FPTR_RtlTimeFieldsToTime NtDll::RtlTimeFieldsToTime = (NtDll::FPTR_RtlTimeFieldsToTime)GetProcAddress(hNtDll, "RtlTimeFieldsToTime");
NtDll::FPTR_RtlTimeToTimeFields NtDll::RtlTimeToTimeFields = (NtDll::FPTR_RtlTimeToTimeFields)GetProcAddress(hNtDll, "RtlTimeToTimeFields");
NtDll::FPTR_RtlTryEnterCriticalSection NtDll::RtlTryEnterCriticalSection = (NtDll::FPTR_RtlTryEnterCriticalSection)GetProcAddress(hNtDll, "RtlTryEnterCriticalSection");
NtDll::FPTR_RtlInitializeCriticalSection NtDll::RtlInitializeCriticalSection = (NtDll::FPTR_RtlInitializeCriticalSection)GetProcAddress(hNtDll, "RtlInitializeCriticalSection");
NtDll::FPTR_RtlEnterCriticalSection NtDll::RtlEnterCriticalSection = (NtDll::FPTR_RtlEnterCriticalSection)GetProcAddress(hNtDll, "RtlEnterCriticalSection");
NtDll::FPTR_RtlLeaveCriticalSection NtDll::RtlLeaveCriticalSection = (NtDll::FPTR_RtlLeaveCriticalSection)GetProcAddress(hNtDll, "RtlLeaveCriticalSection");
NtDll::FPTR_RtlCreateHeap NtDll::RtlCreateHeap = (NtDll::FPTR_RtlCreateHeap)GetProcAddress(hNtDll, "RtlCreateHeap");
NtDll::FPTR_RtlAllocateHeap NtDll::RtlAllocateHeap = (NtDll::FPTR_RtlAllocateHeap)GetProcAddress(hNtDll, "RtlAllocateHeap");
NtDll::FPTR_RtlFreeHeap NtDll::RtlFreeHeap = (NtDll::FPTR_RtlFreeHeap)GetProcAddress(hNtDll, "RtlFreeHeap");
NtDll::FPTR_RtlReAllocateHeap NtDll::RtlReAllocateHeap = (NtDll::FPTR_RtlReAllocateHeap)GetProcAddress(hNtDll, "RtlReAllocateHeap");
NtDll::FPTR_RtlSizeHeap NtDll::RtlSizeHeap = (NtDll::FPTR_RtlSizeHeap)GetProcAddress(hNtDll, "RtlSizeHeap");
NtDll::FPTR_RtlDestroyHeap NtDll::RtlDestroyHeap = (NtDll::FPTR_RtlDestroyHeap)GetProcAddress(hNtDll, "RtlDestroyHeap");
NtDll::FPTR_RtlEqualString NtDll::RtlEqualString = (NtDll::FPTR_RtlEqualString)GetProcAddress(hNtDll, "RtlEqualString");
NtDll::FPTR_NtWaitForSingleObject NtDll::NtWaitForSingleObject = (NtDll::FPTR_NtWaitForSingleObject)GetProcAddress(hNtDll, "NtWaitForSingleObject");
NtDll::FPTR_NtWaitForMultipleObjects NtDll::NtWaitForMultipleObjects = (NtDll::FPTR_NtWaitForMultipleObjects)GetProcAddress(hNtDll, "NtWaitForMultipleObjects");
NtDll::FPTR_NtAllocateVirtualMemory NtDll::NtAllocateVirtualMemory = (NtDll::FPTR_NtAllocateVirtualMemory)GetProcAddress(hNtDll, "NtAllocateVirtualMemory");
NtDll::FPTR_NtFreeVirtualMemory NtDll::NtFreeVirtualMemory = (NtDll::FPTR_NtFreeVirtualMemory)GetProcAddress(hNtDll, "NtFreeVirtualMemory");
NtDll::FPTR_NtQueryVirtualMemory NtDll::NtQueryVirtualMemory = (NtDll::FPTR_NtQueryVirtualMemory)GetProcAddress(hNtDll, "NtQueryVirtualMemory");
NtDll::FPTR_NtClearEvent NtDll::NtClearEvent = (NtDll::FPTR_NtClearEvent)GetProcAddress(hNtDll, "NtClearEvent");
NtDll::FPTR_NtClose NtDll::NtClose = (NtDll::FPTR_NtClose)GetProcAddress(hNtDll, "NtClose");
NtDll::FPTR_NtDelayExecution NtDll::NtDelayExecution = (NtDll::FPTR_NtDelayExecution)GetProcAddress(hNtDll, "NtDelayExecution");
NtDll::FPTR_NtDuplicateObject NtDll::NtDuplicateObject = (NtDll::FPTR_NtDuplicateObject)GetProcAddress(hNtDll, "NtDuplicateObject");
NtDll::FPTR_NtFlushBuffersFile NtDll::NtFlushBuffersFile = (NtDll::FPTR_NtFlushBuffersFile)GetProcAddress(hNtDll, "NtFlushBuffersFile");
NtDll::FPTR_NtQueryInformationFile NtDll::NtQueryInformationFile = (NtDll::FPTR_NtQueryInformationFile)GetProcAddress(hNtDll, "NtQueryInformationFile");
NtDll::FPTR_NtQueryDirectoryFile NtDll::NtQueryDirectoryFile = (NtDll::FPTR_NtQueryDirectoryFile)GetProcAddress(hNtDll, "NtQueryDirectoryFile");
NtDll::FPTR_NtQueryFullAttributesFile NtDll::NtQueryFullAttributesFile = (NtDll::FPTR_NtQueryFullAttributesFile)GetProcAddress(hNtDll, "NtQueryFullAttributesFile");
NtDll::FPTR_NtQueryVolumeInformationFile NtDll::NtQueryVolumeInformationFile = (NtDll::FPTR_NtQueryVolumeInformationFile)GetProcAddress(hNtDll, "NtQueryVolumeInformationFile");
NtDll::FPTR_NtCreateEvent NtDll::NtCreateEvent = (NtDll::FPTR_NtCreateEvent)GetProcAddress(hNtDll, "NtCreateEvent");
NtDll::FPTR_NtCreateMutant NtDll::NtCreateMutant = (NtDll::FPTR_NtCreateMutant)GetProcAddress(hNtDll, "NtCreateMutant");
NtDll::FPTR_NtReleaseMutant NtDll::NtReleaseMutant = (NtDll::FPTR_NtReleaseMutant)GetProcAddress(hNtDll, "NtReleaseMutant");
NtDll::FPTR_NtCreateSemaphore NtDll::NtCreateSemaphore = (NtDll::FPTR_NtCreateSemaphore)GetProcAddress(hNtDll, "NtCreateSemaphore");
NtDll::FPTR_NtReleaseSemaphore NtDll::NtReleaseSemaphore = (NtDll::FPTR_NtReleaseSemaphore)GetProcAddress(hNtDll, "NtReleaseSemaphore");
NtDll::FPTR_NtCreateDirectoryObject NtDll::NtCreateDirectoryObject = (NtDll::FPTR_NtCreateDirectoryObject)GetProcAddress(hNtDll, "NtCreateDirectoryObject");
NtDll::FPTR_NtCreateFile NtDll::NtCreateFile = (NtDll::FPTR_NtCreateFile)GetProcAddress(hNtDll, "NtCreateFile");
NtDll::FPTR_NtReadFile NtDll::NtReadFile = (NtDll::FPTR_NtReadFile)GetProcAddress(hNtDll, "NtReadFile");
NtDll::FPTR_NtWriteFile NtDll::NtWriteFile = (NtDll::FPTR_NtWriteFile)GetProcAddress(hNtDll, "NtWriteFile");
NtDll::FPTR_NtYieldExecution NtDll::NtYieldExecution = (NtDll::FPTR_NtYieldExecution)GetProcAddress(hNtDll, "NtYieldExecution");
NtDll::FPTR_NtSetInformationFile NtDll::NtSetInformationFile = (NtDll::FPTR_NtSetInformationFile)GetProcAddress(hNtDll, "NtSetInformationFile");
NtDll::FPTR_NtSetEvent NtDll::NtSetEvent = (NtDll::FPTR_NtSetEvent)GetProcAddress(hNtDll, "NtSetEvent");
NtDll::FPTR_NtSuspendThread NtDll::NtSuspendThread = (NtDll::FPTR_NtSuspendThread)GetProcAddress(hNtDll, "NtSuspendThread");
NtDll::FPTR_NtResumeThread NtDll::NtResumeThread = (NtDll::FPTR_NtResumeThread)GetProcAddress(hNtDll, "NtResumeThread");
NtDll::FPTR_NtSetLdtEntries NtDll::NtSetLdtEntries = (NtDll::FPTR_NtSetLdtEntries)GetProcAddress(hNtDll, "NtSetLdtEntries");
NtDll::FPTR_NtQueueApcThread NtDll::NtQueueApcThread = (NtDll::FPTR_NtQueueApcThread)GetProcAddress(hNtDll, "NtQueueApcThread");
#define IMPORT(API) \
NtDll::FPTR_##API NtDll::API = (NtDll::FPTR_##API)GetProcAddress(hNtDll, #API)
IMPORT(RtlInitAnsiString);
IMPORT(RtlInitUnicodeString);
IMPORT(RtlAnsiStringToUnicodeString);
IMPORT(RtlAppendStringToString);
IMPORT(RtlAppendUnicodeStringToString);
IMPORT(RtlUnicodeStringToAnsiString);
IMPORT(RtlFreeAnsiString);
IMPORT(RtlNtStatusToDosError);
IMPORT(RtlTimeFieldsToTime);
IMPORT(RtlTimeToTimeFields);
IMPORT(RtlTryEnterCriticalSection);
IMPORT(RtlInitializeCriticalSection);
IMPORT(RtlEnterCriticalSection);
IMPORT(RtlLeaveCriticalSection);
IMPORT(RtlCreateHeap);
IMPORT(RtlAllocateHeap);
IMPORT(RtlFreeHeap);
IMPORT(RtlReAllocateHeap);
IMPORT(RtlSizeHeap);
IMPORT(RtlDestroyHeap);
IMPORT(RtlEqualString);
IMPORT(NtWaitForSingleObject);
IMPORT(NtWaitForMultipleObjects);
IMPORT(NtAllocateVirtualMemory);
IMPORT(NtFreeVirtualMemory);
IMPORT(NtQueryVirtualMemory);
IMPORT(NtClearEvent);
IMPORT(NtClose);
IMPORT(NtDelayExecution);
IMPORT(NtDuplicateObject);
IMPORT(NtFlushBuffersFile);
IMPORT(NtQueryInformationFile);
IMPORT(NtQueryDirectoryFile);
IMPORT(NtQueryFullAttributesFile);
IMPORT(NtQueryVolumeInformationFile);
IMPORT(NtCreateEvent);
IMPORT(NtCreateMutant);
IMPORT(NtReleaseMutant);
IMPORT(NtCreateSemaphore);
IMPORT(NtReleaseSemaphore);
IMPORT(NtCreateDirectoryObject);
IMPORT(NtCreateFile);
IMPORT(NtReadFile);
IMPORT(NtWriteFile);
IMPORT(NtYieldExecution);
IMPORT(NtSetInformationFile);
IMPORT(NtSetEvent);
IMPORT(NtSuspendThread);
IMPORT(NtResumeThread);
IMPORT(NtSetLdtEntries);
IMPORT(NtQueueApcThread);

View File

@ -704,6 +704,15 @@ typedef NTSTATUS(NTAPI *FPTR_RtlAppendStringToString)
IN PSTRING Source
);
// ******************************************************************
// * RtlAppendUnicodeStringToString
// ******************************************************************
typedef NTSTATUS(NTAPI *FPTR_RtlAppendUnicodeStringToString)
(
IN OUT PUNICODE_STRING Destination,
IN PUNICODE_STRING Source
);
// ******************************************************************
// * RtlUnicodeStringToAnsiString
// ******************************************************************
@ -1143,56 +1152,60 @@ typedef PVOID (NTAPI *FPTR_RtlDestroyHeap)
// ******************************************************************
// * Exported API
// ******************************************************************
extern FPTR_RtlInitAnsiString RtlInitAnsiString;
extern FPTR_RtlInitUnicodeString RtlInitUnicodeString;
extern FPTR_RtlAnsiStringToUnicodeString RtlAnsiStringToUnicodeString;
extern FPTR_RtlAppendStringToString RtlAppendStringToString;
extern FPTR_RtlUnicodeStringToAnsiString RtlUnicodeStringToAnsiString;
extern FPTR_RtlFreeAnsiString RtlFreeAnsiString;
extern FPTR_RtlNtStatusToDosError RtlNtStatusToDosError;
extern FPTR_RtlTimeFieldsToTime RtlTimeFieldsToTime;
extern FPTR_RtlTimeToTimeFields RtlTimeToTimeFields;
extern FPTR_RtlTryEnterCriticalSection RtlTryEnterCriticalSection;
extern FPTR_RtlInitializeCriticalSection RtlInitializeCriticalSection;
extern FPTR_RtlEnterCriticalSection RtlEnterCriticalSection;
extern FPTR_RtlLeaveCriticalSection RtlLeaveCriticalSection;
extern FPTR_NtWaitForSingleObject NtWaitForSingleObject;
extern FPTR_NtWaitForMultipleObjects NtWaitForMultipleObjects;
extern FPTR_RtlCreateHeap RtlCreateHeap;
extern FPTR_RtlAllocateHeap RtlAllocateHeap;
extern FPTR_RtlFreeHeap RtlFreeHeap;
extern FPTR_RtlReAllocateHeap RtlReAllocateHeap;
extern FPTR_RtlSizeHeap RtlSizeHeap;
extern FPTR_RtlDestroyHeap RtlDestroyHeap;
extern FPTR_RtlEqualString RtlEqualString;
extern FPTR_NtAllocateVirtualMemory NtAllocateVirtualMemory;
extern FPTR_NtFreeVirtualMemory NtFreeVirtualMemory;
extern FPTR_NtQueryVirtualMemory NtQueryVirtualMemory;
extern FPTR_NtClearEvent NtClearEvent;
extern FPTR_NtClose NtClose;
extern FPTR_NtDelayExecution NtDelayExecution;
extern FPTR_NtDuplicateObject NtDuplicateObject;
extern FPTR_NtFlushBuffersFile NtFlushBuffersFile;
extern FPTR_NtQueryInformationFile NtQueryInformationFile;
extern FPTR_NtQueryDirectoryFile NtQueryDirectoryFile;
extern FPTR_NtQueryFullAttributesFile NtQueryFullAttributesFile;
extern FPTR_NtQueryVolumeInformationFile NtQueryVolumeInformationFile;
extern FPTR_NtCreateEvent NtCreateEvent;
extern FPTR_NtCreateMutant NtCreateMutant;
extern FPTR_NtReleaseMutant NtReleaseMutant;
extern FPTR_NtCreateSemaphore NtCreateSemaphore;
extern FPTR_NtReleaseSemaphore NtReleaseSemaphore;
extern FPTR_NtCreateDirectoryObject NtCreateDirectoryObject;
extern FPTR_NtCreateFile NtCreateFile;
extern FPTR_NtReadFile NtReadFile;
extern FPTR_NtWriteFile NtWriteFile;
extern FPTR_NtYieldExecution NtYieldExecution;
extern FPTR_NtSetInformationFile NtSetInformationFile;
extern FPTR_NtSetEvent NtSetEvent;
extern FPTR_NtSuspendThread NtSuspendThread;
extern FPTR_NtResumeThread NtResumeThread;
extern FPTR_NtSetLdtEntries NtSetLdtEntries;
extern FPTR_NtQueueApcThread NtQueueApcThread;
#define EXTERN(API) \
extern FPTR_##API API
EXTERN(RtlInitAnsiString);
EXTERN(RtlInitUnicodeString);
EXTERN(RtlAnsiStringToUnicodeString);
EXTERN(RtlAppendStringToString);
EXTERN(RtlAppendUnicodeStringToString);
EXTERN(RtlUnicodeStringToAnsiString);
EXTERN(RtlFreeAnsiString);
EXTERN(RtlNtStatusToDosError);
EXTERN(RtlTimeFieldsToTime);
EXTERN(RtlTimeToTimeFields);
EXTERN(RtlTryEnterCriticalSection);
EXTERN(RtlInitializeCriticalSection);
EXTERN(RtlEnterCriticalSection);
EXTERN(RtlLeaveCriticalSection);
EXTERN(NtWaitForSingleObject);
EXTERN(NtWaitForMultipleObjects);
EXTERN(RtlCreateHeap);
EXTERN(RtlAllocateHeap);
EXTERN(RtlFreeHeap);
EXTERN(RtlReAllocateHeap);
EXTERN(RtlSizeHeap);
EXTERN(RtlDestroyHeap);
EXTERN(RtlEqualString);
EXTERN(NtAllocateVirtualMemory);
EXTERN(NtFreeVirtualMemory);
EXTERN(NtQueryVirtualMemory);
EXTERN(NtClearEvent);
EXTERN(NtClose);
EXTERN(NtDelayExecution);
EXTERN(NtDuplicateObject);
EXTERN(NtFlushBuffersFile);
EXTERN(NtQueryInformationFile);
EXTERN(NtQueryDirectoryFile);
EXTERN(NtQueryFullAttributesFile);
EXTERN(NtQueryVolumeInformationFile);
EXTERN(NtCreateEvent);
EXTERN(NtCreateMutant);
EXTERN(NtReleaseMutant);
EXTERN(NtCreateSemaphore);
EXTERN(NtReleaseSemaphore);
EXTERN(NtCreateDirectoryObject);
EXTERN(NtCreateFile);
EXTERN(NtReadFile);
EXTERN(NtWriteFile);
EXTERN(NtYieldExecution);
EXTERN(NtSetInformationFile);
EXTERN(NtSetEvent);
EXTERN(NtSuspendThread);
EXTERN(NtResumeThread);
EXTERN(NtSetLdtEntries);
EXTERN(NtQueueApcThread);
#if defined(__cplusplus)
}