Esempio n. 1
0
void VProcess::_ReadProductName( VString& outName) const
{
#if VERSIONWIN
#ifndef XTOOLBOX_AS_STANDALONE
	DWORD size = ::GetFileVersionInfoSizeW( GetExecutableFilePath().GetPath().GetCPointer(), NULL);
	void *buffer = malloc( size);
	if ( (buffer != NULL) && GetFileVersionInfoW( GetExecutableFilePath().GetPath().GetCPointer(), NULL, size, buffer))
	{
		void *valueAdress;
		UINT valueSize;
		if (::VerQueryValueW( buffer, L"\\StringFileInfo\\040904B0\\ProductName", &valueAdress, &valueSize))
		{
			outName.FromBlock( valueAdress, (valueSize - 1) * sizeof( UniChar), VTC_UTF_16);
		}
	}
	if (buffer != NULL)
		free( buffer);
#endif
#elif VERSIONMAC
	CFStringRef cfProductName = (CFStringRef) CFBundleGetValueForInfoDictionaryKey( CFBundleGetMainBundle(), kCFBundleNameKey);
	if (cfProductName != NULL)
		outName.MAC_FromCFString( cfProductName);

#elif VERSION_LINUX
    outName="Wakanda Server";	//Postponed Linux Implementation
#endif
}
Esempio n. 2
0
bool Module::getVers(const wchar_t* path)
{
    fileVer_ = 0;
    prodVer_ = 0;

    bool ok = false;
    DWORD h;
    DWORD size0 = GetFileVersionInfoSizeW(path, &h);
    if (size0 == 0)
    {
        return ok;
    }

    unsigned char* buf0 = new unsigned char[size0];
    int rc = GetFileVersionInfoW(path, h, size0, buf0);
    if (rc)
    {
        const VS_FIXEDFILEINFO* info;
        const wchar_t* subBlock = L"\\";
        void* buf1 = 0;
        unsigned int size1 = 0;
        rc = VerQueryValueW(buf0, subBlock, &buf1, &size1);
        if (rc && (size1 == sizeof(*info)))
        {
            info = static_cast<const VS_FIXEDFILEINFO*>(buf1);
            fileVer_ = static_cast<unsigned long long>(info->dwFileVersionMS) << 32 | info->dwFileVersionLS;
            prodVer_ = static_cast<unsigned long long>(info->dwProductVersionMS) << 32 | info->dwProductVersionLS;
            ok = true;
        }
    }

    delete[] buf0;
    return ok;
}
Esempio n. 3
0
static BOOL check_native_ie(void)
{
    static const WCHAR cszPath[] = {'b','r','o','w','s','e','u','i','.','d','l','l',0};
    DWORD handle,size;
    BOOL ret = TRUE;

    size = GetFileVersionInfoSizeW(cszPath,&handle);
    if (size)
    {
        LPVOID buf;
        LPWSTR lpFileDescription;
        UINT dwBytes;
        static const WCHAR cszFD[] = {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o','\\','0','4','0','9','0','4','e','4','\\','F','i','l','e','D','e','s','c','r','i','p','t','i','o','n',0};
        static const WCHAR cszWine[] = {'W','i','n','e',0};

        buf = HeapAlloc(GetProcessHeap(),0,size);
        GetFileVersionInfoW(cszPath,0,size,buf);

        if (VerQueryValueW(buf, cszFD, (LPVOID*)&lpFileDescription, &dwBytes) &&
            strstrW(lpFileDescription,cszWine))
                ret = FALSE;

        HeapFree(GetProcessHeap(), 0, buf);
    }

    return ret;
}
Esempio n. 4
0
DWORD getIMEVersion(HKL kbd_layout, wchar_t* filename) {
	DWORD version=0;
	switch ((DWORD)kbd_layout) {
		case _CHT_HKL_NEW_PHONETIC:
		case _CHT_HKL_NEW_CHANG_JIE:
		case _CHT_HKL_NEW_QUICK:
		case _CHT_HKL_HK_CANTONESE:
		case _CHS_HKL:
			break;
		default:
			// Do not know how to extract version number
			return 0;
	}
	DWORD ver_handle;
	DWORD buf_size = GetFileVersionInfoSizeW(filename, &ver_handle);
	if (!buf_size)  return 0;
	void* buf = malloc(buf_size);
    if (!buf)  return 0;
	if (GetFileVersionInfoW(filename, ver_handle, buf_size, buf)) {
		void* data = NULL;
		UINT  data_len;
		if (VerQueryValueW(buf, L"\\", &data, &data_len)) {
			VS_FIXEDFILEINFO FAR* info = (VS_FIXEDFILEINFO FAR*)data;
			version = (info->dwFileVersionMS & 0x00ff0000) << 8
					| (info->dwFileVersionMS & 0x000000ff) << 16
					| (DWORD)kbd_layout & 0xffff;
		}
	}
	free(buf);
	return version;
}
Esempio n. 5
0
		void FromFile(const std::basic_string<WCHAR>& pathW)
		{
			DWORD wtf;
			DWORD size;

			Translations.clear();

			size = GetFileVersionInfoSizeW(pathW.c_str(), &wtf);
			if(!size)
				return;

      data.resize(size);
			if(!GetFileVersionInfoW(pathW.c_str(), 0, size, data.data()))
				return;

			// fixed info (main shit)
			VS_FIXEDFILEINFO* ffi = 0;
			UINT ffilen = 0;
			if(!VerQueryValueW(data.data(), L"\\", (void**)&ffi, &ffilen))
				return;
			m_a = HIWORD(ffi->dwFileVersionMS);
			m_b = LOWORD(ffi->dwFileVersionMS);
			m_c = HIWORD(ffi->dwProductVersionLS);
			m_d = LOWORD(ffi->dwProductVersionLS);

			// Read the list of languages and code pages.
			LANGANDCODEPAGE* lpTranslate;
			VerQueryValueW(data.data(), L"\\VarFileInfo\\Translation", (LPVOID*)&lpTranslate, &ffilen);

			for(unsigned i = 0; i < (ffilen / sizeof(LANGANDCODEPAGE)); i++)
			{
				Translations.push_back(lpTranslate[i]);
			}
		}
static bool
IsH264DecoderBlacklisted()
{
#ifdef BLACKLIST_CRASHY_H264_DECODERS
  WCHAR systemPath[MAX_PATH + 1];
  if (!ConstructSystem32Path(L"msmpeg2vdec.dll", systemPath, MAX_PATH + 1)) {
    // Cannot build path -> Assume it's not the blacklisted DLL.
    return false;
  }

  DWORD zero;
  DWORD infoSize = GetFileVersionInfoSizeW(systemPath, &zero);
  if (infoSize == 0) {
    // Can't get file info -> Assume we don't have the blacklisted DLL.
    return false;
  }
  auto infoData = MakeUnique<unsigned char[]>(infoSize);
  VS_FIXEDFILEINFO *vInfo;
  UINT vInfoLen;
  if (GetFileVersionInfoW(systemPath, 0, infoSize, infoData.get()) &&
    VerQueryValueW(infoData.get(), L"\\", (LPVOID*)&vInfo, &vInfoLen))
  {
    if ((vInfo->dwFileVersionMS == ((12u << 16) | 0u))
        && ((vInfo->dwFileVersionLS == ((9200u << 16) | 16426u))
            || (vInfo->dwFileVersionLS == ((9200u << 16) | 17037u)))) {
      // 12.0.9200.16426 & .17037 are blacklisted on Win64, see bug 1242343.
      return true;
    }
  }
#endif // BLACKLIST_CRASHY_H264_DECODERS
  return false;
}
Esempio n. 7
0
File: main.c Progetto: GYGit/reactos
static BOOL check_native_ie(void)
{
    DWORD handle, size;
    LPWSTR file_desc;
    UINT bytes;
    void* buf;
    BOOL ret;

    static const WCHAR browseui_dllW[] = {'b','r','o','w','s','e','u','i','.','d','l','l',0};
    static const WCHAR wineW[] = {'W','i','n','e',0};
    static const WCHAR file_desc_strW[] =
        {'\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
#ifndef __REACTOS__
         '\\','0','4','0','9','0','4','e','4',
#else
         '\\','0','4','0','9','0','4','b','0',
#endif
         '\\','F','i','l','e','D','e','s','c','r','i','p','t','i','o','n',0};

    size = GetFileVersionInfoSizeW(browseui_dllW, &handle);
    if(!size)
        return TRUE;

    buf = HeapAlloc(GetProcessHeap(), 0, size);
    GetFileVersionInfoW(browseui_dllW, 0, size,buf);

    ret = !VerQueryValueW(buf, file_desc_strW, (void**)&file_desc, &bytes) || !strstrW(file_desc, wineW);

    HeapFree(GetProcessHeap(), 0, buf);
    return ret;
}
int MusicRegeditManager::getLocalIEVersion() const
{
#ifdef Q_OS_WIN
    DWORD versionInfoSize = GetFileVersionInfoSizeW(L"mshtml.dll", nullptr);
    if(versionInfoSize == 0)
    {
        return -1;
    }

    BYTE *pData = new BYTE[versionInfoSize];
    if(!GetFileVersionInfoW(L"mshtml.dll", 0, versionInfoSize, pData))
    {
        delete[] pData;
        return -1;
    }

    VS_FIXEDFILEINFO *fixedFileInfo = nullptr;
    UINT fixedFileInfoSize = 0;
    if(!VerQueryValueW(pData, L"\\", (LPVOID*)&fixedFileInfo, &fixedFileInfoSize))
    {
        delete[] pData;
        return -1;
    }

    delete[] pData;
    return HIWORD(fixedFileInfo->dwProductVersionMS);
#endif
    return -1;
}
Esempio n. 9
0
bool PluginPackage::fetchInfo()
{
    DWORD versionInfoSize, zeroHandle;
    versionInfoSize = GetFileVersionInfoSizeW(m_path.charactersWithNullTermination(), &zeroHandle); 
    if (versionInfoSize == 0)
        return false;

    OwnArrayPtr<char> versionInfoData(new char[versionInfoSize]);

    if (!GetFileVersionInfoW(m_path.charactersWithNullTermination(), 0, versionInfoSize, versionInfoData.get()))
        return false;

    m_name = getVersionInfo(versionInfoData.get(), "ProductName");
    m_description = getVersionInfo(versionInfoData.get(), "FileDescription");
    if (m_name.isNull() || m_description.isNull())
        return false;

    VS_FIXEDFILEINFO* info;
    UINT infoSize;
    if (!VerQueryValue(versionInfoData.get(), TEXT("\\"), (LPVOID*) &info, &infoSize) || infoSize < sizeof(VS_FIXEDFILEINFO))
        return false;
    m_moduleVersion.leastSig = info->dwFileVersionLS;
    m_moduleVersion.mostSig = info->dwFileVersionMS;

    if (isPluginBlacklisted())
        return false;

    Vector<String> types;
    getVersionInfo(versionInfoData.get(), "MIMEType").split('|', types);
    Vector<String> extensionLists;
    getVersionInfo(versionInfoData.get(), "FileExtents").split('|', extensionLists);
    Vector<String> descriptions;
    getVersionInfo(versionInfoData.get(), "FileOpenName").split('|', descriptions);

    for (unsigned i = 0; i < types.size(); i++) {
        String type = types[i].lower();
        String description = i < descriptions.size() ? descriptions[i] : "";
        String extensionList = i < extensionLists.size() ? extensionLists[i] : "";

        Vector<String> extensionsVector;
        extensionList.split(',', extensionsVector);

        // Get rid of the extension list that may be at the end of the description string.
        int pos = description.find("(*");
        if (pos != -1) {
            // There might be a space that we need to get rid of.
            if (pos > 1 && description[pos - 1] == ' ')
                pos--;
            description = description.left(pos);
        }

        // Determine the quirks for the MIME types this plug-in supports
        determineQuirks(type);

        m_mimeToExtensions.add(type, extensionsVector);
        m_mimeToDescriptions.add(type, description);
    }

    return true;
}
Esempio n. 10
0
/**
 * Obtains the version number from the specified PE file's version information
 * Version Format: A.B.C.D (Example 10.0.0.300)
 *  
 * @param  path The path of the file to check the version on
 * @param  A    The first part of the version number
 * @param  B    The second part of the version number
 * @param  C    The third part of the version number
 * @param  D    The fourth part of the version number
 * @return TRUE if successful
 */
static BOOL
GetVersionNumberFromPath(LPWSTR path, DWORD &A, DWORD &B, 
                         DWORD &C, DWORD &D) 
{
  DWORD fileVersionInfoSize = GetFileVersionInfoSizeW(path, 0);
  nsAutoArrayPtr<char> fileVersionInfo = new char[fileVersionInfoSize];
  if (!GetFileVersionInfoW(path, 0, fileVersionInfoSize,
                           fileVersionInfo.get())) {
      LOG(("Could not obtain file info of old service.  (%d)\n", 
           GetLastError()));
      return FALSE;
  }

  VS_FIXEDFILEINFO *fixedFileInfo = 
    reinterpret_cast<VS_FIXEDFILEINFO *>(fileVersionInfo.get());
  UINT size;
  if (!VerQueryValueW(fileVersionInfo.get(), L"\\", 
    reinterpret_cast<LPVOID*>(&fixedFileInfo), &size)) {
      LOG(("Could not query file version info of old service.  (%d)\n", 
           GetLastError()));
      return FALSE;
  }  

  A = HIWORD(fixedFileInfo->dwFileVersionMS);
  B = LOWORD(fixedFileInfo->dwFileVersionMS);
  C = HIWORD(fixedFileInfo->dwFileVersionLS);
  D = LOWORD(fixedFileInfo->dwFileVersionLS);
  return TRUE;
}
Esempio n. 11
0
void VProcess::_ReadProductVersion( VString& outVersion) const
{
#if VERSIONWIN
#ifndef XTOOLBOX_AS_STANDALONE
	DWORD size = ::GetFileVersionInfoSizeW( GetExecutableFilePath().GetPath().GetCPointer(), NULL);
	void *buffer = malloc( size);
	if ( (buffer != NULL) && GetFileVersionInfoW( GetExecutableFilePath().GetPath().GetCPointer(), NULL, size, buffer))
	{
		void *valueAdress;
		UINT valueSize;
		if (::VerQueryValueW( buffer, L"\\StringFileInfo\\040904B0\\ProductVersion", &valueAdress, &valueSize))
		{
			outVersion.FromBlock( valueAdress, (valueSize - 1) * sizeof( UniChar), VTC_UTF_16);
		}
	}
	if (buffer != NULL)
		free( buffer);
#endif
#elif VERSIONMAC
	// The constant for the "short version" property does not exist.
	CFStringRef cfProductVersion = (CFStringRef) CFBundleGetValueForInfoDictionaryKey( CFBundleGetMainBundle(), CFSTR ( "CFBundleShortVersionString" ) /*kCFBundleVersionKey*/);
	if (cfProductVersion != NULL)
	{
		outVersion.MAC_FromCFString( cfProductVersion);
	}

#elif VERSION_LINUX
    //jmo - We get the Linux product version with SetProductVersion() on VRIAServerApplication init
#endif
}
Esempio n. 12
0
BOOL GetVersionText(
	LPCWSTR /* IN */ szModulePath,
	LPCSTR /* IN */ szBlock,
	LPWSTR /* OUT */ szText, 
	DWORD /* IN  */ dwMaxTextLen
	)
{
	// Copying version information to buffer
	UINT iDataLength=GetFileVersionInfoSizeW(szModulePath,NULL);
	if (iDataLength<2)
		return FALSE;
	BYTE* pData=new BYTE[iDataLength+2];
	if (pData==NULL)
		return FALSE;

	if (!GetFileVersionInfoW(szModulePath,NULL,iDataLength,pData))
	{
		delete[] pData;
		return FALSE;
	}
	
	VOID* pTranslations,* pProductVersion=NULL;
	WCHAR szTranslation[200];
	
	
	// Checking first translation block
	if (!VerQueryValueW(pData,L"VarFileInfo\\Translation",&pTranslations,&iDataLength))
	{
		delete[] pData;
		return FALSE;
	}
	swprintf_s(szTranslation,200,L"\\StringFileInfo\\%04X%04X\\%S",LPWORD(pTranslations)[0],LPWORD(pTranslations)[1],szBlock);
	
	
	
	if (!VerQueryValueW(pData,szTranslation,&pProductVersion,&iDataLength))
	{
		// Checking english if nothing else does not found
		swprintf_s(szTranslation,200,L"\\StringFileInfo\\040904b0\\%S",szBlock);
		
		if (!VerQueryValueW(pData,szTranslation,&pProductVersion,&iDataLength))
		{
			delete[] pData;
			return FALSE;
		}
	}


	
	// Copying information from pProductVersion to szText
	wcscpy_s(szText,dwMaxTextLen,(LPCWSTR)pProductVersion);
	
	delete[] pData;
	return TRUE;
}
Esempio n. 13
0
/**************************************************************************
 * pSetupGetVersionInfoFromImage [SETUPAPI.@]
 *
 * Retrieves version information for a given file.
 *
 * PARAMS
 *     lpFileName       [I] File name
 *     lpFileVersion    [O] Pointer to the full file version
 *     lpVersionVarSize [O] Pointer to the size of the variable version
 *                          information
 *
 * RETURNS
 *     Success: TRUE
 *     Failure: FALSE
 */
BOOL WINAPI
pSetupGetVersionInfoFromImage(LPWSTR lpFileName,
                              PULARGE_INTEGER lpFileVersion,
                              LPWORD lpVersionVarSize)
{
    DWORD dwHandle;
    DWORD dwSize;
    LPVOID lpInfo;
    UINT uSize;
    VS_FIXEDFILEINFO *lpFixedInfo;
    LPWORD lpVarSize;

    dwSize = GetFileVersionInfoSizeW(lpFileName, &dwHandle);
    if (dwSize == 0)
        return FALSE;

    lpInfo = MyMalloc(dwSize);
    if (lpInfo == NULL)
        return FALSE;

    if (!GetFileVersionInfoW(lpFileName, 0, dwSize, lpInfo))
    {
        MyFree(lpInfo);
        return FALSE;
    }

    if (!VerQueryValueW(lpInfo, BackSlash,
                        (LPVOID*)&lpFixedInfo, &uSize))
    {
        MyFree(lpInfo);
        return FALSE;
    }

    lpFileVersion->LowPart = lpFixedInfo->dwFileVersionLS;
    lpFileVersion->HighPart = lpFixedInfo->dwFileVersionMS;

    *lpVersionVarSize = 0;
    if (!VerQueryValueW(lpInfo, TranslationRegKey,
                        (LPVOID*)&lpVarSize, &uSize))
    {
        MyFree(lpInfo);
        return TRUE;
    }

    if (uSize >= 4)
    {
        *lpVersionVarSize = *lpVarSize;
    }

    MyFree(lpInfo);

    return TRUE;
}
Esempio n. 14
0
/* Sets *matches to whether the file (whose path is filePath) matches the
 * versions set in sig.
 * Return ERROR_SUCCESS in case of success (whether or not the file matches),
 * something else if an install-halting error occurs.
 */
static UINT ACTION_FileVersionMatches(const MSISIGNATURE *sig, LPCWSTR filePath,
 BOOL *matches)
{
    UINT len;
    void *version;
    VS_FIXEDFILEINFO *info = NULL;
    DWORD zero, size = GetFileVersionInfoSizeW( filePath, &zero );

    *matches = FALSE;

    if (!size) return ERROR_SUCCESS;
    if (!(version = msi_alloc( size ))) return ERROR_OUTOFMEMORY;

    if (GetFileVersionInfoW( filePath, 0, size, version ))
        VerQueryValueW( version, szBackSlash, (void **)&info, &len );

    if (info)
    {
        TRACE("comparing file version %d.%d.%d.%d:\n",
              HIWORD(info->dwFileVersionMS),
              LOWORD(info->dwFileVersionMS),
              HIWORD(info->dwFileVersionLS),
              LOWORD(info->dwFileVersionLS));
        if (info->dwFileVersionMS < sig->MinVersionMS
            || (info->dwFileVersionMS == sig->MinVersionMS &&
                info->dwFileVersionLS < sig->MinVersionLS))
        {
            TRACE("less than minimum version %d.%d.%d.%d\n",
                   HIWORD(sig->MinVersionMS),
                   LOWORD(sig->MinVersionMS),
                   HIWORD(sig->MinVersionLS),
                   LOWORD(sig->MinVersionLS));
        }
        else if ((sig->MaxVersionMS || sig->MaxVersionLS) &&
                 (info->dwFileVersionMS > sig->MaxVersionMS ||
                  (info->dwFileVersionMS == sig->MaxVersionMS &&
                   info->dwFileVersionLS > sig->MaxVersionLS)))
        {
            TRACE("greater than maximum version %d.%d.%d.%d\n",
                   HIWORD(sig->MaxVersionMS),
                   LOWORD(sig->MaxVersionMS),
                   HIWORD(sig->MaxVersionLS),
                   LOWORD(sig->MaxVersionLS));
        }
        else if (!match_languages( version, sig->Languages ))
        {
            TRACE("languages %s not supported\n", debugstr_w( sig->Languages ));
        }
        else *matches = TRUE;
    }
    msi_free( version );
    return ERROR_SUCCESS;
}
Esempio n. 15
0
	std::wstring DebugHelper::DumpModules(uint32 processId) const {
		HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPMODULE, processId);
		if (hSnapshot == INVALID_HANDLE_VALUE)
			throw std::runtime_error("Could not create module snapshot!");

		std::wostringstream strmModules;
		MODULEENTRY32W moduleEntry = {0};
		moduleEntry.dwSize = sizeof(moduleEntry);

		if (Module32FirstW(hSnapshot, &moduleEntry) != FALSE) {
			do if (moduleEntry.th32ProcessID == processId) {
				strmModules << L"  0x" << std::hex << std::uppercase
							<< reinterpret_cast<void*>(moduleEntry.modBaseAddr) << L": "
							<< (moduleEntry.szModule != nullptr ? moduleEntry.szModule : L"<null>");

				if (moduleEntry.szExePath != nullptr) {
					DWORD dwVersionInfoHandle = 0;
					DWORD dwVersionInfoSize = GetFileVersionInfoSizeW(moduleEntry.szExePath, &dwVersionInfoHandle);

					UINT fileInfoSize = 0;
					VS_FIXEDFILEINFO *pFileInfo = nullptr;
					Utils::ByteBuffer versionInfoBuffer(dwVersionInfoSize);

					if (dwVersionInfoSize != 0 &&

						GetFileVersionInfoW(moduleEntry.szExePath, dwVersionInfoHandle,
							dwVersionInfoSize, versionInfoBuffer.data()) != FALSE &&

						VerQueryValueW(versionInfoBuffer.data(), L"\\",
							reinterpret_cast<LPVOID*>(&pFileInfo), &fileInfoSize) != FALSE &&

						fileInfoSize >= sizeof(VS_FIXEDFILEINFO))
					{
						// Output file version string...
						strmModules << L" (" << std::dec
									<< HIWORD(pFileInfo->dwFileVersionMS) << L'.'
									<< LOWORD(pFileInfo->dwFileVersionMS) << L'.'
									<< HIWORD(pFileInfo->dwFileVersionLS) << L'.'
									<< LOWORD(pFileInfo->dwFileVersionLS) << L')';
					}
				}

				strmModules << L"\r\n";
			}
			while (Module32NextW(hSnapshot, &moduleEntry) != FALSE);
		}

		CloseHandle(hSnapshot);
		return strmModules.str();
	}
