IStreamSharedPtr;
45 | }
46 |
--------------------------------------------------------------------------------
/WinToolsLib/License.cpp:
--------------------------------------------------------------------------------
1 | #include "License.h"
2 | #include "Exception.h"
3 | #include "Registry\Key.h"
4 | #include "Checksum\Crc.h"
5 | #include "Process\Process.h"
6 |
7 | namespace WinToolsLib
8 | {
9 | String License::GetUserId()
10 | {
11 | auto processorId = GetProcessorId();
12 | auto productId = GetProductId();
13 | auto userId = String::FormatS(Text("%s/%s"), processorId.GetBuffer(), productId.GetBuffer());
14 |
15 | auto data = (PCByte)userId.GetBuffer();
16 | auto size = userId.GetLength() * sizeof(TChar);
17 | auto hash = Checksum::Crc32::Calc(data, size);
18 |
19 | return String::FormatS(Text("%010u"), hash);
20 | }
21 |
22 | String License::GetProcessorId()
23 | {
24 | struct
25 | {
26 | UInt32 eax;
27 | UInt32 ebx;
28 | UInt32 ecx;
29 | UInt32 edx;
30 | } id;
31 |
32 | __cpuid((Int32*)&id, 1);
33 |
34 | return String::FormatS(Text("%08X%08X"), id.edx, id.eax);
35 | }
36 |
37 | String License::GetProductId()
38 | {
39 | try
40 | {
41 | auto currentVersion = Registry::Key::Open(
42 | HKEY_LOCAL_MACHINE,
43 | Text("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"),
44 | Process::Process::IsWow64() ? KEY_WOW64_64KEY | KEY_QUERY_VALUE : KEY_QUERY_VALUE);
45 |
46 | const String keyName(Text("ProductId"));
47 | String productId;
48 |
49 | currentVersion.EnumValue([&keyName, &productId](const TChar* name, UInt32 type, Buffer& data)
50 | {
51 | if (keyName == name && REG_SZ == type)
52 | {
53 | productId = (const TChar*)data.GetBuffer();
54 | }
55 | });
56 |
57 | return productId;
58 | }
59 | catch (Exception&)
60 | {
61 | }
62 |
63 | return String();
64 | }
65 | }
--------------------------------------------------------------------------------
/WinToolsLib/License.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Types.h"
3 | #include "String.h"
4 |
5 | namespace WinToolsLib
6 | {
7 | class License
8 | {
9 | public:
10 | static String GetUserId();
11 |
12 | private:
13 | static String GetProcessorId();
14 | static String GetProductId();
15 | };
16 | }
17 |
--------------------------------------------------------------------------------
/WinToolsLib/Log.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Types.h"
3 | #include "String.h"
4 | #include "DebugOutput.h"
5 |
6 | #if _WINTOOLSLIB_LOG_LEVEL & 0x0100
7 | #define ENABLE_LOG_CHECKPOINT
8 | #endif
9 |
10 | #if _WINTOOLSLIB_LOG_LEVEL & 0x0010
11 | #define ENABLE_LOG_INFO
12 | #endif
13 |
14 | #if _WINTOOLSLIB_LOG_LEVEL & 0x0008
15 | #define ENABLE_LOG_EXCEPTION
16 | #endif
17 |
18 | #if _WINTOOLSLIB_LOG_LEVEL & 0x0004
19 | #define ENABLE_LOG_WARNING
20 | #endif
21 |
22 | #if _WINTOOLSLIB_LOG_LEVEL & 0x0002
23 | #define ENABLE_LOG_ERROR
24 | #endif
25 |
26 | #if _WINTOOLSLIB_LOG_LEVEL & 0x0001
27 | #define ENABLE_LOG_FATAL
28 | #endif
29 |
30 | namespace WinToolsLib
31 | {
32 | #ifdef ENABLE_LOG_CHECKPOINT
33 | #define LOG_CHECKPOINT(...) DebugOutput(Text(" %s"), String::FormatS(__VA_ARGS__).GetBuffer())
34 | #else
35 | #define LOG_CHECKPOINT(...)
36 | #endif
37 |
38 | #ifdef ENABLE_LOG_INFO
39 | #define LOG_INFO(...) DebugOutput(Text(" %s"), String::FormatS(__VA_ARGS__).GetBuffer())
40 | #else
41 | #define LOG_INFO(...)
42 | #endif
43 |
44 | #ifdef ENABLE_LOG_EXCEPTION
45 | #define LOG_EXCEPTION(...) DebugOutput(Text(" %s"), String::FormatS(__VA_ARGS__).GetBuffer())
46 | #else
47 | #define LOG_EXCEPTION(...)
48 | #endif
49 |
50 | #ifdef ENABLE_LOG_WARNING
51 | #define LOG_WARNING(...) DebugOutput(Text(" %s"), String::FormatS(__VA_ARGS__).GetBuffer())
52 | #else
53 | #define LOG_WARNING(...)
54 | #endif
55 |
56 | #ifdef ENABLE_LOG_ERROR
57 | #define LOG_ERROR(...) DebugOutput(Text(" %s"), String::FormatS(__VA_ARGS__).GetBuffer())
58 | #else
59 | #define LOG_ERROR(...)
60 | #endif
61 |
62 | #ifdef ENABLE_LOG_FATAL
63 | #define LOG_FATAL(...) DebugOutput(Text(" %s"), String::FormatS(__VA_ARGS__).GetBuffer())
64 | #else
65 | #define LOG_FATAL(...)
66 | #endif
67 | }
68 |
--------------------------------------------------------------------------------
/WinToolsLib/Module.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Types.h"
3 | #include "String.h"
4 | #include
5 |
6 | namespace WinToolsLib
7 | {
8 | class Module;
9 | typedef std::list ModuleList;
10 |
11 | class Module
12 | {
13 | public:
14 | Module(String name, String path, PByte base, UInt32 size, Bool isKernel);
15 | Module(Module&& other);
16 | Module(const Module& other);
17 | ~Module();
18 |
19 | Module& operator=(Module&& other);
20 | Module& operator=(const Module& other);
21 |
22 | const String& GetName() const;
23 | const String& GetPath() const;
24 | PByte GetBase() const;
25 | UInt32 GetSize() const;
26 | Bool IsKernel() const;
27 |
28 | static ModuleList GetKernelList();
29 | static ModuleList GetList(UInt32 processId);
30 |
31 | protected:
32 | Void MoveFrom(Module& other);
33 | Void CopyFrom(const Module& other);
34 |
35 | protected:
36 | String m_name;
37 | String m_path;
38 | PByte m_base;
39 | UInt32 m_size;
40 | Bool m_isKernel;
41 | };
42 |
43 | inline const String& Module::GetName() const
44 | {
45 | return m_name;
46 | }
47 |
48 | inline const String& Module::GetPath() const
49 | {
50 | return m_path;
51 | }
52 |
53 | inline PByte Module::GetBase() const
54 | {
55 | return m_base;
56 | }
57 |
58 | inline UInt32 Module::GetSize() const
59 | {
60 | return m_size;
61 | }
62 |
63 | inline Bool Module::IsKernel() const
64 | {
65 | return m_isKernel;
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/WinToolsLib/Monitor.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "Types.h"
3 |
4 | #include
5 | #include
6 | #include
7 |
8 | //
9 | // Based on monitor implementation by Herb Sutter
10 | //
11 |
12 | namespace WinToolsLib
13 | {
14 | template
15 | class Monitor
16 | {
17 | Monitor(const Monitor& other) = delete; // Non-copyable
18 | Monitor& operator=(const Monitor& other) = delete; // Non-copyable
19 |
20 | public:
21 | Monitor()
22 | {
23 | m_lock = std::make_unique();
24 | }
25 |
26 | explicit Monitor(T&& t) :
27 | m_lock(std::make_unique()),
28 | m_t(std::move(t))
29 | {
30 | }
31 |
32 | Monitor(Monitor&& other)
33 | {
34 | MoveFrom(other);
35 | }
36 |
37 | Monitor& operator=(Monitor&& other)
38 | {
39 | MoveFrom(other);
40 | return *this;
41 | }
42 |
43 | template
44 | typename std::result_of::type operator()(F f) const
45 | {
46 | std::lock_guard hold(*m_lock);
47 | return f(m_t);
48 | }
49 |
50 | protected:
51 | Void MoveFrom(Monitor& other)
52 | {
53 | m_t = std::move(other.m_t);
54 | m_lock = std::move(other.m_lock);
55 | }
56 |
57 | private:
58 | mutable T m_t;
59 | mutable std::unique_ptr m_lock;
60 | };
61 | }
62 |
--------------------------------------------------------------------------------
/WinToolsLib/Net/Http.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "..\Types.h"
3 | #include "..\Buffer.h"
4 | #include "..\Handles\InternetHandle.h"
5 |
6 | namespace WinToolsLib
7 | {
8 | namespace Net
9 | {
10 | using namespace Handles;
11 |
12 | struct Flag
13 | {
14 | enum
15 | {
16 | Reload = INTERNET_FLAG_RELOAD,
17 | Secure = INTERNET_FLAG_SECURE,
18 | NoCacheWrite = INTERNET_FLAG_NO_CACHE_WRITE,
19 | IgnoreCertInvalidName = INTERNET_FLAG_IGNORE_CERT_CN_INVALID,
20 | IgnoreCertInvalidDate = INTERNET_FLAG_IGNORE_CERT_DATE_INVALID
21 | };
22 | };
23 |
24 | class Http
25 | {
26 | public:
27 | Http(PCTChar userAgent);
28 | Http(Http&& other);
29 |
30 | Http& operator=(Http&& other);
31 |
32 | Void Connect(PCTChar pszServer, UInt16 port);
33 |
34 | static Bool IsOffline(InternetHandle hInternet = nullptr);
35 | static Void GoOnline(InternetHandle hInternet = nullptr);
36 |
37 | Void SendRequest(
38 | PCTChar pszVerb,
39 | PCTChar pszUrl,
40 | PCTChar pszHeaders,
41 | PCByte pBody,
42 | UInt32 bodyLength,
43 | UInt32 flags = 0);
44 |
45 | Void SendGetRequest(
46 | PCTChar pszUrl,
47 | UInt32 flags = 0);
48 |
49 | Void SendPostRequest(
50 | PCTChar pszUrl,
51 | PCTChar pszHeaders,
52 | PCByte pBody,
53 | UInt32 bodyLength,
54 | UInt32 flags = 0);
55 |
56 | UInt32 GetContentSize() const;
57 |
58 | typedef std::function ReadFileCallback;
59 | Buffer ReadFile(UInt32 chunkSize = (256 * 1024), ReadFileCallback callback = nullptr) const;
60 |
61 | StringA ReadStringA(UInt32 chunkSize = 1024) const;
62 |
63 | struct Options
64 | {
65 | enum
66 | {
67 | TryToGoOnline = 1,
68 | IgnoreUnknownCertificateAuthority
69 | };
70 | };
71 | Void SetOption(UInt32 option);
72 | Void SetSendTimeout(UInt32 milliseconds);
73 |
74 | protected:
75 | Void MoveFrom(Http& other);
76 | Void SetIgnoreUnknownCertificateAuthority();
77 | Void SetSendTimeout();
78 |
79 | private:
80 | InternetHandle m_hInternet;
81 | InternetHandle m_hConnect;
82 | InternetHandle m_hRequest;
83 | UInt32 m_options;
84 | UInt32 m_sendTimeout;
85 | };
86 |
87 | inline Void Http::SetOption(UInt32 option)
88 | {
89 | m_options |= option;
90 | }
91 |
92 | inline Void Http::SetSendTimeout(UInt32 milliseconds)
93 | {
94 | m_sendTimeout = milliseconds;
95 | }
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/WinToolsLib/Net/Mac.cpp:
--------------------------------------------------------------------------------
1 | #include "Mac.h"
2 | #include "..\Exception.h"
3 |
4 | #include
5 | #include
6 |
7 | #include
8 | #include
9 | #pragma comment (lib, "IPHlpApi.lib")
10 |
11 | namespace WinToolsLib
12 | {
13 | namespace Net
14 | {
15 | Buffer Mac::GetFirst()
16 | {
17 | //
18 | // The recommended method of calling the GetAdaptersAddresses function
19 | // is to pre-allocate a 15KB working buffer pointed to by the AdapterAddresses parameter.
20 | //
21 | ULONG size = 15 * 1024;
22 | while (True)
23 | {
24 | Buffer buffer(size);
25 | PIP_ADAPTER_ADDRESSES pAddresses = (PIP_ADAPTER_ADDRESSES)buffer.GetBuffer();
26 |
27 | auto result = ::GetAdaptersAddresses(0, 0, NULL, pAddresses, &size);
28 | if (ERROR_BUFFER_OVERFLOW == result)
29 | {
30 | continue;
31 | }
32 | else if (ERROR_SUCCESS == result)
33 | {
34 | Buffer mac(pAddresses->PhysicalAddress, pAddresses->PhysicalAddressLength);
35 | return mac;
36 | }
37 |
38 | break;
39 | }
40 |
41 | return Buffer();
42 | }
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/WinToolsLib/Net/Mac.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "..\Types.h"
3 | #include "..\Buffer.h"
4 |
5 | namespace WinToolsLib
6 | {
7 | namespace Net
8 | {
9 | class Mac
10 | {
11 | public:
12 | static Buffer GetFirst();
13 |
14 | private:
15 | };
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/WinToolsLib/Net/Url.cpp:
--------------------------------------------------------------------------------
1 | #include "Url.h"
2 | #include "..\Exception.h"
3 |
4 | #include
5 |
6 | #include
7 | #include
8 | #include
9 | #pragma comment (lib, "Shlwapi.lib")
10 |
11 | namespace WinToolsLib
12 | {
13 | namespace Net
14 | {
15 | String Url::Encode(const TChar* url, EncodePortion flag)
16 | {
17 | const auto maxAttempts = 4;
18 | const auto maxLength = INTERNET_MAX_URL_LENGTH;
19 | const auto step = maxLength / maxAttempts;
20 |
21 | for (auto i = 1; i <= maxAttempts; i++)
22 | {
23 | DWORD length = step * i;
24 | std::vector buffer(length + 1);
25 |
26 | auto result = ::UrlEscape(url, &buffer[0], &length, static_cast(flag));
27 | if (S_OK == result)
28 | {
29 | return String(&buffer[0]);
30 | }
31 | if (E_POINTER == result)
32 | {
33 | continue;
34 | }
35 | THROW_WIN32_EXCEPTION(result);
36 | }
37 | THROW_WIN32_EXCEPTION(E_POINTER);
38 | }
39 |
40 | String Url::Decode(const TChar* url)
41 | {
42 | const auto maxAttempts = 4;
43 | const auto maxLength = INTERNET_MAX_URL_LENGTH;
44 | const auto step = maxLength / maxAttempts;
45 |
46 | for (auto i = 1; i <= maxAttempts; i++)
47 | {
48 | DWORD length = step * i;
49 | std::vector buffer(length + 1);
50 |
51 | auto result = ::UrlUnescape((PTSTR)url, &buffer[0], &length, 0);
52 | if (S_OK == result)
53 | {
54 | return String(&buffer[0]);
55 | }
56 | if (E_POINTER == result)
57 | {
58 | continue;
59 | }
60 | THROW_WIN32_EXCEPTION(result);
61 | }
62 | THROW_WIN32_EXCEPTION(E_POINTER);
63 | }
64 | }
65 | }
66 |
--------------------------------------------------------------------------------
/WinToolsLib/Net/Url.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "..\Types.h"
3 | #include "..\String.h"
4 |
5 | namespace WinToolsLib
6 | {
7 | namespace Net
8 | {
9 | enum class EncodePortion : UInt32
10 | {
11 | None = 0x00000000,
12 | SegmentOnly = 0x00002000
13 | };
14 |
15 | class Url
16 | {
17 | public:
18 | static String Encode(const TChar* url, EncodePortion flag = EncodePortion::None);
19 | static String Decode(const TChar* url);
20 | };
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/WinToolsLib/Os/Authorization/Impersonate.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "..\..\Types.h"
3 |
4 | namespace WinToolsLib { namespace Os { namespace Authorization
5 | {
6 | class Impersonate
7 | {
8 | public:
9 | Impersonate();
10 | ~Impersonate();
11 |
12 | static Void LoggedOnUser();
13 | static Void CreateProcessAsLoggedOnUser(
14 | const TChar* application,
15 | const TChar* parameters = nullptr);
16 |
17 | private:
18 | Bool m_revertToSelf;
19 | };
20 |
21 | } } }
--------------------------------------------------------------------------------
/WinToolsLib/Os/Authorization/Sid.cpp:
--------------------------------------------------------------------------------
1 | #include "Sid.h"
2 |
3 | #pragma comment(lib, "Advapi32.lib")
4 |
5 | namespace WinToolsLib { namespace Os { namespace Authorization
6 | {
7 | Sid::Sid(PSID psid) :
8 | m_psid(psid)
9 | {
10 | }
11 |
12 | Sid::Sid(Sid&& other) :
13 | m_psid(nullptr)
14 | {
15 | MoveFrom(other);
16 | }
17 |
18 | Sid::~Sid()
19 | {
20 | Free();
21 | }
22 |
23 | Sid& Sid::operator=(Sid&& other)
24 | {
25 | MoveFrom(other);
26 | return *this;
27 | }
28 |
29 | Void Sid::Free()
30 | {
31 | if (m_psid)
32 | {
33 | auto psid = m_psid;
34 | m_psid = nullptr;
35 | ::FreeSid(psid);
36 | }
37 | }
38 |
39 | Void Sid::Attach(PSID psid)
40 | {
41 | Free();
42 | m_psid = psid;
43 | }
44 |
45 | PSID Sid::Detach()
46 | {
47 | auto psid = m_psid;
48 | m_psid = nullptr;
49 | return psid;
50 | }
51 |
52 | Bool Sid::IsAdmin()
53 | {
54 | SID_IDENTIFIER_AUTHORITY ntAuthority = SECURITY_NT_AUTHORITY;
55 | Sid adminGroup;
56 |
57 | auto success = ::AllocateAndInitializeSid(
58 | &ntAuthority,
59 | 2,
60 | SECURITY_BUILTIN_DOMAIN_RID,
61 | DOMAIN_ALIAS_RID_ADMINS,
62 | 0, 0, 0, 0, 0, 0,
63 | adminGroup.GetAddress());
64 |
65 | if (!success)
66 | {
67 | return False;
68 | }
69 |
70 | BOOL isMember = FALSE;
71 |
72 | success = ::CheckTokenMembership(NULL, adminGroup, &isMember);
73 | if (!success)
74 | {
75 | return False;
76 | }
77 |
78 | return TRUE == isMember;
79 | }
80 |
81 | Bool Sid::IsSystem()
82 | {
83 | SID_IDENTIFIER_AUTHORITY ntAuthority = SECURITY_NT_AUTHORITY;
84 | Sid system;
85 |
86 | auto success = ::AllocateAndInitializeSid(
87 | &ntAuthority,
88 | 1,
89 | SECURITY_LOCAL_SYSTEM_RID,
90 | 0, 0, 0, 0, 0, 0, 0,
91 | system.GetAddress());
92 |
93 | if (!success)
94 | {
95 | return False;
96 | }
97 |
98 | BOOL isSystem = FALSE;
99 |
100 | success = ::CheckTokenMembership(NULL, system, &isSystem);
101 | if (!success)
102 | {
103 | return False;
104 | }
105 |
106 | return TRUE == isSystem;
107 | }
108 |
109 | Void Sid::MoveFrom(Sid& other)
110 | {
111 | if (this != &other)
112 | {
113 | Attach(other.Detach());
114 | }
115 | }
116 |
117 | } } }
--------------------------------------------------------------------------------
/WinToolsLib/Os/Authorization/Sid.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "..\..\Types.h"
3 |
4 | #include
5 |
6 | namespace WinToolsLib { namespace Os { namespace Authorization
7 | {
8 | class Sid
9 | {
10 | Sid(const Sid& other); // Non-copyable
11 | Sid& operator=(const Sid& other); // Non-copyable
12 |
13 | public:
14 | Sid(PSID psid = nullptr);
15 | Sid(Sid&& other);
16 | ~Sid();
17 |
18 | Sid& operator=(Sid&& other);
19 |
20 | Void Free();
21 | Void Attach(PSID psid);
22 | PSID Detach();
23 |
24 | operator PSID() const;
25 | PSID* GetAddress();
26 |
27 | static Bool IsAdmin();
28 | static Bool IsSystem();
29 |
30 | protected:
31 | Void MoveFrom(Sid& other);
32 |
33 | private:
34 | PSID m_psid;
35 | };
36 |
37 | inline Sid::operator PSID() const
38 | {
39 | return m_psid;
40 | }
41 |
42 | inline PSID* Sid::GetAddress()
43 | {
44 | return &m_psid;
45 | }
46 |
47 | } } }
--------------------------------------------------------------------------------
/WinToolsLib/Os/Firewall/FirewallPolicy.cpp:
--------------------------------------------------------------------------------
1 | #include "FirewallPolicy.h"
2 | #include "..\..\Exception.h"
3 |
4 | namespace WinToolsLib { namespace Os { namespace Firewall
5 | {
6 | FirewallPolicy::FirewallPolicy()
7 | {
8 | auto hr = ::CoCreateInstance(
9 | __uuidof(NetFwPolicy2),
10 | nullptr,
11 | CLSCTX_INPROC_SERVER,
12 | __uuidof(INetFwPolicy2),
13 | (PVoid*)&m_fwPolicy);
14 |
15 | if (FAILED(hr))
16 | {
17 | THROW_WIN32_EXCEPTION(hr);
18 | }
19 | }
20 |
21 | FirewallPolicy::~FirewallPolicy()
22 | {
23 | }
24 |
25 | RuleList FirewallPolicy::GetRuleList()
26 | {
27 | Com::Ptr ruleList;
28 | auto hr = m_fwPolicy->get_Rules(&ruleList);
29 | if (FAILED(hr))
30 | {
31 | THROW_WIN32_EXCEPTION(hr);
32 | }
33 |
34 | return RuleList(std::move(ruleList));
35 | }
36 |
37 | ProfileList FirewallPolicy::GetCurrentProfileTypes() const
38 | {
39 | long profileBitmask = 0;
40 | auto hr = m_fwPolicy->get_CurrentProfileTypes(&profileBitmask);
41 | if (FAILED(hr))
42 | {
43 | THROW_WIN32_EXCEPTION(hr);
44 | }
45 |
46 | if ((profileBitmask & (UInt32)Profile::All) == (UInt32)Profile::All)
47 | {
48 | return ProfileList({ Profile::All });
49 | }
50 |
51 | ProfileList list;
52 | if ((profileBitmask & (UInt32)Profile::Domain) == (UInt32)Profile::Domain) list.push_back(Profile::Domain);
53 | if ((profileBitmask & (UInt32)Profile::Public) == (UInt32)Profile::Public) list.push_back(Profile::Public);
54 | if ((profileBitmask & (UInt32)Profile::Private) == (UInt32)Profile::Private) list.push_back(Profile::Private);
55 | return list;
56 | }
57 |
58 | Void FirewallPolicy::SetDefaultOutboundAction(Profile profile, Action action)
59 | {
60 | auto hr = m_fwPolicy->put_DefaultOutboundAction(NET_FW_PROFILE_TYPE2(profile), NET_FW_ACTION(action));
61 | if (FAILED(hr))
62 | {
63 | THROW_WIN32_EXCEPTION(hr);
64 | }
65 | }
66 | } } }
--------------------------------------------------------------------------------
/WinToolsLib/Os/Firewall/FirewallPolicy.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "..\..\Types.h"
3 | #include "..\..\Com\Ptr.h"
4 |
5 | #include
6 | #include
7 |
8 | #include "RuleList.h"
9 |
10 | namespace WinToolsLib { namespace Os { namespace Firewall
11 | {
12 | enum class Profile
13 | {
14 | Domain = NET_FW_PROFILE2_DOMAIN,
15 | Private = NET_FW_PROFILE2_PRIVATE,
16 | Public = NET_FW_PROFILE2_PUBLIC,
17 | All = NET_FW_PROFILE2_ALL
18 | };
19 | typedef std::vector ProfileList;
20 |
21 | class FirewallPolicy
22 | {
23 | public:
24 | FirewallPolicy();
25 | ~FirewallPolicy();
26 |
27 | RuleList GetRuleList();
28 | ProfileList GetCurrentProfileTypes() const;
29 |
30 | Void SetDefaultOutboundAction(Profile profile, Action action);
31 |
32 | private:
33 | Com::Ptr m_fwPolicy;
34 | };
35 |
36 | } } }
--------------------------------------------------------------------------------
/WinToolsLib/Os/Firewall/Rule.h:
--------------------------------------------------------------------------------
1 | #pragma once
2 | #include "..\..\Types.h"
3 | #include "..\..\String.h"
4 | #include "..\..\Com\Ptr.h"
5 |
6 | #include
7 |
8 | namespace WinToolsLib { namespace Os { namespace Firewall
9 | {
10 | enum class Action
11 | {
12 | Block = NET_FW_ACTION_BLOCK,
13 | Allow = NET_FW_ACTION_ALLOW
14 | };
15 |
16 | enum class Direction
17 | {
18 | In = NET_FW_RULE_DIR_IN,
19 | Out = NET_FW_RULE_DIR_OUT
20 | };
21 |
22 | class RuleList;
23 |
24 | class Rule
25 | {
26 | Rule(const Rule& other) = delete;
27 | Rule& operator=(const Rule& other) = delete;
28 | public:
29 | Rule();
30 | Rule(Com::Ptr&& rule);
31 | Rule(Rule&& other);
32 | ~Rule();
33 |
34 | Rule& operator=(Rule&& other);
35 |
36 | const Action GetAction() const;
37 | const Direction GetDirection() const;
38 | const Bool IsEnabled() const;
39 | const WChar* GetLocalAddresses() const;
40 | const WChar* GetName() const;
41 | const WChar* GetRemoteAddresses() const;
42 |
43 | Void SetAction(Action value);
44 | Void SetDirection(Direction value);
45 | Void SetEnabled(Bool value);
46 | Void SetLocalAddresses(const WChar* value);
47 | Void SetName(const WChar* value);
48 | Void SetRemoteAddresses(const WChar* value);
49 |
50 | protected:
51 | Void MoveFrom(Rule& other);
52 |
53 | private:
54 | operator const INetFwRule*() const;
55 | operator INetFwRule*();
56 |
57 | private:
58 | Com::Ptr