Skip to content

Commit

Permalink
Set higher baud rate of COM1 on connect
Browse files Browse the repository at this point in the history
  • Loading branch information
psrok1 committed Aug 7, 2024
1 parent 7636df0 commit f8226f6
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
17 changes: 17 additions & 0 deletions drakshell/guest/drakshell.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
45 changes: 45 additions & 0 deletions drakshell/guest/include/nt_loader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)(
Expand Down Expand Up @@ -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();
4 changes: 4 additions & 0 deletions drakshell/guest/nt_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ PExitThread pExitThread;
PSleep pSleep;
PVirtualFree pVirtualFree;
PGetLastError pGetLastError;
PGetCommState pGetCommState;
PSetCommState pSetCommState;

bool load_winapi() {
HANDLE hKernel32, hUser32;
Expand All @@ -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;
}

0 comments on commit f8226f6

Please sign in to comment.