mirror-ac/user/client.cpp

77 lines
1.3 KiB
C++
Raw Normal View History

2023-08-18 07:33:13 +02:00
#include "client.h"
#include "common.h"
global::Client::Client( LPTSTR PipeName )
{
this->pipe_name = PipeName;
this->pipe_handle = CreateFile(
this->pipe_name,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
0,
NULL
);
if ( this->pipe_handle == INVALID_HANDLE_VALUE )
{
LOG_ERROR( "CreateFile failed with status 0x%x", GetLastError() );
return;
}
2023-08-18 16:34:15 +02:00
/* test the write function */
global::headers::PIPE_PACKET_HEADER header;
header.message_type = REQUEST_PATTERNS_TO_BE_SCANNED;
this->WriteToPipe( &header, sizeof( global::headers::PIPE_PACKET_HEADER ) );
2023-08-18 07:33:13 +02:00
}
2023-08-18 09:18:00 +02:00
void global::Client::WriteToPipe( PVOID Buffer, SIZE_T Size )
2023-08-18 07:33:13 +02:00
{
DWORD bytes_written;
WriteFile(
this->pipe_handle,
2023-08-18 09:18:00 +02:00
Buffer,
Size,
2023-08-18 07:33:13 +02:00
&bytes_written,
NULL
);
if ( bytes_written == 0 )
{
LOG_ERROR( "WriteFile failed with status code 0x%x", GetLastError() );
return;
}
2023-08-18 09:18:00 +02:00
LOG_INFO( "Sent bytes over pipe" );
2023-08-18 07:33:13 +02:00
}
2023-08-18 16:34:15 +02:00
void global::Client::ReadPipe(PVOID Buffer, SIZE_T Size)
{
BOOL status = FALSE;
DWORD bytes_read;
do
{
status = ReadFile(
this->pipe_handle,
Buffer,
Size,
&bytes_read,
NULL
);
if ( !status && GetLastError() != ERROR_MORE_DATA )
break;
} while ( !status );
if ( !status )
{
LOG_ERROR( "ReadFile failed with status 0x%x", GetLastError() );
return;
}
}