in TPM Parser/Tpm2Lib/Tpm2.cs [180:235]
public static string GetErrorString(Type inParmsType, uint resultCode, out TpmRc theMaskedError)
{
// There are two encoding for errors - format 0 and format 1. Decode the error type
var resultCodeValue = resultCode;
bool formatOneErrorType = ((resultCodeValue & 0x80) != 0);
uint resultCodeMask = formatOneErrorType ? 0xBFU : 0x97FU;
// Extract the actual error code
uint maskedErrorVal = resultCode & resultCodeMask;
var maskedError = (TpmRc)maskedErrorVal;
theMaskedError = maskedError;
string errorEntity = "Unknown";
uint errorEntityIndex = 0;
string errorParmName = "Unknown";
if (formatOneErrorType)
{
errorEntityIndex = (resultCodeValue & 0xF00U) >> 8;
if (errorEntityIndex == 0)
{
// ReSharper disable once RedundantAssignment
errorEntity = "Unknown";
}
if ((resultCodeValue & 0x40) != 0)
{
errorEntity = "Parameter";
errorParmName = GetParmName(inParmsType, errorEntityIndex);
}
else
{
if (errorEntityIndex >= 8)
{
errorEntityIndex -= 8;
errorEntity = "Session";
}
else
{
errorEntity = "handle";
}
}
}
string errorString = String.Format(
"[Code=TpmRc.{0}],[FullVal=0x{1:X},{1}]\n" +
"[ErrorEntity={2}],[ParmNum={3}]" +
"[ParmName={4}]",
new Object[] {
maskedError.ToString(),
//(uint)maskedError,
resultCodeValue,
errorEntity,
errorEntityIndex,
errorParmName
});
return errorString;
}