Coder Social home page Coder Social logo

compoundfilereader's Introduction

compoundfilereader

Simple standalone C++ header file to read compound file (Structured Storage File) content.

Source code structure

  • src/include/compoundfilereader.h The only header file needed for parsing compound file.
  • src/include/utf.h The helper header file used for converting between utf16, utf8, and unicode. It's used by samples.
  • test/data Real world compound files for tests.
  • samples/cfb Command line tool to list and dump compound files.
  • samples/IEOpenedTabParser Command line tool to show IE opened tab information.
  • vsproject Project and solution files for Microsoft Visual Studio.

Usage

  • Copy compoundfilereader.h to your source tree or: install "compoundfilereader" by git submodule
  • #include <compoundfilereader.h> in your source code
  • Construct a CompoundFileReader object by giving the buffer (see compoundfilereader.h for details)

Build the samples

Linux

Run make (requires gcc and g++)

Windows

  • Option 1: double click 'vsproject\cfbreader\cfbreader.sln' then build in Visual Studio
  • Option 2: run 'build.bat' in Visual Studio Command Prompt (requires Visual Studio)

Run the samples

Try the following:

out/ieot "test/data/{BC59C035-E8AC-11E4-825B-10604B7CB9F0}.dat"
out/cfb list "test/data/a test email message.msg"
out/cfb dump "test/data/a test email message.msg" __properties_version1.0

TODO

  • Unit tests
  • Make the reader able to connect to abstract interfaces such as istream

Microsoft Open Source Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

compoundfilereader's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

compoundfilereader's Issues

Dead loop if recursively visiting left or right child node

In function EnumNodes( ), level limit is not increased for left or right sibling node, only increased for child node.
So for a maliciously crafted CFB file, there is a chance to do endless recursion(root -> left -> left -> left ...).

Here is my modified source code to add recursion depth limit.

maliciously crafted CFB file also attached:
endless.zip

    void EnumFiles(const COMPOUND_FILE_ENTRY* entry, int maxLevel, EnumFilesCallback callback) const
    {
        utf16string dir;
        unsigned int depth = 0;
        EnumNodes(GetEntry(entry->childID), 0, maxLevel, dir, callback, depth);
    }

private:
    static constexpr unsigned int MAX_RECURSIVE_DEPTH = 5;

    // Enum entries with same level, including 'entry' itself
    void EnumNodes(const COMPOUND_FILE_ENTRY* entry, int currentLevel, int maxLevel, 
        const utf16string &dir, EnumFilesCallback callback, unsigned int depth) const
    {
      if (++depth > MAX_RECURSIVE_DEPTH)
          return;

        if (maxLevel > 0 && currentLevel >= maxLevel)
            return;
        if (entry == nullptr)
            return;

        callback(entry, dir, currentLevel + 1);

        const COMPOUND_FILE_ENTRY* child = GetEntry(entry->childID);
        if (child != nullptr)
        {
            utf16string newDir = dir;
            if (dir.length() != 0)
                newDir.append(1, '\n');
            newDir.append(entry->name, entry->nameLen / 2);
            EnumNodes(GetEntry(entry->childID), currentLevel + 1, maxLevel, newDir, callback, depth);
        }

        EnumNodes(GetEntry(entry->leftSiblingID), currentLevel, maxLevel, dir, callback, depth);
        EnumNodes(GetEntry(entry->rightSiblingID), currentLevel, maxLevel, dir, callback, depth);
    }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.