File: types.cpp

package info (click to toggle)
uefitool 0.28.0%2BA73-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,728 kB
  • sloc: ansic: 55,322; cpp: 23,375; sh: 43; xml: 23; makefile: 5
file content (308 lines) | stat: -rwxr-xr-x 19,442 bytes parent folder | download
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
/* types.cpp
 
 Copyright (c) 2016, Nikolaj Schlej. All rights reserved.
 This program and the accompanying materials
 are licensed and made available under the terms and conditions of the BSD License
 which accompanies this distribution.  The full text of the license may be found at
 http://opensource.org/licenses/bsd-license.php
 
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
 WITHWARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 */

#include "ustring.h"
#include "types.h"
#include "ffs.h"
#include "intel_fit.h"

UString regionTypeToUString(const UINT8 type)
{
    switch (type) {
        // Intel specific
        case Subtypes::DescriptorRegion:  return UString("Descriptor");
        case Subtypes::BiosRegion:        return UString("BIOS");
        case Subtypes::MeRegion:          return UString("ME");
        case Subtypes::GbeRegion:         return UString("GbE");
        case Subtypes::PdrRegion:         return UString("PDR");
        case Subtypes::DevExp1Region:     return UString("DevExp1");
        case Subtypes::Bios2Region:       return UString("BIOS2");
        case Subtypes::MicrocodeRegion:   return UString("Microcode");
        case Subtypes::EcRegion:          return UString("EC");
        case Subtypes::DevExp2Region:     return UString("DevExp2");
        case Subtypes::IeRegion:          return UString("IE");
        case Subtypes::Tgbe1Region:       return UString("10GbE1");
        case Subtypes::Tgbe2Region:       return UString("10GbE2");
        case Subtypes::Reserved1Region:   return UString("Reserved1");
        case Subtypes::Reserved2Region:   return UString("Reserved2");
        case Subtypes::PttRegion:         return UString("PTT");
        // AMD specific
        case Subtypes::PspL1DirectoryRegion:return UString("PSP directory");
        case Subtypes::PspL2DirectoryRegion:return UString("PSP L2 directory");
        case Subtypes::PspDirectoryFile:    return UString("PSP file");
    };
    
    return  usprintf("Unknown %02Xh", type);
}

UString itemTypeToUString(const UINT8 type)
{
    switch (type) {
        case Types::Root:                       return UString("Root");
        case Types::Image:                      return UString("Image");
        case Types::Capsule:                    return UString("Capsule");
        case Types::Region:                     return UString("Region");
        case Types::Volume:                     return UString("Volume");
        case Types::Padding:                    return UString("Padding");
        case Types::File:                       return UString("File");
        case Types::Section:                    return UString("Section");
        case Types::FreeSpace:                  return UString("Free space");
        case Types::VssStore:                   return UString("VSS store");
        case Types::Vss2Store:                  return UString("VSS2 store");
        case Types::FtwStore:                   return UString("FTW store");
        case Types::FdcStore:                   return UString("FDC store");
        case Types::SysFStore:                  return UString("SysF store");
        case Types::EvsaStore:                  return UString("EVSA store");
        case Types::CmdbStore:                  return UString("CMDB store");
        case Types::PhoenixFlashMapStore:       return UString("FlashMap store");
        case Types::InsydeFlashDeviceMapStore:  return UString("FlashDeviceMap store");
        case Types::DellDvarStore:              return UString("DVAR store");
        case Types::NvarGuidStore:              return UString("NVAR GUID store");
        case Types::NvarEntry:                  return UString("NVAR entry");
        case Types::VssEntry:                   return UString("VSS entry");
        case Types::SysFEntry:                  return UString("SysF entry");
        case Types::EvsaEntry:                  return UString("EVSA entry");
        case Types::PhoenixFlashMapEntry:       return UString("FlashMap entry");
        case Types::InsydeFlashDeviceMapEntry:  return UString("FlashDeviceMap entry");
        case Types::DellDvarEntry:              return UString("DVAR entry");
        case Types::Microcode:                  return UString("Microcode");
        case Types::SlicData:                   return UString("SLIC data");
        case Types::FptStore:                   return UString("FPT store");
        case Types::FptEntry:                   return UString("FPT entry");
        case Types::IfwiHeader:                 return UString("IFWI header");
        case Types::IfwiPartition:              return UString("IFWI partition");
        case Types::FptPartition:               return UString("FPT partition");
        case Types::BpdtStore:                  return UString("BPDT store");
        case Types::BpdtEntry:                  return UString("BPDT entry");
        case Types::BpdtPartition:              return UString("BPDT partition");
        case Types::CpdStore:                   return UString("CPD store");
        case Types::CpdEntry:                   return UString("CPD entry");
        case Types::CpdPartition:               return UString("CPD partition");
        case Types::CpdExtension:               return UString("CPD extension");
        case Types::CpdSpiEntry:                return UString("CPD SPI entry");
        case Types::StartupApDataEntry:         return UString("Startup AP data");
        case Types::DirectoryTable:             return UString("Table");
        case Types::DirectoryTableEntry:        return UString("Table entry");
    }
    
    return usprintf("Unknown %02Xh", type);
}

UString itemSubtypeToUString(const UINT8 type, const UINT8 subtype)
{
    switch (type) {
        case Types::Image:
            if      (subtype == Subtypes::IntelImage)                   return UString("Intel");
            else if (subtype == Subtypes::UefiImage)                    return UString("UEFI");
            else if (subtype == Subtypes::AmdImage)                     return UString("AMD");
            break;
        case Types::Padding:
            if      (subtype == Subtypes::ZeroPadding)                  return UString("Empty (00h)");
            else if (subtype == Subtypes::OnePadding)                   return UString("Empty (FFh)");
            else if (subtype == Subtypes::DataPadding)                  return UString("Non-empty");
            break;
        case Types::Volume:
            if      (subtype == Subtypes::UnknownVolume)                return UString("Unknown");
            else if (subtype == Subtypes::Ffs2Volume)                   return UString("FFSv2");
            else if (subtype == Subtypes::Ffs3Volume)                   return UString("FFSv3");
            else if (subtype == Subtypes::NvramVolume)                  return UString("NVRAM");
            else if (subtype == Subtypes::MicrocodeVolume)              return UString("Microcode");
            break;
        case Types::Capsule:
            if      (subtype == Subtypes::AptioSignedCapsule)           return UString("Aptio signed");
            else if (subtype == Subtypes::AptioUnsignedCapsule)         return UString("Aptio unsigned");
            else if (subtype == Subtypes::UefiCapsule)                  return UString("UEFI 2.0");
            else if (subtype == Subtypes::ToshibaCapsule)               return UString("Toshiba");
            break;
        case Types::Region:                                             return regionTypeToUString(subtype);
        case Types::File:                                               return fileTypeToUString(subtype);
        case Types::Section:                                            return sectionTypeToUString(subtype);
        case Types::NvarEntry:
            if      (subtype == Subtypes::InvalidNvarEntry)             return UString("Invalid");
            else if (subtype == Subtypes::InvalidLinkNvarEntry)         return UString("Invalid link");
            else if (subtype == Subtypes::LinkNvarEntry)                return UString("Link");
            else if (subtype == Subtypes::DataNvarEntry)                return UString("Data");
            else if (subtype == Subtypes::FullNvarEntry)                return UString("Full");
            break;
        case Types::VssEntry:
            if      (subtype == Subtypes::InvalidVssEntry)              return UString("Invalid");
            else if (subtype == Subtypes::StandardVssEntry)             return UString("Standard");
            else if (subtype == Subtypes::AppleVssEntry)                return UString("Apple");
            else if (subtype == Subtypes::AuthVssEntry)                 return UString("Auth");
            else if (subtype == Subtypes::IntelVssEntry)                return UString("Intel");
            break;
        case Types::SysFEntry:
            if      (subtype == Subtypes::InvalidSysFEntry)             return UString("Invalid");
            else if (subtype == Subtypes::NormalSysFEntry)              return UString("Normal");
            break;
        case Types::EvsaEntry:
            if      (subtype == Subtypes::InvalidEvsaEntry)             return UString("Invalid");
            else if (subtype == Subtypes::UnknownEvsaEntry)             return UString("Unknown");
            else if (subtype == Subtypes::GuidEvsaEntry)                return UString("GUID");
            else if (subtype == Subtypes::NameEvsaEntry)                return UString("Name");
            else if (subtype == Subtypes::DataEvsaEntry)                return UString("Data");
            break;
        case Types::PhoenixFlashMapEntry:
            if      (subtype == Subtypes::VolumeFlashMapEntry)          return UString("Volume");
            else if (subtype == Subtypes::DataFlashMapEntry)            return UString("Data");
            else if (subtype == Subtypes::UnknownFlashMapEntry)         return UString("Unknown");
            break;
        case Types::DellDvarEntry:
            if      (subtype == Subtypes::InvalidDvarEntry)             return UString("Invalid");
            else if (subtype == Subtypes::NamespaceGuidDvarEntry)       return UString("NamespaceGuid");
            else if (subtype == Subtypes::NameIdDvarEntry)              return UString("NameId");
            else if (subtype == Subtypes::UnknownDvarEntry)             return UString("Unknown");
            break;
        case Types::Microcode:
            if      (subtype == Subtypes::IntelMicrocode)               return UString("Intel");
            else if (subtype == Subtypes::AmdMicrocode)                 return UString("AMD");
            break;
        case Types::FptEntry:
            if      (subtype == Subtypes::ValidFptEntry)                return UString("Valid");
            else if (subtype == Subtypes::InvalidFptEntry)              return UString("Invalid");
            break;
        case Types::FptPartition:
            if      (subtype == Subtypes::CodeFptPartition)             return UString("Code");
            else if (subtype == Subtypes::DataFptPartition)             return UString("Data");
            else if (subtype == Subtypes::GlutFptPartition)             return UString("GLUT");
            break;
        case Types::IfwiPartition:
            if      (subtype == Subtypes::BootIfwiPartition)            return UString("Boot");
            else if (subtype == Subtypes::DataIfwiPartition)            return UString("Data");
            break;
        case Types::CpdPartition:
            if      (subtype == Subtypes::ManifestCpdPartition)         return UString("Manifest");
            else if (subtype == Subtypes::MetadataCpdPartition)         return UString("Metadata");
            else if (subtype == Subtypes::KeyCpdPartition)              return UString("Key");
            else if (subtype == Subtypes::CodeCpdPartition)             return UString("Code");
            break;
        case Types::StartupApDataEntry:
            if      (subtype == Subtypes::x86128kStartupApDataEntry)    return UString("X86 128K");
            break;
        case Types::DirectoryTable:
            if (subtype == Subtypes::PSPDirectory)                 return UString("PSP table");
            if (subtype == Subtypes::ComboDirectory)               return UString("Combo table");
            if (subtype == Subtypes::BIOSDirectory)                return UString("BIOS table");
            if (subtype == Subtypes::ISHDirectory)                 return UString("ISH table");
            break;
        case Types::DirectoryTableEntry:
            if (subtype == Subtypes::PSPDirectory)                 return UString("PSP directory");
            if (subtype == Subtypes::ComboDirectory)               return UString("Combo directory");
            if (subtype == Subtypes::BIOSDirectory)                return UString("BIOS directory");
            break;
    }
    
    return UString();
}

UString compressionTypeToUString(const UINT8 algorithm)
{
    switch (algorithm) {
        case COMPRESSION_ALGORITHM_NONE:                    return UString("None");
        case COMPRESSION_ALGORITHM_EFI11:                   return UString("EFI 1.1");
        case COMPRESSION_ALGORITHM_TIANO:                   return UString("Tiano");
        case COMPRESSION_ALGORITHM_UNDECIDED:               return UString("Undecided Tiano/EFI 1.1");
        case COMPRESSION_ALGORITHM_LZMA:                    return UString("LZMA");
        case COMPRESSION_ALGORITHM_LZMA_INTEL_LEGACY:       return UString("Intel legacy LZMA");
        case COMPRESSION_ALGORITHM_LZMAF86:                 return UString("LZMAF86");
        case COMPRESSION_ALGORITHM_GZIP:                    return UString("GZip");
        case COMPRESSION_ALGORITHM_ZLIB:                    return UString("Zlib");
        case COMPRESSION_ALGORITHM_BROTLI:                  return UString("Brotli");
    }
    
    return usprintf("Unknown %02Xh", algorithm);
}

UString actionTypeToUString(const UINT8 action)
{
    switch (action) {
        case Actions::NoAction:      return UString();
        case Actions::Create:        return UString("Create");
        case Actions::Insert:        return UString("Insert");
        case Actions::Replace:       return UString("Replace");
        case Actions::Remove:        return UString("Remove");
        case Actions::Rebuild:       return UString("Rebuild");
        case Actions::Rebase:        return UString("Rebase");
    }
    
    return usprintf("Unknown %02Xh", action);
}

