2023-09-02 15:47:15 +02:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection.Metadata.Ecma335;
|
2023-09-02 17:56:46 +02:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2023-09-02 15:47:15 +02:00
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Serilog;
|
2023-09-02 17:56:46 +02:00
|
|
|
|
using server;
|
|
|
|
|
using service;
|
2023-09-02 15:47:15 +02:00
|
|
|
|
|
|
|
|
|
namespace server
|
|
|
|
|
{
|
|
|
|
|
public class Message
|
|
|
|
|
{
|
|
|
|
|
private byte[] _buffer;
|
|
|
|
|
private int _bufferSize;
|
|
|
|
|
private int _messageType;
|
2023-09-02 17:56:46 +02:00
|
|
|
|
private ILogger _logger;
|
2023-09-02 15:47:15 +02:00
|
|
|
|
|
|
|
|
|
private enum MESSAGE_TYPE
|
|
|
|
|
{
|
|
|
|
|
MESSAGE_TYPE_REPORT = 1,
|
|
|
|
|
MESSAGE_TYPE_SEND = 2,
|
|
|
|
|
MESSAGE_TYPE_RECEIVE = 3
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct PACKET_HEADER
|
|
|
|
|
{
|
|
|
|
|
int messageType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct REPORT_PACKET_HEADER
|
|
|
|
|
{
|
|
|
|
|
int reportId;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-02 17:56:46 +02:00
|
|
|
|
public Message(byte[] buffer, int bufferSize, ILogger logger)
|
2023-09-02 15:47:15 +02:00
|
|
|
|
{
|
|
|
|
|
_buffer = buffer;
|
|
|
|
|
_bufferSize = bufferSize;
|
2023-09-02 17:56:46 +02:00
|
|
|
|
_logger = logger;
|
2023-09-02 15:47:15 +02:00
|
|
|
|
|
|
|
|
|
this.GetMessageType();
|
|
|
|
|
|
2023-09-02 17:56:46 +02:00
|
|
|
|
_logger.Information("Message type: {0}", _messageType);
|
|
|
|
|
|
2023-09-02 15:47:15 +02:00
|
|
|
|
switch (_messageType)
|
|
|
|
|
{
|
|
|
|
|
case (int)MESSAGE_TYPE.MESSAGE_TYPE_REPORT:
|
|
|
|
|
this.HandleReportMessage(this.GetReportType());
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2023-09-02 17:56:46 +02:00
|
|
|
|
_logger.Information("This message type is not accepted at the moment.");
|
2023-09-02 15:47:15 +02:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GetMessageType()
|
|
|
|
|
{
|
|
|
|
|
_messageType = BitConverter.ToInt32(_buffer, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int GetReportType()
|
|
|
|
|
{
|
|
|
|
|
return BitConverter.ToInt32(_buffer, sizeof(int));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void HandleReportMessage(int reportId)
|
|
|
|
|
{
|
2023-09-02 17:56:46 +02:00
|
|
|
|
_logger.Information("Report id: {0}", reportId);
|
|
|
|
|
|
|
|
|
|
var openHandleFailure = Helper.BytesToStructure<Types.Reports.OPEN_HANDLE_FAILURE_REPORT>(ref _buffer);
|
|
|
|
|
|
|
|
|
|
_logger.Information("Report code: {0}, ProcessID: {1:x}, ThreadId: {2:x}, DesiredAccess{3:x}",
|
|
|
|
|
openHandleFailure.ReportCode,
|
|
|
|
|
openHandleFailure.ProcessId,
|
|
|
|
|
openHandleFailure.ThreadId,
|
|
|
|
|
openHandleFailure.DesiredAccess);
|
|
|
|
|
|
2023-09-02 15:47:15 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|