hao 0.0.19

Read, edit, create and write .net assemblies
Documentation
//! The raw ECMA-335 metadata, as stored in the file: the metadata root, its
//! streams, and the tables and heaps inside them.
//!
//! Most code wants [`Module`](crate::Module) and the entries in
//! [`crate::dotnet::entries`] instead, which are loaded from this layer and
//! link everything up: a type's methods, a method's signature, and so on. Here,
//! rows point at other rows and heaps by plain indexes that you follow yourself.
//! Use it to look at a file as stored (row counts, heap offsets, coded indexes),
//! or for the flag types the entries share, such as
//! [`TypeAttributes`](streams::tables_stream::TypeAttributes).
//!
//! - [`metadata_header`]: the metadata root and the headers locating each stream.
//! - [`streams`]: the heaps (`#Strings`, `#Blob`, `#GUID`, `#US`) and, in
//!   [`streams::tables_stream`], the tables.
//!
//! [`Metadata`](crate::dotnet::Metadata) parses an image down to this level:
//!
//! ```no_run
//! use hao::dotnet::Metadata;
//!
//! let bytes = std::fs::read("Example.dll").unwrap();
//! let metadata = Metadata::parse(&bytes).unwrap();
//! let streams = &metadata.metadata_streams;
//! let tables = &streams.tables_stream;
//!
//! // The Module table has one row. Its name is an offset into #Strings.
//! let module = tables.modules().unwrap().next().unwrap().unwrap();
//! let name = streams.strings_stream.read_string(module.name.0).unwrap();
//! println!("{name}: {} types", tables.header.table_locations.type_def.rows.0);
//! ```

mod calculator;
pub mod image_headers;
pub mod metadata_header;
pub mod streams;
use bitflags::bitflags;

/// A raw metadata token: table number in the high byte, 1-based row in the low
/// 24 bits. Nothing in hao produces or consumes it yet; resolved tokens are
/// [`MemberToken`](crate::dotnet::il::MemberToken).
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct MDToken(u32);

bitflags! {
    /// The tables stream header's `HeapSizes` byte (ECMA-335 §II.24.2.6), plus
    /// runtime-specific bits: mostly which heap indexes are 4 bytes wide.
    #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
    #[cfg_attr(feature = "reflect", derive(facet::Facet), facet(opaque))]
    pub struct MDStreamFlags: u8 {
        /// `#Strings` offsets are 4 bytes instead of 2.
        const BigStrings = 1;
        /// `#GUID` indexes are 4 bytes instead of 2.
        const BigGUID = 2;
        /// `#Blob` offsets are 4 bytes instead of 2.
        const BigBlob = 4;
        /// Padding bit; not in ECMA-335, and has no effect on reading.
        const Padding = 8;
        /// The stream holds only Edit and Continue deltas. Not in ECMA-335.
        const DeltaOnly = 0x20;
        /// An extra 4-byte value follows the header's `Sorted` mask. Not in ECMA-335.
        const ExtraData = 0x40;
        /// Some rows may be marked deleted. Not in ECMA-335.
        const HasDelete = 0x80;
    }
}