Skip to content

Commit cba6932

Browse files
plusvicsimonhf
andauthored
Implement non-blocking API (VirusTotal#1428)
With this change the yr_scanner_scan_mem_blocks function can return ERROR_BLOCK_NOT_READY when the YR_MEMORY_BLOCK_ITERATOR that provides memory blocks to the function is not ready to return the next block. After this error the caller can retry the call to yr_scanner_scan_mem_blocks multiple times until the function succeeds or fails with some other error code. Co-authored-by: Simon Hardy-Francis <simonhf@gmail.com>
1 parent 09116e8 commit cba6932

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1992
-570
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,15 @@ test-alignment
6565
test-api
6666
test-arena
6767
test-arena-stream
68+
test-async
6869
test-atoms
6970
test-bitmask
7071
test-elf
7172
test-exception
72-
test-rules
73+
test-rules-pass-1
74+
test-rules-pass-2
75+
test-rules-pass-3
76+
test-rules.yarc
7377
test-pb
7478
test-pe
7579
test-re-split

Makefile.am

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,36 @@ yarac_SOURCES = \
5454
yarac_LDADD = -Llibyara/.libs -lyara
5555
yarac_DEPENDENCIES = libyara/.libs/libyara.la
5656

57-
test_alignment_SOURCES = tests/test-alignment.c
58-
test_arena_SOURCES = tests/test-arena.c
57+
test_alignment_SOURCES = tests/test-alignment.c tests/util.c
58+
test_alignment_LDADD = libyara/.libs/libyara.a
59+
test_arena_SOURCES = tests/test-arena.c tests/util.c
5960
test_arena_LDADD = libyara/.libs/libyara.a
6061
test_atoms_SOURCES = tests/test-atoms.c tests/util.c
6162
test_atoms_LDADD = libyara/.libs/libyara.a
62-
test_rules_SOURCES = tests/test-rules.c tests/util.c
63-
test_rules_LDADD = libyara/.libs/libyara.a
63+
test_rules_pass_1_SOURCES = tests/test-rules-pass-1.c tests/util.c
64+
test_rules_pass_1_LDADD = libyara/.libs/libyara.a
65+
test_rules_pass_2_SOURCES = tests/test-rules-pass-2.c tests/util.c
66+
test_rules_pass_2_LDADD = libyara/.libs/libyara.a
67+
test_rules_pass_3_SOURCES = tests/test-rules-pass-3.c tests/util.c
68+
test_rules_pass_3_LDADD = libyara/.libs/libyara.a
6469
test_pe_SOURCES = tests/test-pe.c tests/util.c
6570
test_pe_LDADD = libyara/.libs/libyara.a
6671
test_elf_SOURCES = tests/test-elf.c tests/util.c
6772
test_elf_LDADD = libyara/.libs/libyara.a
68-
test_version_SOURCES = tests/test-version.c
69-
test_api_LDADD = libyara/.libs/libyara.a
73+
test_version_SOURCES = tests/test-version.c tests/util.c
74+
test_version_LDADD = libyara/.libs/libyara.a
7075
test_api_SOURCES = tests/test-api.c tests/util.c
71-
test_bitmask_SOURCES = tests/test-bitmask.c
76+
test_api_LDADD = libyara/.libs/libyara.a
77+
test_bitmask_SOURCES = tests/test-bitmask.c tests/util.c
7278
test_bitmask_LDADD = libyara/.libs/libyara.a
7379
test_math_SOURCES = tests/test-math.c tests/util.c
7480
test_math_LDADD = libyara/.libs/libyara.a
75-
test_stack_SOURCES = tests/test-stack.c
81+
test_stack_SOURCES = tests/test-stack.c tests/util.c
7682
test_stack_LDADD = libyara/.libs/libyara.a
77-
test_re_split_SOURCES = tests/test-re-split.c
83+
test_re_split_SOURCES = tests/test-re-split.c tests/util.c
7884
test_re_split_LDADD = libyara/.libs/libyara.a
85+
test_async_SOURCES = tests/test-async.c tests/util.c
86+
test_async_LDADD = libyara/.libs/libyara.a
7987

8088
TESTS = $(check_PROGRAMS)
8189
TESTS_ENVIRONMENT = TOP_SRCDIR=$(top_srcdir)
@@ -85,14 +93,17 @@ check_PROGRAMS = \
8593
test-alignment \
8694
test-atoms \
8795
test-api \
88-
test-rules \
96+
test-rules-pass-1 \
97+
test-rules-pass-2 \
98+
test-rules-pass-3 \
8999
test-pe \
90100
test-elf \
91101
test-version \
92102
test-bitmask \
93103
test-math \
94104
test-stack \
95-
test-re-split
105+
test-re-split \
106+
test-async
96107

97108
if POSIX
98109
# The -fsanitize=address option makes test-exception fail. Include the test

docs/capi.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -891,6 +891,31 @@ Functions
891891
892892
Define a string external variable.
893893
894+
.. c:function:: int yr_scanner_scan_mem_blocks(YR_SCANNER* scanner, YR_MEMORY_BLOCK_ITERATOR* iterator)
895+
896+
.. versionadded:: 3.8.0
897+
898+
Scan a serie of memory blocks that are provided by a :c:type:`YR_MEMORY_BLOCK_ITERATOR`.
899+
The iterator has a pair of `first` and `next` functions, that must return
900+
the first and next blocks respectively. The how the data is split in blocks is
901+
up to the iterator implementation.
902+
903+
Returns one of the following error codes:
904+
905+
:c:macro:`ERROR_SUCCESS`
906+
907+
:c:macro:`ERROR_INSUFFICIENT_MEMORY`
908+
909+
:c:macro:`ERROR_TOO_MANY_SCAN_THREADS`
910+
911+
:c:macro:`ERROR_SCAN_TIMEOUT`
912+
913+
:c:macro:`ERROR_CALLBACK_ERROR`
914+
915+
:c:macro:`ERROR_TOO_MANY_MATCHES`
916+
917+
:c:macro:`ERROR_BLOCK_NOT_READY`
918+
894919
.. c:function:: int yr_scanner_scan_mem(YR_SCANNER* scanner, const uint8_t* buffer, size_t buffer_size)
895920
896921
.. versionadded:: 3.8.0
@@ -1000,3 +1025,7 @@ Error codes
10001025
your rules contains very short or very common strings like ``01 02`` or
10011026
``FF FF FF FF``. The limit is defined by ``YR_MAX_STRING_MATCHES`` in
10021027
*./include/yara/limits.h*
1028+
1029+
.. c:macro:: ERROR_BLOCK_NOT_READY
1030+
1031+
Next memory block to scan is not ready; custom iterators may return this.

0 commit comments

Comments
 (0)