mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
swap ENVIRONMENT_IS_* functions for Utils named exports
This commit is contained in:
parent
c70f14419a
commit
1c24c05647
41 changed files with 117 additions and 141 deletions
|
@ -106,9 +106,6 @@
|
||||||
|
|
||||||
"COMPILE_TIME": false,
|
"COMPILE_TIME": false,
|
||||||
"COMPILE_MSG": false,
|
"COMPILE_MSG": false,
|
||||||
"PKG_VERSION": false,
|
"PKG_VERSION": false
|
||||||
"ENVIRONMENT_IS_WORKER": false,
|
|
||||||
"ENVIRONMENT_IS_NODE": false,
|
|
||||||
"ENVIRONMENT_IS_WEB": false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,15 +86,6 @@ module.exports = function (grunt) {
|
||||||
COMPILE_TIME: JSON.stringify(compileTime),
|
COMPILE_TIME: JSON.stringify(compileTime),
|
||||||
COMPILE_MSG: JSON.stringify(grunt.option("compile-msg") || grunt.option("msg") || ""),
|
COMPILE_MSG: JSON.stringify(grunt.option("compile-msg") || grunt.option("msg") || ""),
|
||||||
PKG_VERSION: JSON.stringify(pkg.version),
|
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();
|
moduleEntryPoints = listEntryModules();
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
import Dish from "./Dish";
|
import Dish from "./Dish";
|
||||||
import Recipe from "./Recipe";
|
import Recipe from "./Recipe";
|
||||||
import log from "loglevel";
|
import log from "loglevel";
|
||||||
|
import { isWorkerEnvironment } from "./Utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main controller for CyberChef.
|
* The main controller for CyberChef.
|
||||||
|
@ -46,7 +47,7 @@ class Chef {
|
||||||
notUTF8 = options && options.hasOwnProperty("treatAsUtf8") && !options.treatAsUtf8;
|
notUTF8 = options && options.hasOwnProperty("treatAsUtf8") && !options.treatAsUtf8;
|
||||||
let error = false;
|
let error = false;
|
||||||
|
|
||||||
if (containsFc && ENVIRONMENT_IS_WORKER()) self.setOption("attemptHighlight", false);
|
if (containsFc && isWorkerEnvironment()) self.setOption("attemptHighlight", false);
|
||||||
|
|
||||||
// Clean up progress
|
// Clean up progress
|
||||||
if (progress >= recipeConfig.length) {
|
if (progress >= recipeConfig.length) {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
* @license Apache-2.0
|
* @license Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Utils from "./Utils";
|
import Utils, { isNodeEnvironment } from "./Utils";
|
||||||
import DishError from "./errors/DishError";
|
import DishError from "./errors/DishError";
|
||||||
import BigNumber from "bignumber.js";
|
import BigNumber from "bignumber.js";
|
||||||
import log from "loglevel";
|
import log from "loglevel";
|
||||||
|
@ -140,7 +140,7 @@ class Dish {
|
||||||
if (this.type !== type) {
|
if (this.type !== type) {
|
||||||
|
|
||||||
// Node environment => _translate is sync
|
// Node environment => _translate is sync
|
||||||
if (Utils.isNode()) {
|
if (isNodeEnvironment()) {
|
||||||
this._translate(type, notUTF8);
|
this._translate(type, notUTF8);
|
||||||
return this.value;
|
return this.value;
|
||||||
|
|
||||||
|
@ -349,7 +349,7 @@ class Dish {
|
||||||
log.debug(`Translating Dish from ${Dish.enumLookup(this.type)} to ${Dish.enumLookup(toType)}`);
|
log.debug(`Translating Dish from ${Dish.enumLookup(this.type)} to ${Dish.enumLookup(toType)}`);
|
||||||
|
|
||||||
// Node environment => translate is sync
|
// Node environment => translate is sync
|
||||||
if (Utils.isNode()) {
|
if (isNodeEnvironment()) {
|
||||||
this._toArrayBuffer();
|
this._toArrayBuffer();
|
||||||
this.type = Dish.ARRAY_BUFFER;
|
this.type = Dish.ARRAY_BUFFER;
|
||||||
this._fromArrayBuffer(toType, notUTF8);
|
this._fromArrayBuffer(toType, notUTF8);
|
||||||
|
@ -404,7 +404,7 @@ class Dish {
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return toByteArrayFuncs[Utils.isNode() && "node" || "browser"][this.type]();
|
return toByteArrayFuncs[isNodeEnvironment() && "node" || "browser"][this.type]();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new DishError(`Error translating from ${Dish.enumLookup(this.type)} to ArrayBuffer: ${err}`);
|
throw new DishError(`Error translating from ${Dish.enumLookup(this.type)} to ArrayBuffer: ${err}`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -173,7 +173,7 @@ class Utils {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
static printable(str, preserveWs=false) {
|
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));
|
str = Utils.byteArrayToChars(Utils.strToByteArray(str));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -410,9 +410,9 @@ class Utils {
|
||||||
const utf8Str = utf8.encode(str);
|
const utf8Str = utf8.encode(str);
|
||||||
|
|
||||||
if (str.length !== utf8Str.length) {
|
if (str.length !== utf8Str.length) {
|
||||||
if (ENVIRONMENT_IS_WORKER()) {
|
if (isWorkerEnvironment()) {
|
||||||
self.setOption("attemptHighlight", false);
|
self.setOption("attemptHighlight", false);
|
||||||
} else if (ENVIRONMENT_IS_WEB()) {
|
} else if (isWebEnvironment()) {
|
||||||
window.app.options.attemptHighlight = false;
|
window.app.options.attemptHighlight = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -465,9 +465,9 @@ class Utils {
|
||||||
const utf8Str = utf8.encode(str);
|
const utf8Str = utf8.encode(str);
|
||||||
|
|
||||||
if (str.length !== utf8Str.length) {
|
if (str.length !== utf8Str.length) {
|
||||||
if (ENVIRONMENT_IS_WORKER()) {
|
if (isWorkerEnvironment()) {
|
||||||
self.setOption("attemptHighlight", false);
|
self.setOption("attemptHighlight", false);
|
||||||
} else if (ENVIRONMENT_IS_WEB()) {
|
} else if (isWebEnvironment()) {
|
||||||
window.app.options.attemptHighlight = false;
|
window.app.options.attemptHighlight = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -528,9 +528,9 @@ class Utils {
|
||||||
try {
|
try {
|
||||||
const utf8Str = utf8.decode(str);
|
const utf8Str = utf8.decode(str);
|
||||||
if (str.length !== utf8Str.length) {
|
if (str.length !== utf8Str.length) {
|
||||||
if (ENVIRONMENT_IS_WORKER()) {
|
if (isWorkerEnvironment()) {
|
||||||
self.setOption("attemptHighlight", false);
|
self.setOption("attemptHighlight", false);
|
||||||
} else if (ENVIRONMENT_IS_WEB()) {
|
} else if (isWebEnvironment()) {
|
||||||
window.app.options.attemptHighlight = false;
|
window.app.options.attemptHighlight = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -992,7 +992,7 @@ class Utils {
|
||||||
*/
|
*/
|
||||||
static readFile(file) {
|
static readFile(file) {
|
||||||
|
|
||||||
if (Utils.isNode()) {
|
if (isNodeEnvironment()) {
|
||||||
return Buffer.from(file).buffer;
|
return Buffer.from(file).buffer;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -1036,7 +1036,7 @@ class Utils {
|
||||||
* @throws {TypeError} thrown if the method is called from a browser environment
|
* @throws {TypeError} thrown if the method is called from a browser environment
|
||||||
*/
|
*/
|
||||||
static readFileSync(file) {
|
static readFileSync(file) {
|
||||||
if (!Utils.isNode()) {
|
if (!isNodeEnvironment()) {
|
||||||
throw new TypeError("Browser environment cannot support readFileSync");
|
throw new TypeError("Browser environment cannot support readFileSync");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1141,13 +1141,23 @@ class Utils {
|
||||||
}[token];
|
}[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;
|
export default Utils;
|
||||||
|
@ -1267,12 +1277,13 @@ String.prototype.count = function(chr) {
|
||||||
* @param {string} msg
|
* @param {string} msg
|
||||||
*/
|
*/
|
||||||
export function sendStatusMessage(msg) {
|
export function sendStatusMessage(msg) {
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage(msg);
|
self.sendStatusMessage(msg);
|
||||||
else if (ENVIRONMENT_IS_WEB())
|
else if (isWebEnvironment())
|
||||||
app.alert(msg, 10000);
|
app.alert(msg, 10000);
|
||||||
else if (ENVIRONMENT_IS_NODE())
|
else if (isNodeEnvironment())
|
||||||
log.debug(msg);
|
// eslint-disable-next-line no-console
|
||||||
|
console.debug(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import DishType from "./DishType";
|
import DishType from "./DishType";
|
||||||
import Utils from "../Utils";
|
import Utils, { isNodeEnvironment } from "../Utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translation methods for file Dishes
|
* Translation methods for file Dishes
|
||||||
|
@ -18,7 +18,7 @@ class DishFile extends DishType {
|
||||||
*/
|
*/
|
||||||
static toArrayBuffer() {
|
static toArrayBuffer() {
|
||||||
DishFile.checkForValue(this.value);
|
DishFile.checkForValue(this.value);
|
||||||
if (Utils.isNode()) {
|
if (isNodeEnvironment()) {
|
||||||
this.value = Utils.readFileSync(this.value);
|
this.value = Utils.readFileSync(this.value);
|
||||||
} else {
|
} else {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import DishType from "./DishType";
|
import DishType from "./DishType";
|
||||||
import Utils from "../Utils.mjs";
|
import { isNodeEnvironment } from "../Utils.mjs";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -19,7 +19,7 @@ class DishListFile extends DishType {
|
||||||
static toArrayBuffer() {
|
static toArrayBuffer() {
|
||||||
DishListFile.checkForValue(this.value);
|
DishListFile.checkForValue(this.value);
|
||||||
|
|
||||||
if (Utils.isNode()) {
|
if (isNodeEnvironment()) {
|
||||||
this.value = this.value.map(file => Uint8Array.from(file.data));
|
this.value = this.value.map(file => Uint8Array.from(file.data));
|
||||||
}
|
}
|
||||||
this.value = DishListFile.concatenateTypedArrays(...this.value).buffer;
|
this.value = DishListFile.concatenateTypedArrays(...this.value).buffer;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import OperationConfig from "../config/OperationConfig.json";
|
import OperationConfig from "../config/OperationConfig.json";
|
||||||
import Utils from "../Utils";
|
import Utils, { isWorkerEnvironment } from "../Utils";
|
||||||
import Recipe from "../Recipe";
|
import Recipe from "../Recipe";
|
||||||
import Dish from "../Dish";
|
import Dish from "../Dish";
|
||||||
import {detectFileType} from "./FileType";
|
import {detectFileType} from "./FileType";
|
||||||
|
@ -390,7 +390,7 @@ class Magic {
|
||||||
const dish = new Dish();
|
const dish = new Dish();
|
||||||
dish.set(input, Dish.ARRAY_BUFFER);
|
dish.set(input, Dish.ARRAY_BUFFER);
|
||||||
|
|
||||||
if (ENVIRONMENT_IS_WORKER()) self.loadRequiredModules(recipeConfig);
|
if (isWorkerEnvironment()) self.loadRequiredModules(recipeConfig);
|
||||||
|
|
||||||
const recipe = new Recipe(recipeConfig);
|
const recipe = new Recipe(recipeConfig);
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
import kbpgp from "kbpgp";
|
import kbpgp from "kbpgp";
|
||||||
import * as es6promisify from "es6-promisify";
|
import * as es6promisify from "es6-promisify";
|
||||||
const promisify = es6promisify.default ? es6promisify.default.promisify : es6promisify.promisify;
|
const promisify = es6promisify.default ? es6promisify.default.promisify : es6promisify.promisify;
|
||||||
|
@ -45,7 +46,7 @@ export const ASP = kbpgp.ASP({
|
||||||
msg = `Stage: ${info.what}`;
|
msg = `Stage: ${info.what}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage(msg);
|
self.sendStatusMessage(msg);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import bcrypt from "bcryptjs";
|
import bcrypt from "bcryptjs";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bcrypt operation
|
* Bcrypt operation
|
||||||
|
@ -44,7 +45,7 @@ class Bcrypt extends Operation {
|
||||||
|
|
||||||
return await bcrypt.hash(input, salt, null, p => {
|
return await bcrypt.hash(input, salt, null, p => {
|
||||||
// Progress callback
|
// Progress callback
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage(`Progress: ${(p * 100).toFixed(0)}%`);
|
self.sendStatusMessage(`Progress: ${(p * 100).toFixed(0)}%`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import bcrypt from "bcryptjs";
|
import bcrypt from "bcryptjs";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bcrypt compare operation
|
* Bcrypt compare operation
|
||||||
|
@ -43,7 +45,7 @@ class BcryptCompare extends Operation {
|
||||||
|
|
||||||
const match = await bcrypt.compare(input, hash, null, p => {
|
const match = await bcrypt.compare(input, hash, null, p => {
|
||||||
// Progress callback
|
// Progress callback
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage(`Progress: ${(p * 100).toFixed(0)}%`);
|
self.sendStatusMessage(`Progress: ${(p * 100).toFixed(0)}%`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
import { isImage } from "../lib/FileType";
|
import { isImage } from "../lib/FileType";
|
||||||
import { toBase64 } from "../lib/Base64";
|
import { toBase64 } from "../lib/Base64";
|
||||||
import jimp from "jimp";
|
import jimp from "jimp";
|
||||||
|
@ -67,7 +68,7 @@ class BlurImage extends Operation {
|
||||||
image.blur(blurAmount);
|
image.blur(blurAmount);
|
||||||
break;
|
break;
|
||||||
case "Gaussian":
|
case "Gaussian":
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Gaussian blurring image. This may take a while...");
|
self.sendStatusMessage("Gaussian blurring image. This may take a while...");
|
||||||
image.gaussian(blurAmount);
|
image.gaussian(blurAmount);
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -8,8 +8,9 @@
|
||||||
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
import {BombeMachine} from "../lib/Bombe";
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
import {ROTORS, ROTORS_FOURTH, REFLECTORS, Reflector} from "../lib/Enigma";
|
import { BombeMachine } from "../lib/Bombe";
|
||||||
|
import { ROTORS, ROTORS_FOURTH, REFLECTORS, Reflector } from "../lib/Enigma";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Bombe operation
|
* Bombe operation
|
||||||
|
@ -139,7 +140,7 @@ class Bombe extends Operation {
|
||||||
const ciphertext = input.slice(offset);
|
const ciphertext = input.slice(offset);
|
||||||
const reflector = new Reflector(reflectorstr);
|
const reflector = new Reflector(reflectorstr);
|
||||||
let update;
|
let update;
|
||||||
if (ENVIRONMENT_IS_WORKER()) {
|
if (isWorkerEnvironment()) {
|
||||||
update = this.updateStatus;
|
update = this.updateStatus;
|
||||||
} else {
|
} else {
|
||||||
update = undefined;
|
update = undefined;
|
||||||
|
|
|
@ -8,6 +8,7 @@ import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
import { isImage } from "../lib/FileType";
|
import { isImage } from "../lib/FileType";
|
||||||
import { toBase64 } from "../lib/Base64.mjs";
|
import { toBase64 } from "../lib/Base64.mjs";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
import jimp from "jimp";
|
import jimp from "jimp";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,7 +113,7 @@ class ContainImage extends Operation {
|
||||||
throw new OperationError(`Error loading image. (${err})`);
|
throw new OperationError(`Error loading image. (${err})`);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Containing image...");
|
self.sendStatusMessage("Containing image...");
|
||||||
image.contain(width, height, alignMap[hAlign] | alignMap[vAlign], resizeMap[alg]);
|
image.contain(width, height, alignMap[hAlign] | alignMap[vAlign], resizeMap[alg]);
|
||||||
const imageBuffer = await image.getBufferAsync(jimp.AUTO);
|
const imageBuffer = await image.getBufferAsync(jimp.AUTO);
|
||||||
|
|
|
@ -8,6 +8,7 @@ import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
import { isImage } from "../lib/FileType";
|
import { isImage } from "../lib/FileType";
|
||||||
import { toBase64 } from "../lib/Base64.mjs";
|
import { toBase64 } from "../lib/Base64.mjs";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
import jimp from "jimp";
|
import jimp from "jimp";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,7 +113,7 @@ class CoverImage extends Operation {
|
||||||
throw new OperationError(`Error loading image. (${err})`);
|
throw new OperationError(`Error loading image. (${err})`);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Covering image...");
|
self.sendStatusMessage("Covering image...");
|
||||||
image.cover(width, height, alignMap[hAlign] | alignMap[vAlign], resizeMap[alg]);
|
image.cover(width, height, alignMap[hAlign] | alignMap[vAlign], resizeMap[alg]);
|
||||||
const imageBuffer = await image.getBufferAsync(jimp.AUTO);
|
const imageBuffer = await image.getBufferAsync(jimp.AUTO);
|
||||||
|
|
|
@ -8,6 +8,7 @@ import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
import { isImage } from "../lib/FileType";
|
import { isImage } from "../lib/FileType";
|
||||||
import { toBase64 } from "../lib/Base64.mjs";
|
import { toBase64 } from "../lib/Base64.mjs";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
import jimp from "jimp";
|
import jimp from "jimp";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -103,7 +104,7 @@ class CropImage extends Operation {
|
||||||
throw new OperationError(`Error loading image. (${err})`);
|
throw new OperationError(`Error loading image. (${err})`);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Cropping image...");
|
self.sendStatusMessage("Cropping image...");
|
||||||
if (autocrop) {
|
if (autocrop) {
|
||||||
image.autocrop({
|
image.autocrop({
|
||||||
|
|
|
@ -8,6 +8,7 @@ import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
import { isImage } from "../lib/FileType";
|
import { isImage } from "../lib/FileType";
|
||||||
import { toBase64 } from "../lib/Base64";
|
import { toBase64 } from "../lib/Base64";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
import jimp from "jimp";
|
import jimp from "jimp";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,7 +49,7 @@ class DitherImage extends Operation {
|
||||||
throw new OperationError(`Error loading image. (${err})`);
|
throw new OperationError(`Error loading image. (${err})`);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Applying dither to image...");
|
self.sendStatusMessage("Applying dither to image...");
|
||||||
image.dither565();
|
image.dither565();
|
||||||
const imageBuffer = await image.getBufferAsync(jimp.AUTO);
|
const imageBuffer = await image.getBufferAsync(jimp.AUTO);
|
||||||
|
|
|
@ -8,6 +8,7 @@ import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
import { isImage } from "../lib/FileType";
|
import { isImage } from "../lib/FileType";
|
||||||
import { toBase64 } from "../lib/Base64";
|
import { toBase64 } from "../lib/Base64";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
import jimp from "jimp";
|
import jimp from "jimp";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,7 +56,7 @@ class FlipImage extends Operation {
|
||||||
throw new OperationError(`Error loading image. (${err})`);
|
throw new OperationError(`Error loading image. (${err})`);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Flipping image...");
|
self.sendStatusMessage("Flipping image...");
|
||||||
switch (flipAxis){
|
switch (flipAxis){
|
||||||
case "Horizontal":
|
case "Horizontal":
|
||||||
|
|
|
@ -6,7 +6,8 @@
|
||||||
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import Utils from "../Utils";
|
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";
|
import OperationError from "../errors/OperationError";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,7 +62,7 @@ class FromCharcode extends Operation {
|
||||||
return [];
|
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
|
// Split into groups of 2 if the whole string is concatenated and
|
||||||
// too long to be a single character
|
// too long to be a single character
|
||||||
|
|
|
@ -5,7 +5,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import {fromHex} from "../lib/Hex";
|
import { fromHex } from "../lib/Hex";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* From Hexdump operation
|
* From Hexdump operation
|
||||||
|
@ -55,7 +57,7 @@ class FromHexdump extends Operation {
|
||||||
const w = (width - 13) / 4;
|
const w = (width - 13) / 4;
|
||||||
// w should be the specified width of the hexdump and therefore a round number
|
// 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 (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;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
import { isImage } from "../lib/FileType";
|
import { isImage } from "../lib/FileType";
|
||||||
import { toBase64 } from "../lib/Base64.mjs";
|
import { toBase64 } from "../lib/Base64.mjs";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
import jimp from "jimp";
|
import jimp from "jimp";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -65,12 +66,12 @@ class ImageBrightnessContrast extends Operation {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (brightness !== 0) {
|
if (brightness !== 0) {
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Changing image brightness...");
|
self.sendStatusMessage("Changing image brightness...");
|
||||||
image.brightness(brightness / 100);
|
image.brightness(brightness / 100);
|
||||||
}
|
}
|
||||||
if (contrast !== 0) {
|
if (contrast !== 0) {
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Changing image contrast...");
|
self.sendStatusMessage("Changing image contrast...");
|
||||||
image.contrast(contrast / 100);
|
image.contrast(contrast / 100);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,7 @@ import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
import { isImage } from "../lib/FileType";
|
import { isImage } from "../lib/FileType";
|
||||||
import { toBase64 } from "../lib/Base64.mjs";
|
import { toBase64 } from "../lib/Base64.mjs";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
import jimp from "jimp";
|
import jimp from "jimp";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,7 +59,7 @@ class ImageFilter extends Operation {
|
||||||
throw new OperationError(`Error loading image. (${err})`);
|
throw new OperationError(`Error loading image. (${err})`);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Applying " + filterType.toLowerCase() + " filter to image...");
|
self.sendStatusMessage("Applying " + filterType.toLowerCase() + " filter to image...");
|
||||||
if (filterType === "Greyscale") {
|
if (filterType === "Greyscale") {
|
||||||
image.greyscale();
|
image.greyscale();
|
||||||
|
|
|
@ -8,6 +8,7 @@ import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
import { isImage } from "../lib/FileType";
|
import { isImage } from "../lib/FileType";
|
||||||
import { toBase64 } from "../lib/Base64.mjs";
|
import { toBase64 } from "../lib/Base64.mjs";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
import jimp from "jimp";
|
import jimp from "jimp";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,7 +74,7 @@ class ImageHueSaturationLightness extends Operation {
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (hue !== 0) {
|
if (hue !== 0) {
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Changing image hue...");
|
self.sendStatusMessage("Changing image hue...");
|
||||||
image.colour([
|
image.colour([
|
||||||
{
|
{
|
||||||
|
@ -83,7 +84,7 @@ class ImageHueSaturationLightness extends Operation {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
if (saturation !== 0) {
|
if (saturation !== 0) {
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Changing image saturation...");
|
self.sendStatusMessage("Changing image saturation...");
|
||||||
image.colour([
|
image.colour([
|
||||||
{
|
{
|
||||||
|
@ -93,7 +94,7 @@ class ImageHueSaturationLightness extends Operation {
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
if (lightness !== 0) {
|
if (lightness !== 0) {
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Changing image lightness...");
|
self.sendStatusMessage("Changing image lightness...");
|
||||||
image.colour([
|
image.colour([
|
||||||
{
|
{
|
||||||
|
|
|
@ -8,6 +8,7 @@ import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
import { isImage } from "../lib/FileType";
|
import { isImage } from "../lib/FileType";
|
||||||
import { toBase64 } from "../lib/Base64.mjs";
|
import { toBase64 } from "../lib/Base64.mjs";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
import jimp from "jimp";
|
import jimp from "jimp";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,7 +58,7 @@ class ImageOpacity extends Operation {
|
||||||
throw new OperationError(`Error loading image. (${err})`);
|
throw new OperationError(`Error loading image. (${err})`);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Changing image opacity...");
|
self.sendStatusMessage("Changing image opacity...");
|
||||||
image.opacity(opacity / 100);
|
image.opacity(opacity / 100);
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
import { isImage } from "../lib/FileType";
|
import { isImage } from "../lib/FileType";
|
||||||
import { toBase64 } from "../lib/Base64";
|
import { toBase64 } from "../lib/Base64";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
import jimp from "jimp";
|
import jimp from "jimp";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,7 +49,7 @@ class InvertImage extends Operation {
|
||||||
throw new OperationError(`Error loading image. (${err})`);
|
throw new OperationError(`Error loading image. (${err})`);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Inverting image...");
|
self.sendStatusMessage("Inverting image...");
|
||||||
image.invert();
|
image.invert();
|
||||||
const imageBuffer = await image.getBufferAsync(jimp.AUTO);
|
const imageBuffer = await image.getBufferAsync(jimp.AUTO);
|
||||||
|
|
|
@ -9,8 +9,10 @@
|
||||||
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
import {BombeMachine} from "../lib/Bombe";
|
import { BombeMachine } from "../lib/Bombe";
|
||||||
import {ROTORS, ROTORS_FOURTH, REFLECTORS, Reflector} from "../lib/Enigma";
|
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.
|
* 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();
|
crib = crib.replace(/[^A-Za-z]/g, "").toUpperCase();
|
||||||
const ciphertext = input.slice(offset);
|
const ciphertext = input.slice(offset);
|
||||||
let update;
|
let update;
|
||||||
if (ENVIRONMENT_IS_WORKER()) {
|
if (isWorkerEnvironment()) {
|
||||||
update = this.updateStatus;
|
update = this.updateStatus;
|
||||||
} else {
|
} else {
|
||||||
update = undefined;
|
update = undefined;
|
||||||
|
|
|
@ -8,6 +8,7 @@ import Operation from "../Operation";
|
||||||
import Utils from "../Utils";
|
import Utils from "../Utils";
|
||||||
import forge from "node-forge/dist/forge.min.js";
|
import forge from "node-forge/dist/forge.min.js";
|
||||||
import BigNumber from "bignumber.js";
|
import BigNumber from "bignumber.js";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pseudo-Random Number Generator operation
|
* Pseudo-Random Number Generator operation
|
||||||
|
@ -50,7 +51,7 @@ class PseudoRandomNumberGenerator extends Operation {
|
||||||
|
|
||||||
let bytes;
|
let bytes;
|
||||||
|
|
||||||
if (ENVIRONMENT_IS_WORKER() && self.crypto) {
|
if (isWorkerEnvironment() && self.crypto) {
|
||||||
bytes = self.crypto.getRandomValues(new Uint8Array(numBytes));
|
bytes = self.crypto.getRandomValues(new Uint8Array(numBytes));
|
||||||
bytes = Utils.arrayBufferToStr(bytes.buffer);
|
bytes = Utils.arrayBufferToStr(bytes.buffer);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import Dish from "../Dish";
|
import Dish from "../Dish";
|
||||||
import XRegExp from "xregexp";
|
import XRegExp from "xregexp";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register operation
|
* Register operation
|
||||||
|
@ -72,7 +73,7 @@ class Register extends Operation {
|
||||||
|
|
||||||
if (!registers) return state;
|
if (!registers) return state;
|
||||||
|
|
||||||
if (ENVIRONMENT_IS_WORKER()) {
|
if (isWorkerEnvironment()) {
|
||||||
self.setRegisters(state.forkOffset + state.progress, state.numRegisters, registers.slice(1));
|
self.setRegisters(state.forkOffset + state.progress, state.numRegisters, registers.slice(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@ import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
import { isImage } from "../lib/FileType";
|
import { isImage } from "../lib/FileType";
|
||||||
import { toBase64 } from "../lib/Base64.mjs";
|
import { toBase64 } from "../lib/Base64.mjs";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
import jimp from "jimp";
|
import jimp from "jimp";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,7 +103,7 @@ class ResizeImage extends Operation {
|
||||||
height = image.getHeight() * (height / 100);
|
height = image.getHeight() * (height / 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Resizing image...");
|
self.sendStatusMessage("Resizing image...");
|
||||||
if (aspect) {
|
if (aspect) {
|
||||||
image.scaleToFit(width, height, resizeMap[resizeAlg]);
|
image.scaleToFit(width, height, resizeMap[resizeAlg]);
|
||||||
|
|
|
@ -8,6 +8,7 @@ import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
import { isImage } from "../lib/FileType";
|
import { isImage } from "../lib/FileType";
|
||||||
import { toBase64 } from "../lib/Base64";
|
import { toBase64 } from "../lib/Base64";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
import jimp from "jimp";
|
import jimp from "jimp";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,7 +57,7 @@ class RotateImage extends Operation {
|
||||||
throw new OperationError(`Error loading image. (${err})`);
|
throw new OperationError(`Error loading image. (${err})`);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Rotating image...");
|
self.sendStatusMessage("Rotating image...");
|
||||||
image.rotate(degrees);
|
image.rotate(degrees);
|
||||||
const imageBuffer = await image.getBufferAsync(jimp.AUTO);
|
const imageBuffer = await image.getBufferAsync(jimp.AUTO);
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import Utils from "../Utils";
|
import Utils from "../Utils";
|
||||||
import {scanForFileTypes} from "../lib/FileType";
|
import { scanForFileTypes } from "../lib/FileType";
|
||||||
import {FILE_SIGNATURES} from "../lib/FileSignatures";
|
import { FILE_SIGNATURES } from "../lib/FileSignatures";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scan for Embedded Files operation
|
* Scan for Embedded Files operation
|
||||||
|
|
|
@ -8,6 +8,7 @@ import Operation from "../Operation";
|
||||||
import Utils from "../Utils";
|
import Utils from "../Utils";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
import scryptsy from "scryptsy";
|
import scryptsy from "scryptsy";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scrypt operation
|
* Scrypt operation
|
||||||
|
@ -73,7 +74,7 @@ class Scrypt extends Operation {
|
||||||
input, salt, iterations, memFactor, parallelFactor, keyLength,
|
input, salt, iterations, memFactor, parallelFactor, keyLength,
|
||||||
p => {
|
p => {
|
||||||
// Progress callback
|
// Progress callback
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage(`Progress: ${p.percent.toFixed(0)}%`);
|
self.sendStatusMessage(`Progress: ${p.percent.toFixed(0)}%`);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
|
@ -6,8 +6,9 @@
|
||||||
|
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import Utils from "../Utils";
|
import Utils from "../Utils";
|
||||||
import {DELIM_OPTIONS} from "../lib/Delim";
|
import { DELIM_OPTIONS } from "../lib/Delim";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To Charcode operation
|
* To Charcode operation
|
||||||
|
@ -69,11 +70,11 @@ class ToCharcode extends Operation {
|
||||||
else if (ordinal < 4294967296) padding = 8;
|
else if (ordinal < 4294967296) padding = 8;
|
||||||
else padding = 2;
|
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;
|
output += Utils.hex(ordinal, padding) + delim;
|
||||||
} else {
|
} else {
|
||||||
if (ENVIRONMENT_IS_WORKER()) self.setOption("attemptHighlight", false);
|
if (isWorkerEnvironment()) self.setOption("attemptHighlight", false);
|
||||||
output += ordinal.toString(base) + delim;
|
output += ordinal.toString(base) + delim;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
import notepack from "notepack.io";
|
import notepack from "notepack.io";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To MessagePack operation
|
* To MessagePack operation
|
||||||
|
@ -35,7 +36,7 @@ class ToMessagePack extends Operation {
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
try {
|
try {
|
||||||
if (ENVIRONMENT_IS_WORKER()) {
|
if (isWorkerEnvironment()) {
|
||||||
return notepack.encode(input);
|
return notepack.encode(input);
|
||||||
} else {
|
} else {
|
||||||
const res = notepack.encode(input);
|
const res = notepack.encode(input);
|
||||||
|
|
|
@ -8,6 +8,7 @@ import Operation from "../Operation";
|
||||||
import Utils from "../Utils";
|
import Utils from "../Utils";
|
||||||
import { bitOp, xor } from "../lib/BitwiseOp";
|
import { bitOp, xor } from "../lib/BitwiseOp";
|
||||||
import { toHex } from "../lib/Hex";
|
import { toHex } from "../lib/Hex";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XOR Brute Force operation
|
* XOR Brute Force operation
|
||||||
|
@ -94,7 +95,7 @@ class XORBruteForce extends Operation {
|
||||||
|
|
||||||
input = input.slice(sampleOffset, sampleOffset + sampleLength);
|
input = input.slice(sampleOffset, sampleOffset + sampleLength);
|
||||||
|
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Calculating " + Math.pow(256, keyLength) + " values...");
|
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++) {
|
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) + "%");
|
self.sendStatusMessage("Calculating " + l + " values... " + Math.floor(key / l * 100) + "%");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
import Operation from "../Operation";
|
import Operation from "../Operation";
|
||||||
import OperationError from "../errors/OperationError";
|
import OperationError from "../errors/OperationError";
|
||||||
import Yara from "libyara-wasm";
|
import Yara from "libyara-wasm";
|
||||||
|
import { isWorkerEnvironment } from "../Utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* YARA Rules operation
|
* YARA Rules operation
|
||||||
|
@ -61,21 +62,21 @@ class YARARules extends Operation {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
if (ENVIRONMENT_IS_WORKER())
|
if (isWorkerEnvironment())
|
||||||
self.sendStatusMessage("Instantiating YARA...");
|
self.sendStatusMessage("Instantiating YARA...");
|
||||||
const [rules, showStrings, showLengths, showMeta, showCounts] = args;
|
const [rules, showStrings, showLengths, showMeta, showCounts] = args;
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
Yara().then(yara => {
|
Yara().then(yara => {
|
||||||
if (ENVIRONMENT_IS_WORKER()) self.sendStatusMessage("Converting data for YARA.");
|
if (isWorkerEnvironment()) self.sendStatusMessage("Converting data for YARA.");
|
||||||
let matchString = "";
|
let matchString = "";
|
||||||
|
|
||||||
const inpArr = new Uint8Array(input); // Turns out embind knows that JS uint8array <==> C++ std::string
|
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);
|
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) {
|
if (resp.compileErrors.size() > 0) {
|
||||||
for (let i = 0; i < resp.compileErrors.size(); i++) {
|
for (let i = 0; i < resp.compileErrors.size(); i++) {
|
||||||
|
|
|
@ -55,17 +55,6 @@ code +=`
|
||||||
|
|
||||||
global.File = File;
|
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
|
* generateChef
|
||||||
*
|
*
|
||||||
|
|
|
@ -321,17 +321,6 @@ import {
|
||||||
|
|
||||||
global.File = File;
|
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
|
* generateChef
|
||||||
*
|
*
|
||||||
|
|
|
@ -8,16 +8,6 @@
|
||||||
* @license Apache-2.0
|
* @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.
|
* Helper function to convert a status to an icon.
|
||||||
|
|
|
@ -15,17 +15,6 @@ import {
|
||||||
logTestReport,
|
logTestReport,
|
||||||
} from "../lib/utils";
|
} 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 TestRegister from "../lib/TestRegister";
|
||||||
import "./tests/nodeApi";
|
import "./tests/nodeApi";
|
||||||
import "./tests/operations";
|
import "./tests/operations";
|
||||||
|
|
|
@ -16,17 +16,6 @@ import {
|
||||||
logTestReport,
|
logTestReport,
|
||||||
} from "../lib/utils";
|
} 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 TestRegister from "../lib/TestRegister";
|
||||||
import "./tests/BCD";
|
import "./tests/BCD";
|
||||||
import "./tests/BSON";
|
import "./tests/BSON";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue