int __cdecl main(int argc, char *argv[])
{
    HMODULE ModuleHandle;
    char ModuleName[64];
    WCHAR *wpModuleName = NULL;
    int err;

    /*Initialize the PAL environment*/
    err = PAL_Initialize(argc, argv);
    if(0 != err)
    {
        return FAIL;
    }

    /*zero the buffer*/
    memset(ModuleName,0,64);
    sprintf_s(ModuleName, _countof(ModuleName), "%s", "rotor_pal");

    /*convert a normal string to a wide one*/
    wpModuleName = convert(ModuleName);

    /*load a module*/
    ModuleHandle = PAL_RegisterLibrary(wpModuleName);

    /*free the memory*/
    free(wpModuleName);

    if(!ModuleHandle)
    {
        Fail("Failed to call PAL_RegisterLibrary API to map a module "
            "into calling process, error code=%u!\n", GetLastError());
    }

    /*decrement the reference count of the loaded DLL*/
    err = PAL_UnregisterLibrary(ModuleHandle);
    if(0 == err)
    {
        Fail("\nFailed to call PAL_UnregisterLibrary API to "
                "decrement the count of the loaded DLL module, "
                "error code=%u!\n", GetLastError());
    }

    PAL_Terminate();
    return PASS;
}
int __cdecl main(int argc, char *argv[])
{
    HMODULE ModuleHandle;
    char ModuleName[64];
    WCHAR *wpModuleName = NULL;
    int err;

    /*Initialize the PAL environment*/
    err = PAL_Initialize(argc, argv);
    if(0 != err)
    {
        return FAIL;
    }

    memset(ModuleName, 0, 64);
    sprintf(ModuleName, "%s", "not_exist_module_name");

    /*convert a normal string to a wide one*/
    wpModuleName = convert(ModuleName);

    /*load a not exist module*/
    ModuleHandle = PAL_RegisterLibrary(wpModuleName);

    /*free the memory*/
    free(wpModuleName);

    if(NULL != ModuleHandle)
    {
        Trace("ERROR: PAL_RegisterLibrary successfully mapped "
              "a module that does not exist into the calling process\n");

        /*decrement the reference count of the loaded DLL*/
        err = PAL_UnregisterLibrary(ModuleHandle);
        if(0 == err)
        {
            Trace("\nFailed to call PAL_UnregisterLibrary API to decrement the "
                "count of the loaded DLL module!\n");
        }
        Fail("");

    }

    PAL_Terminate();
    return PASS;
}
Ejemplo n.º 3
0
extern "C" int _cdecl wmain(int argc, WCHAR **argv)
{
    wchar_t *pArg = NULL;
    wchar_t *szObjName = NULL;
    ULONG DumpFilter = MDInfo::dumpDefault;
    HRESULT hr = 0;
    BOOL    fWantHelp=FALSE;
    
    if (!PAL_RegisterLibrary(L"rotor_palrt") ||
        !PAL_RegisterLibrary(L"sscoree"))
    {
        MDInfo::Error("Unable to register libraries", 1);
    }
    
    // Validate incoming arguments
    for (int i=1;  i<argc;  i++)
    {
        const wchar_t *szArg = argv[i];
        if (*szArg == L'-' || *szArg == L'/')
        {
            if (_wcsicmp(szArg + 1, L"?") == 0)
                fWantHelp=TRUE;

            else if (_wcsicmp(szArg + 1, L"nologo") == 0)
                DumpFilter |= MDInfo::dumpNoLogo;

            else if (_wcsicmp(szArg + 1, L"Hex") == 0)
                DumpFilter |= MDInfo::dumpMoreHex;

            else if (_wcsicmp(szArg + 1, L"header") == 0)
                DumpFilter |= MDInfo::dumpHeader;

            else if (_wcsicmp(szArg + 1, L"csv") == 0)
                DumpFilter |= MDInfo::dumpCSV;

            else if (_wcsicmp(szArg + 1, L"raw") == 0)
                DumpFilter |= MDInfo::dumpRaw;

            else if (_wcsicmp(szArg + 1, L"heaps") == 0)
                DumpFilter |= MDInfo::dumpRawHeaps;

            else if (_wcsicmp(szArg + 1, L"schema") == 0)
                DumpFilter |= MDInfo::dumpSchema;

            else if (_wcsicmp(szArg + 1, L"unsat") == 0)
                DumpFilter |= MDInfo::dumpUnsat;

            else if (_wcsicmp(szArg + 1, L"stats") == 0)
                DumpFilter |= MDInfo::dumpStats;

            else if (_wcsicmp(szArg + 1, L"assem") == 0)
                DumpFilter |= MDInfo::dumpAssem;

            else if (_wcsicmp(szArg + 1, L"validate") == 0)
                DumpFilter |= MDInfo::dumpValidate;

            else if (_wcsicmp(szArg + 1, L"obj") == 0)
            {
                if (++i == argc)
                    Usage();
                else
                    szObjName = argv[i];
            }
#if PLATFORM_UNIX
            else if (*szArg == L'/')
            {
                // Might be a fully qualifed path
                pArg = argv[i];
            }
#endif
        }
        else
            pArg = argv[i];
    }

    // Print banner.
    if (!(DumpFilter & MDInfo::dumpNoLogo))
        PrintLogo();


    if (!pArg || fWantHelp)
        Usage();

    
    CoInitializeCor(0);

    hr = PAL_CoCreateInstance(CLSID_CorMetaDataDispenser,
                  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;
    wchar_t szSpec[_MAX_PATH];
    wchar_t szDrive[_MAX_DRIVE];
    wchar_t szDir[_MAX_DIR];

    OnUnicodeSystem();

    hFind = WszFindFirstFile(pArg, &fdFiles);

    if (hFind == INVALID_HANDLE_VALUE)
    {
        DisplayFile(pArg, false, DumpFilter, szObjName, DisplayString);
    }
    else
    {
        // Convert relative paths to full paths.
        LPWSTR szFname;
        WszGetFullPathName(pArg, _MAX_PATH, szSpec, &szFname);
        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 (WszFindNextFile(hFind, &fdFiles)) ;
        FindClose(hFind);
    }
    g_pDisp->Release();
    CoUninitializeCor();
    return 0;
}