UString fitEntryTypeToUString(const UINT8 type)
{
    switch (type & 0x7F) {
        case INTEL_FIT_TYPE_HEADER:                     return UString("FIT Header");
        case INTEL_FIT_TYPE_MICROCODE:                  return UString("Microcode");
        case INTEL_FIT_TYPE_STARTUP_AC_MODULE:          return UString("Startup ACM");
        case INTEL_FIT_TYPE_DIAG_AC_MODULE:             return UString("Diagnostic ACM");
        case INTEL_FIT_TYPE_PLATFORM_BOOT_POLICY:       return UString("Platform Boot Policy");
        case INTEL_FIT_TYPE_FIT_RESET_STATE:            return UString("FIT Reset State");
        case INTEL_FIT_TYPE_BIOS_STARTUP_MODULE:        return UString("BIOS Startup Module");
        case INTEL_FIT_TYPE_TPM_POLICY:                 return UString("TPM Policy");
        case INTEL_FIT_TYPE_BIOS_POLICY:                return UString("BIOS Policy");
        case INTEL_FIT_TYPE_TXT_POLICY:                 return UString("TXT Policy");
        case INTEL_FIT_TYPE_BOOT_GUARD_KEY_MANIFEST:    return UString("BootGuard Key Manifest");
        case INTEL_FIT_TYPE_BOOT_GUARD_BOOT_POLICY:     return UString("BootGuard Boot Policy");
        case INTEL_FIT_TYPE_CSE_SECURE_BOOT:            return UString("CSE SecureBoot Settings");
        case INTEL_FIT_TYPE_VAB_PROVISIONING_TABLE:     return UString("VAB Provisioning Table");
        case INTEL_FIT_TYPE_VAB_KEY_MANIFEST:           return UString("VAB Key Manifest");
        case INTEL_FIT_TYPE_VAB_IMAGE_MANIFEST:         return UString("VAB Image Manifest");
        case INTEL_FIT_TYPE_VAB_IMAGE_HASH_DESCRIPTORS: return UString("VAB Image Hash Descriptors");
        case INTEL_FIT_TYPE_SACM_DEBUG_RECORD:          return UString("SACM Debug Record");
        case INTEL_FIT_TYPE_ACM_FEATURE_POLICY:         return UString("ACM Feature Policy");
        case INTEL_FIT_TYPE_SCRTM_ERROR_RECORD:         return UString("SCRTM Error Record");
        case INTEL_FIT_TYPE_JMP_DEBUG_POLICY:           return UString("JMP Debug Policy");
        case INTEL_FIT_TYPE_EMPTY:                      return UString("Empty");
    }
    
    return usprintf("Unknown %02Xh", (type & 0x7F));
}

UString hashTypeToUString(const UINT16 algorithm_id)
{
    switch (algorithm_id) {
        case TCG_HASH_ALGORITHM_ID_SHA1:   return UString("SHA1");
        case TCG_HASH_ALGORITHM_ID_SHA256: return UString("SHA256");
        case TCG_HASH_ALGORITHM_ID_SHA384: return UString("SHA384");
        case TCG_HASH_ALGORITHM_ID_SHA512: return UString("SHA512");
        case TCG_HASH_ALGORITHM_ID_NULL:   return UString("NULL");
        case TCG_HASH_ALGORITHM_ID_SM3:    return UString("SM3");
    }
    
    return usprintf("Unknown %04Xh", algorithm_id);
}

UString insydeFlashDeviceMapEntryTypeGuidToUString(const EFI_GUID & guid)
{
    const UByteArray baGuid((const char*)&guid, sizeof(EFI_GUID));
    if (baGuid == INSYDE_FLASH_MAP_REGION_BOOT_FV_GUID)          return UString("Boot Firmare Volume");
    if (baGuid == INSYDE_FLASH_MAP_REGION_BVDT_GUID)             return UString("BIOS Version Data Table");
    if (baGuid == INSYDE_FLASH_MAP_REGION_EC_GUID)               return UString("EC Firmware");
    if (baGuid == INSYDE_FLASH_MAP_REGION_FTW_BACKUP_GUID)       return UString("FTW Backup");
    if (baGuid == INSYDE_FLASH_MAP_REGION_FTW_STATE_GUID)        return UString("FTW State");
    if (baGuid == INSYDE_FLASH_MAP_REGION_FV_GUID)               return UString("Firmare Volume");
    if (baGuid == INSYDE_FLASH_MAP_REGION_FLASH_DEVICE_MAP_GUID) return UString("Flash Device Map");
    if (baGuid == INSYDE_FLASH_MAP_REGION_LOGO_GUID)             return UString("Logo");
    if (baGuid == INSYDE_FLASH_MAP_REGION_MICROCODE_GUID)        return UString("Microcode");
    if (baGuid == INSYDE_FLASH_MAP_REGION_MSDM_TABLE_GUID)       return UString("MSDM Table");
    if (baGuid == INSYDE_FLASH_MAP_REGION_MULTI_CONFIG_GUID)     return UString("MultiConfig");
    if (baGuid == INSYDE_FLASH_MAP_REGION_VAR_DEFAULT_GUID)      return UString("Variable Defaults");
    if (baGuid == INSYDE_FLASH_MAP_REGION_SMBIOS_UPDATE_GUID)    return UString("SMBIOS Update");
    if (baGuid == INSYDE_FLASH_MAP_REGION_VAR_GUID)              return UString("Variables");
    if (baGuid == INSYDE_FLASH_MAP_REGION_UNKNOWN_GUID)          return UString("Unknown");
    if (baGuid == INSYDE_FLASH_MAP_REGION_UNUSED_GUID)           return UString("Unused");
    if (baGuid == INSYDE_FLASH_MAP_REGION_USB_OPTION_ROM_GUID)   return UString("USB Option ROM");
    if (baGuid == INSYDE_FLASH_MAP_REGION_DXE_FV_GUID)           return UString("DXE Firmare Volume");
    if (baGuid == INSYDE_FLASH_MAP_REGION_PEI_FV_GUID)           return UString("PEI Firmare Volume");
    if (baGuid == INSYDE_FLASH_MAP_REGION_UNSIGNED_FV_GUID)      return UString("Unsigned Firmare Volume");
    return guidToUString(guid);
}