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.

The second change changes the backslash to slash. This allows using ovba
on Mac (and probably Linux).
  • Loading branch information
JanMarvin committed Dec 12, 2024
1 parent 8769b09 commit 269b8af
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
5 changes: 3 additions & 2 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 Expand Up @@ -310,7 +311,7 @@ impl Project {
.find(|&module| module.name == name)
.ok_or_else(|| Error::ModuleNotFound(name.to_owned()))?;

let path = format!("/VBA\\{}", &module.stream_name);
let path = format!("/VBA/{}", &module.stream_name);
let offset = module.text_offset;
let src_code = self.decompress_stream_from(path, offset)?;

Expand Down Expand Up @@ -346,7 +347,7 @@ pub fn open_project(raw: Vec<u8>) -> Result<Project> {
let mut container = CompoundFile::open(cursor).map_err(Error::Cfb)?;

// Read *dir* stream
const DIR_STREAM_PATH: &str = r#"/VBA\dir"#;
const DIR_STREAM_PATH: &str = r#"/VBA/dir"#;

let mut buffer = Vec::new();
container
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 @@ -558,6 +570,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 @@ -604,6 +617,7 @@ pub(crate) fn parse_project_information(
ProjectInformation {
information: Information {
sys_kind,
compat,
lcid,
lcid_invoke,
code_page,
Expand Down

0 comments on commit 269b8af

Please sign in to comment.