GithubHelp home page GithubHelp logo

captainhook's Introduction

CaptainHook (version 2.1 beta)

this one isnt release, plz download from here

CaptainHook is a hook framework for x86/x64 arch, it's based on capstone disassembler engine. CaptainHook is easy to use, and very friendly. The hook engine is much like MS Detours, so why to choose it?

  • it supports x64 (Detours x64 is commerical - $10,000~).
  • CaptainHook will know where to locate your hook in real time, the engine analyzes the code, and finds if small API redirection (Wow64 hook on kernelbase for example or some minimal JMP table redirection[particularly common in packed/protected code]) was occurred, and locate your hook in safe area.
  • in the next release, CaptainHook will contain an engine for jmp/conditional jmp repair - if your hook corrupts sensitive code.

whats new?

  • Disable/Eneble hook at runtime, without remove them.
  • some fix in the design of the code and the class.

code example:

#include "CaptainHook.h"
#pragma comment(lib, "CaptainHook.lib")

void (__fastcall *CH_OriginalFunction_1)(...) = OriginalFunction_1;
void (__stdcall  *CH_OriginalFunction_2)(...) = OriginalFunction_2;
void (__fastcall *CH_OriginalFunction_3)(...) = OriginalFunction_3;
void (__fastcall *CH_OriginalFunction_4)(...) = OriginalFunction_4;

int main() {

	unsigned int uiHookId1, uiHookId2;
    CaptainHook *pChook = new CaptainHook();
    if (!pChook) return 0;
    
	pChook->AddInlineHook(&(void *&)CH_OriginalFunction_1, HookedOriginalFunction_1);
	pChook->AddPageGuardHook(&(void *&)CH_OriginalFunction_2, HookedOriginalFunction_2);
    
	pChook->AddInlineHook(&(void *&)CH_OriginalFunction_3, HookedOriginalFunction_3, &uiHookId1);
	pChook->AddPageGuardHook(&(void *&)CH_OriginalFunction_4, HookedOriginalFunction_4, &uiHookId2);
	/*
	:
	*/
	pChook->DisableHook(uiHookId1);
	/*
	:
	*/
	pChook->EnableHook(uiHookId1);
	/*
	:
	*/
	pChook->~CaptainHook(); // this function clean all the hook(s).
    return 0;
}

CaptainHook.h for include is just this file

how to build?

> git clone --recursive https://github.com/shmuelyr/CaptainHook.git
> cd CaptainHook
> "C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\vsvars32.bat"
> msbuild.exe

in the next version:

  • IAT hooking, for dll function.
  • hooking with hardware breakpoint.

Full example:

#include <Windows.h>
#include "CaptainHook.h"

#pragma comment(lib, "CaptainHook.lib")

int(__stdcall *CH_OriginalMessageBoxA)
	(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType) = MessageBoxA;
int __stdcall MyMessageBoxA(HWND hWnd, LPCSTR lpText, LPCSTR lpCaption, UINT uType) {

	return CH_OriginalMessageBoxA(hWnd, "HOOK", "HOOK", uType);
}

int WinMain(HINSTANCE hIns, HINSTANCE hPrev, LPSTR lpCmdLine, int cCmdShow) {
	
	unsigned int uiHookId;
	CaptainHook *pChook = new CaptainHook();
	pChook->AddPageGuardHook(&(void *&)CH_OriginalMessageBoxA, MyMessageBoxA, &uiHookId);
	MessageBoxA(NULL, "test", "test", MB_OK);
	pChook->DisableHook(uiHookId);
	MessageBoxA(NULL, "test", "test", MB_OK);
	pChook->EnableHook(uiHookId);
	MessageBoxA(NULL, "test", "test", MB_OK);
	return 0;
}

Happy Hooking!

captainhook's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

captainhook's Issues

Missing constants on compile

"JMP_TRAMPOLINE_LEN" is undefined CaptainHook.cpp 93
"PG_HOOKTYPE_LEN" is undefined CaptainHook.cpp 128
"JMP_TRAMPOLINE_LEN" is undefined CaptainHook.cpp 133

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.