Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
common_helper_yara
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
common_helper_yara
Commits
d2428d28
Commit
d2428d28
authored
Jun 27, 2017
by
Peter Weidenbach
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get_all_matched_strings_function added
parent
e18fbbd0
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
1 deletions
+36
-1
__init__.py
common_helper_yara/__init__.py
+3
-1
yara_interpretation.py
common_helper_yara/yara_interpretation.py
+20
-0
test_interpretation.py
tests/test_interpretation.py
+13
-0
No files found.
common_helper_yara/__init__.py
View file @
d2428d28
from
.yara_scan
import
scan
from
.yara_scan
import
scan
from
.yara_compile
import
compile_rules
from
.yara_compile
import
compile_rules
from
.yara_interpretation
import
get_all_matched_strings
__all__
=
[
__all__
=
[
'scan'
,
'scan'
,
'compile_rules'
'compile_rules'
,
'get_all_matched_strings'
]
]
common_helper_yara/yara_interpretation.py
0 → 100644
View file @
d2428d28
def
get_all_matched_strings
(
yara_result_dict
):
'''
returns a set of all matched strings
:param yara_result_dict: a result dict
:type yara_result_dict: dict
:return: set
'''
matched_strings
=
set
()
for
matched_rule
in
yara_result_dict
:
matched_strings
.
update
(
_get_matched_strings_of_single_rule
(
yara_result_dict
[
matched_rule
]))
return
matched_strings
def
_get_matched_strings_of_single_rule
(
yara_match
):
matched_strings
=
set
()
print
(
yara_match
[
'strings'
])
for
string_item
in
yara_match
[
'strings'
]:
matched_strings
.
add
(
string_item
[
2
])
return
matched_strings
tests/test_interpretation.py
0 → 100644
View file @
d2428d28
import
unittest
from
common_helper_yara.yara_interpretation
import
get_all_matched_strings
class
TestYaraInterpretation
(
unittest
.
TestCase
):
def
test_get_all_matched_strings
(
self
):
test_data
=
{
'test_rule'
:
{
'rule'
:
'test_rule'
,
'meta'
:
{},
'strings'
:
[(
0
,
'$a'
,
b
'test_1'
),
(
10
,
'$b'
,
b
'test_2'
)],
'matches'
:
True
},
'test_rule2'
:
{
'rule'
:
'test_rule2'
,
'meta'
:
{},
'strings'
:
[(
0
,
'$a'
,
b
'test_1'
),
(
10
,
'$b'
,
b
'test_3'
)],
'matches'
:
True
},
}
result
=
get_all_matched_strings
(
test_data
)
self
.
assertEqual
(
result
,
set
([
b
'test_1'
,
b
'test_2'
,
b
'test_3'
]),
"resulting strings not correct"
)
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