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

远程控制编程

开发平台:

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. // pluginconfig.cpp : implementation file
  16. //
  17. #include "stdafx.h"
  18. #include "bo2kgui.h"
  19. #include "MainFrm.h"
  20. #include "pluginconfig.h"
  21. #include "dll_load.h"
  22. #ifdef _DEBUG
  23. #define new DEBUG_NEW
  24. #undef THIS_FILE
  25. static char THIS_FILE[] = __FILE__;
  26. #endif
  27. /////////////////////////////////////////////////////////////////////////////
  28. // CPluginConfig dialog
  29. CPluginConfig::CPluginConfig(CWnd* pParent /*=NULL*/)
  30. : CDialog(CPluginConfig::IDD, pParent)
  31. {
  32. //{{AFX_DATA_INIT(CPluginConfig)
  33. // NOTE: the ClassWizard will add member initialization here
  34. //}}AFX_DATA_INIT
  35. }
  36. void CPluginConfig::DoDataExchange(CDataExchange* pDX)
  37. {
  38. CDialog::DoDataExchange(pDX);
  39. //{{AFX_DATA_MAP(CPluginConfig)
  40. // NOTE: the ClassWizard will add DDX and DDV calls here
  41. //}}AFX_DATA_MAP
  42. }
  43. BEGIN_MESSAGE_MAP(CPluginConfig, CDialog)
  44. //{{AFX_MSG_MAP(CPluginConfig)
  45. ON_BN_CLICKED(IDC_INSERT, OnInsert)
  46. ON_BN_CLICKED(IDC_REMOVE, OnRemove)
  47. ON_NOTIFY(TVN_SELCHANGED, IDC_OPTIONVARIABLES, OnSelchangedOptionvariables)
  48. ON_BN_CLICKED(IDC_BOOL_DISABLED, OnBoolDisabled)
  49. ON_BN_CLICKED(IDC_BOOL_ENABLED, OnBoolEnabled)
  50. ON_BN_CLICKED(IDC_SETVALUE, OnSetvalue)
  51. //}}AFX_MSG_MAP
  52. END_MESSAGE_MAP()
  53. /////////////////////////////////////////////////////////////////////////////
  54. // CPluginConfig message handlers
  55. BOOL CPluginConfig::OnInitDialog() 
  56. {
  57. CDialog::OnInitDialog();
  58. m_ImgList.Create(IDB_IMGLIST,16,1,RGB(0,255,0));
  59. CListCtrl *pLC=((CListCtrl *)GetDlgItem(IDC_PLUGINS));
  60. pLC->InsertColumn(0,"Plugin Name",LVCFMT_LEFT,100,-1);
  61. pLC->InsertColumn(1,"Version",LVCFMT_LEFT,48,-1);
  62. pLC->InsertColumn(2,"BO2K Ver",LVCFMT_LEFT,60,-1);
  63. pLC->InsertColumn(3,"Description",LVCFMT_LEFT,200,-1);
  64. pLC->SetImageList(&m_ImgList,LVSIL_SMALL);
  65. pLC->SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_HEADERDRAGDROP);
  66. CTreeCtrl *pTC=(CTreeCtrl *)GetDlgItem(IDC_OPTIONVARIABLES);
  67. pTC->SetImageList(&m_ImgList,TVSIL_NORMAL);
  68. int i,count;
  69. CMainFrame *pFrm=(CMainFrame *)AfxGetMainWnd();
  70. count=pFrm->m_arrPluginInfo.GetSize();
  71. for(i=0;i<count;i++) {
  72. CString str;
  73. PLUGIN_INFO pi;
  74. pi=pFrm->m_arrPluginInfo[i];
  75. pLC->InsertItem(i,pi.svFilename,0);
  76. str.Format("%d.%d",pi.wVersionHi,pi.wVersionLo);
  77. pLC->SetItem(i,1,LVIF_TEXT,str,0,0,0,0);
  78. str.Format("%d.%d",pi.wBOVersionHi,pi.wBOVersionLo);
  79. pLC->SetItem(i,2,LVIF_TEXT,str,0,0,0,0);
  80. pLC->SetItem(i,3,LVIF_TEXT,pi.svDescription,0,0,0,0);
  81. }
  82. UpdateVariableList();
  83. EnableControls(FALSE);
  84. return TRUE;  // return TRUE unless you set the focus to a control
  85.               // EXCEPTION: OCX Property Pages should return FALSE
  86. }
  87. void CPluginConfig::EnableControls(BOOL bEnable)
  88. {
  89. // Deselect All List/Tree Controls
  90. ((CTreeCtrl *)GetDlgItem(IDC_OPTIONVARIABLES))->SelectItem(NULL);
  91. ((CListCtrl *)GetDlgItem(IDC_PLUGINS))->SetSelectionMark(-1);
  92. // Enable/Disable Controls
  93. GetDlgItem(IDC_STATIC_NEWVAL)->EnableWindow(FALSE);
  94. GetDlgItem(IDC_STATIC_CURVAL)->EnableWindow(FALSE);
  95. GetDlgItem(IDC_STR_NEWVALUE)->EnableWindow(FALSE);
  96. GetDlgItem(IDC_STR_CURRENTVALUE)->EnableWindow(FALSE);
  97. GetDlgItem(IDC_SETVALUE)->EnableWindow(FALSE);
  98. GetDlgItem(IDC_BOOL_ENABLED)->EnableWindow(FALSE);
  99. GetDlgItem(IDC_BOOL_DISABLED)->EnableWindow(FALSE);
  100. GetDlgItem(IDC_BOOL_GROUP)->EnableWindow(FALSE);
  101. }
  102. BOOL CPluginConfig::IsValidPlugin(LPCSTR svPath)
  103. {
  104. HMODULE hMod;
  105. BOOL bAltLoad=FALSE;
  106. hMod=LoadLibrary(svPath);
  107. if(hMod==NULL) {
  108. bAltLoad=TRUE;
  109. hMod=LoadDLL(svPath);
  110. if(hMod==NULL) return FALSE;
  111. }
  112. FARPROC proc=GetDLLProcAddress(hMod,"InstallPlugin");
  113. if(bAltLoad) FreeDLL(hMod);
  114. else FreeLibrary(hMod);
  115. return (proc==NULL)?FALSE:TRUE;
  116. }
  117. void CPluginConfig::UpdateVariableList()
  118. {
  119. CTreeCtrl *pTC=(CTreeCtrl *)GetDlgItem(IDC_OPTIONVARIABLES);
  120. pTC->DeleteAllItems();
  121. CMainFrame *pFrm=(CMainFrame *)AfxGetMainWnd();
  122. // Add options for executable
  123. pFrm->m_arrVarInfo.RemoveAll();
  124. char *base=(char *)AfxGetInstanceHandle();
  125. PIMAGE_OPTIONAL_HEADER poh=(PIMAGE_OPTIONAL_HEADER)OPTHDROFFSET(base);
  126. pFrm->AddVariables(base, poh->SizeOfImage, -1);
  127. // Add options for all plugins
  128. int i,count;
  129. count=pFrm->m_arrPluginInfo.GetSize();
  130. for(i=0;i<count;i++) {
  131. pFrm->AddVariables((char *)pFrm->m_arrPluginInfo[i].pPluginImage,pFrm->m_arrPluginInfo[i].dwPluginLen,i);
  132. }
  133. // Add option variables to tree control
  134. count=pFrm->m_arrVarInfo.GetSize();
  135. for(i=0;i<count;i++) {
  136. VARIABLE_INFO vi=pFrm->m_arrVarInfo.GetAt(i);
  137. HTREEITEM hti;
  138. // Find category item
  139. hti=pTC->GetRootItem();
  140. while(hti!=NULL) {
  141. if(pTC->GetItemText(hti).Compare(vi.svCategory)==0) break;
  142. hti=pTC->GetNextSiblingItem(hti);
  143. }
  144. if(hti==NULL) {
  145. if(vi.nPlugin==-1) {
  146. hti=pTC->InsertItem(vi.svCategory,4,5);
  147. } else {
  148. hti=pTC->InsertItem(vi.svCategory,6,7);
  149. }
  150. pTC->SetItemData(hti,0xFFFFFFFF);
  151. }
  152. int nImg;
  153. if(vi.VarType=='B') nImg=3;
  154. else if(vi.VarType=='N') nImg=2;
  155. else if(vi.VarType=='S') nImg=1;
  156. hti=pTC->InsertItem(vi.svVarName,nImg,nImg,hti);
  157. pTC->SetItemData(hti,i);
  158. }
  159. }
  160. void CPluginConfig::OnInsert() 
  161. {
  162. CMainFrame *pFrm=(CMainFrame *)AfxGetMainWnd();
  163. CFileDialog cfd(TRUE,".dll",NULL,OFN_PATHMUSTEXIST | OFN_HIDEREADONLY,"DLL Files (*.dll)|*.dll|All Files (*.*)|*.*||",this);
  164. cfd.m_ofn.lpstrTitle="Insert BO2K Plugin";
  165. if(cfd.DoModal()==IDOK) {
  166. if(IsValidPlugin(cfd.GetPathName())) {
  167. int nNum;
  168. CListCtrl *pLC=((CListCtrl *)GetDlgItem(IDC_PLUGINS));
  169. CString str;
  170. PLUGIN_INFO pi;
  171. nNum=pFrm->AddPlugin(cfd.GetPathName());
  172. pi=pFrm->m_arrPluginInfo[nNum];
  173. pLC->InsertItem(nNum,pi.svFilename,0);
  174. str.Format("%d.%d",pi.wVersionHi,pi.wVersionLo);
  175. pLC->SetItem(nNum,1,LVIF_TEXT,str,0,0,0,0);
  176. str.Format("%d.%d",pi.wBOVersionHi,pi.wBOVersionLo);
  177. pLC->SetItem(nNum,2,LVIF_TEXT,str,0,0,0,0);
  178. pLC->SetItem(nNum,3,LVIF_TEXT,pi.svDescription,0,0,0,0);
  179. UpdateVariableList();
  180. } else {
  181. AfxMessageBox("The specified file is not a valid BO2K plugin");
  182. }
  183. }
  184. }
  185. void CPluginConfig::OnRemove() 
  186. {
  187. int nNum;
  188. CMainFrame *pFrm=(CMainFrame *)AfxGetMainWnd();
  189. CListCtrl *pLC=((CListCtrl *)GetDlgItem(IDC_PLUGINS));
  190. nNum=pLC->GetSelectionMark();
  191. if(nNum<0) return;
  192. CString str;
  193. pLC->DeleteItem(nNum);
  194. nNum=pFrm->RemovePlugin(nNum);
  195. UpdateVariableList();
  196. }
  197. void CPluginConfig::OnSelchangedOptionvariables(NMHDR* pNMHDR, LRESULT* pResult) 
  198. {
  199. NMTREEVIEW *pNMTreeView = (NMTREEVIEW*)pNMHDR;
  200. CMainFrame *pFrm=(CMainFrame *)AfxGetMainWnd();
  201. // Hide all option controls
  202. GetDlgItem(IDC_STATIC_NEWVAL)->EnableWindow(FALSE);
  203. GetDlgItem(IDC_STATIC_CURVAL)->EnableWindow(FALSE);
  204. GetDlgItem(IDC_STR_NEWVALUE)->EnableWindow(FALSE);
  205. GetDlgItem(IDC_STR_CURRENTVALUE)->EnableWindow(FALSE);
  206. GetDlgItem(IDC_SETVALUE)->EnableWindow(FALSE);
  207. GetDlgItem(IDC_BOOL_ENABLED)->EnableWindow(FALSE);
  208. GetDlgItem(IDC_BOOL_DISABLED)->EnableWindow(FALSE);
  209. GetDlgItem(IDC_BOOL_GROUP)->EnableWindow(FALSE);
  210. if(pNMTreeView->itemNew.hItem!=NULL) {
  211. int nVar=pNMTreeView->itemNew.lParam;
  212. if(nVar!=0xFFFFFFFF) {
  213. if(pFrm->m_arrVarInfo[nVar].VarType=='B') {
  214. GetDlgItem(IDC_BOOL_GROUP)->EnableWindow();
  215. GetDlgItem(IDC_BOOL_ENABLED)->EnableWindow();
  216. GetDlgItem(IDC_BOOL_DISABLED)->EnableWindow();
  217. if(atoi(pFrm->m_arrVarInfo[nVar].svVarValue)) {
  218. ((CButton *)GetDlgItem(IDC_BOOL_ENABLED))->SetCheck(1);
  219. ((CButton *)GetDlgItem(IDC_BOOL_DISABLED))->SetCheck(0);
  220. } else {
  221. ((CButton *)GetDlgItem(IDC_BOOL_DISABLED))->SetCheck(1);
  222. ((CButton *)GetDlgItem(IDC_BOOL_ENABLED))->SetCheck(0);
  223. }
  224. } else if(pFrm->m_arrVarInfo[nVar].VarType=='N') {
  225. GetDlgItem(IDC_STATIC_NEWVAL)->EnableWindow();
  226. GetDlgItem(IDC_STATIC_CURVAL)->EnableWindow();
  227. GetDlgItem(IDC_STR_NEWVALUE)->EnableWindow();
  228. GetDlgItem(IDC_STR_CURRENTVALUE)->EnableWindow();
  229. GetDlgItem(IDC_SETVALUE)->EnableWindow();
  230. GetDlgItem(IDC_STR_CURRENTVALUE)->SetWindowText(pFrm->m_arrVarInfo[nVar].svVarValue);
  231. GetDlgItem(IDC_STR_NEWVALUE)->SetWindowText("");
  232. ((CEdit *)GetDlgItem(IDC_STR_CURRENTVALUE))->SetLimitText(pFrm->m_arrVarInfo[nVar].nStrLen);
  233. ((CEdit *)GetDlgItem(IDC_STR_NEWVALUE))->SetLimitText(pFrm->m_arrVarInfo[nVar].nStrLen);
  234. GetDlgItem(IDC_STR_CURRENTVALUE)->ModifyStyle(0,ES_NUMBER);
  235. GetDlgItem(IDC_STR_NEWVALUE)->ModifyStyle(0,ES_NUMBER);
  236. } else if(pFrm->m_arrVarInfo[nVar].VarType=='S') {
  237. GetDlgItem(IDC_STATIC_NEWVAL)->EnableWindow();
  238. GetDlgItem(IDC_STATIC_CURVAL)->EnableWindow();
  239. GetDlgItem(IDC_STR_NEWVALUE)->EnableWindow();
  240. GetDlgItem(IDC_STR_CURRENTVALUE)->EnableWindow();
  241. GetDlgItem(IDC_SETVALUE)->EnableWindow();
  242. GetDlgItem(IDC_STR_CURRENTVALUE)->SetWindowText(pFrm->m_arrVarInfo[nVar].svVarValue);
  243. GetDlgItem(IDC_STR_NEWVALUE)->SetWindowText("");
  244. ((CEdit *)GetDlgItem(IDC_STR_CURRENTVALUE))->SetLimitText(pFrm->m_arrVarInfo[nVar].nStrLen);
  245. ((CEdit *)GetDlgItem(IDC_STR_NEWVALUE))->SetLimitText(pFrm->m_arrVarInfo[nVar].nStrLen);
  246. GetDlgItem(IDC_STR_CURRENTVALUE)->ModifyStyle(ES_NUMBER,0);
  247. GetDlgItem(IDC_STR_NEWVALUE)->ModifyStyle(ES_NUMBER,0);
  248. }
  249. }
  250. }
  251. *pResult = 0;
  252. }
  253. void CPluginConfig::OnBoolDisabled() 
  254. {
  255. CTreeCtrl *pTC=(CTreeCtrl *)GetDlgItem(IDC_OPTIONVARIABLES);
  256. CMainFrame *pFrm=(CMainFrame *)AfxGetMainWnd();
  257. HTREEITEM hti=pTC->GetSelectedItem();
  258. int nVar=pTC->GetItemData(hti);
  259. if(nVar!=0xFFFFFFFF) {
  260. pFrm->m_arrVarInfo[nVar].svVarValue[0]='0';
  261. // Set into image
  262. VARIABLE_INFO vi=pFrm->m_arrVarInfo[nVar];
  263. char *ptr;
  264. DWORD pos;
  265. if(vi.nPlugin>=0) {
  266. PLUGIN_INFO pi=pFrm->m_arrPluginInfo[vi.nPlugin];
  267. ptr=(char *)pi.pPluginImage;
  268. } else {
  269. ptr=(char *)AfxGetInstanceHandle();
  270. }
  271. pos=vi.dwPos;
  272. memset(ptr+pos,0,vi.nStrLen+1);
  273. memcpy(ptr+pos,vi.svVarValue,lstrlen(vi.svVarValue));
  274. }
  275. }
  276. void CPluginConfig::OnBoolEnabled() 
  277. {
  278. CTreeCtrl *pTC=(CTreeCtrl *)GetDlgItem(IDC_OPTIONVARIABLES);
  279. CMainFrame *pFrm=(CMainFrame *)AfxGetMainWnd();
  280. HTREEITEM hti=pTC->GetSelectedItem();
  281. int nVar=pTC->GetItemData(hti);
  282. if(nVar!=0xFFFFFFFF) {
  283. pFrm->m_arrVarInfo[nVar].svVarValue[0]='1';
  284. // Set into image
  285. VARIABLE_INFO vi=pFrm->m_arrVarInfo[nVar];
  286. char *ptr;
  287. DWORD pos;
  288. if(vi.nPlugin>=0) {
  289. PLUGIN_INFO pi=pFrm->m_arrPluginInfo[vi.nPlugin];
  290. ptr=(char *)pi.pPluginImage;
  291. } else {
  292. ptr=(char *)AfxGetInstanceHandle();
  293. }
  294. pos=vi.dwPos;
  295. memset(ptr+pos,0,vi.nStrLen+1);
  296. memcpy(ptr+pos,vi.svVarValue,lstrlen(vi.svVarValue));
  297. }
  298. }
  299. void CPluginConfig::OnSetvalue()
  300. {
  301. CMainFrame *pFrm=(CMainFrame *)AfxGetMainWnd();
  302. CTreeCtrl *pTC=(CTreeCtrl *)GetDlgItem(IDC_OPTIONVARIABLES);
  303. HTREEITEM hti=pTC->GetSelectedItem();
  304. int nVar=pTC->GetItemData(hti);
  305. if(nVar!=0xFFFFFFFF) {
  306. CString str;
  307. GetDlgItem(IDC_STR_NEWVALUE)->GetWindowText(str);
  308. if(pFrm->m_arrVarInfo[nVar].VarType=='N') {
  309. int nValue=atoi(str);
  310. if((nValue>pFrm->m_arrVarInfo[nVar].nNumHi) ||
  311.    (nValue<pFrm->m_arrVarInfo[nVar].nNumLo)) {
  312. AfxMessageBox("Value is out of range.");
  313. return;
  314. }
  315. }
  316. lstrcpyn(pFrm->m_arrVarInfo[nVar].svVarValue,str,256);
  317. GetDlgItem(IDC_STR_CURRENTVALUE)->SetWindowText(str);
  318. // Set into image
  319. VARIABLE_INFO vi=pFrm->m_arrVarInfo[nVar];
  320. char *ptr;
  321. DWORD pos;
  322. if(vi.nPlugin>=0) {
  323. PLUGIN_INFO pi=pFrm->m_arrPluginInfo[vi.nPlugin];
  324. ptr=(char *)pi.pPluginImage;
  325. } else {
  326. ptr=(char *)AfxGetInstanceHandle();
  327. }
  328. pos=vi.dwPos;
  329. memset(ptr+pos,0,vi.nStrLen+1);
  330. memcpy(ptr+pos,vi.svVarValue,lstrlen(vi.svVarValue));
  331. }
  332. }