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.

148 lines
4.8 KiB

  1. #include <private.h>
  2. #include <VerifyFinalImage.h>
  3. #include <process.h>
  4. BOOL VerifyLc(PCHAR FileName,
  5. UCHAR* LcFullFileName, // added to move to seperate file
  6. PVLCA pVerifyFunction, // added to move to seperate file
  7. BOOL fRetail) {
  8. HRESULT hr = (*pVerifyFunction)(FileName, LcFullFileName);
  9. if (FAILED(hr)) {
  10. if (hr == HRESULT_FROM_WIN32(ERROR_NO_MATCH)) {
  11. fprintf(stderr,
  12. "BINPLACE : %s BNP0000: resource conflicts with localization constraint \"%s\"\n",
  13. fRetail ? "error" : "warning",
  14. FileName);
  15. }
  16. else {
  17. fprintf(stderr,
  18. "BINPLACE : %s BNP0000: VerifyLc %s failed 0x%lX\n",
  19. fRetail ? "error" : "warning", FileName, hr);
  20. }
  21. return FALSE;
  22. }
  23. return TRUE;
  24. }
  25. typedef DWORD (WINAPI *PFNGVS)(LPSTR, LPDWORD);
  26. BOOL VerifyFinalImage(IN PCHAR FileName,
  27. IN BOOL fRetail,
  28. IN BOOL fVerifyLc, // added to move to seperate file
  29. IN UCHAR* LcFileName, // added to move to seperate file
  30. IN PVLCA pVLCAFunction, // added to move to seperate file
  31. OUT PBOOL BinplaceLc) {
  32. HINSTANCE hVersion;
  33. PFNGVS pfnGetFileVersionInfoSize;
  34. DWORD dwSize;
  35. DWORD dwReturn;
  36. BOOL fRC = TRUE,
  37. rc = TRUE,
  38. tlb = FALSE;
  39. LOADED_IMAGE LoadedImage;
  40. OSVERSIONINFO VersionInfo;
  41. LoadedImage.hFile = INVALID_HANDLE_VALUE;
  42. *BinplaceLc = FALSE;
  43. if (fVerifyLc) {
  44. if (!VerifyLc(FileName, LcFileName, pVLCAFunction, fRetail)) {
  45. fRC = fRetail ? FALSE : TRUE;
  46. goto End1;
  47. }
  48. *BinplaceLc = TRUE;
  49. }
  50. VersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
  51. GetVersionEx ( &VersionInfo );
  52. if ( VersionInfo.dwPlatformId != VER_PLATFORM_WIN32_NT )
  53. return( TRUE ); // Not NT - can't load Win64 binaries
  54. if ( VersionInfo.dwMajorVersion < 5 )
  55. return ( TRUE ); // Prior to Win2K - can't load Win64 binaries
  56. rc = MapAndLoad(FileName, NULL, &LoadedImage, FALSE, TRUE);
  57. if (!rc) {
  58. // Not a binary. See if it's one of the other types we care about (like typelibs)
  59. CHAR szExt[_MAX_EXT];
  60. _splitpath(FileName, NULL, NULL, NULL, szExt);
  61. // The only non-binary images that need version resources are .tlb's
  62. if (_stricmp(szExt, ".tlb")) {
  63. return(TRUE);
  64. }
  65. tlb=TRUE;
  66. }
  67. hVersion = LoadLibraryA("VERSION.DLL");
  68. if (hVersion == NULL) {
  69. goto End1;
  70. }
  71. pfnGetFileVersionInfoSize = (PFNGVS) GetProcAddress(hVersion, "GetFileVersionInfoSizeA");
  72. if (pfnGetFileVersionInfoSize == NULL) {
  73. goto End2;
  74. }
  75. if ((dwReturn = pfnGetFileVersionInfoSize(FileName, &dwSize)) == 0) {
  76. if ( !tlb && (LoadedImage.FileHeader->FileHeader.Machine != IMAGE_FILE_MACHINE_I386) &&
  77. (LoadedImage.FileHeader->FileHeader.Machine != IMAGE_FILE_MACHINE_AMD64) &&
  78. (LoadedImage.FileHeader->FileHeader.Machine != IMAGE_FILE_MACHINE_IA64) ) {
  79. goto End2;
  80. }
  81. if (fRetail) {
  82. fprintf(stderr,
  83. "BINPLACE : %s BNP0000: no version resource detected for \"%s\"\n",
  84. "error",
  85. FileName);
  86. fRC = FALSE;
  87. } else {
  88. fRC = TRUE;
  89. }
  90. }
  91. End2:
  92. FreeLibrary(hVersion);
  93. End1:
  94. if (ImageCheck.Argv != NULL &&
  95. (LoadedImage.hFile != INVALID_HANDLE_VALUE ||
  96. MapAndLoad(FileName, NULL, &LoadedImage, FALSE, TRUE) == TRUE)) {
  97. if ((LoadedImage.FileHeader->FileHeader.Machine == ImageCheck.Machine)) {
  98. int RC;
  99. ImageCheck.Argv[ImageCheck.Argc-2] = FileName;
  100. RC = (int)_spawnvp(P_WAIT, ImageCheck.Argv[0], (const char * const *) ImageCheck.Argv);
  101. if (RC == -1 || RC == 128) {
  102. fprintf(stderr,
  103. "BINPLACE : error BNP0000: Cannot execute (%s). Make sure it (or it's DLL's) exists or verify binplace /CI option.\n", ImageCheck.Argv[0]);
  104. fRC = FALSE;
  105. } else if (RC == 1) {
  106. fprintf(stderr,
  107. "BINPLACE : error BNP0000: ImageCheck (%s) failed.\n", ImageCheck.Argv[0]);
  108. fRC = FALSE;
  109. } else if (RC == ImageCheck.RC) {
  110. fprintf(stderr,
  111. "BINPLACE : error BNP0000: Image checker (%s) detected errors in %s.\n", ImageCheck.Argv[0], FileName);
  112. fRC = FALSE;
  113. }
  114. }
  115. }
  116. if (LoadedImage.hFile != INVALID_HANDLE_VALUE)
  117. UnMapAndLoad(&LoadedImage);
  118. return fRC;
  119. }