Coder Social home page Coder Social logo

zhangyingchun08 / binarynotes.net Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sylvain-prevost/binarynotes.net

0.0 0.0 0.0 14.47 MB

Asn.1 to C# classes (and vice-versa) without having to manually parse or construct sequences, etc.. or other tedious aspects.

Shell 0.01% C# 80.89% XSLT 19.04% Batchfile 0.06%

binarynotes.net's Introduction

BinaryNotes.NET

Nuget

This is a set of 2 tools:

  • C# library enabling marshalling/unmarshalling of asn.1 data buffers into/from objects according to the classes generated by the compiler.
  • ASN.1 Compiler that generates C# classes from an asn.1 file.

It can be used to decode & parse asn.1 DER/BER-encoded binary files/buffers in a coding-friendly manner.
It can also do the reverse and generate asn.1 compliant buffers from easily constructed C# objects.

From Wikipedia: https://en.wikipedia.org/wiki/ASN.1#Example

FooProtocol DEFINITIONS ::= BEGIN

    FooQuestion ::= SEQUENCE {
        trackingNumber INTEGER,
        question       IA5String
    }

END

This asn.1 module can be fed to the compiler to generate corresponding C# class.

call bncompiler\bnc.cmd -mp cs_xsl_modules -o [outdir] -ns [C# namespace] -f [asn1 module]

The generated class can now be used (with help from BinaryNotes library) to easily decode DER/BER data.

IDecoder decoder = CoderFactory.getInstance().newDecoder("DER");

// asn1 data obtained from wikipedia asn.1 example
byte[] asn1Data = new byte[] { 
    0x30,0x13, 
        0x02,0x01,0x05, 
        0x16,0x0e,0x41,0x6e,0x79,0x62,0x6f,0x64,0x79,0x20,0x74,0x68,0x65,0x72,0x65,0x3f
};

using (MemoryStream memoryStream = new MemoryStream(asn1Data))
{
    // request decoding of memorystream using FooQuestion class
    FooQuestion fooQuestion = decoder.decode<FooQuestion>(memoryStream);

    // Display content of FooQuestion object
    Console.WriteLine("\tDecoded trackingNumber : {0}", fooQuestion.TrackingNumber);
    Console.WriteLine("\tDecoded question : {0}", fooQuestion.Question);
}

Result:

    Decoded trackingNumber : 5
    Decoded question : Anybody there?

And conversly the same class can also be used to easily generate DER/BER-encoded data.

IEncoder encoder = CoderFactory.getInstance().newEncoder("DER");

using (MemoryStream memoryStream = new MemoryStream())
{
    // create FooQuestion object and populate it
    FooQuestion fooQuestion = new FooQuestion();
    fooQuestion.TrackingNumber = 5;
    fooQuestion.Question = "Anybody there?";

    // request DER encoding
    encoder.encode<FooQuestion>(fooQuestion, memoryStream);
    byte[] result = memoryStream.ToArray();

    // display result
    Console.WriteLine("\tDER encoded result : {0}", BitConverter.ToString(result).Replace("-", " "));
}

Result:

    DER encoded result : 30 13 02 01 05 16 0E 41 6E 79 62 6F 64 79 20 74 68 65 72 65 3F


Currently focusing on fixes & features additions to enable complete CryptographicMessageSyntax asn.1 decoding/encoding.

See ePassportLibrary for a more concrete example.



Included in 1.5.4.7



New Feature(s)

  • Added encoding/decoding support for large asn.1 integer (size > 8 bytes).
  • Enabled BER indefinite-length decoding.
  • Added .NET assembly StrongName.
  • Now targetting both .NET 4.0 & .NET Standard 2.0 (i.e. it includes .NetCore >= 2.x).
  • Added 'SET OF ANY' support when present within sequence.
  • Added missing EXPLICIT keyword support.
  • Added support of ANY field type regardless of position in sequence.
  • Enable controlled relaxation of minimal tag encoding size for application-class tags.


Bugfixe(s)

  • Fixed OID parsing when not last in sequence.
  • Fixed C# class generation when BOOLEAN element is annotated with a DEFAULT value.
  • Fixed C# class generation when MAX keyword is used in asn.1 constraint.
  • Fixed encoding of elements whose values are matching asn.1 DEFAULT definition (ie, it should NOT be encoded for DER).


Note(s)

  • .NET Framework 4.0 or .NET Standard 2.0 are the minimum version required.



This project is a fork of the original: http://bnotes.sourceforge.net

BinaryNotes v1.5.3 or greater is licensed under Apache Licence v2 http://www.apache.org/licenses/LICENSE-2.0.html
(c) 2006-2011 Abdulla G. Abdurakhmanov ([email protected])


It was developed and maintained by Abdulla G. Abdurakhmanov (http://bnotes.sf.net) until 2007. IMHO, he created a little jewel.

binarynotes.net's People

Contributors

sylvain-prevost avatar

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.