Enable ildasm for *nix
authorKyungwoo Lee <kyulee@microsoft.com>
Tue, 1 Dec 2015 18:16:08 +0000 (10:16 -0800)
committerKyungwoo Lee <kyulee@microsoft.com>
Mon, 7 Dec 2015 14:54:12 +0000 (06:54 -0800)
This enables ildasm for cross-platforms.
Unlike Window (where initialization is done when DLL attach), CoreCLR is explciltly hosted/initialized to get the Metadata related APIs.
This also eliminates the need of setting dynamic library path.
Currently, ildasm binary is assumed to be located same as CoreCLR binary.
I added a simple CoreCLRLoader (not meant to run an assembly file) for just direct uses of APIs. Since I expect this library to be used for ilasm work.
Resource string is also handled using a static string table  based on my prior check-in.
Other changes are mostly mechanic with regard to wide constant string.

19 files changed:
CMakeLists.txt
src/coreclr/hosts/unixcoreruncommon/CMakeLists.txt
src/dlls/mscoree/mscorwks_unixexports.src
src/ildasm/CMakeLists.txt
src/ildasm/dasm.cpp
src/ildasm/dasm_formattype.cpp
src/ildasm/dis.cpp
src/ildasm/dis.h
src/ildasm/dman.cpp
src/ildasm/dres.cpp
src/ildasm/dynamicarray.h [moved from src/ildasm/DynamicArray.h with 100% similarity]
src/ildasm/exe/CMakeLists.txt
src/ildasm/unixcoreclrloader/CMakeLists.txt [new file with mode: 0644]
src/ildasm/unixcoreclrloader/coreclrloader.cpp [new file with mode: 0644]
src/ildasm/unixcoreclrloader/coreclrloader.h [new file with mode: 0644]
src/ildasm/windasm.cpp
src/tools/metainfo/mdinfo.cpp
src/tools/metainfo/mdinfo.h
src/tools/metainfo/mdobj.cpp

index d0720ba..38c1d0c 100644 (file)
@@ -297,6 +297,7 @@ if (CLR_CMAKE_PLATFORM_UNIX)
   add_subdirectory(src/coreclr/hosts/unixcoreruncommon)
   add_subdirectory(src/coreclr/hosts/unixcorerun)
   add_subdirectory(src/coreclr/hosts/unixcoreconsole)
+  add_subdirectory(src/ildasm/unixcoreclrloader)
 endif(CLR_CMAKE_PLATFORM_UNIX)
 
 if(CLR_CMAKE_PLATFORM_DARWIN)
index 0a50cd8..2b5831e 100644 (file)
@@ -5,4 +5,3 @@ add_library(unixcoreruncommon
     coreruncommon.cpp
 )
 
-target_link_libraries(unixcoreruncommon)
index b6ce2fd..8089dc5 100644 (file)
@@ -4,6 +4,12 @@ coreclr_execute_assembly
 coreclr_initialize
 coreclr_shutdown
 
+; il{d}asm
+MetaDataGetDispenser
+GetMetaDataInternalInterface
+GetMetaDataInternalInterfaceFromPublic
+GetMetaDataPublicInterfaceFromInternal
+
 ; Obsolete Unix hosting API, to be removed
 ExecuteAssembly
 
index 91ab76e..7c1019e 100644 (file)
@@ -1,4 +1,4 @@
+add_subdirectory(exe)
 if (WIN32)
-    add_subdirectory(exe)
-    add_subdirectory(rcdll)
+  add_subdirectory(rcdll)
 endif()
index fc8f27e..add414d 100644 (file)
 #include "clrinternal.h"
 #endif
 
+#ifdef FEATURE_PAL
+#include "coreclrloader.h"
+#include "resourcestring.h"
+#define NATIVE_STRING_RESOURCE_NAME dasm_rc
+DECLARE_NATIVE_STRING_RESOURCE_TABLE(NATIVE_STRING_RESOURCE_NAME);
+#endif
+
 struct MIDescriptor
 {
     mdToken tkClass;    // defining class token
@@ -129,6 +136,8 @@ BOOL                    g_fCustomInstructionEncodingSystem = FALSE;
 
 COR_FIELD_OFFSET        *g_rFieldOffset = NULL;
 ULONG                   g_cFieldsMax, g_cFieldOffsets;
+
+char*                   g_pszExeFile;
 char                    g_szInputFile[MAX_FILENAME_LENGTH]; // in UTF-8
 WCHAR                   g_wszFullInputFile[MAX_PATH + 1]; // in UTF-16
 char                    g_szOutputFile[MAX_FILENAME_LENGTH]; // in UTF-8
@@ -230,7 +239,7 @@ WCHAR* RstrW(unsigned id)
         case IDS_E_CANTACCESSW32RES:
         case IDS_E_CANTOPENW32RES:
         case IDS_ERRORREOPENINGFILE:
-            wcscpy_s(buffer,COUNTOF(buffer),L"// ");
+            wcscpy_s(buffer,COUNTOF(buffer),W("// "));
             buff +=3;
             cchBuff -= 3;
             break;
@@ -241,22 +250,26 @@ WCHAR* RstrW(unsigned id)
         case IDS_E_CODESIZE:
         case IDS_W_CREATEDMRES:
         case IDS_E_READINGMRES:
-            wcscpy_s(buffer,COUNTOF(buffer),L"%s// ");
+            wcscpy_s(buffer,COUNTOF(buffer),W("%s// "));
             buff +=5;
             cchBuff -= 5;
             break;
         case IDS_E_NORVA:
-            wcscpy_s(buffer,COUNTOF(buffer),L"/* ");
+            wcscpy_s(buffer,COUNTOF(buffer),W("/* "));
             buff += 3;
             cchBuff -= 3;
             break;
         default:
             break;
     }
+#ifdef FEATURE_PAL
+    LoadNativeStringResource(NATIVE_STRING_RESOURCE_TABLE(NATIVE_STRING_RESOURCE_NAME),id, buff, cchBuff, NULL);
+#else
     _ASSERTE(g_hResources != NULL);
     WszLoadString(g_hResources,id,buff,cchBuff);
+#endif
     if(id == IDS_E_NORVA)
-        wcscat_s(buff,cchBuff,L" */");
+        wcscat_s(buff,cchBuff,W(" */"));
     return buffer;
 }
 
@@ -312,9 +325,32 @@ extern CQuickBytes *        g_szBuf_ProperName;
 ICLRRuntimeHostInternal *g_pCLRRuntimeHostInternal = NULL;
 #endif
 
