Graphical detour installation and simple use examples (WIN7+VC6)

Source: Internet
Author: User

Related downloads:

Http://pan.baidu.com/s/1o7OEMc6

Detour6.rar is the project of this paper

DETOURSEXPRESS30 is the Detour installation file that Microsoft downloaded

Detoured is a compiled library.


Reference

Http://www.cnblogs.com/weiqubo/archive/2011/06/01/2065534.html
http://blog.csdn.net/evi10r/article/details/6659354
http://blog.csdn.net/donglinshengan/article/details/8544464:

http://research.microsoft.com/en-us/projects/detours/

Microsoft detour download


Detours is a library of functions developed by Microsoft that can be used to capture system APIs.

1 installation






2 Build Library

Detour after the download is the source code, need to build their own library;


Copy the SRC folder to the path;


Enter the VC bin execution Vcvars32.bat

Again into SRC, execute NMAKE


Fail to read;

http://blog.csdn.net/donglinshengan/article/details/8544464

Copy System.mak and makefile from the Detours installation directory to the VC directory


and error;

Enter CL command separately to try, error occurred;


Download Mspdb60.dll, copy to system directory; register; The following error occurred; it's not easy to do some work.


Anyway, because the CL command could not be found, copy the command that NMAKE used;

cl/w4/wx/zi/mtd/gy/gm-/zl/od/ddetours_bits=32/dwin32_lean_and_mean/d_win32_winnt=0x403/gs/ddetours_x86=1/dde Tours_32bit=1/d_x86_/ddetours_option_bits=64/fd. \lib. X86\DETOURS.PDB/FOOBJ.X86\DETOURS.OBJ/C Detours.cpp

Go to the Bin directory to run a look directly;


Or not, copy the SRC folder of detour to the bin, and then execute the above command;


At this point, the reference on the Internet to compile their own detour library failure; It is estimated that my VC version is too low, but it is difficult to do so; Download the compiled Detour library directly on the Internet;

3 Simple Use examples

Refer to some examples on the Internet;

In the example, the entry is

int Apientry _tWinMain (hinstance hinstance,
HInstance hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)

Therefore, the new project, the results compiled can not link;


Create the following projects;


Modify the original example code as follows;

Detour6.cpp:Defines the entry point for the console application.//#include "stdafx.h" #include "detour6.h" #include &lt ;d etours.h> #pragma comment (lib, "Detours.lib") #pragma comment (lib, "Detoured.lib") #ifdef _debug#define new Debug_ New#undef this_filestatic char this_file[] = __file__; #endif/////////////////////////////////////////////////////// The one and only application Objectcwinapp theapp;using namespace std;static int (winapi* old_mes SAGEBOXW) (hwnd hwnd,lpcwstr lptext,lpcwstr lpcaption,uint utype) = Messageboxw;int WINAPI New_messageboxw (HWND hwnd, LPCWSTR lptext,lpcwstr lpcaption,uint utype) {//Modify input parameters, call original function int ret = OLD_MESSAGEBOXW (hwnd,l "input parameter has been hook by my ladyship        Modify ", L" [Detour Test] ", utype); return ret;}        VOID Hook () {detourrestoreafterwith ();        Detourtransactionbegin ();        Detourupdatethread (GetCurrentThread ());  The Detourattach can be called several times in a row, indicating that the hook functions Detourattach (& (pvoid&) old_messageboxw,new_messageboxw);      Detourtransactioncommit ();}        VOID unhook () {detourtransactionbegin ();                Detourupdatethread (GetCurrentThread ());        It is possible to call Detourdetach several times in a row, indicating that multiple function hooks Detourdetach (& (pvoid&) old_messageboxw,new_messageboxw) are revoked; Detourtransactioncommit ();} int _tmain (int argc, tchar* argv[], tchar* envp[]) {int nretcode = 0;//Initialize MFC and print and error on Failureif (!a Fxwininit (:: GetModuleHandle (NULL), NULL,:: GetCommandLine (), 0)) {//Todo:change error code to suit your Needscerr <&lt ; _t ("Fatal ERROR:MFC initialization Failed") << Endl;nretcode = 1;} else{//Todo:code Your application ' s behavior here.        MessageBoxW (0,l "normal message box", L "test", 0);        Hook ();        MessageBoxW (0,l "normal message box", L "test", 0); Unhook ();} return nRetCode;}

Success, the final operating effect is as follows;




Graphical detour installation and simple use examples (WIN7+VC6)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.