提交 590fd024 编写于 作者: V vit9696

Utilities: New LogoutHook & nvramdump by @roddy20

上级 b44c3448
......@@ -13,6 +13,7 @@ Utilities/EfiResTool/EfiResTool
Utilities/macserial/macserial
Utilities/icnspack/icnspack
Utilities/ocvalidate/ocvalidate
Utilities/LogoutHook/nvramdump
Utilities/RsaTool/RsaTool
Utilities/TestBmf/Bmf
Utilities/TestDiskImage/DiskImage
......
......@@ -14,6 +14,7 @@ OpenCore Changelog
- Fixed macserial issues when processing 2021 year serials
- Added advanced error checking in ocvalidate utility
- Added `SetupDelay` to configure audio setup delay
- Reworked LogoutHook.command to support older macOS
#### v0.6.4
- Added `BlacklistAppleUpdate` to fix macOS 11 broken update optout
......
......@@ -13,83 +13,31 @@ if [ "$1" = "install" ]; then
exit 0
fi
if [ ! -x /usr/bin/dirname ] || [ ! -x /usr/sbin/nvram ] || [ ! -x /usr/bin/grep ] || [ ! -x /bin/chmod ] || [ ! -x /usr/bin/sed ] || [ ! -x /usr/bin/base64 ] || [ ! -x /bin/rm ] || [ ! -x /bin/mkdir ] || [ ! -x /usr/bin/stat ] || [ ! -x /usr/libexec/PlistBuddy ] || [ ! -x /usr/sbin/ioreg ] || [ ! -x /usr/bin/xxd ] || [ ! -x /usr/sbin/diskutil ] || [ ! -x /bin/cp ] || [ ! -x /usr/bin/wc ] || [ ! -x /usr/bin/uuidgen ] || [ ! -x /usr/bin/hexdump ]; then
if [ ! -x /usr/bin/dirname ] || [ ! -x /usr/sbin/nvram ] || [ ! -x /bin/rm ] || [ ! -x /usr/sbin/diskutil ] || [ ! -x /bin/cp ] ; then
abort "Unix environment is broken!"
fi
thisDir="$(/usr/bin/dirname "${0}")"
uuidDump="${thisDir}/$(/usr/bin/uuidgen)"
if [ "${thisDir}/" = "${uuidDump}" ]; then
echo "uuidgen returns null!"
exit 1
fi
cd "${thisDir}" || abort "Failed to enter working directory!"
if [ ! -x ./nvramdump ]; then
abort "nvramdump is not found!"
fi
abort() {
echo "Fatal error: ${1}"
/bin/rm -rf "${uuidDump}"
exit 1
}
nvram=/usr/sbin/nvram
# FIXME: find an nvram key that is mandatory
if ! "${nvram}" -x '4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102:boot-path' | grep -q 'xml' ; then
nvram="$(pwd)/nvram.mojave"
if [ ! -f "${nvram}" ]; then
abort "${nvram} does NOT exist!"
elif [ ! -x "${nvram}" ]; then
abort "${nvram} is not executable!"
fi
fi
getKey() {
k="$1"
"${nvram}" -x "${k}" | grep -v '[<>]' | /usr/bin/base64 --decode
}
/bin/rm -rf "${uuidDump}"
/bin/mkdir "${uuidDump}" || abort "Failed to create dump directory!"
cd "${uuidDump}" || abort "Failed to enter dump directory!"
"${nvram}" -xp > ./nvram1.plist || abort "Failed to dump nvram!"
for key in BootOrder BootNext Boot0080 Boot0081 Boot0082 Boot0083; do
getKey "8BE4DF61-93CA-11D2-AA0D-00E098032B8C:${key}" > "${key}"
if [ -n "$(/usr/bin/hexdump "${key}" )" ]; then
/usr/libexec/PlistBuddy -c "Import Add:8BE4DF61-93CA-11D2-AA0D-00E098032B8C:${key} ${key}" ./nvram.plist || abort "Failed to import ${key} from 8BE4DF61-93CA-11D2-AA0D-00E098032B8C!"
fi
done
# not an error
# shellcheck disable=SC2043
for key in DefaultBackgroundColor; do
getKey "4D1EDE05-38C7-4A6A-9CC6-4BCCA8B38C14:${key}" > "${key}"
if [ -n "$(/usr/bin/hexdump "${key}" )" ]; then
/usr/libexec/PlistBuddy -c "Import Add:4D1EDE05-38C7-4A6A-9CC6-4BCCA8B38C14:${key} ${key}" ./nvram.plist || abort "Failed to import ${key} from 4D1EDE05-38C7-4A6A-9CC6-4BCCA8B38C14!"
fi
done
rm -f /tmp/nvram.plist
./nvramdump || abort "failed to save nvram.plist!"
# Optional for security reasons: Wi-Fi settings for Install OS X and Recovery
# for key in current-network preferred-count; do
# getKey "36C28AB5-6566-4C50-9EBD-CBB920F83843:${key}" > "${key}"
# if [ -n "$(/usr/bin/hexdump "${key}" )" ]; then
# /usr/libexec/PlistBuddy -c "Import Add:36C28AB5-6566-4C50-9EBD-CBB920F83843:${key} ${key}" ./nvram.plist || abort "Failed to import ${key} from 36C28AB5-6566-4C50-9EBD-CBB920F83843!"
# fi
# done
/usr/libexec/PlistBuddy -c "Add Version integer 1" ./nvram.plist || abort "Failed to add Version!"
/usr/libexec/PlistBuddy -c "Add Add:7C436110-AB2A-4BBB-A880-FE41995C9F82 dict" ./nvram.plist || abort "Failed to add dict 7C436110-AB2A-4BBB-A880-FE41995C9F82"
/usr/libexec/PlistBuddy -c "Merge nvram1.plist Add:7C436110-AB2A-4BBB-A880-FE41995C9F82" ./nvram.plist || abort "Failed to merge with nvram1.plist!"
UUID="$("${nvram}" 4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102:boot-path | /usr/bin/sed 's/.*GPT,\([^,]*\),.*/\1/')"
UUID="$(nvram 4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102:boot-path | /usr/bin/sed 's/.*GPT,\([^,]*\),.*/\1/')"
if [ "$(printf '%s' "${UUID}" | /usr/bin/wc -c)" -eq 36 ] && [ -z "$(echo "${UUID}" | /usr/bin/sed 's/[-0-9A-F]//g')" ]; then
/usr/sbin/diskutil mount "${UUID}" || abort "Failed to mount ${UUID}!"
/bin/cp ./nvram.plist "$(/usr/sbin/diskutil info "${UUID}" | /usr/bin/sed -n 's/.*Mount Point: *//p')" || abort "Failed to copy nvram.plist!"
/bin/cp /tmp/nvram.plist "$(/usr/sbin/diskutil info "${UUID}" | /usr/bin/sed -n 's/.*Mount Point: *//p')" || abort "Failed to copy nvram.plist!"
/usr/sbin/diskutil unmount "${UUID}" || abort "Failed to unmount ${UUID}!"
/bin/rm -rf "${uuidDump}"
exit 0
else
abort "Illegal UUID or unknown loader!"
fi
/bin/rm -rf "${uuidDump}"
## @file
# Created by Rodion Shynharov on 27.12.20.
# Copyright © 2020 Rodion Shingarev. All rights reserved.
# based on the original Apple NVRAM utility
# Copyright (c) 2000-2016 Apple Inc. All rights reserved.
# https://opensource.apple.com/source/system_cmds/system_cmds-854.40.2/nvram.tproj/nvram.c
##
STANDALONE = 1
PROJECT = nvramdump
PRODUCT = $(PROJECT)$(SUFFIX)
OBJS = $(PROJECT).o
include ../../User/Makefile
ifeq ($(DIST),Darwin)
LDFLAGS += -Wl,-framework,IOKit -Wl,-framework,CoreFoundation
endif
LogoutHook
===========
==========
## Installation
```sudo defaults write com.apple.loginwindow LogoutHook /path/to/LogoutHook.command```
......@@ -7,6 +7,3 @@ LogoutHook
or
```/path/to/LogoutHook.command install```
## Notes
`LogoutHook.command` highly depends on macOS `nvram` utility supporting `-x` option, which is unavailable on 10.12 and below. (Our `nvram.mojave` somehow fixes that issue by invoking it instead of system one)
\ No newline at end of file
//
// main.c
// NVRAMdump
//
// Created by Rodion Shingarev on 27.12.20.
// Copyright © 2020 Rodion Shingarev. All rights reserved.
// based on the original NVRAM utility
// Copyright (c) 2000-2016 Apple Inc. All rights reserved.
// https://opensource.apple.com/source/system_cmds/system_cmds-854.40.2/nvram.tproj/nvram.c
//
#include <stdio.h>
#ifdef __APPLE__
#include <stdlib.h>
#include <IOKit/IOKitLib.h>
#include <IOKit/IOKitKeys.h>
#include <CoreFoundation/CoreFoundation.h>
#include <err.h>
#include <mach/mach_error.h>
#include <string.h>
static io_registry_entry_t gOptionsRef;
// GetOFVariable(name, nameRef, valueRef)
//
// Get the named firmware variable.
// Return it and it's symbol in valueRef and nameRef.
//
static kern_return_t GetOFVariable(char *name, CFStringRef *nameRef,
CFTypeRef *valueRef)
{
*nameRef = CFStringCreateWithCString(kCFAllocatorDefault, name,
kCFStringEncodingUTF8);
if (*nameRef == 0) {
errx(1, "Error creating CFString for key %s", name);
}
*valueRef = IORegistryEntryCreateCFProperty(gOptionsRef, *nameRef, 0, 0);
if (*valueRef == 0) return kIOReturnNotFound;
return KERN_SUCCESS;
}
CFDictionaryRef CreateMyDictionary(void) {
char *guid;
// root
CFMutableDictionaryRef dict = CFDictionaryCreateMutable(kCFAllocatorDefault, 0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
//version
int version = 1;
CFNumberRef num = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &version);
CFDictionarySetValue(dict, CFSTR("Version"), num);
CFRelease(num);
//Add
CFMutableDictionaryRef dict0 = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(dict, CFSTR("Add"), dict0);
CFRelease(dict0);
// APPLE_BOOT_VARIABLE_GUID
// Print all of the firmware variables.
CFMutableDictionaryRef dict1;
kern_return_t result;
result = IORegistryEntryCreateCFProperties(gOptionsRef, &dict1, 0, 0);
if (result != KERN_SUCCESS) {
errx(1, "Error getting the firmware variables: %s", mach_error_string(result));
}
CFDictionarySetValue(dict0, CFSTR("7C436110-AB2A-4BBB-A880-FE41995C9F82"), dict1);
CFRelease(dict1);
CFMutableDictionaryRef dict2 = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(dict0, CFSTR("8BE4DF61-93CA-11D2-AA0D-00E098032B8C"), dict2);
// EFI_GLOBAL_VARIABLE_GUID
// Print the given firmware variable.
CFStringRef nameRef;
CFTypeRef valueRef;
const char *key[32];
char name[64];
char v[32];
CFStringRef var;
int i = 0;
int n = 7; // num of keys in this GUID
key[0] = "Boot0080";
key[1] = "BootOrder";
key[2] = "BootNext";
key[3] = "Boot0081";
key[4] = "Boot0082";
key[5] = "Boot0083";
key[6] = "BootCurrent";
guid = "8BE4DF61-93CA-11D2-AA0D-00E098032B8C";
for ( i = 0; i < n; i++ ) {
strcpy(v, key[i]);
strcpy(name, guid);
strcat(name, ":");
strcat(name, v);
var = CFStringCreateWithCString(NULL, v, kCFStringEncodingUTF8);
result = GetOFVariable(name, &nameRef, &valueRef);
if (result == KERN_SUCCESS) {
CFDictionaryAddValue (dict2, var, valueRef);
CFRelease(valueRef);
}
CFRelease(nameRef);
}
CFRelease(dict2);
// APPLE_WIRELESS_NETWORK_VARIABLE_GUID
CFMutableDictionaryRef dict3 = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFDictionarySetValue(dict0, CFSTR("36C28AB5-6566-4C50-9EBD-CBB920F83843"), dict3);
n = 3; // num of keys in this GUID
key[0] = "current-network";
key[1] = "preferred-count";
key[2] = "preferred-networks";
guid = "36C28AB5-6566-4C50-9EBD-CBB920F83843";
for ( i = 0; i < n; i++ ) {
strcpy(v, key[i]);
strcpy(name, guid);
strcat(name, ":");
strcat(name, v);
var = CFStringCreateWithCString(NULL, v, kCFStringEncodingUTF8);
result = GetOFVariable(name, &nameRef, &valueRef);
if (result == KERN_SUCCESS) {
CFDictionaryAddValue (dict3, var, valueRef);
CFRelease(valueRef);
}
CFRelease(nameRef);
}
CFRelease(dict3);
return dict;
}
int main(int argc, const char * argv[]) {
CFDataRef data;
FILE *fp;
kern_return_t result;
mach_port_t masterPort;
result = IOMasterPort(bootstrap_port, &masterPort);
if (result != KERN_SUCCESS) {
errx(1, "Error getting the IOMaster port: %s",
mach_error_string(result));
}
gOptionsRef = IORegistryEntryFromPath(masterPort, "IODeviceTree:/options");
if (gOptionsRef == 0) {
errx(1, "nvram is not supported on this system");
}
CFPropertyListRef propertyList = CreateMyDictionary();
data = CFPropertyListCreateData( kCFAllocatorDefault, propertyList, kCFPropertyListXMLFormat_v1_0, 0, NULL );
if (data == NULL) {
errx(1, "Error converting variables to xml");
}
fp = fopen ("/tmp/nvram.plist", "w");
if (fp == NULL) {
errx(1, "Error opening /tmp/nvram.plist");
}
fwrite(CFDataGetBytePtr(data), sizeof(UInt8), CFDataGetLength(data), fp);
fclose (fp);
CFRelease(data);
IOObjectRelease(gOptionsRef);
return 0;
}
#else
int main() {
fprintf(stderr, "This utility is only supported on macOS\n");
return 1;
}
#endif
......@@ -4,6 +4,7 @@ buildutil() {
UTILS=(
"AppleEfiSignTool"
"EfiResTool"
"LogoutHook"
"disklabel"
"icnspack"
"macserial"
......@@ -178,7 +179,6 @@ package() {
utilScpts=(
"LegacyBoot"
"CreateVault"
"LogoutHook"
"macrecovery"
"kpdescribe"
)
......@@ -186,6 +186,19 @@ package() {
cp -r "${selfdir}/Utilities/${utilScpt}" "${dstdir}/Utilities"/ || exit 1
done
buildutil || exit 1
# Copy LogoutHook.
mkdir -p "${dstdir}/Utilities/LogoutHook" || exit 1
logoutFiles=(
"LogoutHook.command"
"README.md"
"nvramdump"
)
for file in "${logoutFiles[@]}"; do
cp "${selfdir}/Utilities/LogoutHook/${file}" "${dstdir}/Utilities/LogoutHook"/ || exit 1
done
# Copy OpenDuetPkg booter.
for arch in "${ARCHS[@]}"; do
local tgt
......@@ -201,7 +214,6 @@ package() {
fi
done
buildutil || exit 1
utils=(
"macserial"
"ocvalidate"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册