node-yara-rs

git clone git://archive.git.mtrnord.blog/MTRNord/node-yara-rs.git
Log | Files | Refs | README | LICENSE

commit 4241b6580d8bf11b56c2731b81765dd005a86e3e
parent ff743cb7dabe315426f128f6ab3c2d584d827e0b
Author: MTRNord <mtrnord1@gmail.com>
Date:   Tue, 17 Oct 2023 18:08:55 +0200

Deocode strings

Diffstat:
MCHANGELOG.md | 7+++++++
M__test__/index.spec.mjs | 1+
Achangelog.d/+string.bugfix | 2++
Mindex.d.ts | 2++
Msrc/lib.rs | 21++++++++++++++++-----
5 files changed, 28 insertions(+), 5 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md @@ -1,3 +1,10 @@ +# node-yara-rs 0.6.2 (2023-10-17) + +### Bugfixes + +- Also decode the utf8 bytes + + # node-yara-rs 0.6.1 (2023-10-13) ### Bugfixes diff --git a/__test__/index.spec.mjs b/__test__/index.spec.mjs @@ -98,6 +98,7 @@ test('can match file based rules', (t) => { ], length: 4, offset: 0, + stringData: "Test" }, ], }, diff --git a/changelog.d/+string.bugfix b/changelog.d/+string.bugfix @@ -0,0 +1 @@ +Also decode the utf8 bytes +\ No newline at end of file diff --git a/index.d.ts b/index.d.ts @@ -42,6 +42,8 @@ export interface YaraMatch { length: number /** Matched data. */ data: Array<number> + /** If utf-8 then we decode it here */ + stringData?: string } /** * An interface to use yara with node in a stable manner using Rust diff --git a/src/lib.rs b/src/lib.rs @@ -81,6 +81,8 @@ pub struct YaraMatch { pub length: i64, /// Matched data. pub data: Vec<u8>, + /// If utf-8 then we decode it here + pub string_data: Option<String>, } #[napi] @@ -206,11 +208,20 @@ impl YaraScanner { matches: string .matches .iter() - .map(|matches| YaraMatch { - base: matches.base as i64, - offset: matches.offset as i64, - length: matches.length as i64, - data: matches.data.clone(), + .map(|matches| { + let string = String::from_utf8(matches.data.clone()); + let string_data = if let Ok(string_data) = string { + Some(string_data) + } else { + None + }; + YaraMatch { + base: matches.base as i64, + offset: matches.offset as i64, + length: matches.length as i64, + data: matches.data.clone(), + string_data, + } }) .collect(), })