BOWDoc.cpp
上传用户:jinandeyu
上传日期:2007-01-05
资源大小:620k
文件大小:6k
源码类别:

远程控制编程

开发平台:

WINDOWS

  1. /*  Back Orifice 2000 - Remote Administration Suite
  2.     Copyright (C) 1999, Cult Of The Dead Cow
  3.     This program is free software; you can redistribute it and/or modify
  4.     it under the terms of the GNU General Public License as published by
  5.     the Free Software Foundation; either version 2 of the License, or
  6.     (at your option) any later version.
  7.     This program is distributed in the hope that it will be useful,
  8.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.     GNU General Public License for more details.
  11.     You should have received a copy of the GNU General Public License
  12.     along with this program; if not, write to the Free Software
  13.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  14. The author of this program may be contacted at dildog@l0pht.com. */
  15. // BOWDoc.cpp : implementation of the CBOWDoc class
  16. //
  17. #include "stdafx.h"
  18. #include "bo2kgui.h"
  19. #include "MainFrm.h"
  20. #include "BOWDoc.h"
  21. #ifdef _DEBUG
  22. #define new DEBUG_NEW
  23. #undef THIS_FILE
  24. static char THIS_FILE[] = __FILE__;
  25. #endif
  26. #define MAGIC_DWORD 0xCDC31337
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CBOWDoc
  29. IMPLEMENT_DYNCREATE(CBOWDoc, CDocument)
  30. BEGIN_MESSAGE_MAP(CBOWDoc, CDocument)
  31. //{{AFX_MSG_MAP(CBOWDoc)
  32. // NOTE - the ClassWizard will add and remove mapping macros here.
  33. //    DO NOT EDIT what you see in these blocks of generated code!
  34. //}}AFX_MSG_MAP
  35. END_MESSAGE_MAP()
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CBOWDoc construction/destruction
  38. CBOWDoc::CBOWDoc()
  39. {
  40. // TODO: add one-time construction code here
  41. m_pHeadSI=NULL;
  42. }
  43. CBOWDoc::~CBOWDoc()
  44. {
  45. }
  46. void *CBOWDoc::InsertServer(const char *svName,
  47.                         const char *svConnectionType,
  48.         const char *svAddress,
  49.     const char *svEncryption,
  50.     const char *svAuthentication)
  51. {
  52. SERVER_INFO *si,*prev;
  53. si=(SERVER_INFO *)malloc(sizeof(SERVER_INFO));
  54. if(si==NULL) return NULL;
  55. memset(si,0,sizeof(SERVER_INFO));
  56. // Permanent Stuff
  57. lstrcpyn(si->svName,svName,64);
  58. lstrcpyn(si->svConnectionType,svConnectionType,64);
  59. lstrcpyn(si->svAddress,svAddress,512);
  60. lstrcpyn(si->svEncryption,svEncryption,64);
  61. lstrcpyn(si->svAuthentication,svAuthentication,64);
  62. // Temporary Stuff
  63. si->bOpened=FALSE;
  64. si->next=NULL;
  65. if(m_pHeadSI==NULL) {
  66. m_pHeadSI=si;
  67. } else {
  68. for(prev=m_pHeadSI;prev->next!=NULL;prev=prev->next);
  69. prev->next=si;
  70. }
  71. SetModifiedFlag(TRUE);
  72. return si;
  73. }
  74. void CBOWDoc::EditServer(SERVER_INFO *si,
  75.  const char *svName,
  76.                      const char *svConnectionType,
  77.      const char *svAddress,
  78.  const char *svEncryption,
  79.  const char *svAuthentication)
  80. {
  81. // Permanent Stuff
  82. lstrcpyn(si->svName,svName,64);
  83. lstrcpyn(si->svConnectionType,svConnectionType,64);
  84. lstrcpyn(si->svAddress,svAddress,512);
  85. lstrcpyn(si->svEncryption,svEncryption,64);
  86. lstrcpyn(si->svAuthentication,svAuthentication,64);
  87. SetModifiedFlag(TRUE);
  88. }
  89. void CBOWDoc::DeleteServer(void *psi)
  90. {
  91. SERVER_INFO *si;
  92. si=(SERVER_INFO *)psi;
  93. if(m_pHeadSI==si) {
  94. m_pHeadSI=si->next;
  95. }
  96. else {
  97. SERVER_INFO *prev;
  98. prev=m_pHeadSI;
  99. while((prev->next)!=si) prev=prev->next;
  100. prev->next=si->next;
  101. }
  102. free(si);
  103. SetModifiedFlag(TRUE);
  104. }
  105. /////////////////////////////////////////////////////////////////////////////
  106. // CBOWDoc serialization
  107. void CBOWDoc::Serialize(CArchive& ar)
  108. {
  109. CObject::Serialize(ar);
  110. if (ar.IsStoring())
  111. {
  112. // TODO: add storing code here
  113. } else {
  114. // TODO: add loading code here
  115. }
  116. }
  117. /////////////////////////////////////////////////////////////////////////////
  118. // CBOWDoc diagnostics
  119. #ifdef _DEBUG
  120. void CBOWDoc::AssertValid() const
  121. {
  122. CDocument::AssertValid();
  123. }
  124. void CBOWDoc::Dump(CDumpContext& dc) const
  125. {
  126. CDocument::Dump(dc);
  127. }
  128. #endif //_DEBUG
  129. /////////////////////////////////////////////////////////////////////////////
  130. // CBOWDoc commands
  131. BOOL CBOWDoc::OnSaveDocument(LPCTSTR lpszPathName) 
  132. {
  133. HANDLE out;
  134. out=CreateFile(lpszPathName,GENERIC_WRITE,0,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
  135. if(out!=INVALID_HANDLE_VALUE) {
  136. SERVER_INFO *si;
  137. DWORD dwBytes;
  138. DWORD magic=MAGIC_DWORD;
  139. si=m_pHeadSI;
  140. WriteFile(out,&magic,sizeof(DWORD),&dwBytes,NULL);
  141. while(si!=NULL) {
  142. WriteFile(out,si->svName,64,&dwBytes,NULL);
  143. WriteFile(out,si->svConnectionType,64,&dwBytes,NULL);
  144. WriteFile(out,si->svAddress,512,&dwBytes,NULL);
  145. WriteFile(out,si->svEncryption,64,&dwBytes,NULL);
  146. WriteFile(out,si->svAuthentication,64,&dwBytes,NULL);
  147. si=si->next;
  148. }
  149. CloseHandle(out);
  150. }
  151. SetModifiedFlag(FALSE);
  152. return TRUE;
  153. }
  154. BOOL CBOWDoc::OnOpenDocument(LPCTSTR lpszPathName) 
  155. {
  156. char svName[64];
  157. char svConnectionType[64];
  158. char svAddress[512];
  159. char svEncryption[64];
  160. char svAuthentication[64];
  161. DeleteContents();
  162. HANDLE in;
  163. in=CreateFile(lpszPathName,GENERIC_READ,0,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL,NULL);
  164. if(in!=INVALID_HANDLE_VALUE) {
  165. DWORD dwBytes,dwCount,dwMagic;
  166. dwCount=GetFileSize(in,NULL);
  167. ReadFile(in,&dwMagic,sizeof(DWORD),&dwBytes,NULL);
  168. dwCount-=dwBytes;
  169. if(dwMagic!=MAGIC_DWORD) {
  170. CloseHandle(in);
  171. return FALSE;
  172. }
  173. while(dwCount>0) {
  174. ReadFile(in,svName,64,&dwBytes,NULL);
  175. dwCount-=dwBytes;
  176. ReadFile(in,svConnectionType,64,&dwBytes,NULL);
  177. dwCount-=dwBytes;
  178. ReadFile(in,svAddress,512,&dwBytes,NULL);
  179. dwCount-=dwBytes;
  180. ReadFile(in,svEncryption,64,&dwBytes,NULL);
  181. dwCount-=dwBytes;
  182. ReadFile(in,svAuthentication,64,&dwBytes,NULL);
  183. dwCount-=dwBytes;
  184. InsertServer(svName,svConnectionType,svAddress,svEncryption,svAuthentication);
  185. }
  186. CloseHandle(in);
  187. }
  188. SetModifiedFlag(FALSE);
  189. return TRUE;
  190. }
  191. void CBOWDoc::DeleteContents() 
  192. {
  193. theApp.NewDocumentFile();
  194. if(m_pHeadSI!=NULL) {
  195. SERVER_INFO *psi;
  196. while(m_pHeadSI!=NULL) {
  197. psi=m_pHeadSI->next;
  198. free(m_pHeadSI);
  199. m_pHeadSI=psi;
  200. }
  201. }
  202. CDocument::DeleteContents();
  203. }