I am quite new to C++, could anyone help me to fix memory copy issue (invalid pointer of destination):
cut out code looks like this:
int cWrapper::EncryptRun(const unsigned char *data, NewCamDData *cd, int len, bool UseMsgId, comm_type_t commType)
{
memcpy(desKey , cd->desKey, 16);
int sz = sizeof(DES_key_schedule);
memcpy(&ks1, &cd->ks1, sz);
memcpy(&ks2, &cd->ks2, sz);
unsigned char netbuf[CWS_NETMSGSIZE];
memset(&netbuf[2],0,cdLen+2);
memcpy(&netbuf[cdLen+4],data,len);
netbuf[cdLen+4+1]=(data[1]&0xf0)|(((len-3)>>8)&0x0f);
netbuf[cdLen+4+2]=(len-3)&0xff;
memcpy(&data,&netbuf,len);
}
data points to an array of 240 bytes, and netbuf is new byte array to be copied to data.
To complete calls, I am adding the method which calls this:
DllExport int CALLBACK EncryptA(NewCamDData *cd, unsigned char *pBuffer, int len, bool UseMsgId, comm_type_t commType)
{
cw = new cWrapper(525);
int ret = cw->EncryptRun(pBuffer, cd, len, UseMsgId, commType);
return ret; }
This method called from VB.NET.
debugging shows me this:
?netbuf
0x0038ebec ""
[0]: 0 <-first byte of array
[1]: 48 '0'
[2]: 169 '©'
?data
0x0280aee4 "€ ¤+ØÔ&§HœõRøî°¶l-áþ«…"
?sizeof(data)
4
?*data
128 '€' <-first byte of array