Skip to content

Commit

Permalink
Implement module dumping for resymc
Browse files Browse the repository at this point in the history
  • Loading branch information
ergrelet committed Mar 6, 2024
1 parent e42ea20 commit 79e77bd
Show file tree
Hide file tree
Showing 6 changed files with 300 additions and 49 deletions.
61 changes: 61 additions & 0 deletions resym_core/tests/module_dumping.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
use std::path::Path;

use resym_core::{pdb_file::PdbFile, pdb_types::PrimitiveReconstructionFlavor};

const TEST_PDB_FILE_PATH: &str = "tests/data/test.pdb";
const TEST_MODULE_INDEX: usize = 27;
const TEST_MODULE_PATH: &str = "D:\\a\\_work\\1\\s\\Intermediate\\crt\\vcstartup\\build\\xmd\\msvcrt_kernel32\\msvcrt_kernel32.nativeproj\\objd\\amd64\\default_local_stdio_options.obj";

#[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 module_dump = pdb_file
.reconstruct_module_by_path(TEST_MODULE_PATH, PrimitiveReconstructionFlavor::Portable)
.unwrap_or_else(|_| panic!("module dumping"));

insta::assert_snapshot!("module_dumping_by_path_portable", module_dump);
}

#[test]
fn test_module_dumping_by_index_portable() {
test_module_dumping_by_index_internal(
"module_dumping_by_index_portable",
TEST_MODULE_INDEX,
PrimitiveReconstructionFlavor::Portable,
);
}

#[test]
fn test_module_dumping_by_index_microsoft() {
test_module_dumping_by_index_internal(
"module_dumping_by_index_microsoft",
TEST_MODULE_INDEX,
PrimitiveReconstructionFlavor::Microsoft,
);
}

#[test]
fn test_module_dumping_by_index_raw() {
test_module_dumping_by_index_internal(
"module_dumping_by_index_raw",
TEST_MODULE_INDEX,
PrimitiveReconstructionFlavor::Raw,
);
}

fn test_module_dumping_by_index_internal(
snapshot_name: &str,
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 module_dump = pdb_file
.reconstruct_module_by_index(module_index, primitives_flavor)
.unwrap_or_else(|_| panic!("module dumping"));

insta::assert_snapshot!(snapshot_name, module_dump);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: resym_core/tests/module_dumping.rs
expression: module_dump
---
using namespace std;
using PUWSTR_C = const WCHAR*;
using TP_CALLBACK_ENVIRON_V3 = _TP_CALLBACK_ENVIRON_V3;
PULONGLONG (__local_stdio_scanf_options)(); // CodeSize=8
ULONGLONG _OptionsStorage;
VOID (__scrt_initialize_default_local_stdio_options)(); // CodeSize=69
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: resym_core/tests/module_dumping.rs
expression: module_dump
---
using namespace std;
using PUWSTR_C = const wchar_t*;
using TP_CALLBACK_ENVIRON_V3 = _TP_CALLBACK_ENVIRON_V3;
uint64_t* (__local_stdio_scanf_options)(); // CodeSize=8
uint64_t _OptionsStorage;
void (__scrt_initialize_default_local_stdio_options)(); // CodeSize=69
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: resym_core/tests/module_dumping.rs
expression: module_dump
---
using namespace std;
using PUWSTR_C = const wchar_t*;
using TP_CALLBACK_ENVIRON_V3 = _TP_CALLBACK_ENVIRON_V3;
unsigned __int64* (__local_stdio_scanf_options)(); // CodeSize=8
unsigned __int64 _OptionsStorage;
void (__scrt_initialize_default_local_stdio_options)(); // CodeSize=69
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
source: resym_core/tests/module_dumping.rs
expression: module_dump
---
using namespace std;
using PUWSTR_C = const wchar_t*;
using TP_CALLBACK_ENVIRON_V3 = _TP_CALLBACK_ENVIRON_V3;
uint64_t* (__local_stdio_scanf_options)(); // CodeSize=8
uint64_t _OptionsStorage;
void (__scrt_initialize_default_local_stdio_options)(); // CodeSize=69
Loading

0 comments on commit 79e77bd

Please sign in to comment.