Skip to content

Commit

Permalink
CC-1225 jswhat
Browse files Browse the repository at this point in the history
  • Loading branch information
depperm committed Apr 20, 2023
1 parent 1bc8872 commit a6eb62d
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 1 deletion.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,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",
Expand Down
3 changes: 2 additions & 1 deletion src/core/config/Categories.json
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,8 @@
"View Bit Plane",
"Randomize Colour Palette",
"Extract LSB",
"ELF Info"
"ELF Info",
"What Is It"
]
},
{
Expand Down
99 changes: 99 additions & 0 deletions src/core/operations/WhatIsIt.mjs
Original file line number Diff line number Diff line change
@@ -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';

Check failure on line 8 in src/core/operations/WhatIsIt.mjs

View workflow job for this annotation

GitHub Actions / main

Strings must use doublequote

/**
* 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;
let fOptions = { search };

Check failure on line 54 in src/core/operations/WhatIsIt.mjs

View workflow job for this annotation

GitHub Actions / main

'fOptions' is never reassigned. Use 'const' instead
if (filter.length) {
fOptions.filter = filter.split(/,\s?/);
}
if (exclude.length) {
fOptions.exclude = exclude.split(/,\s?/);
}
console.log(fOptions)

Check failure on line 61 in src/core/operations/WhatIsIt.mjs

View workflow job for this annotation

GitHub Actions / main

Missing semicolon
return what.is(input, fOptions);
}
/**
* Displays WhatIsIt results in HTML for web apps.
*
* @param {JSON} options
* @returns {html}
*/
present(options) {
let output = `<table
class='table table-hover table-sm table-bordered'
style='table-layout: fixed;'>
<tr>
<th>Identified as</th>
<th>Matched Text</th>
<th>Description</th>
</tr>`;

options.forEach(option => {
output += `<tr>
<td>${option.name}</td>
<td>${option.matched}</td>
<td>${option.description}(${option.tags.join(', ')})</td>

Check failure on line 84 in src/core/operations/WhatIsIt.mjs

View workflow job for this annotation

GitHub Actions / main

Strings must use doublequote
</tr>`;
});

output += "</table><script type='application/javascript'>$('[data-toggle=\"tooltip\"]').tooltip()</script>";

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;

0 comments on commit a6eb62d

Please sign in to comment.