-
22-02-2011, 09:19 AM #1Junior Member
- Ngày tham gia
- Sep 2015
- Đang ở
- Số 60 Thái Hà, Đống Đa, Hà Nội
- Bài viết
- 0
Cài đặt local hook keyboard lên 1 ứng dụng cụ thể khác như thế nào
Mình đọc hướng dẫn và tự làm hook
mình muốn ở 1 ứng dụng khác, khi ấn nút H thì sẽ có 1 message box hiện ra
nhưng ko được,
Mã:HHOOK hHook;LRESULT CALLBACK HookProc(int nCode,WPARAM wParam,LPARAM lParam){ if (nCode>=0&&nCode==HC_ACTION) { PMSG pMsg=(MSG*)lParam; if(pMsg->message==WM_KEYDOWN) { char ch=LOBYTE(wParam); if(ch=='h'||ch=='H') { MessageBox(HWND_DESKTOP,"Done","Thong bao",MB_OK); } } } return CallNextHookEx(hHook,nCode,wParam,lParam);}void SetHook(){ HWND hwnd=FindWindow("MainWindow","Plants vs. Zombies"); if (hwnd==NULL) { MessageBox(HWND_DESKTOP,"Start game fist","Thong bao",MB_OK); return; } DWORD dwThreadID=0; GetWindowThreadProcessId(hwnd,&dwThreadID); hHook=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)HookProc,hInst,dwThreadID);} ..... case WM_DESTROY: UnhookWindowsHookEx(hHook); PostQuitMessage(0); break;...............
View more random threads:
- Hàm native API NT CreateProcess
- chỉ dẫn phương pháp Hook APi bằng inline hook
- VC++ MFC, công cụ nào hỗ trợ tạo giao diện??
- Làm sao để hook khi đã có hWnd?
- SetWindowHookEx Và hàm Lọc Cùng trong DLL
- Có thể ghi file khi file đang chạy hay không?
- Làm sao hook API cho tất cả các tiến trình
- Mời tham gia tấn công Hark điểm game Diamond
- Chương trình sử dụng Socket IPC trên mạng LAN
- Hook Nhận biết cửa sổ Active hay không ?
-
22-02-2011, 02:18 PM #2Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Hồi trước mình tập hook cũng bị cái lỗi này:
Mã:PMSG pMsg=(MSG*)lParam;
Mã:if (nCode>=0&&nCode==HC_ACTION) { if(!(lParam>>31)) //Key down { char ch=LOBYTE(wParam); if(ch=='h'||ch=='H') { MessageBox(HWND_DESKTOP,"Done","Thong bao",MB_OK); } } }
Tham khảo thêm
http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
-
22-02-2011, 02:35 PM #3Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Thậm chí mình làm như này vẫn ko được
Mã:LRESULT CALLBACK QProc(int nCode,WPARAM wParam,LPARAM lParam){ MessageBox(HWND_DESKTOP,"Done","Thong bao",MB_OK); if (nCode>=0&&nCode==HC_ACTION) { if(!(lParam>>31)) //Key down { char ch=LOBYTE(wParam); if(ch=='h'||ch=='H') { MessageBox(HWND_DESKTOP,"Done","Thong bao",MB_OK); } } } return CallNextHookEx(hHook,nCode,wParam,lParam);}
Mã:// qmod.cpp : Defines the entry point for the application.// #include "stdafx.h"#include "resource.h" #define MAX_LOADSTRING 100 // Global Variables:HINSTANCE hInst; // current instanceTCHAR szTitle[MAX_LOADSTRING]; // The title bar textTCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text // Foward declarations of functions included in this code module:ATOM MyRegisterClass(HINSTANCE hInstance);BOOL InitInstance(HINSTANCE, int);LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM); //my functionvoid InfiniteSunPower(){ HWND hwnd=FindWindow("MainWindow","Plants vs. Zombies"); if (hwnd) { DWORD pid; GetWindowThreadProcessId(hwnd,&pid); HANDLE handle=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_OPERATION|PROCESS_VM_WRITE|PROCESS_VM_READ,FALSE,pid); unsigned char v[6]={0x90,0x90,0x90,0x90,0x90,0x90}; char *address=(char*)0x41BA76 ; WriteProcessMemory(handle,address,v,6,0); }}void AddSunPower(int n=200){ HWND hwnd=FindWindow("MainWindow","Plants vs. Zombies"); if (hwnd) { DWORD pid; GetWindowThreadProcessId(hwnd,&pid); HANDLE handle=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_OPERATION|PROCESS_VM_WRITE|PROCESS_VM_READ,FALSE,pid); char *address=(char*)0x6a9ec0; char *raddress; //lan 1 ReadProcessMemory(handle,address,&raddress,4,0); address=raddress+0x768; //lan 2 ReadProcessMemory(handle,address,&raddress,4,0); address=raddress+0x5560; int temp; ReadProcessMemory(handle,address,&temp,4,0); temp+=n; WriteProcessMemory(handle,address,&temp,4,0); }} void SetChargeRate(int n=20){ HWND hwnd=FindWindow("MainWindow","Plants vs. Zombies"); if (hwnd) { DWORD pid; GetWindowThreadProcessId(hwnd,&pid); HANDLE handle=OpenProcess(PROCESS_QUERY_INFORMATION|PROCESS_VM_OPERATION|PROCESS_VM_WRITE|PROCESS_VM_READ,FALSE,pid); if (n>250) n=250; else if (n<1) n=1; unsigned char v=(unsigned char)n; char *address=(char*)0x48728F ; WriteProcessMemory(handle,address,&v,1,0); }} HHOOK hHook;LRESULT CALLBACK QProc(int nCode,WPARAM wParam,LPARAM lParam){ MessageBox(HWND_DESKTOP,"Done","Thong bao",MB_OK); if (nCode>=0&&nCode==HC_ACTION) { if(!(lParam>>31)) //Key down { char ch=LOBYTE(wParam); if(ch=='h'||ch=='H') { MessageBox(HWND_DESKTOP,"Done","Thong bao",MB_OK); } } } return CallNextHookEx(hHook,nCode,wParam,lParam);}void SetHook(){ HWND hwnd=FindWindow("MainWindow","Plants vs. Zombies"); if (hwnd==NULL) { MessageBox(HWND_DESKTOP,"Start game fist","Thong bao",MB_OK); return; } DWORD dwThreadID=0; GetWindowThreadProcessId(hwnd,&dwThreadID); hHook=SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)QProc,hInst,dwThreadID);} int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ SetHook(); // TODO: Place code here. MSG msg; //HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_QMOD, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } //hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_QMOD); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam;} //// FUNCTION: MyRegisterClass()//// PURPOSE: Registers the window class.//// COMMENTS://// This function and its usage is only necessary if you want this code// to be compatible with Win32 systems prior to the 'RegisterClassEx'// function that was added to Windows 95. It is important to call this function// so that the application will get 'well formed' small icons associated// with it.//ATOM MyRegisterClass(HINSTANCE hInstance){ WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_QMOD); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = NULL; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); return RegisterClassEx(&wcex);} //// FUNCTION: InitInstance(HANDLE, int)//// PURPOSE: Saves instance handle and creates main window//// COMMENTS://// In this function, we save the instance handle in a global variable and// create and display the main program window.//BOOL InitInstance(HINSTANCE hInstance, int nCmdShow){ HWND hWnd; hInst = hInstance; // Store instance handle in our global variable hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, 100, 100, 300, 300, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } //SetLayeredWindowAttributes(hWnd,RGB(0,0,0),255/100*70,LWA_ALPHA); ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE;} //// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)//// PURPOSE: Processes messages for the main window.//// WM_COMMAND - process the application menu// WM_PAINT - Paint the main window// WM_DESTROY - post a quit message and return////LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; CHAR xau[100]; HFONT font; PLOGFONT plf; switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: //DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... RECT rt; GetClientRect(hWnd, &rt); SetBkMode(hdc,TRANSPARENT); plf=(PLOGFONT)LocalAlloc(LPTR, sizeof(LOGFONT)); lstrcpy(plf->lfFaceName, "Arial"); plf->lfWeight = FW_NORMAL; plf->lfHeight=26; font = CreateFontIndirect(plf); SelectObject(hdc,font); strcpy(xau,"Plants vs. Zombies Mod"); SetTextColor(hdc,RGB(255,0,0)); ExtTextOut(hdc,(rt.right-rt.left)/2-120,10,ETO_CLIPPED,&rt,xau,strlen(xau),NULL); lstrcpy(plf->lfFaceName, "Courier New"); plf->lfHeight=18; font = CreateFontIndirect(plf); SelectObject(hdc,font); SetTextColor(hdc,RGB(255,127,39)); strcpy(xau,"H - Infinite Sun Power "); ExtTextOut(hdc,15,50,ETO_CLIPPED,&rt,xau,strlen(xau),NULL); strcpy(xau,"I - Infinite Game Item"); ExtTextOut(hdc,15,70,ETO_CLIPPED,&rt,xau,strlen(xau),NULL); strcpy(xau,"G - Gaining Fast Combo"); ExtTextOut(hdc,15,90,ETO_CLIPPED,&rt,xau,strlen(xau),NULL); EndPaint(hWnd, &ps); LocalFree((LOCALHANDLE) plf); break; case WM_DESTROY: UnhookWindowsHookEx(hHook); PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0;}
-
23-02-2011, 09:50 AM #4Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
theo mình thì có thể cái hook vào nó anti oy
bạn thử cài hook dưới dạng global hook xem sao
ở box hướng dẫn có bài "hook dành cho người mới" bạn ý cài hook global được
-
24-02-2011, 05:31 PM #5Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
MFC có thể làm như sau (Peter lấy ví dụ như là Notepad chẳng hạn nhé, khi bạn nhấn phím vào đó (cửa sổ Edit) thì xuất hiện MessageBox thông báo "Thanh cong roi do!"):
- Lấy Handle cửa sổ đang Focus bằng hàm GetFocus(), đặt là h.
- Lấy Handle cửa sổ cha chứa cửa sổ nhận phím nhấn bằng hàm FindWindow(), đặt là h1 (Cửa sổ Notepad có title là "Untitled - Notepad").
- Lấy cửa sổ con nhận sự kiện nhấn phím bằng hàm FindWindowEx(), đặt là h2 (Chính là cửa sổ có Class name là "Edit", dùng Spy++ để check).
- So sánh h với h2, nếu bằng nhau và nhấn phím thì tạo MessageBox; còn ngược lại thì CallNextHookEx().
Vậy chúng ta có thể tạo một dll chứa hàm lọc phím LowLevelKeyboardProc(), code:
Mã:// Dll_Demo.cpp : Defines the entry point for the DLL application.// #include "windows.h"LRESULT _stdcall CALLBACK LowLevelKeyboardProc( int nCode, WPARAM wParam, LPARAM lParam ){ HWND h=GetFocus(); //Lay Handle cua so dang focus HWND h1=FindWindow(NULL,"Untitled - Notepad"); //Lay Handle cua so cha HWND h2=FindWindowEx(h1,0,"Edit",NULL); //Lay Handle cua so con nhan Su kien nhan phim if ((h==h2)&&((DWORD)lParam & 0x40000000) &&(HC_ACTION==nCode)) //Neu cua so Focus trung voi cua so nhan Su kien nhan phim { MessageBox(HWND_DESKTOP,"Thanh cong roi do!","Thong bao!",MB_OK); } LRESULT RetVal = CallNextHookEx( NULL, nCode, wParam, lParam ); return RetVal;}
Tiếp tục chúng ta set hook trong code exe như sau:
Mã:// Test_Demo.cpp : Defines the entry point for the application.// #include "stdafx.h"#include "resource.h" #define MAX_LOADSTRING 100HHOOK hhk;// Global Variables:HINSTANCE hInst; // current instanceTCHAR szTitle[MAX_LOADSTRING]; // The title bar textTCHAR szWindowClass[MAX_LOADSTRING]; // The title bar text // Foward declarations of functions included in this code module:ATOM MyRegisterClass(HINSTANCE hInstance);BOOL InitInstance(HINSTANCE, int);LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);LRESULT CALLBACK About(HWND, UINT, WPARAM, LPARAM); int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow){ // TODO: Place code here. //Thao tac truoc khi cai Hook typedef LRESULT (CALLBACK *ptr)(int, WPARAM,LPARAM); HINSTANCE Lib = LoadLibrary("Dll_Demo.dll"); ptr LowLevelKeyboardProc; if (Lib == NULL) { return 0; } //Lay address LowLevelKeyboardProc() LowLevelKeyboardProc = (ptr)GetProcAddress(Lib, "LowLevelKeyboardProc"); if (LowLevelKeyboardProc == NULL) { return 0; } //Lay Handle Dll_Demo.DLL HMODULE appInstance = GetModuleHandle("Dll_Demo.DLL"); //Cai Hook hhk=SetWindowsHookEx(WH_KEYBOARD, LowLevelKeyboardProc, appInstance, 0); MSG msg; HACCEL hAccelTable; // Initialize global strings LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING); LoadString(hInstance, IDC_TEST_DEMO, szWindowClass, MAX_LOADSTRING); MyRegisterClass(hInstance); // Perform application initialization: if (!InitInstance (hInstance, nCmdShow)) { return FALSE; } hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_TEST_DEMO); // Main message loop: while (GetMessage(&msg, NULL, 0, 0)) { if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam;} //// FUNCTION: MyRegisterClass()//// PURPOSE: Registers the window class.//// COMMENTS://// This function and its usage is only necessary if you want this code// to be compatible with Win32 systems prior to the 'RegisterClassEx'// function that was added to Windows 95. It is important to call this function// so that the application will get 'well formed' small icons associated// with it.//ATOM MyRegisterClass(HINSTANCE hInstance){ WNDCLASSEX wcex; wcex.cbSize = sizeof(WNDCLASSEX); wcex.style = CS_HREDRAW | CS_VREDRAW; wcex.lpfnWndProc = (WNDPROC)WndProc; wcex.cbClsExtra = 0; wcex.cbWndExtra = 0; wcex.hInstance = hInstance; wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_TEST_DEMO); wcex.hCursor = LoadCursor(NULL, IDC_ARROW); wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW+1); wcex.lpszMenuName = (LPCSTR)IDC_TEST_DEMO; wcex.lpszClassName = szWindowClass; wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL); return RegisterClassEx(&wcex);} //// FUNCTION: InitInstance(HANDLE, int)//// PURPOSE: Saves instance handle and creates main window//// COMMENTS://// In this function, we save the instance handle in a global variable and// create and display the main program window.//BOOL InitInstance(HINSTANCE hInstance, int nCmdShow){ HWND hWnd; hInst = hInstance; // Store instance handle in our global variable hWnd = CreateWindow(szWindowClass, szTitle, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL); if (!hWnd) { return FALSE; } ShowWindow(hWnd, nCmdShow); UpdateWindow(hWnd); return TRUE;} //// FUNCTION: WndProc(HWND, unsigned, WORD, LONG)//// PURPOSE: Processes messages for the main window.//// WM_COMMAND - process the application menu// WM_PAINT - Paint the main window// WM_DESTROY - post a quit message and return////LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam){ int wmId, wmEvent; PAINTSTRUCT ps; HDC hdc; TCHAR szHello[MAX_LOADSTRING]; LoadString(hInst, IDS_HELLO, szHello, MAX_LOADSTRING); switch (message) { case WM_COMMAND: wmId = LOWORD(wParam); wmEvent = HIWORD(wParam); // Parse the menu selections: switch (wmId) { case IDM_ABOUT: DialogBox(hInst, (LPCTSTR)IDD_ABOUTBOX, hWnd, (DLGPROC)About); break; case IDM_EXIT: DestroyWindow(hWnd); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } break; case WM_PAINT: hdc = BeginPaint(hWnd, &ps); // TODO: Add any drawing code here... RECT rt; GetClientRect(hWnd, &rt); DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER); EndPaint(hWnd, &ps); break; case WM_DESTROY: UnhookWindowsHookEx(hhk); PostQuitMessage(0); break; default: return DefWindowProc(hWnd, message, wParam, lParam); } return 0;} // Mesage handler for about box.LRESULT CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam){ switch (message) { case WM_INITDIALOG: return TRUE; case WM_COMMAND: if (LOWORD(wParam) == IDOK || LOWORD(wParam) == IDCANCEL) { EndDialog(hDlg, LOWORD(wParam)); return TRUE; } break; } return FALSE;}
Kết quả là mỗi khi nhấn phím trên Notepad thì chúng ta nhận được một thông báo! Have fun. Đây là code Demo:
p/s: Bạn có thể Hook mà không cần dll.
-
24-02-2011, 07:27 PM #6Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Gửi bởi peterdrew
cám ơn anh Peter, em rất thích cái ý tưởng của anh
ah, cho e hỏi với, e cũng mới tập hook, nhưng e chưa biết cài hook ko có dll như nào,
a có thể cho em 1 demo được ko à
cool cool
cám ơn anh
More : dạo này em bỏ VS2010, xài vc++6.0 portable, thấy nó hay vì nó đơn giản và nhẹ nhàng thích oy anh à
-
02-03-2011, 11:07 AM #7Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Anh có thể dùng idHook
WH_KEYBOARD_LL đối với bàn phím
WH_MOUSE_LL đối với chuột
Phạm vi của những ID này là Global không cần dll vẫn hook đc.
-
03-03-2011, 09:26 AM #8Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Gửi bởi tucute89
thảo nào
trong VC6.0 nó ko có cái này, phải tự định nghĩa thêm vào
#define WH_KEYBOARD_LL 13
#define WH_MOUSE_LL 14
-
03-03-2011, 11:34 AM #9Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Ai cho mình cái ví dụ đc. ko
-
03-03-2011, 11:36 AM #10Junior Member
- Ngày tham gia
- Sep 2015
- Bài viết
- 0
Gửi bởi Học Hỏi
Mình test trên VC++ 2010 -> Project Win32Console
Mã:#include "stdafx.h" //////////////////////////////////////////////////////////////////////////using namespace std; LRESULT CALLBACK LowLevelKeyboardProc(int nCode,WPARAM wParam,LPARAM lParam ){ if ( nCode == HC_ACTION && wParam == WM_KEYDOWN ){ PKBDLLHOOKSTRUCT pp = (PKBDLLHOOKSTRUCT)lParam; if( pp->scanCode == 28 ){ cout << " Vua An Enter ... " ; } } return CallNextHookEx(NULL,nCode,wParam,lParam);} //////////////////////////////////////////////////////////////////////////int _tmain(int argc, _TCHAR* argv[]){ HHOOK hHook = SetWindowsHookEx(WH_KEYBOARD_LL,LowLevelKeyboardProc,GetModuleHandle(0),0); if ( !hHook ) { cout << " Error: " << GetLastError(); return 0; } MSG msg; while( !GetMessage(&msg,NULL,0,0)){ DispatchMessage(&msg); TranslateMessage(&msg); } getch(); return 0;}
Hiện nay, có khá nhiều sản phẩm dương vật giả giá rẻ xuất hiện trên thị trường. Chúng đến từ các nhà sinh sản ở khắp nơi trên thế giới như Mỹ, Nhật, Hồng Kông…Hơn nữa, các đồ chơi này cũng khá đa...
Top một số dương vật giả rẻ và...