memflow 0.2.4

core components of the memflow physical memory introspection framework
Documentation
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
//! This module provides functionality to extract the PluginDescriptorInfo from a binary.
//!
//! Rather than loading the module in memory and finding the correct export
//! the analyzer will do a static analysis based on goblin to piece together
//! the PluginDescriptorInfo structure.

use std::ops::Range;

use dataview::{DataView, Pod};
use goblin::{
    elf::{header::ELFMAG, section_header::SHN_XINDEX, Elf},
    mach::{
        header::{MH_CIGAM, MH_CIGAM_64, MH_MAGIC, MH_MAGIC_64},
        Mach, MachO, SingleArch,
    },
    pe::{self, header::DOS_MAGIC, options::ParseOptions, PE},
    Object,
};
use num_traits::{NumCast, WrappingAdd, WrappingSub, Zero};
use serde::{Deserialize, Serialize};

use crate::{
    error::{Error, Result},
    plugins::{ErrorKind, ErrorOrigin},
};

pub(crate) const MEMFLOW_EXPORT_PREFIX_CONNECTOR: &str = "MEMFLOW_CONNECTOR_";
pub(crate) const MEMFLOW_EXPORT_PREFIX_OS: &str = "MEMFLOW_OS_";

/// The PluginDescriptorInfo struct is adapted and translated from memflow version 0.2.x:
/// https://github.com/memflow/memflow/blob/0.2.0/memflow/src/plugins/mod.rs#L105
#[repr(C, align(4))]
struct PluginDescriptorInfo32 {
    pub plugin_version: i32,
    pub accept_input: u8,   // bool
    pub input_layout: u32,  // &'static TypeLayout
    pub output_layout: u32, // &'static TypeLayout,
    pub name: u32,          // CSliceRef<'static, u8>,
    pub name_length: u32,
    pub version: u32, // CSliceRef<'static, u8>,
    pub version_length: u32,
    pub description: u32, //CSliceRef<'static, u8>,
    pub description_length: u32,
    pub help_callback: u32, // Option<extern "C" fn(callback: HelpCallback) -> ()>,
    pub target_list_callback: u32, // Option<extern "C" fn(callback: TargetCallback) -> i32>,
    pub create: u32,        // CreateFn<T>,
}
const _: [(); std::mem::size_of::<PluginDescriptorInfo32>()] = [(); 0x34];
unsafe impl Pod for PluginDescriptorInfo32 {}

// The padding inside the struct is only really required for targets
// which ignore the aligment property.
// Most notable for i686 cross-compilation the padding is required.
#[repr(C, align(8))]
struct PluginDescriptorInfo64 {
    pub plugin_version: i32,
    pub accept_input: u32,  // bool
    pub input_layout: u64,  // &'static TypeLayout
    pub output_layout: u64, // &'static TypeLayout,
    pub name: u64,          // CSliceRef<'static, u8>,
    pub name_length: u32,
    _pad0: u32,
    pub version: u64, // CSliceRef<'static, u8>,
    pub version_length: u32,
    _pad1: u32,
    pub description: u64, //CSliceRef<'static, u8>,
    pub description_length: u32,
    _pad2: u32,
    pub help_callback: u64, // Option<extern "C" fn(callback: HelpCallback) -> ()>,
    pub target_list_callback: u64, // Option<extern "C" fn(callback: TargetCallback) -> i32>,
    pub create: u64,        // CreateFn<T>,
}
const _: [(); std::mem::size_of::<PluginDescriptorInfo64>()] = [(); 0x60];
unsafe impl Pod for PluginDescriptorInfo64 {}

