OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
nvram.c
Go to the documentation of this file.
1
19#include <windows.h>
20
21#include <stdio.h>
22#include <stdint.h>
23#include <string.h>
24#include <stdbool.h>
25#include <stdlib.h>
26
27/* Boilerplate asking privileges to write to the nvram's efi store. */
29 HANDLE hToken;
30 TOKEN_PRIVILEGES tkp;
31
32 OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &hToken);
33 LookupPrivilegeValue(NULL, SE_SYSTEM_ENVIRONMENT_NAME, &tkp.Privileges[0].Luid);
34 tkp.PrivilegeCount = 1;
35 tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
36 AdjustTokenPrivileges(hToken, FALSE, &tkp, 0, (PTOKEN_PRIVILEGES)NULL, 0);
37}
38
39int main(int argc, char *argv[]) {
40 if (argc < 2) {
41 printf("Usage:\n nvram var\n nvram var value\n");
42 return -1;
43 }
44
45 const char *variable = argv[1];
46 const char *guid = "{7C436110-AB2A-4BBB-A880-FE41995C9F82}";
47 int code = EXIT_SUCCESS;
48
50
51 if (argc == 2) {
52 char readValue[256] = {0};
53 uint32_t readValueSize = GetFirmwareEnvironmentVariableA(
54 variable, guid, readValue, sizeof(readValue)-1);
55 if (readValueSize > 0) {
56 printf("%s = %s\n", variable, readValue);
57 } else {
58 printf("Failed to read %s, code %u\n",
59 variable, (unsigned)GetLastError());
60 code = EXIT_FAILURE;
61 }
62 } else {
63 bool ok = SetFirmwareEnvironmentVariableA(
64 variable, guid, argv[2], strlen(argv[2]));
65 if (ok) {
66 printf("%s was set to %s\n", variable, argv[2]);
67 } else {
68 printf("Failed to set %s to %s, code %u\n",
69 variable, argv[2], (unsigned)GetLastError());
70 code = EXIT_FAILURE;
71 }
72 }
73
74 return code;
75}
int main()
Definition acdtinfo.c:181
UINT32 uint32_t
void obtain_privilege()
Definition nvram.c:28