Skip to content

Commit 11df38f

Browse files
committed
Add IDiaSourceFile::get_checksum metadata, sample
1 parent aac4e8f commit 11df38f

File tree

5 files changed

+84
-4
lines changed

5 files changed

+84
-4
lines changed

.metadata/options.rsp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@ SymTagEnum
66
__MIDL___MIDL_itf_dia2_0000_0000_0001
77
__MIDL___MIDL_itf_dia2_0000_0033_0001
88
__MIDL___MIDL_itf_dia2_0000_0034_0001
9-
PfnPDBDebugDirV
9+
PfnPDBDebugDirV
10+
--memberRemap
11+
IDiaSourceFile::get_checksum::pbData=[Optional]

.windows/winmd/Microsoft.Dia.winmd

0 Bytes
Binary file not shown.

crates/samples/checksum/Cargo.toml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "sample_checksum"
3+
version = "0.1.0"
4+
edition = "2021"
5+
publish = false
6+
7+
[dependencies.windows]
8+
version = "0.53"
9+
10+
[dependencies.microsoft-dia]
11+
path = "../../../"

crates/samples/checksum/src/main.rs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
use microsoft_dia::{nsNone, DiaSource, IDiaDataSource, SymTagCompiland};
2+
use windows::{
3+
core::*,
4+
Win32::System::Com::{CoInitializeEx, COINIT_MULTITHREADED},
5+
};
6+
7+
fn main() -> Result<()> {
8+
unsafe {
9+
// Initialize COM and DIA
10+
CoInitializeEx(None, COINIT_MULTITHREADED).ok()?;
11+
let source: IDiaDataSource = microsoft_dia::helpers::NoRegCoCreate(
12+
s!(
13+
r#"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\DIA SDK\bin\amd64\msdia140.dll"#
14+
),
15+
&DiaSource,
16+
)?;
17+
18+
// Open session against own symbols
19+
let executable = std::env::current_exe().unwrap();
20+
source.loadDataForExe(&HSTRING::from(executable.as_os_str()), None, None)?;
21+
let session = source.openSession()?;
22+
23+
// Get compilands
24+
let symbols =
25+
session
26+
.globalScope()?
27+
.findChildren(SymTagCompiland, None, nsNone.0 as u32)?;
28+
29+
// Get source files
30+
for i in 0..symbols.Count()? {
31+
let symbol = symbols.Item(i as u32)?;
32+
let files = session.findFile(&symbol, PCWSTR::null(), nsNone.0 as u32)?;
33+
34+
// Find files with a checksum and print out details
35+
for j in 0..files.Count()? {
36+
let file = files.Item(j as u32)?;
37+
if file.checksumType()? == 0 {
38+
continue;
39+
}
40+
41+
let mut byte_count = 0u32;
42+
file.get_checksum(&mut byte_count, None)?;
43+
44+
let mut bytes = vec![0; byte_count as usize];
45+
file.get_checksum(&mut byte_count, Some(&mut bytes))?;
46+
47+
println!("File: {}", file.fileName()?);
48+
println!(
49+
"{:02x}: {}\n",
50+
file.checksumType()?,
51+
bytes
52+
.iter()
53+
.map(|b| format!("{:02x}", b).to_string())
54+
.collect::<String>()
55+
);
56+
}
57+
}
58+
59+
Ok(())
60+
}
61+
}

src/bindings.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4609,13 +4609,19 @@ pub mod Dia {
46094609
pub unsafe fn get_checksum(
46104610
&self,
46114611
pcbdata: *mut u32,
4612-
pbdata: &mut [u8],
4612+
pbdata: ::core::option::Option<&mut [u8]>,
46134613
) -> ::windows_core::Result<()> {
46144614
(::windows_core::Interface::vtable(self).get_checksum)(
46154615
::windows_core::Interface::as_raw(self),
4616-
pbdata.len().try_into().unwrap(),
4616+
pbdata
4617+
.as_deref()
4618+
.map_or(0, |slice| slice.len().try_into().unwrap()),
46174619
pcbdata,
4618-
::core::mem::transmute(pbdata.as_ptr()),
4620+
::core::mem::transmute(
4621+
pbdata
4622+
.as_deref()
4623+
.map_or(::core::ptr::null(), |slice| slice.as_ptr()),
4624+
),
46194625
)
46204626
.ok()
46214627
}

0 commit comments

Comments
 (0)