Rizin
unix-like reverse engineering framework and cli tools
driverbin.c
Go to the documentation of this file.
1 #include <stdint.h>
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <dirent.h>
5 #include <unistd.h>
6 
7 int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size);
8 const char * cs_fuzz_arch(uint8_t arch);
9 
10 int main(int argc, char** argv)
11 {
12  FILE * fp;
13  uint8_t Data[0x1000];
14  size_t Size;
15  DIR *d;
16  struct dirent *dir;
17  int r = 0;
18  int i;
19 
20  if (argc != 2) {
21  return 1;
22  }
23 
24  d = opendir(argv[1]);
25  if (d == NULL) {
26  printf("Invalid directory\n");
27  return 2;
28  }
29  if (chdir(argv[1]) != 0) {
30  closedir(d);
31  printf("Invalid directory\n");
32  return 2;
33  }
34 
35  while((dir = readdir(d)) != NULL) {
36  //opens the file, get its size, and reads it into a buffer
37  if (dir->d_type != DT_REG) {
38  continue;
39  }
40 
41  printf("Running %s\n", dir->d_name);
42  fflush(stdout);
43 
44  fp = fopen(dir->d_name, "rb");
45  if (fp == NULL) {
46  r = 3;
47  break;
48  }
49  if (fseek(fp, 0L, SEEK_END) != 0) {
50  fclose(fp);
51  r = 4;
52  break;
53  }
54  Size = ftell(fp);
55  if (Size == (size_t) -1) {
56  fclose(fp);
57  r = 5;
58  break;
59  } else if (Size > 0x1000) {
60  fclose(fp);
61  continue;
62  }
63  if (fseek(fp, 0L, SEEK_SET) != 0) {
64  fclose(fp);
65  r = 7;
66  break;
67  }
68  if (fread(Data, Size, 1, fp) != 1) {
69  fclose(fp);
70  r = 8;
71  break;
72  }
73  if (Size > 0) {
74  printf("command cstool %s\n", cs_fuzz_arch(Data[0]));
75  }
76  for (i=0; i<Size; i++) {
77  printf("%02x", Data[i]);
78  }
79  printf("\n");
80 
81  //lauch fuzzer
82  LLVMFuzzerTestOneInput(Data, Size);
83  fclose(fp);
84  }
85  closedir(d);
86  printf("Ok : whole directory finished\n");
87  return r;
88 }
89 
lzma_index ** i
Definition: index.h:629
#define NULL
Definition: cris-opc.c:27
#define r
Definition: crypto_rc6.c:12
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
cs_arch arch
Definition: cstool.c:13
static static fork const void static count static fd const char const char static newpath chdir
Definition: sflib.h:33
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
Definition: fuzz_disasm.c:221
int main(int argc, char **argv)
Definition: driverbin.c:10
const char * cs_fuzz_arch(uint8_t arch)
Definition: fuzz_disasm.c:217
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname unsigned long static filedes void static end_data_segment static handler static getegid char static len static pgid const char static path static newfd static getpgrp static euid const sigset_t static mask const char static len const gid_t static list const char const char static newpath const char static library readdir
Definition: sflib.h:120
string FILE
Definition: benchmark.py:21
unsigned char uint8_t
Definition: sftypes.h:31
#define d(i)
Definition: sha256.c:44
Definition: sftypes.h:48
char d_name[256]
Definition: sftypes.h:52
#define SEEK_SET
Definition: zip.c:88
#define SEEK_END
Definition: zip.c:84
#define L
Definition: zip_err_str.c:7