[Forensics-changes] [yara] 111/415: Fix Python 3.x compatibility issue and add some test cases
Hilko Bengen
bengen at moszumanska.debian.org
Thu Apr 3 05:42:51 UTC 2014
This is an automated email from the git hooks/post-receive script.
bengen pushed a commit to branch debian
in repository yara.
commit 6f564105246f57520af2f7e41affd014f64d1d8d
Author: Victor M. Alvarez <plusvic at gmail.com>
Date: Wed Aug 3 17:37:29 2011 +0000
Fix Python 3.x compatibility issue and add some test cases
---
windows/libyara/libyara.vcproj | 5 +++--
windows/yara/yara.vcproj | 8 +++----
yara-python/tests.py | 27 ++++++++++++++++++------
yara-python/yara-python.c | 48 +++++++++++++++++++++++++++++++++++++++---
4 files changed, 73 insertions(+), 15 deletions(-)
diff --git a/windows/libyara/libyara.vcproj b/windows/libyara/libyara.vcproj
index 79220dc..f80b1e6 100644
--- a/windows/libyara/libyara.vcproj
+++ b/windows/libyara/libyara.vcproj
@@ -62,7 +62,8 @@
/>
<Tool
Name="VCLibrarianTool"
- AdditionalDependencies="pcre.lib"
+ AdditionalDependencies="pcre32.lib advapi32.lib"
+ OutputFile="$(OutDir)\$(ProjectName)32.lib"
AdditionalLibraryDirectories="..\lib"
IgnoreAllDefaultLibraries="true"
/>
@@ -127,7 +128,7 @@
/>
<Tool
Name="VCLibrarianTool"
- AdditionalDependencies="pcre64.lib"
+ AdditionalDependencies="pcre64.lib advapi32.lib"
OutputFile="$(OutDir)\$(ProjectName)64.lib"
AdditionalLibraryDirectories="..\lib"
IgnoreAllDefaultLibraries="true"
diff --git a/windows/yara/yara.vcproj b/windows/yara/yara.vcproj
index e155b1b..75be317 100644
--- a/windows/yara/yara.vcproj
+++ b/windows/yara/yara.vcproj
@@ -48,10 +48,10 @@
PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_DEPRECATE"
MinimalRebuild="true"
BasicRuntimeChecks="3"
- RuntimeLibrary="1"
+ RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
- Detect64BitPortabilityProblems="true"
+ Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
CompileAs="1"
DisableSpecificWarnings="4996"
@@ -71,7 +71,7 @@
LinkIncremental="2"
AdditionalLibraryDirectories="..\lib;$(OutDir)"
IgnoreAllDefaultLibraries="false"
- IgnoreDefaultLibraryNames=""
+ IgnoreDefaultLibraryNames="msvcrt"
GenerateDebugInformation="true"
SubSystem="1"
RandomizedBaseAddress="1"
@@ -153,7 +153,7 @@
LinkIncremental="2"
AdditionalLibraryDirectories="..\lib;$(OutDir)"
IgnoreAllDefaultLibraries="false"
- IgnoreDefaultLibraryNames=""
+ IgnoreDefaultLibraryNames="msvcrt"
GenerateDebugInformation="true"
SubSystem="1"
RandomizedBaseAddress="1"
diff --git a/yara-python/tests.py b/yara-python/tests.py
index 4c7331b..4d1e366 100644
--- a/yara-python/tests.py
+++ b/yara-python/tests.py
@@ -261,15 +261,13 @@ class TestYara(unittest.TestCase):
f1.close()
p2 = os.path.join(tmpdir,'test2')
- t2 = open(p2, 'wt')
- t2.write('include "%s" rule test2 { condition: test1 }' % p1)
- t2.close()
+ f2 = open(p2, 'wt')
+ f2.write('include "%s" rule test2 { condition: test1 }' % p1)
+ f2.close()
r = yara.compile(p2)
self.assertTrue(len(r.match(data='dummy')) == 2)
- os.remove(p1)
- os.remove(p2)
def testExternals(self):
@@ -304,5 +302,22 @@ class TestYara(unittest.TestCase):
self.assertTrue(rule_data['matches'])
self.assertTrue(rule_data['rule'] == 'test')
+ def testCompare(self):
+
+ r = yara.compile(sources={
+ 'test1': 'rule test { condition: true}',
+ 'test2': 'rule test { condition: true}'
+ })
+
+ m = r.match(data="dummy")
+
+ self.assertTrue(len(m) == 2)
+ self.assertTrue(m[0] < m[1])
+ self.assertTrue(m[0] != m[1])
+ self.assertFalse(m[0] > m[1])
+ self.assertFalse(m[0] == m[1])
+
+
+
if __name__ == "__main__":
- unittest.main()
\ No newline at end of file
+ unittest.main()
diff --git a/yara-python/yara-python.c b/yara-python/yara-python.c
index d4b3bd7..fe19f51 100644
--- a/yara-python/yara-python.c
+++ b/yara-python/yara-python.c
@@ -78,6 +78,7 @@ typedef struct {
static PyObject * Match_repr(PyObject *self);
static PyObject * Match_getattro(PyObject *self, PyObject *name);
static int Match_compare(PyObject *self, PyObject *other);
+static PyObject * Match_richcompare(PyObject *self, PyObject *other, int op);
static long Match_hash(PyObject *self);
static void Match_dealloc(PyObject *self);
@@ -110,7 +111,7 @@ static PyTypeObject Match_Type = {
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
- Match_compare, /*tp_compare*/
+ 0, /*tp_compare*/
Match_repr, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
@@ -118,14 +119,14 @@ static PyTypeObject Match_Type = {
Match_hash, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
- Match_getattro, /*tp_getattro*/
+ Match_getattro, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
"Match class", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
- 0, /* tp_richcompare */
+ Match_richcompare, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
@@ -186,6 +187,47 @@ static PyObject * Match_getattro(PyObject *self, PyObject *name)
return PyObject_GenericGetAttr(self, name);
}
+
+static PyObject * Match_richcompare(PyObject *self, PyObject *other, int op)
+{
+ Match *a = (Match *) self;
+ Match *b = (Match *) other;
+
+ if(PyObject_TypeCheck(other, &Match_Type))
+ {
+ switch(op)
+ {
+ case Py_EQ:
+
+ if (PyObject_RichCompareBool(a->rule, b->rule, Py_EQ) && PyObject_RichCompareBool(a->ns, b->ns, Py_EQ))
+ return Py_True;
+ else
+ return Py_False;
+
+ case Py_NE:
+
+ if (PyObject_RichCompareBool(a->rule, b->rule, Py_NE) || PyObject_RichCompareBool(a->ns, b->ns, Py_NE))
+ return Py_True;
+ else
+ return Py_False;
+
+ case Py_LT:
+ case Py_LE:
+ case Py_GT:
+ case Py_GE:
+
+ if (PyObject_RichCompareBool(a->rule, b->rule, Py_EQ))
+ return PyObject_RichCompare(a->ns, b->ns, op);
+ else
+ return PyObject_RichCompare(a->rule, b->rule, op);
+
+ }
+ }
+
+ return PyErr_Format(PyExc_TypeError, "'Match' objects must be compared with objects of the same class");
+
+}
+
static int Match_compare(PyObject *self, PyObject *other)
{
int result;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/forensics/yara.git
More information about the forensics-changes
mailing list