-
I'm using CryptDecodeObject function in C# using CsWin32. Only initializing PCWSTR with byte*(char*) is allowed. How do I set greater than 255(byte max value)? private static unsafe CMSG_SIGNER_INFO? GetSignerInfo(void* hMsg, uint index)
{
nint pbEncodedSigner = nint.Zero;
uint cbEncodedSigner = 0;
nint pSignerInfo = nint.Zero;
uint cbSignerInfo = 0;
var bResult = PInvoke.CryptMsgGetParam(
hMsg,
28, // CMSG_ENCODED_SIGNER
index,
null,
&cbEncodedSigner);
if (cbEncodedSigner == 0)
{
Cleanup(pbEncodedSigner);
return null;
}
pbEncodedSigner = Marshal.AllocHGlobal((int)cbEncodedSigner / Marshal.SizeOf(typeof(byte)));
bResult = PInvoke.CryptMsgGetParam(
hMsg,
28,
index,
(void*)pbEncodedSigner,
ref cbEncodedSigner);
var error = Marshal.GetLastWin32Error();
if (cbEncodedSigner == 0)
{
Cleanup(pbEncodedSigner);
return null;
}
// HERE!!!
uint byMsg = 500;
PCSTR pMsg = new((byte*)&byMsg);
bResult = PInvoke.CryptDecodeObject(
CERT_QUERY_ENCODING_TYPE.X509_ASN_ENCODING | CERT_QUERY_ENCODING_TYPE.PKCS_7_ASN_ENCODING,
pMsg,
(byte*)pbEncodedSigner,
cbEncodedSigner,
0,
null,
&cbSignerInfo);
pSignerInfo = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(CMSG_SIGNER_INFO)));
return null;
bool Cleanup(nint pbEncodedSigner)
{
if (pbEncodedSigner != nint.Zero)
Marshal.FreeHGlobal(pbEncodedSigner);
return false;
}
} |
Beta Was this translation helpful? Give feedback.
Answered by
AArnott
Feb 21, 2024
Replies: 1 comment 1 reply
-
You appear to be trying to pass a pointer to the byte* byMsg = (byte*)500;
PCSTR pMsg = new(byMsg); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
0x5bfa
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You appear to be trying to pass a pointer to the
500
value. That's not what the documentation requires. It wants to see500
as the value of the pointer itself rather than the value that is pointed to.I think this will do the trick: