CWindowsFireWall.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef CWINDOWSFIREWALL_H
  2. #define CWINDOWSFIREWALL_H
  3. #include <windows.h>
  4. #include <netfw.h>
  5. #include <QString>
  6. #include <vector>
  7. #include <thread>
  8. class CProcessData
  9. {
  10. public:
  11. DWORD pid = 0;
  12. std::wstring sExeName = L"";
  13. std::wstring sExePath = L"";
  14. bool bDisabled = false;
  15. };
  16. class CWindowsFireWall
  17. {
  18. public:
  19. CWindowsFireWall()=delete;
  20. CWindowsFireWall(DWORD pid, bool bcheck = true);
  21. ~CWindowsFireWall();
  22. void removeLastRules();
  23. private:
  24. bool init();
  25. bool setWallOn();
  26. bool disableAllApp();
  27. void cleanup();
  28. bool getAllAppNameList(std::vector<CProcessData> &vAppList);
  29. HRESULT WFCOMInitialize(INetFwPolicy2** ppNetFwPolicy2);
  30. void setAllRulesEnabled(VARIANT_BOOL bEnable);
  31. void threadProc();
  32. void checkInprogressFireWall();
  33. void uploadAppLog(std::vector<CProcessData> &vAppList);
  34. void checkRulesIsEnabled();
  35. std::thread *m_pThrd;
  36. DWORD m_wthreadID;
  37. bool m_bIsRun = true;
  38. HRESULT m_comInit = E_FAIL;
  39. INetFwPolicy2 *m_pNetFwPolicy2 = NULL;
  40. QString m_sErrMsg;
  41. std::vector<std::wstring> m_vDisableRuleNames;
  42. VARIANT_BOOL m_fw_profile2_domain_enabled = VARIANT_TRUE;
  43. VARIANT_BOOL m_fw_profile2_private_enabled = VARIANT_TRUE;
  44. VARIANT_BOOL m_fw_profile2_public_enabled = VARIANT_TRUE;
  45. bool m_bModifyFireWall = false;
  46. DWORD m_pid = 0;
  47. const int m_inprogressCheckSeconds = 60*5;
  48. bool m_bcheck = true;
  49. };
  50. extern std::shared_ptr<CWindowsFireWall> g_windowsFireWallPtr;
  51. #endif // CWINDOWSFIREWALL_H