Repository: microsoft/terminal
File: src/terminal/parser/InputStateMachineEngine.cpp (C++)

Code before:
    // VT52 escape sequences are not used in the input state machine.
    return false;
}

// Method Description:
// - Triggers the CsiDispatch action to indicate that the listener should handle
//      a control sequence. These sequences perform various API-type commands
//      that can include many parameters.
// Arguments:
// - id - Identifier of the control sequence to dispatch.
// - parameters - set of numeric parameters collected while parsing the sequence.
// Return Value:
// - true iff we successfully dispatched the sequence.
bool InputStateMachineEngine::ActionCsiDispatch(const VTID id, const VTParameters parameters)
{
    // GH#4999 - If the client was in VT input mode, but we received a
    // win32-input-mode sequence, then _don't_ passthrough the sequence to the
    // client. It's impossibly unlikely that the client actually wanted
    // win32-input-mode, and if they did, then we'll just translate the
    // INPUT_RECORD back to the same sequence we say here later on, when the
    // client reads it.
    if (_pDispatch->IsVtInputEnabled() &&
        _pfnFlushToInputQueue &&
        id != CsiActionCodes::Win32KeyboardInput &&
        id != CsiActionCodes::FocusIn &&
        id != CsiActionCodes::FocusOut)
    {
        return _pfnFlushToInputQueue();
    }

    DWORD modifierState = 0;
    short vkey = 0;

    bool success = false;
    switch (id)
    {
    case CsiActionCodes::MouseDown:
    case CsiActionCodes::MouseUp:
    {
        DWORD buttonState = 0;
        DWORD eventFlags = 0;
        const size_t firstParameter = parameters.at(0).value_or(0);
        const til::point uiPos{ gsl::narrow_cast<til::CoordType>(parameters.at(1) - 1), gsl::narrow_cast<til::CoordType>(parameters.at(2) - 1) };

        modifierState = _GetSGRMouseModifierState(firstParameter);
        success = _UpdateSGRMouseButtonState(id, firstParameter, buttonState, eventFlags, uiPos);
        success = success && _WriteMouseEvent(uiPos, buttonState, modifierState, eventFlags);
        break;
    }
    // case CsiActionCodes::DSR_DeviceStatusReportResponse:
    case CsiActionCodes::CSI_F3:

Review comment (suggestion):
I'm assuming this filter is due to malicious.exe?
Could you copy the PR description here? This seems rather important to document in code.
(Well most things "should" be documented in code, but this one in particular sounds very important.)

Code after:
    // VT52 escape sequences are not used in the input state machine.
    return false;
}

// Method Description:
// - Triggers the CsiDispatch action to indicate that the listener should handle
//      a control sequence. These sequences perform various API-type commands
//      that can include many parameters.
// Arguments:
// - id - Identifier of the control sequence to dispatch.
// - parameters - set of numeric parameters collected while parsing the sequence.
// Return Value:
// - true iff we successfully dispatched the sequence.
bool InputStateMachineEngine::ActionCsiDispatch(const VTID id, const VTParameters parameters)
{
    // GH#4999 - If the client was in VT input mode, but we received a
    // win32-input-mode sequence, then _don't_ passthrough the sequence to the
    // client. It's impossibly unlikely that the client actually wanted
    // win32-input-mode, and if they did, then we'll just translate the
    // INPUT_RECORD back to the same sequence we say here later on, when the
    // client reads it.
    //
    // Focus events in conpty are special, so don't flush those through either.
    // See GH#12799, GH#12900 for details
    if (_pDispatch->IsVtInputEnabled() &&
        _pfnFlushToInputQueue &&
        id != CsiActionCodes::Win32KeyboardInput &&
        id != CsiActionCodes::FocusIn &&
        id != CsiActionCodes::FocusOut)
    {
        return _pfnFlushToInputQueue();
    }

    DWORD modifierState = 0;
    short vkey = 0;

    bool success = false;
    switch (id)
    {
    case CsiActionCodes::MouseDown:
    case CsiActionCodes::MouseUp:
    {
        DWORD buttonState = 0;
        DWORD eventFlags = 0;
        const size_t firstParameter = parameters.at(0).value_or(0);
        const til::point uiPos{ gsl::narrow_cast<til::CoordType>(parameters.at(1) - 1), gsl::narrow_cast<til::CoordType>(parameters.at(2) - 1) };

        modifierState = _GetSGRMouseModifierState(firstParameter);
        success = _UpdateSGRMouseButtonState(id, firstParameter, buttonState, eventFlags, uiPos);
        success = success && _WriteMouseEvent(uiPos, buttonState, modifierState, eventFlags);
        break;