How does it work?

MagNumDB is a database that contains about 350,000 items. These items are constants, names, values all extracted from more than 6,000 header files (.h, .hxx, .hpp, .idl, etc.) provided by standard Windows and Visual Studio SDKs and WDKs.

Some values have been extracted from the very special uuid.lib file that contains the value of thousands of guids and property keys, not present anywhere else in header files. This can explain some duplicates (because names in uuid.lib are not always exactly the same as names in .h parsed files...).

It also contains around 36,0000 undocumented guids that we found ... meeeeep ...

 "C2P5"

To build this database, we have tried many existing parsers, things like CLANG or other fine tools, but they just don't suit our needs. They can't handle thousands of files that don't compile together, they can't handle some specific (or just very old) Microsoft constructs or annotations, they don't remember the stack of #define directives that led to a definition, they only give you a final AST, not a partial one, etc.

So, in the end, we have written a C/C++ parser named C2P5 (for C/CPP/PreProcessor/Parser), tailored specifically for computing constants. C2P5 is capable of preprocessing, parsing and partially evaluating all header files as if they were included in a one big virtual project (that of course, does not compile) on a 32G RAM machine. It currently supports the following preprocessor and C/C++ constructs:

  • #define preprocessor that define constants
  • #define preprocessor that define expression to compute constants
  • C and C++ constants, strings and enum definitions, and some level of pointerness
  • Special GUID constructs like DECLSPEC_UUID, DEFINE_GUIDSTRUCT, MIDL_INTERFACE, you name it
  • PROPERTYKEY constructs
  • Some IDL constructs
  • Etc.

