ntBldSymDb.cpp revision be8a316f38a47c77279ec3eefdca315d8ea05de9
/* $Id$ */
/** @file
* IPRT - RTDirCreateUniqueNumbered, generic implementation.
*/
/*
* Copyright (C) 2013 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#include <Windows.h>
#include <Dbghelp.h>
#include <iprt/initterm.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/** A structure member we're interested in. */
typedef struct MYMEMBER
{
/** The member name. */
const char * const pszName;
/** Reserved. */
/** The offset of the member. UINT32_MAX if not found. */
/** The size of the member. */
/** Alternative names, optional.
* This is a string of zero terminated strings, ending with an zero length
* string (or double '\\0' if you like). */
const char * const pszzAltNames;
} MYMEMBER;
/** Pointer to a member we're interested. */
/** Members we're interested in. */
typedef struct MYSTRUCT
{
/** The structure name. */
const char * const pszName;
/** Array of members we're interested in. */
/** The number of members we're interested in. */
/** Reserved. */
} MYSTRUCT;
/** Set of structures for one kernel. */
typedef struct MYSET
{
/** The list entry. */
/** The source PDB. */
char *pszPdb;
/** The OS version we've harvested structs for */
/** The structures and their member. */
} MYSET;
/** Pointer a set of structures for one kernel. */
/*******************************************************************************
* Global Variables *
*******************************************************************************/
/** Set if verbose operation.*/
static bool g_fVerbose = false;
/** The members of the KPRCB structure that we're interested in. */
static MYMEMBER g_aKprcbMembers[] =
{
};
/** The structures we're interested in. */
static MYSTRUCT g_aStructs[] =
{
};
/** List of data we've found. This is sorted by version info. */
static RTLISTANCHOR g_SetList;
/**
*
* @param pszFormat The format string.
* @param ... The arguments referenced in the format string.
*/
static void MyDbgPrintf(const char *pszFormat, ...)
{
if (g_fVerbose)
{
RTPrintf("debug: ");
}
}
/**
* Returns the name we wish to use in the C code.
* @returns Structure name.
* @param pStruct The structure descriptor.
*/
{
while (*psz == '_')
psz++;
return psz;
}
/**
* Returns the name we wish to use in the C code.
* @returns Member name.
* @param pStruct The member descriptor.
*/
{
}
/**
* Creates a MYSET with copies of all the data and inserts it into the
* g_SetList in a orderly fashion.
*
* @param pOut The output stream.
*/
{
"/* $" "I" "d" ": $ */\n" /* avoid it being expanded */
"/** @file\n"
" * IPRT - NT kernel type helpers - Autogenerated, do NOT edit.\n"
" */\n"
"\n"
"/*\n"
" * Copyright (C) 2013 Oracle Corporation\n"
" *\n"
" * This file is part of VirtualBox Open Source Edition (OSE), as\n"
" * available from http://www.virtualbox.org. This file is free software;\n"
" * General Public License (GPL) as published by the Free Software\n"
" * Foundation, in version 2 as it comes in the \"COPYING\" file of the\n"
" * VirtualBox OSE distribution. VirtualBox OSE is distributed in the\n"
" * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.\n"
" *\n"
" * The contents of this file may alternatively be used under the terms\n"
" * of the Common Development and Distribution License Version 1.0\n"
" * (CDDL) only, as it comes in the \"COPYING.CDDL\" file of the\n"
" * VirtualBox OSE distribution, in which case the provisions of the\n"
" * CDDL are applicable instead of those of the GPL.\n"
" *\n"
" * You may elect to license modified versions of this file under the\n"
" * terms and conditions of either the GPL or the CDDL or both.\n"
" */\n"
"\n"
"\n"
"#ifndef ___r0drv_nt_symdbdata_h\n"
"#define ___r0drv_nt_symdbdata_h\n"
"\n"
"\n"
);
/*
* Generate types.
*/
{
"typedef struct RTNTSDBTYPE_%s\n"
"{\n",
{
" uint32_t off%s;\n"
" uint32_t cb%s;\n",
}
"} RTNTSDBTYPE_%s;\n"
"\n",
}
"\n"
"typedef struct RTNTSDBSET\n"
"{\n"
" RTNTSDBOSVER%-20s OsVerInfo;\n", "");
{
}
"} RTNTSDBSET;\n"
"typedef RTNTSDBSET const *PCRTNTSDBSET;\n"
"\n");
/*
* Output the data.
*/
"\n"
"#ifndef RTNTSDB_NO_DATA\n"
"const RTNTSDBSET g_rtNtSdbSets[] = \n"
"{\n");
{
" { /* Source: %s */\n"
" /*.OsVerInfo = */\n"
" {\n"
" /* .uMajorVer = */ %u,\n"
" /* .uMinorVer = */ %u,\n"
" /* .fChecked = */ %s,\n"
" /* .fSmp = */ %s,\n"
" /* .uCsdNo = */ %u,\n"
" /* .uBuildNo = */ %u,\n"
" },\n",
{
" /* .%s = */\n"
" {\n", pszStructName);
{
" /* .off%-25s = */ %#06x,\n"
" /* .cb%-26s = */ %#06x,\n",
}
" },\n");
}
" },\n");
}
"};\n"
"#endif /* !RTNTSDB_NO_DATA */\n"
"\n");
}
/**
* Creates a MYSET with copies of all the data and inserts it into the
* g_SetList in a orderly fashion.
*
* @returns Fully complained exit code.
* @param pOsVerInfo The OS version info.
*/
{
/*
* Allocate one big chunk, figure it's size once.
*/
static size_t s_cbNeeded = 0;
if (s_cbNeeded == 0)
{
}
if (!pSet)
/*
* Copy over the data.
*/
{
}
/*
* Link it.
*/
{
break;
}
return RTEXITCODE_SUCCESS;
}
/**
* Checks that we found everything.
*
* @returns Fully complained exit code.
*/
static RTEXITCODE checkThatWeFoundEverything(void)
{
{
while (j-- > 0)
{
rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, " Missing %s::%s\n", g_aStructs[i].pszName, paMembers[j].pszName);
}
}
return rcExit;
}
/**
* Matches the member against what we're looking for.
*
* @returns Number of hits.
* @param cWantedMembers The number members in paWantedMembers.
* @param paWantedMembers The members we're looking for.
* @param pszPrefix The member name prefix.
* @param pszMember The member name.
* @param offMember The member offset.
* @param cbMember The member size.
*/
{
while (iMember-- > 0)
{
{
cHits++;
}
{
while (*pszCur)
{
{
cHits++;
break;
}
}
}
}
return cHits;
}
/**
* Resets the writable structure members prior to processing a PDB.
*
* While processing the PDB, will fill in the sizes and offsets of what we find.
* Afterwards we'll use look for reset values to see that every structure and
* member was located successfully.
*/
static void resetMyStructs(void)
{
{
while (j-- > 0)
{
}
}
}
/**
* Find members in the specified structure type (@a idxType).
*
* @returns Fully bitched exit code.
* @param hFake Fake process handle.
* @param uModAddr The module address.
* @param idxType The type index of the structure which members we're
* going to process.
* @param cWantedMembers The number of wanted members.
* @param paWantedMembers The wanted members. This will be modified.
* @param offDisp Displacement when calculating member offsets.
* @param pszStructNm The top level structure name.
* @param pszPrefix The member name prefix.
* @param pszLogTag The log tag.
*/
{
return RTMsgErrorExit(RTEXITCODE_FAILURE, "%s: TI_GET_CHILDRENCOUNT failed on _KPRCB: %u\n", pszLogTag, GetLastError());
pChildren = (TI_FINDCHILDREN_PARAMS *)alloca(RT_OFFSETOF(TI_FINDCHILDREN_PARAMS, ChildId[cChildren]));
return RTMsgErrorExit(RTEXITCODE_FAILURE, "%s: TI_FINDCHILDREN failed on _KPRCB: %u\n", pszLogTag, GetLastError());
{
//MyDbgPrintf(" %s: child#%u: TypeIndex=%u\n", pszStructNm, i, pChildren->ChildId[i]);
uint32_t idxRefType = 0;
uint32_t cMemberChildren = 0;
)
{
char *pszMember;
if (RT_SUCCESS(rc))
{
/*
* Gather more info and do some debug printing. We'll use some
* of this info below when recursing into sub-structures
* and arrays.
*/
uint32_t uMembTag = 0; SymGetTypeInfo(hFake, uModAddr, pChildren->ChildId[i], TI_GET_SYMTAG, &uMembTag);
uint32_t idxArrayType = 0; SymGetTypeInfo(hFake, uModAddr, idxRefType, TI_GET_ARRAYINDEXTYPEID, &idxArrayType);
MyDbgPrintf(" %#06x LB %#06llx %c%c %2d %2d %2d %2d %2d %4d %s::%s%s\n",
/*
* Recurse into children.
*/
if (cMemberChildren > 0)
{
if (pszSubPrefix)
{
if (rcExit2 != RTEXITCODE_SUCCESS)
}
else
}
/*
* Recurse into arrays too.
*/
else if (cElements > 0 && idxArrayType > 0)
{
MyDbgPrintf("idxArrayType=%u idxElementRefType=%u cbElement=%u\n", idxArrayType, idxElementRefType, cbElement);
if (pszSubPrefix)
{
{
if (rcExit2 != RTEXITCODE_SUCCESS)
}
}
else
}
}
else
}
/* TI_GET_OFFSET fails on bitfields, so just ignore+skip those. */
rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "%s: SymGetTypeInfo(,,,%d,) failed on %s child#%u: %u\n",
} /* For each child. */
return rcExit;
}
/**
* Lookup up structures and members in the given module.
*
* @returns Fully bitched exit code.
* @param hFake Fake process handle.
* @param uModAddr The module address.
* @param pszLogTag The log tag.
*/
{
{
pSymInfo->MaxNameLen = 0;
return RTMsgErrorExit(RTEXITCODE_FAILURE, "%s: Failed to find _KPRCB: %u\n", pszLogTag, GetLastError());
if (rcExit != RTEXITCODE_SUCCESS)
return rcExit;
} /* for each struct we want */
return rcExit;
}
{
return false;
}
/**
* Use various hysterics to figure out the OS version details from the PDB path.
*
* This ASSUMES quite a bunch of things:
* -# Working on unpacked symbol packages. This does not work for
* -# The symbol package has been unpacked into a directory with the same
* name as the symbol package (sans suffixes).
*
* @returns Fully complained exit code.
* @param pszPdb The path to the PDB.
* @param pVerInfo Where to return the version info.
*/
{
else
/* testing only */
{
}
else
return RTEXITCODE_SUCCESS;
}
/**
* Process one PDB.
*
* @returns Fully bitched exit code.
* @param pszPdb The path to the PDB.
*/
{
/*
* We need the size later on, so get that now and present proper IPRT error
* info if the file is missing or inaccessible.
*/
if (RT_FAILURE(rc))
/*
* Figure the windows version details for the given PDB.
*/
if (rcExit != RTEXITCODE_SUCCESS)
return RTMsgErrorExit(RTEXITCODE_FAILURE, "Failed to figure the OS version info for '%s'.\n'", pszPdb);
/*
* Create a fake handle and open the PDB.
*/
if (uModAddr != 0)
{
char szLogTag[32];
/*
* Find the structures.
*/
if (rcExit == RTEXITCODE_SUCCESS)
if (rcExit == RTEXITCODE_SUCCESS)
{
/*
* Save the details for later when we produce the header.
*/
}
}
else
if (!SymCleanup(hFake))
return rcExit;
}
/** The size of the directory entry buffer we're using. */
/**
* Recursively processes relevant files in the specified directory.
*
* @returns Fully complained exit code.
* @param pszDir Pointer to the directory buffer.
* @param cchDir The length of pszDir in pszDir.
* @param pDirEntry Pointer to the directory buffer.
*/
{
/* Make sure we've got some room in the path, to save us extra work further down. */
/* Open directory. */
if (RT_FAILURE(rc))
/* Ensure we've got a trailing slash (there is space for it see above). */
{
}
/*
* Process the files and subdirs.
*/
for (;;)
{
/* Get the next directory. */
if (RT_FAILURE(rc))
break;
/* Skip the dot and dot-dot links. */
continue;
/* Check length. */
{
rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "Path too long: '%s' in '%.*s'\n", pDirEntry->szName, cchDir, pszDir);
break;
}
{
/* Is this a file which might interest us? */
{
RT_STR_TUPLE("ntoskrnl.dbg"),
RT_STR_TUPLE("ntoskrnl.pdb"),
RT_STR_TUPLE("ntkrnlmp.dbg"),
RT_STR_TUPLE("ntkrnlmp.pdb"),
};
int i = RT_ELEMENTS(s_aNames);
while (i-- > 0)
{
/*
* Found debug info file of interest, process it.
*/
if (rcExit2 != RTEXITCODE_SUCCESS)
break;
}
}
{
/*
* Recurse into the subdirectory.
* Note! When we get back pDirEntry will be invalid.
*/
if (rcExit2 != RTEXITCODE_SUCCESS)
}
}
if (rc != VERR_NO_MORE_FILES)
rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "RTDirReadEx failed: %Rrc\npszDir=%.*s", rc, cchDir, pszDir);
if (RT_FAILURE(rc))
rcExit = RTMsgErrorExit(RTEXITCODE_FAILURE, "RTDirClose failed: %Rrc\npszDir=%.*s", rc, cchDir, pszDir);
return rcExit;
}
/**
* Recursively processes relevant files in the specified directory.
*
* @returns Fully complained exit code.
* @param pszDir The directory to search.
*/
{
char szPath[RTPATH_MAX];
if (RT_FAILURE(rc))
union
{
} uBuf;
}
{
if (RT_FAILURE(rc))
return RTMsgInitFailure(rc);
/*
* Parse options.
*/
/*
* Do job.
*/
if (rcExit == RTEXITCODE_SUCCESS)
{
}
return rcExit;
}