Get the IE temporary file with C #

zhaozj2021-02-16  49

Everyone knows that when we visit a website. The system will all cache pictures, animations, etc. on this website to the Internet Temporary folder. We can access it via : / Documents and Settings / / local settings / temptory Internet files. But maybe we have never thought that the files inside are actually different from other folders and documents in our system.

For example, we write a function under VS.NET to return a folder in the specified folder and all files, but when we pass the Internet temporary folder, the system will only return a file, which is Desktop. INI (every folder is available), there is a hidden folder. So this demonstrates that the file in the temporary folder is not existing in terms of ordinary folders and files.

In fact, Windows is in a hidden folder in all hidden files. This folder is not seen, then relying on an index.dat index to read all the content and return to the user.

Then how do we use the program to read the content? Because these days have completed his graduation design in the past few days, it studied. The first thing to reference a user.dll in the system folder. Then use some of its functions to traverse the entire folder and get information for each file.

[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);

Introduce the above three functions to traverse the temporary folder, then reference

[DLLIMPORT ("kernel32.dll", setlasterror = true, charset = charset.auto)] public static extern int filetimetosystemTIME (INTPTR LPFILETIME, INTPTR LPSYSTEMTIME);

Used to convert the FileTime time format into string type in C # so that we will further operate.

The main program is as follows:

#Region introduces a 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 wmonth; public short wdayofweek; public short wha; 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;

#ndregion

#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.ToString () st. WMONTH.TOSTRING () "." st.wday.tostring () "." st.WHOUR.TOSTRING () "." st.wminute.toSTRING () "." st.wsecond. Tostring (); return time;} #ENDREGION

#Region loading data Private void fileok_click (object sender, system.eventargs e) {int nneed = 0, nbufsize; intptr buf; internet_cache_entry_info cacheItem; INTPTR HENUM; BOOL R;

FindfirstURLCACHEENTRY (NULL, INTPTR.ZERO, REF NNEDED);

IF (Marshal.getlastwin32error () == Error_NO_MORE_ITEMS) Return;

nBufSize = nNeeded; buf = Marshal.AllocHGlobal (nBufSize); hEnum = FindFirstUrlCacheEntry (null, buf, ref nNeeded); while (true) {CacheItem = (INTERNET_CACHE_ENTRY_INFO) Marshal.PtrToStructure (buf, typeof (INTERNET_CACHE_ENTRY_INFO));

string modifiedTime = FILETIMEtoDataTime (CacheItem.LastModifiedTime); string expireTime = FILETIMEtoDataTime (CacheItem.ExpireTime); string accessTime = FILETIMEtoDataTime (CacheItem.LastAccessTime); string syncTime = FILETIMEtoDataTime (CacheItem.LastSyncTime);

#Region get data, deposit the database TRY {

// Traverse CacheItem ///////, String S = Marshal.PTRTOStringAuto (CacheItem.lpszSourceURLName);} catch {// Abnormal processing} #ENDREGIONSTRING S = Marshal.PTRTRTOSTRINGAUTO (CacheItem.lpszsourceURLName);

Nneeded = nbufsize; r = findnexturlcachentry (henum, buf, ref nneed);

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);}} MessageBox.Show ( "system data is loaded! "); MARSHAL.FREEHGLOBAL (BUF);

}

#ndregion

转载请注明原文地址:https://www.9cbs.com/read-24403.html

New Post(0)