yara-ffi 3.1.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/copilot-instructions.md +266 -0
- data/.github/workflows/ruby.yml +69 -17
- data/CHANGELOG.md +90 -1
- data/DEVELOPMENT.md +188 -0
- data/Dockerfile +19 -11
- data/Gemfile.lock +38 -23
- data/README.md +56 -36
- data/USAGE.md +747 -0
- data/lib/yara/compiler.rb +161 -0
- data/lib/yara/ffi.rb +500 -111
- data/lib/yara/pattern_match.rb +178 -0
- data/lib/yara/scan_result.rb +573 -71
- data/lib/yara/scan_results.rb +224 -0
- data/lib/yara/scanner.rb +436 -45
- data/lib/yara/version.rb +5 -1
- data/lib/yara.rb +73 -15
- data/yara-ffi.gemspec +4 -4
- metadata +13 -15
- data/lib/yara/user_data.rb +0 -5
- data/lib/yara/yr_meta.rb +0 -10
- data/lib/yara/yr_namespace.rb +0 -5
- data/lib/yara/yr_rule.rb +0 -11
- data/lib/yara/yr_string.rb +0 -15
data/Dockerfile
CHANGED
@@ -1,17 +1,25 @@
|
|
1
|
-
FROM ruby:2.6.6
|
2
1
|
|
3
|
-
|
4
|
-
|
2
|
+
FROM ruby:3.3
|
3
|
+
|
4
|
+
RUN apt-get update -qq \
|
5
|
+
&& apt-get install -y curl git unzip
|
5
6
|
|
6
7
|
WORKDIR /app
|
7
8
|
|
8
9
|
COPY . ./
|
9
|
-
RUN gem install bundler:2.2.15
|
10
|
-
|
10
|
+
RUN gem install bundler:2.2.15 \
|
11
|
+
&& bundle install
|
12
|
+
|
13
|
+
# Install Rust and cargo-c for building YARA-X C API
|
14
|
+
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y \
|
15
|
+
&& . $HOME/.cargo/env \
|
16
|
+
&& cargo install cargo-c
|
17
|
+
|
18
|
+
# Build and install YARA-X C API library
|
19
|
+
RUN . $HOME/.cargo/env \
|
20
|
+
&& git clone --depth 1 --branch v1.5.0 https://github.com/VirusTotal/yara-x.git /tmp/yara-x \
|
21
|
+
&& cd /tmp/yara-x \
|
22
|
+
&& cargo cinstall -p yara-x-capi --release \
|
23
|
+
&& rm -rf /tmp/yara-x
|
11
24
|
|
12
|
-
|
13
|
-
cd /tmp/yara/ && \
|
14
|
-
./bootstrap.sh && \
|
15
|
-
./configure && \
|
16
|
-
make && \
|
17
|
-
make install
|
25
|
+
ENV PATH="/usr/local/bin:$PATH"
|
data/Gemfile.lock
CHANGED
@@ -1,44 +1,59 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
yara-ffi (
|
4
|
+
yara-ffi (4.1.0)
|
5
5
|
ffi
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
ast (2.4.
|
10
|
+
ast (2.4.3)
|
11
11
|
coderay (1.1.3)
|
12
|
-
ffi (1.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
12
|
+
ffi (1.17.2)
|
13
|
+
ffi (1.17.2-aarch64-linux-gnu)
|
14
|
+
ffi (1.17.2-arm64-darwin)
|
15
|
+
ffi (1.17.2-x86_64-darwin)
|
16
|
+
ffi (1.17.2-x86_64-linux-gnu)
|
17
|
+
json (2.13.2)
|
18
|
+
language_server-protocol (3.17.0.5)
|
19
|
+
lint_roller (1.1.0)
|
20
|
+
method_source (1.1.0)
|
21
|
+
minitest (5.25.5)
|
22
|
+
parallel (1.27.0)
|
23
|
+
parser (3.3.9.0)
|
17
24
|
ast (~> 2.4.1)
|
18
|
-
|
25
|
+
racc
|
26
|
+
prism (1.4.0)
|
27
|
+
pry (0.15.2)
|
19
28
|
coderay (~> 1.1)
|
20
29
|
method_source (~> 1.0)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
rubocop (1.
|
30
|
+
racc (1.8.1)
|
31
|
+
rainbow (3.1.1)
|
32
|
+
rake (13.3.0)
|
33
|
+
regexp_parser (2.11.2)
|
34
|
+
rubocop (1.79.2)
|
35
|
+
json (~> 2.3)
|
36
|
+
language_server-protocol (~> 3.17.0.2)
|
37
|
+
lint_roller (~> 1.1.0)
|
26
38
|
parallel (~> 1.10)
|
27
|
-
parser (>= 3.
|
39
|
+
parser (>= 3.3.0.2)
|
28
40
|
rainbow (>= 2.2.2, < 4.0)
|
29
|
-
regexp_parser (>=
|
30
|
-
|
31
|
-
rubocop-ast (>= 1.2.0, < 2.0)
|
41
|
+
regexp_parser (>= 2.9.3, < 3.0)
|
42
|
+
rubocop-ast (>= 1.46.0, < 2.0)
|
32
43
|
ruby-progressbar (~> 1.7)
|
33
|
-
unicode-display_width (>=
|
34
|
-
rubocop-ast (1.
|
35
|
-
parser (>=
|
36
|
-
|
37
|
-
|
44
|
+
unicode-display_width (>= 2.4.0, < 4.0)
|
45
|
+
rubocop-ast (1.46.0)
|
46
|
+
parser (>= 3.3.7.2)
|
47
|
+
prism (~> 1.4)
|
48
|
+
ruby-progressbar (1.13.0)
|
49
|
+
unicode-display_width (3.1.5)
|
50
|
+
unicode-emoji (~> 4.0, >= 4.0.4)
|
51
|
+
unicode-emoji (4.0.4)
|
38
52
|
|
39
53
|
PLATFORMS
|
40
54
|
aarch64-linux
|
41
55
|
arm64-darwin-21
|
56
|
+
ruby
|
42
57
|
x86_64-darwin-19
|
43
58
|
x86_64-linux
|
44
59
|
|
@@ -50,4 +65,4 @@ DEPENDENCIES
|
|
50
65
|
yara-ffi!
|
51
66
|
|
52
67
|
BUNDLED WITH
|
53
|
-
2.
|
68
|
+
2.7.1
|
data/README.md
CHANGED
@@ -1,13 +1,34 @@
|
|
1
1
|
# yara-ffi
|
2
2
|
|
3
|
-
A Ruby library for using [
|
3
|
+
A Ruby library for using [YARA-X](https://virustotal.github.io/yara-x/) via FFI bindings. YARA-X is a modern, Rust-based implementation of YARA that's faster and safer than the original C implementation.
|
4
|
+
|
5
|
+
## Requirements
|
6
|
+
|
7
|
+
- Ruby 3.0 or later
|
8
|
+
- YARA-X C API library (`libyara_x_capi`) installed on your system
|
9
|
+
|
10
|
+
## Major Features
|
11
|
+
|
12
|
+
**🔍 Pattern Matching Analysis**: Extract detailed pattern match information with exact offsets, lengths, and matched data - perfect for forensic analysis.
|
13
|
+
|
14
|
+
**🛠️ Advanced Rule Compilation**: Use the `Yara::Compiler` class for complex scenarios with global variables, structured error reporting, and multiple rule sources.
|
15
|
+
|
16
|
+
**💾 Rule Serialization**: Compile rules once, serialize for persistence or transport, then deserialize for instant scanning - eliminating compilation overhead.
|
17
|
+
|
18
|
+
**🏷️ Metadata & Tags**: Full access to rule metadata with type safety and tag-based rule categorization and filtering.
|
19
|
+
|
20
|
+
**🌐 Global Variables**: Set string, boolean, integer, and float globals at runtime to customize rule behavior dynamically.
|
21
|
+
|
22
|
+
**📁 Namespace Support**: Organize rules logically, avoid naming conflicts, and access qualified rule names in large rule sets.
|
23
|
+
|
24
|
+
**⚡ Performance**: Configurable scan timeouts, efficient resource management with automatic cleanup, and parallel scanning support.
|
4
25
|
|
5
26
|
## Installation
|
6
27
|
|
7
28
|
Add this line to your application's Gemfile:
|
8
29
|
|
9
30
|
```ruby
|
10
|
-
gem "yara"
|
31
|
+
gem "yara-ffi"
|
11
32
|
```
|
12
33
|
|
13
34
|
And then execute:
|
@@ -18,49 +39,48 @@ Or install it yourself as:
|
|
18
39
|
|
19
40
|
$ gem install yara-ffi
|
20
41
|
|
21
|
-
##
|
42
|
+
## Quick Start
|
22
43
|
|
23
44
|
```ruby
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
{
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
condition:
|
37
|
-
$my_text_string or $my_text_regex
|
38
|
-
}
|
39
|
-
RULE
|
40
|
-
|
41
|
-
scanner = Yara::Scanner.new
|
42
|
-
scanner.add_rule(rule)
|
43
|
-
scanner.compile
|
44
|
-
result = scanner.call("one day we were here and then we were not").first
|
45
|
-
result.match?
|
46
|
-
# => true
|
47
|
-
|
48
|
-
scanner.close # run when you are done using the scanner API and want to free up memory.
|
49
|
-
Yara.stop # run when you are completely done using the Yara API to free up memory.
|
45
|
+
require 'yara'
|
46
|
+
|
47
|
+
# Simple test
|
48
|
+
results = Yara.test(rule_string, data)
|
49
|
+
puts "Matched: #{results.first.rule_name}" if results.first&.match?
|
50
|
+
|
51
|
+
# Resource-managed scanning
|
52
|
+
Yara::Scanner.open(rule) do |scanner|
|
53
|
+
scanner.compile
|
54
|
+
results = scanner.scan(data)
|
55
|
+
end
|
50
56
|
```
|
51
57
|
|
58
|
+
**📖 For comprehensive usage examples, advanced features, and API documentation, see [USAGE.md](USAGE.md).**
|
59
|
+
|
60
|
+
## API Overview
|
61
|
+
|
62
|
+
**Core Classes**: `Yara`, `Yara::Scanner`, `Yara::Compiler`, `Yara::ScanResult`, `Yara::ScanResults`, `Yara::PatternMatch`
|
63
|
+
|
64
|
+
**Key Methods**: `Yara.test()`, `Yara.scan()`, `Scanner.open()`, `Scanner#scan()`, `ScanResult#pattern_matches`
|
65
|
+
|
66
|
+
**📖 For detailed API documentation, examples, and advanced usage patterns, see [USAGE.md](USAGE.md).**
|
67
|
+
|
68
|
+
## Installing YARA-X
|
69
|
+
|
70
|
+
You'll need the YARA-X C API library installed on your system. You can:
|
71
|
+
|
72
|
+
1. Build from source: https://github.com/VirusTotal/yara-x
|
73
|
+
2. Install via package manager (when available)
|
74
|
+
3. Use the provided Docker environment
|
75
|
+
|
52
76
|
## Development
|
53
77
|
|
54
|
-
|
78
|
+
See [DEVELOPMENT.md](DEVELOPMENT.md) for detailed development setup instructions, testing guidelines, and contribution workflow.
|
55
79
|
|
56
80
|
## Contributing
|
57
81
|
|
58
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/jonmagic/yara-ffi. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](
|
82
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jonmagic/yara-ffi. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).
|
59
83
|
|
60
84
|
## License
|
61
85
|
|
62
|
-
The gem is available as open source under the terms of the [MIT License](
|
63
|
-
|
64
|
-
## Code of Conduct
|
65
|
-
|
66
|
-
Everyone interacting in the Yara::Ffi project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jonmagic/yara-ffi/blob/master/CODE_OF_CONDUCT.md).
|
86
|
+
The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
|