예제 #1
0
        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));
        }
예제 #2
0
        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.");
        }
예제 #3
0
        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);
        }