-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsymsearch.h
More file actions
119 lines (95 loc) · 3.26 KB
/
Copy pathsymsearch.h
File metadata and controls
119 lines (95 loc) · 3.26 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*
* symsearch: - looks up for unexported kernel symbols
*
* Copyright (C) 2010 Skrilax_CZ
* GPL
*
* This program 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 2 of the License, or
* (at your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifndef _SYMSEARCH_H_
#define _SYMSEARCH_H_
//macros to call functions declared in C but addressed manually
//ret -> return type
//name -> function name
//... parameter list
//expname -> name under which the function is exported
//addresses
#define SYMSEARCH_DECLARE_ADDRESS(name) \
extern unsigned long name##_address
#define SYMSEARCH_DECLARE_ADDRESS_STATIC(name) \
static unsigned long name##_address = 0
#define SYMSEARCH_INIT_ADDRESS(name) \
unsigned long name##_address = 0
#define SYMSEARCH_GET_ADDRESS(name) \
name##_address
//functions
#define SYMSEARCH_DECLARE_FUNCTION(ret,name,...) \
typedef ret (*name##_fp) ( __VA_ARGS__ ); \
extern name##_fp name
#define SYMSEARCH_DECLARE_FUNCTION_STATIC(ret,name,...) \
typedef ret (*name##_fp) ( __VA_ARGS__ ); \
static name##_fp name = 0
#define SYMSEARCH_INIT_FUNCTION(name) \
name##_fp name = (name##_fp)0
//binding (call this in module_init and module is the module name)
#define SYMSEARCH_BIND_ADDRESS(module,name) \
name##_address = lookup_symbol_address(#name); \
if(!name##_address) \
{ \
printk(KERN_INFO #module ": Could not find symbol: " #name ".\n"); \
return -EBUSY; \
}
#define SYMSEARCH_BIND_ADDRESS_TO(module,name,sym) \
sym##_address = lookup_symbol_address(#name); \
if(!sym##_address) \
{ \
printk(KERN_INFO #module ": Could not find symbol: " #name ".\n"); \
return -EBUSY; \
}
#define SYMSEARCH_BIND_FUNCTION(module,name) \
name = (name##_fp)lookup_symbol_address(#name); \
if(!name) \
{ \
printk(KERN_INFO #module ": Could not find symbol: " #name ".\n"); \
return -EBUSY; \
}
#define SYMSEARCH_BIND_FUNCTION_TO(module,name,sym) \
sym = (sym##_fp)lookup_symbol_address(#name); \
if(!sym) \
{ \
printk(KERN_INFO #module ": Could not find symbol: " #name ".\n"); \
return -EBUSY; \
}
#define SYMSEARCH_BIND_FUNCTION_TO_NORET(module,name,sym) \
sym = (sym##_fp)lookup_symbol_address(#name); \
if(!sym) \
{ \
printk(KERN_INFO #module ": Could not find symbol: " #name ".\n"); \
return; \
}
//hijacking function
//injects a Branch instruction to the function beginning
//ARM MODE only !!!
struct hijack_info
{
unsigned long hijack_address;
unsigned long redirection_address;
unsigned long instruction_backup;
};
SYMSEARCH_DECLARE_FUNCTION(unsigned long, lookup_symbol_address, const char *name);
struct hijack_info hijack_function(unsigned long hijack_address, unsigned long redirection_address);
void restore_function(struct hijack_info hijack);
#endif