The parser remembers dynamic preprocessor definitions (#if, #ifdef, etc.) that are conditions for constants definitions and expression computation. All parsed items are saved in the database, as well as the associated conditions. There may be more than one item corresponding to a given name, if there are differences in their associated conditions stack.

C2P5 supports the following types of constants, regardless of the way they are defined in source files:

  • integer, signed or unsigned, from 8-bit to 128-bit
  • floating point number, single (32-bit) or double (64-bit)
  • globally unique identifier, or guid, uuid, CLSID, IID, etc.
  • string, in narrow, wide, or utf-8/16/32 formats
  • character, in narrow, wide, or utf-8/16/32 formats
  • pointer, a constant cast as a pointer
  • property key, or PROPERTYKEY, or PKEY, a combination of a guid (fmtid) and a 32-bit integer (id).

 Powered by

C2P5 and this MagNumDB web site are written in C# and use a Lucene database as a full-text search engine. C2P5 uses a custom ANTLR4cs C grammar for expression parsing, not for preprocessor parsing.

 

 Frequently Asked Questions

  • Q: Can I run custom queries?
    A: Yes. You can use Lucene's query syntax. Note the Database is case insensitive. Check out the list of columns with their corresponding database column names:

    • Index: the item's index.
    • Name: the item's name, or title. For enum values, it's prefixed with the enum's name.
      Corresponding database field: title.
    • Type: the item's type, expressed in a specific, universal system.
      Corresponding database's field: valuetype, but use the value of the Storage type column for queries on items type.
    • Value: the item's value. For string values, it's displayed as is w/o quotes nor escaping.
      Corresponding database field: value. There is also a typedvalue field that can contain database's Int32, Int64, Float, Double or String typed values.
    • Hex Value: the item's hexadecimal value, only valid for integer types.
      There is no corresponding database field.
    • Signed Value: the item's signed value, only valid for integer and double types. Useful when you found a unsigned number and want to get the corresponding signed value (uint -> int for example).
      There is no corresponding database field.
    • Source lines(s): the source lines from which the item was extracted. Comments and characters such as TAB, CR are preserved.
      Corresponding database field: source.
    • File path: the file path from which the item was extracted, terminated by the line index.
      Corresponding database field: filepath. There are also directory and filename fields. filename is useful to query for values in a given file.
    • Score: Database's score value. Items are returned sorted by score.
    • Guid formats: a utility columns that proposes all possible guid formats. Only valid for guid types.
      There is no corresponding database field
    • Char type: the character encoding (narrow, wide, etc.). Only valid for char and string values.
      Corresponding database field: chartype.
    • Storage type: the exact storage type in the database. Only used for specific queries.
      Corresponding database field: valuetype.
    • Conditions: the list of preprocessor conditions for a given item. If a condition is surrounded with a REVERSE function, it means the reverse condition of what's surrounded was the condition.
      Corresponding database field: conditions. There may be multiple conditions fields for one item.

    Some important points to note:

    • If you search for a negative number (like error codes expressed using signed integers), you can surround the search with double quotes, for example searching for "-2147009290" is equivalent to searching for 0x80073CF6, 80073CF6 (or even 3CF6 in this specific case). If you don't surround negative numbers with double quotes, the system will search for signed and unsigned corresponding values.
    • The full-text search uses items' name, value, hex value, guid formats, source lines, etc. so refine your search if you get back too many items.
    • You can search for guid binary values using just a part of their full definition. For example, if you search for '79eac9c5', it will get you 3 guid entries
    • Leading wild card search (*whatever) is allowed, but it may slow down the search significantly.

    Here are some example or custom queries:

    title:wm_user returns the WM_USER Windows message item, not all items that reference the WM_USER token.

    title:wm_u* returns all items (Windows messages probably) whose name starts with WM_U*.

    value:1024 AND title:wm_* returns all items (Windows messages probably) whose name starts with WM_U* and value is 1024. Note AND must be UPPERCASE for database to understand it as an AND operator.

    value:"00000002-0000-0000-C000-000000000046" returns the IMalloc IID guid value.

  • Q: I always get back 400 items at most. Why?
    A: The MagNumDb site currently limits the number of returned items to this value by design. This should be enough for most real search scenarios (like enums with a big list of values).

  • Q: Some values are empty. Why?
    A: The expression evaluator cannot always compute the final value, because it sometimes require contextual information (custom defines, compiler architecture, etc.) that the parser doesn't have at parsing time. You can enable the Source line(s) column to check what's the corresponding source and try to work it out by yourself. The origin file path and line number is also included.

  • Q: Can I get all values for a given enum?
    A: Sure. For example, __VSHPROPID is the name of an enum, and a query like this: parent:__VSHPROPID will get all the enum's values (66 entries).

  • Q: I sometimes get back items whose name starts with "__magnumdb__enum_". Why?
    A: C allows unnamed enums. The MagNumDb parser just gives them a name, using the defining file name and a counter.

  • Q: I sometimes get back the same item/name twice or more with different values. For example:  TARGET_IS_NT60_OR_LATER. Why?
    A: This can be the case with defines. Their value may be different if they were surrounded by # directives (#if, #else, etc.) in the original source code. You can enable the Condition(s) column to check what are the corresponding conditions for a given item.
    Note: if a condition is surrounded with a funny REVERSE function token, it means the reverse condition of what's surrounded.

 Database Metrics

  • Last update date: Thursday May 13, 2020
  • Items count: 340878
  • Parsed files count: 8447
  • Windows SDK version: 10.0.19041.0
  • NetFx SDK version: 4.8
  • MSVC Tools version: 14.25.28610

 

 Contact

We welcome feedback.
Seen anything missing? A bug? A wrong value? Do you have any suggestion for improvements? Do you have an idea for a cool new feature?

Please contact us here

 About MagNumDB

MagNumDB  2017-2020 Simon Mourier V1.3.2. All rights reserved.

Profile for Simon Mourier at Stack Overflow, Q&A for professional and enthusiast programmers


All product names, logos, and brands are property of their respective owners. All company, product and service names used in this website are for identification purposes only.

All values, names, source code fragments displayed here have been extracted from files that are property of their respective owners.

THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND OTHER THAN AS SPECIFICALLY SET FORTH IN THE LICENSE AGREEMENT, INCLUDING WITHOUT LIMITATION WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Index Score Name Type Value Hex value Signed value Guid formats Char type Storage type Source line(s) File path Condition(s)
Index Score Name Type Value Hex value Signed value Guid formats Char type Storage type Source line(s) File path Condition(s)
1 4.875161 Bookmark Int32 292 0x00000124 292 System.Int32
static const int Bookmark = 292;
%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Professional\VSSDK\VisualStudioIntegration\Common\Inc\KnownImageIds.h(354,0)
2 4.136711 EVT_RENDER_FLAGS::EvtRenderBookmark Int32 2 0x00000002 2 System.Int32
EvtRenderBookmark                   // Bookmark
%ProgramFiles(x86)%\Windows Kits\10\Include\10.0.19041.0\um\winevt.h(352,0)
  • If WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_PKG_EVENTLOGSERVICE)
  • If (WINVER >= _WIN32_WINNT_LONGHORN)
3 3.900129 SQL_C_BOOKMARK Int32 -27 0xFFFFFFE5 -27 System.Int32
#define SQL_C_BOOKMARK   SQL_C_UBIGINT                     /* BOOKMARK        */
#define SQL_C_BOOKMARK   SQL_C_UBIGINT                     /* BOOKMARK        */
%ProgramFiles(x86)%\Windows Kits\10\Include\10.0.19041.0\um\sqlext.h(553,0)
  • If WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
  • Ifdef _WIN64
4 3.900129 SQL_C_BOOKMARK Int32 -18 0xFFFFFFEE -18 System.Int32
#define SQL_C_BOOKMARK   SQL_C_ULONG                       /* BOOKMARK        */
#define SQL_C_BOOKMARK   SQL_C_ULONG                       /* BOOKMARK        */
%ProgramFiles(x86)%\Windows Kits\10\Include\10.0.19041.0\um\sqlext.h(555,0)
  • If WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
  • REVERSE(Ifdef _WIN64)
