30 Commits
Author SHA1 Message Date
Victor M. Alvarez cf3e556478 Implement the --skip-larger command-line option in Windows. (#1678)
Also allow a 64 bits integer as the argument to --skip-larger both in Linux and Windows.
2022-04-06 11:13:58 +02:00
Hilko Bengen 1f56e30000 Fix for MSVC builds (#1653)
* cli/yara: Replace printf with _tprintf in console output callback

This unbreaks output on MSVC-based builds as discussed in #1594

* cli/yara: Fix MSVC warning about incompatible pointers
2022-02-17 11:42:16 +01:00
Wesley Shields f7908b7e83 Fix issue with argument handling. (#1640)
There is an issue with argument handling that is causing issues when scanning
using certain argument combinations. I believe this is similar to
https://github.com/VirusTotal/yara/pull/927. Here's an example of it broken in
master:

wxs@wxs-mbp yara % cat rules/always_true.yara
rule a { condition: true }
wxs@wxs-mbp yara % ./yara -p 1 rules/always_true.yara /bin
wxs@wxs-mbp yara %

And the same thing with this fix:

wxs@wxs-mbp yara % ./yara -p 1 rules/always_true.yara /bin
    a /bin/cat
    a /bin/echo
    a /bin/launchctl
    a /bin/df
<snip>

Issue spotted by: Conor Quigley (https://github.com/schrodyn)
2022-02-01 09:57:02 +01:00
pwrdwnsys b9c91e55cf remove duplicate include for args.h (#1641) 2022-02-01 09:50:25 +01:00
Wesley Shields 723e3c2114 Add console module. (#1594)
Add a console module which can be used to print things during condition
execution. This is especially useful for debugging complex conditions where
you're following multiple offsets. For example, people sometimes want to express
a PE by doing this:

uint32(uint32(0x3c)) == 0x50450000

What they really want is:

uint32be(uint32(0x3c)) == 0x50450000

Or they want:

uint32(uint32(0x3c)) == 0x00004550

In either case it would be helpful if they could do:

console.hex(uint32(uint32(0x3c)))

Another example of where this could be useful is being able to know what YARA
thinks an imphash is just by doing:

console.log(pe.imphash())

* Make console module a default module.

* Add support for optional string messages.

Override each function so that it can also take an optional string that is
printed at the start of the message. Tested with the following:

import "pe"
import "math"
import "console"

rule a {
  condition:
    console.hex("0x3c: ", uint32(uint32(0x3c))) and
    console.hex(uint32(uint32(0x3c))) and
    console.log("String: ", "foo\x00bar\x01baz") and
    console.log("foo\x00bar\x01baz") and
    console.log("Some integer: ", 987654321) and
    console.log(987654321) and
    console.log("Some float: ", math.MEAN_BYTES) and
    console.log(math.MEAN_BYTES) and
    console.log("Imphash: ", pe.imphash()) and
    console.log(pe.imphash())
}

* Remove duplicate macro definitions.

* Make console functions use callback.

Add a CALLBACK_MSG_CONSOLE_LOG which the console module uses to send a message
to the main callback. Make the console module functions all generate a single
string which is then passed to the callback. This keeps the callback handler
simple: it just prints a string.

* Fix newlines.

* Add docs for console functionality.

* Add docs for console_callback to yara-python.

* Address comments from Victor.
2021-12-21 09:33:28 +01:00
Victor M. Alvarez a36b497926 Fix issue #1616 (#1621)
This is a more comprehensive fix than #1617, it adds new functions to the API for getting/setting uint32 and uint64 settings.  Using these functions is preferable over calling `yr_(get|set)_configuration` directly.
2021-12-20 10:31:12 +01:00
Victor M. Alvarez 3d520eddf2 Merge remote-tracking branch 'origin/master' 2021-11-18 10:30:40 +01:00
Victor M. Alvarez e21982a77f Fix issue #1593.
When specifying a namespace with an absolute file path (starting with /) the file was not being found as the namespace was used as part of the path.
2021-11-18 10:29:53 +01:00
Dominika Regéciová bbdfa4f6c7 fix loading module data (#1590) 2021-11-15 09:58:04 +01:00
Victor M. Alvarez 6284650806 Fix description for --skip-larger command-line option. 2021-10-29 15:35:14 +02:00
Victor M. Alvarez 99da5cd7fe Implement --skip-larger command-line option.
Based in #1211.
2021-10-29 12:08:45 +02:00
secDre4merandVictor M. Alvarez 605b2edf07 Add maximum size for process memory chunk (#1393)
Co-authored-by: Victor M. Alvarez <[email protected]>
2021-10-28 16:38:04 +02:00
Ladislav ZezulaandLadislav Zezula 658b689002 Workspaces needs to be set as UNICODE in order to work (#1557)
* Workspaces needs to be set as UNICODE in order to work

* Added consistency

Co-authored-by: Ladislav Zezula <[email protected]>
2021-08-30 11:04:06 +02:00
Victor M. Alvarez 95d8a4a9f5 Take into account that _tcstol can return a negative number, but a pid is always positive. 2021-08-19 10:09:46 +02:00
Victor M. Alvarez 006368be1c Fix style with clang-format. 2021-08-18 09:23:37 +02:00
Wesley Shields b27d80687e Fix edge case with pid check. (#1541)
A common use case (I've run into this many times, as have some friends) is to
run yara against a file named after the hash of the content. If the hash happens
to start with a number yara.c treats it as a PID, and will fail. The workaround
is to prefix the file with "./" (or whatever the equivalent is on Windows) so
that the strol() check fails.

This diff switches the behavior so it treats the argument as a file first, and
only if that can be opened is it then checked for a PID. Further, to ensure the
PID check is accurate I extended it so that the entire argument must be
converted. If there are any characters left after the conversion then it is not
a valid PID and we will not attempt to scan it as it is (by definition) not a
valid file nor a valid PID.
2021-08-18 09:21:34 +02:00
Victor M. Alvarez 7b5e0a31e7 Fix issue #1534 2021-08-09 22:33:08 +02:00
Victor M. Alvarez 8817f6cc34 Fix warning in Coverity.
The warning was caused by the use of strcmp with a string returned by readlink, which doesn't guarantee that the string is null-terminated. In this case the use of strcmp is not required as we are checking only one character.
2021-06-11 10:14:08 +02:00
Victor M. Alvarez 57057e86e8 Implement support for unicode file names in Windows. (#1491) 2021-05-11 13:00:30 +02:00
Victor M. Alvarez e1360f6cbe Fix issue #1481 (#1482) 2021-04-19 15:05:24 +02:00
Victor M. Alvarez b01d9ae56c Minor style changes. 2021-03-15 12:22:07 +01:00
Arnim Rupp 1239afcbd4 Update yara.c (#1453)
1. skip all symlinks pointing to . so you do "yara -r test.yar /usr/bin" on debian without -N (/usr/bin/X11 points to . )
2. Show 64 instead of 32 hex chars (regex are shown in full so there's enough clutter anyway)
2021-03-15 11:54:32 +01:00
Victor M. Alvarez bcb9567cdc Improve warnings (#1465)
Includes the following changes:

* Print the rule identifier in warnings due to strings matching too much. The string identifier is not enough, common identifiers like $a are not very informative.
* Use the same format for compile time warnings and scan time warnings.
* --no-warnings disables the "too many matches" warning.
* --fail-on-warnings makes yara fail with the "too many matches" warning.
* Use the same message format in yara and yarac.
2021-03-15 11:47:12 +01:00
Wesley Shields 95b43693dc Switch maximum string limit to warning. (#1350)
When we hit the maximum match limit on a string we currently abort all scanning,
which can be problematic since it isn't a good reason to stop all scanning, and
is better off as a warning to the user.

This commit makes it so that when the string match limit is hit a warning is
printed and scanning will continue. The warning message indicates that the
results may be invalid. It is hard to know for certain if they are invalid
because it depends entirely upon the condition. If you use the # or @ operator
then your condition _MAY_ be invalid since the total number of matches and
locations is not known anymore. Just checking that the string exists won't be an
invalid state since we have confirmed the existence of _AT LEAST_ the maximum
number of occurrences, which clearly satisfies the existence of a single
instance of your string.

I decided to implement this as a callback so the user of libyara has some choice
on the default behavior. If they want to consider this a "stop all scanning"
error they are free to return CALLBACK_ERROR in their callback.
2020-12-17 10:10:27 +01:00
Hilko Bengen 77b873ce6f Avoid strtok_s usage (#1383)
Apparently, the C standard library in older Windows versions does not
contain strtok_s (see discussiion for PR #1381). Since strtok_s is
only used in the single-threaded code of YARA itself, reentrancy is
not really needed.
2020-10-31 18:53:14 +01:00
Victor M. Alvarez fa5682a98d Homogenize function comments and remove empty lines. 2020-10-19 12:00:53 +02: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 54a7fc83f3 Fix issue while compiling in Windows.
The "recursive" argument has been replaced by "scan_opts->recursive_search" in #1349, but it wasn't changed in Windows-specific code.
2020-09-25 20:03:13 +02:00
Wesley Shields dc8f644b21 Implement -N (--no-follow-symlinks).
Implement a -N flag which causes yara to not follow any symlinks when scanning,
regardless of the recursive option.
2020-09-04 09:10:22 +02:00
Victor M. Alvarez 8d3f8259ad Move command line tools to their own directory. 2020-06-26 09:17:35 +02:00