use crate::{
metadata::{
tables::{
types::{CodedIndex, CodedIndexType, TableInfoRef},
CustomDebugInformationRaw, RowReadable, TableId,
},
token::Token,
},
utils::read_le_at_dyn,
Result,
};
impl RowReadable for CustomDebugInformationRaw {
const TABLE_ID: TableId = TableId::CustomDebugInformation;
fn row_read(data: &[u8], offset: &mut usize, rid: u32, sizes: &TableInfoRef) -> Result<Self> {
let offset_org = *offset;
let parent = CodedIndex::read(
data,
offset,
sizes,
CodedIndexType::HasCustomDebugInformation,
)?;
let kind = read_le_at_dyn(data, offset, sizes.is_large_guid())?;
let value = read_le_at_dyn(data, offset, sizes.is_large_blob())?;
Ok(CustomDebugInformationRaw {
rid,
token: Token::new(0x3700_0000 + rid),
offset: offset_org,
parent,
kind,
value,
})
}
}
#[cfg(test)]
mod tests {
use std::sync::Arc;
use super::*;
use crate::metadata::tables::{MetadataTable, TableId, TableInfo};
#[test]
fn crafted_short() {
let data = vec![
0x06, 0x00, 0x01, 0x00, 0x0A, 0x00, ];
let sizes = Arc::new(TableInfo::new_test(
&[
(TableId::CustomDebugInformation, 1),
(TableId::MethodDef, 1000),
],
false,
false,
false,
));
let table = MetadataTable::<CustomDebugInformationRaw>::new(&data, 1, sizes).unwrap();
let eval = |row: CustomDebugInformationRaw| {
assert_eq!(row.rid, 1);
assert_eq!(row.token.value(), 0x37000001);
assert_eq!(row.parent.row, 0);
assert_eq!(row.kind, 0x0001);
assert_eq!(row.value, 0x000A);
};
{
for row in table.iter() {
eval(row);
}
}
{
let row = table.get(1).unwrap();
eval(row);
}
}
#[test]
fn crafted_long() {
let data = vec![
0x06, 0x01, 0x00,
0x00, 0x01, 0x01, 0x00, 0x00, 0x0A, 0x02, 0x00, 0x00, ];
let sizes = Arc::new(TableInfo::new_test(
&[
(TableId::CustomDebugInformation, 1),
(TableId::MethodDef, 100000),
],
true,
true,
true,
));
let table = MetadataTable::<CustomDebugInformationRaw>::new(&data, 1, sizes).unwrap();
let eval = |row: CustomDebugInformationRaw| {
assert_eq!(row.rid, 1);
assert_eq!(row.token.value(), 0x37000001);
assert_eq!(row.parent.row, 8);
assert_eq!(row.kind, 0x00000101);
assert_eq!(row.value, 0x0000020A);
};
{
for row in table.iter() {
eval(row);
}
}
{
let row = table.get(1).unwrap();
eval(row);
}
}
}