Skip to content

Commit 4fa2fe8

Browse files
authored
Adapt to changes in YARA's API (VirusTotal#132)
1 parent c1490e1 commit 4fa2fe8

File tree

4 files changed

+33
-51
lines changed

4 files changed

+33
-51
lines changed

appveyor.yml

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -12,64 +12,52 @@ environment:
1212
# a later point release.
1313
# See: http://www.appveyor.com/docs/installed-software#python
1414

15-
- PYTHON: "C:\\Python27"
16-
PYTHON_VERSION: "2.7.x" # currently 2.7.16
17-
PYTHON_ARCH: "32"
18-
OPENSSL_LIB: "openssl-1.1.0e-vs2008"
19-
VS: "Visual Studio 9 2008"
20-
21-
- PYTHON: "C:\\Python27-x64"
22-
PYTHON_VERSION: "2.7.x" # currently 2.7.16
23-
PYTHON_ARCH: "64"
24-
OPENSSL_LIB: "openssl-1.1.0e-vs2008"
25-
VS: "Visual Studio 9 2008 Win64"
26-
2715
- PYTHON: "C:\\Python35"
2816
PYTHON_VERSION: "3.5.x" # currently 3.5.4
2917
PYTHON_ARCH: "32"
30-
OPENSSL_LIB: "openssl-1.1.0e-vs2015"
18+
OPENSSL_LIB: "https://ci.appveyor.com/api/buildjobs/fakubeldw67e9pmg/artifacts/YARA.OpenSSL.x86.1.1.1.nupkg"
3119
VS: "Visual Studio 14 2015"
3220

3321
- PYTHON: "C:\\Python35-x64"
3422
PYTHON_VERSION: "3.5.x" # currently 3.5.4
3523
PYTHON_ARCH: "64"
36-
OPENSSL_LIB: "openssl-1.1.0e-vs2015"
24+
OPENSSL_LIB: "https://ci.appveyor.com/api/buildjobs/q63539qt9yqaqspo/artifacts/YARA.OpenSSL.x64.1.1.1.nupkg"
3725
VS: "Visual Studio 14 2015 Win64"
3826

3927
- PYTHON: "C:\\Python36"
4028
PYTHON_VERSION: "3.6.x" # currently 3.6.8
4129
PYTHON_ARCH: "32"
42-
OPENSSL_LIB: "openssl-1.1.0e-vs2015"
30+
OPENSSL_LIB: "https://ci.appveyor.com/api/buildjobs/fakubeldw67e9pmg/artifacts/YARA.OpenSSL.x86.1.1.1.nupkg"
4331
VS: "Visual Studio 14 2015"
4432

4533
- PYTHON: "C:\\Python36-x64"
4634
PYTHON_VERSION: "3.6.x" # currently 3.6.8
4735
PYTHON_ARCH: "64"
48-
OPENSSL_LIB: "openssl-1.1.0e-vs2015"
36+
OPENSSL_LIB: "https://ci.appveyor.com/api/buildjobs/q63539qt9yqaqspo/artifacts/YARA.OpenSSL.x64.1.1.1.nupkg"
4937
VS: "Visual Studio 14 2015 Win64"
5038

5139
- PYTHON: "C:\\Python37"
5240
PYTHON_VERSION: "3.7.x" # currently 3.7.0
5341
PYTHON_ARCH: "32"
54-
OPENSSL_LIB: "openssl-1.1.0e-vs2015"
42+
OPENSSL_LIB: "https://ci.appveyor.com/api/buildjobs/fakubeldw67e9pmg/artifacts/YARA.OpenSSL.x86.1.1.1.nupkg"
5543
VS: "Visual Studio 14 2015"
5644

5745
- PYTHON: "C:\\Python37-x64"
5846
PYTHON_VERSION: "3.7.x" # currently 3.7.0
5947
PYTHON_ARCH: "64"
60-
OPENSSL_LIB: "openssl-1.1.0e-vs2015"
48+
OPENSSL_LIB: "https://ci.appveyor.com/api/buildjobs/q63539qt9yqaqspo/artifacts/YARA.OpenSSL.x64.1.1.1.nupkg"
6149
VS: "Visual Studio 14 2015 Win64"
6250

6351
- PYTHON: "C:\\Python38"
6452
PYTHON_VERSION: "3.8.x" # currently 3.8.0
6553
PYTHON_ARCH: "32"
66-
OPENSSL_LIB: "openssl-1.1.0e-vs2015"
54+
OPENSSL_LIB: "https://ci.appveyor.com/api/buildjobs/fakubeldw67e9pmg/artifacts/YARA.OpenSSL.x86.1.1.1.nupkg"
6755
VS: "Visual Studio 14 2015"
6856

6957
- PYTHON: "C:\\Python38-x64"
7058
PYTHON_VERSION: "3.8.x" # currently 3.8.0
7159
PYTHON_ARCH: "64"
72-
OPENSSL_LIB: "openssl-1.1.0e-vs2015"
60+
OPENSSL_LIB: "https://ci.appveyor.com/api/buildjobs/q63539qt9yqaqspo/artifacts/YARA.OpenSSL.x64.1.1.1.nupkg"
7361
VS: "Visual Studio 14 2015 Win64"
7462

7563
install:
@@ -114,32 +102,24 @@ install:
114102
# latest version of wheel.
115103
- "%CMD_IN_ENV% pip install wheel==0.29.0"
116104

105+
# We are in projects/yara-python, lets go out to projects.
117106
- cd ..
118-
- ps: Invoke-WebRequest "https://www.npcglib.org/~stathis/downloads/$env:OPENSSL_LIB.7z" -OutFile "openssl.7z"
119-
- 7z x openssl.7z
120-
- cd yara-python
121-
122-
- ps: >-
123-
If ($env:PYTHON_ARCH -Match "32") {
124-
$env:OPENSSL_LIB_DIR="lib"
125-
} Else {
126-
$env:OPENSSL_LIB_DIR="lib64"
127-
}
128-
129-
# This is workaround for solving an issue caused by CMake not finding an
130-
# appropriate compilet for Visual Studio 9 2008 Win64. This workaround was
131-
# copied from: https://github.com/conda/conda-build/blob/master/appveyor.yml
132-
- call appveyor\setup_x64.bat
133-
134-
# Download and build jansson library
135-
- cd ..
107+
108+
# Download precompiled OpenSSL library.
109+
- ps: Invoke-WebRequest "$env:OPENSSL_LIB" -OutFile "openssl.zip"
110+
- ps: Expand-Archive openssl.zip -DestinationPath openssl
111+
112+
# Download and build jansson library.
136113
- ps: Invoke-WebRequest "https://github.com/akheron/jansson/archive/v$env:JANSSON_VERSION.zip" -OutFile "jansson.zip"
137114
- ps: Expand-Archive jansson.zip -DestinationPath .
138115
- cd jansson-%JANSSON_VERSION%
139116
- md build
140117
- cd build
141118
- cmake -DJANSSON_BUILD_DOCS=OFF -DJANSSON_WITHOUT_TESTS=ON -G "%VS%" ..
142119
- cmake --build . --config Release
120+
121+
# We are in projects/jansson-%JANSSON_VERSION%/build, lets move to
122+
# projects/yara-python
143123
- cd ../../yara-python
144124

145125

@@ -150,16 +130,15 @@ clone_script:
150130
build_script:
151131
# Build the compiled extension
152132
- "%CMD_IN_ENV% python setup.py build_ext --enable-cuckoo --enable-dotnet
153-
-L../jansson-%JANSSON_VERSION%/build/lib/Release;../%OPENSSL_LIB%/%OPENSSL_LIB_DIR%
154-
-I../jansson-%JANSSON_VERSION%/build/include;../%OPENSSL_LIB%/include
133+
-L../jansson-%JANSSON_VERSION%/build/lib/Release;../openssl/lib
134+
-I../jansson-%JANSSON_VERSION%/build/include;../openssl/include
155135
-DHASH_MODULE,HAVE_LIBCRYPTO
156-
-llibcryptoMT"
136+
-llibcrypto"
157137

