Skip to content

Commit 68b4242

Browse files
committed
Merge remote-tracking branch 'origin/main' into magic
2 parents 9826e8b + f0f5b0a commit 68b4242

File tree

33 files changed

+322
-77
lines changed

33 files changed

+322
-77
lines changed

.github/workflows/golang.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
strategy:
1515
fail-fast: false
1616
matrix:
17-
go-version: [ '1.19', '1.20', '1.21.x', '1.22.x' ]
17+
go-version: [ '1.19', '1.20', '1.21.x', '1.22.x', '1.23.x', '1.24.x', '1.25.x' ]
1818
os: [ ubuntu-latest, macos-latest ]
1919
runs-on: ${{ matrix.os }}
2020
steps:

.github/workflows/pr_title.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ jobs:
1313
permissions:
1414
statuses: write
1515
steps:
16-
- uses: aslafy-z/conventional-pr-title-action@a0b851005a0f82ac983a56ead5a8111c0d8e044a # v3.2.0
16+
- uses: amannn/action-semantic-pull-request@fdd4d3ddf614fbcd8c29e4b106d3bbe0cb2c605d # v6.0.1
1717
env:
1818
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ jobs:
187187
CIBW_TEST_SKIP: '*-macosx_arm64 *-macosx_universal2:arm64'
188188
CIBW_BUILD_VERBOSITY: 1
189189

190-
MACOSX_DEPLOYMENT_TARGET: '10.12'
190+
MACOSX_DEPLOYMENT_TARGET: '14.0'
191191

192192
- name: Upload artifacts
193193
uses: actions/upload-artifact@4cec3d8aa04e39d1a68397de0c4cd6fb9dce8ec1 # v4.6.1

Cargo.lock

Lines changed: 11 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[workspace.package]
2-
version = "1.4.0"
2+
version = "1.5.0"
33
authors = ["Victor M. Alvarez <[email protected]>"]
44
edition = "2021"
55
homepage = "https://virustotal.github.io/yara-x"
@@ -105,13 +105,13 @@ walrus = "0.23.3"
105105
wasmtime = { version = "34.0.2", default-features = false }
106106
x509-parser = "0.17.0"
107107
yansi = "1.0.1"
108-
yara-x = { path = "lib", version = "1.4.0" }
109-
yara-x-fmt = { path = "fmt", version = "1.4.0" }
110-
yara-x-macros = { path = "macros", version = "1.4.0" }
111-
yara-x-parser = { path = "parser", version = "1.4.0" }
112-
yara-x-proto = { path = "proto", version = "1.4.0" }
113-
yara-x-proto-yaml = { path = "proto-yaml", version = "1.4.0" }
114-
yara-x-proto-json = { path = "proto-json", version = "1.4.0" }
108+
yara-x = { path = "lib", version = "1.5.0" }
109+
yara-x-fmt = { path = "fmt", version = "1.5.0" }
110+
yara-x-macros = { path = "macros", version = "1.5.0" }
111+
yara-x-parser = { path = "parser", version = "1.5.0" }
112+
yara-x-proto = { path = "proto", version = "1.5.0" }
113+
yara-x-proto-yaml = { path = "proto-yaml", version = "1.5.0" }
114+
yara-x-proto-json = { path = "proto-json", version = "1.5.0" }
115115
zip = "4.3.0"
116116

117117
# Special profile that builds a release binary with link-time optimization.

cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ enable-ansi-support = { workspace = true }
5454
env_logger = { workspace = true, optional = true, features = ["auto-color"] }
5555
log = { workspace = true, optional = true }
5656
protobuf = { workspace = true }
57+
regex = { workspace = true }
5758
serde_json = { workspace = true, features = ["preserve_order"] }
5859
serde = { workspace = true, features = ["derive"] }
5960
strum = { workspace = true }

