Giter VIP home page Giter VIP logo

dia-rs's Introduction

crates.io

Rust for Debug Interface Access (DIA) SDK

The Microsoft Debug Interface Access Software Development Kit (DIA SDK) provides access to debug information stored in program database (.pdb) files generated by Microsoft postcompiler tools.

Start by adding windows and microsoft-dia dependencies to Cargo.toml:

[dependencies.windows]
version = "0.53.0"
features = [
    "Win32_System_Com"
]

[dependencies.microsoft-dia]
version = "0.10.0"

Make use of any DIA SDK APIs as needed.

use microsoft_dia::{nsfRegularExpression, DiaSource, IDiaDataSource, SymTagFunction};
use windows::{core::*, Win32::System::Com::{CoInitializeEx, COINIT_MULTITHREADED}};

fn main() -> windows::core::Result<()> {
    unsafe {
        CoInitializeEx(None, COINIT_MULTITHREADED)?;

        let source: IDiaDataSource = microsoft_dia::helpers::NoRegCoCreate(s!("msdia140.dll"), &DiaSource)?;
        let executable = std::env::current_exe().unwrap();
        source.loadDataForExe(&HSTRING::from(executable.as_os_str()), None, None)?;

        let session = source.openSession()?;
        let symbols = session.globalScope()?.findChildren(SymTagFunction, w!("sample_functions::*"), nsfRegularExpression.0 as u32)?;

        println!("Function symbols found in sample_functions::* ({}):", &executable.to_string_lossy());

        for i in 0..symbols.Count()? {
            println!("\t{}", symbols.Item(i as u32)?.name()?);
        }

        Ok(())
    }
}

dia-rs's People

Contributors

kennykerr avatar microsoft-github-operations[bot] avatar microsoftopensource avatar riverar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

dia-rs's Issues

get_sourceLink appears to need the same optional bindings as get_checksum

Thank you for your help as I stumble through some fun projects using .pdb's.

I've come to ask for some assistance with get_sourceLink. Since this method also needs to be called twice, once to get the length to allocate, then again to get the contents I wanted to see if the same fix applied for get_checksum is applicable here.

The second question is that I just don't see which symbol to actually call get_sourceLink on. My understanding was the sourceLink is an entire table of json formatted information and I could use a bit of hand-holding if you folks have the time on the proper way to invoke this to extract the information.

Thank you very much in advance. This is the last piece of my PDB puzzle.

  • Jeromy

‎Dia::IDiaSourceFile::get_checksum implementation does not work properly

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:

let mut checksum = Vec::<u8>::new();
unsafe {
    // Get the size of the checksum buffer
    let mut cbdata = 0;
    (windows::core::Interface::vtable(&self.source_file).get_checksum)(
        windows::core::Interface::as_raw(&self.source_file),
        0,
        &mut cbdata,
        std::ptr::null_mut()).unwrap();

    // Create a buffer to hold the checksum
    checksum.resize(cbdata as usize, 0);

    // Retrieve the checksum into the buffer
    (windows::core::Interface::vtable(&self.source_file).get_checksum)(
        windows::core::Interface::as_raw(&self.source_file),
        cbdata,
        &mut cbdata,
        checksum.as_mut_ptr()).unwrap();
}

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!

0x806D0005/E_PDB_NOT_FOUND HRESULT for valid(?) loadDataForExe call

Browsing Stack Overflow yielded no solutions, so I thought it would be appropriate to ask here. This is more likely than not a "user" issue from my end, but I wasn't sure if it would've been appropriate to reach out via email, hence this issue.

Here was my attempt:

CoInitializeEx(None, COINIT_MULTITHREADED).ok()?;
let source: IDiaDataSource = microsoft_dia::helpers::NoRegCoCreate(s!("msdia140.dll"), &DiaSource)?;
let binary = HSTRING::from("C:\\Windows\\System32\\ntdll.dll");
let symsrv = HSTRING::from("srv*https://msdl.microsoft.com/download/symbols");
source.loadDataForExe(&binary, &symsrv, None)?;

Which gave me the following error:
Error: Error { code: HRESULT(0x806D0005), message: "" }

Placing symsrv.dll inside the same directory as the binary, as suggested inside the documentation for DIA, didn't solve this either.

Thinking I might get some more insight handling the callback, I tried the following:

let callback = IDiaLoadCallback::from_default(&None)?;

This, however, gave a rather confusing error message:
Error: Error { code: HRESULT(0x00000000), message: "The operation completed successfully." }

Maybe I missed something regarding the initialization of IDiaLoadCallback, but using from_default was the only appropriate method I found.

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.