-
Notifications
You must be signed in to change notification settings - Fork 0
/
CDetour.h
94 lines (74 loc) · 2.56 KB
/
CDetour.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
PROJECT: m0d_s0beit_sa
LICENSE: See LICENSE in the top level directory
COPYRIGHT: Copyright 2007, 2008, 2009, 2010 we_sux
m0d_s0beit_sa is available from http://code.google.com/p/m0d-s0beit-sa/
m0d_s0beit_sa is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
m0d_s0beit_sa is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with m0d_s0beit_sa. If not, see <http://www.gnu.org/licenses/>.
$LastChangedDate: 2009-12-14 01:12:56 -0600 (Mon, 14 Dec 2009) $
$LastChangedBy: futnucks $
$Revision: 31 $
$HeadURL: https://m0d-s0beit-sa.googlecode.com/svn/trunk/src/CDetour.h $
$Id: CDetour.h 31 2009-12-14 07:12:56Z futnucks $
*/
/*
CDetour 2.0 by Sinner, don't forget to credit me!
Credits:
LanceVorgin (his CDetour class) + z0mbie (ADE32)
*/
/*
Type: Opcodes needed:
DETOUR_TYPE_JMP: 5
DETOUR_TYPE_PUSH_RET 6
DETOUR_TYPE_NOP_JMP 6
DETOUR_TYPE_NOP_NOP_JMP 7
DETOUR_TYPE_STC_JC 7
DETOUR_TYPE_CLC_JNC 7
DETOUR_TYPE_OBS_ADD 12
DETOUR_TYPE_OBS_STACKADD 13
DETOUR_TYPE_OBS_ROR 13
DETOUR_TYPE_OBS_XOR 14
DETOUR_TYPE_OBS_ADDNOT 14
*/
#pragma once
#pragma warning(disable: 4311)
#pragma warning(disable: 4312)
#include "ADE32.h"
#include <Windows.h>
typedef enum detour_types_s
{
DETOUR_TYPE_NOT_SET = -1,
DETOUR_TYPE_JMP,
DETOUR_TYPE_PUSH_RET,
DETOUR_TYPE_PUSH_FUNC,
DETOUR_TYPE_CALL_FUNC,
} detour_types_t;
#define DetourRandTypeLow DETOUR_TYPE_OBS_ADD
#define DetourRandTypeHigh DETOUR_TYPE_OBS_ADDNOT
class CDetour
{
public:
void* memcpy_s( void* pvAddress, const void* pvBuffer, size_t stLen );
void *Create(BYTE *orig, const BYTE *det, int iPatchType, int len=0);
void *Create(char *dllName, char *apiName, const BYTE *det, int iPatchType, int len=0);
bool Remove(BYTE *orig, BYTE *jmp, int iPatchType, int len=0);
bool Remove(char *dllName, char *apiName, BYTE *jmp, int iPatchType, int len=0);
bool BackupFunction( BYTE* func, int len );
bool RestoreFunction( BYTE* func, int len );
BYTE bBackup[20];
private:
bool Detour(BYTE *&jmp, BYTE *&orig, const BYTE *&det, int iPatchType, int len);
int GetDetourLen(int iPatchType);
int GetDetourLenAuto(BYTE *&orig, int iMinLen);
private:
HMODULE m_hModule;
DWORD m_dwAddress;
};