internal static string GetCacheItemInfo(string sURL) { int num = 0; IntPtr intPtr = IntPtr.Zero; bool urlCacheEntryInfoA = WinINETCache.GetUrlCacheEntryInfoA(sURL, intPtr, ref num); int lastWin32Error = Marshal.GetLastWin32Error(); if (!urlCacheEntryInfoA) { if (lastWin32Error == 122) { int num2 = num; intPtr = Marshal.AllocHGlobal(num2); urlCacheEntryInfoA = WinINETCache.GetUrlCacheEntryInfoA(sURL, intPtr, ref num); lastWin32Error = Marshal.GetLastWin32Error(); if (!urlCacheEntryInfoA) { Marshal.FreeHGlobal(intPtr); return("GetUrlCacheEntryInfoA with buffer failed. 2=filenotfound 122=insufficient buffer, 259=nomoreitems. Last error: " + lastWin32Error.ToString() + "\n"); } WinINETCache.INTERNET_CACHE_ENTRY_INFOA iNTERNET_CACHE_ENTRY_INFOA = (WinINETCache.INTERNET_CACHE_ENTRY_INFOA)Marshal.PtrToStructure(intPtr, typeof(WinINETCache.INTERNET_CACHE_ENTRY_INFOA)); num = num2; long fileTime = (long)iNTERNET_CACHE_ENTRY_INFOA.LastModifiedTime.dwHighDateTime << 32 | (long)((ulong)iNTERNET_CACHE_ENTRY_INFOA.LastModifiedTime.dwLowDateTime); long fileTime2 = (long)iNTERNET_CACHE_ENTRY_INFOA.LastAccessTime.dwHighDateTime << 32 | (long)((ulong)iNTERNET_CACHE_ENTRY_INFOA.LastAccessTime.dwLowDateTime); long fileTime3 = (long)iNTERNET_CACHE_ENTRY_INFOA.LastSyncTime.dwHighDateTime << 32 | (long)((ulong)iNTERNET_CACHE_ENTRY_INFOA.LastSyncTime.dwLowDateTime); long fileTime4 = (long)iNTERNET_CACHE_ENTRY_INFOA.ExpireTime.dwHighDateTime << 32 | (long)((ulong)iNTERNET_CACHE_ENTRY_INFOA.ExpireTime.dwLowDateTime); string result = string.Concat(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 << 32) + (ulong)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(fileTime2).ToString(), "\nLast Synced: \t", DateTime.FromFileTime(fileTime3).ToString(), "\nEntry Expires:\t", DateTime.FromFileTime(fileTime4).ToString(), "\n" }); Marshal.FreeHGlobal(intPtr); return(result); } } return(string.Format("This URL is not present in the WinINET cache. [Code: {0}]", lastWin32Error)); }
private void RefreshInfo() { try { this.Text = string.Concat(new object[] { "Session Properties (", this.mySession.id, ") ", this.mySession.url }); this.txtProperties.Clear(); this.txtProperties.AppendText(string.Format("SESSION STATE: {0}.\n", this.mySession.state.ToString("g"))); if (this.mySession.state == SessionStates.ReadingResponse) { long num; this.txtProperties.AppendText(string.Format("DOWNLOAD PROGRESS: {0:N0}", this.mySession.oResponse._PeekDownloadProgress)); if ((this.mySession.oResponse["Content-Length"] != string.Empty) && long.TryParse(this.mySession.oResponse["Content-Length"], NumberStyles.Integer, NumberFormatInfo.InvariantInfo, out num)) { this.txtProperties.AppendText(string.Format(" of {0:N0}", num)); } this.txtProperties.AppendText(" bytes.\n\n"); } if ((this.mySession.state >= SessionStates.SendingRequest) && this.mySession.isFlagSet(SessionFlags.SentToGateway)) { this.txtProperties.AppendText("The request was forwarded to the gateway.\n"); } if ((this.mySession.requestBodyBytes != null) && (this.mySession.requestBodyBytes.Length > 0)) { this.txtProperties.AppendText(string.Format("Request Entity Size: {0:N0} bytes.\n", this.mySession.requestBodyBytes.LongLength.ToString())); } if (this.mySession.responseBodyBytes != null) { this.txtProperties.AppendText(string.Format("Response Entity Size: {0:N0} bytes.\n", this.mySession.responseBodyBytes.LongLength.ToString())); } this.txtProperties.AppendText("\n== FLAGS ==================\n"); this.txtProperties.AppendText(string.Format("BitFlags: [{0}] 0x{1}\n", this.mySession.BitFlags, ((int)this.mySession.BitFlags).ToString("x"))); foreach (DictionaryEntry entry in this.mySession.oFlags) { this.txtProperties.AppendText(string.Format("{0}: {1}\n", (entry.Key as string).ToUpper(), entry.Value as string)); } this.txtProperties.AppendText("\n== TIMING INFO ============\n"); this.txtProperties.AppendText(this.mySession.Timers.ToString(true)); if (this.mySession.state >= SessionStates.ReadingResponse) { this.txtProperties.AppendText(this.mySession.isFlagSet(SessionFlags.ResponseStreamed) ? "\nThe response was streamed to the client as it was received.\n" : "\nThe response was buffered before delivery to the client.\n"); } this.txtProperties.AppendText("\n== WININET CACHE INFO ============\n"); this.txtProperties.AppendText(WinINETCache.GetCacheItemInfo(this.mySession.fullUrl)); this.txtProperties.AppendText("\n* Note: Data above shows WinINET's current cache state, not the state at the time of the request.\n"); if (Environment.OSVersion.Version.Major > 5) { this.txtProperties.AppendText("* Note: Data above shows WinINET's Medium Integrity (non-Protected Mode) cache only.\n"); } this.txtProperties.AppendText("\n"); this.txtProperties.Select(0, 0); } catch (Exception exception) { this.txtProperties.Clear(); this.txtProperties.AppendText(exception.Message + "\r\n" + exception.StackTrace); } }
public static void ClearCacheItems(bool bClearFiles, bool bClearCookies) { if (!bClearCookies && !bClearFiles) { throw new ArgumentException("You must call ClearCacheItems with at least one target"); } if (!FiddlerApplication.DoClearCache(bClearFiles, bClearCookies)) { FiddlerApplication.Log.LogString("Cache clearing was handled by an extension. Default clearing was skipped."); return; } if (Environment.OSVersion.Version.Major > 5) { FiddlerApplication.Log.LogString(string.Format("Windows Vista+ detected. Calling INETCPL to clear [{0}{1}].", bClearFiles ? "CacheFiles" : string.Empty, bClearCookies ? "Cookies" : string.Empty)); WinINETCache.VistaClearTracks(bClearFiles, bClearCookies); return; } if (bClearCookies) { WinINETCache.ClearCookiesForHost("*"); } if (!bClearFiles) { return; } FiddlerApplication.Log.LogString("Beginning WinINET Cache clearing..."); long groupId = 0L; int num = 0; IntPtr intPtr = IntPtr.Zero; IntPtr intPtr2 = IntPtr.Zero; intPtr2 = WinINETCache.FindFirstUrlCacheGroup(0, 0, IntPtr.Zero, 0, ref groupId, IntPtr.Zero); int lastWin32Error = Marshal.GetLastWin32Error(); bool flag; if (intPtr2 != IntPtr.Zero && 259 != lastWin32Error && 2 != lastWin32Error) { while (true) { flag = WinINETCache.DeleteUrlCacheGroup(groupId, 2, IntPtr.Zero); lastWin32Error = Marshal.GetLastWin32Error(); if (!flag && 2 == lastWin32Error) { flag = WinINETCache.FindNextUrlCacheGroup(intPtr2, ref groupId, IntPtr.Zero); lastWin32Error = Marshal.GetLastWin32Error(); } if (!flag) { if (259 == lastWin32Error) { break; } if (2 == lastWin32Error) { break; } } } } intPtr2 = WinINETCache.FindFirstUrlCacheEntryExA(null, 0, WinINETCache.WININETCACHEENTRYTYPE.ALL, 0L, IntPtr.Zero, ref num, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); lastWin32Error = Marshal.GetLastWin32Error(); if (IntPtr.Zero == intPtr2 && 259 == lastWin32Error) { return; } int num2 = num; intPtr = Marshal.AllocHGlobal(num2); intPtr2 = WinINETCache.FindFirstUrlCacheEntryExA(null, 0, WinINETCache.WININETCACHEENTRYTYPE.ALL, 0L, intPtr, ref num, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); lastWin32Error = Marshal.GetLastWin32Error(); do { WinINETCache.INTERNET_CACHE_ENTRY_INFOA iNTERNET_CACHE_ENTRY_INFOA = (WinINETCache.INTERNET_CACHE_ENTRY_INFOA)Marshal.PtrToStructure(intPtr, typeof(WinINETCache.INTERNET_CACHE_ENTRY_INFOA)); num = num2; if (WinINETCache.WININETCACHEENTRYTYPE.COOKIE_CACHE_ENTRY != (iNTERNET_CACHE_ENTRY_INFOA.CacheEntryType & WinINETCache.WININETCACHEENTRYTYPE.COOKIE_CACHE_ENTRY)) { flag = WinINETCache.DeleteUrlCacheEntryA(iNTERNET_CACHE_ENTRY_INFOA.lpszSourceUrlName); } flag = WinINETCache.FindNextUrlCacheEntryExA(intPtr2, intPtr, ref num, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); lastWin32Error = Marshal.GetLastWin32Error(); if (!flag && 259 == lastWin32Error) { break; } if (!flag && num > num2) { num2 = num; intPtr = Marshal.ReAllocHGlobal(intPtr, (IntPtr)num2); flag = WinINETCache.FindNextUrlCacheEntryExA(intPtr2, intPtr, ref num, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero); } }while (flag); Marshal.FreeHGlobal(intPtr); FiddlerApplication.Log.LogString("Completed WinINET Cache clearing."); }
public static void ClearCookiesForHost(string sHost) { sHost = sHost.Trim(); if (sHost.Length < 1) { return; } string text; if (sHost == "*") { text = string.Empty; if (Environment.OSVersion.Version.Major > 5) { WinINETCache.VistaClearTracks(false, true); return; } } else { text = (sHost.StartsWith("*") ? sHost.Substring(1).ToLower() : ("@" + sHost.ToLower())); } int num = 0; IntPtr intPtr = IntPtr.Zero; IntPtr intPtr2 = IntPtr.Zero; intPtr2 = WinINETCache.FindFirstUrlCacheEntryA("cookie:", IntPtr.Zero, ref num); if (intPtr2 == IntPtr.Zero && 259 == Marshal.GetLastWin32Error()) { return; } int num2 = num; intPtr = Marshal.AllocHGlobal(num2); intPtr2 = WinINETCache.FindFirstUrlCacheEntryA("cookie:", intPtr, ref num); while (true) { WinINETCache.INTERNET_CACHE_ENTRY_INFOA iNTERNET_CACHE_ENTRY_INFOA = (WinINETCache.INTERNET_CACHE_ENTRY_INFOA)Marshal.PtrToStructure(intPtr, typeof(WinINETCache.INTERNET_CACHE_ENTRY_INFOA)); num = num2; if (WinINETCache.WININETCACHEENTRYTYPE.COOKIE_CACHE_ENTRY == (iNTERNET_CACHE_ENTRY_INFOA.CacheEntryType & WinINETCache.WININETCACHEENTRYTYPE.COOKIE_CACHE_ENTRY)) { bool flag; if (text.Length == 0) { flag = true; } else { string text2 = Marshal.PtrToStringAnsi(iNTERNET_CACHE_ENTRY_INFOA.lpszSourceUrlName); int num3 = text2.IndexOf('/'); if (num3 > 0) { text2 = text2.Remove(num3); } text2 = text2.ToLower(); flag = text2.EndsWith(text); } if (flag) { bool flag2 = WinINETCache.DeleteUrlCacheEntryA(iNTERNET_CACHE_ENTRY_INFOA.lpszSourceUrlName); } } while (true) { bool flag2; if (!(flag2 = WinINETCache.FindNextUrlCacheEntryA(intPtr2, intPtr, ref num))) { if (259 == Marshal.GetLastWin32Error()) { goto IL_19E; } } if (flag2 || num <= num2) { break; } num2 = num; intPtr = Marshal.ReAllocHGlobal(intPtr, (IntPtr)num2); } } IL_19E: Marshal.FreeHGlobal(intPtr); }
public static void ClearFiles() { WinINETCache.ClearCacheItems(true, false); }
public static void ClearCookies() { WinINETCache.ClearCacheItems(false, true); }