tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

Nyx.cpp (1970B)


      1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
      2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 #include "Nyx.h"
      8 
      9 #include "mozilla/dom/TypedArray.h"
     10 
     11 namespace mozilla::dom {
     12 
     13 /* static */
     14 void Nyx::Log(const GlobalObject&, const nsACString& aMsg) {
     15  MOZ_FUZZING_NYX_PRINTF("%s\n", PromiseFlatCString(aMsg).get());
     16 }
     17 
     18 /* static */
     19 bool Nyx::IsEnabled(const GlobalObject&, const nsACString& aFuzzerName) {
     20  return fuzzing::Nyx::instance().is_enabled(
     21      PromiseFlatCString(aFuzzerName).get());
     22 }
     23 
     24 /* static */
     25 bool Nyx::IsReplay(const GlobalObject&) {
     26 #ifdef FUZZING_SNAPSHOT
     27  return fuzzing::Nyx::instance().is_replay();
     28 #endif
     29  return false;
     30 }
     31 
     32 /* static */
     33 bool Nyx::IsStarted(const GlobalObject&) {
     34  return fuzzing::Nyx::instance().started();
     35 }
     36 
     37 /* static */
     38 void Nyx::Start(const GlobalObject&) {
     39  MOZ_FUZZING_NYX_PRINT("INFO: Performing snapshot...\n");
     40  fuzzing::Nyx::instance().start();
     41 }
     42 
     43 /* static */
     44 void Nyx::Release(const GlobalObject&, uint32_t aIterations) {
     45  MOZ_FUZZING_NYX_PRINT("INFO: Reverting snapshot...\n");
     46  fuzzing::Nyx::instance().release(aIterations);
     47 }
     48 
     49 /* static */
     50 void Nyx::GetRawData(const GlobalObject& aGlobal,
     51                     JS::MutableHandle<JSObject*> aRetval, ErrorResult& aRv) {
     52  uint8_t* buf = nullptr;
     53  uint32_t size = fuzzing::Nyx::instance().get_raw_data(&buf);
     54  if (buf == nullptr) {
     55    MOZ_FUZZING_NYX_PRINT("ERROR: Failed to get pointer to global payload.\n");
     56  }
     57 
     58  auto* cx = aGlobal.Context();
     59  JS::Rooted<JSObject*> arrayBuffer(
     60      cx, JS::NewArrayBufferWithUserOwnedContents(cx, size, buf));
     61 
     62  if (!arrayBuffer) {
     63    MOZ_FUZZING_NYX_PRINT("ERROR: Failed to create ArrayBuffer.\n");
     64    return;
     65  }
     66 
     67  aRetval.set(arrayBuffer);
     68 }
     69 
     70 }  // namespace mozilla::dom