Just started to port my injection code over to BDS 2009. I use both aspects of BDS i.e. BCB and Delphi. I havent tried any injection stuff yet, I'm just looking at setting up the IPC comms.
I think i might have run into a bug with the SendIPCMessage / IPC callback when used with the BDS UnicodeString. I’m using a UnicodeString and the Length() method should return the size of the string contained in the UnicodeString object. Under tests, this returns 17 – which is correct for my packet based on the fact that the UnicodeString is twice the length of a the Ansi equiverlent. However, on the IPC callback side, using this value causes the packet to be truncated:
Code: Select all
// Client Send
int iIPCRtn = -1;
DWORD dwSessionId, dwProcessId;
dwProcessId = GetCurrentProcessId();
dwSessionId = ProcessIdToSessionId(dwProcessId, &dwSessionId);
UnicodeString wzPacket;
wzPacket.sprintf(IPC_PACKET_KEY_STATUS,
IPC_PROTOCOL_STARTER,
IPC_TYPE_KEY,
IPC_PROTOCOL_DELIMITER,
IPC_REQUEST_KEY_STATUS,
IPC_PROTOCOL_DELIMITER,
IPC_ACTION_QUERY_OBJECT,
IPC_PROTOCOL_DELIMITER,
dwSessionId,
IPC_PROTOCOL_DELIMITER,
dwProcessId,
IPC_PROTOCOL_TERMINATOR);
if ((SendIpcMessage(IPC_QUEUE_KEY_STATUS_NAME, wzPacket.c_str(), wzPacket.Length(), &iIPCRtn, sizeof(&iIPCRtn), SEND_IPC_TIMEOUT)) && (iIPCRtn >= -1))
{
// do something…
}
// Server Receive
void CALLBACK TKeyPollThrd::IPCKeyMsg(char *cName, void *pMsgBuf, unsigned int iMsgLen, void *pRtnBuf, unsigned int iRtnLen)
{
EnterCriticalSection(&pThis->csKeyCritSect);
try
{
UnicodeString wzMsg = UnicodeString((wchar_t*)pMsgBuf);
wzMsg.SetLength(iMsgLen);
}
__finally
{
LeaveCriticalSection(&pThis->csKeyCritSect);
}
}
Code: Select all
if ((SendIpcMessage(IPC_QUEUE_KEY_STATUS_NAME,
wzPacket.c_str(),
([b]wzPacket.Length()*2)[/b],
&iIPCRtn, sizeof(&iIPCRtn),
SEND_IPC_TIMEOUT)) && (iIPCRtn >= -1))
I have tried adding 1 or 2 to the Length() value just incase the terminator was being clipped of but it makes no difference.
Not quite sure if this is a bug or a problem with UnicodeString. Please advice if anyone else has seen this.
Mike C