1
0
mirror of synced 2024-11-15 02:37:40 +01:00

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

@ -106,9 +106,6 @@
"COMPILE_TIME": false,
"COMPILE_MSG": false,
"PKG_VERSION": false,
"ENVIRONMENT_IS_WORKER": false,
"ENVIRONMENT_IS_NODE": false,
"ENVIRONMENT_IS_WEB": false
"PKG_VERSION": false
}
}

View File

@ -86,15 +86,6 @@ module.exports = function (grunt) {
COMPILE_TIME: JSON.stringify(compileTime),
COMPILE_MSG: JSON.stringify(grunt.option("compile-msg") || grunt.option("msg") || ""),
PKG_VERSION: JSON.stringify(pkg.version),
ENVIRONMENT_IS_WORKER: function() {
return typeof importScripts === "function";
},
ENVIRONMENT_IS_NODE: function() {
return typeof process === "object" && process.versions !== null && process.versions.node !== null && typeof require === "function";
},
ENVIRONMENT_IS_WEB: function() {
return typeof window === "object";
}
},
moduleEntryPoints = listEntryModules();

View File

@ -7,6 +7,7 @@
import Dish from "./Dish";
import Recipe from "./Recipe";
import log from "loglevel";
import { isWorkerEnvironment } from "./Utils";
/**
* The main controller for CyberChef.
@ -46,7 +47,7 @@ class Chef {
notUTF8 = options && options.hasOwnProperty("treatAsUtf8") && !options.treatAsUtf8;
let error = false;
if (containsFc && ENVIRONMENT_IS_WORKER()) self.setOption("attemptHighlight", false);
if (containsFc && isWorkerEnvironment()) self.setOption("attemptHighlight", false);
// Clean up progress
if (progress >= recipeConfig.length) {

View File

@ -5,7 +5,7 @@
* @license Apache-2.0
*/
import Utils from "./Utils";
import Utils, { isNodeEnvironment } from "./Utils";
import DishError from "./errors/DishError";
import BigNumber from "bignumber.js";
import log from "loglevel";
@ -140,7 +140,7 @@ class Dish {
if (this.type !== type) {
// Node environment => _translate is sync
if (Utils.isNode()) {
if (isNodeEnvironment()) {
this._translate(type, notUTF8);
return this.value;
@ -349,7 +349,7 @@ class Dish {
log.debug(`Translating Dish from ${Dish.enumLookup(this.type)} to ${Dish.enumLookup(toType)}`);
// Node environment => translate is sync
if (Utils.isNode()) {
if (isNodeEnvironment()) {
this._toArrayBuffer();
this.type = Dish.ARRAY_BUFFER;
this._fromArrayBuffer(toType, notUTF8);
@ -404,7 +404,7 @@ class Dish {
};
try {
return toByteArrayFuncs[Utils.isNode() && "node" || "browser"][this.type]();
return toByteArrayFuncs[isNodeEnvironment() && "node" || "browser"][this.type]();
} catch (err) {
throw new DishError(`Error translating from ${Dish.enumLookup(this.type)} to ArrayBuffer: ${err}`);
}

View File

@ -173,7 +173,7 @@ class Utils {
* @returns {string}
*/
static printable(str, preserveWs=false) {
if (ENVIRONMENT_IS_WEB() && window.app && !window.app.options.treatAsUtf8) {
if (isWebEnvironment() && window.app && !window.app.options.treatAsUtf8) {
str = Utils.byteArrayToChars(Utils.strToByteArray(str));
}
@ -410,9 +410,9 @@ class Utils {
const utf8Str = utf8.encode(str);
if (str.length !== utf8Str.length) {
if (ENVIRONMENT_IS_WORKER()) {
if (isWorkerEnvironment()) {
self.setOption("attemptHighlight", false);
} else if (ENVIRONMENT_IS_WEB()) {
} else if (isWebEnvironment()) {
window.app.options.attemptHighlight = false;
}
}
@ -465,9 +465,9 @@ class Utils {
const utf8Str = utf8.encode(str);
if (str.length !== utf8Str.length) {
if (ENVIRONMENT_IS_WORKER()) {
if (isWorkerEnvironment()) {
self.setOption("attemptHighlight", false);
} else if (ENVIRONMENT_IS_WEB()) {
} else if (isWebEnvironment()) {
window.app.options.attemptHighlight = false;
}
}
@ -528,9 +528,9 @@ class Utils {
try {
const utf8Str = utf8.decode(str);
if (str.length !== utf8Str.length) {
if (ENVIRONMENT_IS_WORKER()) {
if (isWorkerEnvironment()) {
self.setOption("attemptHighlight", false);
} else if (ENVIRONMENT_IS_WEB()) {
} else if (isWebEnvironment()) {
window.app.options.attemptHighlight = false;
}
}
@ -992,7 +992,7 @@ class Utils {
*/
static readFile(file) {
if (Utils.isNode()) {
if (isNodeEnvironment()) {
return Buffer.from(file).buffer;
} else {
@ -1036,7 +1036,7 @@ class Utils {
* @throws {TypeError} thrown if the method is called from a browser environment
*/
static readFileSync(file) {
if (!Utils.isNode()) {
if (!isNodeEnvironment()) {
throw new TypeError("Browser environment cannot support readFileSync");
}
@ -1141,13 +1141,23 @@ class Utils {
}[token];
}
/**
* Check if code is running in a Node environment
*/
static isNode() {
return typeof process !== "undefined" && process.versions != null && process.versions.node != null;
}
}
/**
* Check whether the code is running in a Node.js environment
*/
export function isNodeEnvironment() {
return typeof process !== "undefined" && process.versions != null && process.versions.node != null;
}
/** */
export function isWebEnvironment() {
return typeof window === "object";
}
/** */
export function isWorkerEnvironment() {
return typeof importScripts === "function";
}
export default Utils;
@ -1267,12 +1277,13 @@ String.prototype.count = function(chr) {
* @param {string} msg
*/
export function sendStatusMessage(msg) {
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage(msg);
else if (ENVIRONMENT_IS_WEB())
else if (isWebEnvironment())
app.alert(msg, 10000);
else if (ENVIRONMENT_IS_NODE())
log.debug(msg);
else if (isNodeEnvironment())
// eslint-disable-next-line no-console
console.debug(msg);
}

View File

@ -5,7 +5,7 @@
*/
import DishType from "./DishType";
import Utils from "../Utils";
import Utils, { isNodeEnvironment } from "../Utils";
/**
* Translation methods for file Dishes
@ -18,7 +18,7 @@ class DishFile extends DishType {
*/
static toArrayBuffer() {
DishFile.checkForValue(this.value);
if (Utils.isNode()) {
if (isNodeEnvironment()) {
this.value = Utils.readFileSync(this.value);
} else {
return new Promise((resolve, reject) => {

View File

@ -5,7 +5,7 @@
*/
import DishType from "./DishType";
import Utils from "../Utils.mjs";
import { isNodeEnvironment } from "../Utils.mjs";
/**
@ -19,7 +19,7 @@ class DishListFile extends DishType {
static toArrayBuffer() {
DishListFile.checkForValue(this.value);
if (Utils.isNode()) {
if (isNodeEnvironment()) {
this.value = this.value.map(file => Uint8Array.from(file.data));
}
this.value = DishListFile.concatenateTypedArrays(...this.value).buffer;

View File

@ -1,5 +1,5 @@
import OperationConfig from "../config/OperationConfig.json";
import Utils from "../Utils";
import Utils, { isWorkerEnvironment } from "../Utils";
import Recipe from "../Recipe";
import Dish from "../Dish";
import {detectFileType} from "./FileType";
@ -390,7 +390,7 @@ class Magic {
const dish = new Dish();
dish.set(input, Dish.ARRAY_BUFFER);
if (ENVIRONMENT_IS_WORKER()) self.loadRequiredModules(recipeConfig);
if (isWorkerEnvironment()) self.loadRequiredModules(recipeConfig);
const recipe = new Recipe(recipeConfig);
try {

View File

@ -11,6 +11,7 @@
*/
import OperationError from "../errors/OperationError";
import { isWorkerEnvironment } from "../Utils";
import kbpgp from "kbpgp";
import * as es6promisify from "es6-promisify";
const promisify = es6promisify.default ? es6promisify.default.promisify : es6promisify.promisify;
@ -45,7 +46,7 @@ export const ASP = kbpgp.ASP({
msg = `Stage: ${info.what}`;
}
if (ENVIRONMENT_IS_WORKER())
if (isWorkerEnvironment())
self.sendStatusMessage(msg);
}
});

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++) {

View File

@ -55,17 +55,6 @@ code +=`
global.File = File;
// Define global environment functions
global.ENVIRONMENT_IS_WORKER = function() {
return typeof importScripts === "function";
};
global.ENVIRONMENT_IS_NODE = function() {
return typeof process === "object" && typeof require === "function";
};
global.ENVIRONMENT_IS_WEB = function() {
return typeof window === "object";
};
/**
* generateChef
*

View File

@ -321,17 +321,6 @@ import {
global.File = File;
// Define global environment functions
global.ENVIRONMENT_IS_WORKER = function() {
return typeof importScripts === "function";
};
global.ENVIRONMENT_IS_NODE = function() {
return typeof process === "object" && typeof require === "function";
};
global.ENVIRONMENT_IS_WEB = function() {
return typeof window === "object";
};
/**
* generateChef
*

View File

@ -8,16 +8,6 @@
* @license Apache-2.0
*/
// Define global environment functions
global.ENVIRONMENT_IS_WORKER = function() {
return typeof importScripts === "function";
};
global.ENVIRONMENT_IS_NODE = function() {
return typeof process === "object" && typeof require === "function";
};
global.ENVIRONMENT_IS_WEB = function() {
return typeof window === "object";
};
/**
* Helper function to convert a status to an icon.

View File

@ -15,17 +15,6 @@ import {
logTestReport,
} from "../lib/utils";
// Define global environment functions
global.ENVIRONMENT_IS_WORKER = function() {
return typeof importScripts === "function";
};
global.ENVIRONMENT_IS_NODE = function() {
return typeof process === "object" && typeof require === "function";
};
global.ENVIRONMENT_IS_WEB = function() {
return typeof window === "object";
};
import TestRegister from "../lib/TestRegister";
import "./tests/nodeApi";
import "./tests/operations";

View File

@ -16,17 +16,6 @@ import {
logTestReport,
} from "../lib/utils";
// Define global environment functions
global.ENVIRONMENT_IS_WORKER = function() {
return typeof importScripts === "function";
};
global.ENVIRONMENT_IS_NODE = function() {
return typeof process === "object" && typeof require === "function";
};
global.ENVIRONMENT_IS_WEB = function() {
return typeof window === "object";
};
import TestRegister from "../lib/TestRegister";
import "./tests/BCD";
import "./tests/BSON";