Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser: read optional PROJECTCOMPATVERSION Record. #21

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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
11 changes: 11 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,15 @@ 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)?;
Expand Down Expand Up @@ -562,6 +571,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 +629,7 @@ pub(crate) fn parse_project_information(
ProjectInformation {
information: Information {
sys_kind,
compat,
lcid,
lcid_invoke,
code_page,
Expand Down