BOOL WINAPI CryptAcquireContextW(HCRYPTPROV *phProv, LPCTSTR pszContainer, LPCTSTR pszProvider, DWORD dwProvType, DWORD dwFlags) { static const WCHAR *className = L"Windows.Security.Cryptography.CryptographicBuffer"; const UINT32 clen = wcslen(className); HSTRING hClassName = NULL; HSTRING_HEADER header; HRESULT hr = WindowsCreateStringReference(className, clen, &header, &hClassName); if (FAILED(hr)) { WindowsDeleteString(hClassName); return FALSE; } ICryptographicBufferStatics *cryptoStatics = NULL; hr = RoGetActivationFactory(hClassName, &IID_ICryptographicBufferStatics, (void**)&cryptoStatics); WindowsDeleteString(hClassName); if (FAILED(hr)) return FALSE; *phProv = cryptoStatics; return TRUE; }
// called by winrt on startup HRESULT FrameworkView::Run() { LogFunction(); // Initialize XPCOM, create mWidget and go! We get a // callback in MetroAppShell::Run, in which we kick // off normal browser execution / event dispatching. mMetroApp->Run(); // Gecko is completely shut down at this point. WinUtils::Log("Exiting FrameworkView::Run()"); WindowsDeleteString(sActivationURI); return S_OK; }
void vlc_rand_bytes (void *buf, size_t len) { size_t count = len; uint8_t *p_buf = (uint8_t *)buf; /* fill buffer with pseudo-random data */ while (count > 0) { unsigned int val; val = rand(); if (count < sizeof (val)) { memcpy (p_buf, &val, count); break; } memcpy (p_buf, &val, sizeof (val)); count -= sizeof (val); p_buf += sizeof (val); } #if VLC_WINSTORE_APP static const WCHAR *className = L"Windows.Security.Cryptography.CryptographicBuffer"; const UINT32 clen = wcslen(className); HSTRING hClassName = NULL; HSTRING_HEADER header; HRESULT hr = WindowsCreateStringReference(className, clen, &header, &hClassName); if (hr) { WindowsDeleteString(hClassName); return; } ICryptographicBufferStatics *cryptoStatics = NULL; hr = RoGetActivationFactory(hClassName, &IID_ICryptographicBufferStatics, (void**)&cryptoStatics); WindowsDeleteString(hClassName); if (hr) return; IBuffer *buffer = NULL; hr = ICryptographicBufferStatics_GenerateRandom(cryptoStatics, len, &buffer); if (hr) { ICryptographicBufferStatics_Release(cryptoStatics); return; } UINT32 olength; unsigned char *rnd = NULL; hr = ICryptographicBufferStatics_CopyToByteArray(cryptoStatics, buffer, &olength, (BYTE**)&rnd); memcpy(buf, rnd, len); IBuffer_Release(buffer); ICryptographicBufferStatics_Release(cryptoStatics); #else HCRYPTPROV hProv; /* acquire default encryption context */ if( CryptAcquireContext( &hProv, // Variable to hold returned handle. NULL, // Use default key container. MS_DEF_PROV, // Use default CSP. PROV_RSA_FULL, // Type of provider to acquire. CRYPT_VERIFYCONTEXT) ) // Flag values { /* fill buffer with pseudo-random data, intial buffer content is used as auxillary random seed */ CryptGenRandom(hProv, len, buf); CryptReleaseContext(hProv, 0); } #endif /* VLC_WINSTORE_APP */ }
/*********************************************************************** * WindowsDeleteStringBuffer (combase.@) */ HRESULT WINAPI WindowsDeleteStringBuffer(HSTRING_BUFFER buf) { return WindowsDeleteString((HSTRING)buf); }
/*********************************************************************** * WindowsDeleteStringBuffer (combase.@) */ HRESULT WINAPI WindowsDeleteStringBuffer(HSTRING_BUFFER buf) { TRACE("(%p)\n", buf); return WindowsDeleteString((HSTRING)buf); }
static HRESULT WinRTSHGetFolderPath(HWND hwnd, int csidl, HANDLE hToken, DWORD dwFlags, LPWSTR pszPath) { VLC_UNUSED(hwnd); VLC_UNUSED(hToken); HRESULT hr; IStorageFolder *folder; if (dwFlags != SHGFP_TYPE_CURRENT) return E_NOTIMPL; folder = NULL; csidl &= ~0xFF00; /* CSIDL_FLAG_MASK */ if (csidl == CSIDL_APPDATA) { IApplicationDataStatics *appDataStatics = NULL; IApplicationData *appData = NULL; static const WCHAR *className = L"Windows.Storage.ApplicationData"; const UINT32 clen = wcslen(className); HSTRING hClassName = NULL; HSTRING_HEADER header; hr = WindowsCreateStringReference(className, clen, &header, &hClassName); if (FAILED(hr)) goto end_appdata; hr = RoGetActivationFactory(hClassName, &IID_IApplicationDataStatics, (void**)&appDataStatics); if (FAILED(hr)) goto end_appdata; if (!appDataStatics) { hr = E_FAIL; goto end_appdata; } hr = IApplicationDataStatics_get_Current(appDataStatics, &appData); if (FAILED(hr)) goto end_appdata; if (!appData) { hr = E_FAIL; goto end_appdata; } hr = IApplicationData_get_LocalFolder(appData, &folder); end_appdata: WindowsDeleteString(hClassName); if (appDataStatics) IApplicationDataStatics_Release(appDataStatics); if (appData) IApplicationData_Release(appData); } else { IKnownFoldersStatics *knownFoldersStatics = NULL; static const WCHAR *className = L"Windows.Storage.KnownFolders"; const UINT32 clen = wcslen(className); HSTRING hClassName = NULL; HSTRING_HEADER header; hr = WindowsCreateStringReference(className, clen, &header, &hClassName); if (FAILED(hr)) goto end_other; hr = RoGetActivationFactory(hClassName, &IID_IKnownFoldersStatics, (void**)&knownFoldersStatics); if (FAILED(hr)) goto end_other; if (!knownFoldersStatics) { hr = E_FAIL; goto end_other; } switch (csidl) { case CSIDL_PERSONAL: hr = IKnownFoldersStatics_get_DocumentsLibrary(knownFoldersStatics, &folder); break; case CSIDL_MYMUSIC: hr = IKnownFoldersStatics_get_MusicLibrary(knownFoldersStatics, &folder); break; case CSIDL_MYPICTURES: hr = IKnownFoldersStatics_get_PicturesLibrary(knownFoldersStatics, &folder); break; case CSIDL_MYVIDEO: hr = IKnownFoldersStatics_get_VideosLibrary(knownFoldersStatics, &folder); break; default: hr = E_NOTIMPL; } end_other: WindowsDeleteString(hClassName); if (knownFoldersStatics) IKnownFoldersStatics_Release(knownFoldersStatics); } if( SUCCEEDED(hr) && folder != NULL ) { HSTRING path = NULL; IStorageItem *item = NULL; PCWSTR pszPathTemp; hr = IStorageFolder_QueryInterface(folder, &IID_IStorageItem, (void**)&item); if (FAILED(hr)) goto end_folder; hr = IStorageItem_get_Path(item, &path); if (FAILED(hr)) goto end_folder; pszPathTemp = WindowsGetStringRawBuffer(path, NULL); wcscpy(pszPath, pszPathTemp); end_folder: WindowsDeleteString(path); IStorageFolder_Release(folder); if (item) IStorageItem_Release(item); } return hr; }