Chào mừng đến với Diễn đàn lập trình - Cộng đồng lập trình.
Kết quả 1 đến 10 của 10
  1. #1
    Ngày tham gia
    Sep 2015
    Bài viết
    0

    Tại sao hook rồi tắt mở lại mới nhận được dữ liệu Postmessage

    Dùng dll hook vào một chương trình khác. tạo NewWndProc, và đăng ký RegisterWindowMessage(L"WM_HOOK_WRITE"); tở dùng PostMessage gởi dữ liệu tới hook. Nhưng hook lần đầu thì không nhận dữ liệu. Tắt rồi bật lại hook thì nhận được tại sao thế.

    File hook.cpp:
    Mã:
    // hook.cpp : Defines the exported functions for the DLL application.
    //
    
    #include "stdafx.h"
    #include "hook.h"
    #include "KTClient.h"
    
    const UINT WM_HOOK_WRITE = RegisterWindowMessage(L"WM_HOOK_WRITE");
    const UINT WM_HOOKEX = RegisterWindowMessage(L"WM_HOOKEX_RK");
    #define WM_FEEDBACK WM_USER + 100
    #define SHIFTED 0x8000;
    
    HINSTANCE hDll;
    WNDPROC OldWndProc = NULL;
    LRESULT CALLBACK NewWndProc(HWND, UINT, WPARAM, LPARAM);
    VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime);
    
    UINT_PTR nTimerID = 0;
    BOOL bHooked = FALSE;
    
    KTClient theClient;
    
    BOOL APIENTRY DllMain( HMODULE hModule,
    					  DWORD  ul_reason_for_call,
    					  LPVOID lpReserved
    					  )
    {
    	switch (ul_reason_for_call)
    	{
    	case DLL_PROCESS_ATTACH:
    		hDll = (HINSTANCE)hModule;
    		DisableThreadLibraryCalls(hDll);
    		break;
    	case DLL_THREAD_ATTACH:
    	case DLL_THREAD_DETACH:
    	case DLL_PROCESS_DETACH:
    		break;
    	}
    	return TRUE;
    }
    
    #define pCW ((CWPSTRUCT*)lParam)
    LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam)
    {
    	HWND hVLWnd = pCW->hwnd;
    	HHOOK hHook = (HHOOK)pCW->wParam;
    	if ((pCW->message == WM_HOOKEX) && pCW->lParam)
    	{	//Inject Dll
    		//MessageBox(HWND_DESKTOP, L"Case 1", L"Dang lam", MB_OK);
    		UnhookWindowsHookEx(hHook);
    		if (bHooked)
    			goto END;
    		char lib_name[MAX_PATH];
    		GetModuleFileName(hDll, (LPWCH)lib_name, MAX_PATH);
    		if (!LoadLibrary((LPCTSTR)lib_name))
    			goto END;
    		OldWndProc = (WNDPROC)SetWindowLong(hVLWnd, GWL_WNDPROC, (LONG)NewWndProc);
    		if (OldWndProc == NULL)
    		{
    			FreeLibrary(hDll);
    		}
    		else
    		{
    			bHooked = TRUE;
    			theClient.AttachWindow(hVLWnd);
    			nTimerID = SetTimer(NULL, NULL, 100, (TIMERPROC)TimerProc);
    		}
    	}
    	else if (pCW->message == WM_HOOKEX)
    	{	//Unmap Dll
    		//MessageBox(HWND_DESKTOP, L"Case 2", L"Dang lam", MB_OK);
    		UnhookWindowsHookEx(hHook);
    		if (!bHooked)
    			goto END;
    		if (!SetWindowLong(hVLWnd, GWL_WNDPROC, (LONG)OldWndProc))
    			goto END;
    		FreeLibrary(hDll);
    		if (nTimerID)
    			KillTimer(NULL, nTimerID);
    		//theClient.SetAutoHit(0);
    		bHooked = FALSE;
    	}
    END:
    	return CallNextHookEx(hHook, nCode, wParam, lParam);
    }
    LRESULT CALLBACK NewWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
    {
    	if (uMsg == WM_HOOK_WRITE)
    	{
    		//Setting Parameters
    		switch (wParam)
    		{
    		case 1:
    			theClient.m_1 = (BOOL)lParam;
    			break;
    		case 2:
    			theClient.m_2 = (BOOL)lParam;
    			break;
    		case 3:
    			theClient.m_3 = (BOOL)lParam;
    			break;
    		case 4:
    			theClient.m_4 = (BOOL)lParam;
    			break;
    		case 5:
    			theClient.m_5 = (BOOL)lParam;
    			break;
    		case 6:
    			theClient.m_6 = (BOOL)lParam;
    			break;
    		case 7:
    			theClient.m_7 = (BOOL)lParam;
    			break;
    		case 8:
    			theClient.m_8 = (BOOL)lParam;
    			break;
    		case 9:
    			theClient.m_9 = (BOOL)lParam;
    			break;
    		case 0:
    			theClient.m_0 = (BOOL)lParam;
    			break;
    		case 11:
    			theClient.m_F1 = (BOOL)lParam;
    			break;
    		case 12:
    			theClient.m_F2 = (BOOL)lParam;
    			break;
    		case 13:
    			theClient.m_F3 = (BOOL)lParam;
    			break;
    		case 14:
    			theClient.m_F4 = (BOOL)lParam;
    			break;
    		case 15:
    			theClient.m_F5 = (BOOL)lParam;
    			break;
    		case 16:
    			theClient.m_F6 = (BOOL)lParam;
    			break;
    		case 17:
    			theClient.m_F7 = (BOOL)lParam;
    			break;
    		case 18:
    			theClient.m_F8 = (BOOL)lParam;
    			break;
    
    		case 21:
    			theClient.m_n1 = (UINT)lParam;
    			break;
    		case 22:
    			theClient.m_n2 = (UINT)lParam;
    			break;
    		case 23:
    			theClient.m_n3 = (UINT)lParam;
    			break;
    		case 24:
    			theClient.m_n4 = (UINT)lParam;
    			break;
    		case 25:
    			theClient.m_n5 = (UINT)lParam;
    			break;
    		case 26:
    			theClient.m_n6 = (UINT)lParam;
    			break;
    		case 27:
    			theClient.m_n7 = (UINT)lParam;
    			break;
    		case 28:
    			theClient.m_n8 = (UINT)lParam;
    			break;
    		case 29:
    			theClient.m_n9 = (UINT)lParam;
    			break;
    		case 20:
    			theClient.m_n0 = (UINT)lParam;
    			break;
    		case 31:
    			theClient.m_nF1 = (UINT)lParam;
    			break;
    		case 32:
    			theClient.m_nF2 = (UINT)lParam;
    			break;
    		case 33:
    			theClient.m_nF3 = (UINT)lParam;
    			break;
    		case 34:
    			theClient.m_nF4 = (UINT)lParam;
    			break;
    		case 35:
    			theClient.m_nF5 = (UINT)lParam;
    			break;
    		case 36:
    			theClient.m_nF6 = (UINT)lParam;
    			break;
    		case 37:
    			theClient.m_nF7 = (UINT)lParam;
    			break;
    		case 38:
    			theClient.m_nF8 = (UINT)lParam;
    			break;
    
    		//case 40:
    			//MessageBox(HWND_DESKTOP, (LPCTSTR)lParam, L"", MB_OK);
    			//break;
    	//	case cmd_minhp:
    	//		theClient.m_nMinHP = lParam;
    	//		break;
    	//	case cmd_automp:
    	//		theClient.m_bAutoMP = lParam;
    	//		break;
    	//	case cmd_minmp:
    	//		theClient.m_nMinMP = lParam;
    	//		break;
    	//	case cmd_autoam:
    	//		theClient.m_bAutoAM = lParam;
    	//		break;
    	//	case cmd_minam:
    	//		theClient.m_nMinAM = lParam;
    	//		break;
    	//	case cmd_autohit:
    	//		theClient.SetAutoHit(lParam);
    	//		break;
    	//	case cmd_searchrange:
    	//		theClient.m_nSearchRange = lParam;
    	//		break;
    	//	case cmd_hitlimit:
    	//		theClient.SetHitLimit(lParam);
    	//		break;
    	//	case cmd_hitrange:
    	//		theClient.m_nHitRange = lParam;
    	//		break;
    	//	case cmd_hitclose:
    	//		theClient.m_bHitClosed = lParam;
    	//		break;
    	//	case cmd_skillradius:
    	//		theClient.m_nSkillRadius = (lParam>64)?lParam:64;
    	//		break;
    	//	case cmd_collect:
    	//		theClient.m_nAutoObj = lParam;
    	//		break;
    	//	case cmd_sendhwnd:
    	//		theClient.m_hWndServer = (HWND)lParam;
    	//		break;
    		}
    		return 0;
    	}
    	return CallWindowProc(OldWndProc, hWnd, uMsg, wParam, lParam);
    }
    
    VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
    {
    	//static UINT nUsingTimer = 0;
    	/UsingTimer++;
    	//After 2s and each minutes
    	//if (nUsingTimer%600==20)
    	//	theClient.CheckEquip(); //Kiem tra do hu hong
    	//MessageBox(HWND_DESKTOP, L"Day ne", L"Duoc ko", MB_OK);
    
    	theClient.CheckStatus();
    	theClient.SearchAttack();
    }
    int InjectDll(HWND hWnd)
    {
    	if (!IsWindow(hWnd))
    		return 0;
    	HHOOK hHook = SetWindowsHookEx(WH_CALLWNDPROC,(HOOKPROC)HookProc, hDll, GetWindowThreadProcessId(hWnd,NULL));
    	if (hHook == NULL)
    		return 0;
    	SendMessage(hWnd, WM_HOOKEX, WPARAM(hHook), 1);
    	return 1;
    }
    int UnmapDll(HWND hWnd)
    {
    	if (!IsWindow(hWnd))
    		return 0;
    	HHOOK hHook = SetWindowsHookEx(WH_CALLWNDPROC,(HOOKPROC)HookProc, hDll, GetWindowThreadProcessId(hWnd,NULL));
    	if (hHook == NULL)
    		return 0;
    	SendMessage(hWnd, WM_HOOKEX, (WPARAM)hHook, 0);
    	return 1;
    }
    File main:
    Mã:
    ...
    const UINT WM_HOOK_WRITE = RegisterWindowMessage(L"WM_HOOK_WRITE");
    ...
    ::PostMessage(hWnd, WM_HOOK_WRITE, 1, ktParam.b1);
    ::PostMessage(hWnd, WM_HOOK_WRITE, 2, ktParam.b2);
    ::PostMessage(hWnd, WM_HOOK_WRITE, 3, ktParam.b3);
    ::PostMessage(hWnd, WM_HOOK_WRITE, 4, ktParam.b4);
    ::PostMessage(hWnd, WM_HOOK_WRITE, 5, ktParam.b5);

  2. #2
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Hook này kỳ lạ thế nhỉ? Code đâu rồi, post thử xem có giúp được gì không?

  3. #3
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    đó là mã nguồn của ngocnl viết cho VLTK áp dụng vô cho game TLBB hay các game khác cũng được.

    Nhân tiện hỏi thêm tí. Chương trình của tớ khi debug chạy không có lỗi hay warning nào cả. Nhưng khi thoát chương trình thì hiện bảng thông báo lỗi như sau. Ai biết chỉ giùm.
    Mã:
    Debug Assertion Failed!
    
    File:..cmdtarg.cpp
    Line: 43
    For ìnormation on how your program can cause assertion failure, see Visual C== documentation on asserts.
    
    (Press Retry to debug the application)

  4. #4
    Trích dẫn Gửi bởi theboy909
    đó là mã nguồn của ngocnl viết cho VLTK áp dụng vô cho game TLBB hay các game khác cũng được.
    Mình đang viết auto Kiếm Thế. Để trao đổi dữ liệu giữa 2 process mình sử dụng WM_COPYDATA hoặc SendMessage + ReadProcessMemory chứ không làm giống ngocnl. Như vậy có thể trao đổi một lúc bao nhiêu dữ liệu tùy thích [IMG]images/smilies/smile.png[/IMG].
    Còn về lỗi assert, bạn mở file cmdtarg.cpp, đến dòng 43 xem dòng đó là gì? Có dạng assert(.....);

  5. #5
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Mã:
    case DLL_PROCESS_ATTACH:
    		hDll = (HINSTANCE)hModule;
    		DisableThreadLibraryCalls(hDll);
                    WM_HOOK_WRITE = RegisterWindowMessage(L"WM_HOOK_WRITE");
    Bạn thử chuyển dòng lệnh RegisterWindowMessage vào trong hàm DllMain như trên xem sao.
    Bạn viết auto Kiếm Thế à?

  6. #6
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    bài này bạn theboy909 hỏi bên VVN rồi mà

    cái hiện tượng là bạn thấy con số 17C92B24 thôi, cái chính bạn phải reverse xem hàm đó mục đích cụ thể là làm gì , lúc ấy haỹ code, cứ xem con số thế này thì ko tổng quát đâu, mỗi máy, mỗi win sẽ là 1 số khác nhau thì sao .

    P/s : Cheat Engine à

  7. #7
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Xem dòng đó là gì rồi sao nữa?

    Mã:
    CCmdTarget::~CCmdTarget()
    {
    #ifndef _AFX_NO_OLE_SUPPORT
    	if (m_xDispatch.m_vtbl != 0)
    		((COleDispatchImpl*)&m_xDispatch)->Disconnect();
    	ASSERT(m_dwRef <= 1);
    #endif
    	m_pModuleState = NULL;
    }
    Tìm trên mạnh thì được cái này

    I had the same problem.

    Seemed to be a problem with different versions of MFC (actually, there were completely different includes in my files, one was standard win32, the other one AFX/MFC) in different stdafx.h files I was using in a project combined from 2 other projects.

    I reduced to one, the error disappeared. Maybe it helps you.

    In case someone else needs this info: the assertion occured here:

    Mã:
    CCmdTarget::~CCmdTarget()
     {
    #ifndef _AFX_NO_OLE_SUPPORT
     	if (m_xDispatch.m_vtbl != 0)
      		((COleDispatchImpl*)&m_xDispatch)->Disconnect();
      	ASSERT(m_dwRef <= 1);
     #endif 
     	m_pModuleState = NULL;
    }
    Nếu như vậy tại sao bây giờ mới bị vì lúc trước chạy bình thường. VS có khả năng tự động thay đổi stdafx.h à.
    File stdafx.h trong Main:
    Mã:
    #pragma once
    
    #ifndef _SECURE_ATL
    #define _SECURE_ATL 1
    #endif
    
    #ifndef VC_EXTRALEAN
    #define VC_EXTRALEAN            // Exclude rarely-used stuff from Windows headers
    #endif
    
    #include "targetver.h"
    
    #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS      // some CString constructors will be explicit
    
    // turns off MFC's hiding of some common and often safely ignored warning messages
    #define _AFX_ALL_WARNINGS
    
    #include <afxwin.h>         // MFC core and standard components
    #include <afxext.h>         // MFC extensions
    
    
    #include <afxdisp.h>        // MFC Automation classes
    
    
    
    #ifndef _AFX_NO_OLE_SUPPORT
    #include <afxdtctl.h>           // MFC support for Internet Explorer 4 Common Controls
    #endif
    #ifndef _AFX_NO_AFXCMN_SUPPORT
    #include <afxcmn.h>                     // MFC support for Windows Common Controls
    #endif // _AFX_NO_AFXCMN_SUPPORT
    
    
    
    
    
    
    
    
    
    #ifdef _UNICODE
    #if defined _M_IX86
    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #elif defined _M_IA64
    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='ia64' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #elif defined _M_X64
    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #else
    #pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
    #endif
    #endif
    File stdafx.h trong hook
    Mã:
    #pragma once
    
    #ifndef WINVER                          // Specifies that the minimum required platform is Windows Vista.
    #define WINVER 0x0600           // Change this to the appropriate value to target other versions of Windows.
    #endif
    
    #ifndef _WIN32_WINNT            // Specifies that the minimum required platform is Windows Vista.
    #define _WIN32_WINNT 0x0600     // Change this to the appropriate value to target other versions of Windows.
    #endif
    
    #ifndef _WIN32_WINDOWS          // Specifies that the minimum required platform is Windows 98.
    #define _WIN32_WINDOWS 0x0410 // Change this to the appropriate value to target Windows Me or later.
    #endif
    
    #ifndef _WIN32_IE                       // Specifies that the minimum required platform is Internet Explorer 7.0.
    #define _WIN32_IE 0x0700        // Change this to the appropriate value to target other versions of IE.
    #endif
    
    #define WIN32_LEAN_AND_MEAN             // Exclude rarely-used stuff from Windows headers
    // Windows Header Files:
    #include <windows.h>
    #include <math.h>
    #include <stdio.h>
    Hỏi thêm
    Tớ đang tìm địa chỉ trạng thái đánh hay đứng im. Tở search với 2 giá trị 0 và 1 thì ra 1 địa chỉ ảo có value thay đổi khi đánh và khống đánh. Tớ xem what write to address thì được code sau.
    Code :
    mov [ecx + 30],bl
    ecx = 17C92B24
    mov [ecx + 31],al
    ecx = 17C92B24


    Tờ tìm value 17C92B24 thì có 1 address khác. Tạo pointer với địa chỉ này và offset 30 thì trỏ tới địa chỉ ảo trên (31 thì không). tớ xem what access pointer. Then
    Code :
    mov eax,[eax + 28]
    eax = 17C92B24

    Sao lại ra 17C92B24. Giờ phải làm sao tiếp đây.

  8. #8
    Lỗi assert bạn thử google và tìm cách nhé, mình chỉ biết là khi điều kiện FALSE thì nó sẽ hiện ra hộp thoại assert.
    Còn nếu là game Kiếm Thế thì mỗi NPC đều có một biến gọi là m_nDoing ở offset 0x940, cho biết NPC đó đang làm gì.
    Các giá trị có thể có của m_nDoing:
    Mã:
    enum NPC_CMD
    {
    	do_none					= 0,
    	do_stand				= 1,
    	do_walk					= 2,
    	do_run					= 3,
    	do_jump					= 4,
    	do_skill					= 5,
    	do_magic				= 6,
    	do_attack				= 7,
    	do_sit					= 8,
    	do_hurt					= 9,
    	do_death				= 10,
    	do_idle					= 11,
    	do_specialskill1		= 12,
    	do_special1				= 13,
    	do_special2				= 14,
    	do_special3				= 15,
    	do_special4				= 16,
    	do_runattack			= 17,
    	do_manyattack		= 18,
    	do_jumpattack			= 19,
    	do_revive				= 20,
    	do_stall					= 21,
    	do_movepos			= 22,
    	do_knockback			= 23,
    	do_specialskill2		= 25,
    };

  9. #9
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Tớ hỏi cách tìm địa chỉ ấy. Nếu ASM có dạng
    Mã:
    mov [ecx + 30], eax
    thì đơn giản nhưng thay eax thành bl thì có ý nghĩa gì hình như bl chỉ lưu trữ có 2 con số, liệu có phải tìm con số khác. Nhức đầu quá! Khong biết nữa!

  10. #10
    Ngày tham gia
    Sep 2015
    Bài viết
    0
    Trích dẫn Gửi bởi theboy909
    Tớ hỏi cách tìm địa chỉ ấy. Nếu ASM có dạng
    Mã:
    mov [ecx + 30], eax
    thì đơn giản nhưng thay eax thành bl thì có ý nghĩa gì hình như bl chỉ lưu trữ có 2 con số, liệu có phải tìm con số khác. Nhức đầu quá! Khong biết nữa!
    Bạn có thể add Y!M của mình: holyiii@yahoo.com, chúng ta sẽ trao đổi rõ hơn [IMG]images/smilies/biggrin.png[/IMG]

 

 

Quyền viết bài

  • Bạn Không thể gửi Chủ đề mới
  • Bạn Không thể Gửi trả lời
  • Bạn Không thể Gửi file đính kèm
  • Bạn Không thể Sửa bài viết của mình
  •