Xeno-rat
Loading...
Searching...
No Matches
xeno_rat_server.SocketHandler Class Reference
Collaboration diagram for xeno_rat_server.SocketHandler:

Public Member Functions

 SocketHandler (Socket socket, byte[] _EncryptionKey)
 
async Task< bool > SendAsync (byte[] data)
 Sends the provided data asynchronously over the socket.
 
async Task< byte[]> ReceiveAsync ()
 Asynchronously receives data and processes it according to the protocol, then returns the processed data.
 
byte[] Concat (byte[] b1, byte[] b2)
 Concatenates two byte arrays and returns the result.
 
byte[] BTruncate (byte[] bytes, int offset)
 Truncates the input byte array starting from the specified offset and returns the truncated byte array.
 
int BytesToInt (byte[] data, int offset=0)
 Converts the specified byte array to an integer value.
 
byte[] IntToBytes (int data)
 Converts an integer to a byte array.
 
void SetRecvTimeout (int ms)
 Sets the receive timeout for the socket.
 
void ResetRecvTimeout ()
 Resets the receive timeout for the socket.
 

Public Attributes

Socket sock
 
byte[] EncryptionKey
 
int socktimeout = 0
 

Private Member Functions

async Task< byte[]> RecvAllAsync_ddos_unsafer (int size)
 Asynchronously receives all the data of the specified size from the connected socket and returns the received data as a byte array.
 
async Task< byte[]> RecvAllAsync_ddos_safer (int size)
 Asynchronously receives all data of the specified size from the socket and returns the received data as a byte array.
 
header ParseHeader (byte[] data)
 Parses the header from the provided byte array and returns the parsed header object.
 

Private Attributes

bool doProtocolUpgrade = false
 

Constructor & Destructor Documentation

◆ SocketHandler()

xeno_rat_server.SocketHandler.SocketHandler ( Socket socket,
byte[] _EncryptionKey )
inline

Member Function Documentation

◆ BTruncate()

byte[] xeno_rat_server.SocketHandler.BTruncate ( byte[] bytes,
int offset )
inline

Truncates the input byte array starting from the specified offset and returns the truncated byte array.

Parameters
bytesThe input byte array from which to truncate.
offsetThe offset from which to start truncating the byte array.
Returns
The truncated byte array starting from the specified offset .

This method creates a new byte array T_data with a length equal to the difference between the length of the input byte array bytes and the specified offset . It then uses the Buffer.BlockCopy method to copy a portion of the input byte array starting from the specified offset into the new byte array T_data . The truncated byte array T_data is then returned.

Here is the caller graph for this function:

◆ BytesToInt()

int xeno_rat_server.SocketHandler.BytesToInt ( byte[] data,
int offset = 0 )
inline

Converts the specified byte array to an integer value.

Parameters
dataThe byte array to be converted.
offsetThe offset within the byte array at which to begin converting (default is 0).
Returns
The integer value represented by the specified byte array.

This method converts the specified byte array to an integer value, taking into account the endianness of the system. If the system is little-endian, the bytes are combined in little-endian order (least significant byte first). If the system is big-endian, the bytes are combined in big-endian order (most significant byte first).

Here is the caller graph for this function:

◆ Concat()

byte[] xeno_rat_server.SocketHandler.Concat ( byte[] b1,
byte[] b2 )
inline

Concatenates two byte arrays and returns the result.

Parameters
b1The first byte array to be concatenated. If null, an empty byte array is used.
b2The second byte array to be concatenated.
Returns
A byte array containing the concatenated elements of b1 and b2 .

This method concatenates the elements of the input byte arrays b1 and b2 into a single byte array. If b1 is null, an empty byte array is used for concatenation.

Here is the caller graph for this function:

◆ IntToBytes()

byte[] xeno_rat_server.SocketHandler.IntToBytes ( int data)
inline

Converts an integer to a byte array.

Parameters
dataThe integer to be converted to a byte array.
Returns
A byte array representing the input integer.

This method converts the input integer data to a byte array of length 4. If the system architecture is little-endian, the bytes are arranged in little-endian order, otherwise in big-endian order.

Here is the caller graph for this function:

◆ ParseHeader()

header xeno_rat_server.SocketHandler.ParseHeader ( byte[] data)
inlineprivate

Parses the header from the provided byte array and returns the parsed header object.

Parameters
dataThe byte array containing the header information.
Returns
The parsed header object.

This method parses the header from the provided byte array. If the first byte of the array is 1, it indicates that the data is compressed, and the method sets the corresponding properties of the header object. If the first byte is not 0 or 1, the method returns null, indicating an invalid header.

Exceptions
IndexOutOfRangeExceptionThrown if the provided byte array is empty or does not contain sufficient data for parsing the header.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReceiveAsync()

async Task< byte[]> xeno_rat_server.SocketHandler.ReceiveAsync ( )
inline

Asynchronously receives data and processes it according to the protocol, then returns the processed data.

Returns
The processed data received from the client.

This method continuously receives data from the client and processes it according to the protocol. It first receives the length of the data, then the actual data. The method checks for disconnection at each step and returns null if the client has disconnected. If the received data indicates a protocol upgrade, it performs the upgrade and returns the processed data. If the received data does not indicate a protocol upgrade, it processes the data according to the current protocol and returns the processed data.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RecvAllAsync_ddos_safer()

async Task< byte[]> xeno_rat_server.SocketHandler.RecvAllAsync_ddos_safer ( int size)
inlineprivate

Asynchronously receives all data of the specified size from the socket and returns the received data as a byte array.

Parameters
sizeThe size of the data to be received.
Returns
The received data as a byte array. Returns null if the socket is not connected, or if a timeout occurs while waiting for data.

This method asynchronously receives data from the socket until the total received data size matches the specified size. If the socket is not connected, the method returns null. If a timeout occurs while waiting for data, the method returns null. The method uses asynchronous socket operations to efficiently receive data without blocking the calling thread.

◆ RecvAllAsync_ddos_unsafer()

async Task< byte[]> xeno_rat_server.SocketHandler.RecvAllAsync_ddos_unsafer ( int size)
inlineprivate

Asynchronously receives all the data of the specified size from the connected socket and returns the received data as a byte array.

Parameters
sizeThe size of the data to be received.
Returns
The received data as a byte array.

This method asynchronously receives data from the connected socket until the specified size is reached. It uses a while loop to continuously receive data in chunks and updates the total received and remaining data size until all the data is received. If the socket is not connected, it returns null. If no data is received (recv = 0), it sets the data to null and breaks the loop.

Here is the caller graph for this function:

◆ ResetRecvTimeout()

void xeno_rat_server.SocketHandler.ResetRecvTimeout ( )
inline

Resets the receive timeout for the socket.

This method sets the receive timeout for the socket to zero, effectively disabling the receive timeout feature.

Here is the caller graph for this function:

◆ SendAsync()

async Task< bool > xeno_rat_server.SocketHandler.SendAsync ( byte[] data)
inline

Sends the provided data asynchronously over the socket.

Parameters
dataThe byte array to be sent.
Returns
A task representing the asynchronous operation. The task result is true if the data was sent successfully; otherwise, false.
Exceptions
ArgumentNullExceptionThrown when the input data is null.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetRecvTimeout()

void xeno_rat_server.SocketHandler.SetRecvTimeout ( int ms)
inline

Sets the receive timeout for the socket.

Parameters
msThe receive timeout value in milliseconds.

This method sets the receive timeout for the socket to the specified value in milliseconds.

Here is the caller graph for this function:

Member Data Documentation

◆ doProtocolUpgrade

bool xeno_rat_server.SocketHandler.doProtocolUpgrade = false
private

◆ EncryptionKey

byte [] xeno_rat_server.SocketHandler.EncryptionKey

◆ sock

Socket xeno_rat_server.SocketHandler.sock

◆ socktimeout

int xeno_rat_server.SocketHandler.socktimeout = 0

The documentation for this class was generated from the following file: