@automattic/yara 2.3.0 → 2.4.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.
@@ -10,26 +10,44 @@ on:
10
10
 
11
11
  jobs:
12
12
  test:
13
- runs-on: ubuntu-latest
14
-
15
13
  strategy:
16
14
  fail-fast: false
17
15
  matrix:
18
16
  node-version:
19
- - '14.x'
20
- - '16.x'
17
+ - '14'
18
+ - '16'
19
+ - '18'
20
+ os:
21
+ - 'ubuntu'
22
+ - 'macos'
23
+
24
+ runs-on: ${{ matrix.os }}-latest
21
25
 
22
26
  steps:
23
27
  - uses: actions/checkout@v2
28
+
29
+ - name: Setup MacOs
30
+ if: matrix.os == 'macos'
31
+ run: brew install autoconf automake libmagic
32
+
24
33
  - name: Use Node.js ${{ matrix.node-version }}
25
- uses: actions/setup-node@v1
34
+ uses: actions/setup-node@master
26
35
  with:
27
36
  node-version: ${{ matrix.node-version }}
28
37
 
29
- - name: Install dependencies
38
+ - name: Build binaries with node-pre-gyp
30
39
  run: |
31
- sudo apt-get install libyara-dev
32
- npm install
40
+ set -x
41
+ npm install --build-from-source
42
+
43
+ ls -lh ./build/Release
44
+ md5sum ./build/Release/yara.node || md5 ./build/Release/yara.node || true
45
+
46
+ - name: Upload binaries as Action run artifacts
47
+ uses: actions/upload-artifact@v2
48
+ with:
49
+ name: node${{ matrix.node-version }}-${{ matrix.os }}-yara.node
50
+ path: ./build/Release/yara.node
33
51
 
34
- # - name: Run tests
35
- # run: npm test
52
+ - name: Run tests
53
+ run: npm test
package/Makefile ADDED
@@ -0,0 +1,34 @@
1
+
2
+ BASE=$(shell pwd)
3
+ OSNAME=$(shell uname)
4
+
5
+ CFGOPTS += --with-crypto
6
+ CFGOPTS += --enable-magic
7
+
8
+ ifeq ($(OSNAME),Darwin)
9
+ CFLAGS += -I/usr/local/include/node
10
+ CFLAGS += -I/usr/local/include
11
+ LDFLAGS += -L/usr/local/lib
12
+ endif
13
+
14
+ YARA?=4.2.3
15
+
16
+ libyara: yara
17
+
18
+ yara:
19
+ -rm -rf $(BASE)/build/yara
20
+ -rm -rf $(BASE)/deps/yara-$(YARA)
21
+ test -f $(BASE)/deps/yara-$(YARA).tar.gz || curl -L -k https://github.com/VirusTotal/yara/archive/v$(YARA).tar.gz > $(BASE)/deps/yara-$(YARA).tar.gz
22
+ cd $(BASE)/deps && tar -xzvf yara-$(YARA).tar.gz
23
+ cd $(BASE)/deps/yara-$(YARA) && ./bootstrap.sh
24
+ cd $(BASE)/deps/yara-$(YARA) && \
25
+ CFLAGS="$(CFLAGS)" \
26
+ LDFLAGS="$(LDFLAGS)" \
27
+ ./configure \
28
+ $(CFGOPTS) \
29
+ --enable-static \
30
+ --disable-shared \
31
+ --with-pic \
32
+ --prefix=$(BASE)/build/yara
33
+ cd $(BASE)/deps/yara-$(YARA) && make
34
+ cd $(BASE)/deps/yara-$(YARA) && make install
package/README.md CHANGED
@@ -5,7 +5,7 @@ This module implements [YARA][yara] bindings for [Node.js][nodejs].
5
5
 
6
6
  **This module is supported on Linux and MacOS (using homebrew) platforms only**
7
7
 
8
- This module uses the installed version of libyara. You should download,
8
+ This module uses the installed version of libyara 3.9. You should download,
9
9
  compile and install your preferred version, or use one of the following
10
10
  commands using your system package manager:
11
11
 
@@ -24,7 +24,7 @@ This module is installed using [node package manager (npm)][npm]:
24
24
  # during installation using node-gyp. A suitable build chain
25
25
  # must be configured before installation.
26
26
 
27
- npm install @automattic/yara
27
+ npm i --save "yara@npm:@automattic/yara@latest"
28
28
 
29
29
  It is loaded using the `require()` function:
30
30
 
package/binding.gyp CHANGED
@@ -10,10 +10,12 @@
10
10
  "-fno-rtti"
