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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
use core::panic;
use binrw::BinRead;
use bitflags::bitflags;
use encoding_rs::Encoding;
use getset::Getters;
use crate::{
binread_flags::binread_flags,
strings::{NullTerminatedString, StringEncoding},
CurrentOffset,
};
#[cfg(feature = "serde")]
use serde::Serialize;
/// The LinkInfo structure specifies information necessary to resolve a
/// linktarget if it is not found in its original location. This includes
/// information about the volume that the target was stored on, the mapped
/// drive letter, and a Universal Naming Convention (UNC)form of the path
/// if one existed when the linkwas created. For more details about UNC
/// paths, see [MS-DFSNM] section 2.2.1.4
#[derive(Debug, BinRead, Getters)]
#[cfg_attr(feature = "serde", derive(Serialize))]
#[getset(get = "pub")]
#[allow(unused)]
#[br(import(default_codepage: &'static Encoding))]
pub struct LinkInfo {
/// stores the beginning og this data structure
#[serde(skip)]
#[getset(skip)]
link_info_offset: CurrentOffset,
/// LinkInfoSize (4 bytes): A 32-bit, unsigned integer that specifies the
/// size, in bytes, of the LinkInfo structure. All offsets specified in
/// this structure MUST be less than this value, and all strings contained
/// in this structure MUST fit within the extent defined by this size.
link_info_size: u32,
/// LinkInfoHeaderSize (4 bytes): A 32-bit, unsigned integer that
/// specifies the size, in bytes, of the LinkInfo header section, which is
/// composed of the LinkInfoSize, LinkInfoHeaderSize, LinkInfoFlags,
/// VolumeIDOffset, LocalBasePathOffset, CommonNetworkRelativeLinkOffset,
/// CommonPathSuffixOffset fields, and, if included, the
/// LocalBasePathOffsetUnicode and CommonPathSuffixOffsetUnicode fields.
link_info_header_size: u32,
/// Flags that specify whether the VolumeID, LocalBasePath,
/// LocalBasePathUnicode, and CommonNetworkRelativeLinkfields are present
/// in this structure.
link_info_flags: LinkInfoFlags,
/// VolumeIDOffset (4 bytes): A 32-bit, unsigned integer that specifies the
/// location of the VolumeID field. If the VolumeIDAndLocalBasePath flag is
/// set, this value is an offset, in bytes, from the start of the LinkInfo
/// structure; otherwise, this value MUST be zero.
#[br(
assert(
if link_info_flags.has_volume_id_and_local_base_path() {
volume_id_offset >= link_info_header_size &&
volume_id_offset < link_info_size
} else {
true // we handle the other case as non-fatal error
}
),
map = |x: u32| {
if link_info_flags.has_volume_id_and_local_base_path() {
x
} else {
if x != 0 {
log::warn!("The VolumeIDAndLocalBasePath flag was not set, \
but the VolumeID field is not set to zero (actual value is \
0x{x:08x}). I set it to be zero.");
}
0
}
}
)]
volume_id_offset: u32,
/// LocalBasePathOffset (4 bytes): A 32-bit, unsigned integer that
/// specifies the location of the LocalBasePath field. If the
/// VolumeIDAndLocalBasePath flag is set, this value is an offset, in
/// bytes, from the start of the LinkInfo structure; otherwise, this value
/// MUST be zero.
#[br(
assert(
if link_info_flags.has_volume_id_and_local_base_path() {
local_base_path_offset >= link_info_header_size &&
local_base_path_offset < link_info_size
} else {
true // we handle the other case as non-fatal error
}
),
map = |x: u32| {
if link_info_flags.has_volume_id_and_local_base_path() {
x
} else {
if x != 0 {
log::warn!("The VolumeIDAndLocalBasePath flag was not set, \
but the LocalBasePath field is not set to zero (actual \
value is 0x{x:08x}). I set it to be zero.");
}
0
}
}
)]
local_base_path_offset: u32,
/// CommonNetworkRelativeLinkOffset (4 bytes): A 32-bit, unsigned integer
/// that specifies the location of the CommonNetworkRelativeLink field. If
/// the CommonNetworkRelativeLinkAndPathSuffix flag is set, this value is
/// an offset, in bytes, from the start of the LinkInfo structure;
/// otherwise, this value MUST be zero.
#[br(
assert(
if link_info_flags.has_common_network_relative_link_and_path_suffix() {
common_network_relative_link_offset >= link_info_header_size &&
common_network_relative_link_offset < link_info_size
} else {
true // we handle the other case as non-fatal error
}
),
map = |x: u32| {
if link_info_flags.has_common_network_relative_link_and_path_suffix() {
x
} else {
if x != 0 {
log::warn!("The CommonNetworkRelativeLinkAndPathSuffix flag \
was not set, but the CommonNetworkRelativeLinkOffset field \
is not set to zero (actual value is 0x{x:08x}). I set it to \
be zero.");
}
0
}
}
)]
common_network_relative_link_offset: u32,
/// CommonPathSuffixOffset (4 bytes): A 32-bit, unsigned integer that
/// specifies the location of the CommonPathSuffix field. This value is
/// an offset, in bytes, from the start of the LinkInfo structure.
#[cfg_attr(not(docsrs), br(assert(common_path_suffix_offset < link_info_size
&& common_path_suffix_offset >= link_info_header_size)))]
common_path_suffix_offset: u32,
/// LocalBasePathOffsetUnicode (4 bytes): An optional, 32-bit, unsigned
/// integer that specifies the location of the LocalBasePathUnicode field.
/// If the VolumeIDAndLocalBasePath flag is set, this value is an offset,
/// in bytes, from the start of the LinkInfo structure; otherwise, this
/// value MUST be zero. This field can be present only if the value of the
/// LinkInfoHeaderSize field is greater than or equal to 0x00000024.
#[br(
if(link_info_header_size >= 0x24),
assert(
if let Some(offset) = local_base_path_offset_unicode {
if link_info_flags.has_volume_id_and_local_base_path() {
offset >= link_info_header_size && offset < link_info_size
} else {
true // we handle the other case as non-fatal error
}
} else {
true // this link doesn't handle unicode
},
"offset has unexpected value: {local_base_path_offset_unicode:?}"
),
map = |x: Option<u32>| x.map(|x: u32| {
if link_info_flags.has_volume_id_and_local_base_path() {
x
} else {
if x != 0 {
log::warn!("The VolumeIDAndLocalBasePath flag was not set,\
but the LocalBasePathOffsetUnicode field is not set to zero\
(actual value is 0x{x:08x}). I set it to be zero.");
}
0
}
})
)]
local_base_path_offset_unicode: Option<u32>,
/// CommonPathSuffixOffsetUnicode (4 bytes): An optional, 32-bit, unsigned
/// integer that specifies the location of the CommonPathSuffixUnicode
/// field. This value is an offset, in bytes, from the start of the
/// LinkInfo structure. This field can be present only if the value of the
/// LinkInfoHeaderSize field is greater than or equal to 0x00000024.
#[br(
if(link_info_header_size >= 0x24),
assert (
if let Some(offset) = common_path_suffix_offset_unicode {
offset > link_info_header_size && offset < link_info_size
} else {true}
)
)]
common_path_suffix_offset_unicode: Option<u32>,
/// An optional VolumeID structure (section 2.3.1) that specifies
/// information about the volume that the link target was on when the link
/// was created. This field is present if the VolumeIDAndLocalBasePath
/// flag is set.
#[br(
if(link_info_flags.has_volume_id_and_local_base_path()),
args(default_codepage),
seek_before(binrw::io::SeekFrom::Start((link_info_offset.as_ref() + volume_id_offset).into()))
)]
volume_id: Option<VolumeID>,
/// An optional, NULL–terminated string, defined by the system default code
/// page, which is used to construct the full path to the link item or link
/// target by appending the string in the CommonPathSuffix field. This
/// field is present if the VolumeIDAndLocalBasePath flag is set.
#[br(
if(link_info_flags.has_volume_id_and_local_base_path()),
args(StringEncoding::CodePage(default_codepage)),
map=|o: Option<NullTerminatedString>| o.map(|n| n.to_string()),
seek_before(binrw::io::SeekFrom::Start((link_info_offset.as_ref() + local_base_path_offset).into()))
)]
#[getset(skip)]
local_base_path: Option<String>,
/// An optional CommonNetworkRelativeLink structure (section 2.3.2) that
/// specifies information about the network location where the link target
/// is stored.
#[br(
if(link_info_flags.has_common_network_relative_link_and_path_suffix()),
args(default_codepage),
seek_before(binrw::io::SeekFrom::Start((link_info_offset.as_ref() + common_network_relative_link_offset).into()))
)]
common_network_relative_link: Option<CommonNetworkRelativeLink>,
/// A NULL–terminated string, defined by the system default code page,
/// which is used to construct the full path to the link item or link
/// target by being appended to the string in the LocalBasePath field.
#[br(
if(common_path_suffix_offset != 0),
args(StringEncoding::CodePage(default_codepage)),
map=|n: NullTerminatedString| n.to_string(),
seek_before(binrw::io::SeekFrom::Start((link_info_offset.as_ref() + common_path_suffix_offset).into()))
)]
#[getset(skip)]
common_path_suffix: String,
/// An optional, NULL–terminated, Unicode string that is used to construct
/// the full path to the link item or link target by appending the string
/// in the CommonPathSuffixUnicode field. This field can be present only
/// if the VolumeIDAndLocalBasePath flag is set and the value of the
/// LinkInfoHeaderSize field is greater than or equal to 0x00000024.
#[br(
if(link_info_header_size >= 0x24 && link_info_flags.has_volume_id_and_local_base_path()),
args(StringEncoding::Unicode),
map=|o: Option<NullTerminatedString>| o.map(|n| n.to_string()),
seek_before(binrw::io::SeekFrom::Start((link_info_offset.as_ref() + local_base_path_offset_unicode.unwrap()).into()))
)]
local_base_path_unicode: Option<String>,
/// An optional, NULL–terminated, Unicode string that is used to construct
/// the full path to the link item or link target by being appended to the
/// string in the LocalBasePathUnicode field. This field can be present
/// only if the value of the LinkInfoHeaderSize field is greater than or
/// equal to 0x00000024.
#[br(
if(link_info_header_size >= 0x24 && common_path_suffix_offset_unicode.map(|o| o != 0).unwrap_or(false)),
args(StringEncoding::Unicode),
map=|o: Option<NullTerminatedString>| o.map(|n| n.to_string()),
seek_before(binrw::io::SeekFrom::Start((link_info_offset.as_ref() + common_path_suffix_offset_unicode.unwrap()).into()))
)]
common_path_suffix_unicode: Option<String>,
}
impl LinkInfo {
/// An optional, NULL–terminated string, defined by the system default code
/// page, which is used to construct the full path to the link item or link
/// target by appending the string in the CommonPathSuffix field. This
/// field is present if the VolumeIDAndLocalBasePath flag is set.
pub fn local_base_path(&self) -> Option<&str> {
self.local_base_path.as_ref().map(|x| x.as_ref())
}
/// A NULL–terminated string, defined by the system default code page,
/// which is used to construct the full path to the link item or link
/// target by being appended to the string in the LocalBasePath field.
pub fn common_path_suffix(&self) -> &str {
self.common_path_suffix.as_ref()
}
}
impl From<LinkInfo> for Vec<u8> {
fn from(_val: LinkInfo) -> Self {
unimplemented!()
}
}
bitflags! {
/// Flags that specify whether the VolumeID, LocalBasePath, LocalBasePathUnicode,
/// and CommonNetworkRelativeLink fields are present in this structure.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize))]
pub struct LinkInfoFlags: u32 {
/// If set, the VolumeIDand LocalBasePath fields are present, and their
/// locations are specified by the values of the VolumeIDOffset and
/// LocalBasePathOffset fields, respectively. If the value of the
/// LinkInfoHeaderSize field is greater than or equal to 0x00000024, the
/// LocalBasePathUnicode field is present, and its location is specified
/// by the value of the LocalBasePathOffsetUnicode field. If not set,
/// the VolumeID, LocalBasePath, and LocalBasePathUnicode fields are
/// not present, and the values of the VolumeIDOffset and
/// LocalBasePathOffset fields are zero. If the value of the
/// LinkInfoHeaderSize field is greater than or equal to 0x00000024,
/// the value of the LocalBasePathOffsetUnicode field is zero.
const VOLUME_ID_AND_LOCAL_BASE_PATH = 0b0000_0000_0000_0000_0000_0000_0000_0001;
/// If set, the CommonNetworkRelativeLink field is present, and its
/// location is specified by the value of the
/// CommonNetworkRelativeLinkOffset field.If not set, the
/// CommonNetworkRelativeLink field is not present, and the value of
/// the CommonNetworkRelativeLinkOffset field is zero
const COMMON_NETWORK_RELATIVE_LINK_AND_PATH_SUFFIX = 0b0000_0000_0000_0000_0000_0000_0000_0010;
}
}
binread_flags!(LinkInfoFlags, u32);
#[allow(missing_docs)]
impl LinkInfoFlags {
pub fn has_volume_id_and_local_base_path(&self) -> bool {
self.contains(Self::VOLUME_ID_AND_LOCAL_BASE_PATH)
}
pub fn has_common_network_relative_link_and_path_suffix(&self) -> bool {
self.contains(Self::COMMON_NETWORK_RELATIVE_LINK_AND_PATH_SUFFIX)
}
}
/// The VolumeID structure specifies information about the volume that a link
/// target was on when the link was created. This information is useful for
/// resolving the link if the file is not found in its original location.
#[derive(Clone, Debug, BinRead, Getters)]
#[cfg_attr(feature = "serde", derive(Serialize))]
#[getset(get = "pub")]
#[allow(unused)]
#[br(import(default_codepage: &'static Encoding))]
pub struct VolumeID {
#[getset(skip)]
#[cfg_attr(feature = "serde", serde(skip))]
start_offset: CurrentOffset,
/// VolumeIDSize (4 bytes): A 32-bit, unsigned integer that specifies the
/// size, in bytes, of this structure. This value MUST be greater than
/// `0x00000010``. All offsets specified in this structure MUST be less
/// than this value, and all strings contained in this structure MUST fit
/// within the extent defined by this size.
#[br(assert(volume_id_size > 0x10))]
volume_id_size: u32,
/// A 32-bit, unsigned integer that specifies the type of drive the link
/// target is stored on.
drive_type: DriveType,
/// A 32-bit, unsigned integer that specifies the drive serial number of
/// the volume the link target is stored on.
drive_serial_number: u32,
/// VolumeLabelOffset (4 bytes): A 32-bit, unsigned integer that
/// specifies the location of a string that contains the volume label of
/// the drive that the link target is stored on. This value is an offset,
/// in bytes, from the start of the VolumeID structure to a NULL-terminated
/// string of characters, defined by the system default code page. The
/// volume label string is located in the Data field of this structure.
///
/// If the value of this field is 0x00000014, it MUST be ignored, and the
/// value of the VolumeLabelOffsetUnicode field MUST be used to locate the
/// volume label string.
#[br(assert(volume_label_offset < volume_id_size))]
volume_label_offset: u32,
/// VolumeLabelOffsetUnicode (4 bytes): An optional, 32-bit, unsigned
/// integer that specifies the location of a string that contains the
/// volume label of the drive that the link target is stored on. This value
/// is an offset, in bytes, from the start of the VolumeID structure to a
/// NULL-terminated string of Unicode characters. The volume label string
/// is located in the Data field of this structure.
///
/// If the value of the VolumeLabelOffset field is not 0x00000014, this
/// field MUST NOT be present; instead, the value of the VolumeLabelOffset
/// field MUST be used to locate the volume label string.
#[br(if(volume_label_offset == 0x14))]
volume_label_offset_unicode: Option<u32>,
/// The label of the volume that the link target is stored on.
#[br(
args({volume_label_offset_unicode.and(Some(StringEncoding::Unicode)).unwrap_or(StringEncoding::CodePage(default_codepage))}),
map=|s: NullTerminatedString| s.to_string()
)]
#[getset(skip)]
volume_label: String,
#[cfg_attr(feature = "serde", serde(skip))]
#[getset(skip)]
_next_offset: CurrentOffset,
}
impl VolumeID {
/// The label of the volume that the link target is stored on.
pub fn volume_label(&self) -> &str {
self.volume_label.as_ref()
}
}
impl From<VolumeID> for Vec<u8> {
fn from(_val: VolumeID) -> Self {
unimplemented!()
}
}
/// A 32-bit, unsigned integer that specifies the type of drive the link target is stored on.
#[derive(Clone, Debug, BinRead)]
#[cfg_attr(feature = "serde", derive(Serialize))]
#[br(repr(u32))]
pub enum DriveType {
/// The drive type cannot be determined.
DriveUnknown = 0x00,
/// The root path is invalid; for example, there is no volume mounted at the path.
DriveNoRootDir = 0x01,
/// The drive has removable media, such as a floppy drive, thumb drive, or flash card reader.
DriveRemovable = 0x02,
/// The drive has fixed media, such as a hard drive or flash drive.
DriveFixed = 0x03,
/// The drive is a remote (network) drive.
DriveRemote = 0x04,
/// The drive is a CD-ROM drive.
DriveCDRom = 0x05,
/// The drive is a RAM disk.
DriveRamdisk = 0x06,
}
/// The CommonNetworkRelativeLink structure specifies information about the network location where a
/// link target is stored, including the mapped drive letter and the UNC path prefix. For details on
/// UNC paths, see [MS-DFSNM] section 2.2.1.4.
///
/// <https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-shllink/23bb5877-e3dd-4799-9f50-79f05f938537>
#[derive(Clone, Debug, BinRead)]
#[cfg_attr(feature = "serde", derive(Serialize))]
#[allow(unused)]
#[br(import(default_codepage: &'static Encoding))]
pub struct CommonNetworkRelativeLink {
#[serde(skip)]
/// CommonNetworkRelativeLinkSize (4 bytes): A 32-bit, unsigned integer
/// that specifies the size, in bytes, of the CommonNetworkRelativeLink
/// structure. This value MUST be greater than or equal to 0x00000014. All
/// offsets specified in this structure MUST be less than this value, and
/// all strings contained in this structure MUST fit within the extent
/// defined by this size.
#[br(assert(common_network_relative_link_size >= 0x14))]
common_network_relative_link_size: u32,
/// Flags that specify the contents of the DeviceNameOffset and
/// NetProviderType fields.
flags: CommonNetworkRelativeLinkFlags,
/// NetNameOffset (4 bytes): A 32-bit, unsigned integer that specifies the
/// location of the NetName field. This value is an offset, in bytes, from
/// the start of the CommonNetworkRelativeLink structure.
#[br(assert(net_name_offset < common_network_relative_link_size))]
net_name_offset: u32,
/// DeviceNameOffset (4 bytes): A 32-bit, unsigned integer that specifies
/// the location of the DeviceName field. If the ValidDevice flag is set,
/// this value is an offset, in bytes, from the start of the
/// CommonNetworkRelativeLink structure; otherwise, this value MUST be
/// zero.
#[br(
assert(
device_name_offset < common_network_relative_link_size &&
if flags.has_valid_device() {
device_name_offset > 0
} else {
device_name_offset == 0
}
)
)]
device_name_offset: u32,
/// NetworkProviderType (4 bytes): A 32-bit, unsigned integer that
/// specifies the type of network provider. If the ValidNetType flag is
/// set, this value MUST be one of the following; otherwise, this value
/// MUST be ignored.
#[br(map = |t| if flags.has_valid_net_type() {Some(t)} else {None})]
network_provider_type: Option<NetworkProviderType>,
/// NetNameOffsetUnicode (4 bytes): An optional, 32-bit, unsigned integer
/// that specifies the location of the NetNameUnicode field. This value is
/// an offset, in bytes, from the start of the CommonNetworkRelativeLink
/// structure. This field MUST be present if the value of the NetNameOffset
/// field is greater than 0x00000014; otherwise, this field MUST NOT be present.
#[br(if(net_name_offset > 0x00000014))]
net_name_offset_unicode: Option<u32>,
/// DeviceNameOffsetUnicode (4 bytes): An optional, 32-bit, unsigned
/// integer that specifies the location of the DeviceNameUnicode field.
/// This value is an offset, in bytes, from the start of the
/// CommonNetworkRelativeLink structure. This field MUST be present if the
/// value of the NetNameOffset field is greater than 0x00000014; otherwise,
/// this field MUST NOT be present.
#[br(if(net_name_offset > 0x00000014))]
device_name_offset_unicode: Option<u32>,
/// A NULL–terminated string, as defined by the system default code
/// page, which specifies a server share path; for example,
/// "\\server\share".
#[br(
args(StringEncoding::CodePage(default_codepage)),
map=|n: NullTerminatedString| n.to_string()
)]
net_name: String,
/// A NULL–terminated string, as defined by the system default code
/// page, which specifies a device; for example, the drive letter
/// "D:".
#[br(
if(flags.has_valid_device()),
args(StringEncoding::CodePage(default_codepage)),
map=|n: Option<NullTerminatedString>| n.map(|s| s.to_string())
)]
device_name: Option<String>,
/// An optional, NULL–terminated, Unicode string that is the Unicode
/// version of the NetName string. This field MUST be present if the value
/// of the NetNameOffset field is greater than 0x00000014; otherwise, this
/// field MUST NOT be present.
#[br(
if(net_name_offset > 0x00000014),
args(StringEncoding::Unicode),
map=|n: Option<NullTerminatedString>| n.map(|s| s.to_string())
)]
net_name_unicode: Option<String>,
/// An optional, NULL–terminated, Unicode string that is the Unicode
/// version of the DeviceName string. This field MUST be present if the
/// value of the NetNameOffset field is greater than 0x00000014; otherwise,
/// this field MUST NOT be present.
#[br(
if(net_name_offset > 0x00000014 && flags.has_valid_device()),
args(StringEncoding::Unicode),
map=|n: Option<NullTerminatedString>| n.map(|s| s.to_string())
)]
device_name_unicode: Option<String>,
}
impl From<CommonNetworkRelativeLink> for Vec<u8> {
fn from(_val: CommonNetworkRelativeLink) -> Self {
unimplemented!()
}
}
impl CommonNetworkRelativeLink {
/// returns the name of this link
pub fn name(&self) -> String {
if self.flags.has_valid_device() {
self.device_name_unicode
.as_ref()
.or(self.device_name.as_ref())
.expect("device name must be set, if VALID_DEVICE is set")
.to_string()
} else if self.flags.has_valid_net_type() {
self.net_name_unicode
.as_ref()
.unwrap_or(&self.net_name)
.to_string()
} else {
panic!("either one of VALID_DEVICE or VALID_NET_TYPE must be set")
}
}
}
bitflags! {
/// Flags that specify the contents of the DeviceNameOffset and NetProviderType fields.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(Serialize))]
pub struct CommonNetworkRelativeLinkFlags: u32 {
/// If set, the DeviceNameOffset field contains an offset to the device
/// name. If not set, the DeviceNameOffset field does not contain an
/// offset to the device name, and its value MUST be zero.
const VALID_DEVICE = 0b0000_0000_0000_0000_0000_0000_0000_0001;
/// If set, the NetProviderType field contains the network provider
/// type. If not set, the NetProviderType field does not contain the
/// network provider type, and its value MUST be zero.
const VALID_NET_TYPE = 0b0000_0000_0000_0000_0000_0000_0000_0010;
}
}
binread_flags!(CommonNetworkRelativeLinkFlags, u32);
#[allow(missing_docs)]
impl CommonNetworkRelativeLinkFlags {
pub fn has_valid_device(&self) -> bool {
*self & Self::VALID_DEVICE == Self::VALID_DEVICE
}
pub fn has_valid_net_type(&self) -> bool {
*self & Self::VALID_NET_TYPE == Self::VALID_NET_TYPE
}
}
/// A 32-bit, unsigned integer that specifies the type of network provider.
/// <https://learn.microsoft.com/de-de/windows/win32/api/winbase/ns-winbase-file_remote_protocol_info>
#[allow(missing_docs)]
#[derive(Clone, Debug, BinRead)]
#[cfg_attr(feature = "serde", derive(Serialize))]
#[br(repr(u32))]
pub enum NetworkProviderType {
None = 0,
MSNet = 0x00010000,
Smb = 0x00020000,
Netware = 0x00030000,
Vines = 0x00040000,
TenNet = 0x00050000,
Locus = 0x00060000,
SunPCNFS = 0x00070000,
LanStep = 0x00080000,
NineTiles = 0x00090000,
Lantastic = 0x000A0000,
As400 = 0x000B0000,
FTPNFS = 0x000C0000,
PathWorks = 0x000D0000,
LifeNet = 0x000E0000,
PowerLAN = 0x000F0000,
BWNFS = 0x00100000,
Cogent = 0x00110000,
Farallon = 0x00120000,
AppleTalk = 0x00130000,
Intergraph = 0x00140000,
SymfoNet = 0x00150000,
ClearCase = 0x00160000,
Frontier = 0x00170000,
BMC = 0x00180000,
DCE = 0x00190000,
Avid = 0x1a0000,
Docuspace = 0x1b0000,
Mangosoft = 0x1c0000,
Sernet = 0x1d0000,
Riverfront1 = 0x1e0000,
Riverfront2 = 0x1f0000,
Decorb = 0x200000,
Protstor = 0x210000,
FjRedir = 0x220000,
Distinct = 0x230000,
Twins = 0x240000,
Rdr2Sample = 0x250000,
CSC = 0x260000,
_3In1 = 0x270000,
ExtendNet = 0x290000,
Stac = 0x2a0000,
Foxbat = 0x2b0000,
Yahoo = 0x2c0000,
Exifs = 0x2d0000,
Dav = 0x2e0000,
Knoware = 0x2f0000,
ObjectDire = 0x300000,
Masfax = 0x310000,
HobNfs = 0x320000,
Shiva = 0x330000,
Ibmal = 0x340000,
Lock = 0x350000,
Termsrv = 0x360000,
Srt = 0x370000,
Quincy = 0x380000,
Openafs = 0x390000,
Avid1 = 0x3a0000,
Dfs = 0x3b0000,
Kwnp = 0x3c0000,
Zenworks = 0x3d0000,
Driveonweb = 0x3e0000,
Vmware = 0x3f0000,
Rsfx = 0x400000,
Mfiles = 0x410000,
MsNfs = 0x420000,
Google = 0x430000,
}