Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alanedwardes/binarymapper
A .NET Core library to map binary files into C-style structures.
https://github.com/alanedwardes/binarymapper
binary nuget parsing reading structures
Last synced: 1 day ago
JSON representation
A .NET Core library to map binary files into C-style structures.
- Host: GitHub
- URL: https://github.com/alanedwardes/binarymapper
- Owner: alanedwardes
- License: mit
- Created: 2018-04-11T21:09:15.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-07-29T22:02:09.000Z (4 months ago)
- Last Synced: 2024-11-07T07:51:47.317Z (8 days ago)
- Topics: binary, nuget, parsing, reading, structures
- Language: C#
- Homepage: https://alanedwardes.github.io/docs/BinaryMapper/
- Size: 128 KB
- Stars: 8
- Watchers: 5
- Forks: 4
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BinaryMapper [![AppVeyor](https://ci.appveyor.com/api/projects/status/raisen0g2fdmc0js/branch/master?svg=true)](https://ci.appveyor.com/project/alanedwardes/binarymapper)
BinaryMapper is a simple cross-platform library to parse binary files into their respective data structures in C#. It uses reflection to understand structures, and reads the data into the structure from a seekable stream.
Currently the library supports reading Minidumps and executables based on the structures published on MSDN. Spporting other file formats is a case of definining the structures and pointing the library at them.
## BinaryMapper.Core [![NuGet](https://img.shields.io/nuget/v/BinaryMapper.Core.svg)](https://www.nuget.org/packages/BinaryMapper.Core/)
This example shows how to load a binary stream into structures you have defined.
```csharp
public class MYFILE_HEADER_STRUCT
{
public uint Signature;
public uint Version;
public uint SomeOffset;
public uint NumberOfEntries;
[ArraySize(nameof(NumberOfEntries))]
public MYFILE_STREAM_STRUCT[] MyStructures;
}public class MYFILE_STREAM_STRUCT
{
public uint Flags;
}var stream = File.OpenRead("myfile.bin");
var streamBinaryMapper = new StreamBinaryMapper();
var header = streamBinaryMapper.ReadObject(stream);
```## BinaryMapper.Windows.Minidump [![NuGet](https://img.shields.io/nuget/v/BinaryMapper.Windows.Minidump.svg)](https://www.nuget.org/packages/BinaryMapper.Windows.Minidump/)
This example shows how to extract the names of the loaded modules from a memory dump stream.
```csharp
var stream = File.OpenRead("minidump.dmp");
var minidumpMapper = new MinidumpMapper();
var minidump = minidumpMapper.ReadMinidump(stream);Console.WriteLine($"This minidump is of type {minidump.Header.Flags}");
foreach (var module in minidump.Modules)
{
Console.WriteLine(module.Key);
}
```## BinaryMapper.Windows.Executable [![NuGet](https://img.shields.io/nuget/v/BinaryMapper.Windows.Executable.svg)](https://www.nuget.org/packages/BinaryMapper.Windows.Executable/)
This example shows how to load an executable, find out whether it is 32 or 64 bit, and which version of Windows it targets.
```csharp
var stream = File.OpenRead("executable.exe");
var executableMapper = new ExecutableMapper();
var executable = executableMapper.ReadExecutable(stream);if (executable.OptionalHeader != null)
{
Console.WriteLine($"32-bit executable for Windows {executable.OptionalHeader.OperatingSystemVersion}");
}
else
{
Console.WriteLine($"64-bit executable for Windows {executable.OptionalHeader64.OperatingSystemVersion}");
}
```