-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add IDiaSourceFile::get_checksum metadata, sample (#20)
- Loading branch information
Showing
5 changed files
with
84 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[package] | ||
name = "sample_checksum" | ||
version = "0.1.0" | ||
edition = "2021" | ||
publish = false | ||
|
||
[dependencies.windows] | ||
version = "0.53" | ||
|
||
[dependencies.microsoft-dia] | ||
path = "../../../" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
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; | ||
file.get_checksum(&mut byte_count, None)?; | ||
|
||
let mut bytes = vec![0; byte_count as usize]; | ||
file.get_checksum(&mut byte_count, Some(&mut bytes))?; | ||
|
||
println!("File: {}", file.fileName()?); | ||
println!( | ||
"{:02x}: {}\n", | ||
file.checksumType()?, | ||
bytes | ||
.iter() | ||
.map(|b| format!("{:02x}", b).to_string()) | ||
.collect::<String>() | ||
); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters