Binary Ninja API C++: Websocket Provider


◆ BinaryNinja::WebsocketClient

class BinaryNinja::WebsocketClient

Public Member Functions

bool Connect (const std::string &host, const std::unordered_map< std::string, std::string > &headers, BNWebsocketClientOutputCallbacks *callbacks)
 Connect to a given url, asynchronously.
virtual bool Write (const std::vector< uint8_t > &data)=0
 Write some data to the websocket.
virtual bool Disconnect ()=0
 Disconnect the websocket.
Public Member Functions inherited from BinaryNinja::CoreRefCountObject< BNWebsocketClient, BNNewWebsocketClientReference, BNFreeWebsocketClient >
 CoreRefCountObject ()
virtual ~CoreRefCountObject ()
BNWebsocketClientGetObject () const
void AddRef ()
void Release ()
void AddRefForRegistration ()
void ReleaseForRegistration ()
void AddRefForCallback ()
void ReleaseForCallback ()

Protected Member Functions

 WebsocketClient (WebsocketProvider *provider)
 WebsocketClient (BNWebsocketClient *instance)
bool ReadData (uint8_t *data, uint64_t len)
virtual void DestroyClient ()
 Cleanup any resources created by the client.
virtual bool Connect (const std::string &host, const std::unordered_map< std::string, std::string > &headers)=0
 Virtual method for performing the connection, overridden by a subclass.

Static Protected Member Functions

static void DestroyClientCallback (void *ctxt)
static bool ConnectCallback (void *ctxt, const char *host, uint64_t headerCount, const char *const *headerKeys, const char *const *headerValues)
static bool WriteCallback (const uint8_t *data, uint64_t len, void *ctxt)
static bool DisconnectCallback (void *ctxt)
static void ErrorCallback (const char *msg, void *ctxt)

◆ WebsocketClient() [1/2]

WebsocketClient::WebsocketClient ( WebsocketProvider * provider)
protected

◆ WebsocketClient() [2/2]

◆ DestroyClientCallback()

void WebsocketClient::DestroyClientCallback ( void * ctxt)
staticprotected

◆ ConnectCallback()

bool WebsocketClient::ConnectCallback ( void * ctxt,
const char * host,
uint64_t headerCount,
const char *const * headerKeys,
const char *const * headerValues )
staticprotected

◆ WriteCallback()

bool WebsocketClient::WriteCallback ( const uint8_t * data,
uint64_t len,
void * ctxt )
staticprotected

◆ DisconnectCallback()

bool WebsocketClient::DisconnectCallback ( void * ctxt)
staticprotected

◆ ErrorCallback()

void WebsocketClient::ErrorCallback ( const char * msg,
void * ctxt )
staticprotected

◆ ReadData()

bool WebsocketClient::ReadData ( uint8_t * data,
uint64_t len )
protected

◆ DestroyClient()

void WebsocketClient::DestroyClient ( )
protectedvirtual

Cleanup any resources created by the client.

◆ Connect() [1/2]

virtual bool BinaryNinja::WebsocketClient::Connect ( const std::string & host,
const std::unordered_map< std::string, std::string > & headers )
protectedpure virtual

Virtual method for performing the connection, overridden by a subclass.

Parameters
hostFull url with scheme, domain, optionally port, and path
headersHTTP header keys and values
Returns
True if the connection has started, but not necessarily if it succeeded

Implemented in BinaryNinja::CoreWebsocketClient.

◆ Connect() [2/2]

bool WebsocketClient::Connect ( const std::string & host,
const std::unordered_map< std::string, std::string > & headers,
BNWebsocketClientOutputCallbacks * callbacks )

Connect to a given url, asynchronously.

The connection will be run in a separate thread managed by the websocket provider.

Callbacks will be called **on the thread of the connection**, so be sure to ExecuteOnMainThread any long-running or gui operations in the callbacks.

If the connection succeeds, connectedCallback will be called. On normal termination, disconnectedCallback will be called. If the connection succeeds, but later fails, disconnectedCallback will not be called, and errorCallback will be called instead. If the connection fails, neither connectedCallback nor disconnectedCallback will be called, and errorCallback will be called instead.

