Home > Back-end >  Memcpy to crash the program, please help to find the reason
Memcpy to crash the program, please help to find the reason

Time:01-05



 

Void CServerDlg: : OnClientRecive (CONNID dwConnID, dwords dwCommand, const BYTE * pData, int iLength)
{

Try {
The switch (dwCommand)
{
Case: 99999
{
Char * buff=new char [iLength + 1];
Memset (buff, 0, iLength + 1);
Memcpy (buff, pData, iLength);

SoftCloseByNickname (buff);
The delete [] buff;
break;
}
Case CMD_ASK_PWD:
{
//InsertLog (" received key request ");
//AfxMessageBox (" received key request ");
//generate keys
String PWD=GenerateRandPwd ();
TagClientPwd * pClientPwd=new tagClientPwd;
: : memset (pClientPwd - & gt; SzPwd, 0, 17);
PClientPwd - & gt; ConnId=dwConnID;
Strcpy (pClientPwd - & gt; SzPwd, PWD. C_str ());
M_ptrClientPwd. AddTail (pClientPwd);

//send keys
STD: : string encoded_data=https://bbs.csdn.net/topics/base64_encode (reinterpret_cast (PWD) c_str ()), the PWD. The size ());
M_ClientServer. Send (dwConnID CMD_PWD_RESULT, (BYTE *) encoded_data. C_str (), encoded_data. The size ());
}
break;
Case CMD_FIND_WINDOW_TITLE:
{
//AfxMessageBox (" find a window!" );
Buff tagHackToolCheck *=new tagHackToolCheck ();
: : memset (buff, 0, sizeof (tagHackToolCheck));
Memcpy (buff, pData, iLength);

SYSTEMTIME STR.
GetLocalTime (& amp; str);
Cstrings time;
Time. The Format (wglog \ \ "window - % d % d - % which xt", STR) wYear, STR., wMonth, STR., wDay);

The FILE * fp=fopen (time, "at +");
If (fp)
{
SYSTEMTIME st.
GetLocalTime (& amp; St);

Cstrings output;
. The output Format (" % d % d - % d % d: % d: % d [% s] USES - & gt; % s \ n ", st. wYear, st. wMonth, st. wDay, st. wHour, st. wMinute, st. wSecond, buff - & gt; Nickname, buff - & gt; The flag);

Fputs (output. GetBuffer (0), fp);
fclose(fp);


//m_editCtrl +=cstrings (" \ n ") + output;
//the UpdateData (FALSE);

SoftCloseByNickname (buff - & gt; Nickname);
ClearHeartInfo (buff - & gt; Nickname);

}

The delete buff.
break;
}
Case CMD_FIND_PROCESS:
{
Buff tagHackToolCheck *=new tagHackToolCheck ();
: : memset (buff, 0, sizeof (tagHackToolCheck));
Memcpy (buff, pData, iLength);

SYSTEMTIME STR.
GetLocalTime (& amp; str);
Cstrings time;
Time. The Format (" wglog \ \ process - % % d % d - which xt ", STR) wYear, STR., wMonth, STR., wDay);

The FILE * fp=fopen (time, "at +");
If (fp)
{
SYSTEMTIME st.
GetLocalTime (& amp; St);

Cstrings output;
. The output Format (" % d % d - % d % d: % d: % d [% s] USES - & gt; % s \ n ", st. wYear, st. wMonth, st. wDay, st. wHour, st. wMinute, st. wSecond, buff - & gt; Nickname, buff - & gt; The flag);

//m_editCtrl +=cstrings (" \ n ") + output;
//the UpdateData (FALSE);



Fputs (output. GetBuffer (0), fp);
fclose(fp);

SoftCloseByNickname (buff - & gt; Nickname);
ClearHeartInfo (buff - & gt; Nickname);
}

The delete buff.
break;
}

//there is something wrong with the keyword here is encrypted window first comments
/*
Case CMD_ASK_WINDOW_KEYWORDS:
{
String PWD="";
The POSITION pos=m_ptrClientPwd. GetHeadPosition ();
While (pos!=NULL)
{
The POSITION temp=pos;
TagClientPwd * pInfo=(tagClientPwd *) m_ptrClientPwd GetNext (pos);
If (pInfo!=NULL)
{
If (pInfo - & gt; ConnId==dwConnID)
{
The PWD=pInfo - & gt; SzPwd;
break;
}
}
}
If (PWD. Empty ())
{
return;
}


String windowKeywords;
The FILE * fp=fopen (" window. TXT ", "r");
If (fp)
{
Char line [128].
Memset (line, 0, 128);
while(! The feof (fp))
{

The fgets (line, 128, fp);
If (line [strlen (line) - 1]=='\ n') {
Line [strlen (line) - 1]='\ 0';
}
If (line [strlen (line) - 1]=='\ r) {
Line [strlen (line) - 1]='\ 0';
}
WindowKeywords + + string=line (", ");
}
fclose(fp);
}


WindowKeywords [windowKeywords. The size () - 1]='\ 0';


//m_editCtrl +=cstrings (" \ n Windows key word: "). + windowKeywords c_str ();
//the UpdateData (FALSE);

//cstrings STR.
//STR. The Format (" % d ", windowKeywords. The size ());
//AfxMessageBox (STR);


AES AES ((unsigned char *) PWD c_str ());
Char * buff=new char [1024].
: : memset (buff, 0, 1024);
Memcpy (buff, (char *) windowKeywords c_str (), windowKeywords. The size ());
Buff=(char *) aes. Encode (buff, 1024);
STD: : string encoded_data=https://bbs.csdn.net/topics/base64_encode (reinterpret_cast (buff), 1024);

//AfxMessageBox (encoded_data c_str ());



Byte * sendbuff=new byte [encoded_data. The size () + 1);
Memset (sendbuff, 0, encoded_data. The size () + 1);
Memcpy (sendbuff, encoded_data c_str (), encoded_data. The size ());
M_ClientServer. Send (dwConnID CMD_WINDOW_DATA, sendbuff, encoded_data. The size ());

//BOOL bRet=m_ClientServer. Send (dwConnID CMD_WINDOW_DATA, sendbuff, windowKeywords. The size ());
//if (! BRet)
//{
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related