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
e2cb4e39
Commit
e2cb4e39
authored
7 years ago
by
Wesley Shields
Committed by
Victor M. Alvarez
7 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a 'which_callback' keyword to match(), which limits when the python callback will be called.
parent
2587a645
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
4 deletions
+20
-4
yara-python.c
yara-python.c
+20
-4
No files found.
yara-python.c
View file @
e2cb4e39
...
@@ -389,6 +389,7 @@ typedef struct _CALLBACK_DATA
...
@@ -389,6 +389,7 @@ typedef struct _CALLBACK_DATA
PyObject
*
callback
;
PyObject
*
callback
;
PyObject
*
modules_data
;
PyObject
*
modules_data
;
PyObject
*
modules_callback
;
PyObject
*
modules_callback
;
int
which
;
}
CALLBACK_DATA
;
}
CALLBACK_DATA
;
...
@@ -551,6 +552,10 @@ PyObject* convert_dictionary_to_python(
...
@@ -551,6 +552,10 @@ PyObject* convert_dictionary_to_python(
}
}
#define CALLBACK_ALL 0x01
#define CALLBACK_MATCHES 0x02
#define CALLBACK_NON_MATCHES 0x04
int
yara_callback
(
int
yara_callback
(
int
message
,
int
message
,
void
*
message_data
,
void
*
message_data
,
...
@@ -578,6 +583,7 @@ int yara_callback(
...
@@ -578,6 +583,7 @@ int yara_callback(
PyObject
*
module_data
;
PyObject
*
module_data
;
PyObject
*
callback_result
;
PyObject
*
callback_result
;
PyObject
*
module_info_dict
;
PyObject
*
module_info_dict
;
int
which
=
((
CALLBACK_DATA
*
)
user_data
)
->
which
;
Py_ssize_t
data_size
;
Py_ssize_t
data_size
;
PyGILState_STATE
gil_state
;
PyGILState_STATE
gil_state
;
...
@@ -587,7 +593,12 @@ int yara_callback(
...
@@ -587,7 +593,12 @@ int yara_callback(
if
(
message
==
CALLBACK_MSG_SCAN_FINISHED
)
if
(
message
==
CALLBACK_MSG_SCAN_FINISHED
)
return
CALLBACK_CONTINUE
;
return
CALLBACK_CONTINUE
;
if
(
message
==
CALLBACK_MSG_RULE_NOT_MATCHING
&&
callback
==
NULL
)
if
(
message
==
CALLBACK_MSG_RULE_NOT_MATCHING
&&
(
callback
==
NULL
||
which
&
CALLBACK_MATCHES
))
return
CALLBACK_CONTINUE
;
if
(
message
==
CALLBACK_MSG_RULE_MATCHING
&&
(
callback
==
NULL
||
which
&
CALLBACK_NON_MATCHES
))
return
CALLBACK_CONTINUE
;
return
CALLBACK_CONTINUE
;
if
(
message
==
CALLBACK_MSG_IMPORT_MODULE
&&
modules_data
==
NULL
)
if
(
message
==
CALLBACK_MSG_IMPORT_MODULE
&&
modules_data
==
NULL
)
...
@@ -1331,7 +1342,7 @@ static PyObject* Rules_match(
...
@@ -1331,7 +1342,7 @@ static PyObject* Rules_match(
static
char
*
kwlist
[]
=
{
static
char
*
kwlist
[]
=
{
"filepath"
,
"pid"
,
"data"
,
"externals"
,
"filepath"
,
"pid"
,
"data"
,
"externals"
,
"callback"
,
"fast"
,
"timeout"
,
"modules_data"
,
"callback"
,
"fast"
,
"timeout"
,
"modules_data"
,
"modules_callback"
,
NULL
"modules_callback"
,
"which_callbacks"
,
NULL
};
};
char
*
filepath
=
NULL
;
char
*
filepath
=
NULL
;
...
@@ -1354,11 +1365,12 @@ static PyObject* Rules_match(
...
@@ -1354,11 +1365,12 @@ static PyObject* Rules_match(
callback_data
.
callback
=
NULL
;
callback_data
.
callback
=
NULL
;
callback_data
.
modules_data
=
NULL
;
callback_data
.
modules_data
=
NULL
;
callback_data
.
modules_callback
=
NULL
;
callback_data
.
modules_callback
=
NULL
;
callback_data
.
which
=
CALLBACK_ALL
;
if
(
PyArg_ParseTupleAndKeywords
(
if
(
PyArg_ParseTupleAndKeywords
(
args
,
args
,
keywords
,
keywords
,
"|sis#OOOiOO"
,
"|sis#OOOiOO
i
"
,
kwlist
,
kwlist
,
&
filepath
,
&
filepath
,
&
pid
,
&
pid
,
...
@@ -1369,7 +1381,8 @@ static PyObject* Rules_match(
...
@@ -1369,7 +1381,8 @@ static PyObject* Rules_match(
&
fast
,
&
fast
,
&
timeout
,
&
timeout
,
&
callback_data
.
modules_data
,
&
callback_data
.
modules_data
,
&
callback_data
.
modules_callback
))
&
callback_data
.
modules_callback
,
&
callback_data
.
which
))
{
{
if
(
filepath
==
NULL
&&
data
==
NULL
&&
pid
==
0
)
if
(
filepath
==
NULL
&&
data
==
NULL
&&
pid
==
0
)
{
{
...
@@ -2136,6 +2149,9 @@ MOD_INIT(yara)
...
@@ -2136,6 +2149,9 @@ MOD_INIT(yara)
PyModule_AddIntConstant
(
m
,
"CALLBACK_CONTINUE"
,
0
);
PyModule_AddIntConstant
(
m
,
"CALLBACK_CONTINUE"
,
0
);
PyModule_AddIntConstant
(
m
,
"CALLBACK_ABORT"
,
1
);
PyModule_AddIntConstant
(
m
,
"CALLBACK_ABORT"
,
1
);
PyModule_AddIntConstant
(
m
,
"CALLBACK_ALL"
,
CALLBACK_ALL
);
PyModule_AddIntConstant
(
m
,
"CALLBACK_MATCHES"
,
CALLBACK_MATCHES
);
PyModule_AddIntConstant
(
m
,
"CALLBACK_NON_MATCHES"
,
CALLBACK_NON_MATCHES
);
PyModule_AddStringConstant
(
m
,
"__version__"
,
YR_VERSION
);
PyModule_AddStringConstant
(
m
,
"__version__"
,
YR_VERSION
);
PyModule_AddStringConstant
(
m
,
"YARA_VERSION"
,
YR_VERSION
);
PyModule_AddStringConstant
(
m
,
"YARA_VERSION"
,
YR_VERSION
);
PyModule_AddIntConstant
(
m
,
"YARA_VERSION_HEX"
,
YR_VERSION_HEX
);
PyModule_AddIntConstant
(
m
,
"YARA_VERSION_HEX"
,
YR_VERSION_HEX
);
...
...
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