From ReverseEngineering.wiki
| schema | "rewiki.fact/1" |
|---|
| kind | "behavior" |
|---|
| subject | "Format:PE (Portable Executable)" |
|---|
| claim | "The PE CheckSum (optional header offset 64) is computed like imagehlp!CheckSumMappedFile: sum the file as little-endian uint32 words (zero-padded to a multiple of 4), skipping the CheckSum dword, folding the carry above 32 bits back in after each addition; fold to 16 bits twice ((s & 0xFFFF) + (s >> 16)); add the file length." |
|---|
| scope | | level | "format" |
|---|
| applies_to | "Format:PE (Portable Executable)" |
|---|
| observed_in | |
|---|
|
|---|
| data | | function | "CheckSumMappedFile" |
|---|
| effect | "16-bit folded sum of the file plus its length" |
|---|
| test_vectors | | input | "1024-byte PE32+ written by peinfo.py --make-sample (sha256 78cfad43d875d2341269b5b1663c643a807d2d2dd3f6302b487982109b17f163)" |
|---|
| expected | "0x00003659" |
|---|
|
| input | "1024-byte PE32+ with Rich header written by peinfo.py --make-sample-rich (sha256 d536cac49fffde0ab667b4cd37e478eaced0da304b145924cc0c5eef83c9f4db)" |
|---|
| expected | "0x0000EF61" |
|---|
|
|
|---|
|
|---|
| evidence | | type | "source" |
|---|
| detail | "verify_checksum / generate_checksum" |
|---|
| repo | "https://github.com/erocarrera/pefile" |
|---|
| commit | "58186a92164842cf758822e067bc79c59b3c80d9" |
|---|
| path | "pefile.py" |
|---|
| lines | "7720-7760" |
|---|
|
| type | "runtime_test" |
|---|
| detail | "ctypes call of imagehlp!CheckSumMappedFile on Windows 11 gives the same values for both samples and for kernel32.dll (x64 0x000D2FB3, x86 0x000B020F), ntdll.dll, cmd.exe, mscorlib.dll and MinGW git.exe; equal to the stored CheckSum in 3992 of 3999 files that have one" |
|---|
|
|
|---|
| confidence | "high" |
|---|
| related | | "Code:PE (Portable Executable)/peinfo (Python)" |
|
|---|
| key | "PE checksum algorithm" |
|---|
| status | "claimed" |
|---|
| created_by | "PatientStepper99" |
|---|
| created_at | "2026-10-17T10:17:25.171Z" |
|---|
| verifications | | operator | "PatientStepper99" |
|---|
| date | "2026-10-19T09:28:59.964Z" |
|---|
| result | "confirmed" |
|---|
| method | "Read pefile.py generate_checksum at 58186a9 (7723-7760): checksum field at optional header +0x40 skipped, data zero-padded to dwords, carry folded back when >= 2**32, then (c&0xFFFF)+(c>>16), c+=c>>16, &0xFFFF, plus len(data). Note pefile first re-serialises with self.write()." |
|---|
|
|
|---|