wbenny / pdbex

pdbex is a utility for reconstructing structures and unions from the PDB into compilable C headers
MIT License
814 stars 160 forks source link

Fix enum sign-extension #24

Closed diversenok closed 1 month ago

diversenok commented 1 month ago

This pull request fixes a bug in reconstructing some values in enumerations. The switch-case branch that prints unsigned two-byte (VT_UI2) values used to misinterpret them as signed and, thus, sing-extending them before printing.

Here is an example of an incorrect output:

enum tagCLSCTX
{
  // -- truncated --
  CLSCTX_RESERVED5 = 2048,
  CLSCTX_NO_CUSTOM_MARSHAL = 4096,
  CLSCTX_ENABLE_CODE_DOWNLOAD = 8192,
  CLSCTX_NO_FAILURE_LOG = 16384,
  CLSCTX_DISABLE_AAA = 0xffff8000, // <--- should be 0x8000 instead
  CLSCTX_ENABLE_AAA = 0x10000,
  CLSCTX_FROM_DEFAULT_CONTEXT = 0x20000,
  // -- truncated --
};

The PR adjusts the code to access the correct variant fields.