ACPI AML decompiler w/ CFG recovery and structured pseudocode
1#include "t.h"
2
3#include "p.h"
4
5static int parse_has_error(const uint8_t *b, size_t n) {
6 tobi_parse_result r;
7 (void)tobi_parse(b, n, 0, &r);
8 int has = tobi_diag_has_error(&r.diag);
9 tobi_parse_result_free(&r);
10 return has;
11}
12
13static int strict_fails(const uint8_t *b, size_t n) {
14 tobi_parse_result r;
15 int ok = tobi_parse(b, n, 1, &r);
16 int has = tobi_diag_has_error(&r.diag);
17 tobi_parse_result_free(&r);
18 return !ok && has;
19}
20
21int t_bad(void) {
22 uint8_t trunc_pkg[] = {0x14,0x20,'M','T'};
23 T_CHECK(parse_has_error(trunc_pkg, sizeof(trunc_pkg)));
24 uint8_t invalid_pkg[] = {0x14,0x80,0x00};
25 T_CHECK(parse_has_error(invalid_pkg, sizeof(invalid_pkg)));
26 uint8_t unterm_str[] = {0x0d,'a','b'};
27 T_CHECK(parse_has_error(unterm_str, sizeof(unterm_str)));
28 uint8_t trunc_name[] = {0x08,'A'};
29 T_CHECK(parse_has_error(trunc_name, sizeof(trunc_name)));
30 uint8_t bad_table[40] = {'D','S','D','T',1,0,0,0};
31 T_CHECK(parse_has_error(bad_table, sizeof(bad_table)));
32 uint8_t bad_sum[40] = {'S','S','D','T',40,0,0,0};
33 T_CHECK(strict_fails(bad_sum, sizeof(bad_sum)));
34 uint8_t trunc_mutex[] = {0x5b,0x01,'M','T','X','0'};
35 T_CHECK(parse_has_error(trunc_mutex, sizeof(trunc_mutex)));
36 uint8_t trunc_processor[] = {0x5b,0x83,0x05,'P','R','C','0'};
37 T_CHECK(parse_has_error(trunc_processor, sizeof(trunc_processor)));
38 uint8_t trunc_power[] = {0x5b,0x84,0x05,'P','W','R','0'};
39 T_CHECK(parse_has_error(trunc_power, sizeof(trunc_power)));
40 uint8_t rnd[128];
41 for (size_t i = 0; i < sizeof(rnd); i++) {
42 rnd[i] = (uint8_t)(i * 37u + 11u);
43 }
44 tobi_parse_result r;
45 T_CHECK(tobi_parse(rnd, sizeof(rnd), 0, &r));
46 tobi_parse_result_free(&r);
47 uint8_t deep[160];
48 for (size_t i = 0; i < sizeof(deep); i += 2) {
49 deep[i] = 0x10;
50 deep[i + 1] = 0x7f;
51 }
52 T_CHECK(parse_has_error(deep, sizeof(deep)));
53 return 0;
54}