

![]() |
![]() |
|
|
#1 (permalink) |
|
Loading javascript...
Senior Member
Moderator ![]() Inquisitor |
This is used to write JMPs or CALLs to an address for hijacking game functions to your own code. You can enable or disable an individual hook, and it keeps all the hooks in a linked list so that you can quickly enable or disable all of them (useful for avoiding b.net's login hash check *hint*).
To create a hook, all you have to do is: Code:
hook* hMyHook = new hook((void*)0xBADF00D,MyDetour, true, 0); Hope this helps some of you, and you C++ gurus can go ahead and criticize my lack of code commenting. :P hook.h Code:
#ifndef __HOOKING_CLASS__
#define __HOOKING_CLASS__
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
class hook
{
private:
static hook* First;
hook* Next;
void* code;
void* hookfunc;
char* origbytes;
bool UseJMP;
int NOPpadding;
public:
hook(void* code, void* hookfunc, bool UseJMP, int NOPpadding);
~hook();
static int DeleteAllHooks();
static int SetAllHooks(bool state);
void set(bool state);
};
#endif
Code:
#include "hook.h"
hook* hook::First = 0;
hook::hook(void* cd, void* hf, bool JMP, int NOP)
{
if(!cd || !hf)
{
return;
}
origbytes = 0;
Next = 0;
code = cd;
hookfunc = hf;
UseJMP = JMP;
NOPpadding = NOP;
if(!First)
{
First = this;
}
else
{
hook* h = First;
while(h->Next) h = h->Next;
h->Next = this;
}
set(1);
}
hook::~hook()
{
if(origbytes)
{
delete [] origbytes;
}
if( First == this)
{
First = First->Next;
}
else
{
hook* h = First;
while(h->Next != this) h = h->Next;
h->Next = this->Next;
}
}
int hook::DeleteAllHooks()
{
if(!First) return 0;
hook* h = First;
hook* temp = 0;
int x = 0;
while(h -> Next)
{
temp = h;
h = h->Next;
delete temp;
x++;
}
delete h;
return x+1;
}
int hook::SetAllHooks(bool state)
{
if(!First) return 0;
hook* h = First;
hook* temp = 0;
int x = 0;
while( h-> Next )
{
temp = h;
h = h->Next;
temp->set(state);
x++;
}
h->set(state);
return x+1;
}
void hook::set(bool state)
{
HANDLE Thread = GetCurrentThread();
DWORD oldPriority = GetThreadPriority(Thread);
SetThreadPriority(Thread, THREAD_PRIORITY_TIME_CRITICAL);
DWORD OldProtect = 0;
VirtualProtect(code, 5+NOPpadding, PAGE_READWRITE, &OldProtect);
if(!state)
{
if(origbytes)
{
memcpy(code, origbytes, 5+NOPpadding);
delete [] origbytes;
origbytes = 0;
}
}
else
{
if(origbytes)
{
delete [] origbytes;
}
DWORD size = 5+NOPpadding+1;
origbytes = new char [size];
memcpy(origbytes, code, 5+NOPpadding);
char Data[5] = {0};
Data[0] = 0xE8 + UseJMP;
*(DWORD*)(Data+1) = (DWORD)hookfunc - (DWORD)code - 5;
memcpy(code, Data, 5);
memset((void*)((DWORD)code+5), 0x90, NOPpadding);
}
VirtualProtect(code, 5+NOPpadding, OldProtect, &OldProtect);
SetThreadPriority(Thread, oldPriority);
}
|
|
|
|
![]() |
![]() |
|
Advertisement
|
|
![]() |
![]() |
|
|
#3 (permalink) |
![]() ![]() ![]() Blessed |
Very nice lazy mans linked list. I like the flag for enabling and disabling, but I'm afraid I would obsess myself into adding specific enabling of hooks. I prefer to keep each hook as it's own object, instead of using an internal management technique (like a self altering linked list), and simply store them in a generic container. This allows you much finer control in addition to usually being much more efficient, as you would be hard pressed to find structures that run faster than the available standards, unless you wrote them yourself (assuming your competent) from scratch or obtained written from scratch code from a competent programmer.
|
|
|
|
![]() |
![]() |
![]() |
![]() |
|
|
#6 (permalink) | ||
![]() ![]() Deviant Join Date: Jul 2008
Location: here
Posts: 51
![]() |
If you could add a couple of "CALL"/"RET" in your code, I think It could really rox :D
Musnt you write: Quote:
Quote:
Last edited by Mixter : 08-19-2008 at 06:26 AM. |
||
|
|
|
![]() |
![]() |
| Sponsored links | |
|
Advertisement
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [Re-Release] DBZ Supreme RPG Code Generator | TheSpectator | Warcraft Gaming | 24 | 09-18-2007 08:52 PM |
| Question regarding code caves | arpsmack | Starcraft Hacking Related | 24 | 04-23-2007 12:09 PM |
| our korean hack source code | HiddenReverC | Reverse Engineering | 5 | 08-18-2006 05:45 AM |
| Is this the Zero2.0.2 source? | ShadowTassadar | Programming | 32 | 07-09-2005 11:06 PM |
| All times are GMT. The time now is 12:42 AM. |

