Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 47 additions & 1 deletion src/symbol/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,9 @@ pub enum SymbolData<'t> {
/// OEM information.
OEM(OemSymbol<'t>),
/// Environment block split off from S_COMPILE2.
EnvBlock(EnvBlockSymbol<'t>)
EnvBlock(EnvBlockSymbol<'t>),
/// A COFF section in a PE executable.
Section(SectionSymbol<'t>),
}

impl<'t> SymbolData<'t> {
Expand Down Expand Up @@ -269,6 +271,7 @@ impl<'t> SymbolData<'t> {
Self::SeparatedCode(_) => None,
Self::OEM(_) => None,
Self::EnvBlock(_) => None,
Self::Section(data) => Some(data.name),
}
}
}
Expand Down Expand Up @@ -327,6 +330,7 @@ impl<'t> TryFromCtx<'t> for SymbolData<'t> {
S_SEPCODE => SymbolData::SeparatedCode(buf.parse_with(kind)?),
S_OEM => SymbolData::OEM(buf.parse_with(kind)?),
S_ENVBLOCK => SymbolData::EnvBlock(buf.parse_with(kind)?),
S_SECTION => SymbolData::Section(buf.parse_with(kind)?),
other => return Err(Error::UnimplementedSymbolKind(other)),
};

Expand Down Expand Up @@ -1713,6 +1717,48 @@ impl<'t> TryFromCtx<'t, SymbolKind> for EnvBlockSymbol <'t> {
}
}

/// A COFF section in a PE executable.
///
/// Symbol kind `S_SECTION`.
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct SectionSymbol<'t> {
/// Section number.
pub isec: u16,
/// Alignment of this section (power of 2).
pub align: u8,
/// Reserved. Must be zero.
pub reserved: u8,
/// Section's RVA.
pub rva: u32,
/// Section's CB.
pub cb: u32,
/// Section characteristics.
pub characteristics: u32,
Comment thread
DanielT marked this conversation as resolved.
Outdated
/// Section name.
pub name: RawString<'t>

}

impl<'t> TryFromCtx<'t, SymbolKind> for SectionSymbol <'t> {
type Error = Error;

fn try_from_ctx(this: &'t [u8], kind: SymbolKind) -> Result<(Self, usize)> {
let mut buf = ParseBuffer::from(this);

let symbol = SectionSymbol {
isec: buf.parse()?,
align: buf.parse()?,
reserved: buf.parse()?,
rva: buf.parse()?,
cb: buf.parse()?,
characteristics: buf.parse()?,
name: parse_symbol_name(&mut buf, kind)?
};

Ok((symbol, buf.pos()))
}
}

/// PDB symbol tables contain names, locations, and metadata about functions, global/static data,
/// constants, data types, and more.
///
Expand Down