#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[serde(rename_all = "snake_case")]
pub enum PluginKind {
    Connector,
    Os,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[serde(rename_all = "snake_case")]
pub enum PluginFileType {
    Pe,
    Elf,
    Mach,
}

#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[serde(rename_all = "snake_case")]
pub enum PluginArchitecture {
    Unknown(u32),
    X86,
    X86_64,
    Arm,
    Arm64,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
pub struct PluginDescriptorInfo {
    pub plugin_kind: PluginKind,
    pub export_name: String,
    pub file_type: PluginFileType,
    pub architecture: PluginArchitecture,
    pub plugin_version: i32,
    pub name: String,
    pub version: String,
    pub description: String,
}

/// Peaks into the first 4 bytes of the header and matches it against a known set of binary magic constants.
pub fn is_binary(bytes: &[u8]) -> Result<()> {
    let view = DataView::from(bytes);
    let elfmag = u32::from_le_bytes(*ELFMAG);
    match view.read::<u32>(0) {
        tag if (tag as u16) == DOS_MAGIC => Ok(()),
        MH_MAGIC | MH_CIGAM | MH_MAGIC_64 | MH_CIGAM_64 => Ok(()),
        mag if mag == elfmag => Ok(()),
        tag => Err(Error(ErrorOrigin::Inventory, ErrorKind::NotSupported)
            .log_error(format!("unknown binary format (tag={:#}", tag))),
    }
}

/// Parses and returns all descriptors found in the binary.
/// This function tries to guess the binary type.
pub fn parse_descriptors(bytes: &[u8]) -> Result<Vec<PluginDescriptorInfo>> {
    let object = Object::parse(bytes).map_err(|err| {
        Error(ErrorOrigin::Inventory, ErrorKind::InvalidExeFile)
            .log_error(format!("unable to parse binary object: {}", err))
    })?;
    match object {
        Object::PE(pe) => pe_parse_descriptors(bytes, &pe),
        Object::Mach(mach) => mach_parse_descriptors(bytes, &mach),
        Object::Elf(elf) => elf_parse_descriptors(bytes, &elf),
        _ => Err(Error(ErrorOrigin::Inventory, ErrorKind::NotSupported)
            .log_error("unknown binary format")),
    }
}

/// Returns the plugin kind based of the export prefix
fn plugin_kind(export_name: &str) -> Result<PluginKind> {
    // match by export prefix
    if export_name.starts_with(MEMFLOW_EXPORT_PREFIX_CONNECTOR) {
        Ok(PluginKind::Connector)
    } else if export_name.starts_with(MEMFLOW_EXPORT_PREFIX_OS) {
        Ok(PluginKind::Os)
    } else {
        Err(Error(ErrorOrigin::Inventory, ErrorKind::PluginNotFound))
    }
}

/// Parses the descriptors in a PE binary.
/// This function currently supports x86 and x86_64 binaries.
fn pe_parse_descriptors(bytes: &[u8], pe: &PE) -> Result<Vec<PluginDescriptorInfo>> {
    let mut ret = vec![];

    for export in pe.exports.iter() {
        if let Some(export_name) = export.name {
            if let Ok(plugin_kind) = plugin_kind(export_name) {
                if let Some(offset) = export.offset {
                    let data_view = DataView::from(bytes);

                    if pe.is_64 {
                        let raw_desc = data_view.read::<PluginDescriptorInfo64>(offset);
                        #[rustfmt::skip]
                        ret.push(PluginDescriptorInfo {
                            plugin_kind,
                            export_name: export_name.to_string(),
                            file_type: PluginFileType::Pe,
                            architecture: pe_architecture(pe),
                            plugin_version: raw_desc.plugin_version,
                            name: read_string(bytes, pe_va_to_offset(pe, raw_desc.name), raw_desc.name_length as usize)?,
                            version: read_string(bytes, pe_va_to_offset(pe, raw_desc.version), raw_desc.version_length as usize)?,
                            description: read_string(bytes, pe_va_to_offset(pe, raw_desc.description), raw_desc.description_length as usize)?,
                        });
                    } else {
                        let raw_desc = data_view.read::<PluginDescriptorInfo32>(offset);
                        #[rustfmt::skip]
                        ret.push(PluginDescriptorInfo {
                            plugin_kind,
                            export_name: export_name.to_string(),
                            file_type: PluginFileType::Pe,
                            architecture: pe_architecture(pe),
                            plugin_version: raw_desc.plugin_version,
                            name: read_string(bytes, pe_va_to_offset(pe, raw_desc.name as u64), raw_desc.name_length as usize)?,
                            version: read_string(bytes, pe_va_to_offset(pe, raw_desc.version as u64), raw_desc.version_length as usize)?,
                            description: read_string(bytes, pe_va_to_offset(pe, raw_desc.description as u64), raw_desc.description_length as usize)?,
                        });
                    }
                }
            }
        }
    }

    Ok(ret)
}

fn pe_architecture(pe: &PE) -> PluginArchitecture {
    // https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#machine-types
    match pe.header.coff_header.machine {
        0x14c => PluginArchitecture::X86,
        0x8664 => PluginArchitecture::X86_64,
        0x1c0 | 0x1c4 => PluginArchitecture::Arm,
        0xAA64 => PluginArchitecture::Arm64,
        _ => PluginArchitecture::Unknown(pe.header.coff_header.machine as u32),
    }
}

fn pe_va_to_offset(pe: &PE, va: u64) -> usize {
    let image_base = pe.image_base as u64;
    if va < image_base {
        return 0;
    }
    let offset_va = va - image_base;
    let file_alignment = pe
        .header
        .optional_header
        .map(|h| h.windows_fields.file_alignment)
        .unwrap_or(512);
    pe::utils::find_offset(
        offset_va as usize,
        &pe.sections,
        file_alignment,
        &ParseOptions::default(),
    )
    .unwrap_or(0)
}

fn read_string(bytes: &[u8], offset: usize, len: usize) -> Result<String> {
    if offset == 0 {
        if len <= 1 {
            // allow empty strings (e.g. for the description field)
            return Ok(String::new());
        } else {
            // we expect a string but found nothing
            return Err(Error(ErrorOrigin::Inventory, ErrorKind::NotFound)
                .log_error("unable to read referenced string in binary"));
        }
    }

    if offset + len > bytes.len() {
        return Err(Error(ErrorOrigin::Inventory, ErrorKind::OutOfBounds)
            .log_error("referenced string is outside of the file"));
    }
    let mut buffer = vec![0u8; len];
    buffer.copy_from_slice(&bytes[offset..offset + len]);

    let result = std::str::from_utf8(&buffer[..]).map_err(|err| {
        Error(ErrorOrigin::Inventory, ErrorKind::Encoding).log_error(format!(
            "unable to read referenced string in binary: {}",
            err
        ))
    })?;

    Ok(result.to_owned())
}

fn mach_parse_descriptors(bytes: &[u8], mach: &Mach) -> Result<Vec<PluginDescriptorInfo>> {
    let mut ret = vec![];

    match mach {
        Mach::Binary(macho) => {
            let mut descriptors = macho_parse_descriptors(bytes, macho)?;
            ret.append(&mut descriptors);
        }
        Mach::Fat(multiarch) => {
            let arches = multiarch.arches().map_err(|err| {
                Error(ErrorOrigin::Inventory, ErrorKind::InvalidExeFile)
                    .log_error(format!("unable to extract arches from mach: {}", err))
            })?;
            for (index, fatarch) in arches.iter().enumerate() {
                if let Ok(arch) = multiarch.get(index) {
                    match arch {
                        SingleArch::MachO(macho) => {
                            let offset = fatarch.offset as usize;
                            let len = fatarch.size as usize;
                            let mut descriptors =
                                macho_parse_descriptors(&bytes[offset..offset + len], &macho)?;
                            ret.append(&mut descriptors);
                        }
                        SingleArch::Archive(_) => {
                            return Err(Error(ErrorOrigin::Inventory, ErrorKind::NotSupported)
                                .log_error("mach archives are not supported yet"));
                        }
                    }
                }
            }
        }
    }

    Ok(ret)
}

fn macho_parse_descriptors(bytes: &[u8], macho: &MachO) -> Result<Vec<PluginDescriptorInfo>> {
    let mut ret = vec![];

    if !macho.little_endian {
        return Err(Error(ErrorOrigin::Inventory, ErrorKind::NotSupported)
            .log_error("big endian binaries are not supported yet"));
    }

    if let Ok(exports) = macho.exports() {
        for export in exports.iter() {
            // stripping initial _ is required for MACH builds
            let export_name = export.name.strip_prefix('_').unwrap_or(&export.name);

            if let Ok(plugin_kind) = plugin_kind(export_name) {
                let offset = export.offset;

                let data_view = DataView::from(bytes);

                if macho.is_64 {
                    let raw_desc = data_view.read::<PluginDescriptorInfo64>(offset as usize);
                    #[rustfmt::skip]
                    ret.push(PluginDescriptorInfo{
                        plugin_kind,
                        export_name: export_name.to_string(),
                        file_type: PluginFileType::Mach,
                        architecture: macho_architecture(macho),
                        plugin_version: raw_desc.plugin_version,
                        name: read_string(bytes, macho_va_to_offset(raw_desc.name), raw_desc.name_length as usize)?,
                        version: read_string(bytes, macho_va_to_offset(raw_desc.version), raw_desc.version_length as usize)?,
                        description: read_string(bytes, macho_va_to_offset(raw_desc.description), raw_desc.description_length as usize)?,
                    });
                } else {
                    let raw_desc = data_view.read::<PluginDescriptorInfo32>(offset as usize);
                    #[rustfmt::skip]
                    ret.push(PluginDescriptorInfo{
                        plugin_kind,
                        export_name: export.name.to_string(),
                        file_type: PluginFileType::Mach,
                        architecture: macho_architecture(macho),
                        plugin_version: raw_desc.plugin_version,
                        name: read_string(bytes, macho_va_to_offset(raw_desc.name as u64), raw_desc.name_length as usize)?,
                        version: read_string(bytes, macho_va_to_offset(raw_desc.version as u64), raw_desc.version_length as usize)?,
                        description: read_string(bytes, macho_va_to_offset(raw_desc.description as u64), raw_desc.description_length as usize)?,
                    });
                }
            }
        }
    }

    Ok(ret)
}

fn macho_architecture(macho: &MachO) -> PluginArchitecture {
    // https://crystal-lang.org/api/0.24.0/Debug/MachO/CpuType.html
    match macho.header.cputype {
        7 => PluginArchitecture::X86,
        16777223 => PluginArchitecture::X86_64,
        12 => PluginArchitecture::Arm,
        16777228 => PluginArchitecture::Arm64,
        _ => PluginArchitecture::Unknown(macho.header.cputype),
    }
}

fn macho_va_to_offset(va: u64) -> usize {
    // TODO: why is this offset padded so high? is there a vm base somewhere?
    (va & 0xffff_ffff) as usize
}

/// Parses the descriptors in an ELF binary.
/// This function currently supports x86, x86_64, aarch64 and armv7.
fn elf_parse_descriptors(bytes: &[u8], elf: &Elf) -> Result<Vec<PluginDescriptorInfo>> {
    let mut ret = vec![];

    if !elf.little_endian {
        return Err(Error(ErrorOrigin::Inventory, ErrorKind::NotSupported)
            .log_error("big endian binaries are not supported yet"));
    }

    let iter = elf
        .dynsyms
        .iter()
        .filter(|s| !s.is_import())
        .filter_map(|s| elf.dynstrtab.get_at(s.st_name).map(|n| (s, n)));

    for (sym, export_name) in iter {
        if let Ok(plugin_kind) = plugin_kind(export_name) {
            if sym.st_shndx == SHN_XINDEX as usize {
                return Err(Error(ErrorOrigin::Inventory, ErrorKind::NotSupported)
                    .log_error("unsupported elf SHN_XINDEX header flag"));
            }

            // section
            let section = elf
                .program_headers
                .iter()
                .find(|h| h.vm_range().contains(&(sym.st_value as usize)))
                .ok_or_else(|| {
                    Error(ErrorOrigin::Inventory, ErrorKind::NotFound)
                        .log_error("could not find any section containing the plugin descriptor")
                })?;

            // compute proper file offset based on section
            let offset = section.p_offset + sym.st_value - section.p_vaddr;

            let data_view = DataView::from(bytes);

            if elf.is_64 {
                let mut raw_desc = data_view.read::<PluginDescriptorInfo64>(offset as usize);
                elf_apply_relocs::<u64, _>(
                    elf,
                    sym.st_value..sym.st_value + sym.st_size,
                    &mut raw_desc,
                )?;
                #[rustfmt::skip]
                ret.push(PluginDescriptorInfo{
                    plugin_kind,
                    export_name: export_name.to_string(),
                    file_type: PluginFileType::Elf,
                    architecture: elf_architecture(elf),
                    plugin_version: raw_desc.plugin_version,
                    name: read_string(bytes, raw_desc.name as usize, raw_desc.name_length as usize)?,
                    version: read_string(bytes, raw_desc.version as usize, raw_desc.version_length as usize)?,
                    description: read_string(bytes, raw_desc.description as usize, raw_desc.description_length as usize)?,
                });
            } else {
                let mut raw_desc = data_view.read::<PluginDescriptorInfo32>(offset as usize);
                elf_apply_relocs::<u32, _>(
                    elf,
                    sym.st_value..sym.st_value + sym.st_size,
                    &mut raw_desc,
                )?;
                #[rustfmt::skip]
                ret.push(PluginDescriptorInfo{
                    plugin_kind,
                    export_name: export_name.to_string(),
                    file_type: PluginFileType::Elf,
                    architecture: elf_architecture(elf),
                    plugin_version: raw_desc.plugin_version,
                    name: read_string(bytes, raw_desc.name as usize, raw_desc.name_length as usize)?,
                    version: read_string(bytes, raw_desc.version as usize, raw_desc.version_length as usize)?,
                    description: read_string(bytes, raw_desc.description as usize, raw_desc.description_length as usize)?,
                });
            }
        }
    }

    Ok(ret)
}

fn elf_architecture(elf: &Elf) -> PluginArchitecture {
    // https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html
    match elf.header.e_machine {
        3 => PluginArchitecture::X86,
        62 => PluginArchitecture::X86_64,
        40 => PluginArchitecture::Arm,
        183 => PluginArchitecture::Arm64,
        _ => PluginArchitecture::Unknown(elf.header.e_machine as u32),
    }
}

fn elf_apply_relocs<N, T>(elf: &Elf, va_range: Range<u64>, obj: &mut T) -> Result<()>
where
    N: Pod + Eq + Zero + NumCast + WrappingAdd + WrappingSub,
    T: Pod,
{
    for section_relocs in elf.shdr_relocs.iter() {
        for reloc in section_relocs.1.iter() {
            if reloc.r_offset >= va_range.start && reloc.r_offset < va_range.end {
                let field_offset = reloc.r_offset - va_range.start;

                let data_view = DataView::from_mut(obj);
                let value = data_view.read::<N>(field_offset as usize);

                // skip over entries that already contain the proper reference
                if value != N::zero() {
                    continue;
                }

                // https://chromium.googlesource.com/android_tools/+/8301b711a9ac7de56e9a9ff3dee0b2ebfc9a380f/ndk/sources/android/crazy_linker/src/crazy_linker_elf_relocations.cpp#36
                // TODO: generalize this check
                if reloc.r_type != 8 && reloc.r_type != 23 && reloc.r_type != 1027 {
                    return Err(Error(ErrorOrigin::Inventory, ErrorKind::NotSupported)
                        .log_error("only relative relocations are supported right now"));
                }

                // simulate a `wrapping_add_signed`
                let addend = reloc.r_addend.unwrap_or_default();
                let value = if addend > 0 {
                    value.wrapping_add(&(num_traits::cast(addend).unwrap()))
                } else {
                    value.wrapping_sub(&(num_traits::cast(-addend).unwrap()))
                };
                data_view.write::<N>(field_offset as usize, &value);
            }
        }
    }
    Ok(())
}

#[cfg(test)]
mod tests {
    use super::*;