158138
after_build:
159139
- "%CMD_IN_ENV% python setup.py install"
160140

161141
test_script:
162-
# Run the project tests
163142
- "%CMD_IN_ENV% python tests.py"
164143

165144
after_test:
@@ -187,5 +166,5 @@ deploy:
187166
#
188167

189168
# Uncomment these lines for enabling Remote Desktop for debugging purposes.
190-
# on_finish:
191-
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))
169+
#on_finish:
170+
# - ps: $blockRdp = $true; iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/appveyor/ci/master/scripts/enable-rdp.ps1'))

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def run(self):
221221
module.define_macros.append(('HAVE_STRLCAT', '1'))
222222

223223
if self.enable_profiling:
224-
module.define_macros.append(('PROFILING_ENABLED', '1'))
224+
module.define_macros.append(('YR_PROFILING_ENABLED', '1'))
225225

226226
if self.dynamic_linking:
227227
module.libraries.append('yara')
@@ -315,7 +315,7 @@ def run(self):
315315

316316
setup(
317317
name='yara-python',
318-
version='3.11.0',
318+
version='4.0.0',
319319
description='Python interface for YARA',
320320
long_description=readme,
321321
license='Apache 2.0',

yara

Submodule yara updated 125 files

yara-python.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ PyObject* convert_object_to_python(
423423
switch(object->type)
424424
{
425425
case OBJECT_TYPE_INTEGER:
426-
if (object->value.i != UNDEFINED)
426+
if (object->value.i != YR_UNDEFINED)
427427
result = Py_BuildValue("l", object->value.i);
428428
break;
429429

@@ -546,7 +546,7 @@ PyObject* convert_dictionary_to_python(
546546
{
547547
PyDict_SetItemString(
548548
py_dict,
549-
dictionary->items->objects[i].key,
549+
dictionary->items->objects[i].key->c_string,
550550
py_object);
551551

552552
Py_DECREF(py_object);
@@ -562,6 +562,7 @@ PyObject* convert_dictionary_to_python(
562562
#define CALLBACK_ALL CALLBACK_MATCHES | CALLBACK_NON_MATCHES
563563

564564
int yara_callback(
565+
YR_SCAN_CONTEXT* context,
565566
int message,
566567
void* message_data,
567568
void* user_data)
@@ -724,7 +725,7 @@ int yara_callback(
724725

725726
yr_rule_strings_foreach(rule, string)
726727
{
727-
yr_string_matches_foreach(string, m)
728+
yr_string_matches_foreach(context, string, m)
728729
{
729730
object = PyBytes_FromStringAndSize((char*) m->data, m->data_length);
730731

@@ -1455,7 +1456,6 @@ static PyObject* Rules_match(
14551456
callback_data.matches = PyList_New(0);
14561457

14571458
Py_BEGIN_ALLOW_THREADS
1458-
14591459
error = yr_rules_scan_file(
14601460
object->rules,
14611461
filepath,
@@ -1464,6 +1464,7 @@ static PyObject* Rules_match(
14641464
&callback_data,
14651465
timeout);
14661466

1467+
14671468
Py_END_ALLOW_THREADS
14681469
}
14691470
else if (data != NULL)
@@ -1664,6 +1665,7 @@ void raise_exception_on_error(
16641665
int error_level,
16651666
const char* file_name,
16661667
int line_number,
1668+
const YR_RULE* rule,
16671669
const char* message,
16681670
void* user_data)
16691671
{
@@ -1690,6 +1692,7 @@ void raise_exception_on_error_or_warning(
16901692
int error_level,
16911693
const char* file_name,
16921694
int line_number,
1695+
const YR_RULE* rule,
16931696
const char* message,
16941697
void* user_data)
16951698
{

0 commit comments

Comments
 (0)