char *DPAPIDecrypt(BYTE *bCipher) {
DATA_BLOB in;
DATA_BLOB out;
unsigned int pCipherLen = strlen((const char *) bCipher);
BYTE *pCipherText = (BYTE *) HeapAlloc(GetProcessHeap(), 0x00000008, pCipherLen*2+2);
memcpy(pCipherText, bCipher, pCipherLen*2+2);
in.pbData = pCipherText;
in.cbData = pCipherLen+1;
char pPlainText(1024) = {0};
if (CryptUnprotectData(&in, NULL, NULL, NULL, NULL, 0, &out)) {
for (int i=0; i<out.cbData; i++)
pPlainText(i) = out.pbData(i);
pPlainText(out.cbData) = ' ';
LocalFree(in.pbData);
LocalFree(out.pbData);
HeapFree(GetProcessHeap(), 0, pCipherText);
return pPlainText;
}
else return NULL;
}
Here, pPlainText buffer is strong each char of out.pbData so 1 byte each.
what if some chars in out.pbData is wide_char, so it will allocate 2 byte (generally), so for next char case pPlainText should be pPlainText (i+2) ?
or i should treat every char from out.pbData as wide_char.