    const NAME: &str = "coredump";
    const VERSION: &str = "0.2.0";
    const DESCRIPTION: &str =
        "win32 coredump connector for the memflow physical memory introspection framework";

    #[test]
    fn test_pe_x86_64() {
        let file = include_bytes!("../../../assets/tests/memflow_coredump.x86_64.dll");

        assert_eq!(is_binary(&file[..]), Ok(()));

        assert_eq!(
            parse_descriptors(&file[..]).unwrap(),
            vec![PluginDescriptorInfo {
                plugin_kind: PluginKind::Connector,
                export_name: "MEMFLOW_CONNECTOR_COREDUMP".to_owned(),
                file_type: PluginFileType::Pe,
                architecture: PluginArchitecture::X86_64,
                plugin_version: 1,
                name: NAME.to_owned(),
                version: VERSION.to_owned(),
                description: DESCRIPTION.to_owned(),
            }]
        );
    }

    #[test]
    fn test_pe_x86() {
        let file = include_bytes!("../../../assets/tests/memflow_coredump.x86.dll");

        assert_eq!(is_binary(&file[..]), Ok(()));

        assert_eq!(
            parse_descriptors(&file[..]).unwrap(),
            vec![PluginDescriptorInfo {
                plugin_kind: PluginKind::Connector,
                export_name: "MEMFLOW_CONNECTOR_COREDUMP".to_owned(),
                file_type: PluginFileType::Pe,
                architecture: PluginArchitecture::X86,
                plugin_version: 1,
                name: NAME.to_owned(),
                version: VERSION.to_owned(),
                description: DESCRIPTION.to_owned(),
            }]
        );
    }

