Created
April 28, 2023 18:28
-
-
Save kennykerr/975a1baf184ec9b235b537179f2b21b5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
use windows_metadata::reader::*; | |
fn main() { | |
let files = File::with_default(&[]).unwrap(); | |
let reader = &Reader::new(&files); | |
let mut collisions = std::collections::BTreeMap::<(&str, bool), Vec<&str>>::new(); | |
for namespace in reader.namespaces() { | |
if namespace.starts_with("Windows.Wdk") { | |
continue; | |
} | |
for method in reader.namespace_functions(namespace) { | |
let name = reader.method_def_name(method); | |
collisions | |
.entry((name, has_arch(reader, reader.method_def_attributes(method)))) | |
.or_default() | |
.push(namespace); | |
} | |
for field in reader.namespace_constants(namespace) { | |
let name = reader.field_name(field); | |
collisions | |
.entry((name, has_arch(reader, reader.field_attributes(field)))) | |
.or_default() | |
.push(namespace); | |
} | |
for def in reader.namespace_types(namespace, &Default::default()) { | |
if reader.type_def_flags(def).contains(TypeAttributes::WINRT) { | |
continue; | |
} | |
let name = reader.type_def_name(def); | |
let kind = reader.type_def_kind(def); | |
if kind == TypeKind::Class && name == "Apis" { | |
continue; | |
} | |
collisions | |
.entry((name, has_arch(reader, reader.type_def_attributes(def)))) | |
.or_default() | |
.push(namespace); | |
if kind == TypeKind::Enum && !reader.type_def_is_scoped(def) { | |
for field in reader.type_def_fields(def) { | |
let name = reader.field_name(field); | |
if reader.field_flags(field).contains(FieldAttributes::LITERAL) { | |
collisions | |
.entry((name, has_arch(reader, reader.field_attributes(field)))) | |
.or_default() | |
.push(namespace); | |
} | |
} | |
} | |
} | |
} | |
for (count, ((name, _), namespaces)) in collisions | |
.iter() | |
.filter(|((_, has_arch), namespaces)| !has_arch && namespaces.len() > 1) | |
.enumerate() | |
{ | |
println!("{}. {name}", count + 1); | |
for namespace in namespaces { | |
println!(" {namespace}"); | |
} | |
} | |
} | |
fn has_arch(reader: &Reader, mut attributes: impl Iterator<Item = Attribute>) -> bool { | |
attributes.any(|attribute| reader.attribute_name(attribute) == "SupportedArchitectureAttribute") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment