猿问

如何打开 Thumbscache.db

我正在尝试打开 thumbscache.db 文件,我尝试像打开任何其他数据库一样打开它,但没有用。我还在 C# 中寻找任何 API 或支持。请建议是否有其他方法。顺便说一句,下面是我到目前为止的方法。


1. 像任何其他数据库一样打开它。


        path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

        path += @"\Microsoft\Windows\Explorer\thumbcache_1280.db";

        datasource = "Data source = " + path;

        SQLiteCommand cmd = new SQLiteCommand();

        SQLiteConnection conn = new SQLiteConnection(datasource);

        cmd.Connection = conn;

        cmd.CommandText = "SELECT * FROM Filename";

        conn.Open();

        SQLiteDataAdapter sqda = new SQLiteDataAdapter(cmd);

        DataTable dt = new DataTable();

        sqda.Fill(dt);

        dataGridView1.DataSource = dt;

        conn.Close();

但是出现了这个异常。

2.使用ShellFile打开它

        ShellFile shellFile = ShellFile.FromFilePath(path);
        Bitmap bitmap = shellFile.Thumbnail.ExtraLargeBitmap;
        pbThumbs.Image = bitmap;

而不是 thumbscache 它提供文件拇指图标。

http://img2.mukewang.com/634a5f29000156db03040403.jpg

3. 使用 OpenMcdf 作为 OLE 文档打开


        path = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

        path += @"\Microsoft\Windows\Explorer\thumbcache_1280.db";

        CompoundFile cf = new CompoundFile(path);

        CFStream foundStream = cf.RootStorage.GetStream("Filename");

        byte[] temp = foundStream.GetData();

这个异常出现了。

http://img4.mukewang.com/634a5f350001770104040175.jpg

倚天杖
浏览 194回答 1
1回答

慕莱坞森

以下是用于打开 thumbcache*.db 文件的 C# 类。public class ThumbCache{&nbsp; &nbsp; private const int WindowsVista = 0x14;&nbsp; &nbsp; private const int Windows7 = 0x15;&nbsp; &nbsp; private const int Windows8 = 0x1A;&nbsp; &nbsp; private const int Windows8v2 = 0x1C;&nbsp; &nbsp; private const int Windows8v3 = 0x1E;&nbsp; &nbsp; private const int Windows8_1 = 0x1F;&nbsp; &nbsp; private const int Windows10 = 0x20;&nbsp; &nbsp; private Stream stream;&nbsp; &nbsp; private uint fileVersion;&nbsp; &nbsp; private byte[] tempBytes = new byte[65536];&nbsp; &nbsp; private uint[] entryOffsets;&nbsp; &nbsp; public int ImageCount { get { return entryOffsets.Length; } }&nbsp; &nbsp; public ThumbCache(string fileName)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; stream = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);&nbsp; &nbsp; &nbsp; &nbsp; ReadFromStream(stream);&nbsp; &nbsp; }&nbsp; &nbsp; public ThumbCache(Stream stream)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; ReadFromStream(stream);&nbsp; &nbsp; }&nbsp; &nbsp; ~ThumbCache()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; stream.Close();&nbsp; &nbsp; }&nbsp; &nbsp; private void ReadFromStream(Stream stream)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; stream.Read(tempBytes, 0, 32);&nbsp; &nbsp; &nbsp; &nbsp; string magic = Encoding.ASCII.GetString(tempBytes, 0, 4);&nbsp; &nbsp; &nbsp; &nbsp; if (!magic.Equals("CMMM"))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw new ApplicationException("This is not a valid ThumbCache file.");&nbsp; &nbsp; &nbsp; &nbsp; fileVersion = BitConverter.ToUInt32(tempBytes, 4);&nbsp; &nbsp; &nbsp; &nbsp; uint fileType = BitConverter.ToUInt32(tempBytes, 8);&nbsp; &nbsp; &nbsp; &nbsp; uint firstEntryPtr = 0;&nbsp; &nbsp; &nbsp; &nbsp; uint availableEntryPtr = 0;&nbsp; &nbsp; &nbsp; &nbsp; if (fileVersion < Windows8v2)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; firstEntryPtr = BitConverter.ToUInt32(tempBytes, 12);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; availableEntryPtr = BitConverter.ToUInt32(tempBytes, 16);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; else&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; firstEntryPtr = BitConverter.ToUInt32(tempBytes, 16);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; availableEntryPtr = BitConverter.ToUInt32(tempBytes, 20);&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; stream.Seek(firstEntryPtr, SeekOrigin.Begin);&nbsp; &nbsp; &nbsp; &nbsp; List<uint> entryOffsetList = new List<uint>();&nbsp; &nbsp; &nbsp; &nbsp; try&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uint entrySize;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; while (stream.Position < stream.Length)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; entryOffsetList.Add((uint)stream.Position);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stream.Read(tempBytes, 0, 8);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if ((tempBytes[0] != 'C') || (tempBytes[1] != 'M') || (tempBytes[2] != 'M') || (tempBytes[3] != 'M'))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; entrySize = BitConverter.ToUInt32(tempBytes, 4);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stream.Seek(entrySize - 8, SeekOrigin.Current);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; catch { }&nbsp; &nbsp; &nbsp; &nbsp; entryOffsets = entryOffsetList.ToArray();&nbsp; &nbsp; }&nbsp; &nbsp; public ThumbInfo GetImage(int imageIndex, bool needImage)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; if (entryOffsets.Length == 0) return null;&nbsp; &nbsp; &nbsp; &nbsp; if ((imageIndex < 0) || (imageIndex >= entryOffsets.Length)) return null;&nbsp; &nbsp; &nbsp; &nbsp; return new ThumbInfo(stream, entryOffsets[imageIndex], tempBytes, fileVersion, needImage);&nbsp; &nbsp; }&nbsp; &nbsp; public Dictionary<string, string> GetMetadata(ThumbInfo info)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; var dict = new Dictionary<string, string>();&nbsp; &nbsp; &nbsp; &nbsp; if (entryOffsets.Length == 0) return dict;&nbsp; &nbsp; &nbsp; &nbsp; if (info == null) return dict;&nbsp; &nbsp; &nbsp; &nbsp; dict.Add("File offset", info.fileOffset.ToString());&nbsp; &nbsp; &nbsp; &nbsp; dict.Add("Entry size", info.entrySize.ToString());&nbsp; &nbsp; &nbsp; &nbsp; dict.Add("Entry hash", info.entryHash.ToString("X16"));&nbsp; &nbsp; &nbsp; &nbsp; dict.Add("Filename length", info.fileNameLength.ToString());&nbsp; &nbsp; &nbsp; &nbsp; dict.Add("Padding length", info.paddingLength.ToString());&nbsp; &nbsp; &nbsp; &nbsp; dict.Add("Data length", info.dataLength.ToString());&nbsp; &nbsp; &nbsp; &nbsp; dict.Add("Image width", info.imageWidth.ToString());&nbsp; &nbsp; &nbsp; &nbsp; dict.Add("Image height", info.imageHeight.ToString());&nbsp; &nbsp; &nbsp; &nbsp; dict.Add("Data checksum", info.dataChecksum.ToString("X16"));&nbsp; &nbsp; &nbsp; &nbsp; dict.Add("Header checksum", info.headerChecksum.ToString("X16"));&nbsp; &nbsp; &nbsp; &nbsp; return dict;&nbsp; &nbsp; }&nbsp; &nbsp; public class ThumbInfo&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; public Image image;&nbsp; &nbsp; &nbsp; &nbsp; public long fileOffset;&nbsp; &nbsp; &nbsp; &nbsp; public uint entrySize;&nbsp; &nbsp; &nbsp; &nbsp; public ulong entryHash;&nbsp; &nbsp; &nbsp; &nbsp; public uint fileNameLength;&nbsp; &nbsp; &nbsp; &nbsp; public uint paddingLength;&nbsp; &nbsp; &nbsp; &nbsp; public uint dataLength;&nbsp; &nbsp; &nbsp; &nbsp; public ulong dataChecksum;&nbsp; &nbsp; &nbsp; &nbsp; public ulong headerChecksum;&nbsp; &nbsp; &nbsp; &nbsp; public uint imageWidth;&nbsp; &nbsp; &nbsp; &nbsp; public uint imageHeight;&nbsp; &nbsp; &nbsp; &nbsp; public ThumbInfo(Stream stream, long offset, byte[] tempBytes, uint fileVersion, bool needImage)&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fileOffset = offset;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stream.Seek(fileOffset, SeekOrigin.Begin);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stream.Read(tempBytes, 0, 64);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; int bytePtr = 0;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; string magic = Encoding.ASCII.GetString(tempBytes, bytePtr, 4); bytePtr += 4;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!magic.Equals("CMMM"))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw new ApplicationException("Incorrect format.");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; entrySize = BitConverter.ToUInt32(tempBytes, bytePtr); bytePtr += 4;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; entryHash = BitConverter.ToUInt64(tempBytes, bytePtr); bytePtr += 8;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (fileVersion == WindowsVista)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bytePtr += 8; // wchar x 4&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fileNameLength = BitConverter.ToUInt32(tempBytes, bytePtr); bytePtr += 4;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; paddingLength = BitConverter.ToUInt32(tempBytes, bytePtr); bytePtr += 4;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dataLength = BitConverter.ToUInt32(tempBytes, bytePtr); bytePtr += 4;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (fileVersion >= Windows8)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imageWidth = BitConverter.ToUInt32(tempBytes, bytePtr); bytePtr += 4;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; imageHeight = BitConverter.ToUInt32(tempBytes, bytePtr); bytePtr += 4;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bytePtr += 4; // unknown&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dataChecksum = BitConverter.ToUInt64(tempBytes, bytePtr); bytePtr += 8;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; headerChecksum = BitConverter.ToUInt64(tempBytes, bytePtr); bytePtr += 8;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (!needImage || dataLength == 0 || dataLength > 0x1000000)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stream.Seek(fileOffset + entrySize - dataLength, SeekOrigin.Begin);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (dataLength > tempBytes.Length)&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; tempBytes = new byte[dataLength];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stream.Read(tempBytes, 0, (int)dataLength);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; using (var mstream = new MemoryStream(tempBytes))&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image = new Bitmap(mstream);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }}详细解决方案在这里。
随时随地看视频慕课网APP
我要回答