Merge remote-tracking branch 'upstream/master' into render-markdown

This commit is contained in:
j433866 2019-08-29 13:23:37 +01:00
commit 45fccb94e1
49 changed files with 834 additions and 772 deletions

View file

@ -167,6 +167,7 @@
"Parse IP range",
"Parse IPv6 address",
"Parse IPv4 header",
"Parse UDP",
"Parse SSH Host Key",
"Parse URI",
"URL Encode",

View file

@ -109,7 +109,7 @@ export function mean(data) {
*/
export function median(data) {
if ((data.length % 2) === 0 && data.length > 0) {
data.sort(function(a, b){
data.sort(function(a, b) {
return a.minus(b);
});
const first = data[Math.floor(data.length / 2)];

View file

@ -327,13 +327,13 @@ export function convertCoordinates (input, inFormat, inDelim, outFormat, outDeli
* @param {string} input - The input data to be split
* @returns {number[]} An array of the different items in the string, stored as floats
*/
function splitInput (input){
function splitInput (input) {
const split = [];
input.split(/\s+/).forEach(item => {
// Remove any character that isn't a digit, decimal point or negative sign
item = item.replace(/[^0-9.-]/g, "");
if (item.length > 0){
if (item.length > 0) {
// Turn the item into a float
split.push(parseFloat(item));
}
@ -350,7 +350,7 @@ function splitInput (input){
* @param {number} precision - The precision the result should be rounded to
* @returns {{string: string, degrees: number}} An object containing the raw converted value (obj.degrees), and a formatted string version (obj.string)
*/
function convDMSToDD (degrees, minutes, seconds, precision){
function convDMSToDD (degrees, minutes, seconds, precision) {
const absDegrees = Math.abs(degrees);
let conv = absDegrees + (minutes / 60) + (seconds / 3600);
let outString = round(conv, precision) + "°";
@ -566,7 +566,7 @@ export function findFormat (input, delim) {
// Test DMS/DDM/DD formats
if (testData !== undefined) {
const split = splitInput(testData);
switch (split.length){
switch (split.length) {
case 3:
return "Degrees Minutes Seconds";
case 2:

View file

@ -241,7 +241,7 @@ export function ipv6ListedRange(match, includeNetworkInfo) {
ipv6List = ipv6List.filter(function(str) {
return str.trim();
});
for (let i =0; i < ipv6List.length; i++){
for (let i =0; i < ipv6List.length; i++) {
ipv6List[i] = ipv6List[i].trim();
}
const ipv6CidrList = ipv6List.filter(function(a) {
@ -502,8 +502,8 @@ export function ipv6Compare(a, b) {
const a_ = strToIpv6(a),
b_ = strToIpv6(b);
for (let i = 0; i < a_.length; i++){
if (a_[i] !== b_[i]){
for (let i = 0; i < a_.length; i++) {
if (a_[i] !== b_[i]) {
return a_[i] - b_[i];
}
}

View file

@ -85,7 +85,7 @@ function getWords(length=3) {
const words = [];
let word;
let previousWord;
while (words.length < length){
while (words.length < length) {
do {
word = wordList[Math.floor(Math.random() * wordList.length)];
} while (previousWord === word);

View file

@ -71,8 +71,8 @@ class AESDecrypt extends Operation {
* @throws {OperationError} if cannot decrypt input or invalid key length
*/
run(input, args) {
const key = Utils.convertToByteArray(args[0].string, args[0].option),
iv = Utils.convertToByteArray(args[1].string, args[1].option),
const key = Utils.convertToByteString(args[0].string, args[0].option),
iv = Utils.convertToByteString(args[1].string, args[1].option),
mode = args[2],
inputType = args[3],
outputType = args[4],

View file

@ -64,7 +64,7 @@ class BlurImage extends Operation {
throw new OperationError(`Error loading image. (${err})`);
}
try {
switch (blurType){
switch (blurType) {
case "Fast":
if (isWorkerEnvironment())
self.sendStatusMessage("Fast blurring image...");

View file

@ -29,12 +29,12 @@ class ChangeIPFormat extends Operation {
{
"name": "Input format",
"type": "option",
"value": ["Dotted Decimal", "Decimal", "Hex"]
"value": ["Dotted Decimal", "Decimal", "Octal", "Hex"]
},
{
"name": "Output format",
"type": "option",
"value": ["Dotted Decimal", "Decimal", "Hex"]
"value": ["Dotted Decimal", "Decimal", "Octal", "Hex"]
}
];
}
@ -54,7 +54,6 @@ class ChangeIPFormat extends Operation {
if (lines[i] === "") continue;
let baIp = [];
let octets;
let decimal;
if (inFormat === outFormat) {
output += lines[i] + "\n";
@ -70,11 +69,10 @@ class ChangeIPFormat extends Operation {
}
break;
case "Decimal":
decimal = lines[i].toString();
baIp.push(decimal >> 24 & 255);
baIp.push(decimal >> 16 & 255);
baIp.push(decimal >> 8 & 255);
baIp.push(decimal & 255);
baIp = this.fromNumber(lines[i].toString(), 10);
break;
case "Octal":
baIp = this.fromNumber(lines[i].toString(), 8);
break;
case "Hex":
baIp = fromHex(lines[i]);
@ -100,6 +98,10 @@ class ChangeIPFormat extends Operation {
decIp = ((baIp[0] << 24) | (baIp[1] << 16) | (baIp[2] << 8) | baIp[3]) >>> 0;
output += decIp.toString() + "\n";
break;
case "Octal":
decIp = ((baIp[0] << 24) | (baIp[1] << 16) | (baIp[2] << 8) | baIp[3]) >>> 0;
output += "0" + decIp.toString(8) + "\n";
break;
case "Hex":
hexIp = "";
for (j = 0; j < baIp.length; j++) {
@ -115,6 +117,22 @@ class ChangeIPFormat extends Operation {
return output.slice(0, output.length-1);
}
/**
* Constructs an array of IP address octets from a numerical value.
* @param {string} value The value of the IP address
* @param {number} radix The numeral system to be used
* @returns {number[]}
*/
fromNumber(value, radix) {
const decimal = parseInt(value, radix);
const baIp = [];
baIp.push(decimal >> 24 & 255);
baIp.push(decimal >> 16 & 255);
baIp.push(decimal >> 8 & 255);
baIp.push(decimal & 255);
return baIp;
}
}
export default ChangeIPFormat;

View file

@ -111,7 +111,7 @@ class DNSOverHTTPS extends Operation {
* @returns {JSON}
*/
function extractData(data) {
if (typeof(data) == "undefined"){
if (typeof(data) == "undefined") {
return [];
} else {
const dataValues = [];

View file

@ -20,7 +20,7 @@ class ExtractDomains extends Operation {
this.name = "Extract domains";
this.module = "Regex";
this.description = "Extracts domain names.<br>Note that this will not include paths. Use <strong>Extract URLs</strong> to find entire URLs.";
this.description = "Extracts fully qualified domain names.<br>Note that this will not include paths. Use <strong>Extract URLs</strong> to find entire URLs.";
this.inputType = "string";
this.outputType = "string";
this.args = [

View file

@ -58,7 +58,7 @@ class FlipImage extends Operation {
try {
if (isWorkerEnvironment())
self.sendStatusMessage("Flipping image...");
switch (flipAxis){
switch (flipAxis) {
case "Horizontal":
image.flip(true, false);
break;

View file

@ -47,7 +47,7 @@ class GenerateLoremIpsum extends Operation {
*/
run(input, args) {
const [length, lengthType] = args;
if (length < 1){
if (length < 1) {
throw new OperationError("Length must be greater than 0");
}
switch (lengthType) {

View file

@ -48,7 +48,7 @@ class ImageFilter extends Operation {
*/
async run(input, args) {
const [filterType] = args;
if (!isImage(new Uint8Array(input))){
if (!isImage(new Uint8Array(input))) {
throw new OperationError("Invalid file type.");
}

View file

@ -34,7 +34,7 @@ class MicrosoftScriptDecoder extends Operation {
run(input, args) {
const matcher = /#@~\^.{6}==(.+).{6}==\^#~@/;
const encodedData = matcher.exec(input);
if (encodedData){
if (encodedData) {
return MicrosoftScriptDecoder._decode(encodedData[1]);
} else {
return "";

View file

@ -134,7 +134,7 @@ CMYK: ${cmyk}
static _hslToRgb(h, s, l) {
let r, g, b;
if (s === 0){
if (s === 0) {
r = g = b = l; // achromatic
} else {
const hue2rgb = function hue2rgb(p, q, t) {

View file

@ -0,0 +1,84 @@
/**
* @author h345983745 []
* @copyright Crown Copyright 2019
* @license Apache-2.0
*/
import Operation from "../Operation.mjs";
import Stream from "../lib/Stream.mjs";
import {toHex} from "../lib/Hex.mjs";
import OperationError from "../errors/OperationError.mjs";
/**
* Parse UDP operation
*/
class ParseUDP extends Operation {
/**
* ParseUDP constructor
*/
constructor() {
super();
this.name = "Parse UDP";
this.module = "Default";
this.description = "Parses a UDP header and payload (if present).";
this.infoURL = "https://wikipedia.org/wiki/User_Datagram_Protocol";
this.inputType = "ArrayBuffer";
this.outputType = "json";
this.presentType = "html";
this.args = [];
}
/**
* @param {ArrayBuffer} input
* @returns {Object}
*/
run(input, args) {
if (input.byteLength < 8) {
throw new OperationError("Need 8 bytes for a UDP Header");
}
const s = new Stream(new Uint8Array(input));
// Parse Header
const UDPPacket = {
"Source port": s.readInt(2),
"Destination port": s.readInt(2),
"Length": s.readInt(2),
"Checksum": toHex(s.getBytes(2), "")
};
// Parse data if present
if (s.hasMore()) {
UDPPacket.Data = toHex(s.getBytes(UDPPacket.Length - 8), "");
}
return UDPPacket;
}
/**
* Displays the UDP Packet in a table style
* @param {Object} data
* @returns {html}
*/
present(data) {
const html = [];
html.push("<table class='table table-hover table-sm table-bordered table-nonfluid' style='table-layout: fixed'>");
html.push("<tr>");
html.push("<th>Field</th>");
html.push("<th>Value</th>");
html.push("</tr>");
for (const key in data) {
html.push("<tr>");
html.push("<td style=\"word-wrap:break-word\">" + key + "</td>");
html.push("<td>" + data[key] + "</td>");
html.push("</tr>");
}
html.push("</table>");
return html.join("");
}
}
export default ParseUDP;

View file

@ -41,7 +41,7 @@ class ScanForEmbeddedFiles extends Operation {
* @returns {string}
*/
run(input, args) {
let output = "Scanning data for 'magic bytes' which may indicate embedded files. The following results may be false positives and should not be treat as reliable. Any suffiently long file is likely to contain these magic bytes coincidentally.\n",
let output = "Scanning data for 'magic bytes' which may indicate embedded files. The following results may be false positives and should not be treat as reliable. Any sufficiently long file is likely to contain these magic bytes coincidentally.\n",
numFound = 0;
const categories = [],
data = new Uint8Array(input);

View file

@ -62,7 +62,7 @@ class SharpenImage extends Operation {
async run(input, args) {
const [radius, amount, threshold] = args;
if (!isImage(new Uint8Array(input))){
if (!isImage(new Uint8Array(input))) {
throw new OperationError("Invalid file type.");
}

View file

@ -79,7 +79,7 @@ class SwapEndianness extends Operation {
const word = data.slice(i, i + wordLength);
// Pad word if too short
if (padIncompleteWords && word.length < wordLength){
if (padIncompleteWords && word.length < wordLength) {
for (j = word.length; j < wordLength; j++) {
word.push(0);
}

View file

@ -51,7 +51,7 @@ class UNIXTimestampToWindowsFiletime extends Operation {
input = new BigNumber(input);
if (units === "Seconds (s)"){
if (units === "Seconds (s)") {
input = input.multipliedBy(new BigNumber("10000000"));
} else if (units === "Milliseconds (ms)") {
input = input.multipliedBy(new BigNumber("10000"));
@ -65,7 +65,7 @@ class UNIXTimestampToWindowsFiletime extends Operation {
input = input.plus(new BigNumber("116444736000000000"));
if (format === "Hex"){
if (format === "Hex") {
return input.toString(16);
} else {
return input.toFixed();

View file

@ -57,7 +57,7 @@ class WindowsFiletimeToUNIXTimestamp extends Operation {
input = input.minus(new BigNumber("116444736000000000"));
if (units === "Seconds (s)"){
if (units === "Seconds (s)") {
input = input.dividedBy(new BigNumber("10000000"));
} else if (units === "Milliseconds (ms)") {
input = input.dividedBy(new BigNumber("10000"));