Skip to content

Commit

Permalink
Flush INPUT_RECORD objects prior to SendMessage/GenerateConsoleCtrlEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
rprichard authored and zacps committed Nov 23, 2018
1 parent 472b77f commit 61c62d7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/agent/ConsoleInput.cc
Original file line number Diff line number Diff line change
Expand Up @@ -343,12 +343,19 @@ void ConsoleInput::doWrite(bool isEof)
idx += charSize;
}
m_byteQueue.erase(0, idx);
flushInputRecords(records);
}

void ConsoleInput::flushInputRecords(std::vector<INPUT_RECORD> &records)
{
if (records.size() == 0) {
return;
}
DWORD actual = 0;
if (records.size() > 0) {
if (!WriteConsoleInputW(m_conin, records.data(), records.size(), &actual)) {
trace("WriteConsoleInputW failed");
}
if (!WriteConsoleInputW(m_conin, records.data(), records.size(), &actual)) {
trace("WriteConsoleInputW failed");
}
records.clear();
}

int ConsoleInput::scanInput(std::vector<INPUT_RECORD> &records,
Expand All @@ -360,6 +367,7 @@ int ConsoleInput::scanInput(std::vector<INPUT_RECORD> &records,

// Ctrl-C.
if (input[0] == '\x03' && (inputConsoleMode() & ENABLE_PROCESSED_INPUT)) {
flushInputRecords(records);
trace("Ctrl-C");
BOOL ret = GenerateConsoleCtrlEvent(CTRL_C_EVENT, 0);
trace("GenerateConsoleCtrlEvent: %d", ret);
Expand Down Expand Up @@ -652,6 +660,7 @@ void ConsoleInput::appendKeyPress(std::vector<INPUT_RECORD> &records,
virtualKey == VK_HOME ||
virtualKey == VK_END) &&
!ctrl && !leftAlt && !rightAlt && !shift) {
flushInputRecords(records);
if (hasDebugInput) {
trace("sending keypress to console HWND");
}
Expand Down
1 change: 1 addition & 0 deletions src/agent/ConsoleInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ConsoleInput

private:
void doWrite(bool isEof);
void flushInputRecords(std::vector<INPUT_RECORD> &records);
int scanInput(std::vector<INPUT_RECORD> &records,
const char *input,
int inputSize,
Expand Down

0 comments on commit 61c62d7

Please sign in to comment.