29 gettimeofday (&Time, NULL);
33 return Time.tv_sec * 1000LL + Time.tv_usec / 1000LL;
44 PathLength = AsciiStrLen (Path);
46 for (Index = 0; Index < PathLength; ++Index) {
52 || (Path[Index] ==
'_')
53 || (Path[Index] ==
'-')
54 || (Path[Index] ==
'.')
55 || (Path[Index] ==
'/')
56 || (Path[Index] ==
'\\'))
72 IN CONST CHAR8 *Comment
78 CommentLength = AsciiStrLen (Comment);
80 for (Index = 0; Index < CommentLength; ++Index) {
94 IN CONST CHAR8 *Identifier,
95 IN BOOLEAN IsKernelIdentifier
99 UINTN IdentifierLength;
101 if (IsKernelIdentifier) {
105 if (AsciiStrCmp (Identifier,
"kernel") == 0) {
113 if ( (AsciiStrCmp (Identifier,
"Any") == 0)
114 || (AsciiStrCmp (Identifier,
"Apple") == 0))
134 IdentifierLength = AsciiStrLen (Identifier);
136 for (Index = 0; Index < IdentifierLength; ++Index) {
143 || (Identifier[Index] ==
'_')
144 || (Identifier[Index] ==
'-')
145 || (Identifier[Index] ==
'.'))
161 IN CONST CHAR8 *Arch,
162 IN BOOLEAN IsKernelArch
172 if ( (AsciiStrCmp (Arch,
"Auto") == 0)
173 || (AsciiStrCmp (Arch,
"i386-user32") == 0))
181 if (AsciiStrCmp (Arch,
"Any") == 0) {
190 if ( (AsciiStrCmp (Arch,
"i386") != 0)
191 && (AsciiStrCmp (Arch,
"x86_64") != 0))
201 IN CONST CHAR8 *Property
213 IN CONST CHAR8 *Driver,
214 IN CONST UINTN DriverIndex
220 DriverLength = AsciiStrLen (Driver);
221 if (DriverLength == 0) {
222 DEBUG ((DEBUG_WARN,
"UEFI->Drivers[%u].Path value is missing!\n", DriverIndex));
231 DEBUG ((DEBUG_WARN,
"UEFI->Drivers[%u].Path does not end with \"%a\"!\n", DriverIndex,
".efi"));
235 for (Index = 0; Index < DriverLength; ++Index) {
241 || (Driver[Index] ==
'_')
242 || (Driver[Index] ==
'-')
243 || (Driver[Index] ==
'.')
244 || (Driver[Index] ==
'/'))
252 DEBUG ((DEBUG_WARN,
"UEFI->Drivers[%u].Path contains illegal character!\n", DriverIndex));
261 IN CONST CHAR8 *AsciiDevicePath
265 CHAR16 *UnicodeDevicePath;
266 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
267 CHAR16 *TextualDevicePath;
275 if (UnicodeDevicePath != NULL) {
279 DevicePath = ConvertTextToDevicePath (UnicodeDevicePath);
280 if (DevicePath != NULL) {
284 TextualDevicePath = ConvertDevicePathToText (DevicePath, FALSE, FALSE);
285 if (TextualDevicePath != NULL) {
290 if (
OcStriCmp (UnicodeDevicePath, TextualDevicePath) != 0) {
293 "Original path: %s\nPath after internal conversion: %s\n",
303 FreePool (TextualDevicePath);
306 FreePool (DevicePath);
309 FreePool (UnicodeDevicePath);
317 IN CONST CHAR8 *AsciiGuid
323 Status = AsciiStrToGuid (AsciiGuid, &Guid);
328 return !EFI_ERROR (Status);
339 CONST UINT8 *ByteData;
340 CONST UINT8 *ByteMask;
343 if (DataSize != MaskSize) {
347 ByteData = (CONST UINT8 *)Data;
348 ByteMask = (CONST UINT8 *)Mask;
350 for (Index = 0; Index < DataSize; ++Index) {
354 if ((ByteData[Index] & ~ByteMask[Index]) != 0) {
364 IN CONST CHAR8 *PatchSection,
365 IN UINT32 PatchIndex,
366 IN BOOLEAN FindSizeCanBeZero,
367 IN CONST UINT8 *Find,
369 IN CONST UINT8 *Replace,
370 IN UINT32 ReplaceSize,
371 IN CONST UINT8 *Mask,
373 IN CONST UINT8 *ReplaceMask,
374 IN UINT32 ReplaceMaskSize
384 if (!FindSizeCanBeZero && (FindSize != ReplaceSize)) {
387 "%a[%u] has different Find and Replace size (%u vs %u)!\n",
400 if (MaskSize != FindSize) {
403 "%a[%u] has Mask set but its size is different from Find (%u vs %u)!\n",
416 "%a[%u]->Find requires Mask to be active for corresponding bits!\n",
424 if (ReplaceMaskSize > 0) {
428 if (ReplaceMaskSize != ReplaceSize) {
431 "%a[%u] has ReplaceMask set but its size is different from Replace (%u vs %u)!\n",
444 "%a[%u]->Replace requires ReplaceMask to be active for corresponding bits!\n",
466 CONST UINT8 *PrimaryEntry;
467 CONST UINT8 *SecondaryEntry;
471 for (Index = 0; Index < Number; ++Index) {
472 for (Index2 = Index + 1; Index2 < Number; ++Index2) {
477 PrimaryEntry = (UINT8 *)First +
Size * Index;
478 SecondaryEntry = (UINT8 *)First +
Size * Index2;
479 if (DupChecker (PrimaryEntry, SecondaryEntry)) {
483 DEBUG ((DEBUG_WARN,
"at Index %u and %u!\n", Index, Index2));
494 IN CONST CHAR8 *EntrySection,
495 IN CONST CHAR8 *FirstString,
496 IN CONST CHAR8 *SecondString
499 if (AsciiStrCmp (FirstString, SecondString) == 0) {
503 DEBUG ((DEBUG_WARN,
"%a: %a is duplicated ", EntrySection, FirstString[0] !=
'\0' ? FirstString :
"<empty string>"));
512 IN CONST CHAR8 *FuncName,
516 if (ErrorCount != 0) {
517 DEBUG ((DEBUG_WARN,
"%a returns %u %a!\n", FuncName, ErrorCount, ErrorCount > 1 ?
"errors" :
"error"));
519 DEBUG ((DEBUG_VERBOSE,
"%a returns no errors!\n", FuncName));
DMG_SIZE_DEVICE_PATH Size
INTN IsAsciiAlpha(IN CHAR8 Char)
BOOLEAN IsAsciiNumber(IN CHAR8 Char)
BOOLEAN IsAsciiPrint(IN CHAR8 Char)
CHAR8 *EFIAPI OcAsciiStrChr(IN CONST CHAR8 *String, IN CHAR8 Char)
BOOLEAN EFIAPI OcAsciiEndsWith(IN CONST CHAR8 *String, IN CONST CHAR8 *SearchString, IN BOOLEAN CaseInsensitiveMatch)
INTN EFIAPI OcStriCmp(IN CONST CHAR16 *FirstString, IN CONST CHAR16 *SecondString)
CHAR16 * AsciiStrCopyToUnicode(IN CONST CHAR8 *String, IN UINTN Length)
BOOLEAN AsciiDevicePathIsLegal(IN CONST CHAR8 *AsciiDevicePath)
BOOLEAN DataHasProperMasking(IN CONST VOID *Data, IN CONST VOID *Mask, IN UINTN DataSize, IN UINTN MaskSize)
UINT32 ReportError(IN CONST CHAR8 *FuncName, IN UINT32 ErrorCount)
BOOLEAN AsciiArchIsLegal(IN CONST CHAR8 *Arch, IN BOOLEAN IsKernelArch)
UINT32 ValidatePatch(IN CONST CHAR8 *PatchSection, IN UINT32 PatchIndex, IN BOOLEAN FindSizeCanBeZero, IN CONST UINT8 *Find, IN UINT32 FindSize, IN CONST UINT8 *Replace, IN UINT32 ReplaceSize, IN CONST UINT8 *Mask, IN UINT32 MaskSize, IN CONST UINT8 *ReplaceMask, IN UINT32 ReplaceMaskSize)
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)
INT64 GetCurrentTimestamp(VOID)
BOOLEAN AsciiFileSystemPathIsLegal(IN CONST CHAR8 *Path)
BOOLEAN AsciiIdentifierIsLegal(IN CONST CHAR8 *Identifier, IN BOOLEAN IsKernelIdentifier)
BOOLEAN AsciiGuidIsLegal(IN CONST CHAR8 *AsciiGuid)
BOOLEAN AsciiCommentIsLegal(IN CONST CHAR8 *Comment)
BOOLEAN AsciiUefiDriverIsLegal(IN CONST CHAR8 *Driver, IN CONST UINTN DriverIndex)
BOOLEAN AsciiPropertyIsLegal(IN CONST CHAR8 *Property)
BOOLEAN(* DUPLICATION_CHECK)(IN CONST VOID *PrimaryEntry, IN CONST VOID *SecondaryEntry)