C + + Detours to implement simple system function interception __jquery

Source: Internet
Author: User

Alas, nearly six months have not written, the return of the missing population, because the blogger participated in the work. Before school, see a lot of reading in the school after the work of Daniel also rarely updated blog, before the shrug. Now found that it is really a work of free time than to go to school, so also miss the previous in the University of a person in the library a computer bottle of mineral water a day of time, haha. However, it is not a bad thing to write a blog when you are free.


Today implement a simple call to the Detours.lib static library implementation of a system function (systems) interception.

The primary programming environment is still visual Studio 2017. Environment this thing, all the same, which is convenient to use which one.

Very simple. According to the truth is using Detours Express 3.0, but the official website seems to be integrated into one, or.

Website detours static Library download address:


After downloading, get:


Get a bunch of files after decompression:


Then open the VS2017 Developer command line:


Then enter the SRC directory of this folder:


Enter the NMAKE command and compile the source file to get the corresponding static library file, which is the same as the makefile principle in Linux, but this becomes the compilation of the Windows environment.


Then put the corresponding header files Detours.h,detver.h and detours.lib files in your corresponding program directory.

1.



2.



3.



The final step is to write the calling source code (note: Solution configuration in Release mode)

GOGOGO.C:

#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
#include "detours.h"                                         //Load header file

#pragma comment (lib, "Detours.lib");

Int (*poldsystem) (char const* _command) = System;           Record the address of the original function

int newsystem (_in_opt_z_ char const* _command) {
	printf ("Prohibit execution of%s", _command);
	return 1;
}


void Hook () {
	detourrestoreafterwith ();                              Recovery status, avoid repeated interception change address
	detourtransactionbegin ();                              Start intercepting
	Detourupdatethread (GetCurrentThread ());                Intercepts the current thread
	Detourattach ((void**) &poldsystem, newsystem);          Intercept
	detourtransactioncommit ();                             Effective
}

void Main () {

	system ("Notepad");
	Hook ();

	System ("Notepad");                                     How to prevent system from opening Notepad
	//need to modify the code area

	GetChar () with the help of detours;


Running effect (good low):

1.



2.

Related Article

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.