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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
// SPDX-FileCopyrightText: Provenant contributors
// SPDX-License-Identifier: Apache-2.0
//! Parser for Microsoft Update Manifest (.mum) files.
//!
//! Extracts Windows Update package metadata from .mum XML manifest files.
//!
//! # Supported Formats
//! - `*.mum` - Microsoft Update Manifest XML files
//!
//! # Implementation Notes
//! - Format: XML with assembly and package metadata
//! - Spec: Windows Update manifests
use crate::models::{DatasourceId, PackageType};
use std::path::Path;
use crate::parser_warn as warn;
use quick_xml::events::Event;
use quick_xml::reader::Reader;
use crate::models::PackageData;
use crate::parsers::utils::{MAX_ITERATION_COUNT, read_file_to_string, truncate_field};
use super::PackageParser;
const PACKAGE_TYPE: PackageType = PackageType::WindowsUpdate;
pub struct MicrosoftUpdateManifestParser;
impl PackageParser for MicrosoftUpdateManifestParser {
const PACKAGE_TYPE: PackageType = PACKAGE_TYPE;
fn is_match(path: &Path) -> bool {
path.extension().is_some_and(|ext| ext == "mum")
}
fn extract_packages(path: &Path) -> Vec<PackageData> {
let content = match read_file_to_string(path, None) {
Ok(c) => c,
Err(e) => {
warn!("Failed to read .mum file {:?}: {}", path, e);
return vec![PackageData {
package_type: Some(PACKAGE_TYPE),
datasource_id: Some(DatasourceId::MicrosoftUpdateManifestMum),
..Default::default()
}];
}
};
vec![parse_mum_xml(&content)]
}
}
pub(crate) fn parse_mum_xml(content: &str) -> PackageData {
let mut reader = Reader::from_str(content);
reader.config_mut().trim_text(true);
let mut name = None;
let mut version = None;
let mut description = None;
let mut copyright = None;
let mut homepage_url = None;
let mut buf = Vec::new();
let mut iteration_count: usize = 0;
loop {
iteration_count += 1;
if iteration_count > MAX_ITERATION_COUNT {
warn!(
"Exceeded MAX_ITERATION_COUNT ({}) parsing .mum XML, stopping",
MAX_ITERATION_COUNT
);
break;
}
match reader.read_event_into(&mut buf) {
Ok(Event::Empty(e)) => {
if e.name().as_ref() == b"assemblyIdentity" {
for attr in e.attributes().filter_map(|a| a.ok()) {
match attr.key.as_ref() {
b"name" => {
let raw = attr.value.to_vec();
let has_invalid = String::from_utf8(raw.clone()).is_err();
let val = String::from_utf8_lossy(&raw).into_owned();
if has_invalid {
warn!(
"Invalid UTF-8 in 'name' attribute, using lossy conversion"
);
}
name = Some(truncate_field(val));
}
b"version" => {
let raw = attr.value.to_vec();
let has_invalid = String::from_utf8(raw.clone()).is_err();
let val = String::from_utf8_lossy(&raw).into_owned();
if has_invalid {
warn!(
"Invalid UTF-8 in 'version' attribute, using lossy conversion"
);
}
version = Some(truncate_field(val));
}
_ => {}
}
}
}
}
Ok(Event::Start(e)) => {
if e.name().as_ref() == b"assembly" {
for attr in e.attributes().filter_map(|a| a.ok()) {
match attr.key.as_ref() {
b"description" => {
let raw = attr.value.to_vec();
let has_invalid = String::from_utf8(raw.clone()).is_err();
let val = String::from_utf8_lossy(&raw).into_owned();
if has_invalid {
warn!(
"Invalid UTF-8 in 'description' attribute, using lossy conversion"
);
}
description = Some(truncate_field(val));
}
b"copyright" => {
let raw = attr.value.to_vec();
let has_invalid = String::from_utf8(raw.clone()).is_err();
let val = String::from_utf8_lossy(&raw).into_owned();
if has_invalid {
warn!(
"Invalid UTF-8 in 'copyright' attribute, using lossy conversion"
);
}
copyright = Some(truncate_field(val));
}
b"supportInformation" => {
let raw = attr.value.to_vec();
let has_invalid = String::from_utf8(raw.clone()).is_err();
let val = String::from_utf8_lossy(&raw).into_owned();
if has_invalid {
warn!(
"Invalid UTF-8 in 'supportInformation' attribute, using lossy conversion"
);
}
homepage_url = Some(truncate_field(val));
}
_ => {}
}
}
}
}
Ok(Event::Eof) => break,
Err(e) => {
warn!(
"Error parsing XML at position {}: {}",
reader.buffer_position(),
e
);
break;
}
_ => {}
}
buf.clear();
}
PackageData {
package_type: Some(PACKAGE_TYPE),
name,
version,
description,
homepage_url,
copyright,
datasource_id: Some(DatasourceId::MicrosoftUpdateManifestMum),
..Default::default()
}
}
crate::register_parser!(
"Microsoft Update Manifest .mum file",
&["*.mum"],
"windows-update",
"",
None,
);