diff --git a/server/2015Remote/2015Remote.rc b/server/2015Remote/2015Remote.rc index 7628f01..7964de0 100644 Binary files a/server/2015Remote/2015Remote.rc and b/server/2015Remote/2015Remote.rc differ diff --git a/server/2015Remote/2015RemoteDlg.cpp b/server/2015Remote/2015RemoteDlg.cpp index 997cbe2..f804d8d 100644 --- a/server/2015Remote/2015RemoteDlg.cpp +++ b/server/2015Remote/2015RemoteDlg.cpp @@ -1041,6 +1041,13 @@ VOID CMy2015RemoteDlg::MessageHandle(CONTEXT_OBJECT* ContextObject) { switch (ContextObject->InDeCompressedBuffer.GetBYTE(0)) { + case SOCKET_DLLLOADER: {// 请求DLL + BYTE cmd[32] = { COMMAND_BYE }; + const char reason[] = "请求不支持, 主控命令其退出!"; + memcpy(cmd + 1, reason, sizeof(reason)); + m_iocpServer->Send(ContextObject, cmd, sizeof(cmd)); + break; + } case COMMAND_BYE: { CancelIo((HANDLE)ContextObject->sClientSocket); diff --git a/server/2015Remote/ShellDlg.cpp b/server/2015Remote/ShellDlg.cpp index 26ddfeb..9b1eb15 100644 --- a/server/2015Remote/ShellDlg.cpp +++ b/server/2015Remote/ShellDlg.cpp @@ -6,6 +6,18 @@ #include "ShellDlg.h" #include "afxdialogex.h" +BEGIN_MESSAGE_MAP(CAutoEndEdit, CEdit) + ON_WM_CHAR() +END_MESSAGE_MAP() + +void CAutoEndEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { + // 将光标移动到文本末尾 + int nLength = GetWindowTextLength(); + SetSel(nLength, nLength); + + // 调用父类处理输入字符 + CEdit::OnChar(nChar, nRepCnt, nFlags); +} // CShellDlg 对话框 @@ -34,6 +46,7 @@ void CShellDlg::DoDataExchange(CDataExchange* pDX) BEGIN_MESSAGE_MAP(CShellDlg, CDialog) ON_WM_CLOSE() ON_WM_CTLCOLOR() + ON_WM_SIZE() END_MESSAGE_MAP() @@ -59,6 +72,12 @@ BOOL CShellDlg::OnInitDialog() BYTE bToken = COMMAND_NEXT; m_iocpServer->OnClientPreSending(m_ContextObject, &bToken, sizeof(BYTE)); + m_Edit.SetWindowTextA(">>"); + m_nCurSel = m_Edit.GetWindowTextLengthA(); + m_nReceiveLength = m_nCurSel; + m_Edit.SetSel((int)m_nCurSel, (int)m_nCurSel); + m_Edit.PostMessage(EM_SETSEL, m_nCurSel, m_nCurSel); + return TRUE; // return TRUE unless you set the focus to a control // 异常: OCX 属性页应返回 FALSE } @@ -76,6 +95,12 @@ VOID CShellDlg::OnReceiveComplete() } +#include +std::string removeAnsiCodes(const std::string& input) { + std::regex ansi_regex("\x1B\\[[0-9;]*[mK]"); + return std::regex_replace(input, ansi_regex, ""); +} + VOID CShellDlg::AddKeyBoardData(void) { // 最后填上0 @@ -84,7 +109,8 @@ VOID CShellDlg::AddKeyBoardData(void) //Shit\0 m_ContextObject->InDeCompressedBuffer.WriteBuffer((LPBYTE)"", 1); //从被控制端来的数据我们要加上一个\0 Buffer tmp = m_ContextObject->InDeCompressedBuffer.GetMyBuffer(0); - CString strResult = tmp.c_str(); //获得所有的数据 包括 \0 + bool firstRecv = tmp.c_str() == std::string(">"); + CString strResult = firstRecv ? "" : CString("\r\n") + removeAnsiCodes(tmp.c_str()).c_str(); //获得所有的数据 包括 \0 //替换掉原来的换行符 可能cmd 的换行同w32下的编辑控件的换行符不一致 所有的回车换行 strResult.Replace("\n", "\r\n"); @@ -146,15 +172,14 @@ BOOL CShellDlg::PreTranslateMessage(MSG* pMsg) //然后将数据发送出去 LPBYTE pSrc = (LPBYTE)str.GetBuffer(0) + m_nCurSel; #ifdef _DEBUG - OutputDebugStringA("[Shell]=> "); - OutputDebugStringA((char*)pSrc); + TRACE("[Shell]=> %s", (char*)pSrc); #endif int length = str.GetLength() - m_nCurSel; m_iocpServer->OnClientPreSending(m_ContextObject, pSrc, length); m_nCurSel = m_Edit.GetWindowTextLength(); if (0 == strcmp((char*)pSrc, "exit\r\n")) { - ShowWindow(SW_HIDE); + return PostMessage(WM_CLOSE); } } // 限制VK_BACK @@ -190,3 +215,19 @@ HBRUSH CShellDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) } return hbr; } + + +void CShellDlg::OnSize(UINT nType, int cx, int cy) +{ + CDialog::OnSize(nType, cx, cy); + + if (!m_Edit.GetSafeHwnd()) return; // 确保控件已创建 + + // 计算新位置和大小 + CRect rc; + m_Edit.GetWindowRect(&rc); + ScreenToClient(&rc); + + // 重新设置控件大小 + m_Edit.MoveWindow(0, 0, cx, cy, TRUE); +} diff --git a/server/2015Remote/ShellDlg.h b/server/2015Remote/ShellDlg.h index d3f5a41..5a2348d 100644 --- a/server/2015Remote/ShellDlg.h +++ b/server/2015Remote/ShellDlg.h @@ -2,6 +2,14 @@ #include "IOCPServer.h" #include "afxwin.h" +// 无论光标位置在哪,新输入的文字总是出现在文本末尾 +class CAutoEndEdit : public CEdit { +public: + afx_msg void OnChar(UINT nChar, UINT nRepCnt, UINT nFlags); + DECLARE_MESSAGE_MAP() +}; + + // CShellDlg 对话框 class CShellDlg : public CDialog @@ -29,7 +37,8 @@ protected: public: virtual BOOL OnInitDialog(); afx_msg void OnClose(); - CEdit m_Edit; + CAutoEndEdit m_Edit; virtual BOOL PreTranslateMessage(MSG* pMsg); afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor); + afx_msg void OnSize(UINT nType, int cx, int cy); };