5 3.900129 JET_errInvalidBookmark Int32 -1045 0xFFFFFBEB -1045 System.Int32
#define JET_errInvalidBookmark              -1045 /* Invalid bookmark */
#define JET_errInvalidBookmark              -1045 /* Invalid bookmark */
%ProgramFiles(x86)%\Windows Kits\10\Include\10.0.19041.0\um\esent.h(3264,0)
  • If !defined(_JET_INCLUDED)
6 3.447259 OpenOptions::useBookmarks Int32 256 0x00000100 256 System.Int32
useBookmarks =              0x0100, // turn on bookmark support
%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.16.27023\atlmfc\include\afxdb.h(631,0)
7 3.447259 dbBindBookmark Int32 15 0x0000000F 15 System.Int32
#define dbBindBookmark			DAO_BOOKMARK			// bookmark psuedo field
%ProgramFiles(x86)%\Windows Kits\10\Include\10.0.19041.0\um\dbdao.h(74,0)
  • If WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
8 3.412612 JET_errBadBookmark Int32 -328 0xFFFFFEB8 -328 System.Int32
#define JET_errBadBookmark                  -328  /* Bookmark has no corresponding address in database */
#define JET_errBadBookmark                  -328  /* Bookmark has no corresponding address in database */
%ProgramFiles(x86)%\Windows Kits\10\Include\10.0.19041.0\um\esent.h(3076,0)
  • If !defined(_JET_INCLUDED)
9 2.925097 JET_bitPrereadNormalizedKey Int32 8 0x00000008 8 System.Int32
#define JET_bitPrereadNormalizedKey 0x00000008  /*  Normalized key/bookmark provided instead of column value */
#define JET_bitPrereadNormalizedKey 0x00000008  /*  Normalized key/bookmark provided instead of column value */
%ProgramFiles(x86)%\Windows Kits\10\Include\10.0.19041.0\um\esent.h(2435,0)
  • If !defined(_JET_INCLUDED)
  • If ( JET_VERSION >= 0x0601 )
  • If ( JET_VERSION >= 0x0602 )
10 2.757807 EVT_RENDER_FLAGS Enum
typedef enum _EVT_RENDER_FLAGS
{
    EvtRenderEventValues = 0,           // Variants
    EvtRenderEventXml,                  // XML
    EvtRenderBookmark                   // Bookmark

 } EVT_RENDER_FLAGS;
%ProgramFiles(x86)%\Windows Kits\10\Include\10.0.19041.0\um\winevt.h(348,0)
  • If WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_PKG_EVENTLOGSERVICE)
  • If (WINVER >= _WIN32_WINNT_LONGHORN)
11 2.757807 E_DAO_InvalidBookmark UInt32 2148142167 0x800A0C57 -2146825129 System.UInt32
#define E_DAO_InvalidBookmark				DBDAOERR(3159) //Not a valid bookmark.
%ProgramFiles(x86)%\Windows Kits\10\Include\10.0.19041.0\um\dbdaoerr.h(189,0)
  • If WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
12 2.757807 ED_EDIT_SEEK_BOOKMARK Int32 4781 0x000012AD 4781 System.Int32
#define ED_EDIT_SEEK_BOOKMARK	ED_BASE+685L	// seek to bookmark (just like
%ProgramFiles(x86)%\Windows Kits\10\Include\10.0.19041.0\um\edevdefs.h(515,0)
  • If WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
13 2.757807 JET_bitBookmarkPermitVirtualCurrency Int32 1 0x00000001 1 System.Int32
#define JET_bitBookmarkPermitVirtualCurrency    0x00000001  //  place cursor on relative position in index if specified bookmark no longer exists
%ProgramFiles(x86)%\Windows Kits\10\Include\10.0.19041.0\um\esent.h(2340,0)
  • If !defined(_JET_INCLUDED)
  • If ( JET_VERSION >= 0x0501 )
14 1.206541 OpenOptions Enum
enum OpenOptions
	{
		none =                      0x0,
		readOnly =                  0x0004,
		appendOnly =                0x0008,
		skipDeletedRecords =        0x0010, // turn on skipping of deleted records, Will slow Move(n).
		noDirtyFieldCheck =         0x0020, // disable automatic dirty field checking
		useBookmarks =              0x0100, // turn on bookmark support
		useMultiRowFetch =          0x0200, // turn on multi-row fetch model
		userAllocMultiRowBuffers =  0x0400, // if multi-row fetch on, user will alloc memory for buffers
		useExtendedFetch =          0x0800, // use SQLExtendedFetch with forwardOnly type recordsets
		executeDirect =             0x2000, // Directly execute SQL rather than prepared execute
		optimizeBulkAdd =           0x4000, // Use prepared HSTMT for multiple AddNews, dirty fields must not change.
		firstBulkAdd =              0x8000, // INTERNAL to MFC, don't specify on Open.
	};
%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Professional\VC\Tools\MSVC\14.16.27023\atlmfc\include\afxdb.h(624,0)