@automattic/yara 2.4.0 → 2.5.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.
package/.dockerignore ADDED
@@ -0,0 +1,6 @@
1
+ Dockerfile
2
+ README.md
3
+ build/
4
+ deps/yara-*
5
+ example/
6
+ node_modules/
@@ -0,0 +1,14 @@
1
+ # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
2
+ # https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/configuration-options-for-dependency-updates#package-ecosystem
3
+ version: 2
4
+
5
+ updates:
6
+ - package-ecosystem: "npm"
7
+ directory: "/"
8
+ schedule:
9
+ interval: "daily"
10
+
11
+ - package-ecosystem: "github-actions"
12
+ directory: "/"
13
+ schedule:
14
+ interval: daily
@@ -0,0 +1,108 @@
1
+ # Here we build the yara.node binary, package it and copy it to the repository.
2
+ # Both MacOS and Linux (Debian-based) versions are built here.
3
+ name: Build the binary
4
+
5
+ on:
6
+ push:
7
+ branches: [ master ]
8
+ pull_request:
9
+
10
+ # allow these jobs to commit to the repository
11
+ permissions:
12
+ contents: write
13
+
14
+ jobs:
15
+ # We need to use the node-yara binary on Debian 10.x machines
16
+ # hence we're using the container to build it
17
+ build-debian:
18
+ strategy:
19
+ fail-fast: false
20
+ matrix:
21
+ node-version:
22
+ # - '14'
23
+ - '16'
24
+ # - '18'
25
+
26
+ runs-on: ubuntu-22.04
27
+
28
+ steps:
29
+ - uses: actions/checkout@v3
30
+
31
+ - name: Build binaries inside the container
32
+ run: |
33
+ set -x
34
+
35
+ # what's the package version?
36
+ # e.g. Binary staged at "build/stage/Automattic/node-yara/raw/master/binaries/yara-v2.5.0-linux-x64.tar.gz"
37
+ export PACKAGE_VERSION=$(jq -r .version package.json)
38
+
39
+ # build inside the container and copy the package to the host
40
+ docker build -t yara/debian .
41
+ docker images
42
+ docker run --rm --volume /tmp:/tmp yara/debian cp ./binaries/yara-v${PACKAGE_VERSION}-linux-x64.tar.gz /tmp
43
+ ls -lh /tmp/yara-v${PACKAGE_VERSION}-*
44
+
45
+ # copy it to the repository clone and see if there's a difference
46
+ cp /tmp/yara-v${PACKAGE_VERSION}-* ./binaries
47
+ git status --porcelain
48
+
49
+ # By default, the commit is made in the name of "GitHub Actions"
50
+ # and co-authored by the user that made the last commit.
51
+ # https://github.com/marketplace/actions/git-auto-commit
52
+ - name: Commit the changes to the binary files
53
+ if: false # node-gyp builds are not reproducible, hence each build would create a "new" commit -> disabling for now (comment out this line if needed)
54
+ uses: stefanzweifel/git-auto-commit-action@v4
55
+ with:
56
+ ref: ${{ github.head_ref }} # https://github.com/marketplace/actions/git-auto-commit#checkout-the-correct-branch
57
+ commit_message: Commit the binary package changes for Linux / Node.js ${{ matrix.node-version }}
58
+ file_pattern: './binaries/*.tar.gz'
59
+
60
+
61
+ build-macos:
62
+ strategy:
63
+ fail-fast: false
64
+ matrix:
65
+ node-version:
66
+ # - '14'
67
+ - '16'
68
+ # - '18'
69
+
70
+ runs-on: macos-12
71
+
72
+ steps:
73
+ - uses: actions/checkout@v3
74
+
75
+ - name: Setup MacOs
76
+ run: brew install autoconf automake libmagic
77
+
78
+ - name: Use Node.js ${{ matrix.node-version }}
79
+ uses: actions/setup-node@master
80
+ with:
81
+ node-version: ${{ matrix.node-version }}
82
+
83
+ - name: Build binaries with node-pre-gyp
84
+ run: |
85
+ set -x
86
+ npm install --ignore-scripts
87
+ time -p npx node-pre-gyp configure rebuild
88
+
89
+ otool -L build/Release/yara.node
90
+
91
+ npx node-pre-gyp configure package
92
+
93
+ cp ./build/stage/Automattic/node-yara/raw/master/binaries/yara-*.tar.gz ./binaries
94
+ git status --porcelain
95
+
96
+ - name: Run tests
97
+ run: npm test
98
+
99
+ # By default, the commit is made in the name of "GitHub Actions"
100
+ # and co-authored by the user that made the last commit.
101
+ # https://github.com/marketplace/actions/git-auto-commit
102
+ - name: Commit the changes to the binary files
103
+ if: false # node-gyp builds are not reproducible, hence each build would create a "new" commit -> disabling for now (comment out this line if needed)
104
+ uses: stefanzweifel/git-auto-commit-action@v4
105
+ with:
106
+ ref: ${{ github.head_ref }} # https://github.com/marketplace/actions/git-auto-commit#checkout-the-correct-branch
107
+ commit_message: Commit the binary package changes for MacOS / Node.js ${{ matrix.node-version }}
108
+ file_pattern: './binaries/*.tar.gz'
@@ -0,0 +1,44 @@
1
+ # Check if the binaries we have in this repository actually work when "npm i" is run
2
+ name: Install and test the binary
3
+
4
+ on:
5
+ push:
6
+ branches: [ master ]
7
+ pull_request:
8
+
9
+ jobs:
10
+ test:
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ node-version:
15
+ # - '14'
16
+ - '16.16'
17
+ # - '18'
18
+ container:
19
+ - 'node:16.16-buster-slim'
20
+ - 'node:16.16-bullseye-slim'
21
+ - 'debian:unstable-slim'
22
+
23
+ runs-on: 'ubuntu-22.04' # the host system for the Action to be run, tests will be run inside the containers defined above
24
+
25
+ container:
26
+ image: ${{ matrix.container }}
27
+
28
+ steps:
29
+ - uses: actions/checkout@v3
30
+
31
+ - name: Use Node.js ${{ matrix.node-version }}
32
+ if: matrix.container == 'debian:unstable-slim' # node:16.16 containers already have Node.js installed, obviously :)
33
+ uses: actions/setup-node@master
34
+ with:
35
+ node-version: ${{ matrix.node-version }}
36
+
37
+ - name: Print distro and Node.js version information
38
+ run: cat /etc/os-release && node -v && npm -v
39
+
40
+ - name: Install the package
41
+ run: npm install
42
+
43
+ - name: Run the tests
44
+ run: npm test
@@ -13,7 +13,7 @@ jobs:
13
13
  publish-npm:
