C# 读取IE缓存文件(2)
private void button1_Click(object sender, EventArgs e) { int nNeeded = 0, nBufSize; IntPtr buf; INTERNET_CACHE_ENTRY_INFO CacheItem; IntPtr hEnum; bool r; FindFirstUrlCacheEntry(null, IntPtr.Zero, ref nNeeded); if (Marshal.GetLastWin32Error() == ERROR_NO_MORE_ITEMS) return; nBufSize = nNeeded; buf = Marshal.AllocHGlobal(nBufSize); hEnum = FindFirstUrlCacheEntry(null, buf, ref nNeeded); var sb = new StringBuilder(); while (true) { CacheItem = (INTERNET_CACHE_ENTRY_INFO) Marshal.PtrToStructure(buf,typeof (INTERNET_CACHE_ENTRY_INFO)); string url = Marshal.PtrToStringAuto(CacheItem.lpszSourceUrlName); if (url.Contains("mp.weixin.qq.com/misc/getheadimg")) { string modifiedTime = FILETIMEtoDataTime(CacheItem.LastModifiedTime); string expireTime = FILETIMEtoDataTime(CacheItem.ExpireTime); string accessTime = FILETIMEtoDataTime(CacheItem.LastAccessTime); string syncTime = FILETIMEtoDataTime(CacheItem.LastSyncTime); var LocalFileName = Marshal.PtrToStringAuto(CacheItem.lpszLocalFileName); sb.AppendFormat("\r\nUrl {0}", url); sb.AppendFormat("\r\n本地路径{0}",LocalFileName); if (!File.Exists(LocalFileName)) { sb.AppendFormat("\r\n本地路径不存在!!!"); } else { sb.AppendFormat("\r\nmodifiedTime {0}", modifiedTime); sb.AppendFormat("\r\n expireTime {0}", expireTime); sb.AppendFormat("\r\n accessTime {0}",accessTime ); sb.AppendFormat("\r\n syncTime {0}", syncTime); var id = Util.GetMatchValue(url, @"fakeid\=(\d+)"); var path = @"c:\1\" + id + ".jpg"; if (!File.Exists(path)) { File.Copy(LocalFileName, path); } } // pictureBox1.Image = GetThumbnail(LocalFileName); //if (s.Contains(textBox1.Text)) //{ //} } nNeeded = nBufSize; r = FindNextUrlCacheEntry(hEnum, buf, ref nNeeded); if (!r && Marshal.GetLastWin32Error() == ERROR_NO_MORE_ITEMS) break; if (!r && nNeeded > nBufSize) { nBufSize = nNeeded; buf = Marshal.ReAllocHGlobal(buf, (IntPtr) nBufSize); FindNextUrlCacheEntry(hEnum, buf, ref nNeeded); } } Util.Log(sb); MessageBox.Show("系统数据加载完毕!"); Marshal.FreeHGlobal(buf); } #region MyRegion #region 引入dll [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct INTERNET_CACHE_ENTRY_INFO { public int dwStructSize; public IntPtr lpszSourceUrlName; public IntPtr lpszLocalFileName; public int CacheEntryType; public int dwUseCount; public int dwHitRate; public int dwSizeLow; public int dwSizeHigh; public FILETIME LastModifiedTime; public FILETIME ExpireTime; public FILETIME LastAccessTime; public FILETIME LastSyncTime; public IntPtr lpHeaderInfo; public int dwHeaderInfoSize; public IntPtr lpszFileExtension; public int dwExemptDelta; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)] public struct SYSTEMTIME { public short wYear; public short wMonth; public short wDayOfWeek; public short wDay; public short wHour; public short wMinute; public short wSecond; public short wMilliseconds; } [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern int FileTimeToSystemTime(IntPtr lpFileTime,IntPtr lpSystemTime); [DllImport("wininet.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern IntPtr FindFirstUrlCacheEntry([MarshalAs(UnmanagedType.LPTStr)] string lpszUrlSearchPattern,IntPtr lpFirstCacheEntryInfo,ref int lpdwFirstCacheEntryInfoBufferSize); [DllImport("wininet.dll", SetLastError = true, CharSet = CharSet.Auto)] public static extern bool FindNextUrlCacheEntry(IntPtr hEnumHandle,IntPtr lpNextCacheEntryInfo,ref int lpdwNextCacheEntryInfoBufferSize); [DllImport("wininet.dll")] public static extern bool FindCloseUrlCache( IntPtr hEnumHandle); const int ERROR_NO_MORE_ITEMS = 259; #endregion #region FileTimeToSystemTime private string FILETIMEtoDataTime(FILETIME time) { IntPtr filetime = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(FILETIME))); IntPtr systime = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(SYSTEMTIME))); Marshal.StructureToPtr(time, filetime, true); FileTimeToSystemTime(filetime, systime); SYSTEMTIME st = (SYSTEMTIME)Marshal.PtrToStructure(systime, typeof(SYSTEMTIME)); string Time = st.wYear+"-" + st.wMonth+"-" + st.wDay+" " + st.wHour+":" + st.wMinute+":" + st.wSecond; return Time; } #endregion #endregion
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
2013-12-15 win7开机直接进入系统系统桌面