@@ -76,12 +76,13 @@ def muted(*streams):
76
76
devnull .close ()
77
77
78
78
79
- def has_function (function_name , include_dirs = None , libraries = None , library_dirs = None ):
79
+ def has_function (function_name , includes = None , include_dirs = None , libraries = None , library_dirs = None ):
80
80
"""Checks if a given functions exists in the current platform."""
81
81
compiler = distutils .ccompiler .new_compiler ()
82
82
with muted (sys .stdout , sys .stderr ):
83
83
result = compiler .has_function (
84
84
function_name ,
85
+ includes = includes ,
85
86
include_dirs = include_dirs ,
86
87
libraries = libraries ,
87
88
library_dirs = library_dirs )
@@ -188,12 +189,6 @@ def run(self):
188
189
189
190
exclusions = []
190
191
191
- # Needed to build tlsh
192
- module .define_macros .extend ([('BUCKETS_128' , 1 ), ('CHECKSUM_1B' , 1 )])
193
-
194
- # Needed to build authenticode parser
195
- module .libraries .append ('ssl' )
196
-
197
192
for define in self .define or []:
198
193
module .define_macros .append (define )
199
194
@@ -206,6 +201,22 @@ def run(self):
206
201
building_for_freebsd = 'freebsd' in self .plat_name
207
202
building_for_openbsd = 'openbsd' in self .plat_name # need testing
208
203
204
+ if building_for_windows :
205
+ arch = 'x86' if self .plat_name == 'win32' else 'x64'
206
+ openssl_include_dirs = [
207
+ os .path .join (base_dir , 'yara\\ windows\\ vs2015\\ packages\\ YARA.OpenSSL.{}.1.1.1\\ include' .format (arch )),
208
+ os .path .join (base_dir , 'yara\\ windows\\ vs2017\\ packages\\ YARA.OpenSSL.{}.1.1.1\\ include' .format (arch ))
209
+ ]
210
+ openssl_library_dirs = [
211
+ os .path .join (base_dir , 'yara\\ windows\\ vs2015\\ packages\\ YARA.OpenSSL.{}.1.1.1\\ lib' .format (arch )),
212
+ os .path .join (base_dir , 'yara\\ windows\\ vs2017\\ packages\\ YARA.OpenSSL.{}.1.1.1\\ lib' .format (arch ))
213
+ ]
214
+ openssl_libraries = ['libcrypto' ]
215
+ else :
216
+ openssl_include_dirs = []
217
+ openssl_library_dirs = []
218
+ openssl_libraries = ['crypto' ]
219
+
209
220
if building_for_linux :
210
221
module .define_macros .append (('_GNU_SOURCE' , '1' ))
211
222
module .define_macros .append (('USE_LINUX_PROC' , '1' ))
@@ -264,17 +275,32 @@ def run(self):
264
275
if self .dynamic_linking :
265
276
module .libraries .append ('yara' )
266
277
else :
267
- if not self .define or not ('HASH_MODULE' , '1' ) in self .define :
268
- if (has_function ('MD5_Init' , include_dirs = module .include_dirs , libraries = ['crypto' ], library_dirs = module .library_dirs ) and
269
- has_function ('SHA256_Init' , include_dirs = module .include_dirs , libraries = ['crypto' ], library_dirs = module .library_dirs )):
270
- module .define_macros .append (('HASH_MODULE' , '1' ))
271
- module .define_macros .append (('HAVE_LIBCRYPTO' , '1' ))
272
- module .libraries .append ('crypto' )
273
- elif building_for_windows :
274
- module .define_macros .append (('HASH_MODULE' , '1' ))
275
- module .define_macros .append (('HAVE_WINCRYPT_H' , '1' ))
276
- else :
277
- exclusions .append ('yara/libyara/modules/hash/hash.c' )
278
+ # Is OpenSSL available?
279
+ if (has_function ('OpenSSL_add_all_algorithms' ,
280
+ includes = ['openssl/evp.h' ],
281
+ include_dirs = module .include_dirs + openssl_include_dirs ,
282
+ libraries = module .libraries + openssl_libraries ,
283
+ library_dirs = module .library_dirs + openssl_library_dirs )
284
+ # In case OpenSSL is being linked statically
285
+ or has_function ('OpenSSL_add_all_algorithms' ,
286
+ includes = ['openssl/evp.h' ],
287
+ include_dirs = module .include_dirs + openssl_include_dirs ,
288
+ libraries = module .libraries + openssl_libraries + ['dl' , 'pthread' , 'z' ],
289
+ library_dirs = module .library_dirs + openssl_library_dirs )
290
+ ):
291
+ module .define_macros .append (('HASH_MODULE' , '1' ))
292
+ module .define_macros .append (('HAVE_LIBCRYPTO' , '1' ))
293
+ module .libraries .extend (openssl_libraries )
294
+ module .include_dirs .extend (openssl_include_dirs )
295
+ module .library_dirs .extend (openssl_library_dirs )
296
+ elif building_for_windows :
297
+ # OpenSSL is not available, but in Windows we can rely on Wincrypt.
298
+ module .define_macros .append (('HASH_MODULE' , '1' ))
299
+ module .define_macros .append (('HAVE_WINCRYPT_H' , '1' ))
300
+ else :
301
+ # OpenSSL is not available, exclude hash.c, as it requires some hashing
302
+ # functions.
303
+ exclusions .append ('yara/libyara/modules/hash/hash.c' )
278
304
279
305
if self .enable_magic :
280
306
module .define_macros .append (('MAGIC_MODULE' , '1' ))
0 commit comments