Git Product home page Git Product logo

binaryformatdatastructure's Introduction

BinaryFormatDataStructure

.NET Library for parsing MS-NRBF streams.

Allows the reading of the output that is typically created from BinaryFormatter without the security concerns of automatically instantiating unsafe classes. NRBFReader deserializes primitive types (Boolean, Byte, Char, Double, Int16, Int32, Int64, SByte, Single, UInt16, UInt32, Uint64, Decimal) as well as TimeSpan and DateTime. Primitive arrays are also deserialized. Other class and object information is returned in a BinaryObject type for the caller to evaluate.

What is MS-NRBF?

MS-NRBR or Binary Format Data Structure is a series of data records that describe and object graph and its data. It contains both forward and backward looking record references and can represent cyclical data. Using BinaryFormatter to re-read this stream is generally considered to be unsafe is it will create any object specified in the record with unvalidated data.

Quick start

Here is a quick sample to get you started. However if you are deserializing third part or system objects it is often useful just to inspect the result of ReadStream.

using BinaryFormatDataStructure;
...
// This example assumes an root object but it also could be an array.
// The object type should be already known if you are deserializing trusted data
// but it can also be determined from BinaryObject properties.
var result = (BinaryObject)NRBFReader.ReadStream(stream);
var document = new Document(result);
...
public class Document
{
    ...
    public Document(BinaryObject model)
    {
        // Optional but if other objects in this deserialized graph have a reference back to this object as
        // a "parent" it is useful to keep a record of the created object.
        model.ReferenceObject = this;

        _width = (int)model["_width"];
        _height = (int)model["_height"];

        if (model.ContainsKey("_depth"))
        {
            // Deserialize versioned property
            _depth = (int)model["_depth"];
        }

        var childModel = (BinaryObject)model["child"];
        // TODO: create child object and continue graph deserialization
    }
}

Installing

Just install the BinaryFormatDataStructure NuGet package:

PM> Install-Package BinaryFormatDataStructure

binaryformatdatastructure's People

Contributors

bbowyersmyth avatar rpendleton avatar tomasherceg avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

Forkers

rickbrew riganti

binaryformatdatastructure's Issues

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.