Created
July 24, 2017 15:16
-
-
Save drewsberry/f5035ea51453706e105af91d33cbbeba to your computer and use it in GitHub Desktop.
Analyse HRESULT 32-bit code for what it means in a human readable format.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const facilities = [ | |
{ | |
code: 0, | |
name: "FACILITY_NULL", | |
description: "The default facility code.", | |
}, | |
{ | |
code: 1, | |
name: "FACILITY_RPC", | |
description: "The source of the error code is an RPC subsystem.", | |
}, | |
{ | |
code: 2, | |
name: "FACILITY_DISPATCH", | |
description: "The source of the error code is a COM Dispatch.", | |
}, | |
{ | |
code: 3, | |
name: "FACILITY_STORAGE", | |
description: "The source of the error code is OLE Storage.", | |
}, | |
{ | |
code: 4, | |
name: "FACILITY_ITF", | |
description: "The source of the error code is COM/OLE Interface management.", | |
}, | |
{ | |
code: 7, | |
name: "FACILITY_WIN32", | |
description: "This region is reserved to map undecorated error codes into HRESULTs.", | |
}, | |
{ | |
code: 8, | |
name: "FACILITY_WINDOWS", | |
description: "The source of the error code is the Windows subsystem.", | |
}, | |
{ | |
code: 9, | |
name: "FACILITY_SECURITY/FACILITY_SSPI", | |
description: "The source of the error code is the Security API layer.", | |
}, | |
{ | |
code: 10, | |
name: "FACILITY_CONTROL", | |
description: "The source of the error code is the control mechanism.", | |
}, | |
{ | |
code: 11, | |
name: "FACILITY_CERT", | |
description: "The source of the error code is a certificate client or server?", | |
}, | |
{ | |
code: 12, | |
name: "FACILITY_INTERNET", | |
description: "The source of the error code is Wininet related.", | |
}, | |
{ | |
code: 13, | |
name: "FACILITY_MEDIASERVER", | |
description: "The source of the error code is the Windows Media Server.", | |
}, | |
{ | |
code: 14, | |
name: "FACILITY_MSMQ", | |
description: "The source of the error code is the Microsoft Message Queue.", | |
}, | |
{ | |
code: 15, | |
name: "FACILITY_SETUPAPI", | |
description: "The source of the error code is the Setup API.", | |
}, | |
{ | |
code: 16, | |
name: "FACILITY_SCARD", | |
description: "The source of the error code is the Smart-card subsystem.", | |
}, | |
{ | |
code: 17, | |
name: "FACILITY_COMPLUS", | |
description: "The source of the error code is COM+.", | |
}, | |
{ | |
code: 18, | |
name: "FACILITY_AAF", | |
description: "The source of the error code is the Microsoft agent.", | |
}, | |
{ | |
code: 19, | |
name: "FACILITY_URT", | |
description: "The source of the error code is .NET CLR.", | |
}, | |
{ | |
code: 20, | |
name: "FACILITY_ACS", | |
description: "The source of the error code is the audit collection service.", | |
}, | |
{ | |
code: 21, | |
name: "FACILITY_DPLAY", | |
description: "The source of the error code is Direct Play.", | |
}, | |
{ | |
code: 22, | |
name: "FACILITY_UMI", | |
description: "The source of the error code is the ubiquitous memoryintrospection service.", | |
}, | |
{ | |
code: 23, | |
name: "FACILITY_SXS", | |
description: "The source of the error code is Side-by-side servicing.", | |
}, | |
{ | |
code: 24, | |
name: "FACILITY_WINDOWS_CE", | |
description: "The error code is specific to Windows CE.", | |
}, | |
{ | |
code: 25, | |
name: "FACILITY_HTTP", | |
description: "The source of the error code is HTTP support.", | |
}, | |
{ | |
code: 26, | |
name: "FACILITY_USERMODE_COMMONLOG", | |
description: "The source of the error code is common Logging support.", | |
}, | |
{ | |
code: 31, | |
name: "FACILITY_USERMODE_FILTER_MANAGER", | |
description: "The source of the error code is the user mode filter manager.", | |
}, | |
{ | |
code: 32, | |
name: "FACILITY_BACKGROUNDCOPY", | |
description: "The source of the error code is background copy control", | |
}, | |
{ | |
code: 33, | |
name: "FACILITY_CONFIGURATION", | |
description: "The source of the error code is configuration services.", | |
}, | |
{ | |
code: 34, | |
name: "FACILITY_STATE_MANAGEMENT", | |
description: "The source of the error code is state management services.", | |
}, | |
{ | |
code: 35, | |
name: "FACILITY_METADIRECTORY", | |
description: "The source of the error code is the Microsoft Identity Server.", | |
}, | |
{ | |
code: 36, | |
name: "FACILITY_WINDOWSUPDATE", | |
description: "The source of the error code is a Windows update.", | |
}, | |
{ | |
code: 37, | |
name: "FACILITY_DIRECTORYSERVICE", | |
description: "The source of the error code is Active Directory.", | |
}, | |
{ | |
code: 38, | |
name: "FACILITY_GRAPHICS", | |
description: "The source of the error code is the graphics drivers.", | |
}, | |
{ | |
code: 39, | |
name: "FACILITY_SHELL", | |
description: "The source of the error code is the user Shell.", | |
}, | |
{ | |
code: 40, | |
name: "FACILITY_TPM_SERVICES", | |
description: "The source of the error code is the Trusted Platform Module services.", | |
}, | |
{ | |
code: 41, | |
name: "FACILITY_TPM_SOFTWARE", | |
description: "The source of the error code is the Trusted Platform Module applications.", | |
}, | |
{ | |
code: 48, | |
name: "FACILITY_PLA", | |
description: "The source of the error code is Performance Logs and Alerts", | |
}, | |
{ | |
code: 49, | |
name: "FACILITY_FVE", | |
description: "The source of the error code is Full volume encryption.", | |
}, | |
{ | |
code: 50, | |
name: "FACILITY_FWP", | |
description: "The source of the error code is the Firewall Platform.", | |
}, | |
{ | |
code: 51, | |
name: "FACILITY_WINRM", | |
description: "The source of the error code is the Windows Resource Manager.", | |
}, | |
{ | |
code: 52, | |
name: "FACILITY_NDIS", | |
description: "The source of the error code is the Network Driver Interface.", | |
}, | |
{ | |
code: 53, | |
name: "FACILITY_USERMODE_HYPERVISOR", | |
description: "The source of the error code is the Usermode Hypervisor components.", | |
}, | |
{ | |
code: 54, | |
name: "FACILITY_CMI", | |
description: "The source of the error code is the Configuration Management Infrastructure.", | |
}, | |
{ | |
code: 55, | |
name: "FACILITY_USERMODE_VIRTUALIZATION", | |
description: "The source of the error code is the user mode virtualization subsystem.", | |
}, | |
{ | |
code: 56, | |
name: "FACILITY_USERMODE_VOLMGR", | |
description: "The source of the error code is the user mode volume manager", | |
}, | |
{ | |
code: 57, | |
name: "FACILITY_BCD", | |
description: "The source of the error code is the Boot Configuration Database.", | |
}, | |
{ | |
code: 58, | |
name: "FACILITY_USERMODE_VHD", | |
description: "The source of the error code is user mode virtual hard disk support.", | |
}, | |
{ | |
code: 60, | |
name: "FACILITY_SDIAG", | |
description: "The source of the error code is System Diagnostics.", | |
}, | |
{ | |
code: 61, | |
name: "FACILITY_WEBSERVICES", | |
description: "The source of the error code is the Web Services.", | |
}, | |
{ | |
code: 80, | |
name: "FACILITY_WINDOWS_DEFENDER", | |
description: "The source of the error code is a Windows Defender component.", | |
}, | |
{ | |
code: 81, | |
name: "FACILITY_OPC", | |
description: "The source of the error code is the open connectivity service.", | |
}, | |
]; | |
function analyse_hresult(hresult) { | |
const facilityCode = (hresult >>> 16) & 0x7ff; | |
const errorCode = hresult & 0xffff; | |
const isFailure = (hresult >>> 31) === 1; | |
const isSevereFailure = ((hresult >>> 30) & 0x1) === 1; | |
const isMicrosoftDefined = ((hresult >>> 29) & 0x1) === 1; | |
const isMappedNTStatusValue = ((hresult >>> 28) & 0x1) === 1; | |
const reservedValueIsValid = ((hresult >>> 27) & 0x1) === 1; | |
if (isFailure) { | |
console.log("Hresult represents a failure."); | |
} else { | |
console.log("Hresult represents a warning."); | |
} | |
if (isSevereFailure) { | |
console.log("Hresult is a severe failure."); | |
} | |
if (!isMicrosoftDefined) { | |
console.log("Hresult does not represent a Microsoft defined status code."); | |
console.log("Hresult facility code is", facilityCode); | |
} else { | |
const facility = facilities.find(f => f.code === facilityCode); | |
if (facility === undefined) { | |
console.log("Unable to identify facility for hresult."); | |
} else { | |
console.log("Hresult facility is", facility.name, ":", facility.description); | |
} | |
} | |
if (isMappedNTStatusValue) { | |
console.log("Hresult represents a mapped NT status value."); | |
// TODO: Calculate NT status value and display description of it; | |
// see https://msdn.microsoft.com/en-us/library/cc704588.aspx. | |
} | |
// TODO: Check against known HRESULT values; | |
// see https://msdn.microsoft.com/en-us/library/cc704587.aspx. | |
console.log("Error code is", errorCode); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment