yara-ffi 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/ruby.yml +40 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +85 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +51 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +17 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/yara.rb +71 -0
- data/lib/yara/ffi.rb +111 -0
- data/lib/yara/user_data.rb +5 -0
- data/lib/yara/version.rb +5 -0
- data/lib/yara/yr_meta.rb +7 -0
- data/lib/yara/yr_namespace.rb +5 -0
- data/lib/yara/yr_rule.rb +11 -0
- data/lib/yara/yr_string.rb +5 -0
- data/vendor/cache/ast-2.4.2.gem +0 -0
- data/vendor/cache/coderay-1.1.3.gem +0 -0
- data/vendor/cache/ffi-1.15.0.gem +0 -0
- data/vendor/cache/method_source-1.0.0.gem +0 -0
- data/vendor/cache/minitest-5.14.4.gem +0 -0
- data/vendor/cache/parallel-1.20.1.gem +0 -0
- data/vendor/cache/parser-3.0.0.0.gem +0 -0
- data/vendor/cache/pry-0.14.0.gem +0 -0
- data/vendor/cache/rainbow-3.0.0.gem +0 -0
- data/vendor/cache/rake-13.0.3.gem +0 -0
- data/vendor/cache/regexp_parser-2.1.1.gem +0 -0
- data/vendor/cache/rexml-3.2.4.gem +0 -0
- data/vendor/cache/rubocop-1.11.0.gem +0 -0
- data/vendor/cache/rubocop-ast-1.4.1.gem +0 -0
- data/vendor/cache/ruby-progressbar-1.11.0.gem +0 -0
- data/vendor/cache/unicode-display_width-2.0.0.gem +0 -0
- data/yara-ffi.gemspec +26 -0
- metadata +97 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 380c0c04b4e921df435344606ae662123cdf59e8e1bb20bc442f1282285d87d1
|
4
|
+
data.tar.gz: 5348991427d0376f4d0b31e8a1e9cd64275e760a2a9839e10eb0cc87dcedbfaf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a640d8ef7adce2b261de4e7144e2c8ea35519c566cbd2c6a75c04ab68bda54bbf0d339b37bb210fdf60b1bed7bb152fe3c0e0e20355c7f8ec45364c2dd25dc31
|
7
|
+
data.tar.gz: 9063e8934d649121a5c2e9489d662c5bdb64b695ac359981d0801bc439ba64699fded19c8d0096c3ae4900fb59b8823c84cec153e0573bc81219e3d4e0e74b12
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Ruby
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ main ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ main ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
strategy:
|
21
|
+
matrix:
|
22
|
+
ruby-version: ['2.6', '2.7', '3.0']
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Set up Ruby
|
27
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
28
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
29
|
+
uses: ruby/setup-ruby@v1
|
30
|
+
with:
|
31
|
+
ruby-version: ${{ matrix.ruby-version }}
|
32
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
33
|
+
- name: Install dependencies
|
34
|
+
run: |
|
35
|
+
sudo apt-get update -y
|
36
|
+
sudo apt-get install -y libyara-dev
|
37
|
+
sudo gem install bundler -v 2.2.14
|
38
|
+
bundle install
|
39
|
+
- name: Run tests
|
40
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.4
|
3
|
+
|
4
|
+
Gemspec/DateAssignment:
|
5
|
+
Enabled: true
|
6
|
+
|
7
|
+
Layout/LineLength:
|
8
|
+
Max: 120
|
9
|
+
Layout/SpaceBeforeBrackets:
|
10
|
+
Enabled: true
|
11
|
+
|
12
|
+
Lint/AmbiguousAssignment:
|
13
|
+
Enabled: true
|
14
|
+
Lint/DeprecatedConstants:
|
15
|
+
Enabled: true
|
16
|
+
Lint/DuplicateBranch:
|
17
|
+
Enabled: true
|
18
|
+
Lint/DuplicateRegexpCharacterClassElement:
|
19
|
+
Enabled: true
|
20
|
+
Lint/EmptyBlock:
|
21
|
+
Enabled: true
|
22
|
+
Lint/EmptyClass:
|
23
|
+
Enabled: true
|
24
|
+
Lint/LambdaWithoutLiteralBlock:
|
25
|
+
Enabled: true
|
26
|
+
Lint/NoReturnInBeginEndBlocks:
|
27
|
+
Enabled: true
|
28
|
+
Lint/NumberedParameterAssignment:
|
29
|
+
Enabled: true
|
30
|
+
Lint/OrAssignmentToConstant:
|
31
|
+
Enabled: true
|
32
|
+
Lint/RedundantDirGlobSort:
|
33
|
+
Enabled: true
|
34
|
+
Lint/SymbolConversion:
|
35
|
+
Enabled: true
|
36
|
+
Lint/ToEnumArguments:
|
37
|
+
Enabled: true
|
38
|
+
Lint/TripleQuotes:
|
39
|
+
Enabled: true
|
40
|
+
Lint/UnexpectedBlockArity:
|
41
|
+
Enabled: true
|
42
|
+
Lint/UnmodifiedReduceAccumulator:
|
43
|
+
Enabled: true
|
44
|
+
|
45
|
+
Metrics/AbcSize:
|
46
|
+
Enabled: false
|
47
|
+
Metrics/MethodLength:
|
48
|
+
Enabled: false
|
49
|
+
|
50
|
+
Style/StringLiterals:
|
51
|
+
Enabled: true
|
52
|
+
EnforcedStyle: double_quotes
|
53
|
+
Style/StringLiteralsInInterpolation:
|
54
|
+
Enabled: true
|
55
|
+
EnforcedStyle: double_quotes
|
56
|
+
Style/HashEachMethods:
|
57
|
+
Enabled: true
|
58
|
+
Style/HashTransformKeys:
|
59
|
+
Enabled: true
|
60
|
+
Style/HashTransformValues:
|
61
|
+
Enabled: true
|
62
|
+
Style/ArgumentsForwarding:
|
63
|
+
Enabled: true
|
64
|
+
Style/CollectionCompact:
|
65
|
+
Enabled: true
|
66
|
+
Style/DocumentDynamicEvalDefinition:
|
67
|
+
Enabled: true
|
68
|
+
Style/EndlessMethod:
|
69
|
+
Enabled: true
|
70
|
+
Style/HashConversion:
|
71
|
+
Enabled: true
|
72
|
+
Style/HashExcept:
|
73
|
+
Enabled: true
|
74
|
+
Style/IfWithBooleanLiteralBranches:
|
75
|
+
Enabled: true
|
76
|
+
Style/NegatedIfElseCondition:
|
77
|
+
Enabled: true
|
78
|
+
Style/NilLambda:
|
79
|
+
Enabled: true
|
80
|
+
Style/RedundantArgument:
|
81
|
+
Enabled: true
|
82
|
+
Style/SwapValues:
|
83
|
+
Enabled: true
|
84
|
+
Style/TrailingCommaInArrayLiteral:
|
85
|
+
EnforcedStyleForMultiline: comma
|
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at jonmagic@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
yara-ffi (1.0.0)
|
5
|
+
ffi
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.2)
|
11
|
+
coderay (1.1.3)
|
12
|
+
ffi (1.15.0)
|
13
|
+
method_source (1.0.0)
|
14
|
+
minitest (5.14.4)
|
15
|
+
parallel (1.20.1)
|
16
|
+
parser (3.0.0.0)
|
17
|
+
ast (~> 2.4.1)
|
18
|
+
pry (0.14.0)
|
19
|
+
coderay (~> 1.1)
|
20
|
+
method_source (~> 1.0)
|
21
|
+
rainbow (3.0.0)
|
22
|
+
rake (13.0.3)
|
23
|
+
regexp_parser (2.1.1)
|
24
|
+
rexml (3.2.4)
|
25
|
+
rubocop (1.11.0)
|
26
|
+
parallel (~> 1.10)
|
27
|
+
parser (>= 3.0.0.0)
|
28
|
+
rainbow (>= 2.2.2, < 4.0)
|
29
|
+
regexp_parser (>= 1.8, < 3.0)
|
30
|
+
rexml
|
31
|
+
rubocop-ast (>= 1.2.0, < 2.0)
|
32
|
+
ruby-progressbar (~> 1.7)
|
33
|
+
unicode-display_width (>= 1.4.0, < 3.0)
|
34
|
+
rubocop-ast (1.4.1)
|
35
|
+
parser (>= 2.7.1.5)
|
36
|
+
ruby-progressbar (1.11.0)
|
37
|
+
unicode-display_width (2.0.0)
|
38
|
+
|
39
|
+
PLATFORMS
|
40
|
+
x86_64-darwin-19
|
41
|
+
x86_64-linux
|
42
|
+
|
43
|
+
DEPENDENCIES
|
44
|
+
minitest
|
45
|
+
pry
|
46
|
+
rake
|
47
|
+
rubocop
|
48
|
+
yara-ffi!
|
49
|
+
|
50
|
+
BUNDLED WITH
|
51
|
+
2.2.14
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Jonathan Hoyt
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# yara-ffi
|
2
|
+
|
3
|
+
A Ruby library for using [libyara](https://yara.readthedocs.io/en/stable/capi.html) via FFI.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem "yara"
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install yara-ffi
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
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](https://github.com/jonmagic/yara-ffi/blob/master/CODE_OF_CONDUCT.md).
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
36
|
+
|
37
|
+
## Code of Conduct
|
38
|
+
|
39
|
+
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).
|
data/Rakefile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake/testtask"
|
5
|
+
|
6
|
+
Rake::TestTask.new(:test) do |t|
|
7
|
+
t.libs << "test"
|
8
|
+
t.libs << "lib"
|
9
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
10
|
+
end
|
11
|
+
|
12
|
+
# require "rubocop/rake_task"
|
13
|
+
# RuboCop::RakeTask.new
|
14
|
+
|
15
|
+
require "bundler/setup"
|
16
|
+
|
17
|
+
task default: %i[test]
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "yara"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/yara.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ffi"
|
4
|
+
require "pry"
|
5
|
+
require_relative "yara/version"
|
6
|
+
require_relative "yara/ffi"
|
7
|
+
|
8
|
+
# TBD
|
9
|
+
module Yara
|
10
|
+
class Error < StandardError; end
|
11
|
+
|
12
|
+
CALLBACK_MSG_RULE_MATCHING = 1
|
13
|
+
CALLBACK_MSG_RULE_NOT_MATCHING = 2
|
14
|
+
CALLBACK_MSG_SCAN_FINISHED = 3
|
15
|
+
|
16
|
+
RULE_IDENTIFIER = 1
|
17
|
+
|
18
|
+
def self.test(rule_string, test_string)
|
19
|
+
user_data = UserData.new
|
20
|
+
user_data[:number] = 42
|
21
|
+
scanning = true
|
22
|
+
results = []
|
23
|
+
|
24
|
+
Yara::FFI.yr_initialize
|
25
|
+
|
26
|
+
compiler_pointer = ::FFI::MemoryPointer.new(:pointer)
|
27
|
+
Yara::FFI.yr_compiler_create(compiler_pointer)
|
28
|
+
compiler_pointer = compiler_pointer.get_pointer(0)
|
29
|
+
|
30
|
+
error_callback = proc do |error_level, file_name, line_number, rule, message, user_data|
|
31
|
+
# noop
|
32
|
+
end
|
33
|
+
|
34
|
+
Yara::FFI.yr_compiler_set_callback(compiler_pointer, error_callback, user_data)
|
35
|
+
Yara::FFI.yr_compiler_add_string(compiler_pointer, rule_string, nil)
|
36
|
+
|
37
|
+
rules_pointer =::FFI::MemoryPointer.new(:pointer)
|
38
|
+
Yara::FFI.yr_compiler_get_rules(compiler_pointer, rules_pointer)
|
39
|
+
rules_pointer = rules_pointer.get_pointer(0)
|
40
|
+
|
41
|
+
result_callback = proc do |context_ptr, message, message_data_ptr, user_data_ptr|
|
42
|
+
rule = YrRule.new(message_data_ptr)
|
43
|
+
|
44
|
+
case message
|
45
|
+
when CALLBACK_MSG_RULE_MATCHING
|
46
|
+
results << rule.values[RULE_IDENTIFIER]
|
47
|
+
when CALLBACK_MSG_SCAN_FINISHED
|
48
|
+
scanning = false
|
49
|
+
end
|
50
|
+
|
51
|
+
0 # ERROR_SUCCESS
|
52
|
+
end
|
53
|
+
|
54
|
+
Yara::FFI.yr_rules_scan_mem(
|
55
|
+
rules_pointer,
|
56
|
+
test_string,
|
57
|
+
test_string.bytesize,
|
58
|
+
0,
|
59
|
+
result_callback,
|
60
|
+
user_data,
|
61
|
+
1,
|
62
|
+
)
|
63
|
+
|
64
|
+
while scanning do
|
65
|
+
end
|
66
|
+
|
67
|
+
results
|
68
|
+
ensure
|
69
|
+
Yara::FFI.yr_finalize
|
70
|
+
end
|
71
|
+
end
|
data/lib/yara/ffi.rb
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
require_relative "yr_meta"
|
2
|
+
require_relative "yr_namespace"
|
3
|
+
require_relative "yr_string"
|
4
|
+
require_relative "yr_rule"
|
5
|
+
require_relative "user_data"
|
6
|
+
|
7
|
+
module Yara
|
8
|
+
# FFI bindings to libyara.
|
9
|
+
module FFI
|
10
|
+
extend ::FFI::Library
|
11
|
+
ffi_lib "libyara"
|
12
|
+
|
13
|
+
# int yr_initialize(void)
|
14
|
+
attach_function :yr_initialize, [], :int
|
15
|
+
|
16
|
+
# int yr_finalize(void)
|
17
|
+
attach_function :yr_finalize, [], :int
|
18
|
+
|
19
|
+
# Creates a new compiler and assigns a pointer to that compiler
|
20
|
+
# to the pointer passed into the method. To access the complier
|
21
|
+
# get the pointer from the pointer you passed in.
|
22
|
+
#
|
23
|
+
# Usage:
|
24
|
+
# > compiler_pointer = FFI::MemoryPointer.new(:pointer)
|
25
|
+
# > Yara::FFI.yr_compiler_create(compiler_pointer)
|
26
|
+
# > compiler_pointer = compiler_pointer.get_pointer(0)
|
27
|
+
#
|
28
|
+
# int yr_compiler_create(YR_COMPILER** compiler)
|
29
|
+
attach_function :yr_compiler_create, [
|
30
|
+
:pointer, # compiler_pointer*
|
31
|
+
], :int
|
32
|
+
|
33
|
+
# int yr_compiler_destroy(YR_COMPILER* compiler)
|
34
|
+
attach_function :yr_compiler_destroy, [
|
35
|
+
:pointer, # compiler_pointer
|
36
|
+
], :void
|
37
|
+
|
38
|
+
# void callback_function(
|
39
|
+
# int error_level,
|
40
|
+
# const char* file_name,
|
41
|
+
# int line_number,
|
42
|
+
# const YR_RULE* rule,
|
43
|
+
# const char* message,
|
44
|
+
# void* user_data)
|
45
|
+
callback :add_rule_error_callback, [
|
46
|
+
:int, # error_level
|
47
|
+
:string, # file_name
|
48
|
+
:int, # line_number
|
49
|
+
YrRule.by_ref, # YrRule*
|
50
|
+
:string, # message
|
51
|
+
:pointer, # user_data_pointer
|
52
|
+
], :void
|
53
|
+
|
54
|
+
# void yr_compiler_set_callback(
|
55
|
+
# YR_COMPILER* compiler,
|
56
|
+
# YR_COMPILER_CALLBACK_FUNC callback,
|
57
|
+
# void* user_data)
|
58
|
+
attach_function :yr_compiler_set_callback, [
|
59
|
+
:pointer, # compiler_pointer*
|
60
|
+
:add_rule_error_callback, # proc
|
61
|
+
:pointer, # user_data_pointer
|
62
|
+
], :void
|
63
|
+
|
64
|
+
# int yr_compiler_add_string(
|
65
|
+
# YR_COMPILER* compiler,
|
66
|
+
# const char* string,
|
67
|
+
# const char* namespace_)
|
68
|
+
attach_function :yr_compiler_add_string, [
|
69
|
+
:pointer, # compiler_pointer*
|
70
|
+
:string, # rule string
|
71
|
+
:string, # namespace
|
72
|
+
], :int
|
73
|
+
|
74
|
+
# int yr_compiler_get_rules(
|
75
|
+
# YR_COMPILER* compiler,
|
76
|
+
# YR_RULES** rules)
|
77
|
+
attach_function :yr_compiler_get_rules, [
|
78
|
+
:pointer, # compiler_pointer*
|
79
|
+
:pointer, # rules_pointer*
|
80
|
+
], :int
|
81
|
+
|
82
|
+
# int callback_function(
|
83
|
+
# int message,
|
84
|
+
# void* message_data,
|
85
|
+
# void* user_data)
|
86
|
+
callback :scan_callback, [
|
87
|
+
:pointer, # YR_SCAN_CONTEXT*
|
88
|
+
:int, # message
|
89
|
+
:pointer, # message_data_pointer
|
90
|
+
:pointer, # user_data_pointer
|
91
|
+
], :int
|
92
|
+
|
93
|
+
# int yr_rules_scan_mem(
|
94
|
+
# YR_RULES* rules,
|
95
|
+
# const uint8_t* buffer,
|
96
|
+
# size_t buffer_size,
|
97
|
+
# int flags,
|
98
|
+
# YR_CALLBACK_FUNC callback,
|
99
|
+
# void* user_data,
|
100
|
+
# int timeout)
|
101
|
+
attach_function :yr_rules_scan_mem, [
|
102
|
+
:pointer, # rules_pointer*
|
103
|
+
:string, # buffer (aka test subject)
|
104
|
+
:size_t, # buffer size (String#bytesize)
|
105
|
+
:int, # flags
|
106
|
+
:scan_callback, # proc
|
107
|
+
:pointer, # user_data_pointer
|
108
|
+
:int, # timeout in seconds
|
109
|
+
], :int
|
110
|
+
end
|
111
|
+
end
|
data/lib/yara/version.rb
ADDED
data/lib/yara/yr_meta.rb
ADDED
data/lib/yara/yr_rule.rb
ADDED
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
data/yara-ffi.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/yara/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "yara-ffi"
|
7
|
+
spec.version = Yara::VERSION
|
8
|
+
spec.authors = ["Jonathan Hoyt"]
|
9
|
+
spec.email = ["jonmagic@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = "A Ruby API to libyara."
|
12
|
+
spec.description = "Use libyara from Ruby via ffi bindings."
|
13
|
+
spec.homepage = "https://github.com/jonmagic/yara-ffi"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.4.0")
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/jonmagic/yara-ffi"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/jonmagic/yara-ffi/main/CHANGELOG.md,"
|
20
|
+
|
21
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
22
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
23
|
+
end
|
24
|
+
spec.require_paths = ["lib"]
|
25
|
+
spec.add_dependency "ffi"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yara-ffi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jonathan Hoyt
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-08-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ffi
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Use libyara from Ruby via ffi bindings.
|
28
|
+
email:
|
29
|
+
- jonmagic@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".github/workflows/ruby.yml"
|
35
|
+
- ".gitignore"
|
36
|
+
- ".rubocop.yml"
|
37
|
+
- CHANGELOG.md
|
38
|
+
- CODE_OF_CONDUCT.md
|
39
|
+
- Gemfile
|
40
|
+
- Gemfile.lock
|
41
|
+
- LICENSE.txt
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- bin/console
|
45
|
+
- bin/setup
|
46
|
+
- lib/yara.rb
|
47
|
+
- lib/yara/ffi.rb
|
48
|
+
- lib/yara/user_data.rb
|
49
|
+
- lib/yara/version.rb
|
50
|
+
- lib/yara/yr_meta.rb
|
51
|
+
- lib/yara/yr_namespace.rb
|
52
|
+
- lib/yara/yr_rule.rb
|
53
|
+
- lib/yara/yr_string.rb
|
54
|
+
- vendor/cache/ast-2.4.2.gem
|
55
|
+
- vendor/cache/coderay-1.1.3.gem
|
56
|
+
- vendor/cache/ffi-1.15.0.gem
|
57
|
+
- vendor/cache/method_source-1.0.0.gem
|
58
|
+
- vendor/cache/minitest-5.14.4.gem
|
59
|
+
- vendor/cache/parallel-1.20.1.gem
|
60
|
+
- vendor/cache/parser-3.0.0.0.gem
|
61
|
+
- vendor/cache/pry-0.14.0.gem
|
62
|
+
- vendor/cache/rainbow-3.0.0.gem
|
63
|
+
- vendor/cache/rake-13.0.3.gem
|
64
|
+
- vendor/cache/regexp_parser-2.1.1.gem
|
65
|
+
- vendor/cache/rexml-3.2.4.gem
|
66
|
+
- vendor/cache/rubocop-1.11.0.gem
|
67
|
+
- vendor/cache/rubocop-ast-1.4.1.gem
|
68
|
+
- vendor/cache/ruby-progressbar-1.11.0.gem
|
69
|
+
- vendor/cache/unicode-display_width-2.0.0.gem
|
70
|
+
- yara-ffi.gemspec
|
71
|
+
homepage: https://github.com/jonmagic/yara-ffi
|
72
|
+
licenses:
|
73
|
+
- MIT
|
74
|
+
metadata:
|
75
|
+
homepage_uri: https://github.com/jonmagic/yara-ffi
|
76
|
+
source_code_uri: https://github.com/jonmagic/yara-ffi
|
77
|
+
changelog_uri: https://github.com/jonmagic/yara-ffi/main/CHANGELOG.md,
|
78
|
+
post_install_message:
|
79
|
+
rdoc_options: []
|
80
|
+
require_paths:
|
81
|
+
- lib
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
83
|
+
requirements:
|
84
|
+
- - ">="
|
85
|
+
- !ruby/object:Gem::Version
|
86
|
+
version: 2.4.0
|
87
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
version: '0'
|
92
|
+
requirements: []
|
93
|
+
rubygems_version: 3.0.3
|
94
|
+
signing_key:
|
95
|
+
specification_version: 4
|
96
|
+
summary: A Ruby API to libyara.
|
97
|
+
test_files: []
|