-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnumproptag.pl
executable file
·159 lines (152 loc) · 3.48 KB
/
numproptag.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/perl
# SPDX-License-Identifier: MIT
# written by Jan Engelhardt, 2022
#
# ilspy the NumPropTag API from
# Microsoft.Exchange.Server.Storage.propertyDefinitions.dll,
#
use strict;
use warnings;
&main();
sub main
{
my $csnames = &read_ds();
print STDERR "read_ds: ", scalar(keys %$csnames), " names read\n";
$csnames = &filter_ansi($csnames);
print STDERR "filter_ansi: ", scalar(keys %$csnames), " names left\n";
my $cstags = &kv_invert($csnames);
print STDERR "kv_invert: ", scalar(keys %$cstags), " proptags\n";
&filter_have($cstags);
print STDERR "filter_have: ", scalar(keys %$cstags), " proptags left\n";
&mt_merge($cstags);
&mt_new($cstags);
}
sub read_ds
{
my $names = {};
my $fh;
open($fh, "<dll.numproptag.txt") || die "dll.numproptag.txt: $!";
while (<$fh>) {
my($name, $proptag) = ($_ =~ m{^\s*public const uint (\w+) = (\d+)u;});
if (!defined($proptag)) {
next;
}
$proptag = sprintf("%08x", $proptag + 0);
$names->{$name} = $proptag;
}
close($fh);
return $names;
}
#
# Remove `xxxx001e XAnsi` if we also already have a `xxxx001f X`
#
sub filter_ansi
{
my $in = shift @_;
my $out = {%$in};
foreach my $name (keys %$in) {
next if (substr($name, -4) ne "Ansi");
next if (!exists($in->{$name}));
next if (substr($in->{$name}, -3) ne "01e");
my $unq = substr($name, 0, -4);
next if (!exists($in->{$unq}));
next if (substr($in->{$unq}, -3) ne "01f");
delete $out->{$name};
}
return $out;
}
sub kv_invert
{
my $in = shift @_;
my $out = {};
foreach my $name (keys %$in) {
my $proptag = $in->{$name};
if (!defined($out->{$proptag})) {
$out->{$proptag} = [];
}
push(@{$out->{$proptag}}, $name);
}
return $out;
}
#
# Filter names that mapitags.txt already has
# (Inplace modification)
#
sub filter_have
{
my $cstags = shift @_;
my $fh;
open($fh, "<mapitags.txt") || die "mapitags.txt: $!";
while (<$fh>) {
chomp($_);
my($proptag, $names) = ($_ =~ m{^(\S{8})\S*\s+(.*)});
if (!defined($names)) {
die "Unparsed: $_";
}
if (!defined($cstags->{$proptag})) {
next;
}
$names =~ s{\s*/\*.*}{};
my @names = split(m{\s+}, $names);
my $new_names = [];
foreach my $kw (@{$cstags->{$proptag}}) {
if (grep(m{^(PidTag|\.)\Q$kw\E$}i, @names)) {
next;
}
push(@$new_names, $kw);
}
$cstags->{$proptag} = $new_names;
}
}
#
# Emit new copy of mapitags.txt to stdout, with names merged into existing
# proptags.
#
# Ouptut may contain extra lines because this program does not fully understand
# the +X notation used in mapitags.txt.
#
sub mt_merge
{
my $cstags = shift @_;
my $fh;
open($fh, "<mapitags.txt") || die "mapitags.txt: $!";
while (<$fh>) {
chomp($_);
my($proptag, $markers, $rest) = ($_ =~ m{^(\S{8})(\S*)\s+(.*)});
my($comments) = ($rest =~ m{(\s*/\*.*)});
my $names = defined($comments) ? $` : $rest;
my @names = split(m{\s+}, $names);
if (defined($cstags->{$proptag})) {
foreach my $kw (@{$cstags->{$proptag}}) {
if (grep(m{^(PidTag|\.)\Q$kw\E$}i, @names)) {
next;
}
push(@names, ".$kw");
}
delete $cstags->{$proptag};
}
print "$proptag$markers\t", join(" ", @names);
if (defined($comments)) {
die if (length($comments) == 0);
print $comments;
}
print "\n";
}
}
#
# Emit tags that were completely new
#
sub mt_new
{
my $cstags = shift @_;
if (scalar(keys %$cstags) > 0) {
print "# NEW:\n";
}
foreach my $proptag (sort keys %$cstags) {
print "$proptag\t";
foreach my $k (@{$cstags->{$proptag}}) {
$k = ".$k";
}
print join(" ", @{$cstags->{$proptag}}), "\n";
}
}