OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
ValidateDeviceProperties.c
Go to the documentation of this file.
1
16#include "ocvalidate.h"
17#include "OcValidateLib.h"
18
27STATIC
28BOOLEAN
30 IN CONST VOID *PrimaryEntry,
31 IN CONST VOID *SecondaryEntry
32 )
33{
34 CONST OC_STRING *DevPropsAddPrimaryEntry;
35 CONST OC_STRING *DevPropsAddSecondaryEntry;
36 CONST CHAR8 *DevPropsAddPrimaryDevicePathString;
37 CONST CHAR8 *DevPropsAddSecondaryDevicePathString;
38
39 DevPropsAddPrimaryEntry = *(CONST OC_STRING **)PrimaryEntry;
40 DevPropsAddSecondaryEntry = *(CONST OC_STRING **)SecondaryEntry;
41 DevPropsAddPrimaryDevicePathString = OC_BLOB_GET (DevPropsAddPrimaryEntry);
42 DevPropsAddSecondaryDevicePathString = OC_BLOB_GET (DevPropsAddSecondaryEntry);
43
44 return StringIsDuplicated ("DeviceProperties->Add", DevPropsAddPrimaryDevicePathString, DevPropsAddSecondaryDevicePathString);
45}
46
55STATIC
56BOOLEAN
58 IN CONST VOID *PrimaryEntry,
59 IN CONST VOID *SecondaryEntry
60 )
61{
62 CONST OC_STRING *DevPropsDeletePrimaryEntry;
63 CONST OC_STRING *DevPropsDeleteSecondaryEntry;
64 CONST CHAR8 *DevPropsDeletePrimaryDevicePathString;
65 CONST CHAR8 *DevPropsDeleteSecondaryDevicePathString;
66
67 DevPropsDeletePrimaryEntry = *(CONST OC_STRING **)PrimaryEntry;
68 DevPropsDeleteSecondaryEntry = *(CONST OC_STRING **)SecondaryEntry;
69 DevPropsDeletePrimaryDevicePathString = OC_BLOB_GET (DevPropsDeletePrimaryEntry);
70 DevPropsDeleteSecondaryDevicePathString = OC_BLOB_GET (DevPropsDeleteSecondaryEntry);
71
72 return StringIsDuplicated ("DeviceProperties->Delete", DevPropsDeletePrimaryDevicePathString, DevPropsDeleteSecondaryDevicePathString);
73}
74
75STATIC
76UINT32
78 IN OC_GLOBAL_CONFIG *Config
79 )
80{
81 UINT32 ErrorCount;
82 UINT32 DeviceIndex;
83 UINT32 PropertyIndex;
84 CONST CHAR8 *AsciiDevicePath;
85 CONST CHAR8 *AsciiProperty;
86 OC_ASSOC *PropertyMap;
87
88 ErrorCount = 0;
89
90 for (DeviceIndex = 0; DeviceIndex < Config->DeviceProperties.Add.Count; ++DeviceIndex) {
91 AsciiDevicePath = OC_BLOB_GET (Config->DeviceProperties.Add.Keys[DeviceIndex]);
92
93 if (!AsciiDevicePathIsLegal (AsciiDevicePath)) {
94 DEBUG ((DEBUG_WARN, "DeviceProperties->Add[%u]->DevicePath is borked! Please check the information above!\n", DeviceIndex));
95 ++ErrorCount;
96 }
97
98 PropertyMap = Config->DeviceProperties.Add.Values[DeviceIndex];
99 for (PropertyIndex = 0; PropertyIndex < PropertyMap->Count; ++PropertyIndex) {
100 AsciiProperty = OC_BLOB_GET (PropertyMap->Keys[PropertyIndex]);
101
102 //
103 // Sanitise strings.
104 //
105 if (!AsciiPropertyIsLegal (AsciiProperty)) {
106 DEBUG ((
107 DEBUG_WARN,
108 "DeviceProperties->Add[%u]->Property[%u] contains illegal character!\n",
109 DeviceIndex,
110 PropertyIndex
111 ));
112 ++ErrorCount;
113 }
114 }
115
116 //
117 // Check duplicated properties in DeviceProperties->Add[N].
118 //
119 ErrorCount += FindArrayDuplication (
120 PropertyMap->Keys,
121 PropertyMap->Count,
122 sizeof (PropertyMap->Keys[0]),
124 );
125 }
126
127 //
128 // Check duplicated entries in DeviceProperties->Add.
129 //
130 ErrorCount += FindArrayDuplication (
131 Config->DeviceProperties.Add.Keys,
132 Config->DeviceProperties.Add.Count,
133 sizeof (Config->DeviceProperties.Add.Keys[0]),
135 );
136
137 return ErrorCount;
138}
139
140STATIC
141UINT32
143 IN OC_GLOBAL_CONFIG *Config
144 )
145{
146 UINT32 ErrorCount;
147 UINT32 DeviceIndex;
148 UINT32 PropertyIndex;
149 CONST CHAR8 *AsciiDevicePath;
150 CONST CHAR8 *AsciiProperty;
151
152 ErrorCount = 0;
153
154 for (DeviceIndex = 0; DeviceIndex < Config->DeviceProperties.Delete.Count; ++DeviceIndex) {
155 AsciiDevicePath = OC_BLOB_GET (Config->DeviceProperties.Delete.Keys[DeviceIndex]);
156
157 if (!AsciiDevicePathIsLegal (AsciiDevicePath)) {
158 DEBUG ((DEBUG_WARN, "DeviceProperties->Delete[%u]->DevicePath is borked! Please check the information above!\n", DeviceIndex));
159 ++ErrorCount;
160 }
161
162 for (PropertyIndex = 0; PropertyIndex < Config->DeviceProperties.Delete.Values[DeviceIndex]->Count; ++PropertyIndex) {
163 AsciiProperty = OC_BLOB_GET (Config->DeviceProperties.Delete.Values[DeviceIndex]->Values[PropertyIndex]);
164
165 //
166 // Sanitise strings.
167 //
168 if (!AsciiPropertyIsLegal (AsciiProperty)) {
169 DEBUG ((
170 DEBUG_WARN,
171 "DeviceProperties->Delete[%u]->Property[%u] contains illegal character!\n",
172 DeviceIndex,
173 PropertyIndex
174 ));
175 ++ErrorCount;
176 }
177 }
178
179 //
180 // Check duplicated properties in DeviceProperties->Delete[N].
181 //
182 ErrorCount += FindArrayDuplication (
183 Config->DeviceProperties.Delete.Values[DeviceIndex]->Values,
184 Config->DeviceProperties.Delete.Values[DeviceIndex]->Count,
185 sizeof (Config->DeviceProperties.Delete.Values[DeviceIndex]->Values[0]),
187 );
188 }
189
190 //
191 // Check duplicated entries in DeviceProperties->Delete.
192 //
193 ErrorCount += FindArrayDuplication (
194 Config->DeviceProperties.Delete.Keys,
195 Config->DeviceProperties.Delete.Count,
196 sizeof (Config->DeviceProperties.Delete.Keys[0]),
198 );
199
200 return ErrorCount;
201}
202
203UINT32
205 IN OC_GLOBAL_CONFIG *Config
206 )
207{
208 UINT32 ErrorCount;
209 UINTN Index;
210 STATIC CONFIG_CHECK DevicePropertiesCheckers[] = {
213 };
214
215 DEBUG ((DEBUG_VERBOSE, "config loaded into %a!\n", __func__));
216
217 ErrorCount = 0;
218
219 for (Index = 0; Index < ARRAY_SIZE (DevicePropertiesCheckers); ++Index) {
220 ErrorCount += DevicePropertiesCheckers[Index](Config);
221 }
222
223 return ReportError (__func__, ErrorCount);
224}
#define ARRAY_SIZE(Array)
Definition AppleMacEfi.h:34
#define OC_BLOB_GET(Blob)
BOOLEAN AsciiDevicePathIsLegal(IN CONST CHAR8 *AsciiDevicePath)
UINT32 ReportError(IN CONST CHAR8 *FuncName, IN UINT32 ErrorCount)
BOOLEAN StringIsDuplicated(IN CONST CHAR8 *EntrySection, IN CONST CHAR8 *FirstString, IN CONST CHAR8 *SecondString)
UINT32 FindArrayDuplication(IN VOID *First, IN UINTN Number, IN UINTN Size, IN DUPLICATION_CHECK DupChecker)
BOOLEAN AsciiPropertyIsLegal(IN CONST CHAR8 *Property)
STATIC UINT32 CheckDevicePropertiesAdd(IN OC_GLOBAL_CONFIG *Config)
STATIC BOOLEAN DevPropsDeleteHasDuplication(IN CONST VOID *PrimaryEntry, IN CONST VOID *SecondaryEntry)
STATIC BOOLEAN DevPropsAddHasDuplication(IN CONST VOID *PrimaryEntry, IN CONST VOID *SecondaryEntry)
STATIC UINT32 CheckDevicePropertiesDelete(IN OC_GLOBAL_CONFIG *Config)
UINT32 CheckDeviceProperties(IN OC_GLOBAL_CONFIG *Config)
UINT32(* CONFIG_CHECK)(IN OC_GLOBAL_CONFIG *Config)
Definition ocvalidate.h:27