Esempio n. 16
0
BOOL WINAPI GetFileVersionInfoU(
	LPCSTR lpstrFilename,
	DWORD dwHandle,
	DWORD dwLen,
	LPVOID lpData
)
{
	BOOL ret;
	WCHAR_T_DEC(lpstrFilename);
	WCHAR_T_CONV(lpstrFilename);
	ret = GetFileVersionInfoW(lpstrFilename_w, dwHandle, dwLen, lpData);
	WCHAR_T_FREE(lpstrFilename);
	return ret;
}
Esempio n. 17
0
File: extra.c Progetto: csilles/cxxr
SEXP do_dllversion(SEXP call, SEXP op, SEXP args, SEXP rho)
{
    SEXP path = R_NilValue, ans;
    const wchar_t *dll;
    DWORD dwVerInfoSize;
    DWORD dwVerHnd;

    checkArity(op, args);
    path = CAR(args);
    if(!isString(path) || LENGTH(path) != 1)
	errorcall(call, _("invalid '%s' argument"), "path");
    dll = filenameToWchar(STRING_ELT(path, 0), FALSE);
    dwVerInfoSize = GetFileVersionInfoSizeW(dll, &dwVerHnd);
    PROTECT(ans = allocVector(STRSXP, 2));
    SET_STRING_ELT(ans, 0, mkChar(""));
    SET_STRING_ELT(ans, 1, mkChar(""));
    if (dwVerInfoSize) {
	BOOL  fRet;
	LPSTR lpstrVffInfo;
	LPSTR lszVer = NULL;
	UINT  cchVer = 0;

	lpstrVffInfo = (LPSTR) malloc(dwVerInfoSize);
	if (GetFileVersionInfoW(dll, 0L, dwVerInfoSize, lpstrVffInfo)) {

	    fRet = VerQueryValue(lpstrVffInfo,
				 TEXT("\\StringFileInfo\\040904E4\\FileVersion"),
				 (LPVOID)&lszVer, &cchVer);
	    if(fRet) SET_STRING_ELT(ans, 0, mkChar(lszVer));

	    fRet = VerQueryValue(lpstrVffInfo,
				 TEXT("\\StringFileInfo\\040904E4\\R Version"),
				 (LPVOID)&lszVer, &cchVer);
	    if(fRet) SET_STRING_ELT(ans, 1, mkChar(lszVer));
	    else {
		fRet = VerQueryValue(lpstrVffInfo,
				     TEXT("\\StringFileInfo\\040904E4\\Compiled under R Version"),
				     (LPVOID)&lszVer, &cchVer);
		if(fRet) SET_STRING_ELT(ans, 1, mkChar(lszVer));
	    }

	} else ans = R_NilValue;
	free(lpstrVffInfo);
    } else ans = R_NilValue;
    UNPROTECT(1);
    return ans;
}
Esempio n. 18
0
static bool WindowsGetModuleDescription(MCStringRef p_path, MCStringRef& r_description)
{
	bool t_success;
	t_success = true;

    MCAutoStringRefAsWString t_path;
    /* UNCHECKED */ t_path.Lock(p_path);
    
	DWORD t_size;
	t_size = 0;
	if (t_success)
	{
		t_size = GetFileVersionInfoSizeW(*t_path, nil);
		if (t_size == 0)
			t_success = false;
	}

	void *t_data;
	t_data = nil;
	if (t_success)
		t_success = MCMemoryAllocate(t_size, t_data);

	if (t_success &&
		!GetFileVersionInfoW(*t_path, 0, t_size, t_data))
		t_success = false;

	UINT t_desc_length;
	WCHAR *t_desc;
	t_desc_length = 0;
	t_desc = nil;
	if (t_success &&
		!VerQueryValueW(t_data, L"\\StringFileInfo\\040904b0\\FileDescription", (void **)&t_desc, &t_desc_length))
		t_success = false;

    if (t_success)
        t_success = MCStringCreateWithWString(t_desc, r_description);
    
	MCMemoryDeallocate(t_data);
	
    // Make sure a description gets set
    if (!t_success)
        r_description = MCValueRetain(kMCEmptyString);
    
	return t_success;
}
// Get file version information from a file
static BOOL
GetFileVersion(LPCWSTR szFile, verBlock *vbVersion)
{
  UINT              uLen;
  UINT              dwLen;
  BOOL              bRv;
  DWORD             dwHandle;
  LPVOID            lpData;
  LPVOID            lpBuffer;
  VS_FIXEDFILEINFO  *lpBuffer2;

  ClearVersion(vbVersion);
  if (FileExists(szFile)) {
    bRv    = TRUE;
#ifdef WINCE
    // WinCe takes a non const file path string, while desktop take a const
    LPWSTR lpFilepath = const_cast<LPWSTR>(szFile);
#else
    LPCWSTR lpFilepath = szFile;
#endif
    dwLen  = GetFileVersionInfoSizeW(lpFilepath, &dwHandle);
    lpData = (LPVOID)malloc(dwLen);
    uLen   = 0;

    if (lpData && GetFileVersionInfoW(lpFilepath, dwHandle, dwLen, lpData) != 0) {
      if (VerQueryValueW(lpData, L"\\", &lpBuffer, &uLen) != 0) {
        lpBuffer2 = (VS_FIXEDFILEINFO *)lpBuffer;

        vbVersion->wMajor   = HIWORD(lpBuffer2->dwFileVersionMS);
        vbVersion->wMinor   = LOWORD(lpBuffer2->dwFileVersionMS);
        vbVersion->wRelease = HIWORD(lpBuffer2->dwFileVersionLS);
        vbVersion->wBuild   = LOWORD(lpBuffer2->dwFileVersionLS);
      }
    }

    free(lpData);
  } else {
    /* File does not exist */
    bRv = FALSE;
  }

  return bRv;
}
Esempio n. 20
0
static void fetch_module_versioninfo(LPCWSTR filename, VS_FIXEDFILEINFO* ffi)
{
    DWORD       handle;
    DWORD       sz;
    static const WCHAR backslashW[] = {'\\', '\0'};

    memset(ffi, 0, sizeof(*ffi));
    if ((sz = GetFileVersionInfoSizeW(filename, &handle)))
    {
        void*   info = HeapAlloc(GetProcessHeap(), 0, sz);
        if (info && GetFileVersionInfoW(filename, handle, sz, info))
        {
            VS_FIXEDFILEINFO*   ptr;
            UINT    len;

            if (VerQueryValueW(info, backslashW, (void*)&ptr, &len))
                memcpy(ffi, ptr, min(len, sizeof(*ffi)));
        }
        HeapFree(GetProcessHeap(), 0, info);
    }
}
Esempio n. 21
0
BOOL CFileVersionInfo::Load(LPCWSTR pwszPath)
{
    ULONG cbInfo = GetFileVersionInfoSizeW(pwszPath, NULL);
    if (!cbInfo)
    {
        WARN("GetFileVersionInfoSize %ls failed\n", pwszPath);
        return FALSE;
    }

    m_pInfo = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, cbInfo);
    if (!m_pInfo)
    {
        ERR("HeapAlloc failed bytes %x\n", cbInfo);
        return FALSE;
    }

    if (!GetFileVersionInfoW(pwszPath, 0, cbInfo, m_pInfo))
    {
        ERR("GetFileVersionInfoW failed\n");
        return FALSE;
    }

    LPLANGANDCODEPAGE lpLangCode;
    UINT cBytes;
    if (!VerQueryValueW(m_pInfo, L"\\VarFileInfo\\Translation", (LPVOID *)&lpLangCode, &cBytes) || cBytes < sizeof(LANGANDCODEPAGE))
    {
        ERR("VerQueryValueW failed\n");
        return FALSE;
    }

    /* FIXME: find language from current locale / if not available,
     * default to english
     * for now default to first available language
     */
    m_wLang = lpLangCode->wLang;
    m_wCode = lpLangCode->wCode;
    TRACE("Lang %hx Code %hu\n", m_wLang, m_wCode);

    return TRUE;
}
Esempio n. 22
0
static Status ReadVersionString(const OsPath& modulePathname, wchar_t* out_ver, size_t out_ver_len)
{
	WinScopedPreserveLastError s;	// GetFileVersion*, Ver*

	// determine size of and allocate memory for version information.
	DWORD unused;
	const DWORD ver_size = GetFileVersionInfoSizeW(OsString(modulePathname).c_str(), &unused);	// [bytes]
	if(!ver_size)
	{
		// check if the failure is due to not finding modulePathname
		// (necessary since GetFileVersionInfoSize doesn't SetLastError)
		HMODULE hModule = LoadLibraryExW(OsString(modulePathname).c_str(), 0, LOAD_LIBRARY_AS_DATAFILE);
		if(!hModule)
			return ERR::FAIL;	// NOWARN (file not found - due to FS redirection?)
		FreeLibrary(hModule);
		return ERR::NOT_SUPPORTED;	// NOWARN (module apparently lacks version information)
	}

	shared_ptr<u8> mem = Allocate(ver_size);
	if(!GetFileVersionInfoW(OsString(modulePathname).c_str(), 0, ver_size, mem.get()))
		WARN_RETURN(ERR::_3);

	u16* lang;	// -> 16 bit language ID, 16 bit codepage
	UINT lang_len;
	const BOOL ok = VerQueryValueW(mem.get(), L"\\VarFileInfo\\Translation", (void**)&lang, &lang_len);
	if(!ok || !lang || lang_len != 4)
		WARN_RETURN(ERR::_4);

	wchar_t subblock[64];
	swprintf_s(subblock, ARRAY_SIZE(subblock), L"\\StringFileInfo\\%04X%04X\\FileVersion", lang[0], lang[1]);
	const wchar_t* in_ver;
	UINT in_ver_len;
	if(!VerQueryValueW(mem.get(), subblock, (void**)&in_ver, &in_ver_len))
		WARN_RETURN(ERR::_5);

	wcscpy_s(out_ver, out_ver_len, in_ver);
	return INFO::OK;
}
Esempio n. 23
0
StString StLibrary::DLibGetVersion(const StStringUtfWide& theLibPath) {
    DWORD aFVInfoSize = GetFileVersionInfoSizeW(theLibPath.toCString(), NULL);
    if(aFVInfoSize == 0) {
        return StString();
    }
    LPVOID aBlock = stMemAlloc(aFVInfoSize);
    GetFileVersionInfoW(theLibPath.toCString(), NULL, aFVInfoSize, aBlock);
    VS_FIXEDFILEINFO* aFixedInfo;
    UINT aBufferSize;
    stUtfWide_t aPathToSubBlock[] = L"\\";
    if(VerQueryValueW(aBlock, aPathToSubBlock, (LPVOID* )&aFixedInfo, &aBufferSize) == FALSE ||
       aBufferSize < sizeof(VS_FIXEDFILEINFO)) {
        stMemFree(aBlock);
        return StString();
    }
    StString aVersion = StString("ver.")
        + HIWORD(aFixedInfo->dwFileVersionMS) + '.'
        + LOWORD(aFixedInfo->dwFileVersionMS) + '.'
        + HIWORD(aFixedInfo->dwFileVersionLS) + '.'
        + LOWORD(aFixedInfo->dwFileVersionLS);
    stMemFree(aBlock);
    return aVersion;
}
Esempio n. 24
0
ModuleVersion get_module_version(HINSTANCE module) {
  ModuleVersion version;
  memset(&version, 0, sizeof(version));
  UnicodeString file_name;
  unsigned size = GetModuleFileNameW(module, file_name.buf(MAX_PATH), MAX_PATH);
  if (size != 0) {
    file_name.set_size(size);
    DWORD handle;
    size = GetFileVersionInfoSizeW(file_name.data(), &handle);
    if (size != 0) {
      Array<char> ver_data;
      if (GetFileVersionInfoW(file_name.data(), handle, size, ver_data.buf(size)) != 0) {
        VS_FIXEDFILEINFO* ver;
        if (VerQueryValueW((const LPVOID) ver_data.data(), L"\\", (LPVOID*) &ver, &size) != 0) {
          version.major = HIWORD(ver->dwProductVersionMS);
          version.minor = LOWORD(ver->dwProductVersionMS);
          version.patch = HIWORD(ver->dwProductVersionLS);
          version.revision = LOWORD(ver->dwProductVersionLS);
        }
      }
    }
  }
  return version;
}
Esempio n. 25
0
static LPWSTR app_search_file(LPWSTR path, MSISIGNATURE *sig)
{
    VS_FIXEDFILEINFO *info;
    DWORD attr, handle, size;
    LPWSTR val = NULL;
    LPBYTE buffer;

    if (!sig->File)
    {
        PathRemoveFileSpecW(path);
        PathAddBackslashW(path);

        attr = GetFileAttributesW(path);
        if (attr != INVALID_FILE_ATTRIBUTES &&
            (attr & FILE_ATTRIBUTE_DIRECTORY))
            return strdupW(path);

        return NULL;
    }

    attr = GetFileAttributesW(path);
    if (attr == INVALID_FILE_ATTRIBUTES ||
        (attr & FILE_ATTRIBUTE_DIRECTORY))
        return NULL;

    size = GetFileVersionInfoSizeW(path, &handle);
    if (!size)
        return strdupW(path);

    buffer = msi_alloc(size);
    if (!buffer)
        return NULL;

    if (!GetFileVersionInfoW(path, 0, size, buffer))
        goto done;

    if (!VerQueryValueW(buffer, szBackSlash, (LPVOID)&info, &size) || !info)
        goto done;

    if (sig->MinVersionLS || sig->MinVersionMS)
    {
        if (info->dwFileVersionMS < sig->MinVersionMS)
            goto done;

        if (info->dwFileVersionMS == sig->MinVersionMS &&
            info->dwFileVersionLS < sig->MinVersionLS)
            goto done;
    }

    if (sig->MaxVersionLS || sig->MaxVersionMS)
    {
        if (info->dwFileVersionMS > sig->MaxVersionMS)
            goto done;

        if (info->dwFileVersionMS == sig->MaxVersionMS &&
            info->dwFileVersionLS > sig->MaxVersionLS)
            goto done;
    }

    val = strdupW(path);

done:
    msi_free(buffer);
    return val;
}
Esempio n. 26
0
// If a blacklisted DLL is found, return its information, otherwise "".
static const nsACString&
FindDXVABlacklistedDLL(StaticAutoPtr<D3DDLLBlacklistingCache>& aDLLBlacklistingCache,
                       const char* aDLLBlacklistPrefName)
{
  NS_ASSERTION(NS_IsMainThread(), "Must be on main thread.");

  if (!aDLLBlacklistingCache) {
    // First time here, create persistent data that will be reused in all
    // D3D11-blacklisting checks.
    aDLLBlacklistingCache = new D3DDLLBlacklistingCache();
    ClearOnShutdown(&aDLLBlacklistingCache);
  }

  nsAdoptingCString blacklist = Preferences::GetCString(aDLLBlacklistPrefName);
  if (blacklist.IsEmpty()) {
    // Empty blacklist -> No blacklisting.
    aDLLBlacklistingCache->mBlacklistPref.SetLength(0);
    aDLLBlacklistingCache->mBlacklistedDLL.SetLength(0);
    return aDLLBlacklistingCache->mBlacklistedDLL;
  }

  // Detect changes in pref.
  if (aDLLBlacklistingCache->mBlacklistPref.Equals(blacklist)) {
    // Same blacklist -> Return same result (i.e., don't check DLLs again).
    return aDLLBlacklistingCache->mBlacklistedDLL;
  }
  // Adopt new pref now, so we don't work on it again.
  aDLLBlacklistingCache->mBlacklistPref = blacklist;

  // media.wmf.disable-d3d*-for-dlls format: (whitespace is trimmed)
  // "dll1.dll: 1.2.3.4[, more versions...][; more dlls...]"
  nsTArray<nsCString> dlls;
  SplitAt(";", blacklist, dlls);
  for (const auto& dll : dlls) {
    nsTArray<nsCString> nameAndVersions;
    SplitAt(":", dll, nameAndVersions);
    if (nameAndVersions.Length() != 2) {
      NS_WARNING(nsPrintfCString("Skipping incorrect '%s' dll:versions format",
                                 aDLLBlacklistPrefName).get());
      continue;
    }

    nameAndVersions[0].CompressWhitespace();
    NS_ConvertUTF8toUTF16 name(nameAndVersions[0]);
    WCHAR systemPath[MAX_PATH + 1];
    if (!ConstructSystem32Path(name.get(), systemPath, MAX_PATH + 1)) {
      // Cannot build path -> Assume it's not the blacklisted DLL.
      continue;
    }

    DWORD zero;
    DWORD infoSize = GetFileVersionInfoSizeW(systemPath, &zero);
    if (infoSize == 0) {
      // Can't get file info -> Assume we don't have the blacklisted DLL.
      continue;
    }
    // vInfo is a pointer into infoData, that's why we keep it outside of the loop.
    auto infoData = MakeUnique<unsigned char[]>(infoSize);
    VS_FIXEDFILEINFO *vInfo;
    UINT vInfoLen;
    if (!GetFileVersionInfoW(systemPath, 0, infoSize, infoData.get())
        || !VerQueryValueW(infoData.get(), L"\\", (LPVOID*)&vInfo, &vInfoLen)
        || !vInfo) {
      // Can't find version -> Assume it's not blacklisted.
      continue;
    }

    nsTArray<nsCString> versions;
    SplitAt(",", nameAndVersions[1], versions);
    for (const auto& version : versions) {
      nsTArray<nsCString> numberStrings;
      SplitAt(".", version, numberStrings);
      if (numberStrings.Length() != 4) {
        NS_WARNING(nsPrintfCString("Skipping incorrect '%s' a.b.c.d version format",
                                   aDLLBlacklistPrefName).get());
        continue;
      }
      DWORD numbers[4];
      nsresult errorCode = NS_OK;
      for (int i = 0; i < 4; ++i) {
        numberStrings[i].CompressWhitespace();
        numbers[i] = DWORD(numberStrings[i].ToInteger(&errorCode));
        if (NS_FAILED(errorCode)) {
          break;
        }
        if (numbers[i] > UINT16_MAX) {
          errorCode = NS_ERROR_FAILURE;
          break;
        }
      }

      if (NS_FAILED(errorCode)) {
        NS_WARNING(nsPrintfCString("Skipping incorrect '%s' a.b.c.d version format",
                                   aDLLBlacklistPrefName).get());
        continue;
      }

      if (vInfo->dwFileVersionMS == ((numbers[0] << 16) | numbers[1])
          && vInfo->dwFileVersionLS == ((numbers[2] << 16) | numbers[3])) {
        // Blacklisted! Record bad DLL.
        aDLLBlacklistingCache->mBlacklistedDLL.SetLength(0);
        aDLLBlacklistingCache->mBlacklistedDLL.AppendPrintf(
          "%s (%lu.%lu.%lu.%lu)",
          nameAndVersions[0].get(), numbers[0], numbers[1], numbers[2], numbers[3]);
        return aDLLBlacklistingCache->mBlacklistedDLL;
      }
    }
  }

  // No blacklisted DLL.
  aDLLBlacklistingCache->mBlacklistedDLL.SetLength(0);
  return aDLLBlacklistingCache->mBlacklistedDLL;
}
Esempio n. 27
0
void Diagnostics::run()
{
	QString info;
	QTextStream s( &info );

	s << "<b>" << tr("Locale (time-, number format / codepage):") << "</b> ";
	QLocale::Language language = QLocale::system().language();
	QString locale = (language == QLocale::C ? "English/United States" : QLocale::languageToString( language ) );
	CPINFOEX CPInfoEx;
	if( GetCPInfoEx( GetConsoleCP(), 0, &CPInfoEx ) != 0 )
		locale.append( " / " ).append( QString( (QChar*)CPInfoEx.CodePageName ) );
	s << locale << "<br />";
	emit update( info );
	info.clear();

	s << "<b>" << tr("User rights: ") << "</b>" << getUserRights() << "<br />";
	emit update( info );
	info.clear();

	QStringList base = Common::packages( QStringList()
		<< "Eesti ID-kaardi tarkvara" << "Estonian ID-card software", false );
	if( !base.isEmpty() )
		s << "<b>" << tr("Base version:") << "</b> " << base.join( "<br />" ) << "<br />";
	s << "<b>" << tr("Application version:") << "</b> "<< QCoreApplication::applicationVersion()
#ifdef INTERNATIONAL
		<< " INTERNATIONAL"
#endif
		<< "<br />";
	emit update( info );
	info.clear();

	s << "<b>" << tr("OS:") << "</b> " << Common::applicationOs() << "<br />";
	SYSTEM_INFO sysinfo;
	GetSystemInfo( &sysinfo );
	s << "<b>" << tr("CPU:") << "</b> " << QString::number( sysinfo.dwProcessorType ) << "<br /><br />";
	emit update( info );
	info.clear();

	s << "<b>" << "URLs:" << "</b>";
	const QHash<QString,QString> urls = qApp->urls();
	for(auto i = urls.constBegin(); i != urls.constEnd(); ++i)
		s << "<br />" << i.key() << ": " << i.value();
	s << "<br /><br />";

	s << "<b>" << tr("Arguments:") << "</b> " << qApp->arguments().join(" ") << "<br />";
	s << "<b>" << tr("Library paths:") << "</b> " << QCoreApplication::libraryPaths().join( ";" ) << "<br />";

	s << "<b>" << tr("Libraries") << ":</b><br />" << "QT (" << qVersion() << ")<br />";
	Q_FOREACH( const QString &lib, QStringList()
			<< "digidoc" << "digidocpp" << "qdigidocclient.exe" << "qesteidutil.exe" << "id-updater.exe"
			<< "esteidcsp" << "esteidcm" << "opensc-pkcs11" << "esteid-pkcs11" << "EsteidShellExtension"
			<< "esteid-plugin-ie" << "npesteid-firefox-plugin" << "chrome-token-signing.exe"
			<< "zlib1" << "libeay32" << "ssleay32" << "xerces-c_3_1" << "xsec_1_7" << "libxml2"
			<< "advapi32" << "crypt32" << "winscard" )
	{
		DWORD infoHandle = 0;
		LONG sz = GetFileVersionInfoSize( LPCWSTR(lib.utf16()), &infoHandle );
		if( !sz )
			continue;
		QByteArray data( sz * 2, 0 );
		if( !GetFileVersionInfoW( LPCWSTR(lib.utf16()), 0, sz, data.data() ) )
			continue;
		VS_FIXEDFILEINFO *info = 0;
		UINT len = 0;
		if( !VerQueryValueW( data.constData(), L"\\", (LPVOID*)&info, &len ) )
			continue;
		s << QString( "%1 (%2.%3.%4.%5)" ).arg( lib )
			.arg( HIWORD(info->dwFileVersionMS) )
			.arg( LOWORD(info->dwFileVersionMS) )
			.arg( HIWORD(info->dwFileVersionLS) )
			.arg( LOWORD(info->dwFileVersionLS) ) << "<br />";
	}
	s << "<br />";
	emit update( info );
	info.clear();

	enum {
		Running,
		Stopped,
		NotFound
	} atrfiltr = NotFound, certprop = NotFound;
	if( SC_HANDLE h = OpenSCManager( 0, 0, SC_MANAGER_CONNECT ) )
	{
		if( SC_HANDLE s = OpenService( h, L"atrfiltr", SERVICE_QUERY_STATUS ) )
		{
			SERVICE_STATUS status;
			QueryServiceStatus( s, &status );
			atrfiltr = (status.dwCurrentState == SERVICE_RUNNING) ? Running : Stopped;
			CloseServiceHandle( s );
		}
		if( SC_HANDLE s = OpenService( h, L"CertPropSvc", SERVICE_QUERY_STATUS ))
		{
			SERVICE_STATUS status;
			QueryServiceStatus( s, &status );
			certprop = (status.dwCurrentState == SERVICE_RUNNING) ? Running : Stopped;
			CloseServiceHandle( s );
		}
		CloseServiceHandle( h );
	}
	s << "<br /><b>" << tr("ATRfiltr service status: ") << "</b>" << " ";
	switch( atrfiltr )
	{
	case NotFound: s << tr("Not found"); break;
	case Stopped: s << tr("Not running"); break;
	case Running: s << tr("Running"); break;
	}
	s << "<br /><b>" << tr("Certificate Propagation service status: ") << "</b>" << " ";
	switch( certprop )
	{
	case NotFound: s << tr("Not found"); break;
	case Stopped: s << tr("Not running"); break;
	case Running: s << tr("Running"); break;
	}
	s << "<br />";

	getReaderInfo( s );
	emit update( info );
	info.clear();

	QStringList browsers = Common::packages( QStringList() << "Firefox" << "Google Chrome" );
	QSettings reg( "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Internet Explorer", QSettings::NativeFormat );
	browsers << QString( "Internet Explorer (%1)" ).arg(
		reg.value("svcVersion", reg.value( "Version" ) ).toString() );
	s << "<br /><br /><b>" << tr("Browsers:") << "</b><br />" << browsers.join( "<br />" ) << "<br /><br />";
	emit update( info );
	info.clear();
}
Esempio n. 28
0
/* Sets *matches to whether the file (whose path is filePath) matches the
 * versions set in sig.
 * Return ERROR_SUCCESS in case of success (whether or not the file matches),
 * something else if an install-halting error occurs.
 */
