.bmp file format of Heroes of Might and Magic: C# parsing library

Application

Heroes of Might and Magic

File extension

bmp

KS implementation details

License: CC0-1.0

This page hosts a formal specification of .bmp file format of Heroes of Might and Magic using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.

Usage

Parse a local file and get structure in memory:

var data = HeroesOfMightAndMagicBmp.FromFile("path/to/local/file.bmp");

Or parse structure from a byte array:

byte[] someArray = new byte[] { ... };
var data = new HeroesOfMightAndMagicBmp(new KaitaiStream(someArray));

After that, one can get various attributes from the structure by accessing properties like:

data.Magic // => get magic

C# source code to parse .bmp file format of Heroes of Might and Magic

HeroesOfMightAndMagicBmp.cs

// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild



namespace Kaitai
{
    public partial class HeroesOfMightAndMagicBmp : KaitaiStruct
    {
        public static HeroesOfMightAndMagicBmp FromFile(string fileName)
        {
            return new HeroesOfMightAndMagicBmp(new KaitaiStream(fileName));
        }

        public HeroesOfMightAndMagicBmp(KaitaiStream p__io, KaitaiStruct p__parent = null, HeroesOfMightAndMagicBmp p__root = null) : base(p__io)
        {
            m_parent = p__parent;
            m_root = p__root ?? this;
            _read();
        }
        private void _read()
        {
            _magic = m_io.ReadU2le();
            _width = m_io.ReadU2le();
            _height = m_io.ReadU2le();
            _data = m_io.ReadBytes((Width * Height));
        }
        private ushort _magic;
        private ushort _width;
        private ushort _height;
        private byte[] _data;
        private HeroesOfMightAndMagicBmp m_root;
        private KaitaiStruct m_parent;
        public ushort Magic { get { return _magic; } }
        public ushort Width { get { return _width; } }
        public ushort Height { get { return _height; } }
        public byte[] Data { get { return _data; } }
        public HeroesOfMightAndMagicBmp M_Root { get { return m_root; } }
        public KaitaiStruct M_Parent { get { return m_parent; } }
    }
}