Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
2.8 KiB

  1. #include "version.h"
  2. #include "acFileAttr.h"
  3. #include <ctype.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <imagehlp.h>
  7. // InitVersionStruct
  8. //
  9. // Reads the version information for the specified file
  10. BOOL
  11. InitVersionStruct(
  12. IN OUT PVERSION_STRUCT pVer)
  13. {
  14. DWORD dwNull = 0;
  15. //
  16. // Allocate enough memory for the version stamp
  17. //
  18. pVer->dwSize = GetFileVersionInfoSize(pVer->pszFile, &dwNull);
  19. if (pVer->dwSize == 0) {
  20. LogMsg("File %s does not have version info\n", pVer->pszFile);
  21. return FALSE;
  22. }
  23. pVer->VersionBuffer = (PBYTE)Alloc(pVer->dwSize);
  24. if (pVer->VersionBuffer == NULL) {
  25. LogMsg("InitVersionStruct: failed to allocate %d bytes\n", pVer->dwSize);
  26. return FALSE;
  27. }
  28. //
  29. // Now get the version info from the file
  30. //
  31. if (!GetFileVersionInfo(
  32. pVer->pszFile,
  33. 0,
  34. pVer->dwSize,
  35. pVer->VersionBuffer)) {
  36. LogMsg("GetFileVersionInfo failed with 0x%x for file %s\n",
  37. GetLastError(),
  38. pVer->pszFile);
  39. DeleteVersionStruct(pVer);
  40. return FALSE;
  41. }
  42. // Extract the fixed info
  43. VerQueryValue(
  44. pVer->VersionBuffer,
  45. "\\",
  46. (LPVOID*)&pVer->FixedInfo,
  47. &pVer->FixedInfoSize);
  48. return TRUE;
  49. }
  50. // DeleteVersionStruct
  51. //
  52. // Delete all the memory allocated for this version structure
  53. VOID
  54. DeleteVersionStruct(
  55. IN PVERSION_STRUCT pVer)
  56. {
  57. if (pVer != NULL && pVer->VersionBuffer != NULL) {
  58. Free(pVer->VersionBuffer);
  59. pVer->VersionBuffer = NULL;
  60. ZeroMemory(pVer, sizeof(VERSION_STRUCT));
  61. }
  62. }
  63. static DWORD g_adwLangs[] = {0x000004B0, 0x000004E4, 0x040904B0, 0x040904E4, 0};
  64. #define MAX_VERSION_STRING 256
  65. // QueryVersionEntry
  66. //
  67. // Queries the file's version structure returning the
  68. // value for a specific entry
  69. PSTR
  70. QueryVersionEntry(
  71. IN OUT PVERSION_STRUCT pVer,
  72. IN PSTR pszField)
  73. {
  74. TCHAR szTemp[MAX_VERSION_STRING] = "";
  75. TCHAR* szReturn = NULL;
  76. int i;
  77. UINT unLen;
  78. for (i = 0; g_adwLangs[i]; ++i) {
  79. sprintf(szTemp, "\\StringFileInfo\\%08X\\%s", g_adwLangs[i], pszField);
  80. if (VerQueryValue(pVer->VersionBuffer, szTemp, (PVOID*)&szReturn, &unLen)) {
  81. char* pszValue;
  82. pszValue = Alloc(lstrlen(szReturn) + 1);
  83. if (pszValue == NULL) {
  84. LogMsg("QueryVersionEntry: failed to allocate %d bytes\n",
  85. lstrlen(szReturn) + 1);
  86. return NULL;
  87. }
  88. lstrcpy(pszValue, szReturn);
  89. return pszValue;
  90. }
  91. }
  92. return NULL;
  93. }