Change the value of a variable const
is not possible ; however, if you can force to stop being const
.
BOOL WINAPI H_CertVerifyCertificateChainPolicy( ... ) {
const_cast<PCERT_CHAIN_CONTEXT>(pChainContext)->TrustStatus.dwErrorStatus = CERT_TRUST_IS_REVOKED;
return TRUE;
}
That code will do what you want.
Now, if you want to cheat your application for some kind of test, the best way would be to use dynamic memory and copy the data there:
BOOL WINAPI H_CertVerifyCertificateChainPolicy( ... ) {
PCERT_CHAIN_CONTEXT *tmp = new CERT_CHAIN_CONTEXT;
memcpy( tmp, pChainContext, sizeof( CERT_CHAIN_CONTEXT ) );
tmp->TrustStatus.dwErrorStatus = CERT_TRUST_IS_REVOKED;
return TRUE;
}
And you would need some way for your application to access that memory that you use, instead of the original data.
If what you want is to cheat the cryptographic API, modifying data used internally by it ... let's say that the behavior will be undefined . The same API was based on that data to allocate or not allocate memory, or it will do so in the future, and your changes will make the clamp fence , stop working, malfunction. ..
Or maybe that API will pass pointers to copies of the actual data that she uses, in which case your attempts will be wasteful .
Or maybe you're lucky, nothing happens, and it works.
Or now you cheat on it and in a future update it starts to do weird things .
In general, it's not a good idea to modify to force data that we do not really know how they are used.