swap ENVIRONMENT_IS_* functions for Utils named exports

This commit is contained in:
d98762625 2019-07-05 10:17:52 +01:00
parent c70f14419a
commit 1c24c05647
41 changed files with 117 additions and 141 deletions

View file

@ -6,6 +6,7 @@
import Operation from "../Operation";
import bcrypt from "bcryptjs";
import { isWorkerEnvironment } from "../Utils";
/**
* Bcrypt operation
@ -44,7 +45,7 @@ class Bcrypt extends Operation {
return await bcrypt.hash(input, salt, null, p => {
// Progress callback
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage(`Progress: ${(p * 100).toFixed(0)}%`);
});

View file

@ -6,6 +6,8 @@
import Operation from "../Operation";
import bcrypt from "bcryptjs";
import { isWorkerEnvironment } from "../Utils";
/**
* Bcrypt compare operation
@ -43,7 +45,7 @@ class BcryptCompare extends Operation {
const match = await bcrypt.compare(input, hash, null, p => {
// Progress callback
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage(`Progress: ${(p * 100).toFixed(0)}%`);
});

View file

@ -6,6 +6,7 @@
import Operation from "../Operation";
import OperationError from "../errors/OperationError";
import { isWorkerEnvironment } from "../Utils";
import { isImage } from "../lib/FileType";
import { toBase64 } from "../lib/Base64";
import jimp from "jimp";
@ -67,7 +68,7 @@ class BlurImage extends Operation {
image.blur(blurAmount);
break;
case "Gaussian":
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage("Gaussian blurring image. This may take a while...");
image.gaussian(blurAmount);
break;

View file

@ -8,8 +8,9 @@
import Operation from "../Operation";
import OperationError from "../errors/OperationError";
import {BombeMachine} from "../lib/Bombe";
import {ROTORS, ROTORS_FOURTH, REFLECTORS, Reflector} from "../lib/Enigma";
import { isWorkerEnvironment } from "../Utils";
import { BombeMachine } from "../lib/Bombe";
import { ROTORS, ROTORS_FOURTH, REFLECTORS, Reflector } from "../lib/Enigma";
/**
* Bombe operation
@ -139,7 +140,7 @@ class Bombe extends Operation {
const ciphertext = input.slice(offset);
const reflector = new Reflector(reflectorstr);
let update;
if (ENVIRONMENT_IS_WORKER()) {
if (isWorkerEnvironment()) {
update = this.updateStatus;
} else {
update = undefined;

View file

@ -8,6 +8,7 @@ import Operation from "../Operation";
import OperationError from "../errors/OperationError";
import { isImage } from "../lib/FileType";
import { toBase64 } from "../lib/Base64.mjs";
import { isWorkerEnvironment } from "../Utils";
import jimp from "jimp";
/**
@ -112,7 +113,7 @@ class ContainImage extends Operation {
throw new OperationError(`Error loading image. (${err})`);
}
try {
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage("Containing image...");
image.contain(width, height, alignMap[hAlign] | alignMap[vAlign], resizeMap[alg]);
const imageBuffer = await image.getBufferAsync(jimp.AUTO);

View file

@ -8,6 +8,7 @@ import Operation from "../Operation";
import OperationError from "../errors/OperationError";
import { isImage } from "../lib/FileType";
import { toBase64 } from "../lib/Base64.mjs";
import { isWorkerEnvironment } from "../Utils";
import jimp from "jimp";
/**
@ -112,7 +113,7 @@ class CoverImage extends Operation {
throw new OperationError(`Error loading image. (${err})`);
}
try {
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage("Covering image...");
image.cover(width, height, alignMap[hAlign] | alignMap[vAlign], resizeMap[alg]);
const imageBuffer = await image.getBufferAsync(jimp.AUTO);

View file

@ -8,6 +8,7 @@ import Operation from "../Operation";
import OperationError from "../errors/OperationError";
import { isImage } from "../lib/FileType";
import { toBase64 } from "../lib/Base64.mjs";
import { isWorkerEnvironment } from "../Utils";
import jimp from "jimp";
/**
@ -103,7 +104,7 @@ class CropImage extends Operation {
throw new OperationError(`Error loading image. (${err})`);
}
try {
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage("Cropping image...");
if (autocrop) {
image.autocrop({

View file

@ -8,6 +8,7 @@ import Operation from "../Operation";
import OperationError from "../errors/OperationError";
import { isImage } from "../lib/FileType";
import { toBase64 } from "../lib/Base64";
import { isWorkerEnvironment } from "../Utils";
import jimp from "jimp";
/**
@ -48,7 +49,7 @@ class DitherImage extends Operation {
throw new OperationError(`Error loading image. (${err})`);
}
try {
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage("Applying dither to image...");
image.dither565();
const imageBuffer = await image.getBufferAsync(jimp.AUTO);

View file

@ -8,6 +8,7 @@ import Operation from "../Operation";
import OperationError from "../errors/OperationError";
import { isImage } from "../lib/FileType";
import { toBase64 } from "../lib/Base64";
import { isWorkerEnvironment } from "../Utils";
import jimp from "jimp";
/**
@ -55,7 +56,7 @@ class FlipImage extends Operation {
throw new OperationError(`Error loading image. (${err})`);
}
try {
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage("Flipping image...");
switch (flipAxis){
case "Horizontal":

View file

@ -6,7 +6,8 @@
import Operation from "../Operation";
import Utils from "../Utils";
import {DELIM_OPTIONS} from "../lib/Delim";
import { DELIM_OPTIONS } from "../lib/Delim";
import { isWorkerEnvironment } from "../Utils";
import OperationError from "../errors/OperationError";
/**
@ -61,7 +62,7 @@ class FromCharcode extends Operation {
return [];
}
if (base !== 16 && ENVIRONMENT_IS_WORKER()) self.setOption("attemptHighlight", false);
if (base !== 16 && isWorkerEnvironment()) self.setOption("attemptHighlight", false);
// Split into groups of 2 if the whole string is concatenated and
// too long to be a single character

View file

@ -5,7 +5,9 @@
*/
import Operation from "../Operation";
import {fromHex} from "../lib/Hex";
import { fromHex } from "../lib/Hex";
import { isWorkerEnvironment } from "../Utils";
/**
* From Hexdump operation
@ -55,7 +57,7 @@ class FromHexdump extends Operation {
const w = (width - 13) / 4;
// w should be the specified width of the hexdump and therefore a round number
if (Math.floor(w) !== w || input.indexOf("\r") !== -1 || output.indexOf(13) !== -1) {
if (ENVIRONMENT_IS_WORKER()) self.setOption("attemptHighlight", false);
if (isWorkerEnvironment()) self.setOption("attemptHighlight", false);
}
return output;
}

View file

@ -8,6 +8,7 @@ import Operation from "../Operation";
import OperationError from "../errors/OperationError";
import { isImage } from "../lib/FileType";
import { toBase64 } from "../lib/Base64.mjs";
import { isWorkerEnvironment } from "../Utils";
import jimp from "jimp";
/**
@ -65,12 +66,12 @@ class ImageBrightnessContrast extends Operation {
}
try {
if (brightness !== 0) {
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage("Changing image brightness...");
image.brightness(brightness / 100);
}
if (contrast !== 0) {
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage("Changing image contrast...");
image.contrast(contrast / 100);
}

View file

@ -8,6 +8,7 @@ import Operation from "../Operation";
import OperationError from "../errors/OperationError";
import { isImage } from "../lib/FileType";
import { toBase64 } from "../lib/Base64.mjs";
import { isWorkerEnvironment } from "../Utils";
import jimp from "jimp";
/**
@ -58,7 +59,7 @@ class ImageFilter extends Operation {
throw new OperationError(`Error loading image. (${err})`);
}
try {
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage("Applying " + filterType.toLowerCase() + " filter to image...");
if (filterType === "Greyscale") {
image.greyscale();

View file

@ -8,6 +8,7 @@ import Operation from "../Operation";
import OperationError from "../errors/OperationError";
import { isImage } from "../lib/FileType";
import { toBase64 } from "../lib/Base64.mjs";
import { isWorkerEnvironment } from "../Utils";
import jimp from "jimp";
/**
@ -73,7 +74,7 @@ class ImageHueSaturationLightness extends Operation {
}
try {
if (hue !== 0) {
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage("Changing image hue...");
image.colour([
{
@ -83,7 +84,7 @@ class ImageHueSaturationLightness extends Operation {
]);
}
if (saturation !== 0) {
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage("Changing image saturation...");
image.colour([
{
@ -93,7 +94,7 @@ class ImageHueSaturationLightness extends Operation {
]);
}
if (lightness !== 0) {
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage("Changing image lightness...");
image.colour([
{

View file

@ -8,6 +8,7 @@ import Operation from "../Operation";
import OperationError from "../errors/OperationError";
import { isImage } from "../lib/FileType";
import { toBase64 } from "../lib/Base64.mjs";
import { isWorkerEnvironment } from "../Utils";
import jimp from "jimp";
/**
@ -57,7 +58,7 @@ class ImageOpacity extends Operation {
throw new OperationError(`Error loading image. (${err})`);
}
try {
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage("Changing image opacity...");
image.opacity(opacity / 100);

View file

@ -8,6 +8,7 @@ import Operation from "../Operation";
import OperationError from "../errors/OperationError";
import { isImage } from "../lib/FileType";
import { toBase64 } from "../lib/Base64";
import { isWorkerEnvironment } from "../Utils";
import jimp from "jimp";
/**
@ -48,7 +49,7 @@ class InvertImage extends Operation {
throw new OperationError(`Error loading image. (${err})`);
}
try {
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage("Inverting image...");
image.invert();
const imageBuffer = await image.getBufferAsync(jimp.AUTO);

View file

@ -9,8 +9,10 @@
import Operation from "../Operation";
import OperationError from "../errors/OperationError";
import {BombeMachine} from "../lib/Bombe";
import {ROTORS, ROTORS_FOURTH, REFLECTORS, Reflector} from "../lib/Enigma";
import { BombeMachine } from "../lib/Bombe";
import { ROTORS, ROTORS_FOURTH, REFLECTORS, Reflector } from "../lib/Enigma";
import { isWorkerEnvironment } from "../Utils";
/**
* Convenience method for flattening the preset ROTORS object into a newline-separated string.
@ -222,7 +224,7 @@ class MultipleBombe extends Operation {
crib = crib.replace(/[^A-Za-z]/g, "").toUpperCase();
const ciphertext = input.slice(offset);
let update;
if (ENVIRONMENT_IS_WORKER()) {
if (isWorkerEnvironment()) {
update = this.updateStatus;
} else {
update = undefined;

View file

@ -8,6 +8,7 @@ import Operation from "../Operation";
import Utils from "../Utils";
import forge from "node-forge/dist/forge.min.js";
import BigNumber from "bignumber.js";
import { isWorkerEnvironment } from "../Utils";
/**
* Pseudo-Random Number Generator operation
@ -50,7 +51,7 @@ class PseudoRandomNumberGenerator extends Operation {
let bytes;
if (ENVIRONMENT_IS_WORKER() && self.crypto) {
if (isWorkerEnvironment() && self.crypto) {
bytes = self.crypto.getRandomValues(new Uint8Array(numBytes));
bytes = Utils.arrayBufferToStr(bytes.buffer);
} else {

View file

@ -7,6 +7,7 @@
import Operation from "../Operation";
import Dish from "../Dish";
import XRegExp from "xregexp";
import { isWorkerEnvironment } from "../Utils";
/**
* Register operation
@ -72,7 +73,7 @@ class Register extends Operation {
if (!registers) return state;
if (ENVIRONMENT_IS_WORKER()) {
if (isWorkerEnvironment()) {
self.setRegisters(state.forkOffset + state.progress, state.numRegisters, registers.slice(1));
}

View file

@ -8,6 +8,7 @@ import Operation from "../Operation";
import OperationError from "../errors/OperationError";
import { isImage } from "../lib/FileType";
import { toBase64 } from "../lib/Base64.mjs";
import { isWorkerEnvironment } from "../Utils";
import jimp from "jimp";
/**
@ -102,7 +103,7 @@ class ResizeImage extends Operation {
height = image.getHeight() * (height / 100);
}
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage("Resizing image...");
if (aspect) {
image.scaleToFit(width, height, resizeMap[resizeAlg]);

View file

@ -8,6 +8,7 @@ import Operation from "../Operation";
import OperationError from "../errors/OperationError";
import { isImage } from "../lib/FileType";
import { toBase64 } from "../lib/Base64";
import { isWorkerEnvironment } from "../Utils";
import jimp from "jimp";
/**
@ -56,7 +57,7 @@ class RotateImage extends Operation {
throw new OperationError(`Error loading image. (${err})`);
}
try {
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage("Rotating image...");
image.rotate(degrees);
const imageBuffer = await image.getBufferAsync(jimp.AUTO);

View file

@ -6,8 +6,8 @@
import Operation from "../Operation";
import Utils from "../Utils";
import {scanForFileTypes} from "../lib/FileType";
import {FILE_SIGNATURES} from "../lib/FileSignatures";
import { scanForFileTypes } from "../lib/FileType";
import { FILE_SIGNATURES } from "../lib/FileSignatures";
/**
* Scan for Embedded Files operation

View file

@ -8,6 +8,7 @@ import Operation from "../Operation";
import Utils from "../Utils";
import OperationError from "../errors/OperationError";
import scryptsy from "scryptsy";
import { isWorkerEnvironment } from "../Utils";
/**
* Scrypt operation
@ -73,7 +74,7 @@ class Scrypt extends Operation {
input, salt, iterations, memFactor, parallelFactor, keyLength,
p => {
// Progress callback
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage(`Progress: ${p.percent.toFixed(0)}%`);
}
);

View file

@ -6,8 +6,9 @@
import Operation from "../Operation";
import Utils from "../Utils";
import {DELIM_OPTIONS} from "../lib/Delim";
import { DELIM_OPTIONS } from "../lib/Delim";
import OperationError from "../errors/OperationError";
import { isWorkerEnvironment } from "../Utils";
/**
* To Charcode operation
@ -69,11 +70,11 @@ class ToCharcode extends Operation {
else if (ordinal < 4294967296) padding = 8;
else padding = 2;
if (padding > 2 && ENVIRONMENT_IS_WORKER()) self.setOption("attemptHighlight", false);
if (padding > 2 && isWorkerEnvironment()) self.setOption("attemptHighlight", false);
output += Utils.hex(ordinal, padding) + delim;
} else {
if (ENVIRONMENT_IS_WORKER()) self.setOption("attemptHighlight", false);
if (isWorkerEnvironment()) self.setOption("attemptHighlight", false);
output += ordinal.toString(base) + delim;
}
}

View file

@ -7,6 +7,7 @@
import Operation from "../Operation";
import OperationError from "../errors/OperationError";
import notepack from "notepack.io";
import { isWorkerEnvironment } from "../Utils";
/**
* To MessagePack operation
@ -35,7 +36,7 @@ class ToMessagePack extends Operation {
*/
run(input, args) {
try {
if (ENVIRONMENT_IS_WORKER()) {
if (isWorkerEnvironment()) {
return notepack.encode(input);
} else {
const res = notepack.encode(input);

View file

@ -8,6 +8,7 @@ import Operation from "../Operation";
import Utils from "../Utils";
import { bitOp, xor } from "../lib/BitwiseOp";
import { toHex } from "../lib/Hex";
import { isWorkerEnvironment } from "../Utils";
/**
* XOR Brute Force operation
@ -94,7 +95,7 @@ class XORBruteForce extends Operation {
input = input.slice(sampleOffset, sampleOffset + sampleLength);
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage("Calculating " + Math.pow(256, keyLength) + " values...");
/**
@ -114,7 +115,7 @@ class XORBruteForce extends Operation {
};
for (let key = 1, l = Math.pow(256, keyLength); key < l; key++) {
if (key % 10000 === 0 && ENVIRONMENT_IS_WORKER()) {
if (key % 10000 === 0 && isWorkerEnvironment()) {
self.sendStatusMessage("Calculating " + l + " values... " + Math.floor(key / l * 100) + "%");
}

View file

@ -7,6 +7,7 @@
import Operation from "../Operation";
import OperationError from "../errors/OperationError";
import Yara from "libyara-wasm";
import { isWorkerEnvironment } from "../Utils";
/**
* YARA Rules operation
@ -61,21 +62,21 @@ class YARARules extends Operation {
* @returns {string}
*/
run(input, args) {
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage("Instantiating YARA...");
const [rules, showStrings, showLengths, showMeta, showCounts] = args;
return new Promise((resolve, reject) => {
Yara().then(yara => {
if (ENVIRONMENT_IS_WORKER()) self.sendStatusMessage("Converting data for YARA.");
if (isWorkerEnvironment()) self.sendStatusMessage("Converting data for YARA.");
let matchString = "";
const inpArr = new Uint8Array(input); // Turns out embind knows that JS uint8array <==> C++ std::string
if (ENVIRONMENT_IS_WORKER()) self.sendStatusMessage("Running YARA matching.");
if (isWorkerEnvironment()) self.sendStatusMessage("Running YARA matching.");
const resp = yara.run(inpArr, rules);
if (ENVIRONMENT_IS_WORKER()) self.sendStatusMessage("Processing data.");
if (isWorkerEnvironment()) self.sendStatusMessage("Processing data.");
if (resp.compileErrors.size() > 0) {
for (let i = 0; i < resp.compileErrors.size(); i++) {