static VOID PrepareBlankLine(VOID) { UINTN i; MyFreePool(BlankLine); // make a buffer for a whole text line BlankLine = AllocatePool((ConWidth + 1) * sizeof(CHAR16)); for (i = 0; i < ConWidth; i++) BlankLine[i] = ' '; BlankLine[i] = 0; }
// Function to tell the firmware that OS X is being launched. This is // required to work around problems on some Macs that don't fully // initialize some hardware (especially video displays) when third-party // OSes are launched in EFI mode. EFI_STATUS SetAppleOSInfo() { CHAR16 *AppleOSVersion = NULL; CHAR8 *AppleOSVersion8 = NULL; EFI_STATUS Status; EFI_GUID apple_set_os_guid = EFI_APPLE_SET_OS_PROTOCOL_GUID; EfiAppleSetOsInterface *SetOs = NULL; Status = refit_call3_wrapper(BS->LocateProtocol, &apple_set_os_guid, NULL, (VOID**) &SetOs); // If not a Mac, ignore the call.... if ((Status != EFI_SUCCESS) || (!SetOs)) return EFI_SUCCESS; if ((SetOs->Version != 0) && GlobalConfig.SpoofOSXVersion) { AppleOSVersion = StrDuplicate(L"Mac OS X"); MergeStrings(&AppleOSVersion, GlobalConfig.SpoofOSXVersion, ' '); if (AppleOSVersion) { AppleOSVersion8 = AllocateZeroPool((StrLen(AppleOSVersion) + 1) * sizeof(CHAR8)); UnicodeStrToAsciiStr(AppleOSVersion, AppleOSVersion8); if (AppleOSVersion8) { Status = refit_call1_wrapper (SetOs->SetOsVersion, AppleOSVersion8); if (!EFI_ERROR(Status)) Status = EFI_SUCCESS; MyFreePool(AppleOSVersion8); } else { Status = EFI_OUT_OF_RESOURCES; Print(L"Out of resources in SetAppleOSInfo!\n"); } if ((Status == EFI_SUCCESS) && (SetOs->Version == 2)) Status = refit_call1_wrapper (SetOs->SetOsVendor, (CHAR8 *) "Apple Inc."); MyFreePool(AppleOSVersion); } // if (AppleOSVersion) } // if if (Status != EFI_SUCCESS) Print(L"Unable to set firmware boot type!\n"); return (Status); } // EFI_STATUS SetAppleOSInfo()
// Get CSR (Apple's System Integrity Protection [SIP], or "rootless") status // information. If the variable is not present and the firmware is Apple, fake // it and claim it's enabled, since that's how OS X 10.11 treats a system with // the variable absent. EFI_STATUS GetCsrStatus(UINT32 *CsrStatus) { UINT32 *ReturnValue = NULL; UINTN CsrLength; EFI_GUID CsrGuid = CSR_GUID; EFI_STATUS Status = EFI_INVALID_PARAMETER; if (CsrStatus) { Status = EfivarGetRaw(&CsrGuid, L"csr-active-config", (CHAR8**) &ReturnValue, &CsrLength); if (Status == EFI_SUCCESS) { if (CsrLength == 4) { *CsrStatus = *ReturnValue; } else { Status = EFI_BAD_BUFFER_SIZE; SPrint(gCsrStatus, 255, L" Unknown System Integrity Protection version"); } MyFreePool(ReturnValue); } else if ((Status == EFI_NOT_FOUND) && (StriSubCmp(L"Apple", ST->FirmwareVendor))) { *CsrStatus = SIP_ENABLED; Status = EFI_SUCCESS; } // if (Status == EFI_SUCCESS) } // if (CsrStatus) return Status; } // INTN GetCsrStatus()
// // Searches for free disk space to allocate FS area there. // NTSTATUS FsLibGetFsArea( IN OUT PBK_FS_AREA pFsArea ) { PVOID WorkBuffer = NULL; NTSTATUS ntStatus; OBJECT_ATTRIBUTES oa; IO_STATUS_BLOCK IoStatus; pFsArea->pDeviceName = &g_FsVolumeDevice; InitializeObjectAttributes(&oa, pFsArea->pDeviceName, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL); ntStatus = ZwOpenFile(&pFsArea->hDevice, GENERIC_READ | GENERIC_WRITE | SYNCHRONIZE, &oa, &IoStatus, FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT); if (NT_SUCCESS(ntStatus)) { if (WorkBuffer = MyAllocatePool(PagedPool, PAGE_SIZE)) { // Searching for FS area. ntStatus = BkAllocateFsArea(pFsArea, WorkBuffer); MyFreePool(WorkBuffer); } // if (WorkBuffer = MyAllocatePool(PagedPool, PAGE_SIZE)) else ntStatus = STATUS_INSUFFICIENT_RESOURCES; ZwClose(pFsArea->hDevice); } // if (NT_SUCCESS(ntStatus)) if (!NT_SUCCESS(ntStatus)) { KdPrint(("VFS: Unable to allocate FS area, status 0x%x\n", ntStatus)); } return(ntStatus); }
VOID BltClearScreen(BOOLEAN ShowBanner) { static EG_IMAGE *Banner = NULL; EG_IMAGE *NewBanner = NULL; INTN BannerPosX, BannerPosY; EG_PIXEL Black = { 0x0, 0x0, 0x0, 0 }; if (ShowBanner && !(GlobalConfig.HideUIFlags & HIDEUI_FLAG_BANNER)) { // load banner on first call if (Banner == NULL) { if (GlobalConfig.BannerFileName) Banner = egLoadImage(SelfDir, GlobalConfig.BannerFileName, FALSE); if (Banner == NULL) Banner = egPrepareEmbeddedImage(&egemb_refind_banner, FALSE); } if (Banner) { if (GlobalConfig.BannerScale == BANNER_FILLSCREEN) { if ((Banner->Height != UGAHeight) || (Banner->Width != UGAWidth)) { NewBanner = egScaleImage(Banner, UGAWidth, UGAHeight); } // if } else if ((Banner->Width > UGAWidth) || (Banner->Height > UGAHeight)) { NewBanner = egCropImage(Banner, 0, 0, (Banner->Width > UGAWidth) ? UGAWidth : Banner->Width, (Banner->Height > UGAHeight) ? UGAHeight : Banner->Height); } // if/elseif if (NewBanner) { MyFreePool(Banner); Banner = NewBanner; } MenuBackgroundPixel = Banner->PixelData[0]; } // if Banner exists // clear and draw banner if (GlobalConfig.ScreensaverTime != -1) egClearScreen(&MenuBackgroundPixel); else egClearScreen(&Black); if (Banner != NULL) { BannerPosX = (Banner->Width < UGAWidth) ? ((UGAWidth - Banner->Width) / 2) : 0; BannerPosY = (INTN) (ComputeRow0PosY() / 2) - (INTN) Banner->Height; if (BannerPosY < 0) BannerPosY = 0; GlobalConfig.BannerBottomEdge = BannerPosY + Banner->Height; if (GlobalConfig.ScreensaverTime != -1) BltImage(Banner, (UINTN) BannerPosX, (UINTN) BannerPosY); } } else { // not showing banner // clear to menu background color egClearScreen(&MenuBackgroundPixel); if (GlobalConfig.SavedScreen != NULL) { BltImage(GlobalConfig.SavedScreen, 0, 0); } } GraphicsScreenDirty = FALSE; egFreeImage(GlobalConfig.ScreenBackground); GlobalConfig.ScreenBackground = egCopyScreen(); } // VOID BltClearScreen()
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Searches for files according to specified Mask starting from specified Path. Links all found into the FileListHead. // Returns number of files found. // ULONG FilesFind( PWCHAR Directory, // directory name to search in PWCHAR Mask, // search mask ULONG Flags, // variouse flags PLIST_ENTRY FileListHead // result list of file descriptors ) { ULONG bSize, Found = 0; HANDLE hDir; NTSTATUS ntStatus; UNICODE_STRING uDirectory; OBJECT_ATTRIBUTES oa = {0}; IO_STATUS_BLOCK IoStatus = {0}; PFILE_DIRECTORY_INFORMATION FileInfo, CurInfo; PFILE_DIRECTORY_ENTRY DirEntry; ULONG DirLenBytes = wcslen(Directory) * sizeof(WCHAR); RtlInitUnicodeString(&uDirectory, Directory); InitializeObjectAttributes(&oa, &uDirectory, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, 0, NULL); ntStatus = ZwCreateFile(&hDir, GENERIC_READ, &oa, &IoStatus, NULL, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_OPEN, FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0); if (NT_SUCCESS(ntStatus)) { if (FileInfo = MyAllocatePool(PagedPool, PAGE_SIZE)) { do { ntStatus = ZwQueryDirectoryFile(hDir, NULL, NULL, 0, &IoStatus, FileInfo, PAGE_SIZE - sizeof(WCHAR), FileDirectoryInformation, FALSE, NULL, FALSE); if (NT_SUCCESS(ntStatus)) { CurInfo = FileInfo; do { if (CurInfo->FileName[0] != '.') { if (!(CurInfo->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) || (Flags & FILES_FIND_DIRECTORIES)) { ULONG NameLen = CurInfo->FileNameLength >> 1; WCHAR z = CurInfo->FileName[NameLen]; CurInfo->FileName[NameLen] = 0; if (__wcswicmp(Mask, (PWCHAR)&CurInfo->FileName)) { if (DirEntry = FilesAlocateDirEntry(DirLenBytes + CurInfo->FileNameLength)) { RtlCopyMemory(&DirEntry->FileInfo, CurInfo, sizeof(FILE_DIRECTORY_INFORMATION)); RtlCopyMemory(&DirEntry->FileInfo.FileName, Directory, DirLenBytes); RtlCopyMemory(&DirEntry->FileInfo.FileName[DirLenBytes >> 1], &CurInfo->FileName, CurInfo->FileNameLength); InsertTailList(FileListHead, &DirEntry->Entry); Found += 1; } } // if (__wcswicmp(Mask, (PWCHAR)&CurInfo->FileName)) CurInfo->FileName[NameLen] = z; } // if (!(CurInfo->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) || (Flags & FILES_FIND_DIRECTORIES)) if ((CurInfo->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (Flags & FILES_SCAN_SUBDIRECTORIES)) { PWCHAR NewDir = MyAllocatePool(PagedPool, DirLenBytes + CurInfo->FileNameLength + 2*sizeof(WCHAR)); if (NewDir) { RtlCopyMemory(NewDir, Directory, DirLenBytes); RtlCopyMemory((PCHAR)NewDir + DirLenBytes, CurInfo->FileName, CurInfo->FileNameLength); NewDir[(DirLenBytes + CurInfo->FileNameLength) >> 1] = '\\'; NewDir[(DirLenBytes + CurInfo->FileNameLength + sizeof(WCHAR)) >> 1] = 0; Found += FilesFind(NewDir, Mask, Flags, FileListHead); MyFreePool(NewDir); } } // if ((CurInfo->FileAttributes & FILE_ATTRIBUTE_DIRECTORY) && (Flags & FILES_SCAN_SUBDIRECTORIES)) } // if (CurInfo->FileName[0] != '.') if (CurInfo->NextEntryOffset == 0) break; CurInfo = (PFILE_DIRECTORY_INFORMATION)((PCHAR)CurInfo + CurInfo->NextEntryOffset); } while(TRUE); } // if (NT_SUCCESS(ntStatus)) } while(NT_SUCCESS(ntStatus));
// // Releases and frees FILE_DIRECTORY_ENTRY structure VOID FilesFreeDirEntry(PFILE_DIRECTORY_ENTRY DirEntry) { ASSERT_FILE_DIRECTORY_ENTRY(DirEntry); MyFreePool(DirEntry); }