Commit 9e0d0ac3 by Wesley Shields Committed by Victor M. Alvarez

Fix which callbacks (#72)

* Fix regression in which_callbacks.

* Add test to detect regression fixed in 367290a586ef7b7f83e5db265bfe39b57847473e.

* Fix typo in previous commit.

* Remove redundant conditional.
parent fb2087f8
......@@ -813,6 +813,21 @@ class TestYara(unittest.TestCase):
r = yara.compile(source='rule test { condition: ext_str matches /ssi$/ }', externals={'ext_str': 'mississippi'})
self.assertFalse(r.match(data='dummy'))
def testCallbackAll(self):
global rule_data
rule_data = []
def callback(data):
global rule_data
rule_data.append(data)
return yara.CALLBACK_CONTINUE
r = yara.compile(source='rule t { condition: true } rule f { condition: false }')
r.match(data='dummy', callback=callback, which_callbacks=yara.CALLBACK_ALL)
self.assertTrue(len(rule_data) == 2)
def testCallback(self):
global rule_data
......@@ -836,6 +851,13 @@ class TestYara(unittest.TestCase):
self.assertTrue(rule_data['rule'] == 'test')
rule_data = None
r = yara.compile(source='rule test { condition: true }')
r.match(data='dummy', callback=callback, which_callbacks=yara.CALLBACK_MATCHES)
self.assertTrue(rule_data['rule'] == 'test')
def testIncludeCallback(self):
def callback(requested_filename, filename, namespace):
......
......@@ -597,10 +597,6 @@ int yara_callback(
if (message == CALLBACK_MSG_SCAN_FINISHED)
return CALLBACK_CONTINUE;
if (message == CALLBACK_MSG_RULE_NOT_MATCHING &&
(callback == NULL || (which & CALLBACK_MATCHES)))
return CALLBACK_CONTINUE;
if (message == CALLBACK_MSG_IMPORT_MODULE && modules_data == NULL)
return CALLBACK_CONTINUE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment