41 Commits
Author SHA1 Message Date
Victor M. Alvarez 3395fee53c Remove assertion from test-aligment.c
`off_t` is not 64 bits in all platforms (like Win32)
2024-04-08 10:53:32 +02:00
Victor M. Alvarez 833a580430 Fix issue #2050.
See also PR #2048.
2024-04-07 17:56:43 +02:00
Victor M. Alvarez 7b4dcd8cce Fix alignment tests.
They were returning OK in all cases, it was broken in cba6932759.
2024-04-07 17:56:36 +02:00
Victor M. Alvarez 3484fcb60b Fix multiple memory alignment issues. (#1724)
The x86 platform is very forgiving when you access a 16-bits variable stored at a memory address that is not aligned to a 2-bytes boundary, or a 32-bits variable that is not aligned to 4-bytes boundary, and so on. Other platforms, like ARM or Sparc are not that flexible, and accessing a value by dereferencing a pointer that is not aligned to the size of the value causes a processor fault.

This fixes multiple issues caused by pointers that are not aligned to the size of the value.

Fixes: #1700
2022-06-07 09:37:27 +02:00
Victor M. Alvarez ac5eae7137 Simplify test-rules by putting running the all the passes in a single binary.
This makes easier to build the tests with Bazel. Also fix some issues with Bazel configuration.
2021-01-12 20:52:55 +01:00
Victor M. AlvarezandSimon Hardy-Francis cba6932759 Implement non-blocking API (#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 <[email protected]>
2020-12-24 10:46:09 +01:00
Victor M. Alvarez 0bce4bd74d Start using clang-format for formatting the code automatically. 2020-10-07 16:27:30 +02:00
Victor M. Alvarez 65904503c9 Change packing of SIZED_STRING from 4 bytes to 1.
This removes 3 unused bytes at the end of each SIZED_STRING. Those 3 bytes are not initialized by alloc_sized_string and cause MemorySanitizer to fail with use-of-uninitialized-value.
2020-07-16 23:22:06 +02:00
Victor M. Alvarez 54eb7c35db Change the way in which the last meta for each rule is marked.
Use a flag for marking the last meta, instead of inserting an empty meta at the end of the list.
2020-03-17 16:44:20 +01:00
Victor M. Alvarez 456b41637d Refactor the way in which YR_AC_MATCH structures are written in the final compiled rules.
This change makes the compiled rules smaller and saves memory during the compilation phase.
2020-03-11 11:04:50 +01:00
Victor M. Alvarez b1bfc3f38b Fix alignment issues. 2020-03-04 19:22:15 +01:00
Victor M. Alvarez b214e7ed08 Fix alignment test cases. 2020-03-04 18:23:37 +01:00
Victor M. Alvarez 7878905230 Remove unused fields and reorganize fields in some structs to make them more cache friendly. 2020-03-02 23:28:32 +01:00
Victor M. Alvarez 62be88c654 Change the way in which lists of Aho-Corasick matches are encoded. 2020-03-02 21:15:47 +01:00
Victor M. Alvarez 9863159134 Remove unused types. 2020-02-28 19:25:11 +01:00
Victor M. Alvarez b68deed0c3 Remove all remaining dependencies from tidx (except for the "magic" module). 2020-02-27 19:54:11 +01:00
Victor M. Alvarez 2b121b166d Track string matches using YR_SCAN_CONTEXT. 2020-02-27 13:51:47 +01:00
Victor M. Alvarez 34ec34fbe1 Start using bitmap for tracking rule matches. 2020-02-27 09:34:29 +01:00
Victor M. Alvarez 8ce23fe46f Add Aho-Corasick automaton to new arena. 2020-02-26 20:45:18 +01:00
Victor M. Alvarez 9c8ac05800 Rules moved to new arena. 2020-02-21 12:58:14 +01:00
Wesley Shields 37aae685c2 Private strings (#1096)
* Add private modifier for strings.

This commit adds a private modifier to the grammar, which can be used on any
string. When this modifier is used the string is treated as normal except it is
never reported back in match objects. It is still searched for normally and
still used normally in condition evaluation but it will never be seen in the
match callback.

This is a useful feature when you have strings that you want to use but they
match a lot of times and you don't want them polluting your log results. The
best example that demonstrates this is the technique described at [1]. In this
example the local file header magic is going to match a lot of times, and it is
only needed to look through the local file header for filenames at offsets
relative to the matches. We don't really care where the offsets of the local
file header are, just where the matching filenames are.

If you are logging where all the matches are for every string and there are
10,000 local file headers that's a lot of log data being generated which is not
helpful at all.

[1]: https://blog.korelogic.com/blog/2015/08/19/yara-ctf-2

* Optimize VM execution code for private strings.

Rather than checking the matches list and only if none are found then check for
private matches, it's better to check only the appropriate list after using
STRING_IS_PRIVATE.

* Add private strings in various tests.

This should cover all the cases of operators on strings that also need to check
for private strings.

* Add docs for private strings.

* Fixup documentation.

Private strings apply to all string types, not just text strings.

* Fix private modifier for chained strings. Add a test case for it too.
2019-08-05 08:38:57 +02:00
Victor M. Alvarez e748df2139 Add num_atoms field to YR_RULE structure. 2018-08-23 13:55:08 +02:00
Victor M. Alvarez 72fd000469 Fix contention while incrementing profiling counters.
In 3cceccd8b6 the increment of profiling counters was changed to an atomic operation. This fixed race-conditions but introduced a noticeable contention while using the same YR_RULES structure with multiple threads. This commit fixes this problem by using one counter per thread, which are aggregated later, outside the critical path.
2018-08-20 14:57:45 +02:00
Victor M. Alvarez 2f72bbfc26 Implement calculation of atom quality based in a prevalence table (#904)
With this new feature you can pass an atom prevalence table to YARA that will be used for computing the quality of each atom based in real-life data instead of using heuristics. The atom prevalence table consists in a list of atoms, sorted lexicographically and accompanied by a score between 0-255 that indicates how frequent is that atom in the data you use to scan with YARA.  With that information YARA can make better selection of the atoms.
2018-07-06 08:59:39 +02:00
Victor M. Alvarez 0681581e84 Add size of Aho-Corasick transition table and match table to the header of compiled rules.
Having this size in the header facilitates iterating over the tables for computing statistics about the Aho-Corasick automaton.
2018-05-07 16:09:26 +02:00
Victor M. Alvarez f35c29dc8c Implement yr_scanner_last_error_string and yr_scanner_last_error_rule functions for getting information about the rule and string that caused a scanning error.
For implementing this feature it was necessary to add a new field to YR_STRING pointing to the YR_RULE that owns the string.
2018-02-13 17:36:12 +01:00
Victor M. Alvarez 31c198d9df Remove dependencies from PROFILING_ENABLED in test cases. 2017-10-02 09:50:54 +02:00
plusvic 5df6581e3b Fix alignment tests 2017-04-26 20:01:07 +02:00
Victor M. Alvarez 6df98f2121 Improve regexp engine
This commit implements two new opcodes for regular expressions and replaces _yr_scan_fast_re_exec with a cleaner implementation in yr_re_fast_scan, as the existing implementation used some hacks that were hard to maintain.
2017-03-15 16:05:43 +01:00
Hilko Bengen 685ec9cf39 Bump ARENA_FILE_VERSION, add corresponding check to tests (#468) 2016-06-27 16:57:49 +02:00
plusvic 3a53f063c6 Change license to 3-clause BSD 2016-06-24 16:35:15 +02:00
Hilko Bengen 9e50e4d39e Travis: Show test-suite.log on failure (#467)
* Travis: Show test-suite.log on failure

* Fix alignment tests to account for change made in 7ff47de

* Travis: Configure 32-bit build without support for cuckoo, magic
2016-06-23 22:46:34 +01:00
Victor M. Alvarez b8d6e875d9 Merge pull request #447 from hillu/fix-sized-string
Fix issue #446
2016-06-16 13:55:33 +01:00
plusvic 89a305f91d Fix issue introduced in 23759af0b2
YR_MATCH was keeping a pointer to the original scanned data. With the introduction of iterator logic the original data is not guaranteed to be in memory by the time YR_MATCH is passed to library clients. Now a copy of the matching string is kept alongside the YR_MATCH structure.
2016-06-14 20:29:05 +02:00
Hilko Bengen 0fcee7ad3d tests: Check layout of SIZED_STRING
The parser writes SIZED_STRING structs directly into arenas that get
serialized to disk, so the layout of this struct is part of the file
format.
2016-05-31 15:42:38 +02:00
plusvic d7699c65ee Remove YR_AC_STATE and YR_AC_AUTOMATON from alignments tests
These two structures are not saved as part of compiled rules anymore, so the checks are not necessary.
2016-05-30 12:40:56 +02:00
Hilko Bengen e987ce3140 test-alignment: Fix number formatting in printf 2016-05-25 01:46:34 +02:00
plusvic 2cc68242ec Fix alignment tests 2016-05-16 12:56:33 +02:00
plusvic 0db16d3639 Implement Aho-Corasick automaton with interleaved arrays.
This improves both the performance and the memory footprint.
2016-05-16 12:21:42 +02:00
plusvic 2976bacd82 Apply YARA's coding style to tests 2016-02-29 16:37:05 +01:00
Victor Manuel Alvarez 738ca45032 Move tests out of libyara 2016-01-21 23:44:03 +01:00