Andes Firmware Image layout as seen in MT76 Wifi Chipsets: C# parsing library

Firmware image found with MediaTek MT76xx wifi chipsets.

Application

Firmware Image wifi chipset

KS implementation details

License: CC0-1.0

This page hosts a formal specification of Andes Firmware Image layout as seen in MT76 Wifi Chipsets using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.

Usage

Runtime library

All parsing code for C# generated by Kaitai Struct depends on the C# runtime library. You have to install it before you can parse data.

The C# runtime library is available in the NuGet Gallery. Installation instructions can also be found there.

Code

Parse a local file and get structure in memory:

var data = AndesFirmware.FromFile("path/to/local/file.bin");

Or parse structure from a byte array:

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

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

data.ImageHeader // => get image header

C# source code to parse Andes Firmware Image layout as seen in MT76 Wifi Chipsets

AndesFirmware.cs

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



namespace Kaitai
{

    /// <summary>
    /// Firmware image found with MediaTek MT76xx wifi chipsets.
    /// </summary>
    public partial class AndesFirmware : KaitaiStruct
    {
        public static AndesFirmware FromFile(string fileName)
        {
            return new AndesFirmware(new KaitaiStream(fileName));
        }

        public AndesFirmware(KaitaiStream p__io, KaitaiStruct p__parent = null, AndesFirmware p__root = null) : base(p__io)
        {
            m_parent = p__parent;
            m_root = p__root ?? this;
            _read();
        }
        private void _read()
        {
            __raw_imageHeader = m_io.ReadBytes(32);
            var io___raw_imageHeader = new KaitaiStream(__raw_imageHeader);
            _imageHeader = new ImageHeader(io___raw_imageHeader, this, m_root);
            _ilm = m_io.ReadBytes(ImageHeader.IlmLen);
            _dlm = m_io.ReadBytes(ImageHeader.DlmLen);
        }
        public partial class ImageHeader : KaitaiStruct
        {
            public static ImageHeader FromFile(string fileName)
            {
                return new ImageHeader(new KaitaiStream(fileName));
            }

            public ImageHeader(KaitaiStream p__io, AndesFirmware p__parent = null, AndesFirmware p__root = null) : base(p__io)
            {
                m_parent = p__parent;
                m_root = p__root;
                _read();
            }
            private void _read()
            {
                _ilmLen = m_io.ReadU4le();
                _dlmLen = m_io.ReadU4le();
                _fwVer = m_io.ReadU2le();
                _buildVer = m_io.ReadU2le();
                _extra = m_io.ReadU4le();
                _buildTime = System.Text.Encoding.GetEncoding("UTF-8").GetString(m_io.ReadBytes(16));
            }
            private uint _ilmLen;
            private uint _dlmLen;
            private ushort _fwVer;
            private ushort _buildVer;
            private uint _extra;
            private string _buildTime;
            private AndesFirmware m_root;
            private AndesFirmware m_parent;
            public uint IlmLen { get { return _ilmLen; } }
            public uint DlmLen { get { return _dlmLen; } }
            public ushort FwVer { get { return _fwVer; } }
            public ushort BuildVer { get { return _buildVer; } }
            public uint Extra { get { return _extra; } }
            public string BuildTime { get { return _buildTime; } }
            public AndesFirmware M_Root { get { return m_root; } }
            public AndesFirmware M_Parent { get { return m_parent; } }
        }
        private ImageHeader _imageHeader;
        private byte[] _ilm;
        private byte[] _dlm;
        private AndesFirmware m_root;
        private KaitaiStruct m_parent;
        private byte[] __raw_imageHeader;
        public ImageHeader ImageHeader { get { return _imageHeader; } }
        public byte[] Ilm { get { return _ilm; } }
        public byte[] Dlm { get { return _dlm; } }
        public AndesFirmware M_Root { get { return m_root; } }
        public KaitaiStruct M_Parent { get { return m_parent; } }
        public byte[] M_RawImageHeader { get { return __raw_imageHeader; } }
    }
}