14
14
  runs-on: ubuntu-latest
15
15
  steps:
16
- - uses: actions/checkout@v2
16
+ - uses: actions/checkout@v3
17
17
  - uses: actions/setup-node@v1
18
18
  with:
19
19
  node-version: 14
@@ -1,7 +1,5 @@
1
- # This workflow will do a clean install of node dependencies, build the source code and run tests
2
- # For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
3
-
4
- name: Tests
1
+ # Check if the binaries we have in this repository actually work when "npm i" is run
2
+ name: Install and test the binary
5
3
 
6
4
  on:
7
5
  push:
@@ -14,40 +12,25 @@ jobs:
14
12
  fail-fast: false
15
13
  matrix:
16
14
  node-version:
17
- - '14'
15
+ # - '14'
18
16
  - '16'
19
- - '18'
17
+ # - '18'
20
18
  os:
21
- - 'ubuntu'
22
- - 'macos'
19
+ - 'ubuntu-22.04'
20
+ - 'macos-12'
23
21
 
24
- runs-on: ${{ matrix.os }}-latest
22
+ runs-on: ${{ matrix.os }}
25
23
 
26
24
  steps:
27
- - uses: actions/checkout@v2
28
-
29
- - name: Setup MacOs
30
- if: matrix.os == 'macos'
31
- run: brew install autoconf automake libmagic
25
+ - uses: actions/checkout@v3
32
26
 
33
27
  - name: Use Node.js ${{ matrix.node-version }}
34
28
  uses: actions/setup-node@master
35
29
  with:
36
30
  node-version: ${{ matrix.node-version }}
37
31
 