static UINT ACTION_FileVersionMatches(const MSISIGNATURE *sig, LPCWSTR filePath,
 BOOL *matches)
{
    UINT rc = ERROR_SUCCESS;

    *matches = FALSE;
    if (sig->Languages)
    {
        FIXME(": need to check version for languages %s\n",
         debugstr_w(sig->Languages));
    }
    else
    {
        DWORD zero, size = GetFileVersionInfoSizeW(filePath, &zero);

        if (size)
        {
            LPVOID buf = msi_alloc( size);

            if (buf)
            {
                UINT versionLen;
                LPVOID subBlock = NULL;

                if (GetFileVersionInfoW(filePath, 0, size, buf))
                    VerQueryValueW(buf, szBackSlash, &subBlock, &versionLen);
                if (subBlock)
                {
                    VS_FIXEDFILEINFO *info = subBlock;

                    TRACE("Comparing file version %d.%d.%d.%d:\n",
                     HIWORD(info->dwFileVersionMS),
                     LOWORD(info->dwFileVersionMS),
                     HIWORD(info->dwFileVersionLS),
                     LOWORD(info->dwFileVersionLS));
                    if (info->dwFileVersionMS < sig->MinVersionMS
                     || (info->dwFileVersionMS == sig->MinVersionMS &&
                     info->dwFileVersionLS < sig->MinVersionLS))
                    {
                        TRACE("Less than minimum version %d.%d.%d.%d\n",
                         HIWORD(sig->MinVersionMS),
                         LOWORD(sig->MinVersionMS),
                         HIWORD(sig->MinVersionLS),
                         LOWORD(sig->MinVersionLS));
                    }
                    else if ((sig->MaxVersionMS || sig->MaxVersionLS) &&
                             (info->dwFileVersionMS > sig->MaxVersionMS ||
                              (info->dwFileVersionMS == sig->MaxVersionMS &&
                               info->dwFileVersionLS > sig->MaxVersionLS)))
                    {
                        TRACE("Greater than maximum version %d.%d.%d.%d\n",
                         HIWORD(sig->MaxVersionMS),
                         LOWORD(sig->MaxVersionMS),
                         HIWORD(sig->MaxVersionLS),
                         LOWORD(sig->MaxVersionLS));
                    }
                    else
                        *matches = TRUE;
                }
                msi_free( buf);
            }
            else
                rc = ERROR_OUTOFMEMORY;
        }
    }
    return rc;
}
Esempio n. 29
0
/***********************************************************************
 *             GetVersionFromFileExW   (ADVPACK.@)
 *
 * Gets the files version or language information.
 *
 * PARAMS
 *   lpszFilename [I] The file to get the info from.
 *   pdwMSVer     [O] Major version.
 *   pdwLSVer     [O] Minor version.
 *   bVersion     [I] Whether to retrieve version or language info.
 *
 * RETURNS
 *   Always returns S_OK.
 *
 * NOTES
 *   If bVersion is TRUE, version information is retrieved, else
 *   pdwMSVer gets the language ID and pdwLSVer gets the codepage ID.
 */
