Skip to content

Commit

Permalink
Parser: read optional PROJECTCOMPATVERSION Record.
Browse files Browse the repository at this point in the history
This record is optional and according to the OBVA documentation not
written by VBA 5.0. Previously, if this record was found, the parser
would simply panic.
  • Loading branch information
JanMarvin committed Dec 19, 2024
1 parent 41290a1 commit b35d437
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ pub enum Reference {
pub struct Information {
/// Specifies the platform for which the VBA project is created.
pub sys_kind: SysKind,
compat: Option<u32>,
lcid: u32,
lcid_invoke: u32,
/// Specifies the code page for the VBA project.
Expand Down
16 changes: 15 additions & 1 deletion src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,21 @@ fn parse_syskind(i: &[u8]) -> IResult<&[u8], SysKind, FormatError<&[u8]>> {
}
}

fn parse_compat(i: &[u8]) -> IResult<&[u8], Option<u32>, FormatError<&[u8]>> {
const COMPAT_SIGNATURE: &[u8] = &[0x4A, 0x00];
let (i, compat) = opt(preceded(
tuple((tag(COMPAT_SIGNATURE), tag(U32_FIXED_SIZE_4))),
le_u32,
))(i)?;
Ok((i, compat))
}

fn parse_lcid(i: &[u8]) -> IResult<&[u8], u32, FormatError<&[u8]>> {
const LCID_SIGNATURE: &[u8] = &[0x02, 0x00];
let (i, lcid) = preceded(tuple((tag(LCID_SIGNATURE), tag(U32_FIXED_SIZE_4))), le_u32)(i)?;
let (i, lcid) = preceded(
tuple((tag(LCID_SIGNATURE), tag(U32_FIXED_SIZE_4))),
le_u32,
)(i)?;
Ok((i, lcid))
}

Expand Down Expand Up @@ -562,6 +574,7 @@ pub(crate) fn parse_project_information(
i: &[u8],
) -> IResult<&[u8], ProjectInformation, FormatError<&[u8]>> {
let (i, sys_kind) = parse_syskind(i)?;
let (i, compat) = parse_compat(i)?;
let (i, lcid) = parse_lcid(i)?;
let (i, lcid_invoke) = parse_lcid_invoke(i)?;
let (i, code_page) = parse_code_page(i)?;
Expand Down Expand Up @@ -619,6 +632,7 @@ pub(crate) fn parse_project_information(
ProjectInformation {
information: Information {
sys_kind,
compat,
lcid,
lcid_invoke,
code_page,
Expand Down

0 comments on commit b35d437

Please sign in to comment.