diff --git a/package-lock.json b/package-lock.json index ec3c65ae..e02dd92b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -55,6 +55,7 @@ "jsonwebtoken": "8.5.1", "jsqr": "^1.4.0", "jsrsasign": "^10.6.1", + "jswhat": "^2.0.1", "kbpgp": "2.1.15", "libbzip2-wasm": "0.0.4", "libyara-wasm": "^1.2.1", @@ -9491,6 +9492,14 @@ "url": "https://github.com/kjur/jsrsasign#donations" } }, + "node_modules/jswhat": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/jswhat/-/jswhat-2.0.1.tgz", + "integrity": "sha512-hG4KZxhTaTSxn03Vr44OAnMUR6pYYWMylcnvkXAaB9qqpjOVKWJZRjN2iFuFa4jbqiyKIBj5t+SL/kpHbk7j5A==", + "bin": { + "what": "dist/what.js" + } + }, "node_modules/jszip": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/jszip/-/jszip-2.7.0.tgz", @@ -24441,6 +24450,11 @@ "resolved": "https://registry.npmjs.org/jsrsasign/-/jsrsasign-10.8.6.tgz", "integrity": "sha512-bQmbVtsfbgaKBTWCKiDCPlUPbdlRIK/FzSwT3BzIgZl/cU6TqXu6pZJsCI/dJVrZ9Gir5GC4woqw9shH/v7MBw==" }, + "jswhat": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/jswhat/-/jswhat-2.0.1.tgz", + "integrity": "sha512-hG4KZxhTaTSxn03Vr44OAnMUR6pYYWMylcnvkXAaB9qqpjOVKWJZRjN2iFuFa4jbqiyKIBj5t+SL/kpHbk7j5A==" + }, "jszip": { "version": "2.7.0", "resolved": "https://registry.npmjs.org/jszip/-/jszip-2.7.0.tgz", diff --git a/package.json b/package.json index 98f9cbc0..82235eaf 100644 --- a/package.json +++ b/package.json @@ -137,6 +137,7 @@ "jsonwebtoken": "8.5.1", "jsqr": "^1.4.0", "jsrsasign": "^10.6.1", + "jswhat": "^2.0.1", "kbpgp": "2.1.15", "libbzip2-wasm": "0.0.4", "libyara-wasm": "^1.2.1", diff --git a/src/core/config/Categories.json b/src/core/config/Categories.json index 629d383a..9393d318 100644 --- a/src/core/config/Categories.json +++ b/src/core/config/Categories.json @@ -473,7 +473,8 @@ "View Bit Plane", "Randomize Colour Palette", "Extract LSB", - "ELF Info" + "ELF Info", + "What Is It" ] }, { diff --git a/src/core/operations/WhatIsIt.mjs b/src/core/operations/WhatIsIt.mjs new file mode 100644 index 00000000..9a28b5df --- /dev/null +++ b/src/core/operations/WhatIsIt.mjs @@ -0,0 +1,99 @@ +/** + * @author depperm [epper.marshall@gmail.com] + * @copyright Crown Copyright 2023 + * @license Apache-2.0 + */ + +import Operation from "../Operation.mjs"; +import what from "jswhat"; + +/** + * WhatIsIt operation + */ +class WhatIsIt extends Operation { + + /** + * WhatIsIt constructor + */ + constructor() { + super(); + + this.name = "What Is It"; + this.module = "Default"; + this.description = "Implements JsWhat, a PyWhat port, to guess what a string is."; + this.infoURL = "https://github.com/apteryxxyz/jswhat"; + this.inputType = "string"; + this.outputType = "JSON"; + this.presentType = "html"; + this.args = [ + { + name: "Search", + type: "boolean", + value: false + }, + { + name: "Filter", + type: "string", + value: "" + }, + { + name: "Exclude", + type: "string", + value: "" + } + ]; + } + + /** + * @param {string} input + * @param {Object[]} args + * @returns {JSON} + */ + run(input, args) { + const [search, filter, exclude] = args; + const fOptions = { search }; + if (filter.length) { + fOptions.filter = filter.split(/,\s?/); + } + if (exclude.length) { + fOptions.exclude = exclude.split(/,\s?/); + } + + return what.is(input, fOptions); + } + /** + * Displays WhatIsIt results in HTML for web apps. + * + * @param {JSON} options + * @returns {html} + */ + present(options) { + let output = ` + + + + + `; + + options.forEach(option => { + output += ` + + + + `; + }); + + output += "
Identified asMatched TextDescription
${option.name}${option.matched}${option.description}(${option.tags.join(", ")})
"; + + if (!options.length) { + output = "Nothing of interest could be detected about the input data.\nHave you tried modifying the operation arguments?"; + } + + return output; + } + +} + +export default WhatIsIt;