+#ifdef FEATURE_CORECLR
+#ifdef FEATURE_PAL
+CoreCLRLoader *g_loader;
+#endif
+MetaDataGetDispenserFunc metaDataGetDispenser;
+GetMetaDataInternalInterfaceFunc getMetaDataInternalInterface;
+GetMetaDataInternalInterfaceFromPublicFunc getMetaDataInternalInterfaceFromPublic;
+GetMetaDataPublicInterfaceFromInternalFunc getMetaDataPublicInterfaceFromInternal;
+#endif
+
 BOOL Init()
 {
-#ifndef FEATURE_CORECLR
+#ifdef FEATURE_CORECLR
+#ifdef FEATURE_PAL
+    g_loader = CoreCLRLoader::Create(g_pszExeFile);
+    metaDataGetDispenser = (MetaDataGetDispenserFunc)g_loader->LoadFunction("MetaDataGetDispenser");
+    getMetaDataInternalInterface = (GetMetaDataInternalInterfaceFunc)g_loader->LoadFunction("GetMetaDataInternalInterface");
+    getMetaDataInternalInterfaceFromPublic = (GetMetaDataInternalInterfaceFromPublicFunc)g_loader->LoadFunction("GetMetaDataInternalInterfaceFromPublic");
+    getMetaDataPublicInterfaceFromInternal = (GetMetaDataPublicInterfaceFromInternalFunc)g_loader->LoadFunction("GetMetaDataPublicInterfaceFromInternal");
+#else // FEATURE_PAL
+    metaDataGetDispenser = (MetaDataGetDispenserFunc)MetaDataGetDispenser;
+    getMetaDataInternalInterface = (GetMetaDataInternalInterfaceFunc)GetMetaDataInternalInterface;
+    getMetaDataInternalInterfaceFromPublic = (GetMetaDataInternalInterfaceFromPublicFunc)GetMetaDataInternalInterfaceFromPublic;
+    getMetaDataPublicInterfaceFromInternal = (GetMetaDataPublicInterfaceFromInternalFunc)GetMetaDataPublicInterfaceFromInternal;
+#endif // FEATURE_PAL
+#else // FEATURE_CORECLR
     if (FAILED(CoInitialize(NULL)))
     {
         return FALSE;
@@ -343,7 +379,7 @@ BOOL Init()
     {
         return FALSE;
     }
-#endif
+#endif // FEATURE_CORECLR
     
     g_szBuf_KEYWORD = new CQuickBytes();
     g_szBuf_COMMENT = new CQuickBytes();
@@ -502,7 +538,14 @@ void Uninit()
         SDELETE(g_szBuf_ProperName);
     }
     
-#ifndef FEATURE_CORECLR
+#ifdef FEATURE_CORECLR
+#ifdef FEATURE_PAL
+    if (g_loader != NULL)
+    {
+        g_loader->Finish();
+    }
+#endif
+#else
     if (g_pCLRRuntimeHostInternal != NULL)
     {
         g_pCLRRuntimeHostInternal->Release();
@@ -981,7 +1024,7 @@ void DumpMscorlib(void* GUICookie)
                                                             &md,         // [OUT] Assembly MetaData.
                                                             &dwFlags)))  // [OUT] Flags.
             {
-                if(wcscmp(wzName,L"mscorlib") == 0)
+                if(wcscmp(wzName,W("mscorlib")) == 0)
                 {
                     printLine(GUICookie,"");
                     sprintf_s(szString,SZSTRING_SIZE,"%s%s ",g_szAsmCodeIndent,KEYWORD(".mscorlib"));
@@ -1416,7 +1459,7 @@ mdToken ResolveTypeDefReflectionNotation(IMDInternalImport *pIMDI,
 }
 
 mdToken ResolveTypeRefReflectionNotation(IMDInternalImport *pIMDI,
-                                         __in __nullterminated char* szNamespace, 
+                                         __in __nullterminated const char* szNamespace, 
                                          __inout __nullterminated char* szName, 
                                          mdToken tkResScope)
 {
@@ -1443,9 +1486,11 @@ mdToken ResolveReflectionNotation(BYTE* dataPtr,
     mdToken ret = 0;
     if(str)
     {
-        char* szNamespace = "";
+        char  szNamespaceDefault[] = "";
+        char* szNamespace = szNamespaceDefault;
         char* szName = str;
         char* szAssembly = NULL;
+        char  szAssemblyMscorlib[] = "mscorlib";
         char* pch;
         memcpy(str,dataPtr,Lstr);
         str[Lstr] = 0;
@@ -1473,7 +1518,7 @@ mdToken ResolveReflectionNotation(BYTE* dataPtr,
                 ret = tk;
             else
                 // TypeDef not found, try TypeRef from mscorlib
-                szAssembly = "mscorlib";
+                szAssembly = szAssemblyMscorlib;
         }
         if(szAssembly != NULL)
         {
@@ -1648,7 +1693,7 @@ mdToken TypeRefToTypeDef(mdToken tk, IMDInternalImport *pIMDI, IMDInternalImport
             if(FAILED(pIAMDI[0]->QueryInterface(IID_IUnknown, (void**)&pUnk))) goto AssignAndReturn;
 
 #ifdef FEATURE_CORECLR
-            if (FAILED(GetMetaDataInternalInterfaceFromPublic(
+            if (FAILED(getMetaDataInternalInterfaceFromPublic(
                 pUnk,
                 IID_IMDInternalImport,
                 (LPVOID *)ppIMDInew)))
@@ -2220,7 +2265,7 @@ BOOL PrettyPrintCustomAttributeNVPairs(unsigned nPairs, BYTE* dataPtr, BYTE* dat
         }
         // type of the field/property
         PCCOR_SIGNATURE dataTypePtr = (PCCOR_SIGNATURE)dataPtr;
-        char* szAppend = "";
+        const char* szAppend = "";
         if(*dataPtr == ELEMENT_TYPE_SZARRAY) // Only SZARRAY modifier can occur in ser.type
         {
             szAppend = "[]";
@@ -2487,7 +2532,6 @@ void DumpCustomAttributeProps(mdToken tkCA, mdToken tkType, mdToken tkOwner, BYT
                     const char*     pszMemberName;
                     ULONG           cComSig;
 
-                    pszMemberName;
                     if (FAILED(g_pImport->GetNameAndSigOfMemberRef(
                         tkOwner, 
                         &typePtr, 
@@ -3284,7 +3328,8 @@ void PrettyPrintOverrideDecl(ULONG i, __inout __nullterminated char* szString, v
     const char *    pszMemberName;
     mdToken         tkDecl,tkDeclParent=0;
     char            szBadToken[256];
-    char*           pszTailSig = "";
+    char            pszTailSigDefault[] = "";
+    char*           pszTailSig = pszTailSigDefault;
     CQuickBytes     qbInstSig;
     char*           szptr = &szString[0];
     szptr+=sprintf_s(szptr,SZSTRING_SIZE,"%s%s ",g_szAsmCodeIndent,KEYWORD(".override"));
@@ -3699,7 +3744,7 @@ lDone: ;
             printError(GUICookie,ERRORMSG(szString));
             return FALSE;
         }
-        char* szt = "SIG:";
+        const char* szt = "SIG:";
         for(ULONG i=0; i<cComSig;)
         {
             szptr = &szString[0];
@@ -4303,7 +4348,8 @@ BOOL DumpProp(mdToken FuncToken, const char *pszClassName, DWORD dwClassAttrs, v
     if(IsPrRTSpecialName(dwAttrs))      szptr+=sprintf_s(szptr,SZSTRING_REMAINING_SIZE(szptr),KEYWORD("rtspecialname "));
 
     {
-        char *pch = "";
+        char pchDefault[] = "";
+        char *pch = pchDefault;
         if(DumpBody)
         {
             pch = szptr+1;
@@ -5795,7 +5841,7 @@ void WritePerfData(const char *KeyDesc, const char *KeyName, const char *UnitDes
 
     if (!g_PerfDataFilePtr)
     {
-        if((g_PerfDataFilePtr = WszCreateFile(L"c:\\temp\\perfdata.dat", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL) ) == INVALID_HANDLE_VALUE)
+        if((g_PerfDataFilePtr = WszCreateFile(W("c:\\temp\\perfdata.dat"), GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, 0, NULL) ) == INVALID_HANDLE_VALUE)
         {
          printLine(NULL,"PefTimer::LogStoppedTime(): Unable to open the FullPath file. No performance data will be generated");
          g_fDumpToPerfWriter = FALSE;
@@ -6767,7 +6813,7 @@ void DumpVtable(void* GUICookie)
     szptr = &szString[0];
     szptr += sprintf_s(szString,SZSTRING_SIZE,"%s%s 0x%04x", g_szAsmCodeIndent,KEYWORD(".subsystem"),j);
     {
-        char* psz[15] = {"// UNKNOWN",
+        const char* psz[15] = {"// UNKNOWN",
                          "// NATIVE",
                          "// WINDOWS_GUI",
                          "// WINDOWS_CUI",
@@ -6944,13 +6990,13 @@ HRESULT VEHandlerReporter( // Return status.
     if(szMsg)
     {
         size_t L = wcslen(szMsg)+256;
-        if(wzMsg = new (nothrow) WCHAR[L])
+        if((wzMsg = new (nothrow) WCHAR[L]) != NULL)
         {
             wcscpy_s(wzMsg,L,szMsg);
             // include token and offset from Context
-            if(Context.Token) swprintf_s(&wzMsg[wcslen(wzMsg)], L-wcslen(wzMsg), L" [token:0x%08X]",Context.Token);
-            if(Context.uOffset) swprintf_s(&wzMsg[wcslen(wzMsg)], L-wcslen(wzMsg), L" [at:0x%X]",Context.uOffset);
-            swprintf_s(&wzMsg[wcslen(wzMsg)], L-wcslen(wzMsg), L" [hr:0x%08X]\n",hrRpt);
+            if(Context.Token) swprintf_s(&wzMsg[wcslen(wzMsg)], L-wcslen(wzMsg), W(" [token:0x%08X]"),Context.Token);
+            if(Context.uOffset) swprintf_s(&wzMsg[wcslen(wzMsg)], L-wcslen(wzMsg), W(" [at:0x%X]"),Context.uOffset);
+            swprintf_s(&wzMsg[wcslen(wzMsg)], L-wcslen(wzMsg), W(" [hr:0x%08X]\n"),hrRpt);
             DumpMI(UnicodeToUtf(wzMsg));
             delete[] wzMsg;
         }
@@ -6964,11 +7010,11 @@ void DumpMetaInfo(__in __nullterminated const WCHAR* pwzFileName, __in_opt __nul
         
     DumpMI((char*)GUICookie); // initialize the print function for DumpMetaInfo
 
-    if(pch && (!_wcsicmp(pch+1,L"lib") || !_wcsicmp(pch+1,L"obj")))
+    if(pch && (!_wcsicmp(pch+1,W("lib")) || !_wcsicmp(pch+1,W("obj"))))
     {   // This works only when all the rest does not
         // Init and run.
 #ifdef FEATURE_CORECLR
-        if (MetaDataGetDispenser(CLSID_CorMetaDataDispenser,
+        if (metaDataGetDispenser(CLSID_CorMetaDataDispenser,
             IID_IMetaDataDispenserEx, (void **)&g_pDisp))
 #else
         if(SUCCEEDED(CoInitialize(0)))
@@ -7006,7 +7052,7 @@ void DumpMetaInfo(__in __nullterminated const WCHAR* pwzFileName, __in_opt __nul
         if(g_pDisp == NULL)
         {
 #ifdef FEATURE_CORECLR
-            hr = MetaDataGetDispenser(CLSID_CorMetaDataDispenser,
+            hr = metaDataGetDispenser(CLSID_CorMetaDataDispenser,
                 IID_IMetaDataDispenserEx, (void **)&g_pDisp);
 #else
             hr = LegacyActivationShim::ClrCoCreateInstance(
@@ -7366,8 +7412,8 @@ void CloseNamespace(__inout __nullterminated char* szString)
 FILE* OpenOutput(__in __nullterminated const WCHAR* wzFileName)
 {
     FILE*   pfile = NULL;
-        if(g_uCodePage == 0xFFFFFFFF) _wfopen_s(&pfile,wzFileName,L"wb");
-        else _wfopen_s(&pfile,wzFileName,L"wt");
+        if(g_uCodePage == 0xFFFFFFFF) _wfopen_s(&pfile,wzFileName,W("wb"));
+        else _wfopen_s(&pfile,wzFileName,W("wt"));
 
     if(pfile)
     {
@@ -7396,6 +7442,7 @@ BOOL DumpFile()
     static char     szFilenameANSI[MAX_FILENAME_LENGTH*3];
     IMetaDataDispenser *pMetaDataDispenser = NULL;
     const char *pszFilename = g_szInputFile;
+    const DWORD openFlags = ofRead | (g_fProject ? 0 : ofNoTransform);
 
     if(!(g_Mode & MODE_GUI))
     {
@@ -7497,9 +7544,8 @@ BOOL DumpFile()
         g_cbMetaData = VAL32(g_CORHeader->MetaData.Size);
     }
 
-    const DWORD openFlags = ofRead | (g_fProject ? 0 : ofNoTransform);
 #ifdef FEATURE_CORECLR
-    if (FAILED(GetMetaDataInternalInterface(
+    if (FAILED(getMetaDataInternalInterface(
         (BYTE *)g_pMetaData,
         g_cbMetaData,
         openFlags,
@@ -7522,7 +7568,7 @@ BOOL DumpFile()
 
     TokenSigInit(g_pImport);
 #ifdef FEATURE_CORECLR
-    if (FAILED(MetaDataGetDispenser(CLSID_CorMetaDataDispenser, IID_IMetaDataDispenser, (LPVOID*)&pMetaDataDispenser)))
+    if (FAILED(metaDataGetDispenser(CLSID_CorMetaDataDispenser, IID_IMetaDataDispenser, (LPVOID*)&pMetaDataDispenser)))
 #else
     if (FAILED(CoCreateInstance(CLSID_CorMetaDataDispenser, 0, CLSCTX_INPROC_SERVER, IID_IMetaDataDispenser, (LPVOID*)&pMetaDataDispenser)))
 #endif
@@ -7863,6 +7909,7 @@ ReportAndExit:
             fSuccess = TRUE;
         }
         fSuccess = TRUE;
+#ifndef FEATURE_PAL
         if(g_pFile) // dump .RES file (if any), if not to console
         {
             WCHAR wzResFileName[2048], *pwc;
@@ -7888,6 +7935,7 @@ ReportAndExit:
                 else printError(g_pFile,szString);
             }
         }
+#endif
         if(g_fShowRefs) DumpRefs(TRUE);
         if(g_fDumpHTML)
         {
index b196483..263ae39 100644 (file)
@@ -132,8 +132,8 @@ const char* ERRORMSG(__in_opt __nullterminated const char* szOrig)
     }
     CONTRACTL_END;
     
-    char* szPrefix = "";
-    char* szPostfix = "";
+    const char* szPrefix = "";
+    const char* szPostfix = "";
     if(g_fDumpHTML)
     {
         szPrefix = "<I><B><FONT COLOR=RED>";
@@ -283,7 +283,7 @@ const char* ProperName(__in __nullterminated const char* name, bool isLocalName)
     _ASSERTE (buff);
     if(g_fUseProperName)
     {
-        char *ret;
+        const char *ret;
         BOOL fQuoted;
         if(name)
         {
index a548736..32e4b6f 100644 (file)
@@ -1760,7 +1760,7 @@ BOOL Disassemble(IMDInternalImport *pImport, BYTE *ILHeader, void *GUICookie, md
                 // Backwards compatible ldstr instruction.
                 if (instr == CEE_LDSTR && TypeFromToken(tk) != mdtString)
                 {
-                    WCHAR *v1 = L"";
+                    const WCHAR *v1 = W("");
 
                     if(g_fShowBytes)
                     {
@@ -2600,7 +2600,7 @@ static const char* keyword[] = {
 #undef KYWD
 };
 static bool KywdNotSorted = TRUE;
-static char* szAllowedSymbols = "#_@$.";
+static const char* szAllowedSymbols = "#_@$.";
 static char DisallowedStarting[256];
 static char DisallowedCont[256];
 
index 1f807af..00a689e 100644 (file)
@@ -152,3 +152,30 @@ char *DumpGenericPars(__inout_ecount(SZSTRING_SIZE) char* szString,
 #define CHECK_REMAINING_SIZE if(ovadd_le((size_t)szString, SZSTRING_SIZE_M4, (size_t)szptr)) break;
 #define SZSTRING_REMAINING_SIZE(x) (ovadd_le((size_t)szString,SZSTRING_SIZE,(size_t)(x))?0:(SZSTRING_SIZE-((size_t)(x)-(size_t)szString)))
 
+typedef int (*MetaDataGetDispenserFunc) (
+    REFCLSID    rclsid,                 // The class to desired.
+    REFIID      riid,                   // Interface wanted on class factory.
+    LPVOID FAR  *ppv);                  // Return interface pointer here.
+
+typedef int (*GetMetaDataInternalInterfaceFunc) (
+    LPVOID      pData,                  // [IN] in memory metadata section
+    ULONG       cbData,                 // [IN] size of the metadata section
+    DWORD       flags,                  // [IN] CorOpenFlags
+    REFIID      riid,                   // [IN] desired interface
+    void        **ppv);                 // [OUT] returned interface
+
+typedef int (*GetMetaDataInternalInterfaceFromPublicFunc) (
+    IUnknown    *pv,                    // [IN] Given interface
+    REFIID      riid,                   // [IN] desired interface
+    void        **ppv);                 // [OUT] returned interface
+
+typedef int (*GetMetaDataPublicInterfaceFromInternalFunc) (
+    void        *pv,                    // [IN] Given interface
+    REFIID      riid,                   // [IN] desired interface
+    void        **ppv);                 // [OUT] returned interface
+
+extern MetaDataGetDispenserFunc metaDataGetDispenser;
+extern GetMetaDataInternalInterfaceFunc getMetaDataInternalInterface;
+extern GetMetaDataInternalInterfaceFromPublicFunc getMetaDataInternalInterfaceFromPublic;
+extern GetMetaDataPublicInterfaceFromInternalFunc getMetaDataPublicInterfaceFromInternal;
+
index 962a3a7..10fd39a 100644 (file)
@@ -14,7 +14,6 @@
 #include "dasmgui.h"
 #include "formattype.h"
 #include "dis.h"
-#include "mlang.h"
 
 #include "ceeload.h"
 #include "dynamicarray.h"
 
 #include "clrinternal.h"
 
+#ifndef MAX_LOCALE_NAME
+#define MAX_LOCALE_NAME (32)
+#endif
+
 extern IMAGE_COR20_HEADER *    g_CORHeader;
 extern IMDInternalImport*      g_pImport;
 extern PELoader * g_pPELoader;
@@ -632,8 +635,8 @@ static BOOL ConvertToLegalFileNameInPlace(__inout LPWSTR wzName)
     // neutralize reserved names
     static const WCHAR * const rwzReserved[] =
     {
-        L"COM", L"LPT", // '1' - '9' must follow after these
-        L"CON", L"PRN", L"AUX", L"NUL"
+        W("COM"), W("LPT"), // '1' - '9' must follow after these
+        W("CON"), W("PRN"), W("AUX"), W("NUL")
     };
 
     for (size_t i = 0; i < (sizeof(rwzReserved) / sizeof(WCHAR *)); i++)
@@ -728,7 +731,7 @@ static void DumpResourceFile(void *GUICookie, BYTE *pRes, DWORD dwOffset, LPCWST
         if ((!(g_Mode & MODE_GUI)) && (g_pFile != NULL)) // embedded resource -- dump as .resources file
         {
             FILE *pF = NULL;
-            _wfopen_s(&pF, pParam->wzFileName, L"wb");
+            _wfopen_s(&pF, pParam->wzFileName, W("wb"));
             if (pF)
             {
                 struct Param
@@ -822,7 +825,7 @@ void DumpManifestResources(void* GUICookie)
             // add the Win32 resource file name to avoid conflict between the native and a managed resource file
             WCHAR *pwc = wcsrchr(wzName, L'.');
             if (pwc == NULL) pwc = &wzName[wcslen(wzName)];
-            wcscpy_s(pwc, 2048 - (pwc - wzFileName), L".res");
+            wcscpy_s(pwc, 2048 - (pwc - wzFileName), W(".res"));
 
             NAME_ARRAY_ADD(1, wzName);
 
@@ -879,7 +882,7 @@ void DumpManifestResources(void* GUICookie)
 
                         // if we have a conflict, add a number suffix to the file name
                         if (!fConflict ||
-                            swprintf_s(wpc, 2048 - (wpc - wzFileName), L"%d", iIndex) <= 0)
+                            swprintf_s(wpc, 2048 - (wpc - wzFileName), W("%d"), iIndex) <= 0)
                     {
                             // no conflict or unable to add index
                             break;
@@ -995,14 +998,14 @@ IMetaDataAssemblyImport* GetAssemblyImport(void* GUICookie)
             {
                 pbManifest += sizeof(DWORD);
 #ifdef FEATURE_CORECLR
-                if (SUCCEEDED(hr = GetMetaDataInternalInterface(
+                if (SUCCEEDED(hr = getMetaDataInternalInterface(
                     pbManifest,
                     VAL32(*pdwSize),
                     ofRead,
                     IID_IMDInternalImport,
                     (LPVOID *)&pParam->pImport)))
                 {
-                    if (FAILED(hr = GetMetaDataPublicInterfaceFromInternal(
+                    if (FAILED(hr = getMetaDataPublicInterfaceFromInternal(
                         pParam->pImport,
                         IID_IMetaDataAssemblyImport,
                         (LPVOID *)&pParam->pAssemblyImport)))
index d2c4191..a3d1fb6 100644 (file)
@@ -8,6 +8,7 @@
 //
 #include "ildasmpch.h"
 
+#ifndef FEATURE_PAL
 #include "debugmacros.h"
 #include "corpriv.h"
 #include "dasmenum.hpp"
@@ -313,3 +314,5 @@ DWORD   DumpResourceToFile(__in __nullterminated WCHAR*   wzFileName)
 
     return ret;
 }
+#endif // FEATURE_PAL
+
index 0e912c2..84c9d2a 100644 (file)
@@ -7,6 +7,17 @@ add_definitions(-D__ILDASM__)
 
 add_definitions(-DFEATURE_CORECLR)
 
+include_directories(..)
+
+if(CLR_CMAKE_PLATFORM_UNIX)
+    include_directories(../unixcoreclrloader)
+    build_resources(${CMAKE_CURRENT_SOURCE_DIR}/../dasm.rc dasm_rc TARGET_CPP_FILE)
+
+    set(ILDASM_RESOURCES
+        ${TARGET_CPP_FILE}
+    )
+endif(CLR_CMAKE_PLATFORM_UNIX)
+
 set(ILDASM_SOURCES
     ../ceeload.cpp
     ../dasm.cpp
@@ -31,23 +42,31 @@ set(ILDASM_LINK_LIBRARIES
     utilcodestaticnohost
     mdhotdata_full
     corguids
-    coreclr
 )
 
 if(CLR_CMAKE_PLATFORM_UNIX)
-    # TODO
     target_link_libraries(ildasm
+        ${ILDASM_LINK_LIBRARIES}
+        unixcoreclrloader
         mscorrc_debug
         coreclrpal
         palrt
     )
+
+    # FreeBSD implements dlopen in libc
+    if(NOT CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
+        target_link_libraries(ildasm
+            dl
+        )
+    endif(NOT CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
 else()
     target_link_libraries(ildasm
         ${ILDASM_LINK_LIBRARIES}
-         msvcrt
-         ole32
-         oleaut32
-         shell32
+        coreclr
+        msvcrt
+        ole32
+        oleaut32
+        shell32
     )
 
     # We will generate PDB only for the debug configuration
diff --git a/src/ildasm/unixcoreclrloader/CMakeLists.txt b/src/ildasm/unixcoreclrloader/CMakeLists.txt
new file mode 100644 (file)
index 0000000..6a3916b
--- /dev/null
@@ -0,0 +1,11 @@
+project(unixcoreclrloader)
+
+include_directories(${CMAKE_SOURCE_DIR}/src/coreclr/hosts/unixcoreruncommon)
+add_library(unixcoreclrloader
+    STATIC
+    coreclrloader.cpp
+)
+
+target_link_libraries(unixcoreclrloader
+    unixcoreruncommon
+)
diff --git a/src/ildasm/unixcoreclrloader/coreclrloader.cpp b/src/ildasm/unixcoreclrloader/coreclrloader.cpp
new file mode 100644 (file)
index 0000000..affa171
--- /dev/null
@@ -0,0 +1,73 @@
+
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+
+#include <stdio.h>
+#include "dlfcn.h"
+#include "coreclrloader.h"
+#include "coreruncommon.h"
+
+using namespace std;
+void *CoreCLRLoader::LoadFunction(const char *funcName)
+{
+    void *func = nullptr;
+    if (coreclrLib == nullptr) {
+        fprintf(stderr, "Error: coreclr should be loaded before loading a function: %s\n", funcName);
+    }
+    else {
+        func = dlsym(coreclrLib, funcName);
+        if (func == nullptr) {
+            fprintf(stderr, "Error: cannot find %s in coreclr\n", funcName);
+        }
+    }
+    return func;
+}
+
+CoreCLRLoader* CoreCLRLoader::Create(const char *exePath)
+{
+    string absolutePath, coreClrPath;
+    GetAbsolutePath(exePath, absolutePath);
+    GetDirectory(absolutePath.c_str(), coreClrPath);
+    coreClrPath.append("/");
+    coreClrPath.append(coreClrDll);
+
+    CoreCLRLoader *loader = new CoreCLRLoader();
+    loader->coreclrLib = dlopen(coreClrPath.c_str(), RTLD_NOW | RTLD_LOCAL);
+    if (loader->coreclrLib == nullptr)
+    {
+        fprintf(stderr, "Error: Fail to load %s\n", coreClrPath.c_str());
+        delete loader;
+        return nullptr;
+    }
+    else
+    {
+        loader->initializeCoreCLR = (InitializeCoreCLRFunction)loader->LoadFunction("coreclr_initialize");
+        loader->shutdownCoreCLR = (ShutdownCoreCLRFunction)loader->LoadFunction("coreclr_shutdown");
+        int ret = loader->initializeCoreCLR(
+                        exePath,
+                        "coreclrloader",
+                        0,
+                        0,
+                        0,
+                        &loader->hostHandle,
+                        &loader->domainId);
+        if (ret != 0)
+        {
+            fprintf(stderr, "Error: Fail to initialize CoreCLR\n");
+            delete loader;
+            return nullptr;
+        }
+    }
+    return loader;
+}
+
+int CoreCLRLoader::Finish()
+{
+  if (hostHandle != 0) {
+      shutdownCoreCLR(hostHandle, domainId);
+      delete this;
+  }
+  return 0;
+}
diff --git a/src/ildasm/unixcoreclrloader/coreclrloader.h b/src/ildasm/unixcoreclrloader/coreclrloader.h
new file mode 100644 (file)
index 0000000..0b1aa48
--- /dev/null
@@ -0,0 +1,32 @@
+
+// Copyright (c) Microsoft. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information.
+//
+
+typedef int (*InitializeCoreCLRFunction)(
+    const char* exePath,
+    const char* appDomainFriendlyName,
+    int propertyCount,
+    const char** propertyKeys,
+    const char** propertyValues,
+    void** hostHandle,
+    unsigned int* domainId);
+
+typedef int (*ShutdownCoreCLRFunction)(
+            void* hostHandle,
+            unsigned int domainId);
+
+class CoreCLRLoader
+{
+private:
+    InitializeCoreCLRFunction initializeCoreCLR;
+    ShutdownCoreCLRFunction shutdownCoreCLR;
+    void *coreclrLib;
+    void* hostHandle;
+    unsigned int domainId;
+public:
+    static CoreCLRLoader* Create(const char *coreClrPath);
+    void* LoadFunction(const char* functionName);
+    int Finish();
+};
+
index e5c7833..1316731 100644 (file)
@@ -61,6 +61,7 @@ extern char                    g_szAsmCodeIndent[];
 
 extern DWORD                   g_Mode;
 
+extern char*                    g_pszExeFile;
 extern char                     g_szInputFile[]; // in UTF-8
 extern WCHAR                    g_wszFullInputFile[]; // in UTF-16
 extern char                     g_szOutputFile[]; // in UTF-8
@@ -171,7 +172,11 @@ int ProcessOneArg(__in __nullterminated char* szArg, __out char** ppszObjFileNam
     if(strlen(szArg) == 0) return 0;
     if ((strcmp(szArg, "/?") == 0) || (strcmp(szArg, "-?") == 0)) return 1;
 
+#ifdef FEATURE_PAL
+    if(szArg[0] == '-')
+#else
     if((szArg[0] == '/') || (szArg[0] == '-'))
+#endif 
     {
         strncpy_s(szOpt,128, &szArg[1],10);
         szOpt[3] = 0;
@@ -485,13 +490,13 @@ char* ANSItoUTF8(__in __nullterminated char* szANSI)
 int ParseCmdLineW(__in __nullterminated WCHAR* wzCmdLine, __out char** ppszObjFileName)
 {
     int     argc,ret=0;
-    LPWSTR* argv= CommandLineToArgvW(wzCmdLine,&argc);
+    LPWSTR* argv= SegmentCommandLine(wzCmdLine, (DWORD*)&argc);
     char*   szArg = new char[2048];
     for(int i=1; i < argc; i++)
     {
         memset(szArg,0,2048);
         WszWideCharToMultiByte(CP_UTF8,0,argv[i],-1,szArg,2048,NULL,NULL);
-        if(ret = ProcessOneArg(szArg,ppszObjFileName)) break;
+        if((ret = ProcessOneArg(szArg,ppszObjFileName)) != 0) break;
     }
     VDELETE(szArg);
     return ret;
@@ -529,7 +534,7 @@ int ParseCmdLineA(__in __nullterminated char* szCmdLine, __out char** ppszObjFil
 
     for(int i=1; i < argc; i++)
     {
-        if(ret = ProcessOneArg(argv[i],ppszObjFileName)) break;
+        if((ret = ProcessOneArg(argv[i],ppszObjFileName)) != 0) break;
     }
     VDELETE(szCmdLineUTF);
     return ret;
@@ -544,6 +549,15 @@ int APIENTRY WinMain(HINSTANCE hInstance,
                      int       nCmdShow)
 #endif
 {
+#if defined(FEATURE_CORECLR) && defined(FEATURE_PAL)
+    if (0 != PAL_Initialize(nCmdShow, lpCmdLine))
+    {
+        printError(g_pFile, "Error: Fail to PAL_Initialize\n");
+        exit(1);
+    }
+    g_pszExeFile = lpCmdLine[0];
+#endif
+
     // ildasm does not need to be SO-robust.
     SO_NOT_MAINLINE_FUNCTION;
 
@@ -581,8 +595,10 @@ int APIENTRY WinMain(HINSTANCE hInstance,
     hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
     hConsoleErr = GetStdHandle(STD_ERROR_HANDLE);
 
+#ifndef FEATURE_PAL
     // Dev11 #5320 - pull the localized resource loader up so if ParseCmdLineW need resources, they're already loaded
     g_hResources = LoadLocalizedResourceDLLForSDK(L"ildasmrc.dll");
+#endif
 
     iCommandLineParsed = ParseCmdLineW((wzCommandLine = GetCommandLineW()),&g_pszObjFileName);
 
index 334628b..d847abd 100644 (file)
@@ -45,7 +45,7 @@ extern DWORD g_ValModuleType;
 #include <ivehandler.h>
 
 // Tables for mapping element type to text
-char *g_szMapElementType[] = 
+const char *g_szMapElementType[] = 
 {
     "End",          // 0x0
     "Void",         // 0x1
@@ -83,7 +83,7 @@ char *g_szMapElementType[] =
     "INTERNAL",
 };
 
-char *g_szMapUndecorateType[] = 
+const char *g_szMapUndecorateType[] = 
 {
     "",                 // 0x0
     "void",
@@ -122,7 +122,7 @@ char *g_szMapUndecorateType[] =
 };
 
 // Provide enough entries for IMAGE_CEE_CS_CALLCONV_MASK (defined in CorHdr.h)
-char *g_strCalling[] = 
+const char *g_strCalling[] = 
 {   
     "[DEFAULT]",
     "[C]",
@@ -142,7 +142,7 @@ char *g_strCalling[] =
     "[INVALID]"
 };
 
-char *g_szNativeType[] =
+const char *g_szNativeType[] =
 {
     "NATIVE_TYPE_END(DEPRECATED!)",  //         = 0x0,    //DEPRECATED
     "NATIVE_TYPE_VOID(DEPRECATED!)",  //        = 0x1,    //DEPRECATED
@@ -215,7 +215,7 @@ void MDInfo::InitSigBuffer()
 
 // helper to append a string into the signature buffer. If size of signature buffer is not big enough,
 // we will grow it.
-HRESULT MDInfo::AddToSigBuffer(__in_z __in char *string)
+HRESULT MDInfo::AddToSigBuffer(__in_z __in const char *string)
 {
     HRESULT     hr;
     size_t LL = strlen((LPSTR)m_sigBuf.Ptr()) + strlen(string) + 1;
@@ -365,6 +365,8 @@ HRESULT DefaultReporter( // Return status.
     return S_OK;
 } // HRESULT DefaultReporter()
 
+
+#ifdef FEATURE_METADATA_VALIDATOR
 class MDVEHandlerClass : public IVEHandler
 {
 public: 
@@ -535,7 +537,7 @@ public:
         // If we failed to find the message anywhere, then issue a hard coded message.
         if (FAILED(hr))
         {
-            swprintf_s(rcMsg, NumItems(rcMsg), L"COM+ Runtime Internal error: 0x%08x", hrRpt);
+            swprintf_s(rcMsg, NumItems(rcMsg), W("COM+ Runtime Internal error: 0x%08x"), hrRpt);
             //DEBUG_STMT(DbgWriteEx(rcMsg));
         }
 
@@ -555,6 +557,7 @@ public:
     static HRESULT STDMETHODCALLTYPE CreateObject(REFIID id, void **object)
     { return E_NOTIMPL; }
 };
+#endif // FEATURE_METADATA_VALIDATOR
 
 #endif
 //=====================================================================================================================
@@ -597,6 +600,7 @@ void MDInfo::DisplayMD()
     if (m_DumpFilter & dumpUnsat)
         DisplayUnsatInfo();
     WriteLine("===========================================================");
+#ifdef FEATURE_METADATA_VALIDATOR
     if (m_DumpFilter & dumpValidate)
     {
         IMetaDataValidate *pValidate = 0;
@@ -672,10 +676,11 @@ ErrExit:
         if (szErrStr)
             Error(szErrStr, hr);
     }
+#endif // FEATURE_METADATA_VALIDATOR
     WriteLine("===========================================================");
 } // MDVEHandlerClass()
 
-int MDInfo::WriteLine(__in_z __in char *str)
+int MDInfo::WriteLine(__in_z __in const char *str)
 {
     ULONG32 count = (ULONG32) strlen(str);
 
@@ -684,7 +689,7 @@ int MDInfo::WriteLine(__in_z __in char *str)
     return count;
 } // int MDInfo::WriteLine()
 
-int MDInfo::Write(__in_z __in char *str)
+int MDInfo::Write(__in_z __in const char *str)
 {
     ULONG32 count = (ULONG32) strlen(str);
 
@@ -692,7 +697,7 @@ int MDInfo::Write(__in_z __in char *str)
     return count;
 } // int MDInfo::Write()
 
-int MDInfo::VWriteLine(__in_z __in char *str, ...)
+int MDInfo::VWriteLine(__in_z __in const char *str, ...)
 {
     va_list marker;
     int     count;
@@ -704,7 +709,7 @@ int MDInfo::VWriteLine(__in_z __in char *str, ...)
     return count;
 } // int MDInfo::VWriteLine()
 
-int MDInfo::VWrite(__in_z __in char *str, ...)
+int MDInfo::VWrite(__in_z __in const char *str, ...)
 {
     va_list marker;
     int     count;
@@ -715,7 +720,7 @@ int MDInfo::VWrite(__in_z __in char *str, ...)
     return count;
 } // int MDInfo::VWrite()
 
-int MDInfo::VWriteMarker(__in_z __in char *str, va_list marker)
+int MDInfo::VWriteMarker(__in_z __in const char *str, va_list marker)
 {
     HRESULT hr;
     int count = -1;
@@ -742,7 +747,7 @@ void MDInfo::Error(const char* szError, HRESULT hr)
 
         IErrorInfo  *pIErr = NULL;          // Error interface.
         BSTR        bstrDesc = NULL;        // Description text.
-
+#ifdef FEATURE_COMINTEROP
         // Try to get an error info object and display the message.
         if (GetErrorInfo(0, &pIErr) == S_OK &&
             pIErr->GetDescription(&bstrDesc) == S_OK)
@@ -750,7 +755,7 @@ void MDInfo::Error(const char* szError, HRESULT hr)
             printf("%ls ", bstrDesc);
             SysFreeString(bstrDesc);
         }
-
+#endif
         // Free the error interface.
         if (pIErr)
             pIErr->Release();
@@ -852,7 +857,7 @@ void MDInfo::DisplayRaw()
 
 // return the name of the type of token passed in
 
-char *MDInfo::TokenTypeName(mdToken inToken)
+const char *MDInfo::TokenTypeName(mdToken inToken)
 {
     switch(TypeFromToken(inToken))
     {
@@ -1203,8 +1208,10 @@ void MDInfo::DisplayMethodInfo(mdMethodDef inMethod, DWORD *pflags)
     if (!*sFlags)
         strcpy_s(sFlags, STRING_BUFFER_LEN, "[none]");
 
-    if (IsMdInstanceInitializerW(flags, memberName)) strcat_s(sFlags, STRING_BUFFER_LEN, "[.ctor] ");
-    if (IsMdClassConstructorW(flags, memberName)) strcat_s(sFlags,STRING_BUFFER_LEN, "[.cctor] ");
+    bool result = (((flags) & mdRTSpecialName) && !wcscmp((memberName), W(".ctor")));
+    if (result) strcat_s(sFlags, STRING_BUFFER_LEN, "[.ctor] ");
+    result = (((flags) & mdRTSpecialName) && !wcscmp((memberName), W(".cctor")));
+    if (result) strcat_s(sFlags,STRING_BUFFER_LEN, "[.cctor] ");
     // "Reserved" flags
     ISFLAG(Md, HasSecurity);
     ISFLAG(Md, RequireSecObject);
@@ -1254,10 +1261,11 @@ void MDInfo::DisplayFieldInfo(mdFieldDef inField, DWORD *pdwFlags)
     DWORD dwCPlusTypeFlag;
     void const *pValue;
     ULONG cbValue;
+#ifdef FEATURE_COMINTEROP
     VARIANT defaultValue;
 
-
     ::VariantInit(&defaultValue);
+#endif
     hr = m_pImport->GetFieldProps( inField, &memTypeDef, memberName, STRING_BUFFER_LEN,
                             &nameLen, &flags, &pbSigBlob, &ulSigBlob, &dwCPlusTypeFlag,
                             &pValue, &cbValue);
@@ -1266,7 +1274,9 @@ void MDInfo::DisplayFieldInfo(mdFieldDef inField, DWORD *pdwFlags)
     if (pdwFlags)
         *pdwFlags = flags;
 
+#ifdef FEATURE_COMINTEROP
     _FillVariant((BYTE)dwCPlusTypeFlag, pValue, cbValue, &defaultValue);
+#endif
 
     char sFlags[STRING_BUFFER_LEN];
 
@@ -1292,14 +1302,17 @@ void MDInfo::DisplayFieldInfo(mdFieldDef inField, DWORD *pdwFlags)
 
     VWriteLine("\t\tField Name: %ls (%8.8X)", memberName, inField);
     VWriteLine("\t\tFlags     : %s (%08x)", sFlags, flags);
+#ifdef FEATURE_COMINTEROP
     if (IsFdHasDefault(flags))
         VWriteLine("\tDefltValue: (%s) %ls", g_szMapElementType[dwCPlusTypeFlag], VariantAsString(&defaultValue));
+#endif
     if (!ulSigBlob) // Signature size should be non-zero for fields
         VWriteLine("\t\tERROR: no valid signature ");
     else
         DisplaySignature(pbSigBlob, ulSigBlob, "");
-
+#ifdef FEATURE_COMINTEROP
     ::VariantClear(&defaultValue);
+#endif
 } // void MDInfo::DisplayFieldInfo()
 
 // displays the RVA for the given global field.
@@ -1477,8 +1490,9 @@ void MDInfo::DisplayParamInfo(mdParamDef inParamDef)
     void const *pValue;
     ULONG cbValue;
 
-
+#ifdef FEATURE_COMINTEROP
     ::VariantInit(&defValue);
+#endif
     HRESULT hr = m_pImport->GetParamProps( inParamDef, &md, &num, paramName, NumItems(paramName),
                             &nameLen, &flags, &dwCPlusFlags, &pValue, &cbValue);
     if (FAILED(hr)) Error("GetParamProps failed.", hr);
@@ -1497,13 +1511,17 @@ void MDInfo::DisplayParamInfo(mdParamDef inParamDef)
         strcpy_s(sFlags,STRING_BUFFER_LEN, "[none]");
 
     VWrite("\t\t\t(%ld) ParamToken : (%08x) Name : %ls flags: %s (%08x)", num, inParamDef, paramName, sFlags, flags);
+#ifdef FEATURE_COMINTEROP
     if (IsPdHasDefault(flags))
         VWriteLine(" Default: (%s) %ls", g_szMapElementType[dwCPlusFlags], VariantAsString(&defValue));
     else
+#endif
         VWriteLine("");
     DisplayCustomAttributes(inParamDef, "\t\t\t");
 
+#ifdef FEATURE_COMINTEROP
     ::VariantClear(&defValue);
+#endif
 } // void MDInfo::DisplayParamInfo()
 
 
@@ -1617,7 +1635,7 @@ LPCWSTR MDInfo::TokenName(mdToken inToken, __out_ecount(bufLen) LPWSTR buffer, U
     LPCUTF8     pName;                  // Token name in UTF8.
 
     if (IsNilToken(inToken))
-        return L"";
+        return W("");
 
     m_pImport->GetNameFromToken(inToken, &pName);
 
@@ -1638,12 +1656,12 @@ LPCWSTR MDInfo::TypeDeforRefName(mdToken inToken, __out_ecount(bufLen) LPWSTR bu
         else if (TypeFromToken(inToken) == mdtTypeRef)
             return (TypeRefName((mdTypeRef) inToken, buffer, bufLen));
         else if (TypeFromToken(inToken) == mdtTypeSpec)
-            return L"[TypeSpec]";
+            return W("[TypeSpec]");
         else
-            return (L"[InvalidReference]");
+            return W("[InvalidReference]");
     }
     else
-        return (L"");
+        return W("");
 } // LPCWSTR MDInfo::TypeDeforRefName()
 
 LPCWSTR MDInfo::MemberDeforRefName(mdToken inToken, __out_ecount(bufLen) LPWSTR buffer, ULONG bufLen)
@@ -1655,10 +1673,10 @@ LPCWSTR MDInfo::MemberDeforRefName(mdToken inToken, __out_ecount(bufLen) LPWSTR
         else if (TypeFromToken(inToken) == mdtMemberRef)
             return (MemberRefName((mdMemberRef) inToken, buffer, bufLen));
         else
-            return (L"[InvalidReference]");
+            return W("[InvalidReference]");
     }
     else
-        return (L"");
+        return W("");
 } // LPCWSTR MDInfo::MemberDeforRefName()
 
 // prints out only the name of the given typedef
@@ -1679,7 +1697,7 @@ LPCWSTR MDInfo::TypeDefName(mdTypeDef inTypeDef, __out_ecount(bufLen) LPWSTR buf
         NULL);                  // [OUT] Put base class TypeDef/TypeRef here.
     if (FAILED(hr))
     {
-        swprintf_s(buffer, bufLen, L"[Invalid TypeDef]");
+        swprintf_s(buffer, bufLen, W("[Invalid TypeDef]"));
     }
 
     return buffer;
@@ -1751,7 +1769,7 @@ LPCWSTR MDInfo::TypeRefName(mdTypeRef tr, __out_ecount(bufLen) LPWSTR buffer, UL
         NULL);              // Put actual size of name here.
     if (FAILED(hr))
     {
-        swprintf_s(buffer, bufLen, L"[Invalid TypeRef]");
+        swprintf_s(buffer, bufLen, W("[Invalid TypeRef]"));
     }
 
     return (buffer);
@@ -1970,7 +1988,9 @@ void MDInfo::DisplayPropertyInfo(mdProperty inProp)
     mdTypeDef   typeDef;
     WCHAR       propName[STRING_BUFFER_LEN];
     DWORD       flags;
+#ifdef FEATURE_COMINTEROP
     VARIANT     defaultValue;
+#endif
     void const  *pValue;
     ULONG       cbValue;
     DWORD       dwCPlusTypeFlag;
@@ -1980,8 +2000,9 @@ void MDInfo::DisplayPropertyInfo(mdProperty inProp)
     ULONG       ulSigBlob;
 
 
+#ifdef FEATURE_COMINTEROP
     ::VariantInit(&defaultValue);
-
+#endif
     hr = m_pImport->GetPropertyProps(
         inProp,                 // [IN] property token
         &typeDef,               // [OUT] typedef containing the property declarion.
@@ -2028,8 +2049,10 @@ void MDInfo::DisplayPropertyInfo(mdProperty inProp)
 
     WCHAR szTempBuf[STRING_BUFFER_LEN];
 
+#ifdef FEATURE_COMINTEROP
     _FillVariant((BYTE)dwCPlusTypeFlag, pValue, cbValue, &defaultValue);
     VWriteLine("\t\tDefltValue: %ls",VariantAsString(&defaultValue));
+#endif
 
     VWriteLine("\t\tSetter    : (%08x) %ls",setter,MemberDeforRefName(setter, szTempBuf, NumItems(szTempBuf)));
     VWriteLine("\t\tGetter    : (%08x) %ls",getter,MemberDeforRefName(getter, szTempBuf, NumItems(szTempBuf))); 
@@ -2038,7 +2061,9 @@ void MDInfo::DisplayPropertyInfo(mdProperty inProp)
     VWriteLine("\t\t%ld Others",others);
     DisplayCustomAttributes(inProp, "\t\t");
 
+#ifdef FEATURE_COMINTEROP
     ::VariantClear(&defaultValue);
+#endif
 } // void MDInfo::DisplayPropertyInfo()
 
 // displays info for each property
@@ -2235,7 +2260,7 @@ void MDInfo::DisplayCustomAttributeInfo(mdCustomAttribute inValue, const char *p
         VWrite(" :: %S", qSigName.Ptr());
 
     // Keep track of coff overhead.
-        if (!wcscmp(L"__DecoratedName", rcName))
+        if (!wcscmp(W("__DecoratedName"), rcName))
         {
             bCoffSymbol = true;
             g_cbCoffNames += cbValue + 6;
@@ -2418,7 +2443,7 @@ void MDInfo::DisplayPermissionInfo(mdPermission inPermission, const char *preFix
     DWORD dwAction;
     const BYTE *pvPermission;
     ULONG cbPermission;
-    char *flagDesc = NULL;
+    const char *flagDesc = NULL;
     char newPreFix[STRING_BUFFER_LEN];
     HRESULT hr;
 
@@ -2468,13 +2493,14 @@ LPWSTR MDInfo::GUIDAsString(GUID inGuid, __out_ecount(bufLen) LPWSTR guidString,
     return guidString;
 } // LPWSTR MDInfo::GUIDAsString()
 
-LPWSTR MDInfo::VariantAsString(VARIANT *pVariant)
+#ifdef FEATURE_COMINTEROP
+LPCWSTR MDInfo::VariantAsString(VARIANT *pVariant)
 {
     HRESULT hr = S_OK;
     if (V_VT(pVariant) == VT_UNKNOWN)
     {
         _ASSERTE(V_UNKNOWN(pVariant) == NULL);
-        return (L"<NULL>");
+        return W("<NULL>");
     }
     else if (SUCCEEDED(hr = ::VariantChangeType(pVariant, pVariant, 0, VT_BSTR)))
         return V_BSTR(pVariant);
@@ -2496,9 +2522,10 @@ LPWSTR MDInfo::VariantAsString(VARIANT *pVariant)
         return V_BSTR(pVariant);
     }
     else
-        return (L"ERROR");
+        return W("ERROR");
     
 } // LPWSTR MDInfo::VariantAsString()
+#endif
 
 bool TrySigUncompress(PCCOR_SIGNATURE pData,              // [IN] compressed data 
                       ULONG       *pDataOut,              // [OUT] the expanded *pData
@@ -3196,7 +3223,7 @@ ErrExit:
 void MDInfo::DisplayCorNativeLink(COR_NATIVE_LINK *pCorNLnk, const char *preFix)
 {
     // Print the LinkType.
-    char *curField = "\tLink Type : ";
+    const char *curField = "\tLink Type : ";
     switch(pCorNLnk->m_linkType)
     {
     case nltNone:
@@ -3677,7 +3704,7 @@ void MDInfo::DisplayASSEMBLYMETADATA(ASSEMBLYMETADATA *pMetaData)
     VWriteLine("\tMinor Version: 0x%08x", pMetaData->usMinorVersion);
     VWriteLine("\tBuild Number: 0x%08x", pMetaData->usBuildNumber);
     VWriteLine("\tRevision Number: 0x%08x", pMetaData->usRevisionNumber);
-    VWriteLine("\tLocale: %ls", pMetaData->cbLocale ? pMetaData->szLocale : L"<null>");
+    VWriteLine("\tLocale: %ls", pMetaData->cbLocale ? pMetaData->szLocale : W("<null>"));
     for (i = 0; i < pMetaData->ulProcessor; i++)
         VWriteLine("\tProcessor #%ld: 0x%08x", i+1, pMetaData->rProcessor[i]);
     for (i = 0; i < pMetaData->ulOS; i++)
index 077a89d..ccf383b 100644 (file)
@@ -46,7 +46,9 @@ public:
 
     void DisplayMD(void);
 
-    LPWSTR VariantAsString(VARIANT *pVariant);
+#ifdef FEATURE_COMINTEROP
+    LPCWSTR VariantAsString(VARIANT *pVariant);
+#endif
 
     void DisplayVersionInfo(void);
 
@@ -98,7 +100,7 @@ public:
 
     LPWSTR GUIDAsString(GUID inGuid, __out_ecount(bufLen) LPWSTR guidString, ULONG bufLen);
 
-    char *TokenTypeName(mdToken inToken);
+    const char *TokenTypeName(mdToken inToken);
 
     void DisplayMemberInfo(mdToken inMember);
     void DisplayMethodInfo(mdMethodDef method, DWORD *pflags = 0);
@@ -171,15 +173,15 @@ private:
 
     int DumpHex(const char *szPrefix, const void *pvData, ULONG cbData, int bText=true, ULONG nLine=16);
 
-    int Write(__in_z __in char *str);
-    int WriteLine(__in_z __in char *str);
+    int Write(__in_z __in const char *str);
+    int WriteLine(__in_z __in const char *str);
 
-    int VWrite(__in_z __in char *str, ...);
-    int VWriteLine(__in_z __in char *str, ...);
-    int VWriteMarker(__in_z __in char *str, va_list marker);
+    int VWrite(__in_z __in const char *str, ...);
+    int VWriteLine(__in_z __in const char *str, ...);
+    int VWriteMarker(__in_z __in const char *str, va_list marker);
     
     void InitSigBuffer();
-    HRESULT AddToSigBuffer(__in_z __in char *string);
+    HRESULT AddToSigBuffer(__in_z __in const char *string);
 
     IMetaDataImport2 *m_pRegImport;
     IMetaDataImport2 *m_pImport;
index 956d4c6..040f73e 100644 (file)
 #endif
 
 #define OBJ_EXT         ".obj"
-#define OBJ_EXT_W       L".obj"
+#define OBJ_EXT_W       W(".obj")
 #define OBJ_EXT_LEN     4
 #define LIB_EXT         ".lib"
-#define LIB_EXT_W       L".lib"
+#define LIB_EXT_W       W(".lib")
 #define LIB_EXT_LEN     4
 
 extern IMetaDataDispenserEx *g_pDisp;
@@ -266,7 +266,7 @@ void DisplayFile(__in_z __in wchar_t* szFile, BOOL isFile, ULONG DumpFilter, __i
 
     if (isFile)
     {
-        wcscpy_s(szScope, 1024, L"file:");
+        wcscpy_s(szScope, 1024, W("file:"));
         wcscat_s(szScope, 1024, szFile);
     }
     else