OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
ACPIe.c
Go to the documentation of this file.
1
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9#include <Uefi/UefiBaseType.h>
10#include <Library/BaseMemoryLib.h>
11#include <Library/BaseOverflowLib.h>
12#include <Library/MemoryAllocationLib.h>
13#include <Library/DebugLib.h>
14#include <IndustryStandard/Acpi.h>
15#include <Library/OcAcpiLib.h>
16#include <IndustryStandard/AcpiAml.h>
17#include <UserFile.h>
18
24STATIC
25VOID
27 IN EFI_STATUS Status
28 )
29{
30 switch (Status) {
31 case EFI_SUCCESS:
32 break;
33
34 case EFI_INVALID_PARAMETER:
35 DEBUG ((DEBUG_ERROR, "EXIT: Invalid parameter!\n"));
36 break;
37
38 case EFI_DEVICE_ERROR:
39 DEBUG ((DEBUG_ERROR, "EXIT: ACPI table is incorrect or not supported by parser!\n"));
40 break;
41
42 case EFI_NOT_FOUND:
43 DEBUG ((DEBUG_ERROR, "EXIT: No entry found in the table.\n"));
44 break;
45
46 case EFI_OUT_OF_RESOURCES:
47 DEBUG ((DEBUG_ERROR, "EXIT: ACPI table has too much nesting!\n"));
48 break;
49
50 case EFI_LOAD_ERROR:
51 DEBUG ((DEBUG_ERROR, "EXIT: File error in table file!\n"));
52 break;
53
54 default:
55 DEBUG ((DEBUG_ERROR, "EXIT: Unknown error!\n"));
56 break;
57 }
58}
59
76STATIC
77EFI_STATUS
79 IN CONST CHAR8 *FileName,
80 IN CONST CHAR8 *PathString,
81 IN UINT8 Entry,
82 OUT UINT32 *Offset
83 )
84{
85 UINT8 *TableStart;
86 EFI_STATUS Status;
87 UINT32 TableLength;
88
89 TableStart = UserReadFile (FileName, &TableLength);
90 if (TableStart == NULL) {
91 DEBUG ((DEBUG_INFO, "No file %a\n", FileName));
92 return EFI_LOAD_ERROR;
93 }
94
95 Status = AcpiFindEntryInMemory (TableStart, PathString, Entry, Offset, TableLength);
96
97 FreePool (TableStart);
98
99 return Status;
100}
101
102// -[f|a] , CHAR8 ** memory_location , CHAR8 ** path , UINT8 occurance
103
114int
116 int argc,
117 char *argv[]
118 )
119{
120 UINT32 ReturnedOffset;
121 EFI_STATUS Status;
122
123 #if defined (VERBOSE) && !defined (FUZZING_TEST)
124 PcdGet32 (PcdFixedDebugPrintErrorLevel) |= DEBUG_VERBOSE | DEBUG_INFO;
125 PcdGet32 (PcdDebugPrintErrorLevel) |= DEBUG_VERBOSE | DEBUG_INFO;
126 #endif
127
128 switch (argc) {
129 case 5:
130 if (((argv[1][0] == '-') && (argv[1][1] == 'f')) || ((argv[1][0] == '-') && (argv[1][1] == 'a'))) {
131 ReturnedOffset = 0;
132
133 if ((argv[1][0] == '-') && (argv[1][1] == 'f')) {
134 DEBUG ((DEBUG_VERBOSE, "Entered main (file)\n"));
135 Status = AcpiFindEntryInFile (
136 argv[2],
137 argv[3],
138 atoi (argv[4]),
139 &ReturnedOffset
140 );
141
142 if (!EFI_ERROR (Status)) {
143 DEBUG ((DEBUG_ERROR, "Returned offset: %d\n", ReturnedOffset));
144 } else {
145 PrintParserError (Status);
146 }
147
148 return 0;
149 }
150
151 DEBUG ((DEBUG_VERBOSE, "Entered main (address)\n"));
152 Status = AcpiFindEntryInFile (
153 argv[2],
154 argv[3],
155 atoi (argv[4]),
156 &ReturnedOffset
157 );
158
159 if (!EFI_ERROR (Status)) {
160 DEBUG ((DEBUG_ERROR, "Returned offset: %d\n", ReturnedOffset));
161 } else {
162 PrintParserError (Status);
163 }
164
165 return 0;
166 }
167
168 DEBUG ((DEBUG_ERROR, "Usage: ACPIe -f *file* *search path* [number of occurance]\n"));
169 return 2;
170
171 break;
172
173 case 4:
174 if (((argv[1][0] == '-') && (argv[1][1] == 'f')) || ((argv[1][0] == '-') && (argv[1][1] == 'a'))) {
175 if ((argv[1][0] == '-') && (argv[1][1] == 'f')) {
176 DEBUG ((DEBUG_VERBOSE, "Entered main (file)\n"));
177 Status = AcpiFindEntryInFile (
178 argv[2],
179 argv[3],
180 1,
181 &ReturnedOffset
182 );
183
184 if (!EFI_ERROR (Status)) {
185 DEBUG ((DEBUG_ERROR, "Returned offset: %d\n", ReturnedOffset));
186 } else {
187 PrintParserError (Status);
188 }
189
190 return 0;
191 }
192
193 DEBUG ((DEBUG_VERBOSE, "Entered main (address)\n"));
194 Status = AcpiFindEntryInFile (
195 argv[2],
196 argv[3],
197 1,
198 &ReturnedOffset
199 );
200
201 if (!EFI_ERROR (Status)) {
202 DEBUG ((DEBUG_ERROR, "Returned offset: %d\n", ReturnedOffset));
203 } else {
204 PrintParserError (Status);
205 }
206
207 return 0;
208 }
209
210 DEBUG ((DEBUG_ERROR, "Usage: ACPIe -f *file* *search path* [number of occurance]\n"));
211 return 2;
212
213 break;
214
215 default:
216 DEBUG ((DEBUG_ERROR, "Usage: ACPIe -f *file* *search path* [number of occurance]\n"));
217 return 0;
218
219 break;
220 }
221
222 return 0;
223}
224
225int
227 const uint8_t *Data,
228 size_t Size
229 )
230{
231 if (Size > 0) {
232 UINT32 offset = 0;
234 (UINT8 *)Data,
235 "_SB.PCI0.GFX0",
236 1,
237 &offset,
238 (UINT32)Size
239 );
240 }
241
242 return 0;
243}
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
Definition ACPIe.c:226
STATIC VOID PrintParserError(IN EFI_STATUS Status)
Definition ACPIe.c:26
STATIC EFI_STATUS AcpiFindEntryInFile(IN CONST CHAR8 *FileName, IN CONST CHAR8 *PathString, IN UINT8 Entry, OUT UINT32 *Offset)
Definition ACPIe.c:78
EFI_STATUS AcpiFindEntryInMemory(IN UINT8 *Table, IN CONST CHAR8 *PathString, IN UINT8 Entry, OUT UINT32 *Offset, IN UINT32 TableLength OPTIONAL)
DMG_SIZE_DEVICE_PATH Size
UINT8 * UserReadFile(IN CONST CHAR8 *FileName, OUT UINT32 *Size)
Definition UserFile.c:62
UINT8 uint8_t
int ENTRY_POINT(void)