    #[test]
    fn test_elf_x86_64() {
        let file = include_bytes!("../../../assets/tests/libmemflow_coredump.x86_64.so");

        assert_eq!(is_binary(&file[..]), Ok(()));

        assert_eq!(
            parse_descriptors(&file[..]).unwrap(),
            vec![PluginDescriptorInfo {
                plugin_kind: PluginKind::Connector,
                export_name: "MEMFLOW_CONNECTOR_COREDUMP".to_owned(),
                file_type: PluginFileType::Elf,
                architecture: PluginArchitecture::X86_64,
                plugin_version: 1,
                name: NAME.to_owned(),
                version: VERSION.to_owned(),
                description: DESCRIPTION.to_owned(),
            }]
        );
    }

    #[test]
    fn test_elf_x86() {
        let file = include_bytes!("../../../assets/tests/libmemflow_coredump.x86.so");

        assert_eq!(is_binary(&file[..]), Ok(()));

        assert_eq!(
            parse_descriptors(&file[..]).unwrap(),
            vec![PluginDescriptorInfo {
                plugin_kind: PluginKind::Connector,
                export_name: "MEMFLOW_CONNECTOR_COREDUMP".to_owned(),
                file_type: PluginFileType::Elf,
                architecture: PluginArchitecture::X86,
                plugin_version: 1,
                name: NAME.to_owned(),
                version: VERSION.to_owned(),
                description: DESCRIPTION.to_owned(),
            }]
        );
    }

