Rizin
unix-like reverse engineering framework and cli tools
standaloneengine.c
Go to the documentation of this file.
1 #include <stdint.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 
5 #include "fuzz.h"
6 
13 int main(int argc, char **argv)
14 {
15  int ii;
16  for(ii = 1; ii < argc; ii++)
17  {
18  FILE *infile;
19  printf("[%s] ", argv[ii]);
20 
21  /* Try and open the file. */
22  infile = fopen(argv[ii], "rb");
23  if(infile)
24  {
25  uint8_t *buffer = NULL;
26  size_t buffer_len;
27 
28  printf("Opened.. ");
29 
30  /* Get the length of the file. */
31  fseek(infile, 0L, SEEK_END);
32  buffer_len = ftell(infile);
33 
34  /* Reset the file indicator to the beginning of the file. */
35  fseek(infile, 0L, SEEK_SET);
36 
37  /* Allocate a buffer for the file contents. */
38  buffer = (uint8_t *)calloc(buffer_len, sizeof(uint8_t));
39  if(buffer)
40  {
41  /* Read all the text from the file into the buffer. */
42  fread(buffer, sizeof(uint8_t), buffer_len, infile);
43  printf("Read %zu bytes, fuzzing.. ", buffer_len);
44 
45  /* Call the fuzzer with the data. */
46  LLVMFuzzerTestOneInput(buffer, buffer_len);
47 
48  printf("complete !!");
49 
50  /* Free the buffer as it's no longer needed. */
51  free(buffer);
52  buffer = NULL;
53  }
54  else
55  {
56  fprintf(stderr,
57  "[%s] Failed to allocate %zu bytes \n",
58  argv[ii],
59  buffer_len);
60  }
61 
62  /* Close the file as it's no longer needed. */
63  fclose(infile);
64  infile = NULL;
65  }
66  else
67  {
68  /* Failed to open the file. Maybe wrong name or wrong permissions? */
69  fprintf(stderr, "[%s] Open failed. \n", argv[ii]);
70  }
71 
72  printf("\n");
73  }
74 }
#define NULL
Definition: cris-opc.c:27
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
Definition: fuzz_disasm.c:221
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
string FILE
Definition: benchmark.py:21
unsigned char uint8_t
Definition: sftypes.h:31
int main(int argc, char **argv)
Definition: buffer.h:15
Definition: z80asm.h:95
#define SEEK_SET
Definition: zip.c:88
#define SEEK_END
Definition: zip.c:84
#define L
Definition: zip_err_str.c:7