/// <summary> /// Clears the cache of the web browser /// </summary> public static void ClearCache() { // Indicates that all of the cache groups in the user's system should be enumerated const int CACHEGROUP_SEARCH_ALL = 0x0; // Indicates that all the cache entries that are associated with the cache group // should be deleted, unless the entry belongs to another cache group. const int CACHEGROUP_FLAG_FLUSHURL_ONDELETE = 0x2; const int ERROR_INSUFFICIENT_BUFFER = 0x7A; // Delete the groups first. // Groups may not always exist on the system. // For more information, visit the following Microsoft Web site: // http://msdn.microsoft.com/library/?url=/workshop/networking/wininet/overview/cache.asp // By default, a URL does not belong to any group. Therefore, that cache may become // empty even when the CacheGroup APIs are not used because the existing URL does not belong to any group. long groupId = 0; IntPtr enumHandle = FindFirstUrlCacheGroup(0, CACHEGROUP_SEARCH_ALL, IntPtr.Zero, 0, ref groupId, IntPtr.Zero); if (enumHandle != IntPtr.Zero) { bool more; do { // Delete a particular Cache Group. DeleteUrlCacheGroup(groupId, CACHEGROUP_FLAG_FLUSHURL_ONDELETE, IntPtr.Zero); more = FindNextUrlCacheGroup(enumHandle, ref groupId, IntPtr.Zero); } while (more); } // Start to delete URLs that do not belong to any group. int cacheEntryInfoBufferSizeInitial = 0; FindFirstUrlCacheEntry(null, IntPtr.Zero, ref cacheEntryInfoBufferSizeInitial); // should always fail because buffer is too small if (Marshal.GetLastWin32Error() == ERROR_INSUFFICIENT_BUFFER) { int cacheEntryInfoBufferSize = cacheEntryInfoBufferSizeInitial; IntPtr cacheEntryInfoBuffer = Marshal.AllocHGlobal(cacheEntryInfoBufferSize); enumHandle = FindFirstUrlCacheEntry(null, cacheEntryInfoBuffer, ref cacheEntryInfoBufferSizeInitial); if (enumHandle != IntPtr.Zero) { bool more; do { INTERNET_CACHE_ENTRY_INFOA internetCacheEntry = (INTERNET_CACHE_ENTRY_INFOA)Marshal.PtrToStructure(cacheEntryInfoBuffer, typeof(INTERNET_CACHE_ENTRY_INFOA)); cacheEntryInfoBufferSizeInitial = cacheEntryInfoBufferSize; DeleteUrlCacheEntry(internetCacheEntry.lpszSourceUrlName); more = FindNextUrlCacheEntry(enumHandle, cacheEntryInfoBuffer, ref cacheEntryInfoBufferSizeInitial); if (!more && Marshal.GetLastWin32Error() == ERROR_INSUFFICIENT_BUFFER) { cacheEntryInfoBufferSize = cacheEntryInfoBufferSizeInitial; cacheEntryInfoBuffer = Marshal.ReAllocHGlobal(cacheEntryInfoBuffer, (IntPtr)cacheEntryInfoBufferSize); more = FindNextUrlCacheEntry(enumHandle, cacheEntryInfoBuffer, ref cacheEntryInfoBufferSizeInitial); } } while (more); } Marshal.FreeHGlobal(cacheEntryInfoBuffer); } }
public static void DeleteUrlCache(string url) { // Pointer to a GROUPID variable long groupId = 0; // Local variables int cacheEntryInfoBufferSizeInitial = 0; int cacheEntryInfoBufferSize = 0; bool returnValue = false; IntPtr enumHandle = FindFirstUrlCacheGroup(0, CACHEGROUP_SEARCH_ALL, IntPtr.Zero, 0, ref groupId, IntPtr.Zero); //If there are no items in the Cache, you are finished. if ((!enumHandle.Equals(IntPtr.Zero) & ERROR_NO_MORE_ITEMS.Equals(Marshal.GetLastWin32Error()))) { return; } //Loop through Cache Group. enumHandle = FindFirstUrlCacheEntry("", IntPtr.Zero, ref cacheEntryInfoBufferSizeInitial); if ((!enumHandle.Equals(IntPtr.Zero) & ERROR_NO_MORE_ITEMS.Equals(Marshal.GetLastWin32Error()))) { return; } cacheEntryInfoBufferSize = cacheEntryInfoBufferSizeInitial; IntPtr cacheEntryInfoBuffer = Marshal.AllocHGlobal(cacheEntryInfoBufferSize); enumHandle = FindFirstUrlCacheEntry("", cacheEntryInfoBuffer, ref cacheEntryInfoBufferSizeInitial); while (true) { INTERNET_CACHE_ENTRY_INFOA internetCacheEntry = (INTERNET_CACHE_ENTRY_INFOA)Marshal.PtrToStructure(cacheEntryInfoBuffer, typeof(INTERNET_CACHE_ENTRY_INFOA)); cacheEntryInfoBufferSizeInitial = cacheEntryInfoBufferSize; string sourceUrlName = Marshal.PtrToStringAnsi(internetCacheEntry.lpszSourceUrlName); if (sourceUrlName == url) { returnValue = DeleteUrlCacheEntry(internetCacheEntry.lpszSourceUrlName); } returnValue = FindNextUrlCacheEntry(enumHandle, cacheEntryInfoBuffer, ref cacheEntryInfoBufferSizeInitial); if (!returnValue & Marshal.GetLastWin32Error() == ERROR_NO_MORE_ITEMS) { break; } if (!returnValue & cacheEntryInfoBufferSizeInitial > cacheEntryInfoBufferSize) { cacheEntryInfoBufferSize = cacheEntryInfoBufferSizeInitial; IntPtr tempIntPtr = new IntPtr(cacheEntryInfoBufferSize); cacheEntryInfoBuffer = Marshal.ReAllocHGlobal(cacheEntryInfoBuffer, tempIntPtr); returnValue = FindNextUrlCacheEntry(enumHandle, cacheEntryInfoBuffer, ref cacheEntryInfoBufferSizeInitial); } } Marshal.FreeHGlobal(cacheEntryInfoBuffer); }
// Methods public static void Purge() { Trace.WriteLine("CachePurger: Start"); long lpGroupId = 0L; int lpdwFirstCacheEntryInfoBufferSize = 0; IntPtr zero = IntPtr.Zero; IntPtr hFind = NativeMethods.FindFirstUrlCacheGroup(0, 0, IntPtr.Zero, 0, ref lpGroupId, IntPtr.Zero); if (!hFind.Equals(IntPtr.Zero) && Win32ErrorNoMoreItems()) { return; } do { NativeMethods.DeleteUrlCacheGroup(lpGroupId, 2, IntPtr.Zero); }while (NativeMethods.FindNextUrlCacheGroup(hFind, ref lpGroupId, IntPtr.Zero)); if (!NativeMethods.FindFirstUrlCacheEntry(null, IntPtr.Zero, ref lpdwFirstCacheEntryInfoBufferSize).Equals(IntPtr.Zero) && Win32ErrorNoMoreItems()) { return; } try { int cb = lpdwFirstCacheEntryInfoBufferSize; zero = Marshal.AllocHGlobal(cb); hFind = NativeMethods.FindFirstUrlCacheEntry(null, zero, ref lpdwFirstCacheEntryInfoBufferSize); while (true) { do { INTERNET_CACHE_ENTRY_INFOA internet_cache_entry_infoa = (INTERNET_CACHE_ENTRY_INFOA)Marshal.PtrToStructure(zero, typeof(INTERNET_CACHE_ENTRY_INFOA)); lpdwFirstCacheEntryInfoBufferSize = cb; NativeMethods.DeleteUrlCacheEntry(internet_cache_entry_infoa.lpszSourceUrlName); }while (NativeMethods.FindNextUrlCacheEntry(hFind, zero, ref lpdwFirstCacheEntryInfoBufferSize)); if (Win32ErrorNoMoreItems() || lpdwFirstCacheEntryInfoBufferSize.Equals(0)) { goto Label_0137; } if (lpdwFirstCacheEntryInfoBufferSize > cb) { cb = lpdwFirstCacheEntryInfoBufferSize; zero = Marshal.ReAllocHGlobal(zero, (IntPtr)cb); } NativeMethods.FindNextUrlCacheEntry(hFind, zero, ref lpdwFirstCacheEntryInfoBufferSize); } } finally { Marshal.FreeHGlobal(zero); } Label_0137: Trace.WriteLine("CachePurger: End"); }
internal static string GetCacheItemInfo(string sURL) { int lpdwCacheEntryInfoBufferSize = 0; int cb = 0; IntPtr zero = IntPtr.Zero; bool flag = GetUrlCacheEntryInfoA(sURL, zero, ref lpdwCacheEntryInfoBufferSize); int num = Marshal.GetLastWin32Error(); if (flag || (num != 0x7a)) { return(string.Format("This URL is not present in the WinINET cache. [Code: {0}]", num)); } cb = lpdwCacheEntryInfoBufferSize; zero = Marshal.AllocHGlobal(cb); flag = GetUrlCacheEntryInfoA(sURL, zero, ref lpdwCacheEntryInfoBufferSize); num = Marshal.GetLastWin32Error(); if (!flag) { Marshal.FreeHGlobal(zero); return("GetUrlCacheEntryInfoA with buffer failed. 2=filenotfound 122=insufficient buffer, 259=nomoreitems. Last error: " + num.ToString() + "\n"); } INTERNET_CACHE_ENTRY_INFOA internet_cache_entry_infoa = (INTERNET_CACHE_ENTRY_INFOA)Marshal.PtrToStructure(zero, typeof(INTERNET_CACHE_ENTRY_INFOA)); lpdwCacheEntryInfoBufferSize = cb; long fileTime = (internet_cache_entry_infoa.LastModifiedTime.dwHighDateTime << 0x20) | ((long)((ulong)internet_cache_entry_infoa.LastModifiedTime.dwLowDateTime)); long num5 = (internet_cache_entry_infoa.LastAccessTime.dwHighDateTime << 0x20) | ((long)((ulong)internet_cache_entry_infoa.LastAccessTime.dwLowDateTime)); long num6 = (internet_cache_entry_infoa.LastSyncTime.dwHighDateTime << 0x20) | ((long)((ulong)internet_cache_entry_infoa.LastSyncTime.dwLowDateTime)); long num7 = (internet_cache_entry_infoa.ExpireTime.dwHighDateTime << 0x20) | ((long)((ulong)internet_cache_entry_infoa.ExpireTime.dwLowDateTime)); string[] strArray = new string[] { "Url:\t\t", Marshal.PtrToStringAnsi(internet_cache_entry_infoa.lpszSourceUrlName), "\nCache File:\t", Marshal.PtrToStringAnsi(internet_cache_entry_infoa.lpszLocalFileName), "\nSize:\t\t", ((ulong)((internet_cache_entry_infoa.dwSizeHigh << 0x20) + internet_cache_entry_infoa.dwSizeLow)).ToString("0,0"), " bytes\nFile Extension:\t", Marshal.PtrToStringAnsi(internet_cache_entry_infoa.lpszFileExtension), "\nHit Rate:\t", internet_cache_entry_infoa.dwHitRate.ToString(), "\nUse Count:\t", internet_cache_entry_infoa.dwUseCount.ToString(), "\nDon't Scavenge for:\t", internet_cache_entry_infoa._Union.dwExemptDelta.ToString(), " seconds\nLast Modified:\t", DateTime.FromFileTime(fileTime).ToString(), "\nLast Accessed:\t", DateTime.FromFileTime(num5).ToString(), "\nLast Synced: \t", DateTime.FromFileTime(num6).ToString(), "\nEntry Expires:\t", DateTime.FromFileTime(num7).ToString(), "\n" }; string str = string.Concat(strArray); Marshal.FreeHGlobal(zero); return(str); }
public static void ClearCache() { bool flag; bool flag1; long num = (long)0; int num1 = 0; int num2 = 0; IntPtr zero = IntPtr.Zero; IntPtr intPtr = IntPtr.Zero; bool flag2 = false; intPtr = FindFirstUrlCacheGroup(0, 0, IntPtr.Zero, 0, ref num, IntPtr.Zero); if ((intPtr == IntPtr.Zero ? true : 259 != Marshal.GetLastWin32Error())) { while (true) { flag = true; if ((259 == Marshal.GetLastWin32Error() ? false : 2 != Marshal.GetLastWin32Error())) { flag2 = DeleteUrlCacheGroup(num, 2, IntPtr.Zero); if ((flag2 ? false : 2 == Marshal.GetLastWin32Error())) { flag2 = FindNextUrlCacheGroup(intPtr, ref num, IntPtr.Zero); } if (flag2) { flag1 = true; } else { flag1 = (259 == Marshal.GetLastWin32Error() ? false : 2 != Marshal.GetLastWin32Error()); } if (!flag1) { break; } } else { break; } } intPtr = FindFirstUrlCacheEntry(null, IntPtr.Zero, ref num1); if ((intPtr == IntPtr.Zero ? true : 259 != Marshal.GetLastWin32Error())) { num2 = num1; zero = Marshal.AllocHGlobal(num2); intPtr = FindFirstUrlCacheEntry(null, zero, ref num1); while (true) { flag = true; INTERNET_CACHE_ENTRY_INFOA structure = (INTERNET_CACHE_ENTRY_INFOA)Marshal.PtrToStructure(zero, typeof(INTERNET_CACHE_ENTRY_INFOA)); if (259 != Marshal.GetLastWin32Error()) { num1 = num2; flag2 = DeleteUrlCacheEntry(structure.lpszSourceUrlName); if (!flag2) { flag2 = FindNextUrlCacheEntry(intPtr, zero, ref num1); } if (!(flag2 ? true : 259 != Marshal.GetLastWin32Error())) { break; } else if ((flag2 ? false : num1 > num2)) { num2 = num1; zero = Marshal.ReAllocHGlobal(zero, (IntPtr)num2); flag2 = FindNextUrlCacheEntry(intPtr, zero, ref num1); } } else { break; } } Marshal.FreeHGlobal(zero); } } }
public static void ClearCacheItems(bool bClearFiles, bool bClearCookies) { if (!bClearCookies && !bClearFiles) { throw new ArgumentException("You must call ClearCacheItems with at least one target"); } if (Environment.OSVersion.Version.Major > 5) { VistaClearTracks(bClearFiles, bClearCookies); } else { if (bClearCookies) { ClearCookiesForHost("*"); } if (bClearFiles) { long lpGroupId = 0L; int lpdwFirstCacheEntryInfoBufferSize = 0; int cb = 0; IntPtr zero = IntPtr.Zero; IntPtr hFind = IntPtr.Zero; bool flag = false; hFind = FindFirstUrlCacheGroup(0, 0, IntPtr.Zero, 0, ref lpGroupId, IntPtr.Zero); int num4 = Marshal.GetLastWin32Error(); if (((hFind != IntPtr.Zero) && (0x103 != num4)) && (2 != num4)) { do { flag = DeleteUrlCacheGroup(lpGroupId, 2, IntPtr.Zero); num4 = Marshal.GetLastWin32Error(); if (!flag && (2 == num4)) { flag = FindNextUrlCacheGroup(hFind, ref lpGroupId, IntPtr.Zero); num4 = Marshal.GetLastWin32Error(); } }while (flag || ((0x103 != num4) && (2 != num4))); } hFind = FindFirstUrlCacheEntryEx(null, 0, WININETCACHEENTRYTYPE.ALL, 0L, IntPtr.Zero, ref lpdwFirstCacheEntryInfoBufferSize, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); num4 = Marshal.GetLastWin32Error(); if ((IntPtr.Zero != hFind) || (0x103 != num4)) { cb = lpdwFirstCacheEntryInfoBufferSize; zero = Marshal.AllocHGlobal(cb); hFind = FindFirstUrlCacheEntryEx(null, 0, WININETCACHEENTRYTYPE.ALL, 0L, zero, ref lpdwFirstCacheEntryInfoBufferSize, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); num4 = Marshal.GetLastWin32Error(); do { INTERNET_CACHE_ENTRY_INFOA internet_cache_entry_infoa = (INTERNET_CACHE_ENTRY_INFOA)Marshal.PtrToStructure(zero, typeof(INTERNET_CACHE_ENTRY_INFOA)); lpdwFirstCacheEntryInfoBufferSize = cb; if (WININETCACHEENTRYTYPE.COOKIE_CACHE_ENTRY != (internet_cache_entry_infoa.CacheEntryType & WININETCACHEENTRYTYPE.COOKIE_CACHE_ENTRY)) { flag = DeleteUrlCacheEntry(internet_cache_entry_infoa.lpszSourceUrlName); } flag = FindNextUrlCacheEntryEx(hFind, zero, ref lpdwFirstCacheEntryInfoBufferSize, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); num4 = Marshal.GetLastWin32Error(); if (!flag && (0x103 == num4)) { break; } if (!flag && (lpdwFirstCacheEntryInfoBufferSize > cb)) { cb = lpdwFirstCacheEntryInfoBufferSize; zero = Marshal.ReAllocHGlobal(zero, (IntPtr)cb); flag = FindNextUrlCacheEntryEx(hFind, zero, ref lpdwFirstCacheEntryInfoBufferSize, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); } }while (flag); Marshal.FreeHGlobal(zero); } } } }
public static Dictionary <string, IeHistoryEntry> GetURLCache() { // Pointer to a GROUPID variable. long groupId = 0; // Local variables. int cacheEntryInfoBufferSizeInitial = 0; int cacheEntryInfoBufferSize = 0; bool returnValue = false; IntPtr enumHandle = FindFirstUrlCacheGroup(0, CACHEGROUP_SEARCH_ALL, IntPtr.Zero, 0, ref groupId, IntPtr.Zero); //If there are no items in the Cache, you are finished. if ((!enumHandle.Equals(IntPtr.Zero) & ERROR_NO_MORE_ITEMS.Equals(Marshal.GetLastWin32Error()))) { return(null); } //Loop through Cache Group. enumHandle = FindFirstUrlCacheEntry(null, IntPtr.Zero, ref cacheEntryInfoBufferSizeInitial); if ((!enumHandle.Equals(IntPtr.Zero) & ERROR_NO_MORE_ITEMS.Equals(Marshal.GetLastWin32Error()))) { return(null); } cacheEntryInfoBufferSize = cacheEntryInfoBufferSizeInitial; IntPtr cacheEntryInfoBuffer = Marshal.AllocHGlobal(cacheEntryInfoBufferSize); enumHandle = FindFirstUrlCacheEntry(null, cacheEntryInfoBuffer, ref cacheEntryInfoBufferSizeInitial); Dictionary <string, IeHistoryEntry> list = new Dictionary <string, IeHistoryEntry>(); while (true) { INTERNET_CACHE_ENTRY_INFOA internetCacheEntry = (INTERNET_CACHE_ENTRY_INFOA)Marshal.PtrToStructure(cacheEntryInfoBuffer, typeof(INTERNET_CACHE_ENTRY_INFOA)); cacheEntryInfoBufferSizeInitial = cacheEntryInfoBufferSize; IeHistoryEntry entry = new IeHistoryEntry(); entry.SourceUrlName = Marshal.PtrToStringAnsi(internetCacheEntry.lpszSourceUrlName); entry.LastAccessDate = FileTime2SystemTime(ref internetCacheEntry.LastAccessTime).ToString(); entry.Type = (EntryType)Enum.Parse(typeof(EntryType), internetCacheEntry.CacheEntryType.ToString()); entry.Url = Marshal.PtrToStringAnsi(internetCacheEntry.lpszLocalFileName); entry.Extension = Marshal.PtrToStringAnsi(internetCacheEntry.lpszFileExtension); entry.HeaderInfo = Marshal.PtrToStringAnsi(internetCacheEntry.lpHeaderInfo); entry.HitRate = internetCacheEntry.dwHitRate.ToString(); entry.LastModifiedTime = FileTime2SystemTime(ref internetCacheEntry.LastModifiedTime).ToString(); entry.LastSyncTime = FileTime2SystemTime(ref internetCacheEntry.LastSyncTime).ToString(); entry.UseCount = internetCacheEntry.dwUseCount.ToString(); string url = entry.SourceUrlName; int position = url.IndexOf("@"); if (position != -1) { url = url.Substring(position + 1); } if (!list.ContainsKey(url)) { list.Add(url, entry); } returnValue = FindNextUrlCacheEntry(enumHandle, cacheEntryInfoBuffer, ref cacheEntryInfoBufferSizeInitial); if (!returnValue & ERROR_NO_MORE_ITEMS.Equals(Marshal.GetLastWin32Error())) { break; } if (!returnValue & cacheEntryInfoBufferSizeInitial > cacheEntryInfoBufferSize) { cacheEntryInfoBufferSize = cacheEntryInfoBufferSizeInitial; IntPtr tempIntPtr = new IntPtr(cacheEntryInfoBufferSize); cacheEntryInfoBuffer = Marshal.ReAllocHGlobal(cacheEntryInfoBuffer, tempIntPtr); returnValue = FindNextUrlCacheEntry(enumHandle, cacheEntryInfoBuffer, ref cacheEntryInfoBufferSizeInitial); } } Marshal.FreeHGlobal(cacheEntryInfoBuffer); return(list); }
public static void ClearCache(bool includeCookies) { if (Environment.OSVersion.Version.Major > 5) { InetCplClearTracks(true, includeCookies); } else { if (includeCookies) { ClearCookies("*"); } long lpGroupId = 0L; int num1 = 0; IntPtr num2 = IntPtr.Zero; IntPtr num3 = IntPtr.Zero; bool flag1 = false; IntPtr firstUrlCacheGroup = FindFirstUrlCacheGroup(0, 0, IntPtr.Zero, 0, ref lpGroupId, IntPtr.Zero); int lastWin32Error1 = Marshal.GetLastWin32Error(); if (firstUrlCacheGroup != IntPtr.Zero && 259 != lastWin32Error1 && 2 != lastWin32Error1) { bool flag2; int lastWin32Error2; do { flag2 = DeleteUrlCacheGroup(lpGroupId, 2, IntPtr.Zero); lastWin32Error2 = Marshal.GetLastWin32Error(); if (!flag2 && 2 == lastWin32Error2) { flag2 = FindNextUrlCacheGroup(firstUrlCacheGroup, ref lpGroupId, IntPtr.Zero); lastWin32Error2 = Marshal.GetLastWin32Error(); } }while (flag2 || 259 != lastWin32Error2 && 2 != lastWin32Error2); } IntPtr firstUrlCacheEntryEx1 = FindFirstUrlCacheEntryEx((string)null, 0, WININETCACHEENTRYTYPE.ALL, 0L, IntPtr.Zero, ref num1, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); int lastWin32Error3 = Marshal.GetLastWin32Error(); if (IntPtr.Zero == firstUrlCacheEntryEx1 && 259 == lastWin32Error3) { return; } int cb = num1; IntPtr num4 = Marshal.AllocHGlobal(cb); IntPtr firstUrlCacheEntryEx2 = FindFirstUrlCacheEntryEx((string)null, 0, WININETCACHEENTRYTYPE.ALL, 0L, num4, ref num1, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); Marshal.GetLastWin32Error(); bool nextUrlCacheEntryEx; do { INTERNET_CACHE_ENTRY_INFOA internetCacheEntryInfoa = (INTERNET_CACHE_ENTRY_INFOA)Marshal.PtrToStructure(num4, typeof(INTERNET_CACHE_ENTRY_INFOA)); num1 = cb; if (WININETCACHEENTRYTYPE.COOKIE_CACHE_ENTRY != (internetCacheEntryInfoa.CacheEntryType & WININETCACHEENTRYTYPE.COOKIE_CACHE_ENTRY)) { flag1 = DeleteUrlCacheEntry(internetCacheEntryInfoa.lpszSourceUrlName); } nextUrlCacheEntryEx = FindNextUrlCacheEntryEx(firstUrlCacheEntryEx2, num4, ref num1, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); int lastWin32Error2 = Marshal.GetLastWin32Error(); if (nextUrlCacheEntryEx || 259 != lastWin32Error2) { if (!nextUrlCacheEntryEx && num1 > cb) { cb = num1; num4 = Marshal.ReAllocHGlobal(num4, (IntPtr)cb); nextUrlCacheEntryEx = FindNextUrlCacheEntryEx(firstUrlCacheEntryEx2, num4, ref num1, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); } } else { break; } }while (nextUrlCacheEntryEx); Marshal.FreeHGlobal(num4); } }
/// <summary> /// Delete all permanent WinINET cookies for host; won't clear memory-only session cookies. /// Supports hostnames with an optional leading wildcard, e.g. *example.com. /// NOTE: Will not work on VistaIE Protected Mode cookies. /// </summary> /// <param name="host">The hostname whose cookies should be cleared</param> public static void ClearCookies(string host) { host = host.Trim(); if (host.Length < 1) { return; } string str1; if (host == "*") { str1 = string.Empty; if (Environment.OSVersion.Version.Major > 5) { InetCplClearTracks(false, true); return; } } else { str1 = host.StartsWith("*") ? host.Substring(1).ToLower() : "@" + host.ToLower(); } int num1 = 0; IntPtr num2 = IntPtr.Zero; IntPtr num3 = IntPtr.Zero; if (FindFirstUrlCacheEntry("cookie:", IntPtr.Zero, ref num1) == IntPtr.Zero && 259 == Marshal.GetLastWin32Error()) { return; } int cb = num1; IntPtr num4 = Marshal.AllocHGlobal(cb); IntPtr firstUrlCacheEntry = FindFirstUrlCacheEntry("cookie:", num4, ref num1); label_8: INTERNET_CACHE_ENTRY_INFOA internetCacheEntryInfoa = (INTERNET_CACHE_ENTRY_INFOA)Marshal.PtrToStructure(num4, typeof(INTERNET_CACHE_ENTRY_INFOA)); num1 = cb; if (WININETCACHEENTRYTYPE.COOKIE_CACHE_ENTRY == (internetCacheEntryInfoa.CacheEntryType & WININETCACHEENTRYTYPE.COOKIE_CACHE_ENTRY)) { bool flag; if (str1.Length == 0) { flag = true; } else { string str2 = Marshal.PtrToStringAnsi(internetCacheEntryInfoa.lpszSourceUrlName); int startIndex = str2.IndexOf('/'); if (startIndex > 0) { str2 = str2.Remove(startIndex); } flag = str2.ToLower().EndsWith(str1); } if (flag) { DeleteUrlCacheEntry(internetCacheEntryInfoa.lpszSourceUrlName); } } while (true) { bool nextUrlCacheEntry = FindNextUrlCacheEntry(firstUrlCacheEntry, num4, ref num1); if (nextUrlCacheEntry || 259 != Marshal.GetLastWin32Error()) { if (!nextUrlCacheEntry && num1 > cb) { cb = num1; num4 = Marshal.ReAllocHGlobal(num4, (IntPtr)cb); } else { goto label_8; } } else { break; } } Marshal.FreeHGlobal(num4); }