38
- - name: Build binaries with node-pre-gyp
39
- run: |
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
32
+ - name: Install the package
33
+ run: npm install
51
34
 
52
- - name: Run tests
35
+ - name: Run the tests
53
36
  run: npm test
package/.nvmrc ADDED
@@ -0,0 +1 @@
1
+ 16.16.0
package/Dockerfile ADDED
@@ -0,0 +1,40 @@
1
+ # this container is used to build binaries for Debian 10 (aka oldstable)
2
+ FROM node:16.16-buster-slim
3
+
4
+ RUN apt-get update -y && \
5
+ apt-get install -y \
6
+ autoconf \
7
+ build-essential \
8
+ curl \
9
+ libmagic-dev \
10
+ libssl-dev \
11
+ libtool \
12
+ pkg-config \
13
+ python3 \
14
+ time
15
+
16
+ WORKDIR /opt/a8c/node-yara
17
+ ENV HOME /opt/a8c/node-yara
18
+
19
+ # leverage the build cache by copying only the dependencies definition
20
+ COPY package.json .
21
+ RUN npm install --ignore-scripts
22
+
23
+ # now, let's copy the rest of the code
24
+ COPY . .
25
+
26
+ # we do not need root anymore
27
+ RUN chown -R nobody:nogroup ${HOME}
28
+ USER nobody
29
+
30
+ # build and test it
31
+ RUN time -p npx node-pre-gyp configure rebuild && \
32
+ npm t
33
+
34
+ # see dynamic dependencies
35
+ RUN ldd build/Release/yara.node
36
+
37
+ # prepare a tar.gz package and copy it to the binaries/ directory
38
+ RUN npx node-pre-gyp package && \
39
+ cp build/stage/Automattic/node-yara/raw/master/binaries/yara-*.tar.gz ./binaries && \
40
+ ls -lh ./binaries
package/README.md CHANGED
@@ -5,18 +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 3.9. You should download,
9
- compile and install your preferred version, or use one of the following
10
- commands using your system package manager:
11
-
12
- # CentOS/Red Hat
13
- sudo yum install yara-devel
14
-
15
- # Debian/Ubuntu
16
- sudo apt-get install libyara-dev
17
-
18
- # MacOS (using homebrew)
19
- sudo brew install yara
8
+ This module is built [using libyara 4.2.3](https://github.com/Automattic/node-yara/blob/master/Makefile#L14) and is statically linked against [libmagic](https://linux.die.net/man/3/libmagic).
20
9
 
21
10
  This module is installed using [node package manager (npm)][npm]:
22
11
 
@@ -26,6 +15,33 @@ This module is installed using [node package manager (npm)][npm]:
26
15
 
27
16
  npm i --save "yara@npm:@automattic/yara@latest"
28
17
 
18
+ # Developing
19
+
20
+ Or when developing this module, run the following after cloning the repo:
21
+
22
+ 1. Clone the repo.
23
+ 2. Make sure the dependencies are installed.
24
+
25
+ For Linux see the `Dockerfile`. For MacOS run `brew install autoconf automake libmagic`.
26
+
27
+ 3. Make sure that you're using the proper Node.js version by running `nvm use`.
28
+ 4. Run:
29
+ ```
30
+ $ npm install --ignore-scripts
31
+
32
+ $ ./node_modules/.bin/node-pre-gyp configure rebuild
33
+ (...)
34
+ SOLINK_MODULE(target) Release/yara.node
35
+
36
+ $ ./node_modules/.bin/node-pre-gyp package
37
+ (...)
38
+ node-pre-gyp info package Binary staged at "build/stage/Automattic/node-yara/raw/master/binaries/yara-v2.4.0-darwin-x64.tar.gz"
39
+ node-pre-gyp info ok
40
+
41
+ $ mv build/stage/Automattic/node-yara/raw/master/binaries/yara-*.tar.gz ./binaries
42
+ ```
43
+ 5. Now you have a new `yara.tar.gz` archives in the `binaries` directory.
44
+
29
45
  It is loaded using the `require()` function:
30
46
 
31
47
  var yara = require("yara")
@@ -0,0 +1,36 @@
1
+ Binaries
2
+ ========
3
+
4
+ These are pre-build binaries coming from the GH Action in this repository. They're used by `node-gyp` and fetched when you run `npm i` for `node-yara` package.
5
+
6
+ For instance:
7
+
8
+ ```
9
+ node-yara$ npm i
10
+
11
+ > @automattic/yara@2.4.0 install
12
+ > node-pre-gyp install --fallback-to-build
13
+
14
+ node-pre-gyp info it worked if it ends with ok
15
+ node-pre-gyp info using node-pre-gyp@1.0.10
16
+ node-pre-gyp info using node@16.16.0 | linux | x64
17
+ node-pre-gyp info check checked for "/tmp/node-yara/build/Release/yara.node" (not found)
18
+ node-pre-gyp http GET https://github.com/Automattic/node-yara/raw/master/binaries/yara-v2.4.0-linux-x64.tar.gz
19
+ node-pre-gyp info install unpacking Release/.deps/Release/obj.target/yara/src/yara.o.d
20
+ node-pre-gyp info install unpacking Release/.deps/Release/obj.target/yara.node.d
21
+ node-pre-gyp info install unpacking Release/.deps/Release/yara.node.d
22
+ node-pre-gyp info install unpacking Release/.deps/build/yara.d
23
+ node-pre-gyp info install unpacking Release/obj.target/yara/src/yara.o
24
+ node-pre-gyp info install unpacking Release/obj.target/yara.node
25
+ node-pre-gyp info extracted file count: 6
26
+ [@automattic/yara] Success: "/tmp/node-yara/build/Release/yara.node" is installed via remote
27
+ node-pre-gyp info ok
28
+ node-pre-gyp info install unpacking Release/yara.node
29
+
30
+ up to date, audited 119 packages in 4s
31
+
32
+ 22 packages are looking for funding
33
+ run `npm fund` for details
34
+
35
+ found 0 vulnerabilities
36
+ ```
package/binding.gyp CHANGED
@@ -1,5 +1,24 @@
1
1
  {
2
2
  "targets": [
3
+ {
4
+ "target_name": "action_before_build",
5
+ "type": "none",
6
+ "copies": [],
7
+ "conditions": [
8
+ ['OS == "linux"', {
9
+ "copies": [{
10
+ "files": [ "/usr/lib/x86_64-linux-gnu/libmagic.a" ],
11
+ "destination": "build/"
12
+ }],
13
+ }],
14
+ ['OS == "mac"', {
15
+ "copies": [{
16
+ "files": [ "/usr/local/opt/libmagic/lib/libmagic.a" ],
17
+ "destination": "build/"
18
+ }],
19
+ }],
20
+ ],
21
+ },
3
22
  {
4
23
  "target_name": "yara",
5
24
  "sources": [
@@ -14,7 +33,7 @@
14
33
  "./build/yara/include"
15
34
  ],
16
35
  "libraries": [
17
- "-lmagic",
36
+ "../build/libmagic.a",
18
37
  "../build/yara/lib/libyara.a"
19
38
  ],
20
39
  "conditions": [
package/package.json CHANGED
@@ -1,17 +1,26 @@
1
1
  {
2
2
  "name": "@automattic/yara",
3
- "version": "2.4.0",
3
+ "version": "2.5.0",
4
4
  "description": "Automattic's fork of YARA support for Node.js",
5
5
  "main": "index.js",
6
6
  "directories": {
7
7
  "example": "example"
8
8
  },
9
9
  "dependencies": {
10
- "nan": "2.14.*",
11
- "typescript": "^3.8.3"
10
+ "@mapbox/node-pre-gyp": "^1.0.10",
11
+ "nan": "2.17.*",
12
+ "typescript": "^4.9.5"
12
13
  },
13
14
  "scripts": {
14
- "test": "mocha test/*"
15
+ "test": "mocha test/*",
16
+ "install": "node-pre-gyp install --fallback-to-build"
17
+ },
18
+ "binary": {
19
+ "module_name": "yara",
20
+ "module_path": "./build/Release",
21
+ "host": "https://github.com/",
22
+ "remote_path": "/Automattic/node-yara/raw/master/binaries/",
23
+ "package_name": "{module_name}-v{version}-{platform}-{arch}.tar.gz"
15
24
  },
16
25
  "contributors": [
17
26
  {