From 0391e3ccc1b97baae8e81efbd9d0dea7358eb4d3 Mon Sep 17 00:00:00 2001 From: Boring <1079299053@qq.com> Date: Thu, 7 Nov 2024 17:19:37 +0800 Subject: [PATCH] add extern "C" for public api --- MemoryModule/LoadDllMemoryApi.h | 36 ++++++++++++++++++--------------- MemoryModule/Loader.h | 34 +++++++++++++++---------------- 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/MemoryModule/LoadDllMemoryApi.h b/MemoryModule/LoadDllMemoryApi.h index f625148..0a413b5 100644 --- a/MemoryModule/LoadDllMemoryApi.h +++ b/MemoryModule/LoadDllMemoryApi.h @@ -11,25 +11,29 @@ typedef HMODULE HMEMORYMODULE; #define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0) #endif -HMEMORYMODULE WINAPI LoadLibraryMemory(_In_ PVOID BufferAddress); +extern "C" { -HMEMORYMODULE WINAPI LoadLibraryMemoryExA( - _In_ PVOID BufferAddress, - _In_ size_t Reserved, - _In_opt_ LPCSTR DllBaseName, - _In_opt_ LPCSTR DllFullName, - _In_ DWORD Flags -); + HMEMORYMODULE WINAPI LoadLibraryMemory(_In_ PVOID BufferAddress); -HMEMORYMODULE WINAPI LoadLibraryMemoryExW( - _In_ PVOID BufferAddress, - _In_ size_t Reserved, - _In_opt_ LPCWSTR DllBaseName, - _In_opt_ LPCWSTR DllFullName, - _In_ DWORD Flags -); + HMEMORYMODULE WINAPI LoadLibraryMemoryExA( + _In_ PVOID BufferAddress, + _In_ size_t Reserved, + _In_opt_ LPCSTR DllBaseName, + _In_opt_ LPCSTR DllFullName, + _In_ DWORD Flags + ); -BOOL WINAPI FreeLibraryMemory(_In_ HMEMORYMODULE hMemoryModule); + HMEMORYMODULE WINAPI LoadLibraryMemoryExW( + _In_ PVOID BufferAddress, + _In_ size_t Reserved, + _In_opt_ LPCWSTR DllBaseName, + _In_opt_ LPCWSTR DllFullName, + _In_ DWORD Flags + ); + + BOOL WINAPI FreeLibraryMemory(_In_ HMEMORYMODULE hMemoryModule); + +} #define NtLoadDllMemory LdrLoadDllMemory #define NtLoadDllMemoryExA LdrLoadDllMemoryExA diff --git a/MemoryModule/Loader.h b/MemoryModule/Loader.h index 8bdce28..a71afe7 100644 --- a/MemoryModule/Loader.h +++ b/MemoryModule/Loader.h @@ -9,9 +9,6 @@ #define MEMORY_FEATURE_LDRP_RELEASE_TLS_ENTRY 0x00000040 #define MEMORY_FEATURE_ALL 0x0000007f -//Get the implementation of the currently running operating system. -NTSTATUS NTAPI LdrQuerySystemMemoryModuleFeatures(_Out_ PDWORD pFeatures); - /* LdrLoadDllMemoryEx dwFlags @@ -47,21 +44,24 @@ NTSTATUS NTAPI LdrQuerySystemMemoryModuleFeatures(_Out_ PDWORD pFeatures); //Hook for dotnet dlls #define LOAD_FLAGS_HOOK_DOT_NET 0x00000010 - -NTSTATUS NTAPI LdrLoadDllMemoryExW( - _Out_ HMEMORYMODULE* BaseAddress, // Output module base address - _Out_opt_ PVOID* LdrEntry, // Receive a pointer to the LDR node of the module - _In_ DWORD dwFlags, // Flags - _In_ LPVOID BufferAddress, // Pointer to the dll file data buffer - _In_ size_t Reserved, // Reserved parameter, must be 0 - _In_opt_ LPCWSTR DllName, // Module file name - _In_opt_ LPCWSTR DllFullName // Module file full path -); - -//Unload modules previously loaded from memory -NTSTATUS NTAPI LdrUnloadDllMemory(_In_ HMEMORYMODULE BaseAddress); - extern "C" { + + //Get the implementation of the currently running operating system. + NTSTATUS NTAPI LdrQuerySystemMemoryModuleFeatures(_Out_ PDWORD pFeatures); + + NTSTATUS NTAPI LdrLoadDllMemoryExW( + _Out_ HMEMORYMODULE* BaseAddress, // Output module base address + _Out_opt_ PVOID* LdrEntry, // Receive a pointer to the LDR node of the module + _In_ DWORD dwFlags, // Flags + _In_ LPVOID BufferAddress, // Pointer to the dll file data buffer + _In_ size_t Reserved, // Reserved parameter, must be 0 + _In_opt_ LPCWSTR DllName, // Module file name + _In_opt_ LPCWSTR DllFullName // Module file full path + ); + + //Unload modules previously loaded from memory + NTSTATUS NTAPI LdrUnloadDllMemory(_In_ HMEMORYMODULE BaseAddress); + __declspec(noreturn) VOID NTAPI LdrUnloadDllMemoryAndExitThread( _In_ HMEMORYMODULE BaseAddress, _In_ DWORD dwExitCode