cli/src/commands/check.rs

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{fs, io};
55
use anyhow::Context;
66
use clap::{arg, value_parser, ArgAction, ArgMatches, Command};
77
use crossterm::tty::IsTty;
8+
use regex;
89
use superconsole::{Component, Line, Lines, Span};
910
use yansi::Color::{Green, Red, Yellow};
1011
use yansi::Paint;
@@ -112,14 +113,28 @@ pub fn exec_check(args: &ArgMatches, config: &Config) -> anyhow::Result<()> {
112113

113114
match config.ty {
114115
MetaValueType::String => {
116+
let message = if let Some(regexp) = &config.regexp {
117+
// Make sure that the regexp is valid.
118+
let _ = regex::bytes::Regex::new(&regexp)?;
119+
format!("`{identifier}` must be a string that matches `/{regexp}/`")
120+
} else {
121+
format!("`{identifier}` must be a string")
122+
};
115123
linter = linter.validator(
116124
|meta| {
117-
matches!(
118-
meta.value,
119-
MetaValue::String(_) | MetaValue::Bytes(_)
120-
)
125+
match (&meta.value, &config.regexp) {
126+
(MetaValue::String((s, _)), Some(regexp)) => {
127+
regex::Regex::new(&regexp).unwrap().is_match(s)
128+
}
129+
(MetaValue::Bytes((s, _)), Some(regexp)) => {
130+
regex::bytes::Regex::new(&regexp).unwrap().is_match(s)
131+
}
132+
(MetaValue::String(_), None) => true,
133+
(MetaValue::Bytes(_), None) => true,
134+
_ => false,
135+
}
121136
},
122-
format!("`{identifier}` must be a string"),
137+
message,
123138
);
124139
}
125140
MetaValueType::Integer => {
@@ -184,7 +199,7 @@ pub fn exec_check(args: &ArgMatches, config: &Config) -> anyhow::Result<()> {
184199
if !config.check.tags.allowed.is_empty() {
185200
compiler.add_linter(
186201
linters::tags_allowed(config.check.tags.allowed.clone())
187-
.error(config.check.tags.error));
202+
.error(config.check.tags.error));
188203
} else if let Some(re) = config
189204
.check
190205
.tags
@@ -252,7 +267,7 @@ pub fn exec_check(args: &ArgMatches, config: &Config) -> anyhow::Result<()> {
252267
Ok(())
253268
},
254269
)
255-
.unwrap();
270+
.unwrap();
256271

257272
Ok(())
258273
}

cli/src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ pub struct RuleNameConfig {
118118
pub struct MetadataConfig {
119119
#[serde(rename = "type")]
120120
pub ty: MetaValueType,
121+
/// A regular expression that the metadata value must match. Only
122+
/// applies if type is MetaValueType::String.
123+
pub regexp: Option<String>,
121124
/// Specifies whether the metadata is required or optional.
122125
#[serde(default)]
123126
pub required: bool,

cli/src/tests/check.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ fn metadata() {
2121
sha256 = { type = "sha256" }
2222
required = { type = "string", required = true }
2323
optional = { type = "string" }
24+
regexp = { type = "string", regexp = "(foo|bar)" }
2425
"#,
2526
)
2627
.unwrap();
@@ -42,14 +43,14 @@ fn metadata() {
4243
| --- required metadata `required` not found
4344
|
4445
warning[text_as_hex]: hex pattern could be written as text literal
45-
--> src/tests/testdata/foo.yar:9:5
46-
|
47-
9 | $foo_hex = { 66 6f 6f }
48-
| ---------------------
49-
| |
50-
| this pattern can be written as a text literal
51-
| help: replace with "foo"
52-
|
46+
--> src/tests/testdata/foo.yar:10:5
47+
|
48+
10 | $foo_hex = { 66 6f 6f }
49+
| ---------------------
50+
| |
51+
| this pattern can be written as a text literal
52+
| help: replace with "foo"
53+
|
5354
"#,
5455
);
5556

@@ -66,6 +67,7 @@ warning[text_as_hex]: hex pattern could be written as text literal
6667
int = 3.14
6768
float = "not a float"
6869
string = true
70+
regexp = "baz"
6971
condition:
7072
true
7173
}"#,
@@ -83,23 +85,36 @@ warning[text_as_hex]: hex pattern could be written as text literal
8385
.stderr(predicate::str::contains(
8486
"warning[invalid_metadata]: metadata `md5` is not valid",
8587
))
88+
.stderr(predicate::str::contains("`md5` must be a MD5"))
8689
.stderr(predicate::str::contains(
8790
"warning[invalid_metadata]: metadata `sha1` is not valid",
8891
))
92+
.stderr(predicate::str::contains("`sha1` must be a SHA-1"))
8993
.stderr(predicate::str::contains(
9094
"warning[invalid_metadata]: metadata `sha256` is not valid",
9195
))
96+
.stderr(predicate::str::contains("`sha256` must be a SHA-256"))
9297
.stderr(predicate::str::contains(
9398
"warning[invalid_metadata]: metadata `bool` is not valid",
9499
))
100+
.stderr(predicate::str::contains("`bool` must be a bool"))
95101
.stderr(predicate::str::contains(
96102
"warning[invalid_metadata]: metadata `int` is not valid",
97103
))
104+
.stderr(predicate::str::contains("`int` must be an int"))
98105
.stderr(predicate::str::contains(
99106
"warning[invalid_metadata]: metadata `float` is not valid",
100107
))
108+
.stderr(predicate::str::contains("`float` must be a float"))
101109
.stderr(predicate::str::contains(
102110
"warning[invalid_metadata]: metadata `string` is not valid",
111+
))
112+
.stderr(predicate::str::contains("`string` must be a string"))
113+
.stderr(predicate::str::contains(
114+
"warning[invalid_metadata]: metadata `regexp` is not valid",
115+
))
116+
.stderr(predicate::str::contains(
117+
"`regexp` must be a string that matches `/(foo|bar)/`",
103118
));
104119
}
105120

cli/src/tests/scan.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ fn print_meta() {
147147
.arg("src/tests/testdata/dummy.file")
148148
.assert()
149149
.success()
150-
.stdout("foo [string=\"foo\",bool=true,int=1,float=3.14] src/tests/testdata/dummy.file\n");
150+
.stdout("foo [string=\"foo\",bool=true,int=1,float=3.14,regexp=\"foo\"] src/tests/testdata/dummy.file\n");
151151
}
152152

153153
#[test]

0 commit comments

Comments
 (0)