I have seen the other links on this site about this topic but they are not helpful. If anyone can help me with this I would greatly appreciate it.
I am reading a line of encrypted text generated with the WinCrypt API using Visual Studio C++ 2010 express like this:
BSTR element;
HRESULT txt = command_body->get_innerText(&element);
size_t len = SysStringLen(element);
unsigned char * cmds;
cmds = (char *)malloc(len);
int ret = wcstombs(cmds,element,len);
The debugger shows that element
is pointing to:
"ƒ¦Þ’Î 80:—ÇE³Ž(ùÖðRñ¨5·®•D²Q „× O»C¤ôýdÉùèGñ(åÒ¬¶»“ŽYÞŸÇi‹Bú{l!‹#dŽ "
element
has data type wchar_t *
, however in order for decryption to take place I need it as a char *. The data was encrypted with RC4 using WinCrypt.
I have tried wcstombs
and it does not work at all. Results in cmds
being "[][]"
.
I am not sure what I am doing wrong but I need to somehow have this data as a char *
or perhaps I am missing something completely. From what I have read here on MSDN it would appear that I would need to specify a new locale..but I am not sure which locale to specify in order for this data to make sense...
Here is the full code:
int main()
{
OleInitialize(NULL);
IWebBrowser2* m_pInetExplorer;
HRESULT hr;
CLSID clsid;
LPUNKNOWN punk=NULL;
CLSIDFromProgID (OLESTR("InternetExplorer.Application"), &clsid);
hr = CoCreateInstance (clsid, NULL, CLSCTX_SERVER, IID_IUnknown, (LPVOID *) &punk);
VARIANT vars[4];
memset(vars,0,sizeof(vars));
BSTR BStrURL = ::SysAllocString(L"http://127.0.0.1:8000/testing.html");
if(SUCCEEDED(hr))
{
punk->QueryInterface (IID_IWebBrowser2, (LPVOID *) &m_pInetExplorer);
punk->Release();
m_pInetExplorer->put_Visible(VARIANT_TRUE);
HRESULT hrie = m_pInetExplorer->Navigate(BStrURL,vars,vars+1,vars+2,vars+3); //Go to webpage
if (SUCCEEDED(hrie))
{
VARIANT_BOOL bBusy = VARIANT_TRUE;
while(bBusy == VARIANT_TRUE)
{
Sleep(500);
m_pInetExplorer->get_Busy(&bBusy);
}
IDispatch* pDisp;
HRESULT test_doc = m_pInetExplorer->get_Document(&pDisp);
if(SUCCEEDED(test_doc))
{
IHTMLDocument2* pHTMLDocument2;
HRESULT hr;
hr = pDisp->QueryInterface( IID_IHTMLDocument2,(void**)&pHTMLDocument2 );
if(SUCCEEDED(hr))
{
IHTMLElement* command_body;
HRESULT get_body = pHTMLDocument2->get_body(&command_body);
if(SUCCEEDED(get_body))
{
BSTR element;
HRESULT txt = command_body->get_innerText(&element);
size_t len = SysStringLen(element);
unsigned char * cmds;
cmds = (char *)malloc(len);
memcpy(cmds,element,len);
}
}
}
}
}
}