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.

314 lines
7.8 KiB

  1. /* DLLexist.exe July 1998
  2. DLLexist is a command line tool made for use with the IIS/Terrain Toolkit.
  3. It finds the directory where IIS is installed by checking the registry key
  4. of the IISADMIN Service.
  5. Then it dumps the Name, Size, Version Number, Manufacturer and Description
  6. of every DLL in the IIS directory.
  7. This information is output to standard out where it is meant to be
  8. piped to a file.
  9. */
  10. #include <windows.h> // for file calls
  11. #include <iostream.h>
  12. #include <string.h> // for strlen function and others
  13. #include <stdio.h> // for printf function and others
  14. #define IISADMINKEY "SYSTEM\\CurrentControlSet\\Services\\IISADMIN"
  15. #define IISADMINNAME "ImagePath"
  16. #define IISEXENAME "\\inetinfo.exe"
  17. // above are used to find the IIS install directory
  18. #define NOTAVAILABLE "NA" // when a version # or size is unavailable
  19. void GetFileVer( CHAR *szFileName, CHAR *szVersion, CHAR *szCompanyName, CHAR *szFileDescription );
  20. void GetFileSize( CHAR *szFileName, CHAR *szSize );
  21. BOOL getIISDir(char *, unsigned int);
  22. BOOL setCurrentDir(char *);
  23. void printCurrentDir(void);
  24. void printFileName(WIN32_FIND_DATA *);
  25. int __cdecl main(int argc, char** argv)
  26. {
  27. char buff[255];
  28. WIN32_FIND_DATA foundFileData;
  29. HANDLE searchHandle;
  30. // get the IIS install directory in buff
  31. if(!getIISDir(buff,256))
  32. return 1;
  33. // set cwd to the IIS install dir
  34. if(!setCurrentDir(buff))
  35. return 1;
  36. //Print the header information
  37. printf("%-12s %-15s %-10s %-30s %-30s","Filename","Version","FileSize","Company","Description");
  38. printf("\n");
  39. // Loop through all DLL's and dump their information
  40. searchHandle = FindFirstFile("*.dll",&foundFileData);
  41. if(searchHandle == INVALID_HANDLE_VALUE)
  42. return 1;
  43. printFileName(&foundFileData);
  44. while( (FindNextFile(searchHandle,&foundFileData)) != 0 )
  45. printFileName(&foundFileData);
  46. return 0;
  47. }
  48. // prints the cFileName member of a WIN32_FIND_DATA struct
  49. // THIS FUNCTION TRUSTS that d points to a VALID structure
  50. // on same line, the version number is also printed;
  51. void printFileName(WIN32_FIND_DATA *d)
  52. {
  53. char *version = new char[256];
  54. char *filesize = new char[256];
  55. char *company = new char[256];
  56. char *description = new char[256];
  57. GetFileVer(d->cFileName,version,company,description);
  58. GetFileSize(d->cFileName,filesize);
  59. printf("%-12s %-15s %-10s %-30s %-30s",d->cFileName,version,filesize,company,description);
  60. printf("\n");
  61. delete [] version;
  62. delete [] filesize;
  63. delete [] company;
  64. delete [] description;
  65. }
  66. // attempts to change current directory to directory specified in p
  67. // return true if successful, false otherwise
  68. BOOL setCurrentDir(char *p)
  69. {
  70. if( (SetCurrentDirectory(p))==0)
  71. return false;
  72. else
  73. return true;
  74. }
  75. // prints current working directory
  76. void printCurrentDir(void)
  77. {
  78. char buffer[255];
  79. if((GetCurrentDirectory(256,buffer)==0) )
  80. printf("Current Directory Failed\n");
  81. else
  82. printf("%s\n", buffer);
  83. return;
  84. }
  85. // getIISDir(...) returns the IIS directory.
  86. // It does a lookup in the registry for the IISADMIN service to get the IIS directory
  87. // c is buffer to put IIS path in
  88. // s is the size of c
  89. // depends on the HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\IISADMIN\ImagePath Key
  90. BOOL getIISDir(char *c, unsigned int s)
  91. {
  92. DWORD buffSize;
  93. unsigned char buffer[255];
  94. LONG retVal;
  95. HKEY iisKey;
  96. int stringSize;
  97. buffSize = 256;
  98. retVal = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  99. IISADMINKEY,
  100. 0,
  101. KEY_EXECUTE,
  102. &iisKey
  103. );
  104. if(retVal != ERROR_SUCCESS)
  105. return false;
  106. retVal = RegQueryValueEx( iisKey,
  107. IISADMINNAME,
  108. NULL,
  109. NULL,
  110. buffer,
  111. &buffSize
  112. );
  113. if(retVal != ERROR_SUCCESS)
  114. return false;
  115. stringSize = strlen((const char*)buffer);
  116. buffer[stringSize-strlen(IISEXENAME)] = 0;
  117. if( s< (strlen( (const char*)buffer)))
  118. return false;
  119. strcpy(c,(const char*)buffer);
  120. return true;
  121. }
  122. /*
  123. GetFileSize takes a filename in szFileName and returns the
  124. size of that file in bytes in szSize. If GetFileSize fails
  125. then NOTAVAILABLE is returned in szSize
  126. */
  127. void GetFileSize( CHAR *szFileName, CHAR *szSize )
  128. {
  129. HANDLE fileHandle;
  130. DWORD fileSize;
  131. fileHandle = CreateFile(szFileName,
  132. GENERIC_READ,
  133. FILE_SHARE_DELETE | FILE_SHARE_READ | FILE_SHARE_WRITE,
  134. NULL,
  135. OPEN_EXISTING,
  136. NULL,
  137. NULL);
  138. if(fileHandle == INVALID_HANDLE_VALUE)
  139. {
  140. strcpy(szSize,NOTAVAILABLE);
  141. return;
  142. }
  143. fileSize = GetFileSize( fileHandle,
  144. NULL
  145. );
  146. if(fileSize == 0xFFFFFFFF)
  147. {
  148. strcpy(szSize,NOTAVAILABLE);
  149. return;
  150. }
  151. wsprintf(szSize,"%d",fileSize);
  152. CloseHandle(fileHandle);
  153. }
  154. /*
  155. Get FileVer Info, grabbed from tonygod
  156. szFilename contains filename
  157. szVersion will contain versionInfo if successful
  158. NOTAVAILABLE otherwise
  159. szCompanyName will contain companyName if successful
  160. NOTAVAILABLE otherwise
  161. szFileDescription will contain fileDescription if successful
  162. NOTAVAILABLE otherwise
  163. */
  164. void GetFileVer( CHAR *szFileName, CHAR *szVersion, CHAR *szCompanyName, CHAR *szFileDescription)
  165. {
  166. BOOL bResult;
  167. DWORD dwHandle = 0;
  168. DWORD dwSize = 0;
  169. LPVOID lpvData;
  170. UINT uLen;
  171. VS_FIXEDFILEINFO *pvs;
  172. LPVOID buffer; // a void *
  173. dwSize = GetFileVersionInfoSize( szFileName, &dwHandle );
  174. if ( dwSize == 0 )
  175. {
  176. strcpy(szVersion,NOTAVAILABLE);
  177. strcpy(szCompanyName,NOTAVAILABLE);
  178. strcpy(szFileDescription,NOTAVAILABLE);
  179. return;
  180. }
  181. lpvData = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, dwSize );
  182. if ( lpvData == NULL )
  183. {
  184. strcpy(szVersion,NOTAVAILABLE);
  185. strcpy(szCompanyName,NOTAVAILABLE);
  186. strcpy(szFileDescription,NOTAVAILABLE);
  187. return;
  188. }
  189. bResult = GetFileVersionInfo(
  190. szFileName,
  191. dwHandle,
  192. dwSize,
  193. lpvData
  194. );
  195. if ( !bResult )
  196. {
  197. strcpy(szVersion,NOTAVAILABLE);
  198. strcpy(szCompanyName,NOTAVAILABLE);
  199. strcpy(szFileDescription,NOTAVAILABLE);
  200. return;
  201. }
  202. bResult = VerQueryValue( lpvData,
  203. "\\",
  204. (LPVOID *)&pvs,
  205. &uLen
  206. );
  207. if ( !bResult )
  208. strcpy(szVersion,NOTAVAILABLE);
  209. else
  210. wsprintf( szVersion, "%d.%d.%d.%d", HIWORD(pvs->dwFileVersionMS),
  211. LOWORD(pvs->dwFileVersionMS),
  212. HIWORD(pvs->dwFileVersionLS),
  213. LOWORD(pvs->dwFileVersionLS));
  214. /* the below query strings need to be fixed, should make a call to VerQueryValue with \VarInfo\Translation */
  215. /* right now it checks for unicode first and then it checks for Us English, this picks up all this works ... must
  216. fix later*/
  217. char szQueryStr[ 0x100 ];
  218. char szQueryStr2[0x100 ];
  219. // Format the strings with the 1200 codepage (Unicode)
  220. wsprintf(szQueryStr,"\\StringFileInfo\\%04X%04X\\%s",GetUserDefaultLangID(), 1200,"FileDescription" );
  221. wsprintf(szQueryStr2, "\\StringFileInfo\\%04X%04X\\%s", GetUserDefaultLangID(), 1200, "CompanyName" );
  222. bResult = VerQueryValue(lpvData,szQueryStr,&buffer,&uLen);
  223. if(uLen == 0)
  224. {
  225. VerQueryValue(lpvData,"\\StringFileInfo\\040904E4\\FileDescription",&buffer,&uLen);
  226. if(uLen == 0)
  227. strcpy(szFileDescription,NOTAVAILABLE);
  228. else
  229. strcpy(szFileDescription,(const char *)buffer);
  230. }
  231. else
  232. {
  233. strcpy(szFileDescription,(const char *)buffer);
  234. }
  235. bResult = VerQueryValue(lpvData,szQueryStr2,&buffer,&uLen);
  236. if(uLen == 0)
  237. {
  238. VerQueryValue(lpvData,"\\StringFileInfo\\040904E4\\CompanyName",&buffer,&uLen);
  239. if(uLen == 0)
  240. strcpy(szCompanyName,NOTAVAILABLE);
  241. else
  242. strcpy(szCompanyName,(const char *)buffer);
  243. }
  244. else
  245. {
  246. strcpy(szCompanyName,(const char *)buffer);
  247. }
  248. HeapFree( GetProcessHeap(), 0, lpvData );
  249. return;
  250. }