getsentry / pdb

A parser for Microsoft PDB (Program Database) debugging information
https://docs.rs/pdb/
Apache License 2.0
367 stars 68 forks source link

Add convenience accessors for ImageSectionHeader characteristics #106

Closed mstange closed 2 years ago

mstange commented 2 years ago

The characteristics field of ImageSectionHeader is currently only exposed as a raw u32. Moreover, it looks like the IMAGE_SCN_ constants are not exposed.

This could be made more ergonomic. For example, there could be a section.is_executable() method.

mstange commented 2 years ago
/// The section should not be padded to the next boundary. This flag is
/// obsolete and is replaced by `IMAGE_SCN_ALIGN_1BYTES`.
pub const IMAGE_SCN_TYPE_NO_PAD: u32 = 0x00000008;
/// The section contains executable code.
pub const IMAGE_SCN_CNT_CODE: u32 = 0x00000020;
/// The section contains initialized data.
pub const IMAGE_SCN_CNT_INITIALIZED_DATA: u32 = 0x00000040;
/// The section contains uninitialized data.
pub const IMAGE_SCN_CNT_UNINITIALIZED_DATA: u32 = 0x00000080;
/// Reserved.
pub const IMAGE_SCN_LNK_OTHER: u32 = 0x00000100;
/// The section contains comments or other information. This is valid only for object files.
pub const IMAGE_SCN_LNK_INFO: u32 = 0x00000200;
/// The section will not become part of the image. This is valid only for object files.
pub const IMAGE_SCN_LNK_REMOVE: u32 = 0x00000800;
/// The section contains COMDAT data. This is valid only for object files.
pub const IMAGE_SCN_LNK_COMDAT: u32 = 0x00001000;
/// Reset speculative exceptions handling bits in the TLB entries for this section.
pub const IMAGE_SCN_NO_DEFER_SPEC_EXC: u32 = 0x00004000;
/// The section contains data referenced through the global pointer.
pub const IMAGE_SCN_GPREL: u32 = 0x00008000;
/// Reserved.
pub const IMAGE_SCN_MEM_PURGEABLE: u32 = 0x00020000;
/// Reserved.
pub const IMAGE_SCN_MEM_LOCKED: u32 = 0x00040000;
/// Reserved.
pub const IMAGE_SCN_MEM_PRELOAD: u32 = 0x00080000;
/// Align data on a 1-byte boundary. This is valid only for object files.
pub const IMAGE_SCN_ALIGN_1BYTES: u32 = 0x00100000;
/// Align data on a 2-byte boundary. This is valid only for object files.
pub const IMAGE_SCN_ALIGN_2BYTES: u32 = 0x00200000;
/// Align data on a 4-byte boundary. This is valid only for object files.
pub const IMAGE_SCN_ALIGN_4BYTES: u32 = 0x00300000;
/// Align data on a 8-byte boundary. This is valid only for object files.
pub const IMAGE_SCN_ALIGN_8BYTES: u32 = 0x00400000;
/// Align data on a 16-byte boundary. This is valid only for object files.
pub const IMAGE_SCN_ALIGN_16BYTES: u32 = 0x00500000;
/// Align data on a 32-byte boundary. This is valid only for object files.
pub const IMAGE_SCN_ALIGN_32BYTES: u32 = 0x00600000;
/// Align data on a 64-byte boundary. This is valid only for object files.
pub const IMAGE_SCN_ALIGN_64BYTES: u32 = 0x00700000;
/// Align data on a 128-byte boundary. This is valid only for object files.
pub const IMAGE_SCN_ALIGN_128BYTES: u32 = 0x00800000;
/// Align data on a 256-byte boundary. This is valid only for object files.
pub const IMAGE_SCN_ALIGN_256BYTES: u32 = 0x00900000;
/// Align data on a 512-byte boundary. This is valid only for object files.
pub const IMAGE_SCN_ALIGN_512BYTES: u32 = 0x00A00000;
/// Align data on a 1024-byte boundary. This is valid only for object files.
pub const IMAGE_SCN_ALIGN_1024BYTES: u32 = 0x00B00000;
/// Align data on a 2048-byte boundary. This is valid only for object files.
pub const IMAGE_SCN_ALIGN_2048BYTES: u32 = 0x00C00000;
/// Align data on a 4096-byte boundary. This is valid only for object files.
pub const IMAGE_SCN_ALIGN_4096BYTES: u32 = 0x00D00000;
/// Align data on a 8192-byte boundary. This is valid only for object files.
pub const IMAGE_SCN_ALIGN_8192BYTES: u32 = 0x00E00000;
/// The section contains extended relocations. The count of relocations for the
/// section exceeds the 16 bits that is reserved for it in the section header.
/// If the `number_of_relocations` field in the section header is `0xffff`, the
/// actual relocation count is stored in the `virtual_address` field of the first
/// relocation. It is an error if `IMAGE_SCN_LNK_NRELOC_OVFL` is set and there
/// are fewer than `0xffff` relocations in the section.
pub const IMAGE_SCN_LNK_NRELOC_OVFL: u32 = 0x01000000;
/// The section can be discarded as needed.
pub const IMAGE_SCN_MEM_DISCARDABLE: u32 = 0x02000000;
/// The section cannot be cached.
pub const IMAGE_SCN_MEM_NOT_CACHED: u32 = 0x04000000;
/// The section cannot be paged.
pub const IMAGE_SCN_MEM_NOT_PAGED: u32 = 0x08000000;
/// The section can be shared in memory.
pub const IMAGE_SCN_MEM_SHARED: u32 = 0x10000000;
/// The section can be executed as code.
pub const IMAGE_SCN_MEM_EXECUTE: u32 = 0x20000000;
/// The section can be read.
pub const IMAGE_SCN_MEM_READ: u32 = 0x40000000;
/// The section can be written to.
pub const IMAGE_SCN_MEM_WRITE: u32 = 0x80000000;