11
11
  ],
12
12
  "include_dirs": [
13
- "<!(node -e 'require(\"nan\")')"
13
+ "<!(node -e 'require(\"nan\")')",
14
+ "./build/yara/include"
14
15
  ],
15
16
  "libraries": [
16
- "-lyara"
17
+ "-lmagic",
18
+ "../build/yara/lib/libyara.a"
17
19
  ],
18
20
  "conditions": [
19
21
  [
@@ -24,6 +26,21 @@
24
26
  }
25
27
  }
26
28
  ]
29
+ ],
30
+ "actions": [
31
+ {
32
+ "action_name": "build_libyara",
33
+ "inputs": [
34
+ "deps"
35
+ ],
36
+ "outputs": [
37
+ "build/yara"
38
+ ],
39
+ "action": [
40
+ "make",
41
+ "libyara"
42
+ ]
43
+ }
27
44
  ]
28
45
  }
29
46
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/yara",
3
- "version": "2.3.0",
3
+ "version": "2.4.0",
4
4
  "description": "Automattic's fork of YARA support for Node.js",
5
5
  "main": "index.js",
6
6
  "directories": {
@@ -10,6 +10,9 @@
10
10
  "nan": "2.14.*",
11
11
  "typescript": "^3.8.3"
12
12
  },
13
+ "scripts": {
14
+ "test": "mocha test/*"
15
+ },
13
16
  "contributors": [
14
17
  {
15
18
  "name": "Stephen Vickers",
@@ -31,5 +34,8 @@
31
34
  "yara"
32
35
  ],
33
36
  "author": "NoSpaceships Ltd <hello@nospaceships.com>",
34
- "license": "MIT"
37
+ "license": "MIT",
38
+ "devDependencies": {
39
+ "mocha": "^10.0.0"
40
+ }
35
41
  }
package/src/yara.cc CHANGED
@@ -7,6 +7,7 @@
7
7
  #include <string>
8
8
  #include <sstream>
9
9
  #include <mutex>
10
+ #include <iostream>
10
11
 
11
12
  #include <errno.h>
12
13
  #include <stdio.h>
@@ -42,9 +43,9 @@ enum VarType {
42
43
  #define ERROR_UNKNOWN_STRING "ERROR_UNKNOWN"
43
44
 
44
45
  void compileCallback(int error_level, const char* file_name, int line_number,
45
- const char* message, void* user_data);
46
+ const YR_RULE* rule, const char* message, void* user_data);
46
47
 
47
- int scanCallback(int message, void* data, void* param);
48
+ int scanCallback(YR_SCAN_CONTEXT* scan_context, int message, void* data, void* param);
48
49
 
49
50
  const char* getErrorString(int code) {
50
51
  size_t count = error_codes.count(code);
@@ -515,11 +516,15 @@ private:
515
516
  };
516
517
 
517
518
  void compileCallback(int error_level, const char* file_name, int line_number,
518
- const char* message, void* user_data) {
519
+ const YR_RULE* rule, const char* message, void* user_data) {
519
520
  CompileArgs* args = (CompileArgs*) user_data;
520
521
 
521
522
  std::ostringstream oss;
522
- oss << args->rule_config->index << ":" << line_number << ":" << message << ":" << file_name;
523
+ oss << args->rule_config->index << ":" << line_number << ":" << message << ":";
524
+
525
+ if (file_name != NULL) {
526
+ oss << file_name;
527
+ }
523
528
 
524
529
  if (error_level == YARA_ERROR_LEVEL_WARNING)
525
530
  args->configure->warnings.push_back(oss.str());
@@ -860,7 +865,7 @@ private:
860
865
  ScanReq* scan_req_;
861
866
  };
862
867
 
