Skip to content

Commit

Permalink
Fix type reconstruction for arrays with right parts
Browse files Browse the repository at this point in the history
  • Loading branch information
ergrelet committed Mar 12, 2024
1 parent 3584efc commit 5bd715f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 15 deletions.
23 changes: 12 additions & 11 deletions resym_core/src/pdb_types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub fn type_name(
// Resolve the complete type's index, if present in the PDB
let complete_element_type_index =
resolve_complete_type_index(type_forwarder, data.element_type);
let (base_name, mut dimensions) = array_base_name(
let ((type_left, type_right), mut dimensions) = array_base_name(
type_finder,
type_forwarder,
complete_element_type_index,
Expand All @@ -123,8 +123,9 @@ pub fn type_name(
let type_size = u32::try_from(type_size(type_finder, complete_element_type_index)?)?;
let mut divider = if type_size == 0 {
log::warn!(
"'{}' has invalid size (0), array dimensions might be incorrect",
base_name
"'{}{}' has invalid size (0), array dimensions might be incorrect",
type_left,
type_right,
);
1
} else {
Expand All @@ -149,7 +150,7 @@ pub fn type_name(
dimensions_str = format!("{dimensions_str}[{dim}]");
}

(base_name, dimensions_str)
(type_left, format!("{}{}", dimensions_str, type_right))
}

pdb::TypeData::Bitfield(data) => {
Expand Down Expand Up @@ -252,13 +253,13 @@ fn array_base_name(
type_index: pdb::TypeIndex,
primitive_flavor: &PrimitiveReconstructionFlavor,
needed_types: &mut TypeSet,
) -> Result<(String, Vec<usize>)> {
) -> Result<((String, String), Vec<usize>)> {
match type_finder.find(type_index)?.parse()? {
pdb::TypeData::Array(data) => {
// Resolve the complete type's index, if present in the PDB
let complete_element_type_index =
resolve_complete_type_index(type_forwarder, data.element_type);
let (base_name, mut base_dimensions) = array_base_name(
let ((type_left, type_right), mut base_dimensions) = array_base_name(
type_finder,
type_forwarder,
complete_element_type_index,
Expand All @@ -268,8 +269,9 @@ fn array_base_name(
let type_size = u32::try_from(type_size(type_finder, complete_element_type_index)?)?;
let mut divider = if type_size == 0 {
log::warn!(
"'{}' has invalid size (0), array dimensions might be incorrect",
base_name
"'{}{}' has invalid size (0), array dimensions might be incorrect",
type_left,
type_right,
);
1
} else {
Expand All @@ -287,7 +289,7 @@ fn array_base_name(
.collect::<Vec<_>>();
base_dimensions.append(&mut dimensions_elem_count);

Ok((base_name, base_dimensions))
Ok(((type_left, type_right), base_dimensions))
}
_ => Ok((
type_name(
Expand All @@ -296,8 +298,7 @@ fn array_base_name(
type_index,
primitive_flavor,
needed_types,
)?
.0,
)?,
vec![],
)),
}
Expand Down
7 changes: 7 additions & 0 deletions resym_core/tests/data/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,13 @@ struct NestedStructUnionRegression1 {
}; /* size: 0x0008 */
};

struct NtdllRegression1 {
VOID(*KernelRoutine)
(struct _KAPC* arg1, VOID (**arg2)(VOID* arg1, VOID* arg2, VOID* arg3),
VOID** arg3, VOID** arg4, VOID** arg5);
LONG (*MajorFunction[28])(struct _DEVICE_OBJECT* arg1, struct _IRP* arg2);
};

} // namespace resym_test

int main() {
Expand Down
Binary file modified resym_core/tests/data/test.pdb
Binary file not shown.
6 changes: 2 additions & 4 deletions resym_core/tests/module_dumping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ const TEST_MODULE_PATH: &str = "D:\\a\\_work\\1\\s\\Intermediate\\crt\\vcstartup

#[test]
fn test_module_dumping_by_path_portable() {
let mut pdb_file =
PdbFile::load_from_file(Path::new(TEST_PDB_FILE_PATH)).expect("load test.pdb");
let pdb_file = PdbFile::load_from_file(Path::new(TEST_PDB_FILE_PATH)).expect("load test.pdb");

let module_dump = pdb_file
.reconstruct_module_by_path(TEST_MODULE_PATH, PrimitiveReconstructionFlavor::Portable)
Expand Down Expand Up @@ -50,8 +49,7 @@ fn test_module_dumping_by_index_internal(
module_index: usize,
primitives_flavor: PrimitiveReconstructionFlavor,
) {
let mut pdb_file =
PdbFile::load_from_file(Path::new(TEST_PDB_FILE_PATH)).expect("load test.pdb");
let pdb_file = PdbFile::load_from_file(Path::new(TEST_PDB_FILE_PATH)).expect("load test.pdb");

let module_dump = pdb_file
.reconstruct_module_by_index(module_index, primitives_flavor)
Expand Down

0 comments on commit 5bd715f

Please sign in to comment.