BeefFuzz.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #pragma warning(disable:4996)
  2. #include <iostream>
  3. #include "BeefySysLib/Common.h"
  4. #include "BeefySysLib/util/Array.h"
  5. #include "BeefySysLib/util/SizedArray.h"
  6. #include "BeefySysLib/util/Dictionary.h"
  7. #include "BeefySysLib/util/CabUtil.h"
  8. #include "BeefySysLib/util/BeefPerf.h"
  9. #include "BeefySysLib/util/Deque.h"
  10. #include "BeefySysLib/util/HashSet.h"
  11. #include "BeefySysLib/util/MultiHashSet.h"
  12. #define BF_DBG_64
  13. #include "IDEHelper/StrHashMap.h"
  14. using namespace Beefy;
  15. #include "FuzzApp.h"
  16. BF_IMPORT void BF_CALLTYPE IDEHelper_ProgramStart();
  17. BF_IMPORT void BF_CALLTYPE IDEHelper_ProgramDone();
  18. static void FuzzInit()
  19. {
  20. BfpSystem_SetCommandLine(0, NULL);
  21. BfpThread_SetName(NULL, "MainThread", NULL);
  22. BfpSystem_Init(BFP_VERSION, BfpSystemInitFlag_None);
  23. IDEHelper_ProgramStart();
  24. gApp = new FuzzApp();
  25. gApp->SetTargetPath("fuzz_testd");
  26. gApp->AddDefine("CLI");
  27. gApp->AddDefine("DEBUG");
  28. gApp->SetStartupObject("fuzz_test.Program");
  29. gApp->SetLinkParams("./libBeefRT_d.a ./libBeefySysLib_d.so -ldl -lpthread -Wl,-rpath -Wl,$ORIGIN");
  30. BF_ASSERT(gApp->Init());
  31. }
  32. void trimwhitespace(const uint8_t*& str, size_t& len)
  33. {
  34. while (len > 0 && isspace(*str))
  35. {
  36. str++;
  37. len--;
  38. }
  39. const uint8_t* end = str + len - 1;
  40. while (len > 0 && isspace(*end))
  41. {
  42. end--;
  43. len--;
  44. }
  45. }
  46. static bool init = false;
  47. extern "C" int LLVMFuzzerTestOneInput(const uint8_t *Data, size_t Size)
  48. {
  49. if (!init)
  50. {
  51. init = true;
  52. FuzzInit();
  53. }
  54. trimwhitespace(Data, Size);
  55. if (Size == 0)
  56. return 0;
  57. gApp->PrepareCompiler();
  58. bool ready = gApp->QueueFile((char*)Data, Size);
  59. //if (ready)
  60. // ready = gApp->QueuePath("./corlib/src");
  61. //if (ready)
  62. // gApp->Compile();
  63. gApp->ReleaseCompiler();
  64. return 0;
  65. }