GithubHelp home page GithubHelp logo

snowberry-software / snowberry.io Goto Github PK

View Code? Open in Web Editor NEW
7.0 1.0 0.0 147 KB

Binary reader and writer that supports different endian types.

License: MIT License

C# 95.40% Batchfile 0.15% PowerShell 2.47% Shell 1.97%
big binary binary-reader binary-reader-writer binary-writer dotnet endianness little reader writer

snowberry.io's Introduction

License NuGet Version

A binary reader and writer that supports different endian types.

Usage

Features

  • Reader

    • Read different endian types for supported data types.
    • Custom analyzer that can be used to analyze bytes when they were filled into a buffer.
    • Read zero terminated strings (ReadCString).
    • Read sized zero terminated strings (ReadSizedCString).
    • Read size prefixed strings (ReadString).
    • Read lines (ReadLine).
    • Read custom Sha1 type.
    • Read padding.
    • Enable custom region view.
  • Writer

    • Write different endian types for supported data types.
    • Write zero terminated strings (WriteCString).
    • Write sized zero terminated string (WriteSizedCString).
    • Write custom Sha1 type.
    • Write padding.
    • Write lines (WriteLine).
    • Write size prefixed strings.
  • Custom Sha1 type based on SHA-1.

Most used types

Name Description
Reader
BaseEndianReader The abstract base type that implements the IEndianReader interface.
EndianStreamReader Used for reading from streams, inherits the BaseEndianReader type.
Writer
EndianStreamWriter Used for writing into streams, inherits the BinaryWriter type and implements the IEndianWriter interface.

Reader and writer

var stream = new MemoryStream();
using var writer = new EndianStreamWriter(stream, keepStreamOpen: true);

writer.Write(10,  EndianType.BIG)
      .Write(20L, EndianType.BIG)
      .Write(30F, EndianType.BIG)
      .Write(40u, EndianType.BIG)
      .Write(50d, EndianType.BIG);
      
writer.BaseStream.Position = 0;

using var reader = new EndianStreamReader(stream);

_ = reader.ReadInt32(EndianType.BIG);
_ = reader.ReadLong(EndianType.BIG);
_ = reader.ReadFloat(EndianType.BIG);
_ = reader.ReadUInt32(EndianType.BIG);
_ = reader.ReadDouble(EndianType.BIG);

Custom analyzer

The Analyzer abstract type can be inherited and used to monitor each buffer fill operation.

This is useful if a binary file is or has encrypted content.

Endian converter

The BinaryEndianConverter type can be used to convert data in a Span<byte> to all supported data types and also accepts an offset.

var buffer = new byte[] { ... };
int offset = ...;
var endianType = EndianType.BIG;

_ = BinaryEndianConverter.ToLong(buffer, endianType);
_ = BinaryEndianConverter.ToLong(buffer, offset, endianType);

Supported data types

Type Endian type(s)
Int8 -
UInt8 -
Int16 Little, Big
UInt16 Little, Big
Int32 Little, Big
UInt32 Little, Big
Int64 Little, Big
UInt64 Little, Big
Float Little, Big
Double Little, Big
Guid Little, Big
Sha1 Little

snowberry.io's People

Contributors

vnncc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

snowberry.io'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.