Skip to content
This repository has been archived by the owner on Dec 9, 2020. It is now read-only.

Basic winmd parsing support #1

Merged
merged 132 commits into from
Nov 4, 2019
Merged

Basic winmd parsing support #1

merged 132 commits into from
Nov 4, 2019

Conversation

kennykerr
Copy link
Contributor

@kennykerr kennykerr commented Nov 1, 2019

This is certainly not done but I'd love some early feedback so I'm putting it out for review. The idea is to provide a winmd reader, similar in spirit to the C++ winmd library used by C++/WinRT, that is natural and familiar to Rust developers. This will be the primary dependency of the Rust/WinRT projection and provide just-in-time projection of WinRT APIs into Rust.

Things that are mostly done:

  • Database - this involves cracking the actual PE file format and finding all of the ECMA 335 streams and tables.
  • Reader - this is analogous to the C++ cache class and provides a convenient starting point for dealing with metadata.
  • Basic database -> tables -> signature query and iteration works.

Things that need more work:

  • Many of the tables don't yet have any or all of their columns defined.
  • Attributing parsing.
  • The library needs it's own Result and Error types.
  • I'd like to get rid of the unsafe code inside the Database and instead simply read the values based on offsets.
  • Lots of testing.

src/reader.rs Outdated Show resolved Hide resolved
use std::io::Result;
use std::vec::*;

// TODO: what about using std::io::Read?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be interested in checking out byteorder: https://docs.rs/byteorder/1.3.2/byteorder/

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to keep dependencies to a minimum and only those that are absolutely essential. For example, I suspect I'll need a dependency on the syn crate for the WinRT projection. 😉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair. I'd still suggest taking a look to see if you can steal some ideas ;-)

src/signatures.rs Outdated Show resolved Hide resolved
src/signatures.rs Outdated Show resolved Hide resolved
tests/dump.rs Outdated Show resolved Hide resolved
tests/reader.rs Show resolved Hide resolved
Cargo.toml Show resolved Hide resolved
src/reader.rs Outdated Show resolved Hide resolved
src/reader.rs Show resolved Hide resolved
let db = Database::new(filename)?;
for t in db.type_def().iter::<TypeDef>() {
if t.flags()?.windows_runtime() {
let types = namespaces.entry(t.namespace()?.to_string()).or_insert_with(|| NamespaceData { ..Default::default() });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not derive Default for NamespaceData?

@kennykerr
Copy link
Contributor Author

Going to stop there. That's (more than) enough for one PR but provides a good starting point for subsequent work. Lots more to do though. We'll address the remaining open issues in this PR separately. @rylev, thanks for all the feedback!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants