Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yara-python
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
fact-depend
yara-python
Commits
9dc95614
Unverified
Commit
9dc95614
authored
4 years ago
by
Dominika Regéciová
Committed by
GitHub
4 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Print all warnings with error_on_warning (#157)
parent
fa3795f9
master
…
v4.4.0
v4.3.1
v4.3.0
v4.2.3
v4.2.0
v4.1.3
v4.1.2
v4.1.0
v4.0.5
No related merge requests found
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
50 additions
and
36 deletions
+50
-36
yara-python.c
yara-python.c
+50
-36
No files found.
yara-python.c
View file @
9dc95614
...
...
@@ -47,14 +47,20 @@ typedef long Py_hash_t;
#if PY_MAJOR_VERSION >= 3
#define PY_STRING(x) PyUnicode_DecodeUTF8(x, strlen(x), "ignore" )
#define PY_STRING_FORMAT(...) PyUnicode_FromFormat(__VA_ARGS__)
#define PY_STRING_TO_C(x) PyUnicode_AsUTF8(x)
#define PY_STRING_CHECK(x) PyUnicode_Check(x)
#else
#define PY_STRING(x) PyString_FromString(x)
#define PY_STRING_FORMAT(...) PyString_FromFormat(__VA_ARGS__)
#define PY_STRING_TO_C(x) PyString_AsString(x)
#define PY_STRING_CHECK(x) (PyString_Check(x) || PyUnicode_Check(x))
#endif
#if PY_VERSION_HEX < 0x03020000
#define PyDescr_NAME(x) (((PyDescrObject*)x)->d_name)
#endif
/* Module globals */
static
PyObject
*
YaraError
=
NULL
;
...
...
@@ -1711,51 +1717,27 @@ void raise_exception_on_error(
line_number
,
message
);
}
}
void
raise_exception_on_error_or_warning
(
int
error_level
,
const
char
*
file_name
,
int
line_number
,
const
YR_RULE
*
rule
,
const
char
*
message
,
void
*
user_data
)
{
if
(
error_level
==
YARA_ERROR_LEVEL_ERROR
)
{
if
(
file_name
!=
NULL
)
PyErr_Format
(
YaraSyntaxError
,
"%s(%d): %s"
,
file_name
,
line_number
,
message
);
else
PyErr_Format
(
YaraSyntaxError
,
"line %d: %s"
,
line_number
,
message
);
}
else
{
PyObject
*
warnings
=
(
PyObject
*
)
user_data
;
PyObject
*
warning_msg
;
if
(
file_name
!=
NULL
)
PyErr_Format
(
YaraWarningError
,
warning_msg
=
PY_STRING_FORMAT
(
"%s(%d): %s"
,
file_name
,
line_number
,
message
);
else
PyErr_Format
(
YaraWarningError
,
warning_msg
=
PY_STRING_FORMAT
(
"line %d: %s"
,
line_number
,
message
);
PyList_Append
(
warnings
,
warning_msg
);
Py_DECREF
(
warning_msg
);
}
}
////////////////////////////////////////////////////////////////////////////////
const
char
*
yara_include_callback
(
...
...
@@ -1951,6 +1933,8 @@ static PyObject* yara_compile(
char
*
filepath
=
NULL
;
char
*
source
=
NULL
;
char
*
ns
=
NULL
;
PyObject
*
warnings
=
PyList_New
(
0
);
bool
warning_error
=
false
;
if
(
PyArg_ParseTupleAndKeywords
(
args
,
...
...
@@ -1973,7 +1957,7 @@ static PyObject* yara_compile(
if
(
error
!=
ERROR_SUCCESS
)
return
handle_error
(
error
,
NULL
);
yr_compiler_set_callback
(
compiler
,
raise_exception_on_error
,
NULL
);
yr_compiler_set_callback
(
compiler
,
raise_exception_on_error
,
warnings
);
if
(
error_on_warning
!=
NULL
)
{
...
...
@@ -1981,10 +1965,7 @@ static PyObject* yara_compile(
{
if
(
PyObject_IsTrue
(
error_on_warning
)
==
1
)
{
yr_compiler_set_callback
(
compiler
,
raise_exception_on_error_or_warning
,
NULL
);
warning_error
=
true
;
}
}
else
...
...
@@ -2170,6 +2151,13 @@ static PyObject* yara_compile(
"compile() takes 1 argument"
);
}
if
(
warning_error
&
PyList_Size
(
warnings
)
>
0
)
{
PyErr_SetObject
(
YaraWarningError
,
warnings
);
}
Py_DECREF
(
warnings
);
if
(
PyErr_Occurred
()
==
NULL
)
{
rules
=
Rules_NEW
();
...
...
@@ -2371,6 +2359,24 @@ static PyMethodDef yara_methods[] = {
ob = Py_InitModule3(name, methods, doc);
#endif
static
PyObject
*
YaraWarningError_getwarnings
(
PyObject
*
self
,
void
*
closure
)
{
PyObject
*
args
=
PyObject_GetAttrString
(
self
,
"args"
);
if
(
!
args
)
{
return
NULL
;
}
PyObject
*
ret
=
PyTuple_GetItem
(
args
,
0
);
Py_XINCREF
(
ret
);
Py_XDECREF
(
args
);
return
ret
;
}
static
PyGetSetDef
YaraWarningError_getsetters
[]
=
{
{
"warnings"
,
YaraWarningError_getwarnings
,
NULL
,
NULL
,
NULL
},
{
NULL
}
};
MOD_INIT
(
yara
)
{
...
...
@@ -2397,6 +2403,14 @@ MOD_INIT(yara)
YaraSyntaxError
=
PyErr_NewException
(
"yara.SyntaxError"
,
YaraError
,
NULL
);
YaraTimeoutError
=
PyErr_NewException
(
"yara.TimeoutError"
,
YaraError
,
NULL
);
YaraWarningError
=
PyErr_NewException
(
"yara.WarningError"
,
YaraError
,
NULL
);
PyTypeObject
*
YaraWarningError_type
=
(
PyTypeObject
*
)
YaraWarningError
;
PyObject
*
descr
=
PyDescr_NewGetSet
(
YaraWarningError_type
,
YaraWarningError_getsetters
);
if
(
PyDict_SetItem
(
YaraWarningError_type
->
tp_dict
,
PyDescr_NAME
(
descr
),
descr
)
<
0
)
{
Py_DECREF
(
m
);
Py_DECREF
(
descr
);
}
Py_DECREF
(
descr
);
#else
YaraError
=
Py_BuildValue
(
"s"
,
"yara.Error"
);
YaraSyntaxError
=
Py_BuildValue
(
"s"
,
"yara.SyntaxError"
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment