зеркало из https://github.com/microsoft/dia-rs.git
Add IDiaSourceFile::get_checksum metadata, sample (#20)
This commit is contained in:
Родитель
0b10cf0654
Коммит
8f7353141a
|
@ -6,4 +6,6 @@ SymTagEnum
|
|||
__MIDL___MIDL_itf_dia2_0000_0000_0001
|
||||
__MIDL___MIDL_itf_dia2_0000_0033_0001
|
||||
__MIDL___MIDL_itf_dia2_0000_0034_0001
|
||||
PfnPDBDebugDirV
|
||||
PfnPDBDebugDirV
|
||||
--memberRemap
|
||||
IDiaSourceFile::get_checksum::pbData=[Optional]
|
||||
|
|
Двоичные данные
.windows/winmd/Microsoft.Dia.winmd
Двоичные данные
.windows/winmd/Microsoft.Dia.winmd
Двоичный файл не отображается.
|
@ -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 = "../../../"
|
|
@ -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(())
|
||||
}
|
||||
}
|
|
@ -4609,13 +4609,19 @@ pub mod Dia {
|
|||
pub unsafe fn get_checksum(
|
||||
&self,
|
||||
pcbdata: *mut u32,
|
||||
pbdata: &mut [u8],
|
||||
pbdata: ::core::option::Option<&mut [u8]>,
|
||||
) -> ::windows_core::Result<()> {
|
||||
(::windows_core::Interface::vtable(self).get_checksum)(
|
||||
::windows_core::Interface::as_raw(self),
|
||||
pbdata.len().try_into().unwrap(),
|
||||
pbdata
|
||||
.as_deref()
|
||||
.map_or(0, |slice| slice.len().try_into().unwrap()),
|
||||
pcbdata,
|
||||
::core::mem::transmute(pbdata.as_ptr()),
|
||||
::core::mem::transmute(
|
||||
pbdata
|
||||
.as_deref()
|
||||
.map_or(::core::ptr::null(), |slice| slice.as_ptr()),
|
||||
),
|
||||
)
|
||||
.ok()
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче