ThumbsLib in C++

ThumbsLib is a library that is able to read the thumbnails from the thumbs.db file of Windows XP system.

The original version of this library was created in C# by petedavis in his website: http://www.petedavis.net/drupal//index.php?q=node/2

For some reason, I need a C++ version of this lib. So I looked for some information on the OLE storage interface, and translated this lib into C++.

The thumbs.db uses the Micorsoft Compound File Format which could be operated by the IStorage interface. This Compound File Format looks like a small file system in it. There maybe “directory” of  ”file” contained, and represented as “IStorage” interface and “IStream” interface.

We could create an IStorage interface from StgOpenStorage.

There is a “Catalog” “file” contained in any thumbs.db file which stores all the thumbnails’ information.

Catalog contains a catalog header and a list of catalog item. You could get each thumbnail’s actual filename from the catalog item.

The data structure is like below:

struct CatalogHeader {

int number1;

int thumbCount;

int thumbWidth;

int thumbHeight;

};

struct CatalogItem {

int num1;

int itemID;                        // thumbnail’s ID, when we need to get the thumbnail’s data, we need this ID

FILETIME filetime;

std::wstring filename;  // the file’s original filename

short num7;                     // seems always to be zero

};

For the detial how we get the thumbnail from the thumbs.db, you may like to visit petedavis’ website.

You could download this lib at: thumbslib

This ThumbsLib (in C++) is easy to use, for example:

ThumbDB dbFile(_T(“.\thumbs.db”));

vector<wstring> aFiles(dbFile.GetThumbFiles());

for (vector<wstring>::iterator itr = aFiles.begin();

itr != aFiles.end();

++itr)

{

dbFile.SaveThumbDataToFile((*itr).c_str(), szBuf);

}

====================中文介绍===================

ThumbsLib 是一个用于读取Windows XP系统下文件缩略图缓存文件thumbs.db的C++程序库。

原始的ThumbDBLib是一个由petedavis使用C#编写的,该库发表在他的个人网站上的:http://www.petedavis.net/drupal//index.php?q=node/2

由于我需要一个C++版本的读取thumbs.db的库,因此我查阅了一些关于OLE存储接口的资料,并将ThumbDBLib翻译成C++版本的。

thumbs.db使用了Micorsoft Compound File Format,我们可以使用 IStorage interface接口访问&操作该文件。这种文件格式内部模拟了一个小的文件系统,其中有文件夹的概念以及文件的概念。在实际使用中,我们用IStorage来操作“文件夹”,用IStream操作“文件”。

使用 StgOpenStorage 函数可以创建一个IStorage接口。

thumbs.db文件中有一个特殊的名为“Catalog”的Stream,其中包含了所有缩略图的相关信息。

“Catalog”中包含一个CatalogHeader,以及一系列的CatalogItem。

struct CatalogHeader {

int number1;

int thumbCount;

int thumbWidth;

int thumbHeight;

};

struct CatalogItem {

int num1;

int itemID;                        // 缩略图ID,我们需要用这个ID构建一个用于打开thumbs.db中各个缩略图实际数据的Stream的文件名。

FILETIME filetime;

std::wstring filename;  // 被缓存缩略图文件的原文件名

short num7;                     // 这个字段似乎总是0

};

更详细的信息,可以参考petedavis’ website中原作者对thumbs.db文件的分析。

点此下载C++版的thumbslib: thumbslib

ThumbsLib的使用与原先的C#版类似,如下:

ThumbDB dbFile(_T(“.\thumbs.db”));

vector<wstring> aFiles(dbFile.GetThumbFiles());

for (vector<wstring>::iterator itr = aFiles.begin();

itr != aFiles.end();

++itr)

{

dbFile.SaveThumbDataToFile((*itr).c_str(), szBuf);

}

  • You may use these HTML tags: <a> <abbr> <acronym> <b> <blockquote> <cite> <code> <del> <em> <i> <q> <strike> <strong>

    *
    To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
    Click to hear an audio file of the anti-spam word

Go to Top