ACPI AML decompiler w/ CFG recovery and structured pseudocode
29

Configure Feed

Select the types of activity you want to include in your feed.

tobi / fuzz / fz.c
1.6 kB 70 lines
1#include "cf.h" 2#include "p.h" 3 4#include <stdint.h> 5#include <stdio.h> 6#include <stdlib.h> 7#include <string.h> 8 9#ifndef TOBI_SRC_DIR 10#define TOBI_SRC_DIR "." 11#endif 12 13static int run_one(const uint8_t *data, size_t len) { 14 tobi_parse_result r; 15 (void)tobi_parse(data, len, 0, &r); 16 if (r.root) { 17 (void)tobi_cf_recover(r.root, &r.diag); 18 } 19 tobi_parse_result_free(&r); 20 return 0; 21} 22 23static void file_one(const char *path) { 24 FILE *fp = fopen(path, "rb"); 25 if (!fp) { 26 return; 27 } 28 (void)fseek(fp, 0, SEEK_END); 29 long n = ftell(fp); 30 rewind(fp); 31 if (n < 0) { 32 fclose(fp); 33 return; 34 } 35 uint8_t *buf = malloc((size_t)n ? (size_t)n : 1); 36 if (!buf) { 37 fclose(fp); 38 abort(); 39 } 40 if ((size_t)n == fread(buf, 1, (size_t)n, fp)) { 41 (void)run_one(buf, (size_t)n); 42 for (size_t i = 0; i <= (size_t)n; i++) { 43 (void)run_one(buf, i); 44 } 45 } 46 free(buf); 47 fclose(fp); 48} 49 50int main(void) { 51 const char *seed[] = { 52 TOBI_SRC_DIR "/fuzz/seed/m0.aml", 53 TOBI_SRC_DIR "/fuzz/seed/m1.aml", 54 TOBI_SRC_DIR "/fuzz/seed/m2.aml", 55 TOBI_SRC_DIR "/fuzz/seed/bad0.aml", 56 }; 57 for (size_t i = 0; i < sizeof(seed) / sizeof(seed[0]); i++) { 58 file_one(seed[i]); 59 } 60 uint32_t x = 0x12345678u; 61 for (size_t n = 0; n < 512; n++) { 62 uint8_t buf[256]; 63 for (size_t i = 0; i < sizeof(buf); i++) { 64 x = x * 1664525u + 1013904223u; 65 buf[i] = (uint8_t)(x >> 24); 66 } 67 (void)run_one(buf, n % sizeof(buf)); 68 } 69 return 0; 70}