Skip to content

Commit 260e60b

Browse files
Gnawbieclaude
andcommitted
Fix uint32 cast failure on exit code table in PS 5.1
PS 5.1 parses hex literals > 0x7FFFFFFF as signed Int32 (e.g. 0xC0000005 becomes -1073741819), then [uint32] cast of a negative value throws at startup. Switch hashtable keys to formatted hex strings ('0xC0000005') and look up via '0x{0:X8}' -f $Code. Range comparisons updated to use plain decimal int64 literals to avoid the same issue. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 389ff2a commit 260e60b

1 file changed

Lines changed: 32 additions & 26 deletions

File tree

ProcessMonitor.ps1

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -48,42 +48,48 @@ function Format-ExitCode {
4848
}
4949

5050
# ── Known exit code descriptions ─────────────────────────────
51-
# Each entry has a Short (log tag) and Plain (layman explanation)
51+
# Keys are uppercase 8-digit hex strings (e.g. "0xC0000005") to avoid
52+
# PS 5.1 signed/unsigned integer casting issues with [uint32] key syntax.
5253
$script:ExitCodeTable = @{
53-
[uint32]0x00000001 = @{ Short="generic error"; Plain="The program exited with a generic failure code - no specific crash reason was recorded." }
54-
[uint32]0x00000002 = @{ Short="file not found"; Plain="The program could not find a file it needed. It may have been moved, deleted, or never installed." }
55-
[uint32]0x00000003 = @{ Short="path not found"; Plain="The program tried to access a folder that does not exist. A reinstall may fix this." }
56-
[uint32]0x00000005 = @{ Short="access denied"; Plain="The program was blocked from accessing a file or resource. Try running as administrator." }
57-
[uint32]0x00000102 = @{ Short="wait timeout"; Plain="The program waited too long for something to respond (a server, a file, another process) and gave up." }
58-
[uint32]0xC0000005 = @{ Short="access violation"; Plain="The program tried to read or write memory it does not own. Usually a bug, bad mod/plugin, or driver conflict. A reinstall or update may help." }
59-
[uint32]0xC0000017 = @{ Short="out of memory"; Plain="The program ran out of memory. Try closing other applications, or your system may need more RAM." }
60-
[uint32]0xC000001D = @{ Short="illegal instruction"; Plain="The program tried to execute an invalid CPU instruction. This can mean corrupt install files, hardware incompatibility, or overclocking instability." }
61-
[uint32]0xC000008E = @{ Short="FP divide by zero"; Plain="The program tried to divide a decimal number by zero. This is a bug in the program." }
62-
[uint32]0xC0000094 = @{ Short="integer divide by zero"; Plain="The program tried to divide a whole number by zero. This is a bug in the program." }
63-
[uint32]0xC00000FD = @{ Short="stack overflow"; Plain="The program ran out of stack space, usually from a function calling itself indefinitely. This is a bug in the program." }
64-
[uint32]0xC0000135 = @{ Short="DLL not found"; Plain="A required library file (.dll) is missing. Try reinstalling the program or installing the relevant runtime (e.g. Visual C++ Redistributable)." }
65-
[uint32]0xC0000142 = @{ Short="DLL init failed"; Plain="A required library loaded but failed to start. This can be caused by a corrupt install, a missing dependency, or an antivirus blocking it." }
66-
[uint32]0xC0000374 = @{ Short="heap corruption"; Plain="The program's memory was corrupted while it was running. Often caused by a bug, an incompatible mod or plugin, or a faulty RAM stick." }
67-
[uint32]0xC0000409 = @{ Short="stack buffer overrun"; Plain="The program wrote data past the end of a reserved memory area. This is a serious bug - if it keeps happening, check for malware or a bad update." }
68-
[uint32]0xC000041D = @{ Short="unhandled callback exception"; Plain="An unhandled error occurred inside a Windows callback. Usually a bug in the program or an incompatible system component." }
69-
[uint32]0xC0000602 = @{ Short="fail fast exception"; Plain="The program detected a critical internal error and shut itself down on purpose. Check the program's own logs for details." }
70-
[uint32]0xE0434352 = @{ Short=".NET CLR exception"; Plain="An unhandled error occurred in a .NET application. Check the Windows Event Viewer (Application log) for the full error message and stack trace." }
71-
[uint32]0xCFFFFFFF = @{ Short="game/custom crash code"; Plain="The game or program caught an internal error and exited with its own crash code. Check the game's own crash log or support site for details." }
54+
"0x00000001" = @{ Short="generic error"; Plain="The program exited with a generic failure code - no specific crash reason was recorded." }
55+
"0x00000002" = @{ Short="file not found"; Plain="The program could not find a file it needed. It may have been moved, deleted, or never installed." }
56+
"0x00000003" = @{ Short="path not found"; Plain="The program tried to access a folder that does not exist. A reinstall may fix this." }
57+
"0x00000005" = @{ Short="access denied"; Plain="The program was blocked from accessing a file or resource. Try running as administrator." }
58+
"0x00000102" = @{ Short="wait timeout"; Plain="The program waited too long for something to respond (a server, a file, another process) and gave up." }
59+
"0xC0000005" = @{ Short="access violation"; Plain="The program tried to read or write memory it does not own. Usually a bug, bad mod/plugin, or driver conflict. A reinstall or update may help." }
60+
"0xC0000017" = @{ Short="out of memory"; Plain="The program ran out of memory. Try closing other applications, or your system may need more RAM." }
61+
"0xC000001D" = @{ Short="illegal instruction"; Plain="The program tried to execute an invalid CPU instruction. This can mean corrupt install files, hardware incompatibility, or overclocking instability." }
62+
"0xC000008E" = @{ Short="FP divide by zero"; Plain="The program tried to divide a decimal number by zero. This is a bug in the program." }
63+
"0xC0000094" = @{ Short="integer divide by zero"; Plain="The program tried to divide a whole number by zero. This is a bug in the program." }
64+
"0xC00000FD" = @{ Short="stack overflow"; Plain="The program ran out of stack space, usually from a function calling itself indefinitely. This is a bug in the program." }
65+
"0xC0000135" = @{ Short="DLL not found"; Plain="A required library file (.dll) is missing. Try reinstalling the program or installing the relevant runtime (e.g. Visual C++ Redistributable)." }
66+
"0xC0000142" = @{ Short="DLL init failed"; Plain="A required library loaded but failed to start. This can be caused by a corrupt install, a missing dependency, or an antivirus blocking it." }
67+
"0xC0000374" = @{ Short="heap corruption"; Plain="The program's memory was corrupted while it was running. Often caused by a bug, an incompatible mod or plugin, or a faulty RAM stick." }
68+
"0xC0000409" = @{ Short="stack buffer overrun"; Plain="The program wrote data past the end of a reserved memory area. This is a serious bug - if it keeps happening, check for malware or a bad update." }
69+
"0xC000041D" = @{ Short="unhandled callback exception"; Plain="An unhandled error occurred inside a Windows callback. Usually a bug in the program or an incompatible system component." }
70+
"0xC0000602" = @{ Short="fail fast exception"; Plain="The program detected a critical internal error and shut itself down on purpose. Check the program's own logs for details." }
71+
"0xE0434352" = @{ Short=".NET CLR exception"; Plain="An unhandled error occurred in a .NET application. Check the Windows Event Viewer (Application log) for the full error message and stack trace." }
72+
"0xCFFFFFFF" = @{ Short="game/custom crash code"; Plain="The game or program caught an internal error and exited with its own crash code. Check the game's own crash log or support site for details." }
7273
}
7374

75+
function Get-ExitCodeKey { param([uint32]$Code); return "0x{0:X8}" -f $Code }
76+
7477
function Get-ExitCodeDescription {
7578
param([uint32]$Code)
76-
if ($script:ExitCodeTable.ContainsKey($Code)) { return $script:ExitCodeTable[$Code].Short }
77-
if ($Code -ge [uint32]0xC0000000 -and $Code -le [uint32]0xCFFFFFFF) { return "unhandled exception" }
78-
if ($Code -ge [uint32]0xE0000000) { return "user-defined exception" }
79+
$key = Get-ExitCodeKey $Code
80+
if ($script:ExitCodeTable.ContainsKey($key)) { return $script:ExitCodeTable[$key].Short }
81+
# 0xC0000000-0xCFFFFFFF = Windows NTSTATUS errors; 0xE0000000+ = user-defined
82+
if ($Code -ge 3221225472 -and $Code -le 3489660927) { return "unhandled exception" }
83+
if ($Code -ge 3758096384) { return "user-defined exception" }
7984
return $null
8085
}
8186

8287
function Get-ExitCodePlain {
8388
param([uint32]$Code)
84-
if ($script:ExitCodeTable.ContainsKey($Code)) { return $script:ExitCodeTable[$Code].Plain }
85-
if ($Code -ge [uint32]0xC0000000 -and $Code -le [uint32]0xCFFFFFFF) { return "An unhandled Windows exception caused the program to crash." }
86-
if ($Code -ge [uint32]0xE0000000) { return "The program exited with a user-defined exception code. Check the program's own logs for details." }
89+
$key = Get-ExitCodeKey $Code
90+
if ($script:ExitCodeTable.ContainsKey($key)) { return $script:ExitCodeTable[$key].Plain }
91+
if ($Code -ge 3221225472 -and $Code -le 3489660927) { return "An unhandled Windows exception caused the program to crash." }
92+
if ($Code -ge 3758096384) { return "The program exited with a user-defined exception code. Check the program's own logs for details." }
8793
return $null
8894
}
8995

0 commit comments

Comments
 (0)