From f8226f6c90fa72aff88b5d058a02a475e8f2fbd6 Mon Sep 17 00:00:00 2001 From: psrok1 Date: Wed, 7 Aug 2024 19:45:33 +0200 Subject: [PATCH] Set higher baud rate of COM1 on connect --- drakshell/guest/drakshell.c | 17 +++++++++++ drakshell/guest/include/nt_loader.h | 45 +++++++++++++++++++++++++++++ drakshell/guest/nt_loader.c | 4 +++ 3 files changed, 66 insertions(+) diff --git a/drakshell/guest/drakshell.c b/drakshell/guest/drakshell.c index 4f475559..88efc279 100644 --- a/drakshell/guest/drakshell.c +++ b/drakshell/guest/drakshell.c @@ -225,6 +225,8 @@ static bool req_download_file(HANDLE hComm) } void __attribute__((noinline)) __attribute__((force_align_arg_pointer)) drakshell_main() { + DCB dcb = { .DCBlength = sizeof(DCB) }; + if(!load_winapi()) { // Failed to load some WinAPI functions return; @@ -249,6 +251,21 @@ void __attribute__((noinline)) __attribute__((force_align_arg_pointer)) drakshel return; } + if(!GetCommState(hComm, &dcb)) + { + OutputDebugStringW(L"Failed to get mode of COM1"); + return; + } + + dcb.BaudRate = 115200; + dcb.fParity = false; + + if(!SetCommState(hComm, &dcb)) + { + OutputDebugStringW(L"Failed to set mode of COM1"); + return; + } + OutputDebugStringW(L"I'm connected"); while(true) { diff --git a/drakshell/guest/include/nt_loader.h b/drakshell/guest/include/nt_loader.h index 2bfefd9d..aff9f45b 100644 --- a/drakshell/guest/include/nt_loader.h +++ b/drakshell/guest/include/nt_loader.h @@ -42,6 +42,37 @@ typedef char* LPSTR; typedef wchar_t* LPWSTR; typedef bool BOOL; +typedef struct _DCB { + DWORD DCBlength; + DWORD BaudRate; + DWORD fBinary : 1; + DWORD fParity : 1; + DWORD fOutxCtsFlow : 1; + DWORD fOutxDsrFlow : 1; + DWORD fDtrControl : 2; + DWORD fDsrSensitivity : 1; + DWORD fTXContinueOnXoff : 1; + DWORD fOutX : 1; + DWORD fInX : 1; + DWORD fErrorChar : 1; + DWORD fNull : 1; + DWORD fRtsControl : 2; + DWORD fAbortOnError : 1; + DWORD fDummy2 : 17; + WORD wReserved; + WORD XonLim; + WORD XoffLim; + BYTE ByteSize; + BYTE Parity; + BYTE StopBits; + char XonChar; + char XoffChar; + char ErrorChar; + char EofChar; + char EvtChar; + WORD wReserved1; +} DCB, *LPDCB; + #define WINAPI __attribute__((ms_abi)) typedef int (WINAPI* PCreateThread)( @@ -149,5 +180,19 @@ typedef DWORD (WINAPI* PGetLastError)(); extern PGetLastError pGetLastError; #define GetLastError (*pGetLastError) +typedef BOOL (WINAPI* PGetCommState)( + HANDLE hFile, + LPDCB lpDCB +); +extern PGetCommState pGetCommState; +#define GetCommState (*pGetCommState) + +typedef BOOL (WINAPI* PSetCommState)( + HANDLE hFile, + LPDCB lpDCB +); +extern PSetCommState pSetCommState; +#define SetCommState (*pSetCommState) + extern void* get_func_from_peb(const wchar_t* libraryName, const char* procName); extern bool load_winapi(); \ No newline at end of file diff --git a/drakshell/guest/nt_loader.c b/drakshell/guest/nt_loader.c index c5a239bc..b72a961f 100644 --- a/drakshell/guest/nt_loader.c +++ b/drakshell/guest/nt_loader.c @@ -218,6 +218,8 @@ PExitThread pExitThread; PSleep pSleep; PVirtualFree pVirtualFree; PGetLastError pGetLastError; +PGetCommState pGetCommState; +PSetCommState pSetCommState; bool load_winapi() { HANDLE hKernel32, hUser32; @@ -244,6 +246,8 @@ bool load_winapi() { pSleep = GetProcAddress(hKernel32, "Sleep"); pVirtualFree = GetProcAddress(hKernel32, "VirtualFree"); pGetLastError = GetProcAddress(hKernel32, "GetLastError"); + pGetCommState = GetProcAddress(hKernel32, "GetCommState"); + pSetCommState = GetProcAddress(hKernel32, "SetCommState"); return true; } \ No newline at end of file