summaryrefslogtreecommitdiffstats
path: root/src/detection/physicalmemory/physicalmemory.c
blob: 0188e054478c063592fe91de2e92dc474f854202 (plain) (blame)
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
#include "physicalmemory.h"

static inline const char* getVendorString(unsigned vendorId) {
    switch (vendorId) {
        case 0x017A:
            return "Apacer";
        case 0x0198:
            return "Kingston";
        case 0x029E:
            return "Corsair";
        case 0x04CB:
            return "A-DATA";
        case 0x04CD:
            return "G-Skill";
        case 0x059B:
        case 0x859B:
            return "Crucial";
        case 0x00CE:
        case 0x80CE:
        case 0xCE00:
            return "Samsung";
        case 0x014F:
            return "Transcend";
        case 0x2C00:
        case 0x802C:
            return "Micron";
        case 0xAD00:
        case 0x80AD:
            return "SK Hynix";
        case 0x5105:
        case 0x8551:
            return "Qimonda";
        case 0x02FE:
            return "Elpida";
        case 0x0467:
            return "Ramaxel";
        default:
            return NULL;
    }
}

void FFPhysicalMemoryUpdateVendorString(FFPhysicalMemoryResult* device) {
    if (device->vendor.length == 0) {
        return;
    }
    if (ffStrbufEqualS(&device->vendor, "Unknown")) {
        ffStrbufClear(&device->vendor);
        return;
    }

    char vendorIdStr[5];
    if (ffStrbufStartsWithS(&device->vendor, "0x")) {
        if (device->vendor.length < 6) {
            return;
        }
        memcpy(vendorIdStr, device->vendor.chars + 2, 4);
    } else {
        if (device->vendor.length < 4) {
            return;
        }
        memcpy(vendorIdStr, device->vendor.chars, 4);
    }
    vendorIdStr[4] = '\0';
    char* pEnd = NULL;
    uint32_t vendorId = (uint32_t) strtoul(vendorIdStr, &pEnd, 16);
    if (*pEnd != '\0') {
        return;
    }
    const char* vendorStr = getVendorString(vendorId);
    if (vendorStr) {
        ffStrbufSetStatic(&device->vendor, vendorStr);
    }
}