buf is actually assign to the value of (LPBYTE) LockResource(LoadResource(NULL, hRsrc));
, any guesses if that's null terminated?
Depends from the type of resource, but most probably no. Anyhow, since you are working with resources, you can get the resource size using the SizeofResource
function.
Still, I'm not sure if you can write on stuff returned by LockResource
(it actually returns a pointer to the region containing the resource, that is probably just a region in the memory-mapped executable). Most probably you'll want to copy it elsewhere before XORing it.
HGLOBAL resource=LoadResource(NULL, hRsrc);
if(resource==NULL)
{
// ... handle the failure ...
}
LPBYTE resPtr=LockResource(resource);
DWORD resSize=SizeofResource(NULL, hRsrc);
if(resPtr==NULL || resSize==0)
{
// ...
}
std::vector<BYTE> buffer(resPtr, resPtr+resSize);
// Now do whatever you want to do with your buffer
for(size_t i=0; i<buffer.size(); ++i)
buffer[i]^=key;