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.

570 lines
16 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. infdump.c
  5. Abstract:
  6. Program to access/dump information contained in Layout INFs in a readable
  7. format. It also supports various forms of querying of the layout INF.
  8. Author:
  9. Vijesh Shetty (vijeshs)
  10. Revision History:
  11. --*/
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. #include <wild.c>
  15. #define DIRCODE TEXT("DirCode=")
  16. #define DIRNAME TEXT("DirName=")
  17. #define UPGATTR TEXT("UpgAttr=")
  18. #define CLNATTR TEXT("CleanAttr=")
  19. #define BOOTFIL TEXT("BootFile=")
  20. #define COMPRESS TEXT("Compress=")
  21. #define TARGNAME TEXT("TargetName=")
  22. #define SIZEEQV TEXT("SizeEQ")
  23. #define SIZEGRT TEXT("SizeGT")
  24. #define SIZELESS TEXT("SizeLT")
  25. #define DISPLAY TEXT("Display=")
  26. typedef enum _SCOPE{
  27. AllFiles, //This means that we do it for every file present
  28. FileSpec // This means we do this on every file that matches the filespec (with wildcard matching too)
  29. }SCOPE, *PSCOPE;
  30. typedef enum _QUERYTYPE{
  31. QUERYON_DIRCODE,
  32. QUERYON_DIRNAME,
  33. QUERYON_UPGRADEATTR,
  34. QUERYON_CLEANINSTALLATTR,
  35. QUERYON_BOOTFILE,
  36. QUERYON_COMPRESS,
  37. QUERYON_TARGETNAME,
  38. QUERYON_SIZEEQV,
  39. QUERYON_SIZEGRT,
  40. QUERYON_SIZELESS
  41. }QUERYTYPE, *PQUERYTYPE;
  42. typedef struct _QUERYPARAM{
  43. QUERYTYPE QueryType;
  44. BYTE Param[MAX_PATH];
  45. }QUERYPARAM, *PQUERYPARAM;
  46. typedef enum _DISPLAYOPTIONS{
  47. Default,
  48. TagInfo,
  49. FileOnly
  50. } DISPLAYOPTIONS, *PDISPLAYOPTIONS;
  51. typedef struct _QUERYSET{
  52. TCHAR LayoutFileName[MAX_PATH];
  53. TCHAR FileNameSpec[MAX_PATH];
  54. SCOPE Scope;
  55. int QueryClauses;
  56. QUERYPARAM QueryParam[20];
  57. DISPLAYOPTIONS DisplayOption;
  58. } QUERYSET, *PQUERYSET;
  59. QUERYSET GlobalQuerySet;
  60. void
  61. OutputFileInfo( PFILE_LAYOUTINFORMATION LayoutInformation,
  62. PCTSTR FileName,
  63. DISPLAYOPTIONS DispType,
  64. PMEDIA_INFO Media_Info );
  65. BOOL
  66. CALLBACK
  67. MyCallback(
  68. IN PLAYOUT_CONTEXT Context,
  69. IN PCTSTR FileName,
  70. IN PFILE_LAYOUTINFORMATION LayoutInformation,
  71. IN PVOID ExtraData,
  72. IN UINT ExtraDataSize,
  73. IN OUT DWORD_PTR Param
  74. )
  75. {
  76. PQUERYSET QuerySet;
  77. int i;
  78. BOOL Display=TRUE;
  79. if( GlobalQuerySet.Scope == FileSpec ){
  80. //Check if it matches wildcard..if not ignore this file
  81. if(!IsNameInExpressionPrivate(GlobalQuerySet.FileNameSpec, FileName))
  82. return( TRUE );
  83. }
  84. if( Param ){
  85. QuerySet = (PQUERYSET)Param;
  86. //Process each clause
  87. for( i=0; i<QuerySet->QueryClauses;i++){
  88. Display=FALSE;
  89. switch( QuerySet->QueryParam[i].QueryType ){
  90. case QUERYON_DIRCODE:
  91. if( LayoutInformation->Directory_Code == (_ttoi((PTCHAR)(QuerySet->QueryParam[i].Param))))
  92. Display = TRUE;
  93. case QUERYON_DIRNAME:
  94. if( !_tcsicmp( LayoutInformation->Directory,(PTCHAR)(QuerySet->QueryParam[i].Param)))
  95. Display = TRUE;
  96. break;
  97. case QUERYON_UPGRADEATTR:
  98. if( LayoutInformation->UpgradeDisposition == (_ttoi((PTCHAR)(QuerySet->QueryParam[i].Param))))
  99. Display = TRUE;
  100. break;
  101. case QUERYON_CLEANINSTALLATTR:
  102. if( LayoutInformation->CleanInstallDisposition == (_ttoi((PTCHAR)(QuerySet->QueryParam[i].Param))))
  103. Display = TRUE;
  104. break;
  105. case QUERYON_BOOTFILE:
  106. if( LayoutInformation->BootMediaNumber && (LayoutInformation->BootMediaNumber != -1)){
  107. if( !_tcsicmp((PTCHAR)(QuerySet->QueryParam[i].Param), TEXT("*")) )
  108. Display = TRUE;
  109. else if( LayoutInformation->BootMediaNumber == (_ttoi((PTCHAR)(QuerySet->QueryParam[i].Param))))
  110. Display = TRUE;
  111. }
  112. break;
  113. case QUERYON_COMPRESS:
  114. if( !_tcsicmp((PTCHAR)(QuerySet->QueryParam[i].Param), TEXT("YES")) ){
  115. if( LayoutInformation->Compression == TRUE )
  116. Display = TRUE;
  117. }else if( !_tcsicmp((PTCHAR)(QuerySet->QueryParam[i].Param), TEXT("NO")) ){
  118. if( LayoutInformation->Compression == FALSE )
  119. Display = TRUE;
  120. }
  121. break;
  122. case QUERYON_TARGETNAME:
  123. if( IsNameInExpressionPrivate( (PTCHAR)(QuerySet->QueryParam[i].Param), LayoutInformation->TargetFileName))
  124. Display = TRUE;
  125. break;
  126. //
  127. // Have to fix so that we don't overflow.
  128. //
  129. case QUERYON_SIZEEQV:
  130. if( LayoutInformation->Size == (ULONG)(_ttol((PTCHAR)(QuerySet->QueryParam[i].Param))))
  131. Display = TRUE;
  132. break;
  133. case QUERYON_SIZEGRT:
  134. if( LayoutInformation->Size > (ULONG)(_ttol((PTCHAR)(QuerySet->QueryParam[i].Param))))
  135. Display = TRUE;
  136. break;
  137. case QUERYON_SIZELESS:
  138. if( LayoutInformation->Size < (ULONG)(_ttol((PTCHAR)(QuerySet->QueryParam[i].Param))))
  139. Display = TRUE;
  140. break;
  141. default:
  142. Display = FALSE;
  143. break;
  144. }
  145. if( !Display )
  146. break;
  147. }
  148. if( Display == TRUE ){
  149. if( QuerySet->DisplayOption == TagInfo ){
  150. BOOL ret=FALSE;
  151. MEDIA_INFO MediaInfo;
  152. ret = FindFileInLayoutInf( Context,
  153. FileName,
  154. NULL,
  155. NULL,
  156. NULL,
  157. &MediaInfo);
  158. if (ret)
  159. OutputFileInfo( LayoutInformation, FileName, QuerySet->DisplayOption, &MediaInfo );
  160. }else
  161. OutputFileInfo( LayoutInformation, FileName, QuerySet->DisplayOption, NULL );
  162. }
  163. }
  164. return( TRUE );
  165. }
  166. void
  167. FindSingleFile( PLAYOUT_CONTEXT LayoutContext,
  168. PCTSTR FileName )
  169. {
  170. BOOL ret=FALSE;
  171. FILE_LAYOUTINFORMATION LayoutInformation;
  172. MEDIA_INFO MediaInfo;
  173. ret = FindFileInLayoutInf( LayoutContext,
  174. FileName,
  175. &LayoutInformation,
  176. NULL,
  177. NULL,
  178. &MediaInfo);
  179. if (ret)
  180. OutputFileInfo( &LayoutInformation, FileName, Default, &MediaInfo );
  181. else
  182. _ftprintf(stderr, TEXT("\nError: File Not Found\n"));
  183. return;
  184. }
  185. void
  186. OutputFileInfo( PFILE_LAYOUTINFORMATION LayoutInformation,
  187. PCTSTR FileName,
  188. DISPLAYOPTIONS DispType,
  189. PMEDIA_INFO Media_Info )
  190. {
  191. TCHAR Disposition[][50]={ TEXT("Always Copy"),
  192. TEXT("Copy if present"),
  193. TEXT("Copy if not present"),
  194. TEXT("Never copy - Copied via INF")
  195. };
  196. if( DispType == FileOnly )
  197. _tprintf(TEXT("%s\n"),FileName);
  198. else
  199. _tprintf(TEXT("Filename - %s\n"),FileName);
  200. if( DispType == FileOnly )
  201. return;
  202. _tprintf(TEXT("Dir Name - %s(%d)\n"), LayoutInformation->Directory, LayoutInformation->Directory_Code);
  203. _tprintf(TEXT("On Upgrade - %s(%d)\n"), Disposition[LayoutInformation->UpgradeDisposition], LayoutInformation->UpgradeDisposition);
  204. _tprintf(TEXT("On Clean Install - %s(%d)\n"), Disposition[LayoutInformation->CleanInstallDisposition], LayoutInformation->CleanInstallDisposition);
  205. _tprintf(TEXT("Media Tag ID - %s\n"),LayoutInformation->Media_tagID);
  206. if( *(LayoutInformation->TargetFileName))
  207. _tprintf(TEXT("Target Filename - %s\n"),LayoutInformation->TargetFileName);
  208. if( LayoutInformation->BootMediaNumber && (LayoutInformation->BootMediaNumber != -1))
  209. _tprintf(TEXT("Boot Media - %d\n"),LayoutInformation->BootMediaNumber);
  210. if( !LayoutInformation->Compression )
  211. _tprintf(TEXT("No Compression\n"));
  212. if( LayoutInformation->Size > 0 )
  213. _tprintf(TEXT("Uncompressed Size- %d\n"),LayoutInformation->Size);
  214. if( LayoutInformation->Count > 1 )
  215. _tprintf(TEXT("Occurrences - %d\n"),LayoutInformation->Count);
  216. if( Media_Info ){
  217. _tprintf(TEXT("Media Name - %s\n"),Media_Info->MediaName);
  218. _tprintf(TEXT("Media Tagfile - %s\n"),Media_Info->TagFilename);
  219. _tprintf(TEXT("Media Rootdir - %s\n"),Media_Info->RootDir);
  220. }
  221. if( DispType != FileOnly )
  222. _tprintf( TEXT("\n"));
  223. return;
  224. }
  225. BOOL
  226. ProcessCommandLine( int ArgCount, TCHAR *ArgArray[] )
  227. /*
  228. Function to process the command line and seperate out options into tokens
  229. */
  230. {
  231. int i, Next;
  232. LPTSTR Arg;
  233. TCHAR Temp[MAX_PATH];
  234. QUERYTYPE QType;
  235. ZeroMemory( &GlobalQuerySet, sizeof(QUERYSET));
  236. GlobalQuerySet.Scope = FileSpec;
  237. lstrcpy( GlobalQuerySet.FileNameSpec, TEXT("*") );
  238. GlobalQuerySet.DisplayOption = Default;
  239. lstrcpy( GlobalQuerySet.LayoutFileName, ArgArray[1] );
  240. Next = 0;
  241. for ( i=2;i < ArgCount;i++ ){ //Go through each directive
  242. Arg = ArgArray[i];
  243. if( Arg[0] != TEXT('/') )
  244. continue;
  245. switch( _toupper(Arg[1]) ){
  246. case TEXT('A'):
  247. GlobalQuerySet.Scope = AllFiles;
  248. break;
  249. case TEXT('S'): //Query Clause ?
  250. //_tprintf(TEXT("S -- %s"),Arg);
  251. if( Arg[2] != TEXT(':')) {
  252. return FALSE;
  253. }
  254. //Dir Code case
  255. if( ! _tcsnicmp( Arg+3, DIRCODE, lstrlen(DIRCODE))){
  256. lstrcpy( Temp, DIRCODE );
  257. QType = QUERYON_DIRCODE;
  258. }
  259. if( ! _tcsnicmp( Arg+3, DIRNAME, lstrlen(DIRNAME))){
  260. lstrcpy( Temp, DIRNAME );
  261. QType = QUERYON_DIRNAME;
  262. }
  263. if( ! _tcsnicmp( Arg+3, UPGATTR, lstrlen(UPGATTR))){
  264. lstrcpy( Temp, UPGATTR );
  265. QType = QUERYON_UPGRADEATTR;
  266. }
  267. if( ! _tcsnicmp( Arg+3, CLNATTR, lstrlen(CLNATTR))){
  268. lstrcpy( Temp, CLNATTR );
  269. QType = QUERYON_CLEANINSTALLATTR;
  270. }
  271. if( ! _tcsnicmp( Arg+3, BOOTFIL, lstrlen(BOOTFIL))){
  272. lstrcpy( Temp, BOOTFIL );
  273. QType = QUERYON_BOOTFILE;
  274. }
  275. if( ! _tcsnicmp( Arg+3, COMPRESS, lstrlen(COMPRESS))){
  276. lstrcpy( Temp, COMPRESS );
  277. QType = QUERYON_COMPRESS;
  278. }
  279. if( ! _tcsnicmp( Arg+3, TARGNAME, lstrlen(TARGNAME))){
  280. lstrcpy( Temp, TARGNAME );
  281. QType = QUERYON_TARGETNAME;
  282. }
  283. if( ! _tcsnicmp( Arg+3, DIRCODE, lstrlen(DIRCODE))){
  284. lstrcpy( Temp, DIRCODE );
  285. QType = QUERYON_DIRCODE;
  286. }
  287. if( ! _tcsnicmp( Arg+3, SIZEEQV, lstrlen(SIZEEQV))){
  288. lstrcpy( Temp, SIZEEQV );
  289. QType = QUERYON_SIZEEQV;
  290. }
  291. if( ! _tcsnicmp( Arg+3, SIZEGRT, lstrlen(SIZEGRT))){
  292. lstrcpy( Temp, SIZEGRT );
  293. QType = QUERYON_SIZEGRT;
  294. }
  295. if( ! _tcsnicmp( Arg+3, SIZELESS, lstrlen(SIZELESS))){
  296. lstrcpy( Temp, SIZELESS );
  297. QType = QUERYON_SIZELESS;
  298. }
  299. GlobalQuerySet.QueryParam[Next].QueryType = QType;
  300. GlobalQuerySet.QueryClauses++;
  301. if( *(Arg+3+lstrlen(Temp)) == TEXT('\0'))
  302. return FALSE;
  303. lstrcpy((LPTSTR)GlobalQuerySet.QueryParam[Next++].Param, Arg+3+lstrlen(Temp));
  304. break;
  305. case TEXT('D'):
  306. //_tprintf(TEXT("D -- %s"),Arg);
  307. if( Arg[2] != TEXT(':'))
  308. return FALSE;
  309. if( !_tcsicmp( Arg+3, TEXT("DEFAULT")))
  310. GlobalQuerySet.DisplayOption = Default;
  311. else if( !_tcsicmp( Arg+3, TEXT("ALL")))
  312. GlobalQuerySet.DisplayOption = TagInfo;
  313. else if( !_tcsicmp( Arg+3, TEXT("FILEONLY")))
  314. GlobalQuerySet.DisplayOption = FileOnly;
  315. break;
  316. default:
  317. break;
  318. }
  319. }// for
  320. if( (GlobalQuerySet.Scope == FileSpec) && (ArgArray[2][0] != TEXT('/'))){
  321. lstrcpy( GlobalQuerySet.FileNameSpec, ArgArray[2] );
  322. }
  323. return( TRUE );
  324. }
  325. _cdecl _tmain( int argc, TCHAR *argv[ ], char *envp[ ] )
  326. {
  327. PTSTR p;
  328. PWSTR InfName;
  329. PLAYOUT_CONTEXT LayoutContext;
  330. int StrLen;
  331. TCHAR LayoutFileName[MAX_PATH], FileName[MAX_PATH];
  332. LPWSTR *CmdlineV;
  333. int CmdlineC;
  334. BOOL ans = FALSE;
  335. int Result = 1;
  336. if(!pSetupInitializeUtils()) {
  337. _tprintf(TEXT("Initialize failure\n") );
  338. return 1;
  339. }
  340. //
  341. // Check Params.
  342. //
  343. if( argc < 3 ) {
  344. _tprintf(
  345. TEXT("Program to process layout inf file to gather information on file(s)\n\n")
  346. TEXT("Usage: %s <Inf Filename> [file specifier] [flags] [arguments] \n")
  347. TEXT("<Inf Filename> - Layout File to examine\n")
  348. TEXT("[file specifier] - File name to query (accepts wildcards) - default is *\n")
  349. TEXT("/a - Enumerates information for all files (overrides file specifier)\n\n" )
  350. TEXT("/s:<property>=<value> - Query based on a property\n" )
  351. TEXT(" There could be multiple /s options and they are \"anded\"\n")
  352. TEXT(" /s:dircode=<value> Looks for files that match the directory code specified\n")
  353. TEXT(" /s:dirname=<value> Looks for files that match the directory path specified\n")
  354. TEXT(" /s:upgattr=<attr> Looks for files that match the action attribute in the upgrade case\n")
  355. TEXT(" /s:cleanattr=<attr> Looks for files that match the action attribute in the clean install case\n")
  356. TEXT(" Valid <attr> values:\n")
  357. TEXT(" 0 - Always Copy\n")
  358. TEXT(" 1 - Copy if present\n")
  359. TEXT(" 2 - Copy if not present\n")
  360. TEXT(" 3 - Never copy - Copied via INF\n")
  361. TEXT(" /s:bootfile=<#> Looks for files that reside on bootdisk # - * for any bootdisk\n")
  362. TEXT(" /s:compress=<yes/no> Looks for files that match the compression flag. Default is Yes.\n")
  363. TEXT(" /s:targetname=<name> Looks for files are renamed to \"name\" on copy\n\n")
  364. TEXT(" /s:size{EQ/LT/GT}<value> Looks for files that satisfy the size condition specified (<= or >= not supported)\n")
  365. TEXT(" EQ# - Equal to (No Space around operator)\n")
  366. TEXT(" LT# - Lesser than (No Space around operator)\n")
  367. TEXT(" GT# - Greater than (No Space around operator)\n")
  368. TEXT("/d:<display type> - The display format for files that match\n" )
  369. TEXT(" /d:default - Display standard fields - no media tag info\n" )
  370. TEXT(" /d:fileonly - Display filename only\n" )
  371. TEXT(" /d:all - Display standard fields + media tag info\n" )
  372. TEXT("\n")
  373. , argv[0] );
  374. Result = 1;
  375. goto cleanup;
  376. }
  377. if( !ProcessCommandLine( argc, argv ) ) {
  378. Result = 0;
  379. goto cleanup;
  380. }
  381. _ftprintf( stderr, TEXT("\nParsing Layout file...wait...\n"));
  382. LayoutContext = BuildLayoutInfContext( GlobalQuerySet.LayoutFileName, LAYOUTPLATFORMS_ALL, 0);
  383. if( !LayoutContext ){
  384. _ftprintf(stderr,TEXT("\nError - Could not build Layout Inf context\n"));
  385. Result = -1;
  386. goto cleanup;
  387. }
  388. if( argc < 3 ){
  389. //DoMenu( LayoutContext );
  390. Result = 0;
  391. goto cleanup;
  392. }
  393. EnumerateLayoutInf( LayoutContext, MyCallback, (DWORD_PTR)&GlobalQuerySet );
  394. CloseLayoutInfContext( LayoutContext );
  395. Result = 0;
  396. cleanup:
  397. pSetupUninitializeUtils();
  398. return Result;
  399. }