use crossbeam_skiplist::SkipMap;
use std::fmt;
use std::sync::Arc;
use crate::metadata::token::Token;
metadata_flags! {
pub struct HashAlgorithmId(u32);
}
impl HashAlgorithmId {
pub const NONE: Self = Self(0x0000);
pub const MD5: Self = Self(0x8003);
pub const SHA1: Self = Self(0x8004);
pub const SHA256: Self = Self(0x800C);
pub const SHA384: Self = Self(0x800D);
pub const SHA512: Self = Self(0x800E);
}
impl fmt::Display for HashAlgorithmId {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Self::NONE => write!(f, "None"),
Self::MD5 => write!(f, "MD5"),
Self::SHA1 => write!(f, "SHA1"),
Self::SHA256 => write!(f, "SHA256"),
Self::SHA384 => write!(f, "SHA384"),
Self::SHA512 => write!(f, "SHA512"),
_ => write!(f, "0x{:08X}", self.bits()),
}
}
}
mod builder;
mod loader;
mod owned;
mod raw;
mod reader;
mod writer;
pub use builder::*;
pub(crate) use loader::*;
pub use owned::*;
pub use raw::*;
pub type AssemblyMap = SkipMap<Token, AssemblyRc>;
pub type AssemblyList = Arc<boxcar::Vec<AssemblyRc>>;
pub type AssemblyRc = Arc<Assembly>;
metadata_flags! {
pub struct AssemblyFlags(u32);
}
impl AssemblyFlags {
pub const PUBLIC_KEY: Self = Self(0x0001);
pub const RETARGETABLE: Self = Self(0x0100);
pub const PA_MASK: Self = Self(0x0070);
pub const PA_MSIL: Self = Self(0x0010);
pub const PA_X86: Self = Self(0x0020);
pub const PA_IA64: Self = Self(0x0030);
pub const PA_AMD64: Self = Self(0x0040);
pub const PA_ARM: Self = Self(0x0050);
pub const PA_ARM64: Self = Self(0x0060);
pub const PA_NO_PLATFORM: Self = Self(0x0070);
pub const CONTENT_TYPE_MASK: Self = Self(0x0E00);
pub const CONTENT_TYPE_WINDOWS_RUNTIME: Self = Self(0x0200);
pub const DISABLE_JIT_COMPILE_OPTIMIZER: Self = Self(0x4000);
pub const ENABLE_JIT_COMPILE_TRACKING: Self = Self(0x8000);
#[inline]
#[must_use]
pub const fn processor_architecture(self) -> Self {
Self(self.0 & Self::PA_MASK.0)
}
#[inline]
#[must_use]
pub const fn content_type(self) -> Self {
Self(self.0 & Self::CONTENT_TYPE_MASK.0)
}
#[must_use]
pub fn processor_architecture_keyword(self) -> &'static str {
match self.processor_architecture() {
Self::PA_MSIL => "cil",
Self::PA_X86 => "x86",
Self::PA_IA64 => "ia64",
Self::PA_AMD64 => "amd64",
Self::PA_ARM => "arm",
Self::PA_ARM64 => "arm64",
Self::PA_NO_PLATFORM => "noplatform",
_ => "",
}
}
}
impl fmt::Display for AssemblyFlags {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut parts = Vec::new();
if self.contains(Self::PUBLIC_KEY) {
parts.push("PublicKey");
}
if self.contains(Self::RETARGETABLE) {
parts.push("Retargetable");
}
if self.contains(Self::DISABLE_JIT_COMPILE_OPTIMIZER) {
parts.push("DisableJITOptimizer");
}
if self.contains(Self::ENABLE_JIT_COMPILE_TRACKING) {
parts.push("EnableJITTracking");
}
if parts.is_empty() {
write!(f, "None")
} else {
write!(f, "{}", parts.join(", "))
}
}
}
#[allow(non_snake_case)]
pub mod AssemblyHashAlgorithm {
pub const NONE: u32 = 0x0000;
pub const MD5: u32 = 0x8003;
pub const SHA1: u32 = 0x8004;
pub const SHA256: u32 = 0x800C;
pub const SHA384: u32 = 0x800D;
pub const SHA512: u32 = 0x800E;
}