Rizin
unix-like reverse engineering framework and cli tools
fuzz_llvm.cpp File Reference
#include "llvm-c/Disassembler.h"
#include "llvm-c/Target.h"
#include "llvm/MC/SubtargetFeature.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/raw_ostream.h"

Go to the source code of this file.

Functions

void LLVMFuzzerInit ()
 
int LLVMFuzzerReturnOneInput (const uint8_t *Data, size_t Size, char *AssemblyText)
 

Function Documentation

◆ LLVMFuzzerInit()

void LLVMFuzzerInit ( )

Definition at line 9 of file fuzz_llvm.cpp.

9  {
10  LLVMInitializeAllTargetInfos();
11  LLVMInitializeAllTargetMCs();
12  LLVMInitializeAllDisassemblers();
13 }

Referenced by LLVMFuzzerTestOneInput().

◆ LLVMFuzzerReturnOneInput()

int LLVMFuzzerReturnOneInput ( const uint8_t Data,
size_t  Size,
char *  AssemblyText 
)

Definition at line 16 of file fuzz_llvm.cpp.

16  {
17  LLVMDisasmContextRef Ctx;
18  std::vector<uint8_t> DataCopy(Data, Data + Size);
19  uint8_t *p = DataCopy.data();
20  int r = 1;
21 
22  switch(Data[0]) {
23  case 0:
24  Ctx = LLVMCreateDisasmCPUFeatures("i386", "", "", nullptr, 0, nullptr, nullptr);
25  if (LLVMSetDisasmOptions(Ctx, LLVMDisassembler_Option_AsmPrinterVariant) == 0) {
26  abort();
27  }
28  break;
29  //TODO other cases
30  default:
31  return 1;
32  }
33  assert(Ctx);
34 
35  if (LLVMDisasmInstruction(Ctx, p+1, Size-1, 0, AssemblyText, 80) > 0) {
36  r = 0;
37  }
38  LLVMDisasmDispose(Ctx);
39 
40  return r;
41 }
#define r
Definition: crypto_rc6.c:12
void * p
Definition: libc.cpp:67
assert(limit<=UINT32_MAX/2)
unsigned char uint8_t
Definition: sftypes.h:31

References assert(), p, and r.

Referenced by LLVMFuzzerTestOneInput().