提交 77c6c9d4 编写于 作者: M MikeBeaton

ToggleSipEntry: Add --show-csr option

上级 99db622f
...@@ -12,6 +12,7 @@ OpenCore Changelog ...@@ -12,6 +12,7 @@ OpenCore Changelog
- Added optional `--codec-setup-delay` argument to AudioDxe - Added optional `--codec-setup-delay` argument to AudioDxe
- Changed units of `Audio` -> `SetupDelay` from microseconds to milliseconds (divide previous value by 1000 if using this setting) - Changed units of `Audio` -> `SetupDelay` from microseconds to milliseconds (divide previous value by 1000 if using this setting)
- Fixed incorrect FAT binary slice being selected under macOS 10.4.11 when performing a cacheless boot - Fixed incorrect FAT binary slice being selected under macOS 10.4.11 when performing a cacheless boot
- Added `--show-csr` option for `Toggle SIP` boot menu entry
#### v0.8.2 #### v0.8.2
- Fixed `AppleCpuPmCfgLock` on macOS 13 - Fixed `AppleCpuPmCfgLock` on macOS 13
......
6168af65a2d3ac59112368336a774bb1 600765052cee1987c810b06636eb2bf6
...@@ -6882,9 +6882,24 @@ SIP will be fully configured, so setting the variable using this boot option ...@@ -6882,9 +6882,24 @@ SIP will be fully configured, so setting the variable using this boot option
\texttt{csrutil} command in macOS Recovery. \texttt{csrutil} command in macOS Recovery.
\texttt{csr-active-config} will be toggled between \texttt{0} for enabled, and a user-specified or \texttt{csr-active-config} will be toggled between \texttt{0} for enabled, and a user-specified or
default value for disabled. The default value is \texttt{0x27F} (see below). default value for disabled.
Any other required value can be specified as a single number in the \texttt{Arguments} for this driver.
This can be specified as hexadecimal, beginning with \texttt{0x}, or as decimal. Options for the driver should be specified as plain text values separated by whitespace in the
\texttt{Arguments} section of \texttt{Driver} entry. Available options are:
\begin{itemize}
\tightlist
\item \texttt{-{}-show-csr} - Boolean flag, enabled if present. \medskip
If enabled, show the current hexadecimal value of \texttt{csr-active-config} in the boot entry name.
This option will not work in OpenCanopy when used in combination with \texttt{OC\_ATTR\_USE\_GENERIC\_LABEL\_IMAGE}
in \texttt{PickerAttributes}. \medskip
\item Numerical value - Default value \texttt{0x27F}. \medskip
Specify the \texttt{csr-active-config} value to use to disabled SIP. This can be specified as
hexadecimal, beginning with \texttt{0x}, or as decimal. For more info see Note 2 below. \medskip
\end{itemize}
\emph{Note 1}: It is recommended not to run macOS with \emph{Note 1}: It is recommended not to run macOS with
SIP disabled. Use of this boot option may make it easier to quickly disable SIP SIP disabled. Use of this boot option may make it easier to quickly disable SIP
......
\documentclass[]{article} \documentclass[]{article}
%DIF LATEXDIFF DIFFERENCE FILE %DIF LATEXDIFF DIFFERENCE FILE
%DIF DEL PreviousConfiguration.tex Thu Jul 7 13:40:40 2022 %DIF DEL PreviousConfiguration.tex Thu Jul 7 13:40:40 2022
%DIF ADD ../Configuration.tex Wed Jul 20 19:52:29 2022 %DIF ADD ../Configuration.tex Sun Jul 24 14:16:13 2022
\usepackage{lmodern} \usepackage{lmodern}
\usepackage{amssymb,amsmath} \usepackage{amssymb,amsmath}
...@@ -6957,9 +6957,29 @@ SIP will be fully configured, so setting the variable using this boot option ...@@ -6957,9 +6957,29 @@ SIP will be fully configured, so setting the variable using this boot option
\texttt{csrutil} command in macOS Recovery. \texttt{csrutil} command in macOS Recovery.
\texttt{csr-active-config} will be toggled between \texttt{0} for enabled, and a user-specified or \texttt{csr-active-config} will be toggled between \texttt{0} for enabled, and a user-specified or
default value for disabled. The default value is \texttt{0x27F} (see below). default value for disabled.
Any other required value can be specified as a single number in the \texttt{Arguments} for this driver. \DIFdelbegin \DIFdel{The default value is }\texttt{\DIFdel{0x27F}} %DIFAUXCMD
This can be specified as hexadecimal, beginning with \texttt{0x}, or as decimal. \DIFdel{(see below).
Any other required value can }\DIFdelend \DIFaddbegin
\DIFadd{Options for the driver should }\DIFaddend be specified as \DIFdelbegin \DIFdel{a single number }\DIFdelend \DIFaddbegin \DIFadd{plain text values separated by whitespace }\DIFaddend in the
\texttt{Arguments} \DIFdelbegin \DIFdel{for this driver. This }\DIFdelend \DIFaddbegin \DIFadd{section of }\texttt{\DIFadd{Driver}} \DIFadd{entry. Available options are:
}
\begin{itemize}
\tightlist
\item \texttt{\DIFadd{-}{}\DIFadd{-show-csr}} \DIFadd{- Boolean flag, enabled if present. }\medskip
\DIFadd{If enabled, show the current hexadecimal value of }\texttt{\DIFadd{csr-active-config}} \DIFadd{in the boot entry name.
This option will not work in OpenCanopy when used in combination with }\texttt{\DIFadd{OC\_ATTR\_USE\_GENERIC\_LABEL\_IMAGE}}
\DIFadd{in }\texttt{\DIFadd{PickerAttributes}}\DIFadd{. }\medskip
\item \DIFadd{Numerical value - Default value }\texttt{\DIFadd{0x27F}}\DIFadd{. }\medskip
\DIFadd{Specify the }\texttt{\DIFadd{csr-active-config}} \DIFadd{value to use to disabled SIP. This }\DIFaddend can be specified as
hexadecimal, beginning with \texttt{0x}, or as decimal. \DIFaddbegin \DIFadd{For more info see Note 2 below. }\medskip
\end{itemize}
\DIFaddend
\emph{Note 1}: It is recommended not to run macOS with \emph{Note 1}: It is recommended not to run macOS with
SIP disabled. Use of this boot option may make it easier to quickly disable SIP SIP disabled. Use of this boot option may make it easier to quickly disable SIP
......
...@@ -1891,7 +1891,9 @@ OcImageLoaderLoad ( ...@@ -1891,7 +1891,9 @@ OcImageLoaderLoad (
); );
/** /**
Parse loaded image protocol load options. Parse loaded image protocol load options, resultant options are in the
same format as is returned by OcParsedVars and may be examined using the
same utility methods.
Assumes CHAR_NULL terminated Unicode string of space separated options, Assumes CHAR_NULL terminated Unicode string of space separated options,
each of form {name} or {name}={value}. Double quotes can be used round {value} to each of form {name} or {name}={value}. Double quotes can be used round {value} to
...@@ -1949,6 +1951,20 @@ OcParseVars ( ...@@ -1949,6 +1951,20 @@ OcParseVars (
IN CONST OC_STRING_FORMAT StringFormat IN CONST OC_STRING_FORMAT StringFormat
); );
/**
Return parsed variable at given index.
@param[in] ParsedVars Parsed variables.
@param[in] Index Index of option to return.
@retval Parsed option.
**/
OC_PARSED_VAR *
OcParsedVarsItemAt (
IN CONST OC_FLEX_ARRAY *ParsedVars,
IN CONST UINTN Index
);
/** /**
Get string value of parsed var or load option. Get string value of parsed var or load option.
Returned value is in same format as raw options. Returned value is in same format as raw options.
......
...@@ -625,6 +625,18 @@ OcParseVars ( ...@@ -625,6 +625,18 @@ OcParseVars (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
OC_PARSED_VAR *
OcParsedVarsItemAt (
IN CONST OC_FLEX_ARRAY *ParsedVars,
IN CONST UINTN Index
)
{
OC_PARSED_VAR *Option;
Option = OcFlexArrayItemAt (ParsedVars, Index);
return Option;
}
BOOLEAN BOOLEAN
OcParsedVarsGetStr ( OcParsedVarsGetStr (
IN CONST OC_FLEX_ARRAY *ParsedVars, IN CONST OC_FLEX_ARRAY *ParsedVars,
......
...@@ -10,17 +10,23 @@ ...@@ -10,17 +10,23 @@
#include <Uefi.h> #include <Uefi.h>
#include <Library/BaseLib.h> #include <Library/BaseLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h> #include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h> #include <Library/UefiRuntimeServicesTableLib.h>
#include <Protocol/OcBootEntry.h> #include <Protocol/OcBootEntry.h>
#define OC_MENU_SIP_IS_DISABLED "Toggle SIP (Disabled)" #define OC_MENU_TOGGLE_SIP "Toggle SIP (%a)"
#define OC_MENU_SIP_IS_ENABLED "Toggle SIP (Enabled)" #define OC_MENU_TOGGLE_SIP_SHOW_CSR "Toggle SIP (0x%X:%a)"
#define OC_MENU_TOGGLE_SIP_MAX_SIZE (\
sizeof(OC_MENU_TOGGLE_SIP_SHOW_CSR) \
+ sizeof(UINT32) * 2 * sizeof (CHAR8) - L_STR_LEN("%X") \
+ L_STR_LEN("Disabled") - L_STR_LEN("%a"))
STATIC UINT32 mCsrUserConfig; STATIC UINT32 mCsrUserConfig;
STATIC UINT32 mCsrNextConfig; STATIC UINT32 mCsrNextConfig;
STATIC UINT32 mAttributes; STATIC UINT32 mAttributes;
STATIC BOOLEAN mShowCsr;
STATIC STATIC
EFI_STATUS EFI_STATUS
...@@ -87,6 +93,7 @@ ToggleSipGetBootEntries ( ...@@ -87,6 +93,7 @@ ToggleSipGetBootEntries (
EFI_STATUS Status; EFI_STATUS Status;
UINT32 CsrActiveConfig; UINT32 CsrActiveConfig;
BOOLEAN IsEnabled; BOOLEAN IsEnabled;
CHAR8 *Name;
// //
// Custom entries only. // Custom entries only.
...@@ -125,13 +132,40 @@ ToggleSipGetBootEntries ( ...@@ -125,13 +132,40 @@ ToggleSipGetBootEntries (
return Status; return Status;
} }
Name = AllocatePool (OC_MENU_TOGGLE_SIP_MAX_SIZE);
if (Name == NULL) {
return EFI_OUT_OF_RESOURCES;
}
if (mShowCsr) {
Status = OcAsciiSafeSPrint (
Name,
OC_MENU_TOGGLE_SIP_MAX_SIZE,
OC_MENU_TOGGLE_SIP_SHOW_CSR,
CsrActiveConfig,
IsEnabled ? "Enabled" : "Disabled"
);
} else {
Status = OcAsciiSafeSPrint (
Name,
OC_MENU_TOGGLE_SIP_MAX_SIZE,
OC_MENU_TOGGLE_SIP,
IsEnabled ? "Enabled" : "Disabled"
);
}
if (EFI_ERROR (Status)) {
ASSERT (FALSE);
FreePool (Name);
return EFI_ABORTED;
}
mToggleSipBootEntries[0].Name = Name;
if (IsEnabled) { if (IsEnabled) {
mToggleSipBootEntries[0].Name = OC_MENU_SIP_IS_ENABLED;
mToggleSipBootEntries[0].Flavour = OC_FLAVOUR_TOGGLE_SIP_ENABLED; mToggleSipBootEntries[0].Flavour = OC_FLAVOUR_TOGGLE_SIP_ENABLED;
mToggleSipBootEntries[0].AudioBasePath = OC_VOICE_OVER_AUDIO_FILE_SIP_IS_ENABLED; mToggleSipBootEntries[0].AudioBasePath = OC_VOICE_OVER_AUDIO_FILE_SIP_IS_ENABLED;
mCsrNextConfig = mCsrUserConfig; mCsrNextConfig = mCsrUserConfig;
} else { } else {
mToggleSipBootEntries[0].Name = OC_MENU_SIP_IS_DISABLED;
mToggleSipBootEntries[0].Flavour = OC_FLAVOUR_TOGGLE_SIP_DISABLED; mToggleSipBootEntries[0].Flavour = OC_FLAVOUR_TOGGLE_SIP_DISABLED;
mToggleSipBootEntries[0].AudioBasePath = OC_VOICE_OVER_AUDIO_FILE_SIP_IS_DISABLED; mToggleSipBootEntries[0].AudioBasePath = OC_VOICE_OVER_AUDIO_FILE_SIP_IS_DISABLED;
mCsrNextConfig = 0; mCsrNextConfig = 0;
...@@ -152,12 +186,36 @@ ToggleSipGetBootEntries ( ...@@ -152,12 +186,36 @@ ToggleSipGetBootEntries (
return EFI_SUCCESS; return EFI_SUCCESS;
} }
STATIC
VOID
EFIAPI
ToggleSipFreeBootEntries (
IN OC_PICKER_ENTRY **Entries,
IN UINTN NumEntries
)
{
UINTN Index;
if (NumEntries == 0) {
return;
}
ASSERT (NumEntries == 1);
ASSERT (Entries != NULL);
for (Index = 0; Index < NumEntries; Index++) {
if (Entries[Index]->Name != NULL) {
FreePool ((VOID *)Entries[Index]->Name); ///< Discard const
}
}
}
STATIC STATIC
OC_BOOT_ENTRY_PROTOCOL OC_BOOT_ENTRY_PROTOCOL
mToggleSipBootEntryProtocol = { mToggleSipBootEntryProtocol = {
OC_BOOT_ENTRY_PROTOCOL_REVISION, OC_BOOT_ENTRY_PROTOCOL_REVISION,
ToggleSipGetBootEntries, ToggleSipGetBootEntries,
NULL ToggleSipFreeBootEntries
}; };
EFI_STATUS EFI_STATUS
...@@ -169,7 +227,11 @@ UefiMain ( ...@@ -169,7 +227,11 @@ UefiMain (
{ {
EFI_STATUS Status; EFI_STATUS Status;
EFI_LOADED_IMAGE_PROTOCOL *LoadedImage; EFI_LOADED_IMAGE_PROTOCOL *LoadedImage;
OC_FLEX_ARRAY *ParsedLoadOptions;
CHAR16 *Option;
UINTN Index;
UINTN Data; UINTN Data;
BOOLEAN HasUserCsr;
Status = gBS->HandleProtocol ( Status = gBS->HandleProtocol (
ImageHandle, ImageHandle,
...@@ -180,21 +242,41 @@ UefiMain ( ...@@ -180,21 +242,41 @@ UefiMain (
return Status; return Status;
} }
Status = EFI_NOT_FOUND; Status = OcParseLoadOptions (LoadedImage, &ParsedLoadOptions);
HasUserCsr = FALSE;
if (!EFI_ERROR (Status)) {
for (Index = 0; Index < ParsedLoadOptions->Count; Index++) {
Option = OcParsedVarsItemAt (ParsedLoadOptions, Index)->Unicode.Name;
if (Option[0] != L'-') {
if (OcUnicodeStartsWith (Option, L"0x", TRUE)) {
Status = StrHexToUintnS (Option, NULL, &Data);
} else {
Status = StrDecimalToUintnS (Option, NULL, &Data);
}
if (OcHasLoadOptions (LoadedImage->LoadOptionsSize, LoadedImage->LoadOptions)) { if (EFI_ERROR (Status)) {
if (OcUnicodeStartsWith (LoadedImage->LoadOptions, L"0x", TRUE)) { DEBUG ((DEBUG_WARN, "BEP: ToggleSip cannot parse %s - %r\n", Option, Status));
Status = StrHexToUintnS (LoadedImage->LoadOptions, NULL, &Data); HasUserCsr = FALSE;
} else { } else {
Status = StrDecimalToUintnS (LoadedImage->LoadOptions, NULL, &Data); HasUserCsr = TRUE;
}
}
} }
if (EFI_ERROR (Status)) { mShowCsr = OcHasParsedVar (ParsedLoadOptions, L"--show-csr", OcStringFormatUnicode);
DEBUG ((DEBUG_WARN, "BEP: ToggleSip cannot parse %s - %r\n", LoadedImage->LoadOptions, Status));
OcFlexArrayFree (&ParsedLoadOptions);
} else {
ASSERT (ParsedLoadOptions == NULL);
if (Status != EFI_NOT_FOUND) {
return Status;
} }
mShowCsr = FALSE;
} }
if (!EFI_ERROR (Status)) { if (HasUserCsr) {
mCsrUserConfig = (UINT32)Data; mCsrUserConfig = (UINT32)Data;
if (OcIsSipEnabled (EFI_SUCCESS, mCsrUserConfig)) { if (OcIsSipEnabled (EFI_SUCCESS, mCsrUserConfig)) {
DEBUG ((DEBUG_WARN, "BEP: Specified value 0x%X will not disable SIP!\n", mCsrUserConfig)); DEBUG ((DEBUG_WARN, "BEP: Specified value 0x%X will not disable SIP!\n", mCsrUserConfig));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册