20#define sprintf_s(dst, size, format, ...) sprintf(dst, format, __VA_ARGS__)
21#define vsprintf_s(dst, size, format, ap) vsprintf(dst, format, ap)
22#define fopen_s(pfile, name, mode) ((*pfile = fopen(name, mode)), (*pfile != 0) ? 0 : -1)
23#define strcpy_s(dst, size, src) strncpy(dst, src, size)
24#define strcat_s(dst, size, src) strncat(dst, src, size)
28#pragma warning(disable:4091)
88#define MAX_PARAMETERS 64
113 _In_ const char* pszFormat,
125 cchBuffer = vsprintf_s(szBuffer,
sizeof(szBuffer), pszFormat, argptr);
144 " [error %lu: ", dwLastError);
177 static const char *pszMsSymbolServer =
"srv**symbols*http://msdl.microsoft.com/download/symbols";
186 error(
"SymInitialize() failed.");
193 Options &= ~SYMOPT_DEFERRED_LOADS;
199 error(
"Failed to connect to symbol server.");
230 pszFullModuleFileName,
234 if (dwModuleBase == 0)
244 printf(
"Successfully loaded symbols for '%s'\n",
245 pszFullModuleFileName);
271 strcat_s(szFullFileName,
sizeof(szFullFileName),
"\\");
272 strcat_s(szFullFileName,
sizeof(szFullFileName), pszModuleName);
280 strcpy_s(szFullFileName,
sizeof(szFullFileName),
"%systemroot%\\system32\\");
281 strcat_s(szFullFileName,
sizeof(szFullFileName), pszModuleName);
290 strcpy_s(szFullFileName,
sizeof(szFullFileName),
"%systemroot%\\SysWOW64\\");
291 strcat_s(szFullFileName,
sizeof(szFullFileName), pszModuleName);
309 ULONG i, cjExportSize, cFunctions, cjTableSize;
311 PULONG pulAddressTable, pulNameTable;
321 if (pExportDir ==
NULL)
330 pExportData =
malloc(cjTableSize);
331 if (pExportData ==
NULL)
333 error(
"Failed to allocate %u bytes of memory for export table\n", cjTableSize);
344 for (
i = 0;
i < cFunctions;
i++)
346 PVOID pvFunction = (pjImageBase + pulAddressTable[
i]);
365 ULONG iIndex = pusOrdinalTable[
i];
366 PSTR pszName = (
PSTR)(pjImageBase + pulNameTable[
i]);
371 *ppExportData = pExportData;
473 printf(
"Unhandled eSymTag: %u\n", eSymTag);
479 printf(
"Could not get type info. Fallig back to ptr\n");
502 error(
"Invalid name for forwarder '%s'!", pszForwarder);
513 error(
"Failed to load module for forwarder '%s'!", pszForwarder);
518 pszName = pchDot + 1;
519 if (pszName[0] ==
'#')
522 if ((iOrdinal == 0) || (iOrdinal > 0xFFFF))
524 error(
"Got invalid ordinal %u for ''", iOrdinal, pszForwarder);
533 if (ullFunction == 0)
555 for (
i = 0;
i < pExportData->cNumberOfExports;
i++)
557 PEXPORT pExport = &pExportData->aExports[
i];
558 ULONG64 ullFunction = dwModuleBase + pExportData->aExports[
i].
ulRva;
566 if (ullFunction == 0)
568 printf(
"Failed to get function for forwarder '%s'. Skipping.\n", pExport->
pszForwarder);
580 error(
"Error: SymFromAddr() failed.");
606 error(
"SymSetContext failed for i = %u.",
i);
617 error(
"SymEnumSymbols failed for i = %u.",
i);
644 switch (pExport->dwCallingConvention)
675 error(
"Failed to open spec file: '%s'\n", pszSpecFile);
680 for (
i = 0;
i < pExportData->cNumberOfExports;
i++)
682 pExport = &pExportData->aExports[
i];
742 printf(
"syntax: createspec <image file> [<spec file>]\n");
749 pszSpecFile =
argv[2];
758 strcpy_s(szSpecFile,
sizeof(szSpecFile), pszStart);
759 strcat_s(szSpecFile,
sizeof(szSpecFile),
".spec");
760 pszSpecFile = szSpecFile;
766 error(
"Failed to init dbghelp!\n"
767 "Make sure you have dbghelp.dll and symsrv.dll in the same folder.\n");
772 printf(
"Loading symbols for '%s', please wait...\n",
argv[1]);
776 error(
"Failed to load module '%s'!",
argv[1]);
784 error(
"Failed to get exports: %lx\n",
hr);
792 error(
"Failed to get symbol information: hr=%lx\n",
hr);
798 printf(
"Spec file '%s' was successfully written.\n", szSpecFile);
int strcmp(const char *String1, const char *String2)
UINT32 strtoul(const char *String, char **Terminator, UINT32 Base)
char * strchr(const char *String, int ch)
BOOL CALLBACK EnumParametersCallback(_In_ PSYMBOL_INFO pSymInfo, _In_ ULONG SymbolSize, _In_ PVOID UserContext)
struct _EXPORT_DATA * PEXPORT_DATA
enum _PARAM_TYPES * PPARAM_TYPES
const CHAR * GetCallingConvention(_In_ PEXPORT pExport)
HRESULT CreateSpecFile(_In_ PCSTR pszSpecFile, _In_ PEXPORT_DATA pExportData)
struct _EXPORT_DATA EXPORT_DATA
ULONG64 GetFunctionFromForwarder(_In_ PCSTR pszForwarder)
HRESULT ParseImageSymbols(_In_ HMODULE hmod, _Inout_ PEXPORT_DATA pExportData)
enum _PARAM_TYPES PARAM_TYPES
HMODULE LoadModuleWithSymbolsFullPath(_In_ PSTR pszFullModuleFileName)
HRESULT GetExportsFromFile(_In_ HMODULE hmod, _Out_ PEXPORT_DATA *ppExportData)
HMODULE LoadModuleWithSymbols(_In_ PSTR pszModuleName)
const char * gapszTypeStrings[]
#define SYMOPT_INCLUDE_32BIT_MODULES
static const WCHAR szDllName[]
BOOL WINAPI SymFromAddr(HANDLE hProcess, DWORD64 Address, DWORD64 *Displacement, PSYMBOL_INFO Symbol)
#define IMAGE_DIRECTORY_ENTRY_EXPORT
#define SYMFLAG_PARAMETER
BOOL WINAPI SymInitialize(HANDLE hProcess, PCSTR UserSearchPath, BOOL fInvadeProcess)
#define GetProcAddress(x, y)
#define GetCurrentProcess()
struct _SYMBOL_INFO SYMBOL_INFO
@ TI_GET_CALLING_CONVENTION
DWORD WINAPI SymSetOptions(DWORD opts)
BOOL WINAPI SymSetContext(HANDLE hProcess, PIMAGEHLP_STACK_FRAME StackFrame, PIMAGEHLP_CONTEXT Context)
BOOL WINAPI SymSetSearchPath(HANDLE hProcess, PCSTR searchPath)
DWORD WINAPI SymGetOptions(void)
DWORD64 WINAPI SymLoadModule64(HANDLE hProcess, HANDLE hFile, PCSTR ImageName, PCSTR ModuleName, DWORD64 BaseOfDll, DWORD SizeOfDll)
BOOL WINAPI SymGetTypeInfo(HANDLE hProcess, DWORD64 ModBase, ULONG TypeId, IMAGEHLP_SYMBOL_TYPE_INFO GetType, PVOID pInfo)
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryExA(LPCSTR lpLibFileName, HANDLE hFile, DWORD dwFlags)
DWORD WINAPI GetCurrentDirectoryA(IN DWORD nBufferLength, OUT LPSTR lpBuffer)
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_opt_ _CRTIMP int __cdecl fclose(_Inout_ FILE *_File)
void __cdecl __debugbreak(void)
#define strcpy_s(d, l, s)
static PEXPLICIT_ACCESSW *static HMODULE hmod
#define _Analysis_assume_(expr)
PVOID WINAPI ImageDirectoryEntryToData(PVOID base, BOOLEAN image, USHORT dir, PULONG size)
BOOL WINAPI SymSrvIsStore(HANDLE hProcess, PCSTR pszPath)
_Check_return_ _CRTIMP _CONST_RETURN char *__cdecl strrchr(_In_z_ const char *_Str, _In_ int _Ch)
int CDECL fopen_s(FILE **pFile, const char *filename, const char *mode)
int CDECL strcat_s(char *dst, size_t elem, const char *src)
DWORD dwCallingConvention
PARAM_TYPES aeParameters[MAX_PARAMETERS]
ULONG64 InstructionOffset
DWORD AddressOfNameOrdinals
BOOL WINAPI SymEnumSymbols(HANDLE hProcess, ULONG64 BaseOfDll, PCSTR Mask, PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback, PVOID UserContext)
#define SYMOPT_ALLOW_ABSOLUTE_SYMBOLS
#define FIELD_OFFSET(t, f)
#define RtlZeroMemory(Destination, Length)
_In_ PWDFDEVICE_INIT _In_ PWDF_REMOVE_LOCK_OPTIONS Options
DWORD WINAPI GetLastError(void)
#define LOAD_WITH_ALTERED_SEARCH_PATH
#define FORMAT_MESSAGE_FROM_SYSTEM
#define LOAD_IGNORE_CODE_AUTHZ_LEVEL
#define DONT_RESOLVE_DLL_REFERENCES