├── IA32
└── ReadSMC.efi
├── ReadSMC
├── AppleSMC.h
├── ReadSMC.c
└── ReadSMC.inf
├── X64
└── ReadSMC.efi
└── readme.md
/IA32/ReadSMC.efi:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andyvand/ReadSMC/329b3011d44354974cc2e39bf12d5991420585f3/IA32/ReadSMC.efi
--------------------------------------------------------------------------------
/ReadSMC/AppleSMC.h:
--------------------------------------------------------------------------------
1 | //********************************************************************
2 | // created: 29:9:2012 13:49
3 | // filename: AppleSMC.h
4 | // author: tiamo
5 | // purpose: apple smc
6 | //********************************************************************
7 |
8 | #ifndef _APPLE_SMC_H_
9 | #define _APPLE_SMC_H_
10 |
11 | #define APPLE_SMC_PROTOCOL_GUID \
12 | { 0x17407e5a, 0xaf6c, 0x4ee8, {0x98, 0xa8, 0x00, 0x21, 0x04, 0x53, 0xcd, 0xd9} }
13 |
14 | typedef EFI_STATUS (EFIAPI* APPLE_SMC_READ_DATA)(IN VOID *This, IN UINT32 DataId, IN UINT32 DataLength, OUT VOID* DataBuffer);
15 |
16 | typedef struct _APPLE_SMC_PROTOCOL
17 | {
18 | UINT64 Signature;
19 | APPLE_SMC_READ_DATA ReadData;
20 | } APPLE_SMC_PROTOCOL;
21 |
22 | extern EFI_GUID gAppleSMCProtocolGuid;
23 |
24 | #endif
25 |
--------------------------------------------------------------------------------
/ReadSMC/ReadSMC.c:
--------------------------------------------------------------------------------
1 | /** @file
2 | This is a test application that demonstrates how to use the C-style entry point
3 | for a shell application.
4 |
5 | Copyright (c) 2009 - 2011, Intel Corporation. All rights reserved.
6 | This program and the accompanying materials
7 | are licensed and made available under the terms and conditions of the BSD License
8 | which accompanies this distribution. The full text of the license may be found at
9 | http://opensource.org/licenses/bsd-license.php
10 |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13 |
14 | **/
15 |
16 | #include
17 | #include
18 | #include
19 | #include
20 | #include
21 | #include
22 | #include
23 | #include "AppleSMC.h"
24 |
25 | #define READ_BUFFER(B, L, I, V, T) do{if((I) >= (L)) return EFI_BAD_BUFFER_SIZE; (V) = (T)((B)[(I)]); (I) += 1;}while(0)
26 | #define WRITE_BUFFER(B, L, I, V, T) do{if((I) >= (L) - 1) return EFI_BUFFER_TOO_SMALL; (B)[(I)] = (T)(V); (I) += 1;}while(0)
27 |
28 | //
29 | // unicode to utf8
30 | //
31 | EFI_STATUS UnicodeToUtf8(CHAR16 CONST* unicodeBuffer, UINTN unicodeCharCount, UINT8* utf8Buffer, UINTN utf8BufferLength)
32 | {
33 | UINT32 j = 0;
34 | utf8Buffer[utf8BufferLength - 1] = 0;
35 | UINT32 i = 0;
36 |
37 | for(i = 0; i < unicodeCharCount; i ++)
38 | {
39 | CHAR16 unicodeChar = unicodeBuffer[i];
40 | if(unicodeChar < 0x0080)
41 | {
42 | WRITE_BUFFER(utf8Buffer, utf8BufferLength, j, unicodeChar, UINT8);
43 | }
44 | else if(unicodeChar < 0x0800)
45 | {
46 | WRITE_BUFFER(utf8Buffer, utf8BufferLength, j, ((unicodeChar >> 6) & 0x0f) | 0xc0, UINT8);
47 | WRITE_BUFFER(utf8Buffer, utf8BufferLength, j, ((unicodeChar >> 0) & 0x3f) | 0x80, UINT8);
48 | }
49 | else
50 | {
51 | WRITE_BUFFER(utf8Buffer, utf8BufferLength, j, ((unicodeChar >> 12) & 0x0f) | 0xe0, UINT8);
52 | WRITE_BUFFER(utf8Buffer, utf8BufferLength, j, ((unicodeChar >> 6) & 0x3f) | 0x80, UINT8);
53 | WRITE_BUFFER(utf8Buffer, utf8BufferLength, j, ((unicodeChar >> 0) & 0x3f) | 0x80, UINT8);
54 | }
55 | }
56 |
57 | if(j < utf8BufferLength - 1)
58 | WRITE_BUFFER(utf8Buffer, utf8BufferLength, j, 0, UINT8);
59 |
60 | return EFI_SUCCESS;
61 | }
62 |
63 | CHAR8 *Utf8FromUnicode(CHAR16 CONST* unicodeString, UINTN unicodeCharCount)
64 | {
65 | UINTN length = unicodeCharCount == -1 ? StrLen(unicodeString) : unicodeCharCount;
66 | UINTN utf8BufferLength = (length * 3 + 1) * sizeof(CHAR8);
67 | UINT8 *utf8NameBuffer = (UINT8 *)(AllocateZeroPool(utf8BufferLength));
68 | if(!utf8NameBuffer)
69 | return NULL;
70 |
71 | if(!EFI_ERROR(UnicodeToUtf8(unicodeString, length, utf8NameBuffer, utf8BufferLength / sizeof(CHAR8))))
72 | return (CHAR8 *)utf8NameBuffer;
73 |
74 | FreePool(utf8NameBuffer);
75 | return NULL;
76 | }
77 |
78 | VOID Usage(IN CHAR16 *Name)
79 | {
80 | Print(L"AppleSMC Key Reader\n");
81 | Print(L"Usage: %s \n", Name);
82 | Print(L"Copyright (C) 2014 AnV Software\n");
83 | }
84 |
85 | /**
86 | UEFI application entry point which has an interface similar to a
87 | standard C main function.
88 |
89 | The ShellCEntryLib library instance wrappers the actual UEFI application
90 | entry point and calls this ShellAppMain function.
91 |
92 | @param[in] Argc The number of items in Argv.
93 | @param[in] Argv Array of pointers to strings.
94 |
95 | @retval 0 The application exited normally.
96 | @retval Other An error occurred.
97 |
98 | **/
99 | INTN
100 | EFIAPI
101 | ShellAppMain (
102 | IN UINTN Argc,
103 | IN CHAR16 **Argv
104 | )
105 | {
106 | EFI_STATUS Status;
107 | EFI_GUID SMCGUID = APPLE_SMC_PROTOCOL_GUID;
108 | APPLE_SMC_PROTOCOL *SMCP;
109 | CHAR8 *SMCK;
110 | UINT32 SMCKID;
111 | UINT32 SMCKL;
112 | UINT32 SMCKLP;
113 | UINT8 *SMCKD;
114 |
115 | if (Argc != 3)
116 | {
117 | Usage(Argv[0]);
118 |
119 | return 1;
120 | }
121 |
122 | SMCK = Utf8FromUnicode(Argv[1], StrLen(Argv[1]));
123 | SMCKID = *(UINT32 *)SMCK;
124 |
125 | SMCKL = (UINT32)StrDecimalToUint64(Argv[2]);
126 |
127 | Status = gBS->LocateProtocol (
128 | &SMCGUID,
129 | NULL,
130 | (VOID **)&SMCP
131 | );
132 |
133 | if (EFI_ERROR(Status))
134 | {
135 | Print(L"ERROR: Could not locate Apple SMC Protocol, no SMC read possible\n");
136 |
137 | return -1;
138 | }
139 |
140 | Print(L"Signature: 0x%llx", SMCP->Signature);
141 |
142 | SMCKD = AllocateZeroPool(SMCKL);
143 |
144 | Status = SMCP->ReadData(SMCKD, SMCKID, SMCKL, SMCKD);
145 |
146 | if (EFI_ERROR(Status))
147 | {
148 | Print(L"ERROR: Could not read SMC key named %s for length %u\n", Argv[1], SMCKL);
149 |
150 | return -1;
151 | };
152 |
153 | Print(L"%s: [ ", Argv[1]);
154 |
155 | SMCKLP = 0;
156 | while (SMCKLP < SMCKL)
157 | {
158 | Print(L"%.2X ", SMCKD);
159 |
160 | ++SMCKLP;
161 | }
162 |
163 | Print(L"]\n");
164 |
165 | return 0;
166 | }
167 |
--------------------------------------------------------------------------------
/ReadSMC/ReadSMC.inf:
--------------------------------------------------------------------------------
1 | ## @file
2 | # This is the shell application
3 | #
4 | # Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.
5 | #
6 | # This program and the accompanying materials
7 | # are licensed and made available under the terms and conditions of the BSD License
8 | # which accompanies this distribution. The full text of the license may be found at
9 | # http://opensource.org/licenses/bsd-license.php
10 | # THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 | # WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 | #
13 | #
14 | ##
15 |
16 | [Defines]
17 | INF_VERSION = 0x00010006
18 | BASE_NAME = ReadSMC
19 | FILE_GUID = faec88Bd-afa1-4653-95F3-cf4790061d41
20 | MODULE_TYPE = UEFI_APPLICATION
21 | VERSION_STRING = 1.0
22 | ENTRY_POINT = ShellCEntryLib
23 |
24 | #
25 | # The following information is for reference only and not required by the build tools.
26 | #
27 | # VALID_ARCHITECTURES = IA32 X64 IPF EBC
28 | #
29 |
30 | [Sources]
31 | ReadSMC.c
32 |
33 | [Packages]
34 | MdePkg/MdePkg.dec
35 | ShellPkg/ShellPkg.dec
36 |
37 | [LibraryClasses]
38 | ShellCEntryLib
39 | MemoryAllocationLib
40 | UefiLib
41 | BaseLib
42 | UefiBootServicesTableLib
43 |
--------------------------------------------------------------------------------
/X64/ReadSMC.efi:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andyvand/ReadSMC/329b3011d44354974cc2e39bf12d5991420585f3/X64/ReadSMC.efi
--------------------------------------------------------------------------------
/readme.md:
--------------------------------------------------------------------------------
1 | - ReadSMC
2 | (U)EFI shell tool to read SMC keys and signature from real SMC device.
--------------------------------------------------------------------------------