XFile.h
上传用户:kklily621
上传日期:2013-06-25
资源大小:252k
文件大小:6k
开发平台:

Visual C++

  1. //=============================================================================================
  2. /*
  3. XFile.h
  4. File operate function of ACL file
  5. Project : XFILTER 1.0 Personal Firewall
  6. Author : Tony Zhu
  7. Create Date : 2001/08/03
  8. Email : xstudio@xfilt.com
  9. URL : http://www.xfilt.com
  10. Copyright (c) 2001-2002 XStudio Technology.
  11. All Rights Reserved.
  12. WARNNING: 
  13. */
  14. //=============================================================================================
  15. #include "XFileRes.h"
  16. #include "Debug.h"
  17. //=============================================================================================
  18. // Internet Info
  19. typedef struct _XUSER_INFO
  20. {
  21. TCHAR sEmail[51];
  22. TCHAR sUserName[21];
  23. TCHAR sPassword[21];
  24. TCHAR sQQ[13];
  25. TCHAR sICQ[13];
  26. TCHAR sName[21];
  27. BYTE bIdType;
  28. TCHAR sId[21];
  29. int iStatus;
  30. BYTE bGender;
  31. BYTE bMetier;
  32. TCHAR sDuty[21];
  33. BYTE bDegree;
  34. BYTE bSalary;
  35. CTime tBirthday;
  36. WORD  wCountry;
  37. WORD  wCity;
  38. TCHAR sAddress[51];
  39. TCHAR sZip[11];
  40. TCHAR sInc[51];
  41. } XUSER_INFO, *PXUSER_INFO;
  42. typedef struct _XNET_COMMAND_HEADER
  43. {
  44. long lVersion;
  45. long lCount;
  46. CTime tCheckTime;
  47. } XNET_COMMAND_HEADER, *PXNET_COMMAND_HEADER;
  48. //=============================================================================================
  49. // ACL file
  50. typedef struct _XACL_HEADER
  51. {
  52. TCHAR sSignature[16];
  53. DWORD ulHeaderLenth;
  54. BYTE bMajor;
  55. BYTE bMinor;
  56. UINT uiSerial;
  57. DWORD ulVersion;
  58. BYTE bSet;
  59. UINT uiLogSize;
  60. BYTE bUpdateInterval;
  61. TCHAR sUserName[16];
  62. TCHAR sACode[16];
  63. TCHAR sWebURL[MAX_PATH];
  64. TCHAR sCommandURL[MAX_PATH];
  65. TCHAR sUserRegisterURL[MAX_PATH];
  66. TCHAR sEmail[MAX_PATH];
  67. DWORD ulAclOffset;
  68. DWORD ulAclCount;
  69. DWORD ulIntranetIPOffset;
  70. DWORD ulIntranetIPCount;
  71. DWORD ulDistrustIPOffset;
  72. DWORD ulDistrustIPCount;
  73. DWORD ulTrustIPOffset;
  74. DWORD ulTrustIPCount;
  75. DWORD ulCustomIPOffset;
  76. DWORD ulCustomIPCount;
  77. DWORD ulTimeOffset;
  78. DWORD ulTimeCount;
  79. } XACL_HEADER, *PXACL_HEADER;
  80. typedef struct _XACL
  81. {
  82. DWORD ulAclID;
  83. TCHAR sApplication[MAX_PATH];
  84. BYTE bRemoteNetType;
  85. BYTE bAccessTimeType;
  86. BYTE bAction;
  87. BYTE bDirection;
  88. BYTE bServiceType;
  89. UINT uiServicePort;
  90. TCHAR sMemo[51];
  91. } XACL, *PXACL;
  92. typedef struct _XACL_IP
  93. {
  94. DWORD ulStartIP;
  95. DWORD ulEndIP;
  96. } XACL_IP, *PXACL_IP;
  97. typedef struct _XACL_TIME
  98. {
  99. BYTE bWeekDay;
  100. CTime tStartTime;
  101. CTime tEndTime;
  102. } XACL_TIME, *PXACL_TIME;
  103. typedef struct _XACL_FILE
  104. {
  105. XACL_HEADER mAclHeader;
  106. XACL_IP mAclIntranetIP;
  107. XACL_TIME mAclTime [ACL_HEADER_TIME_COUNT];
  108. XACL_IP mpAclDistrustIP [MAX_IP_ARIA];
  109. XACL_IP mpAclTrustIP [MAX_IP_ARIA];
  110. XACL_IP mpAclCustomIP [MAX_IP_ARIA];
  111. XACL mpAcl [MAX_ACL];
  112. } XACL_FILE, *PXACL_FILE;
  113. //=============================================================================================
  114. // the packet struct of TCPIPDOG Capture 
  115. typedef struct _SESSION
  116. {
  117. SOCKET s;
  118. DWORD ulRemoteIP;
  119. CTime tStartTime;
  120. BYTE bDirection;
  121. BYTE bProtocol;
  122. UINT uiPort;
  123. BYTE bAction;
  124. UINT uiLocalPort;
  125. DWORD ulLocalIP;
  126. DWORD ulSendData;
  127. DWORD ulRecvData;
  128. TCHAR sPathName[MAX_PATH];
  129. TCHAR sMemo[MAX_PATH];
  130. CTime tEndTime;
  131. } SESSION, *PSESSION;
  132. #define SESSION_LENTH sizeof(SESSION)
  133. //=============================================================================================
  134. // the query session 
  135. typedef struct _QUERY_SESSION
  136. {
  137. BYTE status; //0: no use, 1: using
  138. TCHAR sPathName[MAX_PATH];
  139. } QUERY_SESSION, *PQUERY_SESSION;
  140. //=============================================================================================
  141. // XFITLER Io Control struct
  142. typedef BOOL (WINAPI * ADD_ACL_QUERY)(TCHAR* sPathName, BOOL EnableComboApplication = FALSE);
  143. typedef struct _XFILTER_IO_CONTROL
  144. {
  145. int iWorkMode;
  146. XACL_FILE AclFile;
  147. ADD_ACL_QUERY pAddAclQuery;
  148. HWND hwnd;
  149. SESSION *session;
  150. int isession;
  151. TCHAR sPathName[MAX_PATH];
  152. } XFILTER_IO_CONTROL, *PXFILTER_IO_CONTROL;
  153. typedef int  (WINAPI * XF_IO_CONTROL)(int iControlType, XFILTER_IO_CONTROL* ioControl);
  154. //=============================================================================================
  155. // class of Acl file
  156. class CAclFile
  157. {
  158. private:
  159. CRITICAL_SECTION gCriticalSectionFile;
  160. private:
  161. void InitDefaultValue();
  162. int CreateAcl (const TCHAR *sPathName);
  163. int WriteAcl (const TCHAR *sPathName);
  164. int OpenAcl ();
  165. int AddAclAcl (XACL *pAddAcl, int AddAclCount);
  166. int AddDistrustIP(XACL_IP *pDistrustIP, int AddCount);
  167. int AddTrustIP (XACL_IP *pTrustIP, int AddCount);
  168. int AddCustomIP (XACL_IP *pCustomIP, int AddCount);
  169. int DelAclIP (XACL_IP *pAclIP, DWORD* pCount, DWORD iIndex);
  170. int DelAcl (XACL *pAcl, DWORD* pCount, DWORD iIndex);
  171. public:
  172. CAclFile();
  173. virtual ~CAclFile ();
  174. void CloseAcl ();
  175. int ReadAcl (BOOL IsDLL = FALSE, HINSTANCE instance = NULL);
  176. int SaveAcl ();
  177. int AddAcl (void *pAddAcl, int AddAclCount, int AclType = 0);
  178. int DelAcl (int iIndex, int AclType);
  179. int FreeMemory ();
  180. public:
  181. static int GetBit (BYTE bit, int index, int count = 1);
  182. static int SetBit (BYTE* bit, int index, BOOL isTrue);
  183. static CString DIPToSIP (DWORD* pIP);
  184. static  CString GetAppPath (BOOL IsDLL = FALSE, HINSTANCE instance = NULL,  BOOL IsFullPathName = FALSE);
  185. static CString GetPath (TCHAR *sFilename);
  186. static CString GetName (TCHAR *sFilename);
  187. public:
  188. CFile mAclFile;
  189. XACL_HEADER mAclHeader;
  190. XACL_IP mAclIntranetIP;
  191. XACL_TIME mAllTime;
  192. XACL_TIME mAclTime[ACL_HEADER_TIME_COUNT];
  193. XACL_IP *mpAclDistrustIP;
  194. XACL_IP *mpAclTrustIP;
  195. XACL_IP *mpAclCustomIP;
  196. XACL *mpAcl;
  197. CString mAppPath;
  198. };