Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented SpoofOSXVersion option #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions rEFIt_UEFI/Platform/Platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,9 @@ typedef struct {
UINT8 pad7[2];
UINT8 CustomBoot;
EG_IMAGE *CustomLogo;

//SpoofOSXVersion
CHAR16 *SpoofOSXVersion;

UINT32 RefCLK;

Expand Down
7 changes: 7 additions & 0 deletions rEFIt_UEFI/Platform/Settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -2027,6 +2027,13 @@ GetEarlyUserSettings (
}

DBG ("Custom boot %s (0x%X)\n", CustomBootModeToStr (gSettings.CustomBoot), gSettings.CustomLogo);

// Spoof OSX Version
Prop = GetProperty (DictPointer, "SpoofOSXVersion");
if (Prop != NULL) {
gSettings.SpoofOSXVersion = AllocateZeroPool (AsciiStrSize (Prop->string) * sizeof(CHAR16));
AsciiStrToUnicodeStr (Prop->string, gSettings.SpoofOSXVersion);
}
}

//*** SYSTEM ***
Expand Down
83 changes: 83 additions & 0 deletions rEFIt_UEFI/Platform/apple.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* refind/apple.c
* Functions specific to Apple computers
*
* Copyright (c) 2015 Roderick W. Smith
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#include "entry_scan.h"
#include "lib.h"
#include "apple.h"

/*
* The below definitions and SetAppleOSInfo() function are based on a GRUB patch
* by Andreas Heider:
* https://lists.gnu.org/archive/html/grub-devel/2013-12/msg00442.html
*/

#define EFI_APPLE_SET_OS_PROTOCOL_GUID \
{ 0xc5c5da95, 0x7d5c, 0x45e6, \
{ 0xb2, 0xf1, 0x3f, 0xd5, 0x2b, 0xb1, 0x00, 0x77 } \
}

typedef struct EfiAppleSetOsInterface {
UINT64 Version;
EFI_STATUS EFIAPI (*SetOsVersion) (IN CHAR8 *Version);
EFI_STATUS EFIAPI (*SetOsVendor) (IN CHAR8 *Vendor);
} EfiAppleSetOsInterface;

// 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 = gBS->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) && gSettings.SpoofOSXVersion) {
AppleOSVersion = PoolPrint (L"Mac OS X %s", gSettings.SpoofOSXVersion);
if (AppleOSVersion) {
AppleOSVersion8 = AllocateZeroPool((StrLen(AppleOSVersion) + 1) * sizeof(CHAR8));
UnicodeStrToAsciiStr(AppleOSVersion, AppleOSVersion8);
if (AppleOSVersion8) {
Status = SetOs->SetOsVersion (AppleOSVersion8);
if (!EFI_ERROR(Status))
Status = EFI_SUCCESS;
FreePool(AppleOSVersion8);
} else {
Status = EFI_OUT_OF_RESOURCES;
Print(L"Out of resources in SetAppleOSInfo!\n");
}
if ((Status == EFI_SUCCESS) && (SetOs->Version >= 2))
Status = SetOs->SetOsVendor ((CHAR8 *) "Apple Inc.");
FreePool(AppleOSVersion);
} // if (AppleOSVersion)
} // if
if (Status != EFI_SUCCESS)
Print(L"Unable to set firmware boot type!\n");

return (Status);
} // EFI_STATUS SetAppleOSInfo()
26 changes: 26 additions & 0 deletions rEFIt_UEFI/Platform/apple.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* refind/apple.h
*
* Copyright (c) 2015 Roderick W. Smith
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

#ifndef __APPLE_H_
#define __APPLE_H_

EFI_STATUS SetAppleOSInfo();

#endif
1 change: 1 addition & 0 deletions rEFIt_UEFI/refit.inf
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
Platform/PlatformDriverOverride.c
Platform/Hibernate.c
Platform/Net.c
Platform/apple.c

[Packages]
Clover/CloverPkg.dec
Expand Down
7 changes: 6 additions & 1 deletion rEFIt_UEFI/refit/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
*/

#include "entry_scan.h"
#include "apple.h"
//#include "Platform.h"
//#include "../include/Handle.h"

#include "Version.h"

#ifndef DEBUG_ALL
Expand Down Expand Up @@ -1981,6 +1981,11 @@ RefitMain (IN EFI_HANDLE ImageHandle,
}
}

// spoof OSX version if needed
if (gSettings.SpoofOSXVersion && gSettings.SpoofOSXVersion[0] != L'\0') {
SetAppleOSInfo();
}

#ifdef ENABLE_SECURE_BOOT
// Install secure boot shim
if (EFI_ERROR(Status = InstallSecureBoot())) {
Expand Down