scanoss 0.2.26 → 0.3.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/.github/workflows/reuse.yml +15 -0
- package/.github/workflows/scanoss.yml +24 -0
- package/.gitignore +0 -1
- package/.idea/.gitignore +5 -0
- package/.idea/codeStyles/Project.xml +61 -0
- package/.idea/codeStyles/codeStyleConfig.xml +5 -0
- package/.idea/inspectionProfiles/Project_Default.xml +6 -0
- package/.idea/modules.xml +8 -0
- package/.idea/scanoss.js.iml +12 -0
- package/.idea/vcs.xml +6 -0
- package/.idea/workspace.xml +366 -0
- package/.nyc_output/a25d3ac4-ee71-4c5e-926e-3a17714555cd.json +1 -0
- package/.nyc_output/processinfo/a25d3ac4-ee71-4c5e-926e-3a17714555cd.json +1 -0
- package/.nyc_output/processinfo/index.json +1 -0
- package/.reuse/dep5 +16 -0
- package/LICENSES/CC0-1.0.txt +121 -0
- package/LICENSES/MIT.txt +9 -0
- package/README.md +9 -0
- package/build/main/bin/cli-bin.js +5 -3
- package/build/main/commands/dep.js +1 -2
- package/build/main/commands/fingerprint.js +20 -12
- package/build/main/commands/helpers.js +1 -2
- package/build/main/commands/scan.js +7 -2
- package/build/main/index.js +1 -2
- package/build/main/lib/dependencies/DependencyScanner.d.ts +1 -1
- package/build/main/lib/dependencies/DependencyScanner.js +23 -12
- package/build/main/lib/dependencies/DependencyScannerCfg.js +1 -2
- package/build/main/lib/dependencies/DependencyTypes.js +0 -1
- package/build/main/lib/dependencies/LocalDependency/DependencyTypes.js +0 -1
- package/build/main/lib/dependencies/LocalDependency/LocalDependency.js +3 -2
- package/build/main/lib/dependencies/LocalDependency/parsers/golangParser.d.ts +1 -0
- package/build/main/lib/dependencies/LocalDependency/parsers/golangParser.js +50 -16
- package/build/main/lib/dependencies/LocalDependency/parsers/mavenParser.js +130 -15
- package/build/main/lib/dependencies/LocalDependency/parsers/npmParser.d.ts +10 -0
- package/build/main/lib/dependencies/LocalDependency/parsers/npmParser.js +146 -10
- package/build/main/lib/dependencies/LocalDependency/parsers/pyParser.js +1 -2
- package/build/main/lib/dependencies/LocalDependency/parsers/rubyParser.js +1 -2
- package/build/main/lib/dependencies/LocalDependency/parsers/utils.js +1 -2
- package/build/main/lib/filters/defaultFilter.js +1 -2
- package/build/main/lib/filters/filtering.js +1 -2
- package/build/main/lib/grpc/GrpcDependencyService.js +1 -2
- package/build/main/lib/grpc/scanoss/api/components/v2/scanoss-components_grpc_pb.d.ts +62 -0
- package/build/main/lib/grpc/scanoss/api/components/v2/scanoss-components_grpc_pb.js +128 -0
- package/build/main/lib/grpc/scanoss/api/components/v2/scanoss-components_pb.d.ts +1 -0
- package/build/main/lib/grpc/scanoss/api/components/v2/scanoss-components_pb.js +1403 -0
- package/build/main/lib/scanner/Dispatcher/DispatchableItem.d.ts +14 -5
- package/build/main/lib/scanner/Dispatcher/DispatchableItem.js +30 -10
- package/build/main/lib/scanner/Dispatcher/Dispatcher.d.ts +2 -2
- package/build/main/lib/scanner/Dispatcher/Dispatcher.js +10 -15
- package/build/main/lib/scanner/Dispatcher/DispatcherResponse.js +1 -2
- package/build/main/lib/scanner/Dispatcher/GlobalControllerAborter.js +1 -2
- package/build/main/lib/scanner/Scannable/ScannableItem.js +1 -2
- package/build/main/lib/scanner/Scanner.js +13 -9
- package/build/main/lib/scanner/ScannerCfg.js +2 -3
- package/build/main/lib/scanner/ScannerQueue.d.ts +3 -0
- package/build/main/lib/scanner/ScannerQueue.js +8 -0
- package/build/main/lib/scanner/ScannerTypes.d.ts +9 -2
- package/build/main/lib/scanner/ScannerTypes.js +8 -3
- package/build/main/lib/scanner/WfpProvider/FingerprintPackage.d.ts +9 -0
- package/build/main/lib/scanner/WfpProvider/FingerprintPackage.js +31 -0
- package/build/main/lib/scanner/WfpProvider/WfpCalculator/WfpCalculator.js +178 -21
- package/build/main/lib/scanner/WfpProvider/WfpCalculator/Winnower.d.ts +3 -0
- package/build/main/lib/scanner/WfpProvider/WfpCalculator/Winnower.js +211 -0
- package/build/main/lib/scanner/WfpProvider/WfpProvider.d.ts +2 -2
- package/build/main/lib/scanner/WfpProvider/WfpProvider.js +6 -7
- package/build/main/lib/scanner/WfpProvider/WfpSplitter/WfpSplitter.js +1 -2
- package/build/main/lib/tree/File.js +1 -2
- package/build/main/lib/tree/Folder.js +1 -2
- package/build/main/lib/tree/Node.js +1 -2
- package/build/main/lib/tree/Tree.js +1 -2
- package/build/module/bin/cli-bin.js +5 -2
- package/build/module/commands/fingerprint.js +25 -16
- package/build/module/commands/scan.js +8 -2
- package/build/module/lib/dependencies/DependencyScanner.d.ts +1 -1
- package/build/module/lib/dependencies/DependencyScanner.js +23 -11
- package/build/module/lib/dependencies/LocalDependency/LocalDependency.js +5 -3
- package/build/module/lib/dependencies/LocalDependency/parsers/golangParser.d.ts +1 -0
- package/build/module/lib/dependencies/LocalDependency/parsers/golangParser.js +47 -14
- package/build/module/lib/dependencies/LocalDependency/parsers/mavenParser.js +130 -14
- package/build/module/lib/dependencies/LocalDependency/parsers/npmParser.d.ts +10 -0
- package/build/module/lib/dependencies/LocalDependency/parsers/npmParser.js +140 -8
- package/build/module/lib/grpc/scanoss/api/components/v2/scanoss-components_grpc_pb.d.ts +62 -0
- package/build/module/lib/grpc/scanoss/api/components/v2/scanoss-components_grpc_pb.js +128 -0
- package/build/module/lib/grpc/scanoss/api/components/v2/scanoss-components_pb.d.ts +1 -0
- package/build/module/lib/grpc/scanoss/api/components/v2/scanoss-components_pb.js +1403 -0
- package/build/module/lib/scanner/Dispatcher/DispatchableItem.d.ts +14 -5
- package/build/module/lib/scanner/Dispatcher/DispatchableItem.js +32 -10
- package/build/module/lib/scanner/Dispatcher/Dispatcher.d.ts +2 -2
- package/build/module/lib/scanner/Dispatcher/Dispatcher.js +10 -14
- package/build/module/lib/scanner/Scanner.js +12 -8
- package/build/module/lib/scanner/ScannerCfg.js +2 -2
- package/build/module/lib/scanner/ScannerQueue.d.ts +3 -0
- package/build/module/lib/scanner/ScannerQueue.js +4 -0
- package/build/module/lib/scanner/ScannerTypes.d.ts +9 -2
- package/build/module/lib/scanner/ScannerTypes.js +7 -1
- package/build/module/lib/scanner/WfpProvider/FingerprintPackage.d.ts +9 -0
- package/build/module/lib/scanner/WfpProvider/FingerprintPackage.js +30 -0
- package/build/module/lib/scanner/WfpProvider/WfpCalculator/WfpCalculator.js +178 -20
- package/build/module/lib/scanner/WfpProvider/WfpCalculator/Winnower.d.ts +3 -0
- package/build/module/lib/scanner/WfpProvider/WfpCalculator/Winnower.js +211 -0
- package/build/module/lib/scanner/WfpProvider/WfpProvider.d.ts +2 -2
- package/build/module/lib/scanner/WfpProvider/WfpProvider.js +6 -6
- package/build/tsconfig.module.tsbuildinfo +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -17
- package/src/bin/cli-bin.ts +4 -1
- package/src/commands/fingerprint.ts +26 -17
- package/src/commands/scan.ts +16 -3
- package/src/lib/dependencies/DependencyScanner.ts +20 -13
- package/src/lib/dependencies/LocalDependency/LocalDependency.ts +8 -2
- package/src/lib/dependencies/LocalDependency/parsers/golangParser.ts +67 -15
- package/src/lib/dependencies/LocalDependency/parsers/mavenParser.ts +143 -16
- package/src/lib/dependencies/LocalDependency/parsers/npmParser.ts +182 -7
- package/src/lib/scanner/Dispatcher/DispatchableItem.ts +45 -11
- package/src/lib/scanner/Dispatcher/Dispatcher.ts +11 -14
- package/src/lib/scanner/Scanner.ts +17 -13
- package/src/lib/scanner/ScannerCfg.ts +2 -1
- package/src/lib/scanner/ScannerTypes.ts +10 -2
- package/src/lib/scanner/WfpProvider/{FingerprintPacket.ts → FingerprintPackage.ts} +4 -14
- package/src/lib/scanner/WfpProvider/WfpCalculator/WfpCalculator.ts +177 -20
- package/src/lib/scanner/WfpProvider/WfpProvider.ts +5 -5
- package/tests/WfpCalculator.spec.ts +103 -0
- package/tests/data/dependencies/Gemfile/1/Gemfile +6 -0
- package/tests/data/dependencies/Gemfile/1/Gemfile~ +0 -0
- package/tests/data/dependencies/Gemfile/2/Gemfile +3 -0
- package/tests/data/dependencies/Gemfile/2/Gemfile~ +6 -0
- package/tests/data/dependencies/Gemfile/3/Gemfile +7 -0
- package/tests/data/dependencies/Gemfile/3/Gemfile~ +6 -0
- package/tests/data/dependencies/Gemfile/4/Gemfile +31 -0
- package/tests/data/dependencies/Gemfile/4/Gemfile~ +7 -0
- package/tests/data/dependencies/Gemfile.lock/1/Gemfile.lock +180 -0
- package/tests/data/dependencies/Gemfile.lock/2/Gemfile.lock +60 -0
- package/tests/data/dependencies/Gemfile.lock/2/Gemfile.lock~ +0 -0
- package/tests/data/dependencies/go.sum/1/go.sum +119 -0
- package/tests/data/dependencies/go.sum/depJSON.sh +23 -0
- package/tests/data/dependencies/package-lock/1/package-lock.json +715 -0
- package/tests/data/dependencies/package-lock/2/package-lock.json +32069 -0
- package/tests/data/dependencies/package-lock/3/package-lock.json +9013 -0
- package/tests/data/dependencies/pom.xml/1/pom.xml +162 -0
- package/tests/data/dependencies/yarn-lock/generate_expected_output.sh +4 -0
- package/tests/data/dependencies/yarn-lock/v1/yarn.lock +50 -0
- package/tests/data/dependencies/yarn-lock/v1/yarn.lock-expected +13 -0
- package/tests/data/dependencies/yarn-lock/v1-complex/yarn.lock +27 -0
- package/tests/data/dependencies/yarn-lock/v1-complex/yarn.lock-expected +8 -0
- package/tests/data/dependencies/yarn-lock/v1-complex2/yarn.lock +220 -0
- package/tests/data/dependencies/yarn-lock/v2/yarn.lock +31 -0
- package/tests/data/dependencies/yarn-lock/v2/yarn.lock-expected +57 -0
- package/tests/data/dependencies/yarn-lock/v2-local/yarn.lock +11 -0
- package/tests/data/dependencies/yarn-lock/v2-local/yarn.lock-expected +27204 -0
- package/tests/data/scanner/file1.c +41 -0
- package/tests/data/scanner/file2.go +87 -0
- package/tests/dependencies/golangParser.goModParser.specs.ts +146 -0
- package/tests/dependencies/npmParser.spec.ts +133 -0
- package/tsconfig.json +4 -3
- package/yarn.lock +4596 -5321
- package/examples/defaultFilter.json +0 -203
- package/package-lock.json +0 -18588
- package/src/lib/scanner/Winnower/WinnowerExtractor.ts +0 -37
|
@@ -5,10 +5,9 @@ import { ScannableItem } from '../../Scannable/ScannableItem';
|
|
|
5
5
|
import { ScannerCfg } from '../../ScannerCfg';
|
|
6
6
|
import { ScannerEvents, ScannerInput, WinnowingMode } from '../../ScannerTypes';
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { FingerprintPackage } from '../FingerprintPackage';
|
|
9
9
|
import { IWfpProviderInput, WfpProvider } from '../WfpProvider';
|
|
10
10
|
|
|
11
|
-
|
|
12
11
|
const stringWorker = `
|
|
13
12
|
const { parentPort } = require('worker_threads');
|
|
14
13
|
|
|
@@ -21,7 +20,13 @@ parentPort.on('message', async (scannableItem) => {
|
|
|
21
20
|
scannableItem.contentSource,
|
|
22
21
|
scannableItem.maxSizeWfp
|
|
23
22
|
);
|
|
24
|
-
} else {
|
|
23
|
+
} else if (scannableItem.winnowingMode === "FULL_WINNOWING_HPSM") {
|
|
24
|
+
fingerprint = wfp_hpsm_for_content(
|
|
25
|
+
scannableItem.content,
|
|
26
|
+
scannableItem.contentSource,
|
|
27
|
+
scannableItem.maxSizeWfp
|
|
28
|
+
);
|
|
29
|
+
} else if (scannableItem.winnowingMode === "WINNOWING_ONLY_MD5") {
|
|
25
30
|
fingerprint = wfp_only_md5(
|
|
26
31
|
scannableItem.content,
|
|
27
32
|
scannableItem.contentSource
|
|
@@ -29,13 +34,15 @@ parentPort.on('message', async (scannableItem) => {
|
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
scannableItem.fingerprint = fingerprint;
|
|
32
|
-
|
|
33
37
|
parentPort.postMessage(scannableItem);
|
|
34
|
-
});
|
|
35
38
|
|
|
39
|
+
});
|
|
36
40
|
|
|
37
|
-
|
|
41
|
+
/**
|
|
42
|
+
* Winnowing and HPSM algorithm begins
|
|
43
|
+
*/
|
|
38
44
|
|
|
45
|
+
const crypto = require('crypto');
|
|
39
46
|
const isWin = process.platform === 'win32';
|
|
40
47
|
const pathSeparator = isWin ? String.fromCharCode(92) : '/';
|
|
41
48
|
|
|
@@ -75,18 +82,6 @@ function min_hex_array(array) {
|
|
|
75
82
|
return min;
|
|
76
83
|
}
|
|
77
84
|
|
|
78
|
-
function wfp_for_content(content, contentSource, maxSize) {
|
|
79
|
-
let wfp = wfp_only_md5(content, contentSource);
|
|
80
|
-
wfp += calc_wfp(content, maxSize);
|
|
81
|
-
return wfp;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function wfp_only_md5(contents, contentSource) {
|
|
85
|
-
const file_md5 = crypto.createHash('md5').update(contents).digest('hex');
|
|
86
|
-
let wfp = 'file=' + String(file_md5) + ',' + String(contents.length) + ',' + String(contentSource)+ String.fromCharCode(10);
|
|
87
|
-
return wfp;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
85
|
function calc_wfp(contents, maxSize) {
|
|
91
86
|
let gram = '';
|
|
92
87
|
const window = [];
|
|
@@ -229,6 +224,168 @@ function crc32c_hex(str) {
|
|
|
229
224
|
return crc32c(str).toString(16).padStart(8, '0');
|
|
230
225
|
}
|
|
231
226
|
|
|
227
|
+
function truncate_string(input, maxSize){
|
|
228
|
+
return input.slice(0, maxSize)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function toHexString(byteArray) {
|
|
232
|
+
return Array.from(byteArray, function(byte) {
|
|
233
|
+
return ('0' + (byte & 0xFF).toString(16)).slice(-2);
|
|
234
|
+
}).join('')
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function calc_hpsm(content) {
|
|
238
|
+
let list_normalized = []; //Array of numbers
|
|
239
|
+
let crc_lines = []; //Array of numbers that represent the crc8_maxim for each line of the file
|
|
240
|
+
|
|
241
|
+
let last_line = 0;
|
|
242
|
+
crc8_MAXIM_DOW_GenerateTable();
|
|
243
|
+
|
|
244
|
+
for(let i = 0; i<content.length; i++) {
|
|
245
|
+
const c = content[i];
|
|
246
|
+
if (c == ASCII_LF) { //When there is a new line
|
|
247
|
+
if (list_normalized.length) {
|
|
248
|
+
crc_lines.push(crc8_MAXIM_DOW_Buffer(list_normalized))
|
|
249
|
+
list_normalized=[];
|
|
250
|
+
} else if(last_line+1 == i) {
|
|
251
|
+
crc_lines.push(0xFF);
|
|
252
|
+
} else if (i-last_line > 1) {
|
|
253
|
+
crc_lines.push(0x00)
|
|
254
|
+
}
|
|
255
|
+
last_line = i;
|
|
256
|
+
} else {
|
|
257
|
+
const c_normalized = normalize(c);
|
|
258
|
+
if (c_normalized != 0) list_normalized.push(c_normalized)
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
return "hpsm=" + toHexString(crc_lines)
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* Create a wfp_hpsm package joining wfp (with md5 line) and a hpsm.
|
|
267
|
+
*
|
|
268
|
+
* Example:
|
|
269
|
+
* wfp = file=508cb9dfbe1c7dca5ed24f124473f33d,300,asd.c
|
|
270
|
+
* 11=b19bdbfa
|
|
271
|
+
*
|
|
272
|
+
* hpsm = hpsm=1909ff06ff688630ff45a92b52f47eff3500ffff
|
|
273
|
+
*
|
|
274
|
+
* wfp_hpsm = file=508cb9dfbe1c7dca5ed24f124473f33d,300,asd.c
|
|
275
|
+
* hpsm=1909ff06ff688630ff45a92b52f47eff3500ffff
|
|
276
|
+
* 11=b19bdbfa
|
|
277
|
+
*
|
|
278
|
+
* @param {string} wfp Complete wfp string (with md5 line)
|
|
279
|
+
* @param {string} hpsm
|
|
280
|
+
* @returns {string}
|
|
281
|
+
*/
|
|
282
|
+
function join_wfp_hpsm(wfp, hpsm) {
|
|
283
|
+
let header = wfp.match(/file=.*/);
|
|
284
|
+
header += String.fromCharCode(10);
|
|
285
|
+
header += hpsm;
|
|
286
|
+
wfp = wfp.replace(/file=.*/, "")
|
|
287
|
+
return header + wfp;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
*
|
|
292
|
+
* @param {Buffer} content
|
|
293
|
+
* @param {string} contentSource
|
|
294
|
+
* @param {number} maxSize
|
|
295
|
+
* @returns {string}
|
|
296
|
+
*/
|
|
297
|
+
function wfp_hpsm_for_content(content, contentSource, maxSize) {
|
|
298
|
+
let wfp = wfp_for_content(content, contentSource, maxSize)
|
|
299
|
+
let hpsm = calc_hpsm(content) //Returns a string
|
|
300
|
+
let wfp_hpsm_joined = join_wfp_hpsm(wfp, hpsm)
|
|
301
|
+
return truncate_string(wfp_hpsm_joined, maxSize)
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function wfp_for_content(content, contentSource, maxSize) {
|
|
305
|
+
let wfp = wfp_only_md5(content, contentSource);
|
|
306
|
+
wfp += calc_wfp(content, maxSize);
|
|
307
|
+
return wfp;
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
function wfp_only_md5(contents, contentSource) {
|
|
311
|
+
const file_md5 = crypto.createHash('md5').update(contents).digest('hex');
|
|
312
|
+
let wfp = 'file=' + String(file_md5) + ',' + String(contents.length) + ',' + String(contentSource)+ String.fromCharCode(10);
|
|
313
|
+
return wfp;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* CRC8_MAXIM algorithm begins
|
|
318
|
+
*/
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
//=============================================================================
|
|
322
|
+
// Implementation of CRC-8/MAXIM-DOW,CRC-8/MAXIM,DOW-CRC.
|
|
323
|
+
// Notes: Code ported from C Auto-generated by http://crc.drque.net/
|
|
324
|
+
//=============================================================================
|
|
325
|
+
|
|
326
|
+
//Table size
|
|
327
|
+
const CRC8_MAXIM_DOW_TABLE_SIZE = 0x100
|
|
328
|
+
const CRC8_MAXIM_DOW_POLYNOMIAL = 0x8C // 0x31 reflected
|
|
329
|
+
const CRC8_MAXIM_DOW_INITIAL = 0x00 // 0x00 reflected
|
|
330
|
+
const CRC8_MAXIM_DOW_FINAL = 0x00 // 0x00 reflected
|
|
331
|
+
|
|
332
|
+
let crc8_MAXIM_DOW_Table = []
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Compute CRC of byte without lookup tables.
|
|
336
|
+
*
|
|
337
|
+
* @param {number} crc Current CRC or initial value
|
|
338
|
+
* @param {number} byte New byte to accumulate.
|
|
339
|
+
* @returns {number} Updated CRC.
|
|
340
|
+
*/
|
|
341
|
+
function crc8_MAXIM_DOW_ByteNoTable(crc, byte) {
|
|
342
|
+
crc ^= byte;
|
|
343
|
+
for (let count = 0; count<8; count++) {
|
|
344
|
+
const isSet = (crc & 0x01)
|
|
345
|
+
crc >>= 1;
|
|
346
|
+
if (isSet) crc ^= CRC8_MAXIM_DOW_POLYNOMIAL
|
|
347
|
+
}
|
|
348
|
+
return crc
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
/**
|
|
352
|
+
* Create the lookup table.
|
|
353
|
+
* Note: Must be called before any table based CRC calculations can be done.
|
|
354
|
+
*/
|
|
355
|
+
function crc8_MAXIM_DOW_GenerateTable() {
|
|
356
|
+
for(let i = 0; i<CRC8_MAXIM_DOW_TABLE_SIZE; i++) {
|
|
357
|
+
crc8_MAXIM_DOW_Table.push(crc8_MAXIM_DOW_ByteNoTable(0, i))
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Update CRC by byte.
|
|
363
|
+
*
|
|
364
|
+
* @param {number} crc Initial CRC.
|
|
365
|
+
* @param {number} byte New byte to accumulate.
|
|
366
|
+
* @returns {number} Updated CRC.
|
|
367
|
+
*/
|
|
368
|
+
function crc8_MAXIM_DOW_Byte( crc, byte )
|
|
369
|
+
{
|
|
370
|
+
const index = byte ^ crc;
|
|
371
|
+
return crc8_MAXIM_DOW_Table[ index ] ^ ( crc >> 8 );
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
/**
|
|
375
|
+
* Compute CRC of buffer.
|
|
376
|
+
* Note: crc8_MAXIM_DOW_GenerateTable() must be called before use this function
|
|
377
|
+
*
|
|
378
|
+
* @param {Buffer} buffer Buffer with bytes to calculate CRC.
|
|
379
|
+
* @returns {number} CRC
|
|
380
|
+
*/
|
|
381
|
+
function crc8_MAXIM_DOW_Buffer(buffer) {
|
|
382
|
+
let crc = CRC8_MAXIM_DOW_INITIAL;
|
|
383
|
+
for (let index = 0; index < buffer.length ; index ++) {
|
|
384
|
+
crc = crc8_MAXIM_DOW_Byte(crc, buffer[index])
|
|
385
|
+
}
|
|
386
|
+
crc ^= CRC8_MAXIM_DOW_FINAL;
|
|
387
|
+
return crc;
|
|
388
|
+
}
|
|
232
389
|
`;
|
|
233
390
|
|
|
234
391
|
export class WfpCalculator extends WfpProvider {
|
|
@@ -260,7 +417,7 @@ export class WfpCalculator extends WfpProvider {
|
|
|
260
417
|
|
|
261
418
|
recoveryIndex() {
|
|
262
419
|
// Files: contains all files winnowed but not packed yet
|
|
263
|
-
const files = new
|
|
420
|
+
const files = new FingerprintPackage(this.wfp, this.folderRoot).getFilesFingerprinted();
|
|
264
421
|
if (files.length) {
|
|
265
422
|
const lastFileWinnowed = files[files.length - 1];
|
|
266
423
|
let i = 0;
|
|
@@ -284,7 +441,7 @@ export class WfpCalculator extends WfpProvider {
|
|
|
284
441
|
}
|
|
285
442
|
|
|
286
443
|
protected processPackedWfp(content) {
|
|
287
|
-
const fingerprint = new
|
|
444
|
+
const fingerprint = new FingerprintPackage(content, this.folderRoot);
|
|
288
445
|
this.sendFingerprint(fingerprint);
|
|
289
446
|
}
|
|
290
447
|
|
|
@@ -2,7 +2,7 @@ import { Worker } from 'worker_threads';
|
|
|
2
2
|
import { EventEmitter } from "stream";
|
|
3
3
|
import { ScannerCfg } from "../ScannerCfg";
|
|
4
4
|
import { ScannerEvents, ScannerInput, WinnowingMode } from "../ScannerTypes";
|
|
5
|
-
import {
|
|
5
|
+
import { FingerprintPackage } from "./FingerprintPackage";
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
export interface IWfpProviderInput {
|
|
@@ -46,7 +46,7 @@ export abstract class WfpProvider extends EventEmitter {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
if (this.wfp.length + fingerprint.length >= this.scannerCfg.WFP_FILE_MAX_SIZE) {
|
|
49
|
-
this.sendFingerprint(new
|
|
49
|
+
this.sendFingerprint(new FingerprintPackage(this.wfp, this.folderRoot));
|
|
50
50
|
this.wfp = '';
|
|
51
51
|
}
|
|
52
52
|
this.wfp += fingerprint;
|
|
@@ -56,14 +56,14 @@ export abstract class WfpProvider extends EventEmitter {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
protected finishWinnowing() {
|
|
59
|
-
if (this.wfp.length !== 0) this.sendFingerprint(new
|
|
59
|
+
if (this.wfp.length !== 0) this.sendFingerprint(new FingerprintPackage(this.wfp, this.folderRoot));
|
|
60
60
|
this.pendingFiles = false;
|
|
61
61
|
this.emit(ScannerEvents.WINNOWING_FINISHED);
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
|
|
65
|
-
protected sendFingerprint(
|
|
66
|
-
this.emit(ScannerEvents.WINNOWING_NEW_CONTENT,
|
|
65
|
+
protected sendFingerprint(fingerprintPackage: FingerprintPackage) {
|
|
66
|
+
this.emit(ScannerEvents.WINNOWING_NEW_CONTENT, fingerprintPackage);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
protected sendLog(logMsg: string): void {
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {WfpCalculator} from '../src/lib/scanner/WfpProvider/WfpCalculator/WfpCalculator';
|
|
2
|
+
import { IWfpProviderInput } from '../src/lib/scanner/WfpProvider/WfpProvider';
|
|
3
|
+
import {ScannerEvents, WinnowingMode} from '../src/lib/scanner/ScannerTypes'
|
|
4
|
+
import {
|
|
5
|
+
FingerprintPackage
|
|
6
|
+
} from '../src/lib/scanner/WfpProvider/FingerprintPackage';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
describe('Suit test for WfpCalculator Class', () => {
|
|
11
|
+
|
|
12
|
+
describe('Test Winnowings Modes', function () {
|
|
13
|
+
|
|
14
|
+
let wfpInput: IWfpProviderInput;
|
|
15
|
+
let wfpCalculator: WfpCalculator;
|
|
16
|
+
|
|
17
|
+
beforeEach(function() {
|
|
18
|
+
wfpCalculator = new WfpCalculator();
|
|
19
|
+
wfpCalculator.init();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('Winnowing Full mode', function (done) {
|
|
23
|
+
wfpInput = {
|
|
24
|
+
fileList: [__dirname + "/data/scanner/file1.c"],
|
|
25
|
+
folderRoot: __dirname + "/data/scanner/"
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
let wfpExpected = `file=736c0a4b4440e35baffc9378304ee588,907,file1.c
|
|
29
|
+
8=c0e39912
|
|
30
|
+
9=61eee030
|
|
31
|
+
11=eff88a55
|
|
32
|
+
16=9d9c5251,c8ca7af5
|
|
33
|
+
21=520ee8e5
|
|
34
|
+
26=1f2fa230,2e83cf84,57d0c3d2
|
|
35
|
+
28=4a9386b1
|
|
36
|
+
31=fbf8548e,b6002136
|
|
37
|
+
36=5622280b
|
|
38
|
+
39=8503d2f9
|
|
39
|
+
40=0b62ff71
|
|
40
|
+
`
|
|
41
|
+
|
|
42
|
+
wfpCalculator.on(ScannerEvents.WINNOWING_FINISHED, () => {
|
|
43
|
+
done()
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
wfpCalculator.on(ScannerEvents.ERROR, (err) => {
|
|
47
|
+
done(err)
|
|
48
|
+
})
|
|
49
|
+
|
|
50
|
+
wfpInput.winnowingMode=WinnowingMode.FULL_WINNOWING,
|
|
51
|
+
wfpCalculator.start(wfpInput)
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
it('Winnowing HPSM mode', function (done) {
|
|
56
|
+
|
|
57
|
+
wfpInput = {
|
|
58
|
+
fileList: [__dirname + "/data/scanner/file1.c"],
|
|
59
|
+
folderRoot: __dirname + "/data/scanner/"
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
let wfpExpected = `file=736c0a4b4440e35baffc9378304ee588,907,file1.c
|
|
63
|
+
hpsm=91ffe7ff989bffe7fcff91bdff2dff3d00a400ff9b00a400ffb6004c42ff9c004200ffc700ff62408b
|
|
64
|
+
8=c0e39912
|
|
65
|
+
9=61eee030
|
|
66
|
+
11=eff88a55
|
|
67
|
+
16=9d9c5251,c8ca7af5
|
|
68
|
+
21=520ee8e5
|
|
69
|
+
26=1f2fa230,2e83cf84,57d0c3d2
|
|
70
|
+
28=4a9386b1
|
|
71
|
+
31=fbf8548e,b6002136
|
|
72
|
+
36=5622280b
|
|
73
|
+
39=8503d2f9
|
|
74
|
+
40=0b62ff71
|
|
75
|
+
`
|
|
76
|
+
|
|
77
|
+
let wfpResponse: FingerprintPackage;
|
|
78
|
+
wfpCalculator.on(ScannerEvents.WINNOWING_NEW_CONTENT, (c: FingerprintPackage) => {
|
|
79
|
+
wfpResponse = c;
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
wfpCalculator.on(ScannerEvents.WINNOWING_FINISHED, () => {
|
|
83
|
+
if (wfpResponse.getContent() === wfpExpected) {
|
|
84
|
+
done()
|
|
85
|
+
} else {
|
|
86
|
+
done(new Error("Diferences in wfp generated and expected"))
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
wfpCalculator.on(ScannerEvents.ERROR, (err) => {
|
|
91
|
+
done(err)
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
wfpInput.winnowingMode=WinnowingMode.FULL_WINNOWING_HPSM;
|
|
95
|
+
wfpCalculator.start(wfpInput)
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
|
|
File without changes
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
source 'http://rubygems.org'
|
|
2
|
+
|
|
3
|
+
gem 'rails', '3.0.7'
|
|
4
|
+
|
|
5
|
+
# Bundle edge Rails instead:
|
|
6
|
+
# gem 'rails', :git => 'git://github.com/rails/rails.git'
|
|
7
|
+
|
|
8
|
+
gem 'sqlite3'
|
|
9
|
+
|
|
10
|
+
# Use unicorn as the web server
|
|
11
|
+
# gem 'unicorn'
|
|
12
|
+
|
|
13
|
+
# Deploy with Capistrano
|
|
14
|
+
# gem 'capistrano'
|
|
15
|
+
|
|
16
|
+
# To use debugger (ruby-debug for Ruby 1.8.7+, ruby-debug19 for Ruby 1.9.2+)
|
|
17
|
+
# gem 'ruby-debug'
|
|
18
|
+
# gem 'ruby-debug19', :require => 'ruby-debug'
|
|
19
|
+
|
|
20
|
+
# Bundle the extra gems:
|
|
21
|
+
# gem 'bj'
|
|
22
|
+
# gem 'nokogiri'
|
|
23
|
+
# gem 'sqlite3-ruby', :require => 'sqlite3'
|
|
24
|
+
# gem 'aws-s3', :require => 'aws/s3'
|
|
25
|
+
|
|
26
|
+
# Bundle gems for the local environment. Make sure to
|
|
27
|
+
# put test-only gems in this group so their generators
|
|
28
|
+
# and rake tasks are available in development mode:
|
|
29
|
+
# group :development, :test do
|
|
30
|
+
# gem 'webrat'
|
|
31
|
+
# end
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
GEM
|
|
2
|
+
remote: https://rubygems.org/
|
|
3
|
+
specs:
|
|
4
|
+
actioncable (5.0.6)
|
|
5
|
+
actionpack (= 5.0.6)
|
|
6
|
+
nio4r (>= 1.2, < 3.0)
|
|
7
|
+
websocket-driver (~> 0.6.1)
|
|
8
|
+
actionmailer (5.0.6)
|
|
9
|
+
actionpack (= 5.0.6)
|
|
10
|
+
actionview (= 5.0.6)
|
|
11
|
+
activejob (= 5.0.6)
|
|
12
|
+
mail (~> 2.5, >= 2.5.4)
|
|
13
|
+
rails-dom-testing (~> 2.0)
|
|
14
|
+
actionpack (5.0.6)
|
|
15
|
+
actionview (= 5.0.6)
|
|
16
|
+
activesupport (= 5.0.6)
|
|
17
|
+
rack (~> 2.0)
|
|
18
|
+
rack-test (~> 0.6.3)
|
|
19
|
+
rails-dom-testing (~> 2.0)
|
|
20
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
|
21
|
+
actionview (5.0.6)
|
|
22
|
+
activesupport (= 5.0.6)
|
|
23
|
+
builder (~> 3.1)
|
|
24
|
+
erubis (~> 2.7.0)
|
|
25
|
+
rails-dom-testing (~> 2.0)
|
|
26
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
|
27
|
+
activejob (5.0.6)
|
|
28
|
+
activesupport (= 5.0.6)
|
|
29
|
+
globalid (>= 0.3.6)
|
|
30
|
+
activemodel (5.0.6)
|
|
31
|
+
activesupport (= 5.0.6)
|
|
32
|
+
activerecord (5.0.6)
|
|
33
|
+
activemodel (= 5.0.6)
|
|
34
|
+
activesupport (= 5.0.6)
|
|
35
|
+
arel (~> 7.0)
|
|
36
|
+
activesupport (5.0.6)
|
|
37
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
38
|
+
i18n (~> 0.7)
|
|
39
|
+
minitest (~> 5.1)
|
|
40
|
+
tzinfo (~> 1.1)
|
|
41
|
+
arel (7.1.4)
|
|
42
|
+
bindex (0.5.0)
|
|
43
|
+
builder (3.2.3)
|
|
44
|
+
byebug (9.1.0)
|
|
45
|
+
coffee-rails (4.2.2)
|
|
46
|
+
coffee-script (>= 2.2.0)
|
|
47
|
+
railties (>= 4.0.0)
|
|
48
|
+
coffee-script (2.4.1)
|
|
49
|
+
coffee-script-source
|
|
50
|
+
execjs
|
|
51
|
+
coffee-script-source (1.12.2)
|
|
52
|
+
concurrent-ruby (1.0.5)
|
|
53
|
+
crass (1.0.2)
|
|
54
|
+
erubis (2.7.0)
|
|
55
|
+
execjs (2.7.0)
|
|
56
|
+
ffi (1.9.18)
|
|
57
|
+
globalid (0.4.0)
|
|
58
|
+
activesupport (>= 4.2.0)
|
|
59
|
+
i18n (0.8.6)
|
|
60
|
+
jbuilder (2.7.0)
|
|
61
|
+
activesupport (>= 4.2.0)
|
|
62
|
+
multi_json (>= 1.2)
|
|
63
|
+
jquery-rails (4.3.1)
|
|
64
|
+
rails-dom-testing (>= 1, < 3)
|
|
65
|
+
railties (>= 4.2.0)
|
|
66
|
+
thor (>= 0.14, < 2.0)
|
|
67
|
+
listen (3.0.8)
|
|
68
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
|
69
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
|
70
|
+
loofah (2.1.1)
|
|
71
|
+
crass (~> 1.0.2)
|
|
72
|
+
nokogiri (>= 1.5.9)
|
|
73
|
+
mail (2.6.6)
|
|
74
|
+
mime-types (>= 1.16, < 4)
|
|
75
|
+
method_source (0.9.0)
|
|
76
|
+
mime-types (3.1)
|
|
77
|
+
mime-types-data (~> 3.2015)
|
|
78
|
+
mime-types-data (3.2016.0521)
|
|
79
|
+
mini_portile2 (2.3.0)
|
|
80
|
+
minitest (5.10.3)
|
|
81
|
+
multi_json (1.12.2)
|
|
82
|
+
nio4r (2.1.0)
|
|
83
|
+
nokogiri (1.8.1)
|
|
84
|
+
mini_portile2 (~> 2.3.0)
|
|
85
|
+
puma (3.10.0)
|
|
86
|
+
rack (2.0.3)
|
|
87
|
+
rack-test (0.6.3)
|
|
88
|
+
rack (>= 1.0)
|
|
89
|
+
rails (5.0.6)
|
|
90
|
+
actioncable (= 5.0.6)
|
|
91
|
+
actionmailer (= 5.0.6)
|
|
92
|
+
actionpack (= 5.0.6)
|
|
93
|
+
actionview (= 5.0.6)
|
|
94
|
+
activejob (= 5.0.6)
|
|
95
|
+
activemodel (= 5.0.6)
|
|
96
|
+
activerecord (= 5.0.6)
|
|
97
|
+
activesupport (= 5.0.6)
|
|
98
|
+
bundler (>= 1.3.0)
|
|
99
|
+
railties (= 5.0.6)
|
|
100
|
+
sprockets-rails (>= 2.0.0)
|
|
101
|
+
rails-dom-testing (2.0.3)
|
|
102
|
+
activesupport (>= 4.2.0)
|
|
103
|
+
nokogiri (>= 1.6)
|
|
104
|
+
rails-html-sanitizer (1.0.3)
|
|
105
|
+
loofah (~> 2.0)
|
|
106
|
+
railties (5.0.6)
|
|
107
|
+
actionpack (= 5.0.6)
|
|
108
|
+
activesupport (= 5.0.6)
|
|
109
|
+
method_source
|
|
110
|
+
rake (>= 0.8.7)
|
|
111
|
+
thor (>= 0.18.1, < 2.0)
|
|
112
|
+
rake (12.1.0)
|
|
113
|
+
rb-fsevent (0.10.2)
|
|
114
|
+
rb-inotify (0.9.10)
|
|
115
|
+
ffi (>= 0.5.0, < 2)
|
|
116
|
+
sass (3.5.2)
|
|
117
|
+
sass-listen (~> 4.0.0)
|
|
118
|
+
sass-listen (4.0.0)
|
|
119
|
+
rb-fsevent (~> 0.9, >= 0.9.4)
|
|
120
|
+
rb-inotify (~> 0.9, >= 0.9.7)
|
|
121
|
+
sass-rails (5.0.6)
|
|
122
|
+
railties (>= 4.0.0, < 6)
|
|
123
|
+
sass (~> 3.1)
|
|
124
|
+
sprockets (>= 2.8, < 4.0)
|
|
125
|
+
sprockets-rails (>= 2.0, < 4.0)
|
|
126
|
+
tilt (>= 1.1, < 3)
|
|
127
|
+
spring (2.0.2)
|
|
128
|
+
activesupport (>= 4.2)
|
|
129
|
+
spring-watcher-listen (2.0.1)
|
|
130
|
+
listen (>= 2.7, < 4.0)
|
|
131
|
+
spring (>= 1.2, < 3.0)
|
|
132
|
+
sprockets (3.7.1)
|
|
133
|
+
concurrent-ruby (~> 1.0)
|
|
134
|
+
rack (> 1, < 3)
|
|
135
|
+
sprockets-rails (3.2.1)
|
|
136
|
+
actionpack (>= 4.0)
|
|
137
|
+
activesupport (>= 4.0)
|
|
138
|
+
sprockets (>= 3.0.0)
|
|
139
|
+
sqlite3 (1.3.13)
|
|
140
|
+
thor (0.20.0)
|
|
141
|
+
thread_safe (0.3.6)
|
|
142
|
+
tilt (2.0.8)
|
|
143
|
+
turbolinks (5.0.1)
|
|
144
|
+
turbolinks-source (~> 5)
|
|
145
|
+
turbolinks-source (5.0.3)
|
|
146
|
+
tzinfo (1.2.3)
|
|
147
|
+
thread_safe (~> 0.1)
|
|
148
|
+
uglifier (3.2.0)
|
|
149
|
+
execjs (>= 0.3.0, < 3)
|
|
150
|
+
web-console (3.5.1)
|
|
151
|
+
actionview (>= 5.0)
|
|
152
|
+
activemodel (>= 5.0)
|
|
153
|
+
bindex (>= 0.4.0)
|
|
154
|
+
railties (>= 5.0)
|
|
155
|
+
websocket-driver (0.6.5)
|
|
156
|
+
websocket-extensions (>= 0.1.0)
|
|
157
|
+
websocket-extensions (0.1.2)
|
|
158
|
+
|
|
159
|
+
PLATFORMS
|
|
160
|
+
ruby
|
|
161
|
+
|
|
162
|
+
DEPENDENCIES
|
|
163
|
+
byebug
|
|
164
|
+
coffee-rails (~> 4.2)
|
|
165
|
+
jbuilder (~> 2.5)
|
|
166
|
+
jquery-rails
|
|
167
|
+
listen (~> 3.0.5)
|
|
168
|
+
puma (~> 3.0)
|
|
169
|
+
rails (~> 5.0.0)
|
|
170
|
+
sass-rails (~> 5.0)
|
|
171
|
+
spring
|
|
172
|
+
spring-watcher-listen (~> 2.0.0)
|
|
173
|
+
sqlite3
|
|
174
|
+
turbolinks (~> 5)
|
|
175
|
+
tzinfo-data
|
|
176
|
+
uglifier (>= 1.3.0)
|
|
177
|
+
web-console
|
|
178
|
+
|
|
179
|
+
BUNDLED WITH
|
|
180
|
+
1.15.4
|