C# 读取IE缓存文件(2)
private void button1_Click(object sender, EventArgs e)
{
int nNeeded = , 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 = ; #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
C# 读取IE缓存文件(2)的更多相关文章
- php实现数据库数据读取生成缓存文件
有些时候我们希望减少对数据库的 查询来提高程序的性能,因为这些数据不是经常变更的,而是会在很长一段时间内都不会变化,因此,我们每连接一次数据库,都会把相应的结果用文件的形式保存 起来.比如对于一个商城 ...
- 读取IE缓存文件
使用WebCacheTool项目中的WinInetAPI.cs和Win32API.cs两个类 /// <summary> /// 获取IE缓存文件 /// </summary> ...
- C# 读取IE缓存文件(1)
using System; using System.Runtime.InteropServices; namespace Common { public class IECache { [DllIm ...
- Python3实现从文件中读取指定行的方法
from:http://www.jb51.net/article/66580.htm 这篇文章主要介绍了Python3实现从文件中读取指定行的方法,涉及Python中linecache模块操作文件的使 ...
- CVE-2017-7529-Nginx越界读取缓存漏洞
漏洞参考 https://blog.csdn.net/qq_29647709/article/details/85076309 漏洞原因 Nginx在反向代理站点的时候,通常会将一些文件进行缓存,特别 ...
- 深入探究ASP.NET Core读取Request.Body的正确方式
前言 相信大家在使用ASP.NET Core进行开发的时候,肯定会涉及到读取Request.Body的场景,毕竟我们大部分的POST请求都是将数据存放到Http的Body当中.因为笔者日常开发所使用的 ...
- Nginx越界读取缓存漏洞 CVE-2017-7529
1.漏洞描述 Nginx在反向代理站点的时候,通常会将一些文件进行缓存,特别是静态文件.缓存的部分存储在文件中,每个缓存文件包括"文件头"+"HTTP返回包头" ...
- VS调试经常打断点打上之后没反应的问题
在调试的时候经常会发现打了断点但是始终不进到程序中来,这是因为访问的这个页面在服务器中有缓存,也就是在iis中产生了缓存.访问的时候直接进到读取的缓存文件, 根本没有读取项目文件,所以打了断点肯定进不 ...
- ThinkPHP2.2框架执行流程图,ThinkPHP控制器的执行流程
ThinkPHP2.2框架执行原理.流程图在线手册 ThinkPHP控制器的执行流程 对用户的第一次URL访问 http://<serverIp>/My/index.php/Index/s ...
随机推荐
- Axure RP 实践.1
工作需要设计产品原型,找来Axure RP帮忙,看了一些文章,其中下面这段话深得我心. “只使用Axure的默认控件(Wireframe),不要用那些样式花哨的自定义控件,并且所有页面中使用的颜色不能 ...
- xcode project
An Xcode project is a repository for all the files, resources, and information required to build one ...
- SE 2014年4月8日
1.路由引入的作用? 当网络中运行多种路由协议的时候,由于不同协议的路由算法和度量值等均不相同,路由引入可以将不同协议的路由引入到当前的路由协议中,保证网络的互通. 对比单向入和双向入 单向引入是只将 ...
- UVA12304 2D Geometry 110 in 1! 计算几何
计算几何: 堆几何模版就能够了. . .. Description Problem E 2D Geometry 110 in 1! This is a collection of 110 (in bi ...
- Effective C++:条款38:通过一个复杂的模具has-a要么“基于一些实现”
(一) public继承是"is-a"关联,"has-a"或"依据某物实现出(is-implemented-in-terms-of)"的意思 ...
- JAVA的class打包成dll
一.将已经编译后的java中Class文件进行打包:打包命令JAR 如:将某目录下的所有class文件夹全部进行打包处理: 使用的命令:jar cvf test.jar -C com/ . //注意这 ...
- Mysql加入用户时的错误问题
比如:加入用户 insert into mysql.user(Host,User,Password) values("localhost","test",pas ...
- 《JavaScript设计模式与开发实践》读书笔记之中介者模式
1. 中介者模式 中介者模式的作用就是用来解除对象与对象之间的紧耦合关系,增加中介者后,所有相关对象都通过中介者来通信,而不再相互引用 1.1中介者模式的例子 以泡泡堂游戏为例,先定义一个玩家构造函数 ...
- SQL Server :理解数据页结构
原文:SQL Server :理解数据页结构 我们都很清楚SQL Server用8KB 的页来存储数据,并且在SQL Server里磁盘 I/O 操作在页级执行.也就是说,SQL Server 读取或 ...
- gopkg:一种方便的go pakcage管理方式
在使用go的过程中,我们有时候会引入一些第三方库来使用,而通常的方式就是使用go get,可是这样的方式有一个非常严重的问题,假设第三方库更新了相关接口,非常有可能你就无法使用了,所以我们一套非常好地 ...