If connectedCallback or readCallback return false, the connection will be aborted.

Parameters
hostFull url with scheme, domain, optionally port, and path
headersHTTP header keys and values
callbacksStructure with callbacks for various websocket events
Returns
True if the connection has started, but not necessarily if it succeeded

◆ Write()

virtual bool BinaryNinja::WebsocketClient::Write ( const std::vector< uint8_t > & data)
pure virtual

Write some data to the websocket.

Parameters
Returns
True if successful

Implemented in BinaryNinja::CoreWebsocketClient.

◆ Disconnect()

virtual bool BinaryNinja::WebsocketClient::Disconnect ( )
pure virtual

Disconnect the websocket.

Returns
True if successful

Implemented in BinaryNinja::CoreWebsocketClient.

◆ BinaryNinja::CoreWebsocketClient

class BinaryNinja::CoreWebsocketClient

Public Member Functions

 CoreWebsocketClient (BNWebsocketClient *instance)
virtual ~CoreWebsocketClient ()
virtual bool Connect (const std::string &host, const std::unordered_map< std::string, std::string > &headers) override
 Virtual method for performing the connection, overridden by a subclass.
virtual bool Write (const std::vector< uint8_t > &data) override
 Write some data to the websocket.
virtual bool Disconnect () override
 Disconnect the websocket.
Public Member Functions inherited from BinaryNinja::WebsocketClient
bool Connect (const std::string &host, const std::unordered_map< std::string, std::string > &headers, BNWebsocketClientOutputCallbacks *callbacks)
 Connect to a given url, asynchronously.
Public Member Functions inherited from BinaryNinja::CoreRefCountObject< BNWebsocketClient, BNNewWebsocketClientReference, BNFreeWebsocketClient >
 CoreRefCountObject ()
virtual ~CoreRefCountObject ()
BNWebsocketClientGetObject () const
void AddRef ()
void Release ()
void AddRefForRegistration ()
void ReleaseForRegistration ()
void AddRefForCallback ()
void ReleaseForCallback ()

Additional Inherited Members

Public Attributes inherited from BinaryNinja::CoreRefCountObject< BNWebsocketClient, BNNewWebsocketClientReference, BNFreeWebsocketClient >
std::atomic< int > m_refs
bool m_registeredRef
BNWebsocketClientm_object
Protected Member Functions inherited from BinaryNinja::WebsocketClient
 WebsocketClient (WebsocketProvider *provider)
 WebsocketClient (BNWebsocketClient *instance)
bool ReadData (uint8_t *data, uint64_t len)
virtual void DestroyClient ()
 Cleanup any resources created by the client.
Static Protected Member Functions inherited from BinaryNinja::WebsocketClient
static void DestroyClientCallback (void *ctxt)
static bool ConnectCallback (void *ctxt, const char *host, uint64_t headerCount, const char *const *headerKeys, const char *const *headerValues)
static bool WriteCallback (const uint8_t *data, uint64_t len, void *ctxt)
static bool DisconnectCallback (void *ctxt)
static void ErrorCallback (const char *msg, void *ctxt)

◆ CoreWebsocketClient()

◆ ~CoreWebsocketClient()

virtual BinaryNinja::CoreWebsocketClient::~CoreWebsocketClient ( )
inlinevirtual

◆ Connect()

bool CoreWebsocketClient::Connect ( const std::string & host,
const std::unordered_map< std::string, std::string > & headers )
overridevirtual

Virtual method for performing the connection, overridden by a subclass.

Parameters
hostFull url with scheme, domain, optionally port, and path
headersHTTP header keys and values
Returns
True if the connection has started, but not necessarily if it succeeded

Implements BinaryNinja::WebsocketClient.

◆ Write()

bool CoreWebsocketClient::Write ( const std::vector< uint8_t > & data)
overridevirtual

Write some data to the websocket.

Parameters
Returns
True if successful

Implements BinaryNinja::WebsocketClient.

◆ Disconnect()

bool CoreWebsocketClient::Disconnect ( )
overridevirtual

Disconnect the websocket.

Returns
True if successful

Implements BinaryNinja::WebsocketClient.

◆ BinaryNinja::WebsocketProvider

class BinaryNinja::WebsocketProvider