home *** CD-ROM | disk | FTP | other *** search
- //*****************************************************************************
- // File: metainfo.cpp
- //
- // Copyright (c) 1997-2000 Microsoft Corporation. All Rights Reserved.
- // Microsoft Confidential.
- //*****************************************************************************
- #include <stdio.h>
- #include <ctype.h>
- #include <crtdbg.h>
- #include "mdinfo.h"
-
- #include "__file__.h"
- #include "corver.h"
-
- // Global variables
- bool g_bSchema = false;
- bool g_bRaw = false;
- bool g_bHeader = false;
-
- IMetaDataImport *g_pImport = NULL;
- IMetaDataDispenserEx *g_pDisp = NULL;
-
- void DisplayFile(char* szFile, BOOL isFile, ULONG DumpFilter, char* szObjFile, strPassBackFn pDisplayString);
- void DisplayArchive(char* szFile, ULONG DumpFilter, char* szObjName, strPassBackFn pDisplayString);
-
- void PrintLogo()
- {
- printf("Microsoft (R) NGWS Runtime Meta Data Dump Utility Version %s\n", VER_FILEVERSION_STR);
- printf(VER_LEGALCOPYRIGHT_DOS_STR);
- printf("\n");
- }// PrintLogo
-
- void Usage()
- {
- printf("\n");
- printf("metainfo [-? | -header | -schema | -raw] [-nologo] [-obj <obj file name>] [<filname> | <file pattern>]\n");
- printf(" -? Displays this text.\n");
- printf(" -hex Prints more things in hex as well as words.\n");
- printf(" -header Prints MetaData header information and sizes.\n");
- printf(" -csv Prints the header sizes in Comma Separated format.\n");
- printf(" -unsat Prints unresolved externals.\n");
- printf(" -schema Prints the MetaData schema information.\n");
- printf(" -raw Prints the raw MetaData tables.\n");
- printf(" -heaps Prints the raw heaps (only if -raw).\n");
- printf(" -nologo Do not display the logo and MVID.\n");
- printf(" -obj <objFileName>\n");
- printf(" Prints the MetaData for the specified obj file in the given \n");
- printf(" archive(.lib) - e.g metainfo libc.lib -obj wMSILWinCRTStartup.obj\n");
-
- MDInfo::Error("");
- }
-
- void DisplayString(char *str)
- {
- printf("%s", str);
- }
-
- int _cdecl main(int argc, char** argv)
- {
- char *pArg = NULL;
- char *szObjName = NULL;
- ULONG DumpFilter = MDInfo::dumpDefault;
- HRESULT hr = 0;
- BOOL fWantHelp=FALSE;
-
- // Validate incoming arguments
- for (int i=1; i<argc; i++)
- {
- const char *szArg = argv[i];
- if (*szArg == '-' || *szArg == '/')
- {
- if (lstrcmpi(szArg + 1, "?") == 0)
- fWantHelp=TRUE;
-
- else if (lstrcmpi(szArg + 1, "nologo") == 0)
- DumpFilter |= MDInfo::dumpNoLogo;
-
- else if (lstrcmpi(szArg + 1, "Hex") == 0)
- DumpFilter |= MDInfo::dumpMoreHex;
-
- else if (lstrcmpi(szArg + 1, "header") == 0)
- DumpFilter |= MDInfo::dumpHeader;
-
- else if (lstrcmpi(szArg + 1, "csv") == 0)
- DumpFilter |= MDInfo::dumpCSV;
-
- else if (lstrcmpi(szArg + 1, "raw") == 0)
- DumpFilter |= MDInfo::dumpRaw;
-
- else if (lstrcmpi(szArg + 1, "heaps") == 0)
- DumpFilter |= MDInfo::dumpRawHeaps;
-
- else if (lstrcmpi(szArg + 1, "schema") == 0)
- DumpFilter |= MDInfo::dumpSchema;
-
- else if (lstrcmpi(szArg + 1, "unsat") == 0)
- DumpFilter |= MDInfo::dumpUnsat;
-
- else if (lstrcmpi(szArg + 1, "stats") == 0)
- DumpFilter |= MDInfo::dumpStats;
-
- else if (lstrcmpi(szArg + 1, "obj") == 0)
- {
- if (++i == argc)
- Usage();
- else
- szObjName = argv[i];
- }
- }
- else
- pArg = argv[i];
- }
-
- // Print banner.
- if (!(DumpFilter & MDInfo::dumpNoLogo))
- PrintLogo();
-
-
- if (!pArg || fWantHelp)
- Usage();
-
-
- // Init and run.
- CoInitialize(0);
-
- hr = CoCreateInstance(CLSID_CorMetaDataDispenser, NULL, CLSCTX_INPROC_SERVER,
- IID_IMetaDataDispenserEx, (void **) &g_pDisp);
- if(FAILED(hr)) MDInfo::Error("Unable to CoCreate Meta-data Dispenser", hr);
-
- // Loop through all files in the file pattern passed
- WIN32_FIND_DATA fdFiles;
- HANDLE hFind;
- char szSpec[_MAX_PATH];
- char szDrive[_MAX_DRIVE];
- char szDir[_MAX_DIR];
-
- hFind = FindFirstFile(pArg, &fdFiles);
-
- if (hFind == INVALID_HANDLE_VALUE)
- {
- DisplayFile(pArg, false, DumpFilter, szObjName, DisplayString);
- }
- else
- {
- // Convert relative paths to full paths.
- _fullpath(szSpec, pArg, sizeof(szSpec));
- _splitpath(szSpec, szDrive, szDir, NULL, NULL);
- do
- {
- _makepath(szSpec, szDrive, szDir, fdFiles.cFileName, NULL);
- // display the meta data of the file
- DisplayFile(szSpec, true, DumpFilter, szObjName, DisplayString);
- } while (FindNextFile(hFind, &fdFiles)) ;
- FindClose(hFind);
- }
- g_pDisp->Release();
- CoUninitialize();
- return 0;
- }
-
-