-
Notifications
You must be signed in to change notification settings - Fork 7
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
Dia::IDiaSourceFile::get_checksum implementation does not work properly #18
Comments
Hey @JeromySt, here's a sample. It's slightly inefficient; it allocates a 256 byte buffer up front, due to [package]
name = "sample_checksum"
version = "0.1.0"
edition = "2021"
publish = false
[dependencies.windows]
version = "0.53"
[dependencies.microsoft-dia]
version = "0.10.0" use microsoft_dia::{nsNone, DiaSource, IDiaDataSource, SymTagCompiland};
use windows::{
core::*,
Win32::System::Com::{CoInitializeEx, COINIT_MULTITHREADED},
};
fn main() -> Result<()> {
unsafe {
// Initialize COM and DIA
CoInitializeEx(None, COINIT_MULTITHREADED).ok()?;
let source: IDiaDataSource = microsoft_dia::helpers::NoRegCoCreate(
s!(
r#"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\DIA SDK\bin\amd64\msdia140.dll"#
),
&DiaSource,
)?;
// Open session against own symbols
let executable = std::env::current_exe().unwrap();
source.loadDataForExe(&HSTRING::from(executable.as_os_str()), None, None)?;
let session = source.openSession()?;
// Get compilands
let symbols =
session
.globalScope()?
.findChildren(SymTagCompiland, None, nsNone.0 as u32)?;
// Get source files
for i in 0..symbols.Count()? {
let symbol = symbols.Item(i as u32)?;
let files = session.findFile(&symbol, PCWSTR::null(), nsNone.0 as u32)?;
// Find files with a checksum and print out details
for j in 0..files.Count()? {
let file = files.Item(j as u32)?;
if file.checksumType()? == 0 {
continue;
}
let mut byte_count = 0u32;
let mut bytes = vec![0; 256];
file.get_checksum(&mut byte_count, &mut bytes)?;
bytes.truncate(byte_count as usize);
println!("File: {}", file.fileName()?);
println!(
"{:02x}: {}\n",
file.checksumType()?,
bytes
.iter()
.map(|b| format!("{:02x}", b).to_string())
.collect::<String>()
);
}
}
Ok(())
}
} |
Thank you for the example!
Quite helpful. I was iterating over quite a few different methods (new to Rust, so sorry about the simple questions), but could not get Vec::u8::new() to do the same thing that you just did with vec![0; 256]. Trying to figure out how to get a &mut [u8] from Vec<u8> was driving me up a wall, but I also was trying to use the API, like I did from C#.
I leveraged your example below and all seems in order.
I will close the issue, unless you'd like to use it to track the missing [Optional] metadata issue.
tx
Jeromy Statia
…________________________________
From: Rafael Rivera ***@***.***>
Sent: Tuesday, March 26, 2024 8:26 PM
To: microsoft/dia-rs ***@***.***>
Cc: Mention ***@***.***>; Author ***@***.***>
Subject: Re: [microsoft/dia-rs] Dia::IDiaSourceFile::get_checksum implementation does not work properly (Issue #18)
Hey @JeromySt<https://github.com/JeromySt>, here's a sample. It's slightly inefficient; it allocates a 256 byte buffer up front, due to get_checksum not accepting a null pbdata. (This is a crate metadata issue, this method parameter isn't marked as [Optional]. I'll get this fixed.)
[package]
name = "sample_checksum"
version = "0.1.0"
edition = "2021"
publish = false
[dependencies.windows]
version = "0.53"
features = [
"implement",
"Win32_Foundation",
"Win32_System_Com",
"Win32_System_LibraryLoader",
"Win32_System_Com_StructuredStorage",
"Win32_System_Ole"
]
[dependencies.microsoft-dia]
version = "0.10.0"
use microsoft_dia::{nsNone, DiaSource, IDiaDataSource, SymTagCompiland};
use windows::{
core::*,
Win32::System::Com::{CoInitializeEx, COINIT_MULTITHREADED},
};
fn main() -> Result<()> {
unsafe {
// Initialize COM and DIA
CoInitializeEx(None, COINIT_MULTITHREADED).ok()?;
let source: IDiaDataSource = microsoft_dia::helpers::NoRegCoCreate(
s!(
r#"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\DIA SDK\bin\amd64\msdia140.dll"#
),
&DiaSource,
)?;
// Open session against own symbols
let executable = std::env::current_exe().unwrap();
source.loadDataForExe(&HSTRING::from(executable.as_os_str()), None, None)?;
let session = source.openSession()?;
// Get compilands
let symbols =
session
.globalScope()?
.findChildren(SymTagCompiland, None, nsNone.0 as u32)?;
// Get source files
for i in 0..symbols.Count()? {
let symbol = symbols.Item(i as u32)?;
let files = session.findFile(&symbol, PCWSTR::null(), nsNone.0 as u32)?;
// Find files with a checksum and print out details
for j in 0..files.Count()? {
let file = files.Item(j as u32)?;
if file.checksumType()? == 0 {
continue;
}
let mut byte_count = 0u32;
let mut bytes = vec![0; 256];
file.get_checksum(&mut byte_count, &mut bytes)?;
bytes.set_len(byte_count as usize);
println!("File: {}", file.fileName()?);
println!(
"{:02x}: {}\n",
file.checksumType()?,
bytes
.iter()
.map(|b| format!("{:02x}", b).to_string())
.collect::<String>()
);
}
}
Ok(())
}
}
—
Reply to this email directly, view it on GitHub<#18 (comment)> or unsubscribe<https://github.com/notifications/unsubscribe-auth/AC7XYFPH2RQBJLNLKT4YVGLY2I36VBFKMF2HI4TJMJ2XIZLTSOBKK5TBNR2WLJDUOJ2WLJDOMFWWLO3UNBZGKYLEL5YGC4TUNFRWS4DBNZ2F6YLDORUXM2LUPGBKK5TBNR2WLJDUOJ2WLJDOMFWWLLTXMF2GG2C7MFRXI2LWNF2HTAVFOZQWY5LFUVUXG43VMWSG4YLNMWVXI2DSMVQWIX3UPFYGLLDTOVRGUZLDORPXI6LQMWWES43TOVSUG33NNVSW45FGORXXA2LDOOJIFJDUPFYGLKTSMVYG643JORXXE6NFOZQWY5LFVE2DEOJVGA4TKMZUQKSHI6LQMWSWS43TOVS2K5TBNR2WLKRSGIYDSNBTGY3TSNNHORZGSZ3HMVZKMY3SMVQXIZI>.
You are receiving this email because you were mentioned.
Triage notifications on the go with GitHub Mobile for iOS<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675> or Android<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am trying to leverage the DIA SDK in rust using this crate (Thank You!).
I have been able to flawlessly use it, except for when I tried to leverage Dia::IDiaSourceFile::get_checksum(...). I was unable to find any variation that allowed that API to work properly.
I ended up using something like:
To workaround the issue.
I saw that this method was implemented by windows-bindgen and I was curious if this is a bug, or if it would be worthwhile to investigate this issue for bindgen?
Thank you again for all of this great work!
The text was updated successfully, but these errors were encountered: