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.

322 lines
7.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: extag.c
  7. //
  8. // Contents:
  9. //
  10. // Classes:
  11. //
  12. // Functions:
  13. //
  14. // History: 6-17-96 RichardW Created
  15. //
  16. //----------------------------------------------------------------------------
  17. #define UNICODE
  18. #include <windows.h>
  19. #include <wchar.h>
  20. #include <stdio.h>
  21. WCHAR ExportTag[] = L"Export Version";
  22. WCHAR DomesticTag[] = L"US/Canada Only, Not for Export";
  23. WCHAR OldDomesticTag[] = L"Domestic Use Only";
  24. DWORD DefLang = 0x04b00409;
  25. #define BINARY_TYPE_UNKNOWN 0
  26. #define BINARY_TYPE_CONTROLLED 1
  27. #define BINARY_TYPE_OPEN 2
  28. #define BINARY_TYPE_CONTROLLED_OLD 3
  29. BOOL
  30. CheckIfControlled(
  31. LPWSTR Path,
  32. DWORD Flags)
  33. {
  34. PUCHAR pData;
  35. DWORD cbData;
  36. DWORD Zero;
  37. PWSTR Description;
  38. WCHAR ValueTag[64];
  39. PDWORD pdwTranslation;
  40. DWORD uLen;
  41. cbData = GetFileVersionInfoSize( Path, &Zero );
  42. if ( cbData == 0 )
  43. {
  44. return( BINARY_TYPE_UNKNOWN );
  45. }
  46. pData = LocalAlloc( LMEM_FIXED | LMEM_ZEROINIT, cbData );
  47. if ( !pData )
  48. {
  49. return( BINARY_TYPE_UNKNOWN );
  50. }
  51. if ( ! GetFileVersionInfo( Path, 0, cbData, pData ) )
  52. {
  53. LocalFree( pData );
  54. return( BINARY_TYPE_UNKNOWN );
  55. }
  56. if(!VerQueryValue(pData, L"\\VarFileInfo\\Translation", &pdwTranslation, &uLen))
  57. {
  58. pdwTranslation = &DefLang;
  59. uLen = sizeof(DWORD);
  60. }
  61. swprintf( ValueTag, L"\\StringFileInfo\\%04x%04x\\FileDescription",
  62. LOWORD( *pdwTranslation ), HIWORD( *pdwTranslation ) );
  63. // L"\\StringFileInfo\\040904b0\\FileDescription",
  64. if (VerQueryValue( pData,
  65. ValueTag,
  66. &Description,
  67. &cbData ) )
  68. {
  69. if (wcsstr( Description, DomesticTag ) )
  70. {
  71. LocalFree( pData );
  72. return( BINARY_TYPE_CONTROLLED );
  73. }
  74. if (wcsstr( Description, OldDomesticTag ) )
  75. {
  76. LocalFree( pData );
  77. return( BINARY_TYPE_CONTROLLED_OLD );
  78. }
  79. if ( wcsstr( Description, ExportTag ) )
  80. {
  81. LocalFree( pData );
  82. return( BINARY_TYPE_OPEN );
  83. }
  84. LocalFree( pData );
  85. return( BINARY_TYPE_UNKNOWN );
  86. }
  87. return( BINARY_TYPE_UNKNOWN );
  88. }
  89. VOID
  90. Usage( PWSTR Me )
  91. {
  92. printf("%ws: usage\n", Me);
  93. printf(" %ws file\tCheck file for export / domestic tags\n", Me);
  94. printf(" %ws dir\tCheck all files in directory\n", Me);
  95. }
  96. int
  97. __cdecl
  98. wmain(
  99. int argc,
  100. WCHAR * argv[] )
  101. {
  102. DWORD Result;
  103. PWSTR Path;
  104. WCHAR FullPath[ MAX_PATH ];
  105. WCHAR SearchPath[ MAX_PATH ];
  106. PWSTR FilePart;
  107. DWORD Attrs;
  108. WIN32_FIND_DATA Results;
  109. HANDLE SearchHandle;
  110. DWORD Error;
  111. DWORD FileCount;
  112. DWORD FileErrors;
  113. DWORD FileControlled;
  114. DWORD FileExport;
  115. DWORD FileUntagged;
  116. if ( argc < 2 )
  117. {
  118. Path = TEXT(".");
  119. }
  120. else
  121. {
  122. if ((wcscmp(argv[1], L"-?") == 0) ||
  123. (wcscmp(argv[1], L"/?") == 0) )
  124. {
  125. Usage( argv[0] );
  126. return( 0 );
  127. }
  128. Path = argv[1];
  129. }
  130. //
  131. // Expand it:
  132. if( GetFullPathName(Path,
  133. MAX_PATH,
  134. FullPath,
  135. &FilePart))
  136. {
  137. Path = FullPath;
  138. }
  139. Result = wcslen( Path );
  140. if ( Path[Result - 1] == '\\' )
  141. {
  142. Path[Result - 1] = '\0';
  143. }
  144. Attrs = GetFileAttributes( Path );
  145. if ( Attrs == (DWORD) -1 )
  146. {
  147. Attrs = 0;
  148. }
  149. if ( Attrs & FILE_ATTRIBUTE_DIRECTORY )
  150. {
  151. //
  152. // Yikes!
  153. //
  154. printf("Searching path %ws ...\n\n", Path );
  155. FileCount = 0;
  156. FileErrors = 0;
  157. FileControlled = 0;
  158. FileExport = 0;
  159. FileUntagged = 0;
  160. swprintf( SearchPath, TEXT("%s\\*.*"), Path );
  161. SearchHandle = FindFirstFile( SearchPath, &Results );
  162. if (SearchHandle == INVALID_HANDLE_VALUE)
  163. {
  164. return( 0 );
  165. }
  166. do
  167. {
  168. if ( Results.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
  169. {
  170. continue;
  171. }
  172. FileCount++;
  173. swprintf( SearchPath, TEXT("%s\\%s"), Path, Results.cFileName );
  174. Result = CheckIfControlled( SearchPath, 0 );
  175. switch ( Result )
  176. {
  177. case BINARY_TYPE_UNKNOWN :
  178. Error = GetLastError();
  179. if ( Error )
  180. {
  181. FileErrors++;
  182. if ((Error == ERROR_RESOURCE_DATA_NOT_FOUND) ||
  183. (Error == ERROR_RESOURCE_TYPE_NOT_FOUND) )
  184. {
  185. printf( "File %ws: expected resource data not found\n", SearchPath );
  186. }
  187. else
  188. {
  189. printf( "Error %d while accessing %ws\n", Error, SearchPath );
  190. }
  191. }
  192. else
  193. {
  194. FileUntagged++;
  195. }
  196. break;
  197. case BINARY_TYPE_CONTROLLED:
  198. printf("%ws is DOMESTIC USE ONLY\n", SearchPath );
  199. FileControlled++;
  200. break;
  201. case BINARY_TYPE_CONTROLLED_OLD:
  202. printf("%ws is DOMESTIC USE ONLY (Old Style Tag)\n", SearchPath );
  203. FileControlled++;
  204. break;
  205. case BINARY_TYPE_OPEN:
  206. FileExport++;
  207. printf("%ws tagged as okay for export\n", SearchPath );
  208. break;
  209. }
  210. } while ( FindNextFile( SearchHandle, &Results ) );
  211. FindClose( SearchHandle );
  212. //
  213. // Dump Stats:
  214. //
  215. printf("\n%d files scanned in directory %ws\n", FileCount, Path );
  216. printf(" %5d file(s) were tagged as export controlled\n", FileControlled );
  217. printf(" %5d file(s) were tagged as okay for export\n", FileExport);
  218. printf(" %5d file(s) were not tagged\n", FileUntagged );
  219. if ( FileErrors )
  220. {
  221. printf(" %5d files(s) could not be checked due to errors\n", FileErrors );
  222. }
  223. }
  224. else
  225. {
  226. Result = CheckIfControlled( Path, 0 ) ;
  227. switch ( Result )
  228. {
  229. case BINARY_TYPE_UNKNOWN :
  230. Error = GetLastError();
  231. if ( Error )
  232. {
  233. if ((Error == ERROR_RESOURCE_DATA_NOT_FOUND) ||
  234. (Error == ERROR_RESOURCE_TYPE_NOT_FOUND) )
  235. {
  236. printf( "File %ws: expected resource data not found\n", Path );
  237. }
  238. else
  239. {
  240. printf( "Error %d while accessing %ws\n", Error, Path );
  241. }
  242. }
  243. else
  244. {
  245. printf("Image untagged\n");
  246. }
  247. break;
  248. case BINARY_TYPE_CONTROLLED:
  249. printf("%ws is DOMESTIC USE ONLY\n", Path );
  250. break;
  251. case BINARY_TYPE_CONTROLLED_OLD:
  252. printf("%ws is DOMESTIC USE ONLY (Old Style Tag)\n", Path );
  253. break;
  254. case BINARY_TYPE_OPEN:
  255. printf("%ws is okay for export\n", Path );
  256. break;
  257. }
  258. }
  259. return( Result );
  260. }