HRESULT WINAPI GetVersionFromFileExW(LPCWSTR lpszFilename, LPDWORD pdwMSVer,
                                     LPDWORD pdwLSVer, BOOL bVersion )
{
    VS_FIXEDFILEINFO *pFixedVersionInfo;
    LANGANDCODEPAGE *pLangAndCodePage;
    DWORD dwHandle, dwInfoSize;
    WCHAR szWinDir[MAX_PATH];
    WCHAR szFile[MAX_PATH];
    LPVOID pVersionInfo = NULL;
    BOOL bFileCopied = FALSE;
    UINT uValueLen;

    static const WCHAR backslash[] = {'\\',0};
    static const WCHAR translation[] = {
        '\\','V','a','r','F','i','l','e','I','n','f','o',
        '\\','T','r','a','n','s','l','a','t','i','o','n',0
    };

    TRACE("(%s, %p, %p, %d)\n", debugstr_w(lpszFilename),
          pdwMSVer, pdwLSVer, bVersion);

    *pdwLSVer = 0;
    *pdwMSVer = 0;

    lstrcpynW(szFile, lpszFilename, MAX_PATH);

    dwInfoSize = GetFileVersionInfoSizeW(szFile, &dwHandle);
    if (!dwInfoSize)
    {
        /* check that the file exists */
        if (GetFileAttributesW(szFile) == INVALID_FILE_ATTRIBUTES)
            return S_OK;

        /* file exists, but won't be found by GetFileVersionInfoSize,
        * so copy it to the temp dir where it will be found.
        */
        GetWindowsDirectoryW(szWinDir, MAX_PATH);
        GetTempFileNameW(szWinDir, NULL, 0, szFile);
        CopyFileW(lpszFilename, szFile, FALSE);
        bFileCopied = TRUE;

        dwInfoSize = GetFileVersionInfoSizeW(szFile, &dwHandle);
        if (!dwInfoSize)
            goto done;
    }

    pVersionInfo = HeapAlloc(GetProcessHeap(), 0, dwInfoSize);
    if (!pVersionInfo)
        goto done;

    if (!GetFileVersionInfoW(szFile, dwHandle, dwInfoSize, pVersionInfo))
        goto done;

    if (bVersion)
    {
        if (!VerQueryValueW(pVersionInfo, backslash,
            (LPVOID *)&pFixedVersionInfo, &uValueLen))
            goto done;

        if (!uValueLen)
            goto done;

        *pdwMSVer = pFixedVersionInfo->dwFileVersionMS;
        *pdwLSVer = pFixedVersionInfo->dwFileVersionLS;
    }
    else
    {
        if (!VerQueryValueW(pVersionInfo, translation,
             (LPVOID *)&pLangAndCodePage, &uValueLen))
            goto done;

        if (!uValueLen)
            goto done;

        *pdwMSVer = pLangAndCodePage->wLanguage;
        *pdwLSVer = pLangAndCodePage->wCodePage;
    }

done:
    HeapFree(GetProcessHeap(), 0, pVersionInfo);

    if (bFileCopied)
        DeleteFileW(szFile);

    return S_OK;
}
Esempio n. 30
0
NTSTATUS FspNpRegister(VOID)
{
    extern HINSTANCE DllInstance;
    WCHAR ProviderPath[MAX_PATH];
    WCHAR RegBuffer[1024];
    PWSTR P, Part;
    DWORD RegResult, RegType, RegBufferSize;
    HKEY RegKey;
    BOOLEAN FoundProvider;

    if (0 == GetModuleFileNameW(DllInstance, ProviderPath, MAX_PATH))
        return FspNtStatusFromWin32(GetLastError());

    RegResult = RegCreateKeyExW(
        HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\" FSP_NP_NAME,
        0, 0, 0, KEY_ALL_ACCESS, 0, &RegKey, 0);
    if (ERROR_SUCCESS != RegResult)
        return FspNtStatusFromWin32(RegResult);

    RegResult = RegSetValueExW(RegKey,
        L"Group", 0, REG_SZ, (PVOID) L"NetworkProvider", sizeof L"NetworkProvider");
    if (ERROR_SUCCESS != RegResult)
        goto close_and_exit;

    RegCloseKey(RegKey);

    RegResult = RegCreateKeyExW(
        HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\" FSP_NP_NAME "\\NetworkProvider",
        0, 0, 0, KEY_ALL_ACCESS, 0, &RegKey, 0);
    if (ERROR_SUCCESS != RegResult)
        return FspNtStatusFromWin32(RegResult);

    RegResult = ERROR_RESOURCE_NAME_NOT_FOUND; /* not a real resource error! */
    {
        PVOID VersionInfo = 0;
        DWORD Size;
        PWSTR Description;

        Size = GetFileVersionInfoSizeW(ProviderPath, &Size/*dummy*/);
        if (0 < Size)
        {
            VersionInfo = MemAlloc(Size);
            if (0 != VersionInfo &&
                GetFileVersionInfoW(ProviderPath, 0, Size, VersionInfo) &&
                VerQueryValueW(VersionInfo, L"\\StringFileInfo\\040904b0\\FileDescription",
                    &Description, &Size))
            {
                Size = Size * 2 + sizeof(WCHAR);
                RegResult = RegSetValueExW(RegKey,
                    L"Name", 0, REG_SZ, (PVOID)Description, Size);
            }

            MemFree(VersionInfo);
        }
    }
    if (ERROR_SUCCESS != RegResult)
        goto close_and_exit;

    RegResult = RegSetValueExW(RegKey,
        L"ProviderPath", 0, REG_SZ, (PVOID)ProviderPath, (lstrlenW(ProviderPath) + 1) * sizeof(WCHAR));
    if (ERROR_SUCCESS != RegResult)
        goto close_and_exit;

    RegCloseKey(RegKey);

    RegResult = RegOpenKeyExW(
        HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Control\\NetworkProvider\\Order",
        0, KEY_ALL_ACCESS, &RegKey);
    if (ERROR_SUCCESS != RegResult)
        return FspNtStatusFromWin32(RegResult);

    RegBufferSize = sizeof RegBuffer - sizeof L"," FSP_NP_NAME;
    RegResult = RegQueryValueExW(RegKey,
        L"ProviderOrder", 0, &RegType, (PVOID)RegBuffer, &RegBufferSize);
    if (ERROR_SUCCESS != RegResult)
        goto close_and_exit;
    RegBufferSize /= sizeof(WCHAR);

    FoundProvider = FALSE;
    RegBuffer[RegBufferSize] = L'\0';
    P = RegBuffer, Part = P;
    do
    {
        if (L',' == *P || '\0' == *P)
        {
            if (CSTR_EQUAL == CompareStringW(LOCALE_INVARIANT, NORM_IGNORECASE,
                Part, (int)(P - Part),
                L"" FSP_NP_NAME, (int)(sizeof L"" FSP_NP_NAME - sizeof(WCHAR)) / sizeof(WCHAR)))
            {
                FoundProvider = TRUE;
                break;
            }
            else
                Part = P + 1;
        }
    } while (L'\0' != *P++);

    if (!FoundProvider)
    {
        P--;
        memcpy(P, L"," FSP_NP_NAME, sizeof L"," FSP_NP_NAME);

        RegBufferSize = lstrlenW(RegBuffer);
        RegBufferSize++;

        RegResult = RegSetValueExW(RegKey,
            L"ProviderOrder", 0, REG_SZ, (PVOID)RegBuffer, RegBufferSize * sizeof(WCHAR));
        if (ERROR_SUCCESS != RegResult)
            goto close_and_exit;
    }

    RegCloseKey(RegKey);

    return STATUS_SUCCESS;

close_and_exit:
    RegCloseKey(RegKey);
    return FspNtStatusFromWin32(RegResult);
}