863
- int scanCallback(int message, void* data, void* param) {
868
+ int scanCallback(YR_SCAN_CONTEXT* scan_context, int message, void* data, void* param) {
864
869
  AsyncScan* async_scan = (AsyncScan*) param;
865
870
 
866
871
  YR_RULE* rule;
@@ -896,7 +901,7 @@ int scanCallback(int message, void* data, void* param) {
896
901
  }
897
902
 
898
903
  yr_rule_strings_foreach(rule, string) {
899
- yr_string_matches_foreach(string, match) {
904
+ yr_string_matches_foreach(scan_context, string, match) {
900
905
  std::ostringstream oss;
901
906
  oss << match->offset << ":" << match->match_length << ":" << string->identifier;
902
907
 
@@ -944,6 +949,8 @@ int scanCallback(int message, void* data, void* param) {
944
949
  NAN_METHOD(ScannerWrap::ReconfigureVariables) {
945
950
  Nan::HandleScope scope;
946
951
 
952
+
953
+
947
954
  ScannerWrap* scanner = ScannerWrap::Unwrap<ScannerWrap>(info.This());
948
955
 
949
956
  std::lock_guard<std::mutex> lock(scanner->mutex);
@@ -1152,7 +1159,7 @@ NAN_METHOD(ScannerWrap::Scan) {
1152
1159
 
1153
1160
  Local<Object> req = Nan::To<Object>(info[0]).ToLocalChecked();
1154
1161
 
1155
- char* filename = NULL;
1162
+ std::string filename;
1156
1163
  char *buffer = NULL;
1157
1164
  int64_t offset = 0;
1158
1165
  int64_t length = 0;
@@ -1160,8 +1167,10 @@ NAN_METHOD(ScannerWrap::Scan) {
1160
1167
  int32_t timeout = 0;
1161
1168
  int32_t matched_bytes = 0;
1162
1169
 
1170
+
1163
1171
  if (Nan::Get(req, Nan::New("filename").ToLocalChecked()).ToLocalChecked()->IsString()) {
1164
1172
  Local<String> s = Nan::To<String>(Nan::Get(req, Nan::New("filename").ToLocalChecked()).ToLocalChecked()).ToLocalChecked();
1173
+
1165
1174
  filename = *Nan::Utf8String(s);
1166
1175
  } else if (Nan::Get(req, Nan::New("buffer").ToLocalChecked()).ToLocalChecked()->IsObject()) {
1167
1176
  Local<Object> o = Nan::To<Object>(Nan::Get(req, Nan::New("buffer").ToLocalChecked()).ToLocalChecked()).ToLocalChecked();
@@ -1226,7 +1235,7 @@ NAN_METHOD(ScannerWrap::Scan) {
1226
1235
  }
1227
1236
  }
1228
1237
 
1229
- if ((! filename) && (! buffer)) {
1238
+ if ((filename.empty()) && (! buffer)) {
1230
1239
  Nan::ThrowError("Either filename of buffer is required");
1231
1240
  return;
1232
1241
  }
@@ -1246,8 +1255,9 @@ NAN_METHOD(ScannerWrap::Scan) {
1246
1255
 
1247
1256
  ScanReq* scan_req = new ScanReq();
1248
1257
 
1249
- if (filename)
1250
- scan_req->filename = filename;
1258
+ if (!filename.empty()) {
1259
+ scan_req->filename = filename.c_str();
1260
+ }
1251
1261
 
1252
1262
  scan_req->buffer = buffer;
1253
1263
  scan_req->offset = offset;
@@ -1268,6 +1278,7 @@ NAN_METHOD(ScannerWrap::Scan) {
1268
1278
  Nan::AsyncQueueWorker(async_scan);
1269
1279
 
1270
1280
  info.GetReturnValue().Set(info.This());
1281
+
1271
1282
  }
1272
1283
 
1273
1284
  }; /* namespace yara */
@@ -54,7 +54,7 @@ describe("index.js", function() {
54
54
  var expErrors = [{
55
55
  index: 0,
56
56
  line: 1,
57
- message: "syntax error, unexpected '}', expecting <condition>"
57
+ message: "syntax error"
58
58
  }]
59
59
 
60
60
  assert.deepEqual(error.errors, expErrors)
@@ -78,7 +78,7 @@ describe("index.js", function() {
78
78
  var expErrors = [{
79
79
  index: 0,
80
80
  line: 1,
81
- message: "syntax error, unexpected '}', expecting <condition>"
81
+ message: "syntax error"
82
82
  }]
83
83
 
84
84
  assert.deepEqual(error.errors, expErrors)
@@ -114,7 +114,7 @@ describe("index.js", function() {
114
114
  {
115
115
  index: 0,
116
116
  line: 4,
117
- message: 'Using literal string "stephen" in a boolean operation.'
117
+ message: 'using literal string "stephen" in a boolean operation.'
118
118
  }
119
119
  ]
120
120
 
@@ -160,7 +160,7 @@ describe("index.js", function() {
160
160
  var expErrors = [{
161
161
  index: 0,
162
162
  line: 4,
163
- message: "syntax error, unexpected hex string, expecting identifier"
163
+ message: "syntax error"
164
164
  }]
165
165
 
166
166
  assert.deepEqual(error.errors, expErrors)