-
Notifications
You must be signed in to change notification settings - Fork 318
Expand file tree
/
Copy pathConvertIPv4IpAddressStructureToString.cpp
More file actions
55 lines (41 loc) · 1.33 KB
/
ConvertIPv4IpAddressStructureToString.cpp
File metadata and controls
55 lines (41 loc) · 1.33 KB
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
#include "Win32Helper.h"
#pragma warning( push )
#pragma warning( disable : 6101)
BOOL ConvertIPv4IpAddressStructureToStringW(_In_ PIN_ADDR Address, _Out_ PWCHAR Buffer)
{
#pragma warning( pop )
RTLIPV4ADDRESSTOSTRINGW RtlIpv4AddressToStringW = NULL;
HMODULE hModule = NULL;
WCHAR DisposeableObject[32] = { 0 };
if (Buffer == NULL)
return FALSE;
hModule = GetModuleHandleEx2W(L"ntdll.dll");
if (hModule == NULL)
return FALSE;
RtlIpv4AddressToStringW = (RTLIPV4ADDRESSTOSTRINGW)GetProcAddressA((DWORD64)hModule, "RtlIpv4AddressToStringW");
if (!RtlIpv4AddressToStringW)
return FALSE;
RtlIpv4AddressToStringW(Address, Buffer);
RtlIpv4AddressToStringW = NULL;
return TRUE;
}
#pragma warning( push )
#pragma warning( disable : 6101)
BOOL ConvertIPv4IpAddressStructureToStringA(_In_ PIN_ADDR Address, _Out_ PCHAR Buffer)
{
#pragma warning( pop )
RTLIPV4ADDRESSTOSTRINGA RtlIpv4AddressToStringA = NULL;
HMODULE hModule = NULL;
WCHAR DisposeableObject[32] = { 0 };
if (Buffer == NULL)
return FALSE;
hModule = GetModuleHandleEx2W(L"ntdll.dll");
if (hModule == NULL)
return FALSE;
RtlIpv4AddressToStringA = (RTLIPV4ADDRESSTOSTRINGA)GetProcAddressA((DWORD64)hModule, "RtlIpv4AddressToStringA");
if (!RtlIpv4AddressToStringA)
return FALSE;
RtlIpv4AddressToStringA(Address, Buffer);
RtlIpv4AddressToStringA = NULL;
return TRUE;
}