    #[test]
    fn test_elf_arm64() {
        let file = include_bytes!("../../../assets/tests/libmemflow_coredump.aarch64.so");

        assert_eq!(is_binary(&file[..]), Ok(()));

        assert_eq!(
            parse_descriptors(&file[..]).unwrap(),
            vec![PluginDescriptorInfo {
                plugin_kind: PluginKind::Connector,
                export_name: "MEMFLOW_CONNECTOR_COREDUMP".to_owned(),
                file_type: PluginFileType::Elf,
                architecture: PluginArchitecture::Arm64,
                plugin_version: 1,
                name: NAME.to_owned(),
                version: VERSION.to_owned(),
                description: DESCRIPTION.to_owned(),
            }]
        );
    }

    #[test]
    fn test_elf_arm() {
        let file = include_bytes!("../../../assets/tests/libmemflow_coredump.arm.so");

        assert_eq!(is_binary(&file[..]), Ok(()));

        assert_eq!(
            parse_descriptors(&file[..]).unwrap(),
            vec![PluginDescriptorInfo {
                plugin_kind: PluginKind::Connector,
                export_name: "MEMFLOW_CONNECTOR_COREDUMP".to_owned(),
                file_type: PluginFileType::Elf,
                architecture: PluginArchitecture::Arm,
                plugin_version: 1,
                name: NAME.to_owned(),
                version: VERSION.to_owned(),
                description: DESCRIPTION.to_owned(),
            }]
        );
    }

    #[test]
    fn test_mach_arm64() {
        let file = include_bytes!("../../../assets/tests/libmemflow_native.aarch64.dylib");

        assert_eq!(is_binary(&file[..]), Ok(()));

        assert_eq!(
            parse_descriptors(&file[..]).unwrap(),
            vec![PluginDescriptorInfo {
                plugin_kind: PluginKind::Os,
                export_name: "MEMFLOW_OS_NATIVE".to_owned(),
                file_type: PluginFileType::Mach,
                architecture: PluginArchitecture::Arm64,
                plugin_version: 1,
                name: "native".to_owned(),
                version: "0.2.2".to_owned(),
                description: "System call based proxy-OS for memflow".to_owned(),
            }]
        );
    }
}