forked from kubo/funchook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeson.build
196 lines (171 loc) · 4.21 KB
/
meson.build
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
project(
'funchook',
'c',
version: '2.0.0',
# Nearly Classpath-exception-2.0, but not exactly. Additional clause:
# "If you modify this library, you must extend this exception to
# your version of the library."
license: 'GPL-2.0-or-later WITH Classpath-exception-2.0',
default_options: [
'c_std=c11',
'warning_level=2',
],
meson_version: '>=1.2',
)
cc = meson.get_compiler('c')
host_cpu_family = host_machine.cpu_family()
if host_cpu_family in ['x86', 'x86_64']
funchook_cpu = 'x86'
default_disasm = 'Zydis'
elif host_cpu_family == 'aarch64'
funchook_cpu = 'arm64'
default_disasm = 'capstone'
endif
host_system = host_machine.system()
funchook_deps = []
cdata = configuration_data()
if host_system in ['windows', 'cygwin']
funchook_os = 'windows'
funchook_deps += cc.find_library('psapi')
else
funchook_os = 'unix'
funchook_deps += dependency('dl')
endif
if host_machine.system() == 'linux'
add_project_arguments(
'-D_GNU_SOURCE',
language: 'c',
)
# musl libc doesn't provide the GNU-specific version of strerror_r
# even when _GNU_SOURCE is defined.
gnu_strerror_r = cc.compiles(
'''
#define _GNU_SOURCE
#include <string.h>
int main()
{
char dummy[128];
return *strerror_r(0, dummy, sizeof(dummy));
}
''',
)
cdata.set10('GNU_SPECIFIC_STRERROR_R', gnu_strerror_r)
endif
disasm = get_option('disasm')
if disasm == 'auto'
funchook_disasm = default_disasm
else
funchook_disasm = disasm
endif
if funchook_disasm == 'Zydis'
zydis_dep = dependency(
'zydis',
version: '>=4.0.0',
default_options: {
'minimal': 'enabled',
'decoder': 'enabled',
},
)
cdata.set10('DISASM_ZYDIS', true)
cdata.set10(
'DISASM_ZYDIS_V5',
cc.has_member(
'ZydisDecodedOperandMem',
'disp.size',
dependencies: zydis_dep.partial_dependency(compile_args: true, includes: true),
prefix: '''
#include <Zydis/Zydis.h>
''',
),
)
funchook_deps += zydis_dep
elif disasm == 'capstone'
funchook_deps += dependency(
'capstone',
version: '>=5.0.0',
default_options: {
'archs': [funchook_cpu],
'x86_reduce': true,
'x86_att_disable': true,
},
)
cdata.set10('DISASM_CAPSTONE', true)
endif
sizeof_void_p = cc.sizeof('void*')
cdata.set('SIZEOF_VOID_P', sizeof_void_p)
configure_file(
output: 'config.h',
configuration: cdata,
)
hdrs = files(
'include/funchook.h',
)
src = files(
'src/funchook.c',
f'src/arch_@[email protected]',
f'src/os_@[email protected]',
f'src/disasm_@[email protected]',
)
extra_masmflags = []
if funchook_cpu == 'x86' and sizeof_void_p == 8
if cc.get_id() == 'msvc' and add_languages('masm', native: false)
prehook = 'prehook-x86_64-ms'
src += configure_file(
input: 'src' / f'@[email protected]',
output: f'@[email protected]',
copy: true,
)
elif funchook_os == 'windows'
src += files('src/prehook-x86_64-ms.S')
else
src += files('src/prehook-x86_64-sysv.S')
endif
endif
if funchook_cpu == 'x86' and sizeof_void_p == 4
if cc.get_id() == 'msvc' and add_languages('masm', native: false)
prehook = 'prehook-i686-ms'
src += configure_file(
input: 'src' / f'@[email protected]',
output: f'@[email protected]',
copy: true,
)
extra_masmflags += '/safeseh'
else
src += files('src/prehook-i686-gas.S')
endif
endif
if funchook_cpu == 'arm64'
if cc.get_id() == 'msvc' and add_languages('masm', native: false)
prehook = 'prehook-arm64-ms'
src += configure_file(
input: 'src' / f'@[email protected]',
output: f'@[email protected]',
copy: true,
)
else
src += files('src/prehook-arm64-gas.S')
endif
endif
inc = include_directories('include')
funchook_lib = library(
'funchook',
src,
include_directories: inc,
dependencies: funchook_deps,
masm_args: extra_masmflags,
version: meson.project_version(),
install: true,
)
install_headers(hdrs)
funchook_dep = declare_dependency(
link_with: funchook_lib,
include_directories: inc,
)
pkg = import('pkgconfig')
pkg.generate(
funchook_lib,
name: 'funchook',
description: 'Cross platform inline hooking library',
url: 'https://github.com/kubo/funchook',
)
meson.override_dependency('funchook', funchook_dep)