mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 23:06:16 -04:00
eslint autofix
This commit is contained in:
parent
0d42541860
commit
ad730d806b
60 changed files with 13067 additions and 13014 deletions
751
Gruntfile.js
751
Gruntfile.js
|
@ -1,152 +1,152 @@
|
||||||
module.exports = function(grunt) {
|
module.exports = function (grunt) {
|
||||||
grunt.file.defaultEncoding = "utf8";
|
grunt.file.defaultEncoding = 'utf8';
|
||||||
grunt.file.preserveBOM = false;
|
grunt.file.preserveBOM = false;
|
||||||
|
|
||||||
// Tasks
|
// Tasks
|
||||||
grunt.registerTask("dev",
|
grunt.registerTask('dev',
|
||||||
"A persistent task which creates a development build whenever source files are modified.",
|
'A persistent task which creates a development build whenever source files are modified.',
|
||||||
["clean:dev", "concat:css", "concat:js", "copy:html_dev", "copy:static_dev", "chmod:build", "watch"]);
|
['clean:dev', 'concat:css', 'concat:js', 'copy:html_dev', 'copy:static_dev', 'chmod:build', 'watch']);
|
||||||
|
|
||||||
grunt.registerTask("prod",
|
grunt.registerTask('prod',
|
||||||
"Creates a production-ready build. Use the --msg flag to add a compile message.",
|
'Creates a production-ready build. Use the --msg flag to add a compile message.',
|
||||||
["jshint", "exec:stats", "clean", "jsdoc", "concat", "copy", "cssmin", "uglify:prod", "inline", "htmlmin", "chmod"]);
|
['jshint', 'exec:stats', 'clean', 'jsdoc', 'concat', 'copy', 'cssmin', 'uglify:prod', 'inline', 'htmlmin', 'chmod']);
|
||||||
|
|
||||||
grunt.registerTask("docs",
|
grunt.registerTask('docs',
|
||||||
"Compiles documentation in the /docs directory.",
|
'Compiles documentation in the /docs directory.',
|
||||||
["clean:docs", "jsdoc", "chmod:docs"]);
|
['clean:docs', 'jsdoc', 'chmod:docs']);
|
||||||
|
|
||||||
grunt.registerTask("stats",
|
grunt.registerTask('stats',
|
||||||
"Provides statistics about the code base such as how many lines there are as well as details of file sizes before and after compression.",
|
'Provides statistics about the code base such as how many lines there are as well as details of file sizes before and after compression.',
|
||||||
["concat:js", "uglify:prod", "exec:stats", "exec:repo_size", "exec:display_stats"]);
|
['concat:js', 'uglify:prod', 'exec:stats', 'exec:repo_size', 'exec:display_stats']);
|
||||||
|
|
||||||
grunt.registerTask("default",
|
grunt.registerTask('default',
|
||||||
"Lints the code base and shows stats",
|
'Lints the code base and shows stats',
|
||||||
["jshint", "exec:stats", "exec:display_stats"]);
|
['jshint', 'exec:stats', 'exec:display_stats']);
|
||||||
|
|
||||||
grunt.registerTask("doc", "docs");
|
grunt.registerTask('doc', 'docs');
|
||||||
grunt.registerTask("lint", "jshint");
|
grunt.registerTask('lint', 'jshint');
|
||||||
|
|
||||||
|
|
||||||
// Load tasks provided by each plugin
|
// Load tasks provided by each plugin
|
||||||
grunt.loadNpmTasks("grunt-contrib-jshint");
|
grunt.loadNpmTasks('grunt-contrib-jshint');
|
||||||
grunt.loadNpmTasks("grunt-jsdoc");
|
grunt.loadNpmTasks('grunt-jsdoc');
|
||||||
grunt.loadNpmTasks("grunt-contrib-clean");
|
grunt.loadNpmTasks('grunt-contrib-clean');
|
||||||
grunt.loadNpmTasks("grunt-contrib-concat");
|
grunt.loadNpmTasks('grunt-contrib-concat');
|
||||||
grunt.loadNpmTasks("grunt-contrib-copy");
|
grunt.loadNpmTasks('grunt-contrib-copy');
|
||||||
grunt.loadNpmTasks("grunt-contrib-uglify");
|
grunt.loadNpmTasks('grunt-contrib-uglify');
|
||||||
grunt.loadNpmTasks("grunt-contrib-cssmin");
|
grunt.loadNpmTasks('grunt-contrib-cssmin');
|
||||||
grunt.loadNpmTasks("grunt-contrib-htmlmin");
|
grunt.loadNpmTasks('grunt-contrib-htmlmin');
|
||||||
grunt.loadNpmTasks("grunt-inline-alt");
|
grunt.loadNpmTasks('grunt-inline-alt');
|
||||||
grunt.loadNpmTasks("grunt-chmod");
|
grunt.loadNpmTasks('grunt-chmod');
|
||||||
grunt.loadNpmTasks("grunt-exec");
|
grunt.loadNpmTasks('grunt-exec');
|
||||||
grunt.loadNpmTasks("grunt-contrib-watch");
|
grunt.loadNpmTasks('grunt-contrib-watch');
|
||||||
|
|
||||||
|
|
||||||
// JS includes
|
// JS includes
|
||||||
var js_files = [
|
const js_files = [
|
||||||
// Third party framework libraries
|
// Third party framework libraries
|
||||||
"src/js/lib/jquery-2.1.1.js",
|
'src/js/lib/jquery-2.1.1.js',
|
||||||
"src/js/lib/bootstrap-3.3.6.js",
|
'src/js/lib/bootstrap-3.3.6.js',
|
||||||
"src/js/lib/split.js",
|
'src/js/lib/split.js',
|
||||||
"src/js/lib/bootstrap-switch.js",
|
'src/js/lib/bootstrap-switch.js',
|
||||||
"src/js/lib/yahoo.js",
|
'src/js/lib/yahoo.js',
|
||||||
"src/js/lib/snowfall.jquery.js",
|
'src/js/lib/snowfall.jquery.js',
|
||||||
|
|
||||||
// Third party operation libraries
|
// Third party operation libraries
|
||||||
"src/js/lib/cryptojs/core.js",
|
'src/js/lib/cryptojs/core.js',
|
||||||
"src/js/lib/cryptojs/x64-core.js",
|
'src/js/lib/cryptojs/x64-core.js',
|
||||||
"src/js/lib/cryptojs/enc-base64.js",
|
'src/js/lib/cryptojs/enc-base64.js',
|
||||||
"src/js/lib/cryptojs/enc-utf16.js",
|
'src/js/lib/cryptojs/enc-utf16.js',
|
||||||
"src/js/lib/cryptojs/md5.js",
|
'src/js/lib/cryptojs/md5.js',
|
||||||
"src/js/lib/cryptojs/evpkdf.js",
|
'src/js/lib/cryptojs/evpkdf.js',
|
||||||
"src/js/lib/cryptojs/cipher-core.js",
|
'src/js/lib/cryptojs/cipher-core.js',
|
||||||
"src/js/lib/cryptojs/mode-cfb.js",
|
'src/js/lib/cryptojs/mode-cfb.js',
|
||||||
"src/js/lib/cryptojs/mode-ctr-gladman.js",
|
'src/js/lib/cryptojs/mode-ctr-gladman.js',
|
||||||
"src/js/lib/cryptojs/mode-ctr.js",
|
'src/js/lib/cryptojs/mode-ctr.js',
|
||||||
"src/js/lib/cryptojs/mode-ecb.js",
|
'src/js/lib/cryptojs/mode-ecb.js',
|
||||||
"src/js/lib/cryptojs/mode-ofb.js",
|
'src/js/lib/cryptojs/mode-ofb.js',
|
||||||
"src/js/lib/cryptojs/format-hex.js",
|
'src/js/lib/cryptojs/format-hex.js',
|
||||||
"src/js/lib/cryptojs/lib-typedarrays.js",
|
'src/js/lib/cryptojs/lib-typedarrays.js',
|
||||||
"src/js/lib/cryptojs/pad-ansix923.js",
|
'src/js/lib/cryptojs/pad-ansix923.js',
|
||||||
"src/js/lib/cryptojs/pad-iso10126.js",
|
'src/js/lib/cryptojs/pad-iso10126.js',
|
||||||
"src/js/lib/cryptojs/pad-iso97971.js",
|
'src/js/lib/cryptojs/pad-iso97971.js',
|
||||||
"src/js/lib/cryptojs/pad-nopadding.js",
|
'src/js/lib/cryptojs/pad-nopadding.js',
|
||||||
"src/js/lib/cryptojs/pad-zeropadding.js",
|
'src/js/lib/cryptojs/pad-zeropadding.js',
|
||||||
"src/js/lib/cryptojs/aes.js",
|
'src/js/lib/cryptojs/aes.js',
|
||||||
"src/js/lib/cryptojs/hmac.js",
|
'src/js/lib/cryptojs/hmac.js',
|
||||||
"src/js/lib/cryptojs/rabbit-legacy.js",
|
'src/js/lib/cryptojs/rabbit-legacy.js',
|
||||||
"src/js/lib/cryptojs/rabbit.js",
|
'src/js/lib/cryptojs/rabbit.js',
|
||||||
"src/js/lib/cryptojs/ripemd160.js",
|
'src/js/lib/cryptojs/ripemd160.js',
|
||||||
"src/js/lib/cryptojs/sha1.js",
|
'src/js/lib/cryptojs/sha1.js',
|
||||||
"src/js/lib/cryptojs/sha256.js",
|
'src/js/lib/cryptojs/sha256.js',
|
||||||
"src/js/lib/cryptojs/sha224.js",
|
'src/js/lib/cryptojs/sha224.js',
|
||||||
"src/js/lib/cryptojs/sha512.js",
|
'src/js/lib/cryptojs/sha512.js',
|
||||||
"src/js/lib/cryptojs/sha384.js",
|
'src/js/lib/cryptojs/sha384.js',
|
||||||
"src/js/lib/cryptojs/sha3.js",
|
'src/js/lib/cryptojs/sha3.js',
|
||||||
"src/js/lib/cryptojs/tripledes.js",
|
'src/js/lib/cryptojs/tripledes.js',
|
||||||
"src/js/lib/cryptojs/rc4.js",
|
'src/js/lib/cryptojs/rc4.js',
|
||||||
"src/js/lib/cryptojs/pbkdf2.js",
|
'src/js/lib/cryptojs/pbkdf2.js',
|
||||||
"src/js/lib/jsbn/jsbn.js",
|
'src/js/lib/jsbn/jsbn.js',
|
||||||
"src/js/lib/jsbn/jsbn2.js",
|
'src/js/lib/jsbn/jsbn2.js',
|
||||||
"src/js/lib/jsbn/base64.js",
|
'src/js/lib/jsbn/base64.js',
|
||||||
"src/js/lib/jsbn/ec.js",
|
'src/js/lib/jsbn/ec.js',
|
||||||
"src/js/lib/jsbn/prng4.js",
|
'src/js/lib/jsbn/prng4.js',
|
||||||
"src/js/lib/jsbn/rng.js",
|
'src/js/lib/jsbn/rng.js',
|
||||||
"src/js/lib/jsbn/rsa.js",
|
'src/js/lib/jsbn/rsa.js',
|
||||||
"src/js/lib/jsbn/sec.js",
|
'src/js/lib/jsbn/sec.js',
|
||||||
"src/js/lib/jsrasign/asn1-1.0.js",
|
'src/js/lib/jsrasign/asn1-1.0.js',
|
||||||
"src/js/lib/jsrasign/asn1hex-1.1.js",
|
'src/js/lib/jsrasign/asn1hex-1.1.js',
|
||||||
"src/js/lib/jsrasign/asn1x509-1.0.js",
|
'src/js/lib/jsrasign/asn1x509-1.0.js',
|
||||||
"src/js/lib/jsrasign/base64x-1.1.js",
|
'src/js/lib/jsrasign/base64x-1.1.js',
|
||||||
"src/js/lib/jsrasign/crypto-1.1.js",
|
'src/js/lib/jsrasign/crypto-1.1.js',
|
||||||
"src/js/lib/jsrasign/dsa-modified-1.0.js",
|
'src/js/lib/jsrasign/dsa-modified-1.0.js',
|
||||||
"src/js/lib/jsrasign/ecdsa-modified-1.0.js",
|
'src/js/lib/jsrasign/ecdsa-modified-1.0.js',
|
||||||
"src/js/lib/jsrasign/ecparam-1.0.js",
|
'src/js/lib/jsrasign/ecparam-1.0.js',
|
||||||
"src/js/lib/jsrasign/keyutil-1.0.js",
|
'src/js/lib/jsrasign/keyutil-1.0.js',
|
||||||
"src/js/lib/jsrasign/x509-1.1.js",
|
'src/js/lib/jsrasign/x509-1.1.js',
|
||||||
"src/js/lib/blowfish.dojo.js",
|
'src/js/lib/blowfish.dojo.js',
|
||||||
"src/js/lib/rawdeflate.js",
|
'src/js/lib/rawdeflate.js',
|
||||||
"src/js/lib/rawinflate.js",
|
'src/js/lib/rawinflate.js',
|
||||||
"src/js/lib/zip.js",
|
'src/js/lib/zip.js',
|
||||||
"src/js/lib/unzip.js",
|
'src/js/lib/unzip.js',
|
||||||
"src/js/lib/zlib_and_gzip.js",
|
'src/js/lib/zlib_and_gzip.js',
|
||||||
"src/js/lib/bzip2.js",
|
'src/js/lib/bzip2.js',
|
||||||
"src/js/lib/punycode.js",
|
'src/js/lib/punycode.js',
|
||||||
"src/js/lib/uas_parser.js",
|
'src/js/lib/uas_parser.js',
|
||||||
"src/js/lib/esprima.js",
|
'src/js/lib/esprima.js',
|
||||||
"src/js/lib/escodegen.browser.js",
|
'src/js/lib/escodegen.browser.js',
|
||||||
"src/js/lib/esmangle.min.js",
|
'src/js/lib/esmangle.min.js',
|
||||||
"src/js/lib/diff.js",
|
'src/js/lib/diff.js',
|
||||||
"src/js/lib/moment.js",
|
'src/js/lib/moment.js',
|
||||||
"src/js/lib/moment-timezone.js",
|
'src/js/lib/moment-timezone.js',
|
||||||
"src/js/lib/prettify.js",
|
'src/js/lib/prettify.js',
|
||||||
"src/js/lib/vkbeautify.js",
|
'src/js/lib/vkbeautify.js',
|
||||||
"src/js/lib/Sortable.js",
|
'src/js/lib/Sortable.js',
|
||||||
"src/js/lib/bootstrap-colorpicker.js",
|
'src/js/lib/bootstrap-colorpicker.js',
|
||||||
|
|
||||||
// Custom libraries
|
// Custom libraries
|
||||||
"src/js/lib/canvas_components.js",
|
'src/js/lib/canvas_components.js',
|
||||||
|
|
||||||
// Utility functions
|
// Utility functions
|
||||||
"src/js/core/Utils.js",
|
'src/js/core/Utils.js',
|
||||||
|
|
||||||
// Operation objects
|
// Operation objects
|
||||||
"src/js/operations/*.js",
|
'src/js/operations/*.js',
|
||||||
|
|
||||||
// Core framework objects
|
// Core framework objects
|
||||||
"src/js/core/*.js",
|
'src/js/core/*.js',
|
||||||
"src/js/config/Categories.js",
|
'src/js/config/Categories.js',
|
||||||
"src/js/config/OperationConfig.js",
|
'src/js/config/OperationConfig.js',
|
||||||
|
|
||||||
// HTML view objects
|
// HTML view objects
|
||||||
"src/js/views/html/*.js",
|
'src/js/views/html/*.js',
|
||||||
"!src/js/views/html/main.js",
|
'!src/js/views/html/main.js',
|
||||||
|
|
||||||
// Start the app!
|
// Start the app!
|
||||||
"src/js/views/html/main.js",
|
'src/js/views/html/main.js',
|
||||||
];
|
];
|
||||||
|
|
||||||
var banner = '/**\n\
|
const banner = '/**\n\
|
||||||
* CyberChef - The Cyber Swiss Army Knife\n\
|
* CyberChef - The Cyber Swiss Army Knife\n\
|
||||||
*\n\
|
*\n\
|
||||||
* @copyright Crown Copyright 2016\n\
|
* @copyright Crown Copyright 2016\n\
|
||||||
|
@ -167,278 +167,277 @@ module.exports = function(grunt) {
|
||||||
* limitations under the License.\n\
|
* limitations under the License.\n\
|
||||||
*/\n';
|
*/\n';
|
||||||
|
|
||||||
var template_options = {
|
const template_options = {
|
||||||
data: {
|
data: {
|
||||||
compile_msg: grunt.option("compile-msg") || grunt.option("msg") || "",
|
compile_msg: grunt.option('compile-msg') || grunt.option('msg') || '',
|
||||||
codebase_stats: grunt.file.read("src/static/stats.txt").split("\n").join("<br>")
|
codebase_stats: grunt.file.read('src/static/stats.txt').split('\n').join('<br>'),
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
// Project configuration
|
// Project configuration
|
||||||
grunt.initConfig({
|
grunt.initConfig({
|
||||||
jshint: {
|
jshint: {
|
||||||
options: {
|
options: {
|
||||||
jshintrc: "src/js/.jshintrc"
|
jshintrc: 'src/js/.jshintrc',
|
||||||
},
|
},
|
||||||
gruntfile: ["Gruntfile.js"],
|
gruntfile: ['Gruntfile.js'],
|
||||||
core: ["src/js/core/**/*.js"],
|
core: ['src/js/core/**/*.js'],
|
||||||
config: ["src/js/config/**/*.js"],
|
config: ['src/js/config/**/*.js'],
|
||||||
views: ["src/js/views/**/*.js"],
|
views: ['src/js/views/**/*.js'],
|
||||||
operations: ["src/js/operations/**/*.js"],
|
operations: ['src/js/operations/**/*.js'],
|
||||||
},
|
},
|
||||||
jsdoc: {
|
jsdoc: {
|
||||||
options: {
|
options: {
|
||||||
destination: "docs",
|
destination: 'docs',
|
||||||
template: "node_modules/ink-docstrap/template",
|
template: 'node_modules/ink-docstrap/template',
|
||||||
recurse: true,
|
recurse: true,
|
||||||
readme: "./README.md",
|
readme: './README.md',
|
||||||
configure: "docs/jsdoc.conf.json"
|
configure: 'docs/jsdoc.conf.json',
|
||||||
},
|
},
|
||||||
all: {
|
all: {
|
||||||
src: [
|
src: [
|
||||||
"src/js/**/*.js",
|
'src/js/**/*.js',
|
||||||
"!src/js/lib/**/*",
|
'!src/js/lib/**/*',
|
||||||
],
|
],
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
clean: {
|
clean: {
|
||||||
dev: ["build/dev/*"],
|
dev: ['build/dev/*'],
|
||||||
prod: ["build/prod/*"],
|
prod: ['build/prod/*'],
|
||||||
docs: ["docs/*", "!docs/*.conf.json", "!docs/*.ico"],
|
docs: ['docs/*', '!docs/*.conf.json', '!docs/*.ico'],
|
||||||
},
|
},
|
||||||
concat: {
|
concat: {
|
||||||
options: {
|
options: {
|
||||||
process: template_options
|
process: template_options,
|
||||||
},
|
},
|
||||||
css: {
|
css: {
|
||||||
options: {
|
options: {
|
||||||
banner: banner.replace(/\/\*\*/g, "/*!"),
|
banner: banner.replace(/\/\*\*/g, '/*!'),
|
||||||
process: function(content, srcpath) {
|
process(content, srcpath) {
|
||||||
// Change special comments from /** to /*! to comply with cssmin
|
// Change special comments from /** to /*! to comply with cssmin
|
||||||
content = content.replace(/^\/\*\* /g, "/*! ");
|
content = content.replace(/^\/\*\* /g, '/*! ');
|
||||||
return grunt.template.process(content);
|
return grunt.template.process(content);
|
||||||
}
|
},
|
||||||
},
|
|
||||||
src: [
|
|
||||||
"src/css/lib/**/*.css",
|
|
||||||
"src/css/structure/**/*.css",
|
|
||||||
"src/css/themes/classic.css"
|
|
||||||
],
|
|
||||||
dest: "build/dev/styles.css"
|
|
||||||
},
|
|
||||||
js: {
|
|
||||||
options: {
|
|
||||||
banner: '"use strict";\n'
|
|
||||||
},
|
|
||||||
src: js_files,
|
|
||||||
dest: "build/dev/scripts.js"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
copy: {
|
src: [
|
||||||
html_dev: {
|
'src/css/lib/**/*.css',
|
||||||
options: {
|
'src/css/structure/**/*.css',
|
||||||
process: function(content, srcpath) {
|
'src/css/themes/classic.css',
|
||||||
return grunt.template.process(content, template_options);
|
],
|
||||||
}
|
dest: 'build/dev/styles.css',
|
||||||
},
|
},
|
||||||
src: "src/html/index.html",
|
js: {
|
||||||
dest: "build/dev/index.html"
|
options: {
|
||||||
},
|
banner: '"use strict";\n',
|
||||||
html_prod: {
|
},
|
||||||
options: {
|
src: js_files,
|
||||||
process: function(content, srcpath) {
|
dest: 'build/dev/scripts.js',
|
||||||
return grunt.template.process(content, template_options);
|
},
|
||||||
}
|
},
|
||||||
},
|
copy: {
|
||||||
src: "src/html/index.html",
|
html_dev: {
|
||||||
dest: "build/prod/index.html"
|
options: {
|
||||||
},
|
process(content, srcpath) {
|
||||||
html_inline: {
|
return grunt.template.process(content, template_options);
|
||||||
options: {
|
},
|
||||||
process: function(content, srcpath) {
|
},
|
||||||
|
src: 'src/html/index.html',
|
||||||
|
dest: 'build/dev/index.html',
|
||||||
|
},
|
||||||
|
html_prod: {
|
||||||
|
options: {
|
||||||
|
process(content, srcpath) {
|
||||||
|
return grunt.template.process(content, template_options);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
src: 'src/html/index.html',
|
||||||
|
dest: 'build/prod/index.html',
|
||||||
|
},
|
||||||
|
html_inline: {
|
||||||
|
options: {
|
||||||
|
process(content, srcpath) {
|
||||||
// TODO: Do all this in Jade
|
// TODO: Do all this in Jade
|
||||||
content = content.replace(
|
content = content.replace(
|
||||||
'<a href="cyberchef.htm" style="float: left; margin-left: 10px; margin-right: 80px;" download>Download CyberChef<img src="images/cloud_computing_download-plain-24x24.png" /></a>',
|
'<a href="cyberchef.htm" style="float: left; margin-left: 10px; margin-right: 80px;">Download CyberChef<img src="images/cloud_computing_download-plain-24x24.png" /></a>',
|
||||||
'<span style="float: left; margin-left: 10px;">Compile time: ' + grunt.template.today("dd/mm/yyyy HH:MM:ss") + ' UTC</span>');
|
`<span style="float: left; margin-left: 10px;">Compile time: ${grunt.template.today('dd/mm/yyyy HH:MM:ss')} UTC</span>`);
|
||||||
return grunt.template.process(content, template_options);
|
return grunt.template.process(content, template_options);
|
||||||
}
|
},
|
||||||
},
|
|
||||||
src: "src/html/index.html",
|
|
||||||
dest: "build/prod/cyberchef.htm"
|
|
||||||
},
|
|
||||||
static_dev: {
|
|
||||||
files: [
|
|
||||||
{
|
|
||||||
expand: true,
|
|
||||||
cwd: "src/static/",
|
|
||||||
src: [
|
|
||||||
"**/*",
|
|
||||||
"**/.*",
|
|
||||||
"!stats.txt"
|
|
||||||
],
|
|
||||||
dest: "build/dev/"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
static_prod: {
|
|
||||||
files: [
|
|
||||||
{
|
|
||||||
expand: true,
|
|
||||||
cwd: "src/static/",
|
|
||||||
src: [
|
|
||||||
"**/*",
|
|
||||||
"**/.*",
|
|
||||||
"!stats.txt"
|
|
||||||
],
|
|
||||||
dest: "build/prod/"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
uglify: {
|
src: 'src/html/index.html',
|
||||||
options: {
|
dest: 'build/prod/cyberchef.htm',
|
||||||
preserveComments: function(node, comment) {
|
},
|
||||||
if (comment.value.indexOf("* @license") === 0) return true;
|
static_dev: {
|
||||||
return false;
|
files: [
|
||||||
},
|
{
|
||||||
screwIE8: true,
|
expand: true,
|
||||||
ASCIIOnly: true,
|
cwd: 'src/static/',
|
||||||
beautify: {
|
src: [
|
||||||
beautify: false,
|
'**/*',
|
||||||
inline_script: true,
|
'**/.*',
|
||||||
ascii_only: true,
|
'!stats.txt',
|
||||||
screw_ie8: true
|
],
|
||||||
},
|
dest: 'build/dev/',
|
||||||
compress: {
|
},
|
||||||
screw_ie8: true
|
],
|
||||||
},
|
},
|
||||||
banner: banner
|
static_prod: {
|
||||||
},
|
files: [
|
||||||
prod: {
|
{
|
||||||
src: "build/dev/scripts.js",
|
expand: true,
|
||||||
dest: "build/prod/scripts.js"
|
cwd: 'src/static/',
|
||||||
}
|
src: [
|
||||||
|
'**/*',
|
||||||
|
'**/.*',
|
||||||
|
'!stats.txt',
|
||||||
|
],
|
||||||
|
dest: 'build/prod/',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
uglify: {
|
||||||
|
options: {
|
||||||
|
preserveComments(node, comment) {
|
||||||
|
if (comment.value.indexOf('* @license') === 0) return true;
|
||||||
|
return false;
|
||||||
},
|
},
|
||||||
cssmin: {
|
screwIE8: true,
|
||||||
prod: {
|
ASCIIOnly: true,
|
||||||
src: "build/dev/styles.css",
|
beautify: {
|
||||||
dest: "build/prod/styles.css"
|
beautify: false,
|
||||||
}
|
inline_script: true,
|
||||||
|
ascii_only: true,
|
||||||
|
screw_ie8: true,
|
||||||
},
|
},
|
||||||
htmlmin: {
|
compress: {
|
||||||
prod: {
|
screw_ie8: true,
|
||||||
options: {
|
|
||||||
removeComments: true,
|
|
||||||
collapseWhitespace: true,
|
|
||||||
minifyJS: true,
|
|
||||||
minifyCSS: true
|
|
||||||
},
|
|
||||||
src: "build/prod/index.html",
|
|
||||||
dest: "build/prod/index.html"
|
|
||||||
},
|
|
||||||
inline: {
|
|
||||||
options: {
|
|
||||||
removeComments: true,
|
|
||||||
collapseWhitespace: true,
|
|
||||||
minifyJS: false,
|
|
||||||
minifyCSS: false
|
|
||||||
},
|
|
||||||
src: "build/prod/cyberchef.htm",
|
|
||||||
dest: "build/prod/cyberchef.htm"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
inline: {
|
banner,
|
||||||
options: {
|
},
|
||||||
tag: "",
|
prod: {
|
||||||
inlineTagAttributes: {
|
src: 'build/dev/scripts.js',
|
||||||
js: "type='application/javascript'",
|
dest: 'build/prod/scripts.js',
|
||||||
css: "type='text/css'"
|
},
|
||||||
}
|
},
|
||||||
},
|
cssmin: {
|
||||||
prod: {
|
prod: {
|
||||||
src: "build/prod/cyberchef.htm",
|
src: 'build/dev/styles.css',
|
||||||
dest: "build/prod/cyberchef.htm"
|
dest: 'build/prod/styles.css',
|
||||||
}
|
},
|
||||||
|
},
|
||||||
|
htmlmin: {
|
||||||
|
prod: {
|
||||||
|
options: {
|
||||||
|
removeComments: true,
|
||||||
|
collapseWhitespace: true,
|
||||||
|
minifyJS: true,
|
||||||
|
minifyCSS: true,
|
||||||
},
|
},
|
||||||
chmod: {
|
src: 'build/prod/index.html',
|
||||||
build: {
|
dest: 'build/prod/index.html',
|
||||||
options: {
|
},
|
||||||
mode: "755",
|
inline: {
|
||||||
},
|
options: {
|
||||||
src: ["build/**/*", "build/**/.htaccess", "build/"]
|
removeComments: true,
|
||||||
},
|
collapseWhitespace: true,
|
||||||
docs: {
|
minifyJS: false,
|
||||||
options: {
|
minifyCSS: false,
|
||||||
mode: "755",
|
|
||||||
},
|
|
||||||
src: ["docs/**/*", "docs/"]
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
exec: {
|
src: 'build/prod/cyberchef.htm',
|
||||||
repo_size: {
|
dest: 'build/prod/cyberchef.htm',
|
||||||
command: [
|
},
|
||||||
"git ls-files | wc -l | xargs printf '\n%b\ttracked files\n'",
|
},
|
||||||
"du -hs | egrep -o '^[^\t]*' | xargs printf '%b\trepository size\n'"
|
inline: {
|
||||||
].join(";"),
|
options: {
|
||||||
stderr: false
|
tag: '',
|
||||||
},
|
inlineTagAttributes: {
|
||||||
stats: {
|
js: "type='application/javascript'",
|
||||||
command: "rm src/static/stats.txt;" +
|
css: "type='text/css'",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
prod: {
|
||||||
|
src: 'build/prod/cyberchef.htm',
|
||||||
|
dest: 'build/prod/cyberchef.htm',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
chmod: {
|
||||||
|
build: {
|
||||||
|
options: {
|
||||||
|
mode: '755',
|
||||||
|
},
|
||||||
|
src: ['build/**/*', 'build/**/.htaccess', 'build/'],
|
||||||
|
},
|
||||||
|
docs: {
|
||||||
|
options: {
|
||||||
|
mode: '755',
|
||||||
|
},
|
||||||
|
src: ['docs/**/*', 'docs/'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
exec: {
|
||||||
|
repo_size: {
|
||||||
|
command: [
|
||||||
|
"git ls-files | wc -l | xargs printf '\n%b\ttracked files\n'",
|
||||||
|
"du -hs | egrep -o '^[^\t]*' | xargs printf '%b\trepository size\n'",
|
||||||
|
].join(';'),
|
||||||
|
stderr: false,
|
||||||
|
},
|
||||||
|
stats: {
|
||||||
|
command: `rm src/static/stats.txt;${
|
||||||
[
|
[
|
||||||
"ls src/ -R1 | grep '^$' -v | grep ':$' -v | wc -l | xargs printf '%b\tsource files\n'",
|
"ls src/ -R1 | grep '^$' -v | grep ':$' -v | wc -l | xargs printf '%b\tsource files\n'",
|
||||||
"find src/ -regex '.*\..*' -print | xargs cat | wc -l | xargs printf '%b\tlines\n'",
|
"find src/ -regex '.*\..*' -print | xargs cat | wc -l | xargs printf '%b\tlines\n'",
|
||||||
"du -hs src/ | pcregrep -o '^[^\t]*' | xargs printf '%b\tsize\n'",
|
"du -hs src/ | pcregrep -o '^[^\t]*' | xargs printf '%b\tsize\n'",
|
||||||
|
|
||||||
"ls src/js/ -R1 | grep '\.js$' | wc -l | xargs printf '\n%b\tJavaScript source files\n'",
|
"ls src/js/ -R1 | grep '\.js$' | wc -l | xargs printf '\n%b\tJavaScript source files\n'",
|
||||||
"find src/js/ -regex '.*\.js' -print | xargs cat | wc -l | xargs printf '%b\tlines\n'",
|
"find src/js/ -regex '.*\.js' -print | xargs cat | wc -l | xargs printf '%b\tlines\n'",
|
||||||
"find src/js/ -regex '.*\.js' -exec du -hcs {} \+ | tail -n1 | egrep -o '^[^\t]*' | xargs printf '%b\tsize\n'",
|
"find src/js/ -regex '.*\.js' -exec du -hcs {} \+ | tail -n1 | egrep -o '^[^\t]*' | xargs printf '%b\tsize\n'",
|
||||||
|
|
||||||
"find src/js/ -regex '.*/lib/.*\.js' -print | wc -l | xargs printf '\n%b\tthird party JavaScript source files\n'",
|
"find src/js/ -regex '.*/lib/.*\.js' -print | wc -l | xargs printf '\n%b\tthird party JavaScript source files\n'",
|
||||||
"find src/js/ -regex '.*/lib/.*\.js' -print | xargs cat | wc -l | xargs printf '%b\tlines\n'",
|
"find src/js/ -regex '.*/lib/.*\.js' -print | xargs cat | wc -l | xargs printf '%b\tlines\n'",
|
||||||
"find src/js/ -regex '.*/lib/.*\.js' -exec du -hcs {} \+ | tail -n1 | egrep -o '^[^\t]*' | xargs printf '%b\tsize\n'",
|
"find src/js/ -regex '.*/lib/.*\.js' -exec du -hcs {} \+ | tail -n1 | egrep -o '^[^\t]*' | xargs printf '%b\tsize\n'",
|
||||||
|
|
||||||
"find src/js/ -regex '.*\.js' -not -regex '.*/lib/.*' -print | wc -l | xargs printf '\n%b\tfirst party JavaScript source files\n'",
|
"find src/js/ -regex '.*\.js' -not -regex '.*/lib/.*' -print | wc -l | xargs printf '\n%b\tfirst party JavaScript source files\n'",
|
||||||
"find src/js/ -regex '.*\.js' -not -regex '.*/lib/.*' -print | xargs cat | wc -l | xargs printf '%b\tlines\n'",
|
"find src/js/ -regex '.*\.js' -not -regex '.*/lib/.*' -print | xargs cat | wc -l | xargs printf '%b\tlines\n'",
|
||||||
"find src/js/ -regex '.*\.js' -not -regex '.*/lib/.*' -exec du -hcs {} \+ | tail -n1 | egrep -o '^[^\t]*' | xargs printf '%b\tsize\n'",
|
"find src/js/ -regex '.*\.js' -not -regex '.*/lib/.*' -exec du -hcs {} \+ | tail -n1 | egrep -o '^[^\t]*' | xargs printf '%b\tsize\n'",
|
||||||
|
|
||||||
"du build/dev/scripts.js -h | egrep -o '^[^\t]*' | xargs printf '\n%b\tuncompressed JavaScript size\n'",
|
"du build/dev/scripts.js -h | egrep -o '^[^\t]*' | xargs printf '\n%b\tuncompressed JavaScript size\n'",
|
||||||
"du build/prod/scripts.js -h | egrep -o '^[^\t]*' | xargs printf '%b\tcompressed JavaScript size\n'",
|
"du build/prod/scripts.js -h | egrep -o '^[^\t]*' | xargs printf '%b\tcompressed JavaScript size\n'",
|
||||||
|
|
||||||
"grep -E '^\\s+name: ' src/js/config/Categories.js | wc -l | xargs printf '\n%b\tcategories\n'",
|
"grep -E '^\\s+name: ' src/js/config/Categories.js | wc -l | xargs printf '\n%b\tcategories\n'",
|
||||||
"grep -E '^\\s+\"[A-Za-z0-9 \\-]+\": {' src/js/config/OperationConfig.js | wc -l | xargs printf '%b\toperations\n'",
|
"grep -E '^\\s+\"[A-Za-z0-9 \\-]+\": {' src/js/config/OperationConfig.js | wc -l | xargs printf '%b\toperations\n'",
|
||||||
|
|
||||||
].join(" >> src/static/stats.txt;") + " >> src/static/stats.txt;",
|
|
||||||
stderr: false
|
|
||||||
},
|
|
||||||
display_stats: {
|
|
||||||
command: "cat src/static/stats.txt"
|
|
||||||
},
|
|
||||||
clean_git: {
|
|
||||||
command: "git gc --prune=now --aggressive"
|
|
||||||
},
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
css: {
|
|
||||||
files: "src/css/**/*.css",
|
|
||||||
tasks: ["concat:css", "chmod:build"]
|
|
||||||
},
|
|
||||||
js: {
|
|
||||||
files: "src/js/**/*.js",
|
|
||||||
tasks: ["concat:js_all", "chmod:build"]
|
|
||||||
},
|
|
||||||
html: {
|
|
||||||
files: "src/html/**/*.html",
|
|
||||||
tasks: ["copy:html_dev", "chmod:build"]
|
|
||||||
},
|
|
||||||
static: {
|
|
||||||
files: ["src/static/**/*", "src/static/**/.*"],
|
|
||||||
tasks: ["copy:static_dev", "chmod:build"]
|
|
||||||
},
|
|
||||||
grunt: {
|
|
||||||
files: "Gruntfile.js",
|
|
||||||
tasks: ["clean:dev", "concat:css", "concat:js_all", "copy:html_dev", "copy:static_dev", "chmod:build"]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
|
].join(' >> src/static/stats.txt;')} >> src/static/stats.txt;`,
|
||||||
|
stderr: false,
|
||||||
|
},
|
||||||
|
display_stats: {
|
||||||
|
command: 'cat src/static/stats.txt',
|
||||||
|
},
|
||||||
|
clean_git: {
|
||||||
|
command: 'git gc --prune=now --aggressive',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
css: {
|
||||||
|
files: 'src/css/**/*.css',
|
||||||
|
tasks: ['concat:css', 'chmod:build'],
|
||||||
|
},
|
||||||
|
js: {
|
||||||
|
files: 'src/js/**/*.js',
|
||||||
|
tasks: ['concat:js_all', 'chmod:build'],
|
||||||
|
},
|
||||||
|
html: {
|
||||||
|
files: 'src/html/**/*.html',
|
||||||
|
tasks: ['copy:html_dev', 'chmod:build'],
|
||||||
|
},
|
||||||
|
static: {
|
||||||
|
files: ['src/static/**/*', 'src/static/**/.*'],
|
||||||
|
tasks: ['copy:static_dev', 'chmod:build'],
|
||||||
|
},
|
||||||
|
grunt: {
|
||||||
|
files: 'Gruntfile.js',
|
||||||
|
tasks: ['clean:dev', 'concat:css', 'concat:js_all', 'copy:html_dev', 'copy:static_dev', 'chmod:build'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -17,250 +17,250 @@
|
||||||
* @constant
|
* @constant
|
||||||
* @type {CatConf[]}
|
* @type {CatConf[]}
|
||||||
*/
|
*/
|
||||||
var Categories = [
|
const Categories = [
|
||||||
{
|
{
|
||||||
name: "Favourites",
|
name: 'Favourites',
|
||||||
ops: []
|
ops: [],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Data format",
|
name: 'Data format',
|
||||||
ops: [
|
ops: [
|
||||||
"To Hexdump",
|
'To Hexdump',
|
||||||
"From Hexdump",
|
'From Hexdump',
|
||||||
"To Hex",
|
'To Hex',
|
||||||
"From Hex",
|
'From Hex',
|
||||||
"To Charcode",
|
'To Charcode',
|
||||||
"From Charcode",
|
'From Charcode',
|
||||||
"To Decimal",
|
'To Decimal',
|
||||||
"From Decimal",
|
'From Decimal',
|
||||||
"To Binary",
|
'To Binary',
|
||||||
"From Binary",
|
'From Binary',
|
||||||
"To Base64",
|
'To Base64',
|
||||||
"From Base64",
|
'From Base64',
|
||||||
"Show Base64 offsets",
|
'Show Base64 offsets',
|
||||||
"To Base32",
|
'To Base32',
|
||||||
"From Base32",
|
'From Base32',
|
||||||
"To Base",
|
'To Base',
|
||||||
"From Base",
|
'From Base',
|
||||||
"To HTML Entity",
|
'To HTML Entity',
|
||||||
"From HTML Entity",
|
'From HTML Entity',
|
||||||
"URL Encode",
|
'URL Encode',
|
||||||
"URL Decode",
|
'URL Decode',
|
||||||
"Unescape Unicode Characters",
|
'Unescape Unicode Characters',
|
||||||
"To Quoted Printable",
|
'To Quoted Printable',
|
||||||
"From Quoted Printable",
|
'From Quoted Printable',
|
||||||
"To Punycode",
|
'To Punycode',
|
||||||
"From Punycode",
|
'From Punycode',
|
||||||
"To Hex Content",
|
'To Hex Content',
|
||||||
"From Hex Content",
|
'From Hex Content',
|
||||||
"PEM to Hex",
|
'PEM to Hex',
|
||||||
"Hex to PEM",
|
'Hex to PEM',
|
||||||
"Parse ASN.1 hex string",
|
'Parse ASN.1 hex string',
|
||||||
"Change IP format",
|
'Change IP format',
|
||||||
"Text encoding",
|
'Text encoding',
|
||||||
"Swap endianness",
|
'Swap endianness',
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Encryption / Encoding",
|
name: 'Encryption / Encoding',
|
||||||
ops: [
|
ops: [
|
||||||
"AES Encrypt",
|
'AES Encrypt',
|
||||||
"AES Decrypt",
|
'AES Decrypt',
|
||||||
"Blowfish Encrypt",
|
'Blowfish Encrypt',
|
||||||
"Blowfish Decrypt",
|
'Blowfish Decrypt',
|
||||||
"DES Encrypt",
|
'DES Encrypt',
|
||||||
"DES Decrypt",
|
'DES Decrypt',
|
||||||
"Triple DES Encrypt",
|
'Triple DES Encrypt',
|
||||||
"Triple DES Decrypt",
|
'Triple DES Decrypt',
|
||||||
"Rabbit Encrypt",
|
'Rabbit Encrypt',
|
||||||
"Rabbit Decrypt",
|
'Rabbit Decrypt',
|
||||||
"RC4",
|
'RC4',
|
||||||
"RC4 Drop",
|
'RC4 Drop',
|
||||||
"ROT13",
|
'ROT13',
|
||||||
"XOR",
|
'XOR',
|
||||||
"XOR Brute Force",
|
'XOR Brute Force',
|
||||||
"Derive PBKDF2 key",
|
'Derive PBKDF2 key',
|
||||||
"Derive EVP key",
|
'Derive EVP key',
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Public Key",
|
name: 'Public Key',
|
||||||
ops: [
|
ops: [
|
||||||
"Parse X.509 certificate",
|
'Parse X.509 certificate',
|
||||||
"Parse ASN.1 hex string",
|
'Parse ASN.1 hex string',
|
||||||
"PEM to Hex",
|
'PEM to Hex',
|
||||||
"Hex to PEM",
|
'Hex to PEM',
|
||||||
"Hex to Object Identifier",
|
'Hex to Object Identifier',
|
||||||
"Object Identifier to Hex",
|
'Object Identifier to Hex',
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Logical operations",
|
name: 'Logical operations',
|
||||||
ops: [
|
ops: [
|
||||||
"XOR",
|
'XOR',
|
||||||
"XOR Brute Force",
|
'XOR Brute Force',
|
||||||
"OR",
|
'OR',
|
||||||
"NOT",
|
'NOT',
|
||||||
"AND",
|
'AND',
|
||||||
"ADD",
|
'ADD',
|
||||||
"SUB",
|
'SUB',
|
||||||
"Rotate left",
|
'Rotate left',
|
||||||
"Rotate right",
|
'Rotate right',
|
||||||
"ROT13",
|
'ROT13',
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Networking",
|
name: 'Networking',
|
||||||
ops: [
|
ops: [
|
||||||
"Strip HTTP headers",
|
'Strip HTTP headers',
|
||||||
"Parse User Agent",
|
'Parse User Agent',
|
||||||
"Parse IP range",
|
'Parse IP range',
|
||||||
"Parse IPv6 address",
|
'Parse IPv6 address',
|
||||||
"Parse URI",
|
'Parse URI',
|
||||||
"URL Encode",
|
'URL Encode',
|
||||||
"URL Decode",
|
'URL Decode',
|
||||||
"Format MAC addresses",
|
'Format MAC addresses',
|
||||||
"Change IP format",
|
'Change IP format',
|
||||||
"Group IP addresses",
|
'Group IP addresses',
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Language",
|
name: 'Language',
|
||||||
ops: [
|
ops: [
|
||||||
"Text encoding",
|
'Text encoding',
|
||||||
"Unescape Unicode Characters",
|
'Unescape Unicode Characters',
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Utils",
|
name: 'Utils',
|
||||||
ops: [
|
ops: [
|
||||||
"Diff",
|
'Diff',
|
||||||
"Remove whitespace",
|
'Remove whitespace',
|
||||||
"Remove null bytes",
|
'Remove null bytes',
|
||||||
"To Upper case",
|
'To Upper case',
|
||||||
"To Lower case",
|
'To Lower case',
|
||||||
"Add line numbers",
|
'Add line numbers',
|
||||||
"Remove line numbers",
|
'Remove line numbers',
|
||||||
"Reverse",
|
'Reverse',
|
||||||
"Sort",
|
'Sort',
|
||||||
"Unique",
|
'Unique',
|
||||||
"Split",
|
'Split',
|
||||||
"Count occurrences",
|
'Count occurrences',
|
||||||
"Expand alphabet range",
|
'Expand alphabet range',
|
||||||
"Parse escaped string",
|
'Parse escaped string',
|
||||||
"Drop bytes",
|
'Drop bytes',
|
||||||
"Take bytes",
|
'Take bytes',
|
||||||
"Pad lines",
|
'Pad lines',
|
||||||
"Find / Replace",
|
'Find / Replace',
|
||||||
"Regular expression",
|
'Regular expression',
|
||||||
"Offset checker",
|
'Offset checker',
|
||||||
"Convert distance",
|
'Convert distance',
|
||||||
"Convert area",
|
'Convert area',
|
||||||
"Convert mass",
|
'Convert mass',
|
||||||
"Convert speed",
|
'Convert speed',
|
||||||
"Convert data units",
|
'Convert data units',
|
||||||
"Parse UNIX file permissions",
|
'Parse UNIX file permissions',
|
||||||
"Swap endianness",
|
'Swap endianness',
|
||||||
"Parse colour code",
|
'Parse colour code',
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Date / Time",
|
name: 'Date / Time',
|
||||||
ops: [
|
ops: [
|
||||||
"Parse DateTime",
|
'Parse DateTime',
|
||||||
"Translate DateTime Format",
|
'Translate DateTime Format',
|
||||||
"From UNIX Timestamp",
|
'From UNIX Timestamp',
|
||||||
"To UNIX Timestamp",
|
'To UNIX Timestamp',
|
||||||
"Extract dates",
|
'Extract dates',
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Extractors",
|
name: 'Extractors',
|
||||||
ops: [
|
ops: [
|
||||||
"Strings",
|
'Strings',
|
||||||
"Extract IP addresses",
|
'Extract IP addresses',
|
||||||
"Extract email addresses",
|
'Extract email addresses',
|
||||||
"Extract MAC addresses",
|
'Extract MAC addresses',
|
||||||
"Extract URLs",
|
'Extract URLs',
|
||||||
"Extract domains",
|
'Extract domains',
|
||||||
"Extract file paths",
|
'Extract file paths',
|
||||||
"Extract dates",
|
'Extract dates',
|
||||||
"Regular expression",
|
'Regular expression',
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Compression",
|
name: 'Compression',
|
||||||
ops: [
|
ops: [
|
||||||
"Raw Deflate",
|
'Raw Deflate',
|
||||||
"Raw Inflate",
|
'Raw Inflate',
|
||||||
"Zlib Deflate",
|
'Zlib Deflate',
|
||||||
"Zlib Inflate",
|
'Zlib Inflate',
|
||||||
"Gzip",
|
'Gzip',
|
||||||
"Gunzip",
|
'Gunzip',
|
||||||
"Zip",
|
'Zip',
|
||||||
"Unzip",
|
'Unzip',
|
||||||
"Bzip2 Decompress",
|
'Bzip2 Decompress',
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Hashing",
|
name: 'Hashing',
|
||||||
ops: [
|
ops: [
|
||||||
"Analyse hash",
|
'Analyse hash',
|
||||||
"Generate all hashes",
|
'Generate all hashes',
|
||||||
"MD5",
|
'MD5',
|
||||||
"SHA1",
|
'SHA1',
|
||||||
"SHA224",
|
'SHA224',
|
||||||
"SHA256",
|
'SHA256',
|
||||||
"SHA384",
|
'SHA384',
|
||||||
"SHA512",
|
'SHA512',
|
||||||
"SHA3",
|
'SHA3',
|
||||||
"RIPEMD-160",
|
'RIPEMD-160',
|
||||||
"HMAC",
|
'HMAC',
|
||||||
"Fletcher-16 Checksum",
|
'Fletcher-16 Checksum',
|
||||||
"Adler-32 Checksum",
|
'Adler-32 Checksum',
|
||||||
"CRC-32 Checksum",
|
'CRC-32 Checksum',
|
||||||
"TCP/IP Checksum",
|
'TCP/IP Checksum',
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Code tidy",
|
name: 'Code tidy',
|
||||||
ops: [
|
ops: [
|
||||||
"Syntax highlighter",
|
'Syntax highlighter',
|
||||||
"Generic Code Beautify",
|
'Generic Code Beautify',
|
||||||
"JavaScript Parser",
|
'JavaScript Parser',
|
||||||
"JavaScript Beautify",
|
'JavaScript Beautify',
|
||||||
"JavaScript Minify",
|
'JavaScript Minify',
|
||||||
"JSON Beautify",
|
'JSON Beautify',
|
||||||
"JSON Minify",
|
'JSON Minify',
|
||||||
"XML Beautify",
|
'XML Beautify',
|
||||||
"XML Minify",
|
'XML Minify',
|
||||||
"SQL Beautify",
|
'SQL Beautify',
|
||||||
"SQL Minify",
|
'SQL Minify',
|
||||||
"CSS Beautify",
|
'CSS Beautify',
|
||||||
"CSS Minify",
|
'CSS Minify',
|
||||||
"Strip HTML tags",
|
'Strip HTML tags',
|
||||||
"Diff",
|
'Diff',
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Other",
|
name: 'Other',
|
||||||
ops: [
|
ops: [
|
||||||
"Entropy",
|
'Entropy',
|
||||||
"Frequency distribution",
|
'Frequency distribution',
|
||||||
"Detect File Type",
|
'Detect File Type',
|
||||||
"Scan for Embedded Files",
|
'Scan for Embedded Files',
|
||||||
"Generate UUID",
|
'Generate UUID',
|
||||||
"Numberwang",
|
'Numberwang',
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Flow control",
|
name: 'Flow control',
|
||||||
ops: [
|
ops: [
|
||||||
"Fork",
|
'Fork',
|
||||||
"Merge",
|
'Merge',
|
||||||
"Jump",
|
'Jump',
|
||||||
"Conditional Jump",
|
'Conditional Jump',
|
||||||
"Return",
|
'Return',
|
||||||
]
|
],
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -7,8 +7,8 @@
|
||||||
*
|
*
|
||||||
* @class
|
* @class
|
||||||
*/
|
*/
|
||||||
var Chef = function() {
|
const Chef = function () {
|
||||||
this.dish = new Dish();
|
this.dish = new Dish();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,62 +30,62 @@ var Chef = function() {
|
||||||
* @returns {number} response.duration - The number of ms it took to execute the recipe
|
* @returns {number} response.duration - The number of ms it took to execute the recipe
|
||||||
* @returns {number} response.error - The error object thrown by a failed operation (false if no error)
|
* @returns {number} response.error - The error object thrown by a failed operation (false if no error)
|
||||||
*/
|
*/
|
||||||
Chef.prototype.bake = function(input_text, recipe_config, options, progress, step) {
|
Chef.prototype.bake = function (input_text, recipe_config, options, progress, step) {
|
||||||
var start_time = new Date().getTime(),
|
let start_time = new Date().getTime(),
|
||||||
recipe = new Recipe(recipe_config),
|
recipe = new Recipe(recipe_config),
|
||||||
contains_fc = recipe.contains_flow_control(),
|
contains_fc = recipe.contains_flow_control(),
|
||||||
error = false;
|
error = false;
|
||||||
|
|
||||||
// Reset attempt_highlight flag
|
// Reset attempt_highlight flag
|
||||||
if (options.hasOwnProperty("attempt_highlight")) {
|
if (options.hasOwnProperty('attempt_highlight')) {
|
||||||
options.attempt_highlight = true;
|
options.attempt_highlight = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (contains_fc) options.attempt_highlight = false;
|
if (contains_fc) options.attempt_highlight = false;
|
||||||
|
|
||||||
// Clean up progress
|
// Clean up progress
|
||||||
if (progress >= recipe_config.length) {
|
if (progress >= recipe_config.length) {
|
||||||
progress = 0;
|
progress = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (step) {
|
if (step) {
|
||||||
// Unset breakpoint on this step
|
// Unset breakpoint on this step
|
||||||
recipe.set_breakpoint(progress, false);
|
recipe.set_breakpoint(progress, false);
|
||||||
// Set breakpoint on next step
|
// Set breakpoint on next step
|
||||||
recipe.set_breakpoint(progress + 1, true);
|
recipe.set_breakpoint(progress + 1, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
// If stepping with flow control, we have to start from the beginning
|
// If stepping with flow control, we have to start from the beginning
|
||||||
// but still want to skip all previous breakpoints
|
// but still want to skip all previous breakpoints
|
||||||
if (progress > 0 && contains_fc) {
|
if (progress > 0 && contains_fc) {
|
||||||
recipe.remove_breaks_up_to(progress);
|
recipe.remove_breaks_up_to(progress);
|
||||||
progress = 0;
|
progress = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If starting from scratch, load data
|
// If starting from scratch, load data
|
||||||
if (progress === 0) {
|
if (progress === 0) {
|
||||||
this.dish.set(input_text, Dish.STRING);
|
this.dish.set(input_text, Dish.STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
progress = recipe.execute(this.dish, progress);
|
progress = recipe.execute(this.dish, progress);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// We can't throw the error from here as we will return in the finally block and ignore it
|
// We can't throw the error from here as we will return in the finally block and ignore it
|
||||||
// so we return the error in the result instead.
|
// so we return the error in the result instead.
|
||||||
error = err;
|
error = err;
|
||||||
progress = err.progress;
|
progress = err.progress;
|
||||||
} finally {
|
} finally {
|
||||||
return {
|
return {
|
||||||
result: this.dish.type == Dish.HTML ?
|
result: this.dish.type == Dish.HTML ?
|
||||||
this.dish.get(Dish.HTML) :
|
this.dish.get(Dish.HTML) :
|
||||||
this.dish.get(Dish.STRING),
|
this.dish.get(Dish.STRING),
|
||||||
type: Dish.enum_lookup(this.dish.type),
|
type: Dish.enum_lookup(this.dish.type),
|
||||||
progress: progress,
|
progress,
|
||||||
options: options,
|
options,
|
||||||
duration: new Date().getTime() - start_time,
|
duration: new Date().getTime() - start_time,
|
||||||
error: error
|
error,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -106,15 +106,15 @@ Chef.prototype.bake = function(input_text, recipe_config, options, progress, ste
|
||||||
* @param {Object[]} recipe_config - The recipe configuration object
|
* @param {Object[]} recipe_config - The recipe configuration object
|
||||||
* @returns {number} The time it took to run the silent bake in milliseconds.
|
* @returns {number} The time it took to run the silent bake in milliseconds.
|
||||||
*/
|
*/
|
||||||
Chef.prototype.silent_bake = function(recipe_config) {
|
Chef.prototype.silent_bake = function (recipe_config) {
|
||||||
var start_time = new Date().getTime(),
|
let start_time = new Date().getTime(),
|
||||||
recipe = new Recipe(recipe_config),
|
recipe = new Recipe(recipe_config),
|
||||||
dish = new Dish("", Dish.STRING);
|
dish = new Dish('', Dish.STRING);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
recipe.execute(dish);
|
recipe.execute(dish);
|
||||||
} catch(err) {
|
} catch (err) {
|
||||||
// Suppress all errors
|
// Suppress all errors
|
||||||
}
|
}
|
||||||
return new Date().getTime() - start_time;
|
return new Date().getTime() - start_time;
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,9 +9,9 @@
|
||||||
* @param {byte_array|string|number} value - The value of the input data.
|
* @param {byte_array|string|number} value - The value of the input data.
|
||||||
* @param {number} type - The data type of value, see Dish enums.
|
* @param {number} type - The data type of value, see Dish enums.
|
||||||
*/
|
*/
|
||||||
var Dish = function(value, type) {
|
const Dish = function (value, type) {
|
||||||
this.value = value || typeof value == "string" ? value : null;
|
this.value = value || typeof value === 'string' ? value : null;
|
||||||
this.type = type || Dish.BYTE_ARRAY;
|
this.type = type || Dish.BYTE_ARRAY;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -48,23 +48,23 @@ Dish.HTML = 3;
|
||||||
* @param {string} type_str - The name of the data type.
|
* @param {string} type_str - The name of the data type.
|
||||||
* @returns {number} The data type enum value.
|
* @returns {number} The data type enum value.
|
||||||
*/
|
*/
|
||||||
Dish.type_enum = function(type_str) {
|
Dish.type_enum = function (type_str) {
|
||||||
switch (type_str) {
|
switch (type_str) {
|
||||||
case "byte_array":
|
case 'byte_array':
|
||||||
case "Byte array":
|
case 'Byte array':
|
||||||
return Dish.BYTE_ARRAY;
|
return Dish.BYTE_ARRAY;
|
||||||
case "string":
|
case 'string':
|
||||||
case "String":
|
case 'String':
|
||||||
return Dish.STRING;
|
return Dish.STRING;
|
||||||
case "number":
|
case 'number':
|
||||||
case "Number":
|
case 'Number':
|
||||||
return Dish.NUMBER;
|
return Dish.NUMBER;
|
||||||
case "html":
|
case 'html':
|
||||||
case "HTML":
|
case 'HTML':
|
||||||
return Dish.HTML;
|
return Dish.HTML;
|
||||||
default:
|
default:
|
||||||
throw "Invalid data type string. No matching enum.";
|
throw 'Invalid data type string. No matching enum.';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -75,19 +75,19 @@ Dish.type_enum = function(type_str) {
|
||||||
* @param {string} type_enum - The enum value of the data type.
|
* @param {string} type_enum - The enum value of the data type.
|
||||||
* @returns {number} The data type as a string.
|
* @returns {number} The data type as a string.
|
||||||
*/
|
*/
|
||||||
Dish.enum_lookup = function(type_enum) {
|
Dish.enum_lookup = function (type_enum) {
|
||||||
switch (type_enum) {
|
switch (type_enum) {
|
||||||
case Dish.BYTE_ARRAY:
|
case Dish.BYTE_ARRAY:
|
||||||
return "byte_array";
|
return 'byte_array';
|
||||||
case Dish.STRING:
|
case Dish.STRING:
|
||||||
return "string";
|
return 'string';
|
||||||
case Dish.NUMBER:
|
case Dish.NUMBER:
|
||||||
return "number";
|
return 'number';
|
||||||
case Dish.HTML:
|
case Dish.HTML:
|
||||||
return "html";
|
return 'html';
|
||||||
default:
|
default:
|
||||||
throw "Invalid data type enum. No matching type.";
|
throw 'Invalid data type enum. No matching type.';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,14 +97,14 @@ Dish.enum_lookup = function(type_enum) {
|
||||||
* @param {byte_array|string|number} value - The value of the input data.
|
* @param {byte_array|string|number} value - The value of the input data.
|
||||||
* @param {number} type - The data type of value, see Dish enums.
|
* @param {number} type - The data type of value, see Dish enums.
|
||||||
*/
|
*/
|
||||||
Dish.prototype.set = function(value, type) {
|
Dish.prototype.set = function (value, type) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
|
||||||
if (!this.valid()) {
|
if (!this.valid()) {
|
||||||
var sample = Utils.truncate(JSON.stringify(this.value), 13);
|
const sample = Utils.truncate(JSON.stringify(this.value), 13);
|
||||||
throw "Data is not a valid " + Dish.enum_lookup(type) + ": " + sample;
|
throw `Data is not a valid ${Dish.enum_lookup(type)}: ${sample}`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,11 +114,11 @@ Dish.prototype.set = function(value, type) {
|
||||||
* @param {number} type - The data type of value, see Dish enums.
|
* @param {number} type - The data type of value, see Dish enums.
|
||||||
* @returns {byte_array|string|number} The value of the output data.
|
* @returns {byte_array|string|number} The value of the output data.
|
||||||
*/
|
*/
|
||||||
Dish.prototype.get = function(type) {
|
Dish.prototype.get = function (type) {
|
||||||
if (this.type != type) {
|
if (this.type != type) {
|
||||||
this.translate(type);
|
this.translate(type);
|
||||||
}
|
}
|
||||||
return this.value;
|
return this.value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -127,39 +127,39 @@ Dish.prototype.get = function(type) {
|
||||||
*
|
*
|
||||||
* @param {number} to_type - The data type of value, see Dish enums.
|
* @param {number} to_type - The data type of value, see Dish enums.
|
||||||
*/
|
*/
|
||||||
Dish.prototype.translate = function(to_type) {
|
Dish.prototype.translate = function (to_type) {
|
||||||
// Convert data to intermediate byte_array type
|
// Convert data to intermediate byte_array type
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
case Dish.STRING:
|
case Dish.STRING:
|
||||||
this.value = this.value ? Utils.str_to_byte_array(this.value) : [];
|
this.value = this.value ? Utils.str_to_byte_array(this.value) : [];
|
||||||
this.type = Dish.BYTE_ARRAY;
|
this.type = Dish.BYTE_ARRAY;
|
||||||
break;
|
break;
|
||||||
case Dish.NUMBER:
|
case Dish.NUMBER:
|
||||||
this.value = typeof this.value == "number" ? Utils.str_to_byte_array(this.value.toString()) : [];
|
this.value = typeof this.value === 'number' ? Utils.str_to_byte_array(this.value.toString()) : [];
|
||||||
this.type = Dish.BYTE_ARRAY;
|
this.type = Dish.BYTE_ARRAY;
|
||||||
break;
|
break;
|
||||||
case Dish.HTML:
|
case Dish.HTML:
|
||||||
this.value = this.value ? Utils.str_to_byte_array(Utils.strip_html_tags(this.value, true)) : [];
|
this.value = this.value ? Utils.str_to_byte_array(Utils.strip_html_tags(this.value, true)) : [];
|
||||||
this.type = Dish.BYTE_ARRAY;
|
this.type = Dish.BYTE_ARRAY;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert from byte_array to to_type
|
// Convert from byte_array to to_type
|
||||||
switch (to_type) {
|
switch (to_type) {
|
||||||
case Dish.STRING:
|
case Dish.STRING:
|
||||||
case Dish.HTML:
|
case Dish.HTML:
|
||||||
this.value = this.value ? Utils.byte_array_to_utf8(this.value) : "";
|
this.value = this.value ? Utils.byte_array_to_utf8(this.value) : '';
|
||||||
this.type = Dish.STRING;
|
this.type = Dish.STRING;
|
||||||
break;
|
break;
|
||||||
case Dish.NUMBER:
|
case Dish.NUMBER:
|
||||||
this.value = this.value ? parseFloat(Utils.byte_array_to_utf8(this.value)) : 0;
|
this.value = this.value ? parseFloat(Utils.byte_array_to_utf8(this.value)) : 0;
|
||||||
this.type = Dish.NUMBER;
|
this.type = Dish.NUMBER;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -169,34 +169,34 @@ Dish.prototype.translate = function(to_type) {
|
||||||
*
|
*
|
||||||
* @returns {boolean} Whether the data is valid or not.
|
* @returns {boolean} Whether the data is valid or not.
|
||||||
*/
|
*/
|
||||||
Dish.prototype.valid = function() {
|
Dish.prototype.valid = function () {
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
case Dish.BYTE_ARRAY:
|
case Dish.BYTE_ARRAY:
|
||||||
if (!(this.value instanceof Array)) {
|
if (!(this.value instanceof Array)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that every value is a number between 0 - 255
|
// Check that every value is a number between 0 - 255
|
||||||
for (var i = 0; i < this.value.length; i++) {
|
for (let i = 0; i < this.value.length; i++) {
|
||||||
if (typeof this.value[i] != "number" ||
|
if (typeof this.value[i] !== 'number' ||
|
||||||
this.value[i] < 0 ||
|
this.value[i] < 0 ||
|
||||||
this.value[i] > 255) {
|
this.value[i] > 255) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case Dish.STRING:
|
case Dish.STRING:
|
||||||
case Dish.HTML:
|
case Dish.HTML:
|
||||||
if (typeof this.value == "string") {
|
if (typeof this.value === 'string') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
case Dish.NUMBER:
|
case Dish.NUMBER:
|
||||||
if (typeof this.value == "number") {
|
if (typeof this.value === 'number') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,18 +7,18 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var FlowControl = {
|
const FlowControl = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
FORK_DELIM: "\\n",
|
FORK_DELIM: '\\n',
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
MERGE_DELIM: "\\n",
|
MERGE_DELIM: '\\n',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fork operation.
|
* Fork operation.
|
||||||
|
@ -29,47 +29,48 @@ var FlowControl = {
|
||||||
* @param {Operation[]} state.op_list - The list of operations in the recipe.
|
* @param {Operation[]} state.op_list - The list of operations in the recipe.
|
||||||
* @returns {Object} The updated state of the recipe.
|
* @returns {Object} The updated state of the recipe.
|
||||||
*/
|
*/
|
||||||
run_fork: function(state) {
|
run_fork(state) {
|
||||||
var op_list = state.op_list,
|
let op_list = state.op_list,
|
||||||
input_type = op_list[state.progress].input_type,
|
input_type = op_list[state.progress].input_type,
|
||||||
output_type = op_list[state.progress].output_type,
|
output_type = op_list[state.progress].output_type,
|
||||||
input = state.dish.get(input_type),
|
input = state.dish.get(input_type),
|
||||||
ings = op_list[state.progress].get_ing_values(),
|
ings = op_list[state.progress].get_ing_values(),
|
||||||
split_delim = ings[0],
|
split_delim = ings[0],
|
||||||
merge_delim = ings[1],
|
merge_delim = ings[1],
|
||||||
sub_op_list = [],
|
sub_op_list = [],
|
||||||
inputs = [];
|
inputs = [];
|
||||||
|
|
||||||
if (input)
|
if (input) {
|
||||||
inputs = input.split(split_delim);
|
inputs = input.split(split_delim);
|
||||||
|
}
|
||||||
|
|
||||||
// Create sub_op_list for each tranche to operate on
|
// Create sub_op_list for each tranche to operate on
|
||||||
// (all remaining operations unless we encounter a Merge)
|
// (all remaining operations unless we encounter a Merge)
|
||||||
for (var i = state.progress + 1; i < op_list.length; i++) {
|
for (var i = state.progress + 1; i < op_list.length; i++) {
|
||||||
if (op_list[i].name == "Merge" && !op_list[i].is_disabled()) {
|
if (op_list[i].name == 'Merge' && !op_list[i].is_disabled()) {
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
sub_op_list.push(op_list[i]);
|
sub_op_list.push(op_list[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var recipe = new Recipe(),
|
let recipe = new Recipe(),
|
||||||
output = "",
|
output = '',
|
||||||
progress;
|
progress;
|
||||||
|
|
||||||
recipe.add_operations(sub_op_list);
|
recipe.add_operations(sub_op_list);
|
||||||
|
|
||||||
// Run recipe over each tranche
|
// Run recipe over each tranche
|
||||||
for (i = 0; i < inputs.length; i++) {
|
for (i = 0; i < inputs.length; i++) {
|
||||||
var dish = new Dish(inputs[i], input_type);
|
const dish = new Dish(inputs[i], input_type);
|
||||||
progress = recipe.execute(dish, 0);
|
progress = recipe.execute(dish, 0);
|
||||||
output += dish.get(output_type) + merge_delim;
|
output += dish.get(output_type) + merge_delim;
|
||||||
}
|
}
|
||||||
|
|
||||||
state.dish.set(output, output_type);
|
state.dish.set(output, output_type);
|
||||||
state.progress += progress;
|
state.progress += progress;
|
||||||
return state;
|
return state;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -81,23 +82,23 @@ var FlowControl = {
|
||||||
* @param {Operation[]} state.op_list - The list of operations in the recipe.
|
* @param {Operation[]} state.op_list - The list of operations in the recipe.
|
||||||
* @returns {Object} The updated state of the recipe.
|
* @returns {Object} The updated state of the recipe.
|
||||||
*/
|
*/
|
||||||
run_merge: function(state) {
|
run_merge(state) {
|
||||||
// No need to actually do anything here. The fork operation will
|
// No need to actually do anything here. The fork operation will
|
||||||
// merge when it sees this operation.
|
// merge when it sees this operation.
|
||||||
return state;
|
return state;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
JUMP_NUM: 0,
|
JUMP_NUM: 0,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
MAX_JUMPS: 10,
|
MAX_JUMPS: 10,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Jump operation.
|
* Jump operation.
|
||||||
|
@ -109,19 +110,19 @@ var FlowControl = {
|
||||||
* @param {number} state.num_jumps - The number of jumps taken so far.
|
* @param {number} state.num_jumps - The number of jumps taken so far.
|
||||||
* @returns {Object} The updated state of the recipe.
|
* @returns {Object} The updated state of the recipe.
|
||||||
*/
|
*/
|
||||||
run_jump: function(state) {
|
run_jump(state) {
|
||||||
var ings = state.op_list[state.progress].get_ing_values(),
|
let ings = state.op_list[state.progress].get_ing_values(),
|
||||||
jump_num = ings[0],
|
jump_num = ings[0],
|
||||||
max_jumps = ings[1];
|
max_jumps = ings[1];
|
||||||
|
|
||||||
if (state.num_jumps >= max_jumps) {
|
if (state.num_jumps >= max_jumps) {
|
||||||
throw "Reached maximum jumps, sorry!";
|
throw 'Reached maximum jumps, sorry!';
|
||||||
}
|
}
|
||||||
|
|
||||||
state.progress += jump_num;
|
state.progress += jump_num;
|
||||||
state.num_jumps++;
|
state.num_jumps++;
|
||||||
return state;
|
return state;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -134,24 +135,24 @@ var FlowControl = {
|
||||||
* @param {number} state.num_jumps - The number of jumps taken so far.
|
* @param {number} state.num_jumps - The number of jumps taken so far.
|
||||||
* @returns {Object} The updated state of the recipe.
|
* @returns {Object} The updated state of the recipe.
|
||||||
*/
|
*/
|
||||||
run_cond_jump: function(state) {
|
run_cond_jump(state) {
|
||||||
var ings = state.op_list[state.progress].get_ing_values(),
|
let ings = state.op_list[state.progress].get_ing_values(),
|
||||||
dish = state.dish,
|
dish = state.dish,
|
||||||
regex_str = ings[0],
|
regex_str = ings[0],
|
||||||
jump_num = ings[1],
|
jump_num = ings[1],
|
||||||
max_jumps = ings[2];
|
max_jumps = ings[2];
|
||||||
|
|
||||||
if (state.num_jumps >= max_jumps) {
|
if (state.num_jumps >= max_jumps) {
|
||||||
throw "Reached maximum jumps, sorry!";
|
throw 'Reached maximum jumps, sorry!';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (regex_str !== "" && dish.get(Dish.STRING).search(regex_str) > -1) {
|
if (regex_str !== '' && dish.get(Dish.STRING).search(regex_str) > -1) {
|
||||||
state.progress += jump_num;
|
state.progress += jump_num;
|
||||||
state.num_jumps++;
|
state.num_jumps++;
|
||||||
}
|
}
|
||||||
|
|
||||||
return state;
|
return state;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,9 +164,9 @@ var FlowControl = {
|
||||||
* @param {Operation[]} state.op_list - The list of operations in the recipe.
|
* @param {Operation[]} state.op_list - The list of operations in the recipe.
|
||||||
* @returns {Object} The updated state of the recipe.
|
* @returns {Object} The updated state of the recipe.
|
||||||
*/
|
*/
|
||||||
run_return: function(state) {
|
run_return(state) {
|
||||||
state.progress = state.op_list.length;
|
state.progress = state.op_list.length;
|
||||||
return state;
|
return state;
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,14 +8,14 @@
|
||||||
* @class
|
* @class
|
||||||
* @param {Object} ingredient_config
|
* @param {Object} ingredient_config
|
||||||
*/
|
*/
|
||||||
var Ingredient = function(ingredient_config) {
|
const Ingredient = function (ingredient_config) {
|
||||||
this.name = "";
|
this.name = '';
|
||||||
this.type = "";
|
this.type = '';
|
||||||
this.value = null;
|
this.value = null;
|
||||||
|
|
||||||
if (ingredient_config) {
|
if (ingredient_config) {
|
||||||
this._parse_config(ingredient_config);
|
this._parse_config(ingredient_config);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -25,9 +25,9 @@ var Ingredient = function(ingredient_config) {
|
||||||
* @private
|
* @private
|
||||||
* @param {Object} ingredient_config
|
* @param {Object} ingredient_config
|
||||||
*/
|
*/
|
||||||
Ingredient.prototype._parse_config = function(ingredient_config) {
|
Ingredient.prototype._parse_config = function (ingredient_config) {
|
||||||
this.name = ingredient_config.name;
|
this.name = ingredient_config.name;
|
||||||
this.type = ingredient_config.type;
|
this.type = ingredient_config.type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -36,8 +36,8 @@ Ingredient.prototype._parse_config = function(ingredient_config) {
|
||||||
*
|
*
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
Ingredient.prototype.get_config = function() {
|
Ingredient.prototype.get_config = function () {
|
||||||
return this.value;
|
return this.value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -46,8 +46,8 @@ Ingredient.prototype.get_config = function() {
|
||||||
*
|
*
|
||||||
* @param {*} value
|
* @param {*} value
|
||||||
*/
|
*/
|
||||||
Ingredient.prototype.set_value = function(value) {
|
Ingredient.prototype.set_value = function (value) {
|
||||||
this.value = Ingredient.prepare(value, this.type);
|
this.value = Ingredient.prepare(value, this.type);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,28 +59,28 @@ Ingredient.prototype.set_value = function(value) {
|
||||||
* @param {*} data
|
* @param {*} data
|
||||||
* @param {string} type - The name of the data type.
|
* @param {string} type - The name of the data type.
|
||||||
*/
|
*/
|
||||||
Ingredient.prepare = function(data, type) {
|
Ingredient.prepare = function (data, type) {
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case "binary_string":
|
case 'binary_string':
|
||||||
case "binary_short_string":
|
case 'binary_short_string':
|
||||||
case "editable_option":
|
case 'editable_option':
|
||||||
return Utils.parse_escaped_chars(data);
|
return Utils.parse_escaped_chars(data);
|
||||||
case "byte_array":
|
case 'byte_array':
|
||||||
if (typeof data == "string") {
|
if (typeof data === 'string') {
|
||||||
data = data.replace(/\s+/g, '');
|
data = data.replace(/\s+/g, '');
|
||||||
return Utils.hex_to_byte_array(data);
|
return Utils.hex_to_byte_array(data);
|
||||||
} else {
|
} else {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "number":
|
case 'number':
|
||||||
var number = parseFloat(data);
|
var number = parseFloat(data);
|
||||||
if (isNaN(number)) {
|
if (isNaN(number)) {
|
||||||
var sample = Utils.truncate(data.toString(), 10);
|
const sample = Utils.truncate(data.toString(), 10);
|
||||||
throw "Invalid ingredient value. Not a number: " + sample;
|
throw `Invalid ingredient value. Not a number: ${sample}`;
|
||||||
}
|
}
|
||||||
return number;
|
return number;
|
||||||
default:
|
default:
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,21 +9,21 @@
|
||||||
* @param {string} operation_name
|
* @param {string} operation_name
|
||||||
* @param {Object} operation_config
|
* @param {Object} operation_config
|
||||||
*/
|
*/
|
||||||
var Operation = function(operation_name, operation_config) {
|
const Operation = function (operation_name, operation_config) {
|
||||||
this.name = operation_name;
|
this.name = operation_name;
|
||||||
this.description = "";
|
this.description = '';
|
||||||
this.input_type = -1;
|
this.input_type = -1;
|
||||||
this.output_type = -1;
|
this.output_type = -1;
|
||||||
this.run = null;
|
this.run = null;
|
||||||
this.highlight = null;
|
this.highlight = null;
|
||||||
this.highlight_reverse = null;
|
this.highlight_reverse = null;
|
||||||
this.breakpoint = false;
|
this.breakpoint = false;
|
||||||
this.disabled = false;
|
this.disabled = false;
|
||||||
this.ing_list = [];
|
this.ing_list = [];
|
||||||
|
|
||||||
if (operation_config) {
|
if (operation_config) {
|
||||||
this._parse_config(operation_config);
|
this._parse_config(operation_config);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -33,20 +33,20 @@ var Operation = function(operation_name, operation_config) {
|
||||||
* @private
|
* @private
|
||||||
* @param {Object} operation_config
|
* @param {Object} operation_config
|
||||||
*/
|
*/
|
||||||
Operation.prototype._parse_config = function(operation_config) {
|
Operation.prototype._parse_config = function (operation_config) {
|
||||||
this.description = operation_config.description;
|
this.description = operation_config.description;
|
||||||
this.input_type = Dish.type_enum(operation_config.input_type);
|
this.input_type = Dish.type_enum(operation_config.input_type);
|
||||||
this.output_type = Dish.type_enum(operation_config.output_type);
|
this.output_type = Dish.type_enum(operation_config.output_type);
|
||||||
this.run = operation_config.run;
|
this.run = operation_config.run;
|
||||||
this.highlight = operation_config.highlight;
|
this.highlight = operation_config.highlight;
|
||||||
this.highlight_reverse = operation_config.highlight_reverse;
|
this.highlight_reverse = operation_config.highlight_reverse;
|
||||||
this.flow_control = operation_config.flow_control;
|
this.flow_control = operation_config.flow_control;
|
||||||
|
|
||||||
for (var a = 0; a < operation_config.args.length; a++) {
|
for (let a = 0; a < operation_config.args.length; a++) {
|
||||||
var ingredient_config = operation_config.args[a];
|
const ingredient_config = operation_config.args[a];
|
||||||
var ingredient = new Ingredient(ingredient_config);
|
const ingredient = new Ingredient(ingredient_config);
|
||||||
this.add_ingredient(ingredient);
|
this.add_ingredient(ingredient);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -55,19 +55,19 @@ Operation.prototype._parse_config = function(operation_config) {
|
||||||
*
|
*
|
||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
*/
|
*/
|
||||||
Operation.prototype.get_config = function() {
|
Operation.prototype.get_config = function () {
|
||||||
var ingredient_config = [];
|
const ingredient_config = [];
|
||||||
|
|
||||||
for (var o = 0; o < this.ing_list.length; o++) {
|
for (let o = 0; o < this.ing_list.length; o++) {
|
||||||
ingredient_config.push(this.ing_list[o].get_config());
|
ingredient_config.push(this.ing_list[o].get_config());
|
||||||
}
|
}
|
||||||
|
|
||||||
var operation_config = {
|
const operation_config = {
|
||||||
"op": this.name,
|
op: this.name,
|
||||||
"args": ingredient_config
|
args: ingredient_config,
|
||||||
};
|
};
|
||||||
|
|
||||||
return operation_config;
|
return operation_config;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,8 +76,8 @@ Operation.prototype.get_config = function() {
|
||||||
*
|
*
|
||||||
* @param {Ingredient} ingredient
|
* @param {Ingredient} ingredient
|
||||||
*/
|
*/
|
||||||
Operation.prototype.add_ingredient = function(ingredient) {
|
Operation.prototype.add_ingredient = function (ingredient) {
|
||||||
this.ing_list.push(ingredient);
|
this.ing_list.push(ingredient);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -86,10 +86,10 @@ Operation.prototype.add_ingredient = function(ingredient) {
|
||||||
*
|
*
|
||||||
* @param {Object[]} ing_values
|
* @param {Object[]} ing_values
|
||||||
*/
|
*/
|
||||||
Operation.prototype.set_ing_values = function(ing_values) {
|
Operation.prototype.set_ing_values = function (ing_values) {
|
||||||
for (var i = 0; i < ing_values.length; i++) {
|
for (let i = 0; i < ing_values.length; i++) {
|
||||||
this.ing_list[i].set_value(ing_values[i]);
|
this.ing_list[i].set_value(ing_values[i]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,12 +98,12 @@ Operation.prototype.set_ing_values = function(ing_values) {
|
||||||
*
|
*
|
||||||
* @returns {Object[]}
|
* @returns {Object[]}
|
||||||
*/
|
*/
|
||||||
Operation.prototype.get_ing_values = function() {
|
Operation.prototype.get_ing_values = function () {
|
||||||
var ing_values = [];
|
const ing_values = [];
|
||||||
for (var i = 0; i < this.ing_list.length; i++) {
|
for (let i = 0; i < this.ing_list.length; i++) {
|
||||||
ing_values.push(this.ing_list[i].value);
|
ing_values.push(this.ing_list[i].value);
|
||||||
}
|
}
|
||||||
return ing_values;
|
return ing_values;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -112,8 +112,8 @@ Operation.prototype.get_ing_values = function() {
|
||||||
*
|
*
|
||||||
* @param {boolean} value
|
* @param {boolean} value
|
||||||
*/
|
*/
|
||||||
Operation.prototype.set_breakpoint = function(value) {
|
Operation.prototype.set_breakpoint = function (value) {
|
||||||
this.breakpoint = !!value;
|
this.breakpoint = !!value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -122,8 +122,8 @@ Operation.prototype.set_breakpoint = function(value) {
|
||||||
*
|
*
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
Operation.prototype.is_breakpoint = function() {
|
Operation.prototype.is_breakpoint = function () {
|
||||||
return this.breakpoint;
|
return this.breakpoint;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -132,8 +132,8 @@ Operation.prototype.is_breakpoint = function() {
|
||||||
*
|
*
|
||||||
* @param {boolean} value
|
* @param {boolean} value
|
||||||
*/
|
*/
|
||||||
Operation.prototype.set_disabled = function(value) {
|
Operation.prototype.set_disabled = function (value) {
|
||||||
this.disabled = !!value;
|
this.disabled = !!value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -142,8 +142,8 @@ Operation.prototype.set_disabled = function(value) {
|
||||||
*
|
*
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
Operation.prototype.is_disabled = function() {
|
Operation.prototype.is_disabled = function () {
|
||||||
return this.disabled;
|
return this.disabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -152,6 +152,6 @@ Operation.prototype.is_disabled = function() {
|
||||||
*
|
*
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
Operation.prototype.is_flow_control = function() {
|
Operation.prototype.is_flow_control = function () {
|
||||||
return this.flow_control;
|
return this.flow_control;
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,12 +8,12 @@
|
||||||
* @class
|
* @class
|
||||||
* @param {Object} recipe_config
|
* @param {Object} recipe_config
|
||||||
*/
|
*/
|
||||||
var Recipe = function(recipe_config) {
|
const Recipe = function (recipe_config) {
|
||||||
this.op_list = [];
|
this.op_list = [];
|
||||||
|
|
||||||
if (recipe_config) {
|
if (recipe_config) {
|
||||||
this._parse_config(recipe_config);
|
this._parse_config(recipe_config);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -23,16 +23,16 @@ var Recipe = function(recipe_config) {
|
||||||
* @private
|
* @private
|
||||||
* @param {Object} recipe_config
|
* @param {Object} recipe_config
|
||||||
*/
|
*/
|
||||||
Recipe.prototype._parse_config = function(recipe_config) {
|
Recipe.prototype._parse_config = function (recipe_config) {
|
||||||
for (var c = 0; c < recipe_config.length; c++) {
|
for (let c = 0; c < recipe_config.length; c++) {
|
||||||
var operation_name = recipe_config[c].op;
|
const operation_name = recipe_config[c].op;
|
||||||
var operation_config = OperationConfig[operation_name];
|
const operation_config = OperationConfig[operation_name];
|
||||||
var operation = new Operation(operation_name, operation_config);
|
const operation = new Operation(operation_name, operation_config);
|
||||||
operation.set_ing_values(recipe_config[c].args);
|
operation.set_ing_values(recipe_config[c].args);
|
||||||
operation.set_breakpoint(recipe_config[c].breakpoint);
|
operation.set_breakpoint(recipe_config[c].breakpoint);
|
||||||
operation.set_disabled(recipe_config[c].disabled);
|
operation.set_disabled(recipe_config[c].disabled);
|
||||||
this.add_operation(operation);
|
this.add_operation(operation);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -41,14 +41,14 @@ Recipe.prototype._parse_config = function(recipe_config) {
|
||||||
*
|
*
|
||||||
* @returns {*}
|
* @returns {*}
|
||||||
*/
|
*/
|
||||||
Recipe.prototype.get_config = function() {
|
Recipe.prototype.get_config = function () {
|
||||||
var recipe_config = [];
|
const recipe_config = [];
|
||||||
|
|
||||||
for (var o = 0; o < this.op_list.length; o++) {
|
for (let o = 0; o < this.op_list.length; o++) {
|
||||||
recipe_config.push(this.op_list[o].get_config());
|
recipe_config.push(this.op_list[o].get_config());
|
||||||
}
|
}
|
||||||
|
|
||||||
return recipe_config;
|
return recipe_config;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,8 +57,8 @@ Recipe.prototype.get_config = function() {
|
||||||
*
|
*
|
||||||
* @param {Operation} operation
|
* @param {Operation} operation
|
||||||
*/
|
*/
|
||||||
Recipe.prototype.add_operation = function(operation) {
|
Recipe.prototype.add_operation = function (operation) {
|
||||||
this.op_list.push(operation);
|
this.op_list.push(operation);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,8 +67,8 @@ Recipe.prototype.add_operation = function(operation) {
|
||||||
*
|
*
|
||||||
* @param {Operation[]} operations
|
* @param {Operation[]} operations
|
||||||
*/
|
*/
|
||||||
Recipe.prototype.add_operations = function(operations) {
|
Recipe.prototype.add_operations = function (operations) {
|
||||||
this.op_list = this.op_list.concat(operations);
|
this.op_list = this.op_list.concat(operations);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,12 +78,12 @@ Recipe.prototype.add_operations = function(operations) {
|
||||||
* @param {number} position - The index of the Operation
|
* @param {number} position - The index of the Operation
|
||||||
* @param {boolean} value
|
* @param {boolean} value
|
||||||
*/
|
*/
|
||||||
Recipe.prototype.set_breakpoint = function(position, value) {
|
Recipe.prototype.set_breakpoint = function (position, value) {
|
||||||
try {
|
try {
|
||||||
this.op_list[position].set_breakpoint(value);
|
this.op_list[position].set_breakpoint(value);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
// Ignore index error
|
// Ignore index error
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,10 +93,10 @@ Recipe.prototype.set_breakpoint = function(position, value) {
|
||||||
*
|
*
|
||||||
* @param {number} pos
|
* @param {number} pos
|
||||||
*/
|
*/
|
||||||
Recipe.prototype.remove_breaks_up_to = function(pos) {
|
Recipe.prototype.remove_breaks_up_to = function (pos) {
|
||||||
for (var i = 0; i < pos; i++) {
|
for (let i = 0; i < pos; i++) {
|
||||||
this.op_list[i].set_breakpoint(false);
|
this.op_list[i].set_breakpoint(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -105,11 +105,11 @@ Recipe.prototype.remove_breaks_up_to = function(pos) {
|
||||||
*
|
*
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
Recipe.prototype.contains_flow_control = function() {
|
Recipe.prototype.contains_flow_control = function () {
|
||||||
for (var i = 0; i < this.op_list.length; i++) {
|
for (let i = 0; i < this.op_list.length; i++) {
|
||||||
if (this.op_list[i].is_flow_control()) return true;
|
if (this.op_list[i].is_flow_control()) return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -120,17 +120,17 @@ Recipe.prototype.contains_flow_control = function() {
|
||||||
* @param {number} [start_index=0] - The index to start searching from
|
* @param {number} [start_index=0] - The index to start searching from
|
||||||
* @returns (number}
|
* @returns (number}
|
||||||
*/
|
*/
|
||||||
Recipe.prototype.last_op_index = function(start_index) {
|
Recipe.prototype.last_op_index = function (start_index) {
|
||||||
var i = start_index + 1 || 0,
|
let i = start_index + 1 || 0,
|
||||||
op;
|
op;
|
||||||
|
|
||||||
for (; i < this.op_list.length; i++) {
|
for (; i < this.op_list.length; i++) {
|
||||||
op = this.op_list[i];
|
op = this.op_list[i];
|
||||||
if (op.is_disabled()) return i-1;
|
if (op.is_disabled()) return i - 1;
|
||||||
if (op.is_breakpoint()) return i-1;
|
if (op.is_breakpoint()) return i - 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return i-1;
|
return i - 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -141,56 +141,59 @@ Recipe.prototype.last_op_index = function(start_index) {
|
||||||
* @param {number} [start_from=0] - The index of the Operation to start executing from
|
* @param {number} [start_from=0] - The index of the Operation to start executing from
|
||||||
* @returns {number} - The final progress through the recipe
|
* @returns {number} - The final progress through the recipe
|
||||||
*/
|
*/
|
||||||
Recipe.prototype.execute = function(dish, start_from) {
|
Recipe.prototype.execute = function (dish, start_from) {
|
||||||
start_from = start_from || 0;
|
start_from = start_from || 0;
|
||||||
var op, input, output, num_jumps = 0;
|
let op,
|
||||||
|
input,
|
||||||
|
output,
|
||||||
|
num_jumps = 0;
|
||||||
|
|
||||||
for (var i = start_from; i < this.op_list.length; i++) {
|
for (let i = start_from; i < this.op_list.length; i++) {
|
||||||
op = this.op_list[i];
|
op = this.op_list[i];
|
||||||
if (op.is_disabled()) {
|
if (op.is_disabled()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (op.is_breakpoint()) {
|
if (op.is_breakpoint()) {
|
||||||
return i;
|
return i;
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
input = dish.get(op.input_type);
|
|
||||||
|
|
||||||
if (op.is_flow_control()) {
|
|
||||||
// Package up the current state
|
|
||||||
var state = {
|
|
||||||
"progress" : i,
|
|
||||||
"dish" : dish,
|
|
||||||
"op_list" : this.op_list,
|
|
||||||
"num_jumps" : num_jumps
|
|
||||||
};
|
|
||||||
|
|
||||||
state = op.run(state);
|
|
||||||
i = state.progress;
|
|
||||||
num_jumps = state.num_jumps;
|
|
||||||
} else {
|
|
||||||
output = op.run(input, op.get_ing_values());
|
|
||||||
dish.set(output, op.output_type);
|
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
var e = typeof err == "string" ? { message: err } : err;
|
|
||||||
|
|
||||||
e.progress = i;
|
|
||||||
e.display_str = op.name + " - ";
|
|
||||||
if (e.fileName) {
|
|
||||||
e.display_str += e.name + " in " + e.fileName +
|
|
||||||
" on line " + e.lineNumber +
|
|
||||||
".<br><br>Message: " + e.message;
|
|
||||||
} else {
|
|
||||||
e.display_str += e.message;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.op_list.length;
|
try {
|
||||||
|
input = dish.get(op.input_type);
|
||||||
|
|
||||||
|
if (op.is_flow_control()) {
|
||||||
|
// Package up the current state
|
||||||
|
let state = {
|
||||||
|
progress: i,
|
||||||
|
dish,
|
||||||
|
op_list: this.op_list,
|
||||||
|
num_jumps,
|
||||||
|
};
|
||||||
|
|
||||||
|
state = op.run(state);
|
||||||
|
i = state.progress;
|
||||||
|
num_jumps = state.num_jumps;
|
||||||
|
} else {
|
||||||
|
output = op.run(input, op.get_ing_values());
|
||||||
|
dish.set(output, op.output_type);
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
const e = typeof err === 'string' ? { message: err } : err;
|
||||||
|
|
||||||
|
e.progress = i;
|
||||||
|
e.display_str = `${op.name} - `;
|
||||||
|
if (e.fileName) {
|
||||||
|
e.display_str += `${e.name} in ${e.fileName
|
||||||
|
} on line ${e.lineNumber
|
||||||
|
}.<br><br>Message: ${e.message}`;
|
||||||
|
} else {
|
||||||
|
e.display_str += e.message;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.op_list.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -199,8 +202,8 @@ Recipe.prototype.execute = function(dish, start_from) {
|
||||||
*
|
*
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
Recipe.prototype.to_string = function() {
|
Recipe.prototype.to_string = function () {
|
||||||
return JSON.stringify(this.get_config());
|
return JSON.stringify(this.get_config());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -209,7 +212,7 @@ Recipe.prototype.to_string = function() {
|
||||||
*
|
*
|
||||||
* @param {string} recipe_str
|
* @param {string} recipe_str
|
||||||
*/
|
*/
|
||||||
Recipe.prototype.from_string = function(recipe_str) {
|
Recipe.prototype.from_string = function (recipe_str) {
|
||||||
var recipe_config = JSON.parse(recipe_str);
|
const recipe_config = JSON.parse(recipe_str);
|
||||||
this._parse_config(recipe_config);
|
this._parse_config(recipe_config);
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -7,13 +7,13 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var Base = {
|
const Base = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
DEFAULT_RADIX: 36,
|
DEFAULT_RADIX: 36,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To Base operation.
|
* To Base operation.
|
||||||
|
@ -22,16 +22,16 @@ var Base = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_to: function(input, args) {
|
run_to(input, args) {
|
||||||
if (!input) {
|
if (!input) {
|
||||||
throw ("Error: Input must be a number");
|
throw ('Error: Input must be a number');
|
||||||
}
|
}
|
||||||
var radix = args[0] || Base.DEFAULT_RADIX;
|
const radix = args[0] || Base.DEFAULT_RADIX;
|
||||||
if (radix < 2 || radix > 36) {
|
if (radix < 2 || radix > 36) {
|
||||||
throw "Error: Radix argument must be between 2 and 36";
|
throw 'Error: Radix argument must be between 2 and 36';
|
||||||
}
|
}
|
||||||
return input.toString(radix);
|
return input.toString(radix);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,12 +41,12 @@ var Base = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
run_from: function(input, args) {
|
run_from(input, args) {
|
||||||
var radix = args[0] || Base.DEFAULT_RADIX;
|
const radix = args[0] || Base.DEFAULT_RADIX;
|
||||||
if (radix < 2 || radix > 36) {
|
if (radix < 2 || radix > 36) {
|
||||||
throw "Error: Radix argument must be between 2 and 36";
|
throw 'Error: Radix argument must be between 2 and 36';
|
||||||
}
|
}
|
||||||
return parseInt(input.replace(/\s/g, ""), radix);
|
return parseInt(input.replace(/\s/g, ''), radix);
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,31 +7,31 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var Base64 = {
|
const Base64 = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
ALPHABET: "A-Za-z0-9+/=",
|
ALPHABET: 'A-Za-z0-9+/=',
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
ALPHABET_OPTIONS: [
|
ALPHABET_OPTIONS: [
|
||||||
{name: "Standard: A-Za-z0-9+/=", value: "A-Za-z0-9+/="},
|
{ name: 'Standard: A-Za-z0-9+/=', value: 'A-Za-z0-9+/=' },
|
||||||
{name: "URL safe: A-Za-z0-9-_", value: "A-Za-z0-9-_"},
|
{ name: 'URL safe: A-Za-z0-9-_', value: 'A-Za-z0-9-_' },
|
||||||
{name: "Filename safe: A-Za-z0-9+-=", value: "A-Za-z0-9+\\-="},
|
{ name: 'Filename safe: A-Za-z0-9+-=', value: 'A-Za-z0-9+\\-=' },
|
||||||
{name: "itoa64: ./0-9A-Za-z=", value: "./0-9A-Za-z="},
|
{ name: 'itoa64: ./0-9A-Za-z=', value: './0-9A-Za-z=' },
|
||||||
{name: "XML: A-Za-z0-9_.", value: "A-Za-z0-9_."},
|
{ name: 'XML: A-Za-z0-9_.', value: 'A-Za-z0-9_.' },
|
||||||
{name: "y64: A-Za-z0-9._-", value: "A-Za-z0-9._-"},
|
{ name: 'y64: A-Za-z0-9._-', value: 'A-Za-z0-9._-' },
|
||||||
{name: "z64: 0-9a-zA-Z+/=", value: "0-9a-zA-Z+/="},
|
{ name: 'z64: 0-9a-zA-Z+/=', value: '0-9a-zA-Z+/=' },
|
||||||
{name: "Radix-64: 0-9A-Za-z+/=", value: "0-9A-Za-z+/="},
|
{ name: 'Radix-64: 0-9A-Za-z+/=', value: '0-9A-Za-z+/=' },
|
||||||
{name: "Uuencoding: [space]-_", value: " -_"},
|
{ name: 'Uuencoding: [space]-_', value: ' -_' },
|
||||||
{name: "Xxencoding: +-0-9A-Za-z", value: "+\\-0-9A-Za-z"},
|
{ name: 'Xxencoding: +-0-9A-Za-z', value: '+\\-0-9A-Za-z' },
|
||||||
{name: "BinHex: !-,-0-689@A-NP-VX-Z[`a-fh-mp-r", value: "!-,-0-689@A-NP-VX-Z[`a-fh-mp-r"},
|
{ name: 'BinHex: !-,-0-689@A-NP-VX-Z[`a-fh-mp-r', value: '!-,-0-689@A-NP-VX-Z[`a-fh-mp-r' },
|
||||||
{name: "ROT13: N-ZA-Mn-za-m0-9+/=", value: "N-ZA-Mn-za-m0-9+/="},
|
{ name: 'ROT13: N-ZA-Mn-za-m0-9+/=', value: 'N-ZA-Mn-za-m0-9+/=' },
|
||||||
],
|
],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To Base64 operation.
|
* To Base64 operation.
|
||||||
|
@ -40,17 +40,17 @@ var Base64 = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_to: function(input, args) {
|
run_to(input, args) {
|
||||||
var alphabet = args[0] || Base64.ALPHABET;
|
const alphabet = args[0] || Base64.ALPHABET;
|
||||||
return Utils.to_base64(input, alphabet);
|
return Utils.to_base64(input, alphabet);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
REMOVE_NON_ALPH_CHARS: true,
|
REMOVE_NON_ALPH_CHARS: true,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* From Base64 operation.
|
* From Base64 operation.
|
||||||
|
@ -59,19 +59,19 @@ var Base64 = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_from: function(input, args) {
|
run_from(input, args) {
|
||||||
var alphabet = args[0] || Base64.ALPHABET,
|
let alphabet = args[0] || Base64.ALPHABET,
|
||||||
remove_non_alph_chars = args[1];
|
remove_non_alph_chars = args[1];
|
||||||
|
|
||||||
return Utils.from_base64(input, alphabet, "byte_array", remove_non_alph_chars);
|
return Utils.from_base64(input, alphabet, 'byte_array', remove_non_alph_chars);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
BASE32_ALPHABET: "A-Z2-7=",
|
BASE32_ALPHABET: 'A-Z2-7=',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To Base32 operation.
|
* To Base32 operation.
|
||||||
|
@ -80,49 +80,60 @@ var Base64 = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_to_32: function(input, args) {
|
run_to_32(input, args) {
|
||||||
if (!input) return "";
|
if (!input) return '';
|
||||||
|
|
||||||
var alphabet = args[0] ?
|
let alphabet = args[0] ?
|
||||||
Utils.expand_alph_range(args[0]).join("") : "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
|
Utils.expand_alph_range(args[0]).join('') : 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=',
|
||||||
output = "",
|
output = '',
|
||||||
chr1, chr2, chr3, chr4, chr5,
|
chr1,
|
||||||
enc1, enc2, enc3, enc4, enc5, enc6, enc7, enc8,
|
chr2,
|
||||||
i = 0;
|
chr3,
|
||||||
|
chr4,
|
||||||
|
chr5,
|
||||||
|
enc1,
|
||||||
|
enc2,
|
||||||
|
enc3,
|
||||||
|
enc4,
|
||||||
|
enc5,
|
||||||
|
enc6,
|
||||||
|
enc7,
|
||||||
|
enc8,
|
||||||
|
i = 0;
|
||||||
|
|
||||||
while (i < input.length) {
|
while (i < input.length) {
|
||||||
chr1 = input[i++];
|
chr1 = input[i++];
|
||||||
chr2 = input[i++];
|
chr2 = input[i++];
|
||||||
chr3 = input[i++];
|
chr3 = input[i++];
|
||||||
chr4 = input[i++];
|
chr4 = input[i++];
|
||||||
chr5 = input[i++];
|
chr5 = input[i++];
|
||||||
|
|
||||||
enc1 = chr1 >> 3;
|
enc1 = chr1 >> 3;
|
||||||
enc2 = ((chr1 & 7) << 2) | (chr2 >> 6);
|
enc2 = ((chr1 & 7) << 2) | (chr2 >> 6);
|
||||||
enc3 = (chr2 >> 1) & 31;
|
enc3 = (chr2 >> 1) & 31;
|
||||||
enc4 = ((chr2 & 1) << 4) | (chr3 >> 4);
|
enc4 = ((chr2 & 1) << 4) | (chr3 >> 4);
|
||||||
enc5 = ((chr3 & 15) << 1) | (chr4 >> 7);
|
enc5 = ((chr3 & 15) << 1) | (chr4 >> 7);
|
||||||
enc6 = (chr4 >> 2) & 63;
|
enc6 = (chr4 >> 2) & 63;
|
||||||
enc7 = ((chr4 & 3) << 3) | (chr5 >> 5);
|
enc7 = ((chr4 & 3) << 3) | (chr5 >> 5);
|
||||||
enc8 = chr5 & 31;
|
enc8 = chr5 & 31;
|
||||||
|
|
||||||
if (isNaN(chr2)) {
|
if (isNaN(chr2)) {
|
||||||
enc3 = enc4 = enc5 = enc6 = enc7 = enc8 = 32;
|
enc3 = enc4 = enc5 = enc6 = enc7 = enc8 = 32;
|
||||||
} else if (isNaN(chr3)) {
|
} else if (isNaN(chr3)) {
|
||||||
enc5 = enc6 = enc7 = enc8 = 32;
|
enc5 = enc6 = enc7 = enc8 = 32;
|
||||||
} else if (isNaN(chr4)) {
|
} else if (isNaN(chr4)) {
|
||||||
enc6 = enc7 = enc8 = 32;
|
enc6 = enc7 = enc8 = 32;
|
||||||
} else if (isNaN(chr5)) {
|
} else if (isNaN(chr5)) {
|
||||||
enc8 = 32;
|
enc8 = 32;
|
||||||
}
|
}
|
||||||
|
|
||||||
output += alphabet.charAt(enc1) + alphabet.charAt(enc2) + alphabet.charAt(enc3) +
|
output += alphabet.charAt(enc1) + alphabet.charAt(enc2) + alphabet.charAt(enc3) +
|
||||||
alphabet.charAt(enc4) + alphabet.charAt(enc5) + alphabet.charAt(enc6) +
|
alphabet.charAt(enc4) + alphabet.charAt(enc5) + alphabet.charAt(enc6) +
|
||||||
alphabet.charAt(enc7) + alphabet.charAt(enc8);
|
alphabet.charAt(enc7) + alphabet.charAt(enc8);
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -132,60 +143,71 @@ var Base64 = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_from_32: function(input, args) {
|
run_from_32(input, args) {
|
||||||
if (!input) return [];
|
if (!input) return [];
|
||||||
|
|
||||||
var alphabet = args[0] ?
|
let alphabet = args[0] ?
|
||||||
Utils.expand_alph_range(args[0]).join("") : "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
|
Utils.expand_alph_range(args[0]).join('') : 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=',
|
||||||
remove_non_alph_chars = args[0];
|
remove_non_alph_chars = args[0];
|
||||||
|
|
||||||
var output = [],
|
let output = [],
|
||||||
chr1, chr2, chr3, chr4, chr5,
|
chr1,
|
||||||
enc1, enc2, enc3, enc4, enc5, enc6, enc7, enc8,
|
chr2,
|
||||||
i = 0;
|
chr3,
|
||||||
|
chr4,
|
||||||
|
chr5,
|
||||||
|
enc1,
|
||||||
|
enc2,
|
||||||
|
enc3,
|
||||||
|
enc4,
|
||||||
|
enc5,
|
||||||
|
enc6,
|
||||||
|
enc7,
|
||||||
|
enc8,
|
||||||
|
i = 0;
|
||||||
|
|
||||||
if (remove_non_alph_chars) {
|
if (remove_non_alph_chars) {
|
||||||
var re = new RegExp("[^" + alphabet.replace(/[\]\\\-^]/g, "\\$&") + "]", "g");
|
const re = new RegExp(`[^${alphabet.replace(/[\]\\\-^]/g, '\\$&')}]`, 'g');
|
||||||
input = input.replace(re, "");
|
input = input.replace(re, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
while (i < input.length) {
|
while (i < input.length) {
|
||||||
enc1 = alphabet.indexOf(input.charAt(i++));
|
enc1 = alphabet.indexOf(input.charAt(i++));
|
||||||
enc2 = alphabet.indexOf(input.charAt(i++) || "=");
|
enc2 = alphabet.indexOf(input.charAt(i++) || '=');
|
||||||
enc3 = alphabet.indexOf(input.charAt(i++) || "=");
|
enc3 = alphabet.indexOf(input.charAt(i++) || '=');
|
||||||
enc4 = alphabet.indexOf(input.charAt(i++) || "=");
|
enc4 = alphabet.indexOf(input.charAt(i++) || '=');
|
||||||
enc5 = alphabet.indexOf(input.charAt(i++) || "=");
|
enc5 = alphabet.indexOf(input.charAt(i++) || '=');
|
||||||
enc6 = alphabet.indexOf(input.charAt(i++) || "=");
|
enc6 = alphabet.indexOf(input.charAt(i++) || '=');
|
||||||
enc7 = alphabet.indexOf(input.charAt(i++) || "=");
|
enc7 = alphabet.indexOf(input.charAt(i++) || '=');
|
||||||
enc8 = alphabet.indexOf(input.charAt(i++) || "=");
|
enc8 = alphabet.indexOf(input.charAt(i++) || '=');
|
||||||
|
|
||||||
chr1 = (enc1 << 3) | (enc2 >> 2);
|
chr1 = (enc1 << 3) | (enc2 >> 2);
|
||||||
chr2 = ((enc2 & 3) << 6) | (enc3 << 1) | (enc4 >> 4);
|
chr2 = ((enc2 & 3) << 6) | (enc3 << 1) | (enc4 >> 4);
|
||||||
chr3 = ((enc4 & 15) << 4) | (enc5 >> 1);
|
chr3 = ((enc4 & 15) << 4) | (enc5 >> 1);
|
||||||
chr4 = ((enc5 & 1) << 7) | (enc6 << 2) | (enc7 >> 3);
|
chr4 = ((enc5 & 1) << 7) | (enc6 << 2) | (enc7 >> 3);
|
||||||
chr5 = ((enc7 & 7) << 5) | enc8;
|
chr5 = ((enc7 & 7) << 5) | enc8;
|
||||||
|
|
||||||
output.push(chr1);
|
output.push(chr1);
|
||||||
if (enc2 & 3 !== 0 || enc3 !== 32) output.push(chr2);
|
if (enc2 & 3 !== 0 || enc3 !== 32) output.push(chr2);
|
||||||
if (enc4 & 15 !== 0 || enc5 !== 32) output.push(chr3);
|
if (enc4 & 15 !== 0 || enc5 !== 32) output.push(chr3);
|
||||||
if (enc5 & 1 !== 0 || enc6 !== 32) output.push(chr4);
|
if (enc5 & 1 !== 0 || enc6 !== 32) output.push(chr4);
|
||||||
if (enc7 & 7 !== 0 || enc8 !== 32) output.push(chr5);
|
if (enc7 & 7 !== 0 || enc8 !== 32) output.push(chr5);
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
SHOW_IN_BINARY: false,
|
SHOW_IN_BINARY: false,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
OFFSETS_SHOW_VARIABLE: true,
|
OFFSETS_SHOW_VARIABLE: true,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show Base64 offsets operation.
|
* Show Base64 offsets operation.
|
||||||
|
@ -194,118 +216,118 @@ var Base64 = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {html}
|
* @returns {html}
|
||||||
*/
|
*/
|
||||||
run_offsets: function(input, args) {
|
run_offsets(input, args) {
|
||||||
var alphabet = args[0] || Base64.ALPHABET,
|
let alphabet = args[0] || Base64.ALPHABET,
|
||||||
show_variable = args[1],
|
show_variable = args[1],
|
||||||
offset0 = Utils.to_base64(input, alphabet),
|
offset0 = Utils.to_base64(input, alphabet),
|
||||||
offset1 = Utils.to_base64([0].concat(input), alphabet),
|
offset1 = Utils.to_base64([0].concat(input), alphabet),
|
||||||
offset2 = Utils.to_base64([0, 0].concat(input), alphabet),
|
offset2 = Utils.to_base64([0, 0].concat(input), alphabet),
|
||||||
len0 = offset0.indexOf("="),
|
len0 = offset0.indexOf('='),
|
||||||
len1 = offset1.indexOf("="),
|
len1 = offset1.indexOf('='),
|
||||||
len2 = offset2.indexOf("="),
|
len2 = offset2.indexOf('='),
|
||||||
script = "<script type='application/javascript'>$('[data-toggle=\"tooltip\"]').tooltip()</script>",
|
script = "<script type='application/javascript'>$('[data-toggle=\"tooltip\"]').tooltip()</script>",
|
||||||
static_section = "",
|
static_section = '',
|
||||||
padding = "";
|
padding = '';
|
||||||
|
|
||||||
if (input.length < 1) {
|
if (input.length < 1) {
|
||||||
return "Please enter a string.";
|
return 'Please enter a string.';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Highlight offset 0
|
// Highlight offset 0
|
||||||
if (len0 % 4 == 2) {
|
if (len0 % 4 == 2) {
|
||||||
static_section = offset0.slice(0, -3);
|
static_section = offset0.slice(0, -3);
|
||||||
offset0 = "<span data-toggle='tooltip' data-placement='top' title='" +
|
offset0 = `<span data-toggle='tooltip' data-placement='top' title='${
|
||||||
Utils.from_base64(static_section, alphabet).slice(0, -2) + "'>" +
|
Utils.from_base64(static_section, alphabet).slice(0, -2)}'>${
|
||||||
static_section + "</span>" +
|
static_section}</span>` +
|
||||||
"<span class='hlgreen'>" + offset0.substr(offset0.length - 3, 1) + "</span>" +
|
`<span class='hlgreen'>${offset0.substr(offset0.length - 3, 1)}</span>` +
|
||||||
"<span class='hlred'>" + offset0.substr(offset0.length - 2) + "</span>";
|
`<span class='hlred'>${offset0.substr(offset0.length - 2)}</span>`;
|
||||||
} else if (len0 % 4 == 3) {
|
} else if (len0 % 4 == 3) {
|
||||||
static_section = offset0.slice(0, -2);
|
static_section = offset0.slice(0, -2);
|
||||||
offset0 = "<span data-toggle='tooltip' data-placement='top' title='" +
|
offset0 = `<span data-toggle='tooltip' data-placement='top' title='${
|
||||||
Utils.from_base64(static_section, alphabet).slice(0, -1) + "'>" +
|
Utils.from_base64(static_section, alphabet).slice(0, -1)}'>${
|
||||||
static_section + "</span>" +
|
static_section}</span>` +
|
||||||
"<span class='hlgreen'>" + offset0.substr(offset0.length - 2, 1) + "</span>" +
|
`<span class='hlgreen'>${offset0.substr(offset0.length - 2, 1)}</span>` +
|
||||||
"<span class='hlred'>" + offset0.substr(offset0.length - 1) + "</span>";
|
`<span class='hlred'>${offset0.substr(offset0.length - 1)}</span>`;
|
||||||
} else {
|
} else {
|
||||||
static_section = offset0;
|
static_section = offset0;
|
||||||
offset0 = "<span data-toggle='tooltip' data-placement='top' title='" +
|
offset0 = `<span data-toggle='tooltip' data-placement='top' title='${
|
||||||
Utils.from_base64(static_section, alphabet) + "'>" +
|
Utils.from_base64(static_section, alphabet)}'>${
|
||||||
static_section + "</span>";
|
static_section}</span>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!show_variable) {
|
if (!show_variable) {
|
||||||
offset0 = static_section;
|
offset0 = static_section;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Highlight offset 1
|
// Highlight offset 1
|
||||||
padding = "<span class='hlred'>" + offset1.substr(0, 1) + "</span>" +
|
padding = `<span class='hlred'>${offset1.substr(0, 1)}</span>` +
|
||||||
"<span class='hlgreen'>" + offset1.substr(1, 1) + "</span>";
|
`<span class='hlgreen'>${offset1.substr(1, 1)}</span>`;
|
||||||
offset1 = offset1.substr(2);
|
offset1 = offset1.substr(2);
|
||||||
if (len1 % 4 == 2) {
|
if (len1 % 4 == 2) {
|
||||||
static_section = offset1.slice(0, -3);
|
static_section = offset1.slice(0, -3);
|
||||||
offset1 = padding + "<span data-toggle='tooltip' data-placement='top' title='" +
|
offset1 = `${padding}<span data-toggle='tooltip' data-placement='top' title='${
|
||||||
Utils.from_base64("AA" + static_section, alphabet).slice(1, -2) + "'>" +
|
Utils.from_base64(`AA${static_section}`, alphabet).slice(1, -2)}'>${
|
||||||
static_section + "</span>" +
|
static_section}</span>` +
|
||||||
"<span class='hlgreen'>" + offset1.substr(offset1.length - 3, 1) + "</span>" +
|
`<span class='hlgreen'>${offset1.substr(offset1.length - 3, 1)}</span>` +
|
||||||
"<span class='hlred'>" + offset1.substr(offset1.length - 2) + "</span>";
|
`<span class='hlred'>${offset1.substr(offset1.length - 2)}</span>`;
|
||||||
} else if (len1 % 4 == 3) {
|
} else if (len1 % 4 == 3) {
|
||||||
static_section = offset1.slice(0, -2);
|
static_section = offset1.slice(0, -2);
|
||||||
offset1 = padding + "<span data-toggle='tooltip' data-placement='top' title='" +
|
offset1 = `${padding}<span data-toggle='tooltip' data-placement='top' title='${
|
||||||
Utils.from_base64("AA" + static_section, alphabet).slice(1, -1) + "'>" +
|
Utils.from_base64(`AA${static_section}`, alphabet).slice(1, -1)}'>${
|
||||||
static_section + "</span>" +
|
static_section}</span>` +
|
||||||
"<span class='hlgreen'>" + offset1.substr(offset1.length - 2, 1) + "</span>" +
|
`<span class='hlgreen'>${offset1.substr(offset1.length - 2, 1)}</span>` +
|
||||||
"<span class='hlred'>" + offset1.substr(offset1.length - 1) + "</span>";
|
`<span class='hlred'>${offset1.substr(offset1.length - 1)}</span>`;
|
||||||
} else {
|
} else {
|
||||||
static_section = offset1;
|
static_section = offset1;
|
||||||
offset1 = padding + "<span data-toggle='tooltip' data-placement='top' title='" +
|
offset1 = `${padding}<span data-toggle='tooltip' data-placement='top' title='${
|
||||||
Utils.from_base64("AA" + static_section, alphabet).slice(1) + "'>" +
|
Utils.from_base64(`AA${static_section}`, alphabet).slice(1)}'>${
|
||||||
static_section + "</span>";
|
static_section}</span>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!show_variable) {
|
if (!show_variable) {
|
||||||
offset1 = static_section;
|
offset1 = static_section;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Highlight offset 2
|
// Highlight offset 2
|
||||||
padding = "<span class='hlred'>" + offset2.substr(0, 2) + "</span>" +
|
padding = `<span class='hlred'>${offset2.substr(0, 2)}</span>` +
|
||||||
"<span class='hlgreen'>" + offset2.substr(2, 1) + "</span>";
|
`<span class='hlgreen'>${offset2.substr(2, 1)}</span>`;
|
||||||
offset2 = offset2.substr(3);
|
offset2 = offset2.substr(3);
|
||||||
if (len2 % 4 == 2) {
|
if (len2 % 4 == 2) {
|
||||||
static_section = offset2.slice(0, -3);
|
static_section = offset2.slice(0, -3);
|
||||||
offset2 = padding + "<span data-toggle='tooltip' data-placement='top' title='" +
|
offset2 = `${padding}<span data-toggle='tooltip' data-placement='top' title='${
|
||||||
Utils.from_base64("AAA" + static_section, alphabet).slice(2, -2) + "'>" +
|
Utils.from_base64(`AAA${static_section}`, alphabet).slice(2, -2)}'>${
|
||||||
static_section + "</span>" +
|
static_section}</span>` +
|
||||||
"<span class='hlgreen'>" + offset2.substr(offset2.length - 3, 1) + "</span>" +
|
`<span class='hlgreen'>${offset2.substr(offset2.length - 3, 1)}</span>` +
|
||||||
"<span class='hlred'>" + offset2.substr(offset2.length - 2) + "</span>";
|
`<span class='hlred'>${offset2.substr(offset2.length - 2)}</span>`;
|
||||||
} else if (len2 % 4 == 3) {
|
} else if (len2 % 4 == 3) {
|
||||||
static_section = offset2.slice(0, -2);
|
static_section = offset2.slice(0, -2);
|
||||||
offset2 = padding + "<span data-toggle='tooltip' data-placement='top' title='" +
|
offset2 = `${padding}<span data-toggle='tooltip' data-placement='top' title='${
|
||||||
Utils.from_base64("AAA" + static_section, alphabet).slice(2, -2) + "'>" +
|
Utils.from_base64(`AAA${static_section}`, alphabet).slice(2, -2)}'>${
|
||||||
static_section + "</span>" +
|
static_section}</span>` +
|
||||||
"<span class='hlgreen'>" + offset2.substr(offset2.length - 2, 1) + "</span>" +
|
`<span class='hlgreen'>${offset2.substr(offset2.length - 2, 1)}</span>` +
|
||||||
"<span class='hlred'>" + offset2.substr(offset2.length - 1) + "</span>";
|
`<span class='hlred'>${offset2.substr(offset2.length - 1)}</span>`;
|
||||||
} else {
|
} else {
|
||||||
static_section = offset2;
|
static_section = offset2;
|
||||||
offset2 = padding + "<span data-toggle='tooltip' data-placement='top' title='" +
|
offset2 = `${padding}<span data-toggle='tooltip' data-placement='top' title='${
|
||||||
Utils.from_base64("AAA" + static_section, alphabet).slice(2) + "'>" +
|
Utils.from_base64(`AAA${static_section}`, alphabet).slice(2)}'>${
|
||||||
static_section + "</span>";
|
static_section}</span>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!show_variable) {
|
if (!show_variable) {
|
||||||
offset2 = static_section;
|
offset2 = static_section;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (show_variable ? "Characters highlighted in <span class='hlgreen'>green</span> could change if the input is surrounded by more data." +
|
return (show_variable ? `${"Characters highlighted in <span class='hlgreen'>green</span> could change if the input is surrounded by more data." +
|
||||||
"\nCharacters highlighted in <span class='hlred'>red</span> are for padding purposes only." +
|
"\nCharacters highlighted in <span class='hlred'>red</span> are for padding purposes only." +
|
||||||
"\nUnhighlighted characters are <span data-toggle='tooltip' data-placement='top' title='Tooltip on left'>static</span>." +
|
"\nUnhighlighted characters are <span data-toggle='tooltip' data-placement='top' title='Tooltip on left'>static</span>." +
|
||||||
"\nHover over the static sections to see what they decode to on their own.\n" +
|
'\nHover over the static sections to see what they decode to on their own.\n' +
|
||||||
"\nOffset 0: " + offset0 +
|
'\nOffset 0: '}${offset0
|
||||||
"\nOffset 1: " + offset1 +
|
}\nOffset 1: ${offset1
|
||||||
"\nOffset 2: " + offset2 +
|
}\nOffset 2: ${offset2
|
||||||
script :
|
}${script}` :
|
||||||
offset0 + "\n" + offset1 + "\n" + offset2);
|
`${offset0}\n${offset1}\n${offset2}`);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -317,11 +339,11 @@ var Base64 = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {Object[]} pos
|
* @returns {Object[]} pos
|
||||||
*/
|
*/
|
||||||
highlight_to: function(pos, args) {
|
highlight_to(pos, args) {
|
||||||
pos[0].start = Math.floor(pos[0].start / 3 * 4);
|
pos[0].start = Math.floor(pos[0].start / 3 * 4);
|
||||||
pos[0].end = Math.ceil(pos[0].end / 3 * 4);
|
pos[0].end = Math.ceil(pos[0].end / 3 * 4);
|
||||||
return pos;
|
return pos;
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Highlight from Base64
|
* Highlight from Base64
|
||||||
|
@ -332,10 +354,10 @@ var Base64 = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {Object[]} pos
|
* @returns {Object[]} pos
|
||||||
*/
|
*/
|
||||||
highlight_from: function(pos, args) {
|
highlight_from(pos, args) {
|
||||||
pos[0].start = Math.ceil(pos[0].start / 4 * 3);
|
pos[0].start = Math.ceil(pos[0].start / 4 * 3);
|
||||||
pos[0].end = Math.floor(pos[0].end / 4 * 3);
|
pos[0].end = Math.floor(pos[0].end / 4 * 3);
|
||||||
return pos;
|
return pos;
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var BitwiseOp = {
|
const BitwiseOp = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs bitwise operations across the input data.
|
* Runs bitwise operations across the input data.
|
||||||
|
@ -22,42 +22,42 @@ var BitwiseOp = {
|
||||||
* @param {boolean} differential
|
* @param {boolean} differential
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
_bit_op: function (input, key, func, null_preserving, differential) {
|
_bit_op(input, key, func, null_preserving, differential) {
|
||||||
if (!key || !key.length) key = [0];
|
if (!key || !key.length) key = [0];
|
||||||
var result = [],
|
let result = [],
|
||||||
x = null,
|
x = null,
|
||||||
k = null,
|
k = null,
|
||||||
o = null;
|
o = null;
|
||||||
|
|
||||||
for (var i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
k = key[i % key.length];
|
k = key[i % key.length];
|
||||||
o = input[i];
|
o = input[i];
|
||||||
x = null_preserving && (o === 0 || o == k) ? o : func(o, k);
|
x = null_preserving && (o === 0 || o == k) ? o : func(o, k);
|
||||||
result.push(x);
|
result.push(x);
|
||||||
if (differential && !(null_preserving && (o === 0 || o == k))) {
|
if (differential && !(null_preserving && (o === 0 || o == k))) {
|
||||||
key[i % key.length] = x;
|
key[i % key.length] = x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
XOR_PRESERVE_NULLS: false,
|
XOR_PRESERVE_NULLS: false,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
XOR_DIFFERENTIAL: false,
|
XOR_DIFFERENTIAL: false,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
KEY_FORMAT: ["Hex", "Base64", "UTF8", "UTF16", "UTF16LE", "UTF16BE", "Latin1"],
|
KEY_FORMAT: ['Hex', 'Base64', 'UTF8', 'UTF16', 'UTF16LE', 'UTF16BE', 'Latin1'],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XOR operation.
|
* XOR operation.
|
||||||
|
@ -66,42 +66,42 @@ var BitwiseOp = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_xor: function (input, args) {
|
run_xor(input, args) {
|
||||||
var key = Utils.format[args[0].option].parse(args[0].string || ""),
|
let key = Utils.format[args[0].option].parse(args[0].string || ''),
|
||||||
null_preserving = args[1],
|
null_preserving = args[1],
|
||||||
differential = args[2];
|
differential = args[2];
|
||||||
|
|
||||||
key = Utils.word_array_to_byte_array(key);
|
key = Utils.word_array_to_byte_array(key);
|
||||||
|
|
||||||
return BitwiseOp._bit_op(input, key, BitwiseOp._xor, null_preserving, differential);
|
return BitwiseOp._bit_op(input, key, BitwiseOp._xor, null_preserving, differential);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
XOR_BRUTE_KEY_LENGTH: ["1", "2"],
|
XOR_BRUTE_KEY_LENGTH: ['1', '2'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
XOR_BRUTE_SAMPLE_LENGTH: 100,
|
XOR_BRUTE_SAMPLE_LENGTH: 100,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
XOR_BRUTE_SAMPLE_OFFSET: 0,
|
XOR_BRUTE_SAMPLE_OFFSET: 0,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
XOR_BRUTE_PRINT_KEY: true,
|
XOR_BRUTE_PRINT_KEY: true,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
XOR_BRUTE_OUTPUT_HEX: false,
|
XOR_BRUTE_OUTPUT_HEX: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XOR Brute Force operation.
|
* XOR Brute Force operation.
|
||||||
|
@ -110,41 +110,42 @@ var BitwiseOp = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_xor_brute: function (input, args) {
|
run_xor_brute(input, args) {
|
||||||
var key_length = parseInt(args[0], 10),
|
let key_length = parseInt(args[0], 10),
|
||||||
sample_length = args[1],
|
sample_length = args[1],
|
||||||
sample_offset = args[2],
|
sample_offset = args[2],
|
||||||
null_preserving = args[3],
|
null_preserving = args[3],
|
||||||
differential = args[4],
|
differential = args[4],
|
||||||
crib = args[5],
|
crib = args[5],
|
||||||
print_key = args[6],
|
print_key = args[6],
|
||||||
output_hex = args[7],
|
output_hex = args[7],
|
||||||
regex;
|
regex;
|
||||||
|
|
||||||
var output = "",
|
let output = '',
|
||||||
result,
|
result,
|
||||||
result_utf8;
|
result_utf8;
|
||||||
|
|
||||||
input = input.slice(sample_offset, sample_offset + sample_length);
|
input = input.slice(sample_offset, sample_offset + sample_length);
|
||||||
|
|
||||||
if (crib !== "") {
|
if (crib !== '') {
|
||||||
regex = new RegExp(crib, "im");
|
regex = new RegExp(crib, 'im');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (var key = 1, l = Math.pow(256, key_length); key < l; key++) {
|
for (let key = 1, l = Math.pow(256, key_length); key < l; key++) {
|
||||||
result = BitwiseOp._bit_op(input, Utils.hex_to_byte_array(key.toString(16)), BitwiseOp._xor, null_preserving, differential);
|
result = BitwiseOp._bit_op(input, Utils.hex_to_byte_array(key.toString(16)), BitwiseOp._xor, null_preserving, differential);
|
||||||
result_utf8 = Utils.byte_array_to_utf8(result);
|
result_utf8 = Utils.byte_array_to_utf8(result);
|
||||||
if (crib !== "" && result_utf8.search(regex) === -1) continue;
|
if (crib !== '' && result_utf8.search(regex) === -1) continue;
|
||||||
if (print_key) output += "Key = " + Utils.hex(key, (2*key_length)) + ": ";
|
if (print_key) output += `Key = ${Utils.hex(key, (2 * key_length))}: `;
|
||||||
if (output_hex)
|
if (output_hex) {
|
||||||
output += Utils.byte_array_to_hex(result) + "\n";
|
output += `${Utils.byte_array_to_hex(result)}\n`;
|
||||||
else
|
} else {
|
||||||
output += Utils.printable(result_utf8, false) + "\n";
|
output += `${Utils.printable(result_utf8, false)}\n`;
|
||||||
if (print_key) output += "\n";
|
}
|
||||||
}
|
if (print_key) output += '\n';
|
||||||
return output;
|
}
|
||||||
},
|
return output;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -154,9 +155,9 @@ var BitwiseOp = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_not: function (input, args) {
|
run_not(input, args) {
|
||||||
return BitwiseOp._bit_op(input, null, BitwiseOp._not);
|
return BitwiseOp._bit_op(input, null, BitwiseOp._not);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -166,12 +167,12 @@ var BitwiseOp = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_and: function (input, args) {
|
run_and(input, args) {
|
||||||
var key = Utils.format[args[0].option].parse(args[0].string || "");
|
let key = Utils.format[args[0].option].parse(args[0].string || '');
|
||||||
key = Utils.word_array_to_byte_array(key);
|
key = Utils.word_array_to_byte_array(key);
|
||||||
|
|
||||||
return BitwiseOp._bit_op(input, key, BitwiseOp._and);
|
return BitwiseOp._bit_op(input, key, BitwiseOp._and);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -181,12 +182,12 @@ var BitwiseOp = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_or: function (input, args) {
|
run_or(input, args) {
|
||||||
var key = Utils.format[args[0].option].parse(args[0].string || "");
|
let key = Utils.format[args[0].option].parse(args[0].string || '');
|
||||||
key = Utils.word_array_to_byte_array(key);
|
key = Utils.word_array_to_byte_array(key);
|
||||||
|
|
||||||
return BitwiseOp._bit_op(input, key, BitwiseOp._or);
|
return BitwiseOp._bit_op(input, key, BitwiseOp._or);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -196,12 +197,12 @@ var BitwiseOp = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_add: function (input, args) {
|
run_add(input, args) {
|
||||||
var key = Utils.format[args[0].option].parse(args[0].string || "");
|
let key = Utils.format[args[0].option].parse(args[0].string || '');
|
||||||
key = Utils.word_array_to_byte_array(key);
|
key = Utils.word_array_to_byte_array(key);
|
||||||
|
|
||||||
return BitwiseOp._bit_op(input, key, BitwiseOp._add);
|
return BitwiseOp._bit_op(input, key, BitwiseOp._add);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -211,12 +212,12 @@ var BitwiseOp = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_sub: function (input, args) {
|
run_sub(input, args) {
|
||||||
var key = Utils.format[args[0].option].parse(args[0].string || "");
|
let key = Utils.format[args[0].option].parse(args[0].string || '');
|
||||||
key = Utils.word_array_to_byte_array(key);
|
key = Utils.word_array_to_byte_array(key);
|
||||||
|
|
||||||
return BitwiseOp._bit_op(input, key, BitwiseOp._sub);
|
return BitwiseOp._bit_op(input, key, BitwiseOp._sub);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -227,9 +228,9 @@ var BitwiseOp = {
|
||||||
* @param {number} key
|
* @param {number} key
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
_xor: function (operand, key) {
|
_xor(operand, key) {
|
||||||
return operand ^ key;
|
return operand ^ key;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -239,9 +240,9 @@ var BitwiseOp = {
|
||||||
* @param {number} operand
|
* @param {number} operand
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
_not: function (operand, _) {
|
_not(operand, _) {
|
||||||
return ~operand & 0xff;
|
return ~operand & 0xff;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -252,9 +253,9 @@ var BitwiseOp = {
|
||||||
* @param {number} key
|
* @param {number} key
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
_and: function (operand, key) {
|
_and(operand, key) {
|
||||||
return operand & key;
|
return operand & key;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -265,9 +266,9 @@ var BitwiseOp = {
|
||||||
* @param {number} key
|
* @param {number} key
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
_or: function (operand, key) {
|
_or(operand, key) {
|
||||||
return operand | key;
|
return operand | key;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -278,9 +279,9 @@ var BitwiseOp = {
|
||||||
* @param {number} key
|
* @param {number} key
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
_add: function (operand, key) {
|
_add(operand, key) {
|
||||||
return (operand + key) % 256;
|
return (operand + key) % 256;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -291,9 +292,9 @@ var BitwiseOp = {
|
||||||
* @param {number} key
|
* @param {number} key
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
_sub: function (operand, key) {
|
_sub(operand, key) {
|
||||||
var result = operand - key;
|
const result = operand - key;
|
||||||
return (result < 0) ? 256 + result : result;
|
return (result < 0) ? 256 + result : result;
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,23 +9,23 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var ByteRepr = {
|
const ByteRepr = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
DELIM_OPTIONS: ["Space", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF"],
|
DELIM_OPTIONS: ['Space', 'Comma', 'Semi-colon', 'Colon', 'Line feed', 'CRLF'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
HEX_DELIM_OPTIONS: ["Space", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF", "0x", "\\x", "None"],
|
HEX_DELIM_OPTIONS: ['Space', 'Comma', 'Semi-colon', 'Colon', 'Line feed', 'CRLF', '0x', '\\x', 'None'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
BIN_DELIM_OPTIONS: ["Space", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF", "None"],
|
BIN_DELIM_OPTIONS: ['Space', 'Comma', 'Semi-colon', 'Colon', 'Line feed', 'CRLF', 'None'],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To Hex operation.
|
* To Hex operation.
|
||||||
|
@ -34,10 +34,10 @@ var ByteRepr = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_to_hex: function(input, args) {
|
run_to_hex(input, args) {
|
||||||
var delim = Utils.char_rep[args[0] || "Space"];
|
const delim = Utils.char_rep[args[0] || 'Space'];
|
||||||
return Utils.to_hex(input, delim, 2);
|
return Utils.to_hex(input, delim, 2);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -47,17 +47,17 @@ var ByteRepr = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_from_hex: function(input, args) {
|
run_from_hex(input, args) {
|
||||||
var delim = args[0] || "Space";
|
const delim = args[0] || 'Space';
|
||||||
return Utils.from_hex(input, delim, 2);
|
return Utils.from_hex(input, delim, 2);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
CHARCODE_BASE: 16,
|
CHARCODE_BASE: 16,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To Charcode operation.
|
* To Charcode operation.
|
||||||
|
@ -66,38 +66,38 @@ var ByteRepr = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_to_charcode: function(input, args) {
|
run_to_charcode(input, args) {
|
||||||
var delim = Utils.char_rep[args[0] || "Space"],
|
let delim = Utils.char_rep[args[0] || 'Space'],
|
||||||
base = args[1],
|
base = args[1],
|
||||||
output = "",
|
output = '',
|
||||||
padding = 2,
|
padding = 2,
|
||||||
ordinal;
|
ordinal;
|
||||||
|
|
||||||
if (base < 2 || base > 36) {
|
if (base < 2 || base > 36) {
|
||||||
throw "Error: Base argument must be between 2 and 36";
|
throw 'Error: Base argument must be between 2 and 36';
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
ordinal = Utils.ord(input[i]);
|
ordinal = Utils.ord(input[i]);
|
||||||
|
|
||||||
if (base == 16) {
|
if (base == 16) {
|
||||||
if (ordinal < 256) padding = 2;
|
if (ordinal < 256) padding = 2;
|
||||||
else if (ordinal < 65536) padding = 4;
|
else if (ordinal < 65536) padding = 4;
|
||||||
else if (ordinal < 16777216) padding = 6;
|
else if (ordinal < 16777216) padding = 6;
|
||||||
else if (ordinal < 4294967296) padding = 8;
|
else if (ordinal < 4294967296) padding = 8;
|
||||||
else padding = 2;
|
else padding = 2;
|
||||||
|
|
||||||
if (padding > 2) app.options.attempt_highlight = false;
|
if (padding > 2) app.options.attempt_highlight = false;
|
||||||
|
|
||||||
output += Utils.hex(ordinal, padding) + delim;
|
output += Utils.hex(ordinal, padding) + delim;
|
||||||
} else {
|
} else {
|
||||||
app.options.attempt_highlight = false;
|
app.options.attempt_highlight = false;
|
||||||
output += ordinal.toString(base) + delim;
|
output += ordinal.toString(base) + delim;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return output.slice(0, -delim.length);
|
return output.slice(0, -delim.length);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -107,35 +107,35 @@ var ByteRepr = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_from_charcode: function(input, args) {
|
run_from_charcode(input, args) {
|
||||||
var delim = Utils.char_rep[args[0] || "Space"],
|
let delim = Utils.char_rep[args[0] || 'Space'],
|
||||||
base = args[1],
|
base = args[1],
|
||||||
bites = input.split(delim),
|
bites = input.split(delim),
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
if (base < 2 || base > 36) {
|
if (base < 2 || base > 36) {
|
||||||
throw "Error: Base argument must be between 2 and 36";
|
throw 'Error: Base argument must be between 2 and 36';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (base != 16) {
|
if (base != 16) {
|
||||||
app.options.attempt_highlight = false;
|
app.options.attempt_highlight = 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
|
||||||
if (bites.length == 1 && input.length > 17) {
|
if (bites.length == 1 && input.length > 17) {
|
||||||
bites = [];
|
bites = [];
|
||||||
for (i = 0; i < input.length; i += 2) {
|
for (i = 0; i < input.length; i += 2) {
|
||||||
bites.push(input.slice(i, i+2));
|
bites.push(input.slice(i, i + 2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var latin1 = "";
|
let latin1 = '';
|
||||||
for (i = 0; i < bites.length; i++) {
|
for (i = 0; i < bites.length; i++) {
|
||||||
latin1 += Utils.chr(parseInt(bites[i], base));
|
latin1 += Utils.chr(parseInt(bites[i], base));
|
||||||
}
|
}
|
||||||
return Utils.str_to_byte_array(latin1);
|
return Utils.str_to_byte_array(latin1);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -147,20 +147,20 @@ var ByteRepr = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {Object[]} pos
|
* @returns {Object[]} pos
|
||||||
*/
|
*/
|
||||||
highlight_to: function(pos, args) {
|
highlight_to(pos, args) {
|
||||||
var delim = Utils.char_rep[args[0] || "Space"],
|
let delim = Utils.char_rep[args[0] || 'Space'],
|
||||||
len = delim == "\r\n" ? 1 : delim.length;
|
len = delim == '\r\n' ? 1 : delim.length;
|
||||||
|
|
||||||
pos[0].start = pos[0].start * (2 + len);
|
pos[0].start = pos[0].start * (2 + len);
|
||||||
pos[0].end = pos[0].end * (2 + len) - len;
|
pos[0].end = pos[0].end * (2 + len) - len;
|
||||||
|
|
||||||
// 0x and \x are added to the beginning if they are selected, so increment the positions accordingly
|
// 0x and \x are added to the beginning if they are selected, so increment the positions accordingly
|
||||||
if (delim == "0x" || delim == "\\x") {
|
if (delim == '0x' || delim == '\\x') {
|
||||||
pos[0].start += 2;
|
pos[0].start += 2;
|
||||||
pos[0].end += 2;
|
pos[0].end += 2;
|
||||||
}
|
}
|
||||||
return pos;
|
return pos;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -172,23 +172,23 @@ var ByteRepr = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {Object[]} pos
|
* @returns {Object[]} pos
|
||||||
*/
|
*/
|
||||||
highlight_from: function(pos, args) {
|
highlight_from(pos, args) {
|
||||||
var delim = Utils.char_rep[args[0] || "Space"],
|
let delim = Utils.char_rep[args[0] || 'Space'],
|
||||||
len = delim == "\r\n" ? 1 : delim.length,
|
len = delim == '\r\n' ? 1 : delim.length,
|
||||||
width = len + 2;
|
width = len + 2;
|
||||||
|
|
||||||
// 0x and \x are added to the beginning if they are selected, so increment the positions accordingly
|
// 0x and \x are added to the beginning if they are selected, so increment the positions accordingly
|
||||||
if (delim == "0x" || delim == "\\x") {
|
if (delim == '0x' || delim == '\\x') {
|
||||||
if (pos[0].start > 1) pos[0].start -= 2;
|
if (pos[0].start > 1) pos[0].start -= 2;
|
||||||
else pos[0].start = 0;
|
else pos[0].start = 0;
|
||||||
if (pos[0].end > 1) pos[0].end -= 2;
|
if (pos[0].end > 1) pos[0].end -= 2;
|
||||||
else pos[0].end = 0;
|
else pos[0].end = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
pos[0].start = pos[0].start === 0 ? 0 : Math.round(pos[0].start / width);
|
pos[0].start = pos[0].start === 0 ? 0 : Math.round(pos[0].start / width);
|
||||||
pos[0].end = pos[0].end === 0 ? 0 : Math.ceil(pos[0].end / width);
|
pos[0].end = pos[0].end === 0 ? 0 : Math.ceil(pos[0].end / width);
|
||||||
return pos;
|
return pos;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -198,10 +198,10 @@ var ByteRepr = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_to_decimal: function(input, args) {
|
run_to_decimal(input, args) {
|
||||||
var delim = Utils.char_rep[args[0]];
|
const delim = Utils.char_rep[args[0]];
|
||||||
return input.join(delim);
|
return input.join(delim);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -211,17 +211,17 @@ var ByteRepr = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_from_decimal: function(input, args) {
|
run_from_decimal(input, args) {
|
||||||
var delim = Utils.char_rep[args[0]];
|
const delim = Utils.char_rep[args[0]];
|
||||||
var byte_str = input.split(delim), output = [];
|
let byte_str = input.split(delim),
|
||||||
if (byte_str[byte_str.length-1] === "")
|
output = [];
|
||||||
byte_str = byte_str.slice(0, byte_str.length-1);
|
if (byte_str[byte_str.length - 1] === '') { byte_str = byte_str.slice(0, byte_str.length - 1); }
|
||||||
|
|
||||||
for (var i = 0; i < byte_str.length; i++) {
|
for (let i = 0; i < byte_str.length; i++) {
|
||||||
output[i] = parseInt(byte_str[i]);
|
output[i] = parseInt(byte_str[i]);
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -231,21 +231,21 @@ var ByteRepr = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_to_binary: function(input, args) {
|
run_to_binary(input, args) {
|
||||||
var delim = Utils.char_rep[args[0] || "Space"],
|
let delim = Utils.char_rep[args[0] || 'Space'],
|
||||||
output = "",
|
output = '',
|
||||||
padding = 8;
|
padding = 8;
|
||||||
|
|
||||||
for (var i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
output += Utils.pad(input[i].toString(2), padding) + delim;
|
output += Utils.pad(input[i].toString(2), padding) + delim;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (delim.length) {
|
if (delim.length) {
|
||||||
return output.slice(0, -delim.length);
|
return output.slice(0, -delim.length);
|
||||||
} else {
|
} else {
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -255,19 +255,19 @@ var ByteRepr = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_from_binary: function(input, args) {
|
run_from_binary(input, args) {
|
||||||
if (args[0] != "None") {
|
if (args[0] != 'None') {
|
||||||
var delim_regex = Utils.regex_rep[args[0] || "Space"];
|
const delim_regex = Utils.regex_rep[args[0] || 'Space'];
|
||||||
input = input.replace(delim_regex, '');
|
input = input.replace(delim_regex, '');
|
||||||
}
|
}
|
||||||
|
|
||||||
var output = [];
|
const output = [];
|
||||||
var byte_len = 8;
|
const byte_len = 8;
|
||||||
for (var i = 0; i < input.length; i += byte_len) {
|
for (let i = 0; i < input.length; i += byte_len) {
|
||||||
output.push(parseInt(input.substr(i, byte_len), 2));
|
output.push(parseInt(input.substr(i, byte_len), 2));
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -279,12 +279,12 @@ var ByteRepr = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {Object[]} pos
|
* @returns {Object[]} pos
|
||||||
*/
|
*/
|
||||||
highlight_to_binary: function(pos, args) {
|
highlight_to_binary(pos, args) {
|
||||||
var delim = Utils.char_rep[args[0] || "Space"];
|
const delim = Utils.char_rep[args[0] || 'Space'];
|
||||||
pos[0].start = pos[0].start * (8 + delim.length);
|
pos[0].start = pos[0].start * (8 + delim.length);
|
||||||
pos[0].end = pos[0].end * (8 + delim.length) - delim.length;
|
pos[0].end = pos[0].end * (8 + delim.length) - delim.length;
|
||||||
return pos;
|
return pos;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -296,24 +296,24 @@ var ByteRepr = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {Object[]} pos
|
* @returns {Object[]} pos
|
||||||
*/
|
*/
|
||||||
highlight_from_binary: function(pos, args) {
|
highlight_from_binary(pos, args) {
|
||||||
var delim = Utils.char_rep[args[0] || "Space"];
|
const delim = Utils.char_rep[args[0] || 'Space'];
|
||||||
pos[0].start = pos[0].start === 0 ? 0 : Math.floor(pos[0].start / (8 + delim.length));
|
pos[0].start = pos[0].start === 0 ? 0 : Math.floor(pos[0].start / (8 + delim.length));
|
||||||
pos[0].end = pos[0].end === 0 ? 0 : Math.ceil(pos[0].end / (8 + delim.length));
|
pos[0].end = pos[0].end === 0 ? 0 : Math.ceil(pos[0].end / (8 + delim.length));
|
||||||
return pos;
|
return pos;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
HEX_CONTENT_CONVERT_WHICH: ["Only special chars", "Only special chars including spaces", "All chars"],
|
HEX_CONTENT_CONVERT_WHICH: ['Only special chars', 'Only special chars including spaces', 'All chars'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
HEX_CONTENT_SPACES_BETWEEN_BYTES: false,
|
HEX_CONTENT_SPACES_BETWEEN_BYTES: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To Hex Content operation.
|
* To Hex Content operation.
|
||||||
|
@ -322,38 +322,38 @@ var ByteRepr = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_to_hex_content: function(input, args) {
|
run_to_hex_content(input, args) {
|
||||||
var convert = args[0];
|
const convert = args[0];
|
||||||
var spaces = args[1];
|
const spaces = args[1];
|
||||||
if (convert == "All chars") {
|
if (convert == 'All chars') {
|
||||||
var result = "|" + Utils.to_hex(input) + "|";
|
let result = `|${Utils.to_hex(input)}|`;
|
||||||
if (!spaces) result = result.replace(/ /g, "");
|
if (!spaces) result = result.replace(/ /g, '');
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
var output = "",
|
let output = '',
|
||||||
in_hex = false,
|
in_hex = false,
|
||||||
convert_spaces = convert == "Only special chars including spaces",
|
convert_spaces = convert == 'Only special chars including spaces',
|
||||||
b;
|
b;
|
||||||
for (var i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
b = input[i];
|
b = input[i];
|
||||||
if ((b == 32 && convert_spaces) || (b < 48 && b != 32) || (b > 57 && b < 65) || (b > 90 && b < 97) || b > 122) {
|
if ((b == 32 && convert_spaces) || (b < 48 && b != 32) || (b > 57 && b < 65) || (b > 90 && b < 97) || b > 122) {
|
||||||
if (!in_hex) {
|
if (!in_hex) {
|
||||||
output += "|";
|
output += '|';
|
||||||
in_hex = true;
|
in_hex = true;
|
||||||
} else if (spaces) output += " ";
|
} else if (spaces) output += ' ';
|
||||||
output += Utils.to_hex([b]);
|
output += Utils.to_hex([b]);
|
||||||
} else {
|
} else {
|
||||||
if (in_hex) {
|
if (in_hex) {
|
||||||
output += "|";
|
output += '|';
|
||||||
in_hex = false;
|
in_hex = false;
|
||||||
}
|
|
||||||
output += Utils.chr(input[i]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (in_hex) output += "|";
|
output += Utils.chr(input[i]);
|
||||||
return output;
|
}
|
||||||
},
|
}
|
||||||
|
if (in_hex) output += '|';
|
||||||
|
return output;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -363,32 +363,36 @@ var ByteRepr = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_from_hex_content: function(input, args) {
|
run_from_hex_content(input, args) {
|
||||||
var regex = /\|([a-f\d ]{2,})\|/gi;
|
const regex = /\|([a-f\d ]{2,})\|/gi;
|
||||||
var output = [], m, i = 0;
|
let output = [],
|
||||||
while (!!(m = regex.exec(input))) {
|
m,
|
||||||
|
i = 0;
|
||||||
|
while (m = regex.exec(input)) {
|
||||||
// Add up to match
|
// Add up to match
|
||||||
for (; i < m.index;)
|
for (; i < m.index;) {
|
||||||
output.push(Utils.ord(input[i++]));
|
output.push(Utils.ord(input[i++]));
|
||||||
|
}
|
||||||
|
|
||||||
// Add match
|
// Add match
|
||||||
var bytes = Utils.from_hex(m[1]);
|
const bytes = Utils.from_hex(m[1]);
|
||||||
if (bytes) {
|
if (bytes) {
|
||||||
for (var a = 0; a < bytes.length;)
|
for (let a = 0; a < bytes.length;) { output.push(bytes[a++]); }
|
||||||
output.push(bytes[a++]);
|
} else {
|
||||||
} else {
|
|
||||||
// Not valid hex, print as normal
|
// Not valid hex, print as normal
|
||||||
for (; i < regex.lastIndex;)
|
for (; i < regex.lastIndex;) {
|
||||||
output.push(Utils.ord(input[i++]));
|
output.push(Utils.ord(input[i++]));
|
||||||
}
|
|
||||||
|
|
||||||
i = regex.lastIndex;
|
|
||||||
}
|
}
|
||||||
// Add all after final match
|
}
|
||||||
for (; i < input.length;)
|
|
||||||
output.push(Utils.ord(input[i++]));
|
|
||||||
|
|
||||||
return output;
|
i = regex.lastIndex;
|
||||||
},
|
}
|
||||||
|
// Add all after final match
|
||||||
|
for (; i < input.length;) {
|
||||||
|
output.push(Utils.ord(input[i++]));
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,13 +9,13 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var CharEnc = {
|
const CharEnc = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
IO_FORMAT: ["UTF8", "UTF16", "UTF16LE", "UTF16BE", "Latin1", "Windows-1251", "Hex", "Base64"],
|
IO_FORMAT: ['UTF8', 'UTF16', 'UTF16LE', 'UTF16BE', 'Latin1', 'Windows-1251', 'Hex', 'Base64'],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Text encoding operation.
|
* Text encoding operation.
|
||||||
|
@ -24,23 +24,23 @@ var CharEnc = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run: function(input, args) {
|
run(input, args) {
|
||||||
var input_format = args[0],
|
let input_format = args[0],
|
||||||
output_format = args[1];
|
output_format = args[1];
|
||||||
|
|
||||||
if (input_format == "Windows-1251") {
|
if (input_format == 'Windows-1251') {
|
||||||
input = Utils.win1251_to_unicode(input);
|
input = Utils.win1251_to_unicode(input);
|
||||||
input = CryptoJS.enc.Utf8.parse(input);
|
input = CryptoJS.enc.Utf8.parse(input);
|
||||||
} else {
|
} else {
|
||||||
input = Utils.format[input_format].parse(input);
|
input = Utils.format[input_format].parse(input);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (output_format == "Windows-1251") {
|
if (output_format == 'Windows-1251') {
|
||||||
input = CryptoJS.enc.Utf8.stringify(input);
|
input = CryptoJS.enc.Utf8.stringify(input);
|
||||||
return Utils.unicode_to_win1251(input);
|
return Utils.unicode_to_win1251(input);
|
||||||
} else {
|
} else {
|
||||||
return Utils.format[output_format].stringify(input);
|
return Utils.format[output_format].stringify(input);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var Checksum = {
|
const Checksum = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fletcher-16 Checksum operation.
|
* Fletcher-16 Checksum operation.
|
||||||
|
@ -16,17 +16,17 @@ var Checksum = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_fletcher16: function(input, args) {
|
run_fletcher16(input, args) {
|
||||||
var a = 0,
|
let a = 0,
|
||||||
b = 0;
|
b = 0;
|
||||||
|
|
||||||
for (var i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
a = (a + input[i]) % 0xff;
|
a = (a + input[i]) % 0xff;
|
||||||
b = (b + a) % 0xff;
|
b = (b + a) % 0xff;
|
||||||
}
|
}
|
||||||
|
|
||||||
return Utils.hex(((b << 8) | a) >>> 0, 4);
|
return Utils.hex(((b << 8) | a) >>> 0, 4);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,21 +36,21 @@ var Checksum = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_adler32: function(input, args) {
|
run_adler32(input, args) {
|
||||||
var MOD_ADLER = 65521,
|
let MOD_ADLER = 65521,
|
||||||
a = 1,
|
a = 1,
|
||||||
b = 0;
|
b = 0;
|
||||||
|
|
||||||
for (var i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
a += input[i];
|
a += input[i];
|
||||||
b += a;
|
b += a;
|
||||||
}
|
}
|
||||||
|
|
||||||
a %= MOD_ADLER;
|
a %= MOD_ADLER;
|
||||||
b %= MOD_ADLER;
|
b %= MOD_ADLER;
|
||||||
|
|
||||||
return Utils.hex(((b << 16) | a) >>> 0, 8);
|
return Utils.hex(((b << 16) | a) >>> 0, 8);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,16 +60,16 @@ var Checksum = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_crc32: function(input, args) {
|
run_crc32(input, args) {
|
||||||
var crc_table = window.crc_table || (window.crc_table = Checksum._gen_crc_table()),
|
let crc_table = window.crc_table || (window.crc_table = Checksum._gen_crc_table()),
|
||||||
crc = 0 ^ (-1);
|
crc = 0 ^ (-1);
|
||||||
|
|
||||||
for (var i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
crc = (crc >>> 8) ^ crc_table[(crc ^ input[i]) & 0xff];
|
crc = (crc >>> 8) ^ crc_table[(crc ^ input[i]) & 0xff];
|
||||||
}
|
}
|
||||||
|
|
||||||
return Utils.hex((crc ^ (-1)) >>> 0);
|
return Utils.hex((crc ^ (-1)) >>> 0);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,21 +89,21 @@ var Checksum = {
|
||||||
* Checksum.run_tcp_ip([0x45,0x00,0x01,0x11,0x3f,0x74,0x40,0x00,0x40,0x06,
|
* Checksum.run_tcp_ip([0x45,0x00,0x01,0x11,0x3f,0x74,0x40,0x00,0x40,0x06,
|
||||||
* 0x00,0x00,0xac,0x11,0x00,0x03,0xac,0x11,0x00,0x04])
|
* 0x00,0x00,0xac,0x11,0x00,0x03,0xac,0x11,0x00,0x04])
|
||||||
*/
|
*/
|
||||||
run_tcp_ip: function(input, args) {
|
run_tcp_ip(input, args) {
|
||||||
var csum = 0;
|
let csum = 0;
|
||||||
|
|
||||||
for (var i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
if(i % 2 === 0) {
|
if (i % 2 === 0) {
|
||||||
csum += (input[i] << 8);
|
csum += (input[i] << 8);
|
||||||
} else {
|
} else {
|
||||||
csum += input[i];
|
csum += input[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
csum = (csum >> 16) + (csum & 0xffff);
|
csum = (csum >> 16) + (csum & 0xffff);
|
||||||
|
|
||||||
return Utils.hex(0xffff - csum);
|
return Utils.hex(0xffff - csum);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,19 +112,19 @@ var Checksum = {
|
||||||
* @private
|
* @private
|
||||||
* @returns {array}
|
* @returns {array}
|
||||||
*/
|
*/
|
||||||
_gen_crc_table: function() {
|
_gen_crc_table() {
|
||||||
var c,
|
let c,
|
||||||
crc_table = [];
|
crc_table = [];
|
||||||
|
|
||||||
for (var n = 0; n < 256; n++) {
|
for (let n = 0; n < 256; n++) {
|
||||||
c = n;
|
c = n;
|
||||||
for (var k = 0; k < 8; k++) {
|
for (let k = 0; k < 8; k++) {
|
||||||
c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
|
c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
|
||||||
}
|
}
|
||||||
crc_table[n] = c;
|
crc_table[n] = c;
|
||||||
}
|
}
|
||||||
|
|
||||||
return crc_table;
|
return crc_table;
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,43 +9,43 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var Cipher = {
|
const Cipher = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
IO_FORMAT1: ["Hex", "Base64", "UTF8", "UTF16", "UTF16LE", "UTF16BE", "Latin1"],
|
IO_FORMAT1: ['Hex', 'Base64', 'UTF8', 'UTF16', 'UTF16LE', 'UTF16BE', 'Latin1'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
IO_FORMAT2: ["UTF8", "UTF16", "UTF16LE", "UTF16BE", "Latin1", "Hex", "Base64"],
|
IO_FORMAT2: ['UTF8', 'UTF16', 'UTF16LE', 'UTF16BE', 'Latin1', 'Hex', 'Base64'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
IO_FORMAT3: ["Hex", "Base64", "UTF16", "UTF16LE", "UTF16BE", "Latin1"],
|
IO_FORMAT3: ['Hex', 'Base64', 'UTF16', 'UTF16LE', 'UTF16BE', 'Latin1'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
IO_FORMAT4: ["Latin1", "UTF8", "UTF16", "UTF16LE", "UTF16BE", "Hex", "Base64"],
|
IO_FORMAT4: ['Latin1', 'UTF8', 'UTF16', 'UTF16LE', 'UTF16BE', 'Hex', 'Base64'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
MODES: ["CBC", "CFB", "CTR", "OFB", "ECB"],
|
MODES: ['CBC', 'CFB', 'CTR', 'OFB', 'ECB'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
PADDING: ["Pkcs7", "Iso97971", "AnsiX923", "Iso10126", "ZeroPadding", "NoPadding"],
|
PADDING: ['Pkcs7', 'Iso97971', 'AnsiX923', 'Iso10126', 'ZeroPadding', 'NoPadding'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
RESULT_TYPE: ["Show all", "Ciphertext", "Key", "IV", "Salt"],
|
RESULT_TYPE: ['Show all', 'Ciphertext', 'Key', 'IV', 'Salt'],
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,39 +57,39 @@ var Cipher = {
|
||||||
* @param {function} args
|
* @param {function} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
_enc: function (algo, input, args) {
|
_enc(algo, input, args) {
|
||||||
var key = Utils.format[args[0].option].parse(args[0].string || ""),
|
let key = Utils.format[args[0].option].parse(args[0].string || ''),
|
||||||
iv = Utils.format[args[1].option].parse(args[1].string || ""),
|
iv = Utils.format[args[1].option].parse(args[1].string || ''),
|
||||||
salt = Utils.format[args[2].option].parse(args[2].string || ""),
|
salt = Utils.format[args[2].option].parse(args[2].string || ''),
|
||||||
mode = CryptoJS.mode[args[3]],
|
mode = CryptoJS.mode[args[3]],
|
||||||
padding = CryptoJS.pad[args[4]],
|
padding = CryptoJS.pad[args[4]],
|
||||||
result_option = args[5].toLowerCase(),
|
result_option = args[5].toLowerCase(),
|
||||||
output_format = args[6];
|
output_format = args[6];
|
||||||
|
|
||||||
if (iv.sigBytes === 0) {
|
if (iv.sigBytes === 0) {
|
||||||
// Use passphrase rather than key. Need to convert it to a string.
|
// Use passphrase rather than key. Need to convert it to a string.
|
||||||
key = key.toString(CryptoJS.enc.Latin1);
|
key = key.toString(CryptoJS.enc.Latin1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var encrypted = algo.encrypt(input, key, {
|
const encrypted = algo.encrypt(input, key, {
|
||||||
salt: salt.sigBytes > 0 ? salt : false,
|
salt: salt.sigBytes > 0 ? salt : false,
|
||||||
iv: iv.sigBytes > 0 ? iv : null,
|
iv: iv.sigBytes > 0 ? iv : null,
|
||||||
mode: mode,
|
mode,
|
||||||
padding: padding
|
padding,
|
||||||
});
|
});
|
||||||
|
|
||||||
var result = "";
|
let result = '';
|
||||||
if (result_option == "show all") {
|
if (result_option == 'show all') {
|
||||||
result += "Key: " + encrypted.key.toString(Utils.format[output_format]);
|
result += `Key: ${encrypted.key.toString(Utils.format[output_format])}`;
|
||||||
result += "\nIV: " + encrypted.iv.toString(Utils.format[output_format]);
|
result += `\nIV: ${encrypted.iv.toString(Utils.format[output_format])}`;
|
||||||
if (encrypted.salt) result += "\nSalt: " + encrypted.salt.toString(Utils.format[output_format]);
|
if (encrypted.salt) result += `\nSalt: ${encrypted.salt.toString(Utils.format[output_format])}`;
|
||||||
result += "\n\nCiphertext: " + encrypted.ciphertext.toString(Utils.format[output_format]);
|
result += `\n\nCiphertext: ${encrypted.ciphertext.toString(Utils.format[output_format])}`;
|
||||||
} else {
|
} else {
|
||||||
result = encrypted[result_option].toString(Utils.format[output_format]);
|
result = encrypted[result_option].toString(Utils.format[output_format]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -101,45 +101,45 @@ var Cipher = {
|
||||||
* @param {function} args
|
* @param {function} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
_dec: function (algo, input, args) {
|
_dec(algo, input, args) {
|
||||||
var key = Utils.format[args[0].option].parse(args[0].string || ""),
|
let key = Utils.format[args[0].option].parse(args[0].string || ''),
|
||||||
iv = Utils.format[args[1].option].parse(args[1].string || ""),
|
iv = Utils.format[args[1].option].parse(args[1].string || ''),
|
||||||
salt = Utils.format[args[2].option].parse(args[2].string || ""),
|
salt = Utils.format[args[2].option].parse(args[2].string || ''),
|
||||||
mode = CryptoJS.mode[args[3]],
|
mode = CryptoJS.mode[args[3]],
|
||||||
padding = CryptoJS.pad[args[4]],
|
padding = CryptoJS.pad[args[4]],
|
||||||
input_format = args[5],
|
input_format = args[5],
|
||||||
output_format = args[6];
|
output_format = args[6];
|
||||||
|
|
||||||
// The ZeroPadding option causes a crash when the input length is 0
|
// The ZeroPadding option causes a crash when the input length is 0
|
||||||
if (!input.length) {
|
if (!input.length) {
|
||||||
return "No input";
|
return 'No input';
|
||||||
}
|
}
|
||||||
|
|
||||||
var ciphertext = Utils.format[input_format].parse(input);
|
const ciphertext = Utils.format[input_format].parse(input);
|
||||||
|
|
||||||
if (iv.sigBytes === 0) {
|
if (iv.sigBytes === 0) {
|
||||||
// Use passphrase rather than key. Need to convert it to a string.
|
// Use passphrase rather than key. Need to convert it to a string.
|
||||||
key = key.toString(CryptoJS.enc.Latin1);
|
key = key.toString(CryptoJS.enc.Latin1);
|
||||||
}
|
}
|
||||||
|
|
||||||
var decrypted = algo.decrypt({
|
const decrypted = algo.decrypt({
|
||||||
ciphertext: ciphertext,
|
ciphertext,
|
||||||
salt: salt.sigBytes > 0 ? salt : false
|
salt: salt.sigBytes > 0 ? salt : false,
|
||||||
}, key, {
|
}, key, {
|
||||||
iv: iv.sigBytes > 0 ? iv : null,
|
iv: iv.sigBytes > 0 ? iv : null,
|
||||||
mode: mode,
|
mode,
|
||||||
padding: padding
|
padding,
|
||||||
});
|
});
|
||||||
|
|
||||||
var result;
|
let result;
|
||||||
try {
|
try {
|
||||||
result = decrypted.toString(Utils.format[output_format]);
|
result = decrypted.toString(Utils.format[output_format]);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
result = "Decrypt error: " + err.message;
|
result = `Decrypt error: ${err.message}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -149,9 +149,9 @@ var Cipher = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_aes_enc: function (input, args) {
|
run_aes_enc(input, args) {
|
||||||
return Cipher._enc(CryptoJS.AES, input, args);
|
return Cipher._enc(CryptoJS.AES, input, args);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -161,9 +161,9 @@ var Cipher = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_aes_dec: function (input, args) {
|
run_aes_dec(input, args) {
|
||||||
return Cipher._dec(CryptoJS.AES, input, args);
|
return Cipher._dec(CryptoJS.AES, input, args);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -173,9 +173,9 @@ var Cipher = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_des_enc: function (input, args) {
|
run_des_enc(input, args) {
|
||||||
return Cipher._enc(CryptoJS.DES, input, args);
|
return Cipher._enc(CryptoJS.DES, input, args);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -185,9 +185,9 @@ var Cipher = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_des_dec: function (input, args) {
|
run_des_dec(input, args) {
|
||||||
return Cipher._dec(CryptoJS.DES, input, args);
|
return Cipher._dec(CryptoJS.DES, input, args);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -197,9 +197,9 @@ var Cipher = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_triple_des_enc: function (input, args) {
|
run_triple_des_enc(input, args) {
|
||||||
return Cipher._enc(CryptoJS.TripleDES, input, args);
|
return Cipher._enc(CryptoJS.TripleDES, input, args);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -209,9 +209,9 @@ var Cipher = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_triple_des_dec: function (input, args) {
|
run_triple_des_dec(input, args) {
|
||||||
return Cipher._dec(CryptoJS.TripleDES, input, args);
|
return Cipher._dec(CryptoJS.TripleDES, input, args);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -221,9 +221,9 @@ var Cipher = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_rabbit_enc: function (input, args) {
|
run_rabbit_enc(input, args) {
|
||||||
return Cipher._enc(CryptoJS.Rabbit, input, args);
|
return Cipher._enc(CryptoJS.Rabbit, input, args);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -233,21 +233,21 @@ var Cipher = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_rabbit_dec: function (input, args) {
|
run_rabbit_dec(input, args) {
|
||||||
return Cipher._dec(CryptoJS.Rabbit, input, args);
|
return Cipher._dec(CryptoJS.Rabbit, input, args);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
BLOWFISH_MODES: ["ECB", "CBC", "PCBC", "CFB", "OFB", "CTR"],
|
BLOWFISH_MODES: ['ECB', 'CBC', 'PCBC', 'CFB', 'OFB', 'CTR'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
BLOWFISH_OUTPUT_TYPES: ["Base64", "Hex", "String", "Raw"],
|
BLOWFISH_OUTPUT_TYPES: ['Base64', 'Hex', 'String', 'Raw'],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Blowfish Encrypt operation.
|
* Blowfish Encrypt operation.
|
||||||
|
@ -256,21 +256,21 @@ var Cipher = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_blowfish_enc: function (input, args) {
|
run_blowfish_enc(input, args) {
|
||||||
var key = Utils.format[args[0].option].parse(args[0].string).toString(Utils.format.Latin1),
|
let key = Utils.format[args[0].option].parse(args[0].string).toString(Utils.format.Latin1),
|
||||||
mode = args[1],
|
mode = args[1],
|
||||||
output_format = args[2];
|
output_format = args[2];
|
||||||
|
|
||||||
if (key.length === 0) return "Enter a key";
|
if (key.length === 0) return 'Enter a key';
|
||||||
|
|
||||||
var enc_hex = blowfish.encrypt(input, key, {
|
let enc_hex = blowfish.encrypt(input, key, {
|
||||||
outputType: 1,
|
outputType: 1,
|
||||||
cipherMode: Cipher.BLOWFISH_MODES.indexOf(mode)
|
cipherMode: Cipher.BLOWFISH_MODES.indexOf(mode),
|
||||||
}),
|
}),
|
||||||
enc = CryptoJS.enc.Hex.parse(enc_hex);
|
enc = CryptoJS.enc.Hex.parse(enc_hex);
|
||||||
|
|
||||||
return enc.toString(Utils.format[output_format]);
|
return enc.toString(Utils.format[output_format]);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -280,32 +280,32 @@ var Cipher = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_blowfish_dec: function (input, args) {
|
run_blowfish_dec(input, args) {
|
||||||
var key = Utils.format[args[0].option].parse(args[0].string).toString(Utils.format.Latin1),
|
let key = Utils.format[args[0].option].parse(args[0].string).toString(Utils.format.Latin1),
|
||||||
mode = args[1],
|
mode = args[1],
|
||||||
input_format = args[2];
|
input_format = args[2];
|
||||||
|
|
||||||
if (key.length === 0) return "Enter a key";
|
if (key.length === 0) return 'Enter a key';
|
||||||
|
|
||||||
input = Utils.format[input_format].parse(input);
|
input = Utils.format[input_format].parse(input);
|
||||||
|
|
||||||
return blowfish.decrypt(input.toString(CryptoJS.enc.Base64), key, {
|
return blowfish.decrypt(input.toString(CryptoJS.enc.Base64), key, {
|
||||||
outputType: 0, // This actually means inputType. The library is weird.
|
outputType: 0, // This actually means inputType. The library is weird.
|
||||||
cipherMode: Cipher.BLOWFISH_MODES.indexOf(mode)
|
cipherMode: Cipher.BLOWFISH_MODES.indexOf(mode),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
KDF_KEY_SIZE: 256,
|
KDF_KEY_SIZE: 256,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
KDF_ITERATIONS: 1,
|
KDF_ITERATIONS: 1,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Derive PBKDF2 key operation.
|
* Derive PBKDF2 key operation.
|
||||||
|
@ -314,17 +314,17 @@ var Cipher = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_pbkdf2: function (input, args) {
|
run_pbkdf2(input, args) {
|
||||||
var key_size = args[0] / 32,
|
let key_size = args[0] / 32,
|
||||||
iterations = args[1],
|
iterations = args[1],
|
||||||
salt = CryptoJS.enc.Hex.parse(args[2] || ""),
|
salt = CryptoJS.enc.Hex.parse(args[2] || ''),
|
||||||
input_format = args[3],
|
input_format = args[3],
|
||||||
output_format = args[4],
|
output_format = args[4],
|
||||||
passphrase = Utils.format[input_format].parse(input),
|
passphrase = Utils.format[input_format].parse(input),
|
||||||
key = CryptoJS.PBKDF2(passphrase, salt, { keySize: key_size, iterations: iterations });
|
key = CryptoJS.PBKDF2(passphrase, salt, { keySize: key_size, iterations });
|
||||||
|
|
||||||
return key.toString(Utils.format[output_format]);
|
return key.toString(Utils.format[output_format]);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -334,17 +334,17 @@ var Cipher = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_evpkdf: function (input, args) {
|
run_evpkdf(input, args) {
|
||||||
var key_size = args[0] / 32,
|
let key_size = args[0] / 32,
|
||||||
iterations = args[1],
|
iterations = args[1],
|
||||||
salt = CryptoJS.enc.Hex.parse(args[2] || ""),
|
salt = CryptoJS.enc.Hex.parse(args[2] || ''),
|
||||||
input_format = args[3],
|
input_format = args[3],
|
||||||
output_format = args[4],
|
output_format = args[4],
|
||||||
passphrase = Utils.format[input_format].parse(input),
|
passphrase = Utils.format[input_format].parse(input),
|
||||||
key = CryptoJS.EvpKDF(passphrase, salt, { keySize: key_size, iterations: iterations });
|
key = CryptoJS.EvpKDF(passphrase, salt, { keySize: key_size, iterations });
|
||||||
|
|
||||||
return key.toString(Utils.format[output_format]);
|
return key.toString(Utils.format[output_format]);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -354,20 +354,20 @@ var Cipher = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_rc4: function (input, args) {
|
run_rc4(input, args) {
|
||||||
var message = Utils.format[args[1]].parse(input),
|
let message = Utils.format[args[1]].parse(input),
|
||||||
passphrase = Utils.format[args[0].option].parse(args[0].string),
|
passphrase = Utils.format[args[0].option].parse(args[0].string),
|
||||||
encrypted = CryptoJS.RC4.encrypt(message, passphrase);
|
encrypted = CryptoJS.RC4.encrypt(message, passphrase);
|
||||||
|
|
||||||
return encrypted.ciphertext.toString(Utils.format[args[2]]);
|
return encrypted.ciphertext.toString(Utils.format[args[2]]);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
RC4DROP_BYTES: 768,
|
RC4DROP_BYTES: 768,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RC4 Drop operation.
|
* RC4 Drop operation.
|
||||||
|
@ -376,14 +376,14 @@ var Cipher = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_rc4drop: function (input, args) {
|
run_rc4drop(input, args) {
|
||||||
var message = Utils.format[args[1]].parse(input),
|
let message = Utils.format[args[1]].parse(input),
|
||||||
passphrase = Utils.format[args[0].option].parse(args[0].string),
|
passphrase = Utils.format[args[0].option].parse(args[0].string),
|
||||||
drop = args[3],
|
drop = args[3],
|
||||||
encrypted = CryptoJS.RC4Drop.encrypt(message, passphrase, { drop: drop });
|
encrypted = CryptoJS.RC4Drop.encrypt(message, passphrase, { drop });
|
||||||
|
|
||||||
return encrypted.ciphertext.toString(Utils.format[args[2]]);
|
return encrypted.ciphertext.toString(Utils.format[args[2]]);
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -413,17 +413,17 @@ var Cipher = {
|
||||||
CryptoJS.kdf.OpenSSL.execute = function (password, keySize, ivSize, salt) {
|
CryptoJS.kdf.OpenSSL.execute = function (password, keySize, ivSize, salt) {
|
||||||
// Generate random salt if no salt specified and not set to false
|
// Generate random salt if no salt specified and not set to false
|
||||||
// This line changed from `if (!salt) {` to the following
|
// This line changed from `if (!salt) {` to the following
|
||||||
if (salt === undefined || salt === null) {
|
if (salt === undefined || salt === null) {
|
||||||
salt = CryptoJS.lib.WordArray.random(64/8);
|
salt = CryptoJS.lib.WordArray.random(64 / 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Derive key and IV
|
// Derive key and IV
|
||||||
var key = CryptoJS.algo.EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt);
|
const key = CryptoJS.algo.EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt);
|
||||||
|
|
||||||
// Separate key and IV
|
// Separate key and IV
|
||||||
var iv = CryptoJS.lib.WordArray.create(key.words.slice(keySize), ivSize * 4);
|
const iv = CryptoJS.lib.WordArray.create(key.words.slice(keySize), ivSize * 4);
|
||||||
key.sigBytes = keySize * 4;
|
key.sigBytes = keySize * 4;
|
||||||
|
|
||||||
// Return params
|
// Return params
|
||||||
return CryptoJS.lib.CipherParams.create({ key: key, iv: iv, salt: salt });
|
return CryptoJS.lib.CipherParams.create({ key, iv, salt });
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,18 +9,18 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var Code = {
|
const Code = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
LANGUAGES: ["default-code", "default-markup", "bash", "bsh", "c", "cc", "coffee", "cpp", "cs", "csh", "cv", "cxx", "cyc", "htm", "html", "in.tag", "java", "javascript", "js", "json", "m", "mxml", "perl", "pl", "pm", "py", "python", "rb", "rc", "rs", "ruby", "rust", "sh", "uq.val", "xhtml", "xml", "xsl"],
|
LANGUAGES: ['default-code', 'default-markup', 'bash', 'bsh', 'c', 'cc', 'coffee', 'cpp', 'cs', 'csh', 'cv', 'cxx', 'cyc', 'htm', 'html', 'in.tag', 'java', 'javascript', 'js', 'json', 'm', 'mxml', 'perl', 'pl', 'pm', 'py', 'python', 'rb', 'rc', 'rs', 'ruby', 'rust', 'sh', 'uq.val', 'xhtml', 'xml', 'xsl'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
LINE_NUMS: false,
|
LINE_NUMS: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Syntax highlighter operation.
|
* Syntax highlighter operation.
|
||||||
|
@ -29,18 +29,18 @@ var Code = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {html}
|
* @returns {html}
|
||||||
*/
|
*/
|
||||||
run_syntax_highlight: function(input, args) {
|
run_syntax_highlight(input, args) {
|
||||||
var language = args[0],
|
let language = args[0],
|
||||||
line_nums = args[1];
|
line_nums = args[1];
|
||||||
return "<code class='prettyprint'>" + prettyPrintOne(Utils.escape_html(input), language, line_nums) + "</code>";
|
return `<code class='prettyprint'>${prettyPrintOne(Utils.escape_html(input), language, line_nums)}</code>`;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
BEAUTIFY_INDENT: "\\t",
|
BEAUTIFY_INDENT: '\\t',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XML Beautify operation.
|
* XML Beautify operation.
|
||||||
|
@ -49,10 +49,10 @@ var Code = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_xml_beautify: function(input, args) {
|
run_xml_beautify(input, args) {
|
||||||
var indent_str = args[0];
|
const indent_str = args[0];
|
||||||
return vkbeautify.xml(input, indent_str);
|
return vkbeautify.xml(input, indent_str);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -62,10 +62,10 @@ var Code = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_json_beautify: function(input, args) {
|
run_json_beautify(input, args) {
|
||||||
var indent_str = args[0];
|
const indent_str = args[0];
|
||||||
return vkbeautify.json(input, indent_str);
|
return vkbeautify.json(input, indent_str);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -75,10 +75,10 @@ var Code = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_css_beautify: function(input, args) {
|
run_css_beautify(input, args) {
|
||||||
var indent_str = args[0];
|
const indent_str = args[0];
|
||||||
return vkbeautify.css(input, indent_str);
|
return vkbeautify.css(input, indent_str);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -88,17 +88,17 @@ var Code = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_sql_beautify: function(input, args) {
|
run_sql_beautify(input, args) {
|
||||||
var indent_str = args[0];
|
const indent_str = args[0];
|
||||||
return vkbeautify.sql(input, indent_str);
|
return vkbeautify.sql(input, indent_str);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
PRESERVE_COMMENTS: false,
|
PRESERVE_COMMENTS: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* XML Minify operation.
|
* XML Minify operation.
|
||||||
|
@ -107,10 +107,10 @@ var Code = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_xml_minify: function(input, args) {
|
run_xml_minify(input, args) {
|
||||||
var preserve_comments = args[0];
|
const preserve_comments = args[0];
|
||||||
return vkbeautify.xmlmin(input, preserve_comments);
|
return vkbeautify.xmlmin(input, preserve_comments);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -120,9 +120,9 @@ var Code = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_json_minify: function(input, args) {
|
run_json_minify(input, args) {
|
||||||
return vkbeautify.jsonmin(input);
|
return vkbeautify.jsonmin(input);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -132,10 +132,10 @@ var Code = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_css_minify: function(input, args) {
|
run_css_minify(input, args) {
|
||||||
var preserve_comments = args[0];
|
const preserve_comments = args[0];
|
||||||
return vkbeautify.cssmin(input, preserve_comments);
|
return vkbeautify.cssmin(input, preserve_comments);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -145,9 +145,9 @@ var Code = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_sql_minify: function(input, args) {
|
run_sql_minify(input, args) {
|
||||||
return vkbeautify.sqlmin(input);
|
return vkbeautify.sqlmin(input);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -173,133 +173,133 @@ var Code = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_generic_beautify: function(input, args) {
|
run_generic_beautify(input, args) {
|
||||||
var code = input,
|
let code = input,
|
||||||
t = 0,
|
t = 0,
|
||||||
preserved_tokens = [],
|
preserved_tokens = [],
|
||||||
m;
|
m;
|
||||||
|
|
||||||
// Remove strings
|
// Remove strings
|
||||||
var sstrings = /'([^'\\]|\\.)*'/g;
|
const sstrings = /'([^'\\]|\\.)*'/g;
|
||||||
while (!!(m = sstrings.exec(code))) {
|
while (m = sstrings.exec(code)) {
|
||||||
code = preserve_token(code, m, t++);
|
code = preserve_token(code, m, t++);
|
||||||
sstrings.lastIndex = m.index;
|
sstrings.lastIndex = m.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
var dstrings = /"([^"\\]|\\.)*"/g;
|
const dstrings = /"([^"\\]|\\.)*"/g;
|
||||||
while (!!(m = dstrings.exec(code))) {
|
while (m = dstrings.exec(code)) {
|
||||||
code = preserve_token(code, m, t++);
|
code = preserve_token(code, m, t++);
|
||||||
dstrings.lastIndex = m.index;
|
dstrings.lastIndex = m.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove comments
|
// Remove comments
|
||||||
var scomments = /\/\/[^\n\r]*/g;
|
const scomments = /\/\/[^\n\r]*/g;
|
||||||
while (!!(m = scomments.exec(code))) {
|
while (m = scomments.exec(code)) {
|
||||||
code = preserve_token(code, m, t++);
|
code = preserve_token(code, m, t++);
|
||||||
scomments.lastIndex = m.index;
|
scomments.lastIndex = m.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
var mcomments = /\/\*[\s\S]*?\*\//gm;
|
const mcomments = /\/\*[\s\S]*?\*\//gm;
|
||||||
while (!!(m = mcomments.exec(code))) {
|
while (m = mcomments.exec(code)) {
|
||||||
code = preserve_token(code, m, t++);
|
code = preserve_token(code, m, t++);
|
||||||
mcomments.lastIndex = m.index;
|
mcomments.lastIndex = m.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
var hcomments = /(^|\n)#[^\n\r#]+/g;
|
const hcomments = /(^|\n)#[^\n\r#]+/g;
|
||||||
while (!!(m = hcomments.exec(code))) {
|
while (m = hcomments.exec(code)) {
|
||||||
code = preserve_token(code, m, t++);
|
code = preserve_token(code, m, t++);
|
||||||
hcomments.lastIndex = m.index;
|
hcomments.lastIndex = m.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove regexes
|
// Remove regexes
|
||||||
var regexes = /\/.*?[^\\]\/[gim]{0,3}/gi;
|
const regexes = /\/.*?[^\\]\/[gim]{0,3}/gi;
|
||||||
while (!!(m = regexes.exec(code))) {
|
while (m = regexes.exec(code)) {
|
||||||
code = preserve_token(code, m, t++);
|
code = preserve_token(code, m, t++);
|
||||||
regexes.lastIndex = m.index;
|
regexes.lastIndex = m.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create newlines after ;
|
// Create newlines after ;
|
||||||
code = code.replace(/;/g, ";\n");
|
code = code.replace(/;/g, ';\n');
|
||||||
|
|
||||||
// Create newlines after { and around }
|
// Create newlines after { and around }
|
||||||
code = code.replace(/{/g, "{\n");
|
code = code.replace(/{/g, '{\n');
|
||||||
code = code.replace(/}/g, "\n}\n");
|
code = code.replace(/}/g, '\n}\n');
|
||||||
|
|
||||||
// Remove carriage returns
|
// Remove carriage returns
|
||||||
code = code.replace(/\r/g, "");
|
code = code.replace(/\r/g, '');
|
||||||
|
|
||||||
// Remove all indentation
|
// Remove all indentation
|
||||||
code = code.replace(/^\s+/g, "");
|
code = code.replace(/^\s+/g, '');
|
||||||
code = code.replace(/\n\s+/g, "\n");
|
code = code.replace(/\n\s+/g, '\n');
|
||||||
|
|
||||||
// Remove trailing spaces
|
// Remove trailing spaces
|
||||||
code = code.replace(/\s*$/g, "");
|
code = code.replace(/\s*$/g, '');
|
||||||
|
|
||||||
// Remove newlines before {
|
// Remove newlines before {
|
||||||
code = code.replace(/\n{/g, "{");
|
code = code.replace(/\n{/g, '{');
|
||||||
|
|
||||||
// Indent
|
// Indent
|
||||||
var i = 0,
|
let i = 0,
|
||||||
level = 0;
|
level = 0;
|
||||||
while (i < code.length) {
|
while (i < code.length) {
|
||||||
switch(code[i]) {
|
switch (code[i]) {
|
||||||
case "{":
|
case '{':
|
||||||
level++;
|
level++;
|
||||||
break;
|
break;
|
||||||
case "\n":
|
case '\n':
|
||||||
if (i+1 >= code.length) break;
|
if (i + 1 >= code.length) break;
|
||||||
|
|
||||||
if (code[i+1] == "}") level--;
|
if (code[i + 1] == '}') level--;
|
||||||
var indent = (level >= 0) ? Array(level*4+1).join(" ") : "";
|
var indent = (level >= 0) ? Array(level * 4 + 1).join(' ') : '';
|
||||||
|
|
||||||
code = code.substring(0, i+1) + indent + code.substring(i+1);
|
code = code.substring(0, i + 1) + indent + code.substring(i + 1);
|
||||||
if (level > 0) i += level*4;
|
if (level > 0) i += level * 4;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add strategic spaces
|
// Add strategic spaces
|
||||||
code = code.replace(/\s*([!<>=+-/*]?)=\s*/g, " $1= ");
|
code = code.replace(/\s*([!<>=+-/*]?)=\s*/g, ' $1= ');
|
||||||
code = code.replace(/\s*<([=]?)\s*/g, " <$1 ");
|
code = code.replace(/\s*<([=]?)\s*/g, ' <$1 ');
|
||||||
code = code.replace(/\s*>([=]?)\s*/g, " >$1 ");
|
code = code.replace(/\s*>([=]?)\s*/g, ' >$1 ');
|
||||||
code = code.replace(/([^+])\+([^+=])/g, "$1 + $2");
|
code = code.replace(/([^+])\+([^+=])/g, '$1 + $2');
|
||||||
code = code.replace(/([^-])-([^-=])/g, "$1 - $2");
|
code = code.replace(/([^-])-([^-=])/g, '$1 - $2');
|
||||||
code = code.replace(/([^*])\*([^*=])/g, "$1 * $2");
|
code = code.replace(/([^*])\*([^*=])/g, '$1 * $2');
|
||||||
code = code.replace(/([^/])\/([^/=])/g, "$1 / $2");
|
code = code.replace(/([^/])\/([^/=])/g, '$1 / $2');
|
||||||
code = code.replace(/\s*,\s*/g, ", ");
|
code = code.replace(/\s*,\s*/g, ', ');
|
||||||
code = code.replace(/\s*{/g, " {");
|
code = code.replace(/\s*{/g, ' {');
|
||||||
code = code.replace(/}\n/g, "}\n\n");
|
code = code.replace(/}\n/g, '}\n\n');
|
||||||
|
|
||||||
// Just... don't look at this
|
// Just... don't look at this
|
||||||
code = code.replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)\s*\n([^{])/gim, "$1 ($2)\n $3");
|
code = code.replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)\s*\n([^{])/gim, '$1 ($2)\n $3');
|
||||||
code = code.replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)([^{])/gim, "$1 ($2) $3");
|
code = code.replace(/(if|for|while|with|elif|elseif)\s*\(([^\n]*)\)([^{])/gim, '$1 ($2) $3');
|
||||||
code = code.replace(/else\s*\n([^{])/gim, "else\n $1");
|
code = code.replace(/else\s*\n([^{])/gim, 'else\n $1');
|
||||||
code = code.replace(/else\s+([^{])/gim, "else $1");
|
code = code.replace(/else\s+([^{])/gim, 'else $1');
|
||||||
|
|
||||||
// Remove strategic spaces
|
// Remove strategic spaces
|
||||||
code = code.replace(/\s+;/g, ";");
|
code = code.replace(/\s+;/g, ';');
|
||||||
code = code.replace(/\{\s+\}/g, "{}");
|
code = code.replace(/\{\s+\}/g, '{}');
|
||||||
code = code.replace(/\[\s+\]/g, "[]");
|
code = code.replace(/\[\s+\]/g, '[]');
|
||||||
code = code.replace(/}\s*(else|catch|except|finally|elif|elseif|else if)/gi, "} $1");
|
code = code.replace(/}\s*(else|catch|except|finally|elif|elseif|else if)/gi, '} $1');
|
||||||
|
|
||||||
|
|
||||||
// Replace preserved tokens
|
// Replace preserved tokens
|
||||||
var ptokens = /###preserved_token(\d+)###/g;
|
const ptokens = /###preserved_token(\d+)###/g;
|
||||||
while (!!(m = ptokens.exec(code))) {
|
while (m = ptokens.exec(code)) {
|
||||||
var ti = parseInt(m[1]);
|
const ti = parseInt(m[1]);
|
||||||
code = code.substring(0, m.index) + preserved_tokens[ti] + code.substring(m.index + m[0].length);
|
code = code.substring(0, m.index) + preserved_tokens[ti] + code.substring(m.index + m[0].length);
|
||||||
ptokens.lastIndex = m.index;
|
ptokens.lastIndex = m.index;
|
||||||
}
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
|
|
||||||
function preserve_token(str, match, t) {
|
function preserve_token(str, match, t) {
|
||||||
preserved_tokens[t] = match[0];
|
preserved_tokens[t] = match[0];
|
||||||
return str.substring(0, match.index) +
|
return `${str.substring(0, match.index)
|
||||||
"###preserved_token" + t + "###" +
|
}###preserved_token${t}###${
|
||||||
str.substring(match.index + match[0].length);
|
str.substring(match.index + match[0].length)}`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,37 +9,37 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var Compress = {
|
const Compress = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
COMPRESSION_TYPE: ["Dynamic Huffman Coding", "Fixed Huffman Coding", "None (Store)"],
|
COMPRESSION_TYPE: ['Dynamic Huffman Coding', 'Fixed Huffman Coding', 'None (Store)'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
INFLATE_BUFFER_TYPE: ["Adaptive", "Block"],
|
INFLATE_BUFFER_TYPE: ['Adaptive', 'Block'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
COMPRESSION_METHOD: ["Deflate", "None (Store)"],
|
COMPRESSION_METHOD: ['Deflate', 'None (Store)'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
OS: ["MSDOS", "Unix", "Macintosh"],
|
OS: ['MSDOS', 'Unix', 'Macintosh'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
RAW_COMPRESSION_TYPE_LOOKUP: {
|
RAW_COMPRESSION_TYPE_LOOKUP: {
|
||||||
"Fixed Huffman Coding" : Zlib.RawDeflate.CompressionType.FIXED,
|
'Fixed Huffman Coding': Zlib.RawDeflate.CompressionType.FIXED,
|
||||||
"Dynamic Huffman Coding" : Zlib.RawDeflate.CompressionType.DYNAMIC,
|
'Dynamic Huffman Coding': Zlib.RawDeflate.CompressionType.DYNAMIC,
|
||||||
"None (Store)" : Zlib.RawDeflate.CompressionType.NONE,
|
'None (Store)': Zlib.RawDeflate.CompressionType.NONE,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Raw Deflate operation.
|
* Raw Deflate operation.
|
||||||
|
@ -48,42 +48,42 @@ var Compress = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_raw_deflate: function(input, args) {
|
run_raw_deflate(input, args) {
|
||||||
var deflate = new Zlib.RawDeflate(input, {
|
const deflate = new Zlib.RawDeflate(input, {
|
||||||
compressionType: Compress.RAW_COMPRESSION_TYPE_LOOKUP[args[0]]
|
compressionType: Compress.RAW_COMPRESSION_TYPE_LOOKUP[args[0]],
|
||||||
});
|
});
|
||||||
return Array.prototype.slice.call(deflate.compress());
|
return Array.prototype.slice.call(deflate.compress());
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
INFLATE_INDEX: 0,
|
INFLATE_INDEX: 0,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
INFLATE_BUFFER_SIZE: 0,
|
INFLATE_BUFFER_SIZE: 0,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
INFLATE_RESIZE: false,
|
INFLATE_RESIZE: false,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
INFLATE_VERIFY: false,
|
INFLATE_VERIFY: false,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
RAW_BUFFER_TYPE_LOOKUP: {
|
RAW_BUFFER_TYPE_LOOKUP: {
|
||||||
"Adaptive" : Zlib.RawInflate.BufferType.ADAPTIVE,
|
Adaptive: Zlib.RawInflate.BufferType.ADAPTIVE,
|
||||||
"Block" : Zlib.RawInflate.BufferType.BLOCK,
|
Block: Zlib.RawInflate.BufferType.BLOCK,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Raw Inflate operation.
|
* Raw Inflate operation.
|
||||||
|
@ -92,50 +92,50 @@ var Compress = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_raw_inflate: function(input, args) {
|
run_raw_inflate(input, args) {
|
||||||
// Deal with character encoding issues
|
// Deal with character encoding issues
|
||||||
input = Utils.str_to_byte_array(Utils.byte_array_to_utf8(input));
|
input = Utils.str_to_byte_array(Utils.byte_array_to_utf8(input));
|
||||||
var inflate = new Zlib.RawInflate(input, {
|
let inflate = new Zlib.RawInflate(input, {
|
||||||
index: args[0],
|
index: args[0],
|
||||||
bufferSize: args[1],
|
bufferSize: args[1],
|
||||||
bufferType: Compress.RAW_BUFFER_TYPE_LOOKUP[args[2]],
|
bufferType: Compress.RAW_BUFFER_TYPE_LOOKUP[args[2]],
|
||||||
resize: args[3],
|
resize: args[3],
|
||||||
verify: args[4]
|
verify: args[4],
|
||||||
}),
|
}),
|
||||||
result = Array.prototype.slice.call(inflate.decompress());
|
result = Array.prototype.slice.call(inflate.decompress());
|
||||||
|
|
||||||
// Raw Inflate somethimes messes up and returns nonsense like this:
|
// Raw Inflate somethimes messes up and returns nonsense like this:
|
||||||
// ]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]...
|
// ]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]....]...
|
||||||
// e.g. Input data of [8b, 1d, dc, 44]
|
// e.g. Input data of [8b, 1d, dc, 44]
|
||||||
// Look for the first two square brackets:
|
// Look for the first two square brackets:
|
||||||
if (result.length > 158 && result[0] == 93 && result[5] == 93) {
|
if (result.length > 158 && result[0] == 93 && result[5] == 93) {
|
||||||
// If the first two square brackets are there, check that the others
|
// If the first two square brackets are there, check that the others
|
||||||
// are also there. If they are, throw an error. If not, continue.
|
// are also there. If they are, throw an error. If not, continue.
|
||||||
var valid = false;
|
let valid = false;
|
||||||
for (var i = 0; i < 155; i += 5) {
|
for (let i = 0; i < 155; i += 5) {
|
||||||
if (result[i] != 93) {
|
if (result[i] != 93) {
|
||||||
valid = true;
|
valid = true;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!valid) {
|
|
||||||
throw "Error: Unable to inflate data";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!valid) {
|
||||||
|
throw 'Error: Unable to inflate data';
|
||||||
|
}
|
||||||
|
}
|
||||||
// Trust me, this is the easiest way...
|
// Trust me, this is the easiest way...
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
ZLIB_COMPRESSION_TYPE_LOOKUP: {
|
ZLIB_COMPRESSION_TYPE_LOOKUP: {
|
||||||
"Fixed Huffman Coding" : Zlib.Deflate.CompressionType.FIXED,
|
'Fixed Huffman Coding': Zlib.Deflate.CompressionType.FIXED,
|
||||||
"Dynamic Huffman Coding" : Zlib.Deflate.CompressionType.DYNAMIC,
|
'Dynamic Huffman Coding': Zlib.Deflate.CompressionType.DYNAMIC,
|
||||||
"None (Store)" : Zlib.Deflate.CompressionType.NONE,
|
'None (Store)': Zlib.Deflate.CompressionType.NONE,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zlib Deflate operation.
|
* Zlib Deflate operation.
|
||||||
|
@ -144,22 +144,22 @@ var Compress = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_zlib_deflate: function(input, args) {
|
run_zlib_deflate(input, args) {
|
||||||
var deflate = new Zlib.Deflate(input, {
|
const deflate = new Zlib.Deflate(input, {
|
||||||
compressionType: Compress.ZLIB_COMPRESSION_TYPE_LOOKUP[args[0]]
|
compressionType: Compress.ZLIB_COMPRESSION_TYPE_LOOKUP[args[0]],
|
||||||
});
|
});
|
||||||
return Array.prototype.slice.call(deflate.compress());
|
return Array.prototype.slice.call(deflate.compress());
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
ZLIB_BUFFER_TYPE_LOOKUP: {
|
ZLIB_BUFFER_TYPE_LOOKUP: {
|
||||||
"Adaptive" : Zlib.Inflate.BufferType.ADAPTIVE,
|
Adaptive: Zlib.Inflate.BufferType.ADAPTIVE,
|
||||||
"Block" : Zlib.Inflate.BufferType.BLOCK,
|
Block: Zlib.Inflate.BufferType.BLOCK,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zlib Inflate operation.
|
* Zlib Inflate operation.
|
||||||
|
@ -168,25 +168,25 @@ var Compress = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_zlib_inflate: function(input, args) {
|
run_zlib_inflate(input, args) {
|
||||||
// Deal with character encoding issues
|
// Deal with character encoding issues
|
||||||
input = Utils.str_to_byte_array(Utils.byte_array_to_utf8(input));
|
input = Utils.str_to_byte_array(Utils.byte_array_to_utf8(input));
|
||||||
var inflate = new Zlib.Inflate(input, {
|
const inflate = new Zlib.Inflate(input, {
|
||||||
index: args[0],
|
index: args[0],
|
||||||
bufferSize: args[1],
|
bufferSize: args[1],
|
||||||
bufferType: Compress.ZLIB_BUFFER_TYPE_LOOKUP[args[2]],
|
bufferType: Compress.ZLIB_BUFFER_TYPE_LOOKUP[args[2]],
|
||||||
resize: args[3],
|
resize: args[3],
|
||||||
verify: args[4]
|
verify: args[4],
|
||||||
});
|
});
|
||||||
return Array.prototype.slice.call(inflate.decompress());
|
return Array.prototype.slice.call(inflate.decompress());
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
GZIP_CHECKSUM: false,
|
GZIP_CHECKSUM: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gzip operation.
|
* Gzip operation.
|
||||||
|
@ -195,30 +195,30 @@ var Compress = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_gzip: function(input, args) {
|
run_gzip(input, args) {
|
||||||
var filename = args[1],
|
let filename = args[1],
|
||||||
comment = args[2],
|
comment = args[2],
|
||||||
options = {
|
options = {
|
||||||
deflateOptions: {
|
deflateOptions: {
|
||||||
compressionType: Compress.ZLIB_COMPRESSION_TYPE_LOOKUP[args[0]]
|
compressionType: Compress.ZLIB_COMPRESSION_TYPE_LOOKUP[args[0]],
|
||||||
},
|
},
|
||||||
flags: {
|
flags: {
|
||||||
fhcrc: args[3]
|
fhcrc: args[3],
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
if (filename.length) {
|
if (filename.length) {
|
||||||
options.flags.fname = true;
|
options.flags.fname = true;
|
||||||
options.filename = filename;
|
options.filename = filename;
|
||||||
}
|
}
|
||||||
if (comment.length) {
|
if (comment.length) {
|
||||||
options.flags.fcommenct = true;
|
options.flags.fcommenct = true;
|
||||||
options.comment = comment;
|
options.comment = comment;
|
||||||
}
|
}
|
||||||
|
|
||||||
var gzip = new Zlib.Gzip(input, options);
|
const gzip = new Zlib.Gzip(input, options);
|
||||||
return Array.prototype.slice.call(gzip.compress());
|
return Array.prototype.slice.call(gzip.compress());
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -228,36 +228,36 @@ var Compress = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_gunzip: function(input, args) {
|
run_gunzip(input, args) {
|
||||||
// Deal with character encoding issues
|
// Deal with character encoding issues
|
||||||
input = Utils.str_to_byte_array(Utils.byte_array_to_utf8(input));
|
input = Utils.str_to_byte_array(Utils.byte_array_to_utf8(input));
|
||||||
var gunzip = new Zlib.Gunzip(input);
|
const gunzip = new Zlib.Gunzip(input);
|
||||||
return Array.prototype.slice.call(gunzip.decompress());
|
return Array.prototype.slice.call(gunzip.decompress());
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
PKZIP_FILENAME: "file.txt",
|
PKZIP_FILENAME: 'file.txt',
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
ZIP_COMPRESSION_METHOD_LOOKUP: {
|
ZIP_COMPRESSION_METHOD_LOOKUP: {
|
||||||
"Deflate" : Zlib.Zip.CompressionMethod.DEFLATE,
|
Deflate: Zlib.Zip.CompressionMethod.DEFLATE,
|
||||||
"None (Store)" : Zlib.Zip.CompressionMethod.STORE
|
'None (Store)': Zlib.Zip.CompressionMethod.STORE,
|
||||||
},
|
},
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
ZIP_OS_LOOKUP: {
|
ZIP_OS_LOOKUP: {
|
||||||
"MSDOS" : Zlib.Zip.OperatingSystem.MSDOS,
|
MSDOS: Zlib.Zip.OperatingSystem.MSDOS,
|
||||||
"Unix" : Zlib.Zip.OperatingSystem.UNIX,
|
Unix: Zlib.Zip.OperatingSystem.UNIX,
|
||||||
"Macintosh" : Zlib.Zip.OperatingSystem.MACINTOSH
|
Macintosh: Zlib.Zip.OperatingSystem.MACINTOSH,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zip operation.
|
* Zip operation.
|
||||||
|
@ -266,31 +266,30 @@ var Compress = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_pkzip: function(input, args) {
|
run_pkzip(input, args) {
|
||||||
var password = Utils.str_to_byte_array(args[2]),
|
let password = Utils.str_to_byte_array(args[2]),
|
||||||
options = {
|
options = {
|
||||||
filename: Utils.str_to_byte_array(args[0]),
|
filename: Utils.str_to_byte_array(args[0]),
|
||||||
comment: Utils.str_to_byte_array(args[1]),
|
comment: Utils.str_to_byte_array(args[1]),
|
||||||
compressionMethod: Compress.ZIP_COMPRESSION_METHOD_LOOKUP[args[3]],
|
compressionMethod: Compress.ZIP_COMPRESSION_METHOD_LOOKUP[args[3]],
|
||||||
os: Compress.ZIP_OS_LOOKUP[args[4]],
|
os: Compress.ZIP_OS_LOOKUP[args[4]],
|
||||||
deflateOption: {
|
deflateOption: {
|
||||||
compressionType: Compress.ZLIB_COMPRESSION_TYPE_LOOKUP[args[5]]
|
compressionType: Compress.ZLIB_COMPRESSION_TYPE_LOOKUP[args[5]],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
zip = new Zlib.Zip();
|
zip = new Zlib.Zip();
|
||||||
|
|
||||||
if (password.length)
|
if (password.length) { zip.setPassword(password); }
|
||||||
zip.setPassword(password);
|
zip.addFile(input, options);
|
||||||
zip.addFile(input, options);
|
return Array.prototype.slice.call(zip.compress());
|
||||||
return Array.prototype.slice.call(zip.compress());
|
},
|
||||||
},
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
PKUNZIP_VERIFY: false,
|
PKUNZIP_VERIFY: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unzip operation.
|
* Unzip operation.
|
||||||
|
@ -299,34 +298,34 @@ var Compress = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_pkunzip: function(input, args) {
|
run_pkunzip(input, args) {
|
||||||
var options = {
|
let options = {
|
||||||
password: Utils.str_to_byte_array(args[0]),
|
password: Utils.str_to_byte_array(args[0]),
|
||||||
verify: args[1]
|
verify: args[1],
|
||||||
},
|
},
|
||||||
file = "",
|
file = '',
|
||||||
unzip = new Zlib.Unzip(input, options),
|
unzip = new Zlib.Unzip(input, options),
|
||||||
filenames = unzip.getFilenames(),
|
filenames = unzip.getFilenames(),
|
||||||
output = "<div style='padding: 5px;'>" + filenames.length + " file(s) found</div>\n";
|
output = `<div style='padding: 5px;'>${filenames.length} file(s) found</div>\n`;
|
||||||
|
|
||||||
output += "<div class='panel-group' id='zip-accordion' role='tablist' aria-multiselectable='true'>";
|
output += "<div class='panel-group' id='zip-accordion' role='tablist' aria-multiselectable='true'>";
|
||||||
|
|
||||||
window.uzip = unzip;
|
window.uzip = unzip;
|
||||||
for (var i = 0; i < filenames.length; i++) {
|
for (let i = 0; i < filenames.length; i++) {
|
||||||
file = Utils.byte_array_to_utf8(unzip.decompress(filenames[i]));
|
file = Utils.byte_array_to_utf8(unzip.decompress(filenames[i]));
|
||||||
output += "<div class='panel panel-default'>" +
|
output += `${"<div class='panel panel-default'>" +
|
||||||
"<div class='panel-heading' role='tab' id='heading" + i + "'>" +
|
"<div class='panel-heading' role='tab' id='heading"}${i}'>` +
|
||||||
"<h4 class='panel-title'>" +
|
'<h4 class=\'panel-title\'>' +
|
||||||
"<a class='collapsed' role='button' data-toggle='collapse' data-parent='#zip-accordion' href='#collapse" + i +
|
`<a class='collapsed' role='button' data-toggle='collapse' data-parent='#zip-accordion' href='#collapse${i
|
||||||
"' aria-expanded='true' aria-controls='collapse" + i + "'>" +
|
}' aria-expanded='true' aria-controls='collapse${i}'>${
|
||||||
filenames[i] + "<span class='pull-right'>" + file.length.toLocaleString() + " bytes</span></a></h4></div>" +
|
filenames[i]}<span class='pull-right'>${file.length.toLocaleString()} bytes</span></a></h4></div>` +
|
||||||
"<div id='collapse" + i + "' class='panel-collapse collapse' role='tabpanel' aria-labelledby='heading" + i + "'>" +
|
`<div id='collapse${i}' class='panel-collapse collapse' role='tabpanel' aria-labelledby='heading${i}'>` +
|
||||||
"<div class='panel-body'>" +
|
`<div class='panel-body'>${
|
||||||
Utils.escape_html(file) + "</div></div></div>";
|
Utils.escape_html(file)}</div></div></div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return output + "</div>";
|
return `${output}</div>`;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -336,14 +335,14 @@ var Compress = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_bzip2_decompress: function(input, args) {
|
run_bzip2_decompress(input, args) {
|
||||||
var compressed = new Uint8Array(input),
|
let compressed = new Uint8Array(input),
|
||||||
bzip2_reader,
|
bzip2_reader,
|
||||||
plain = "";
|
plain = '';
|
||||||
|
|
||||||
bzip2_reader = bzip2.array(compressed);
|
bzip2_reader = bzip2.array(compressed);
|
||||||
plain = bzip2.simple(bzip2_reader);
|
plain = bzip2.simple(bzip2_reader);
|
||||||
return plain;
|
return plain;
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,55 +7,55 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var Convert = {
|
const Convert = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
DISTANCE_UNITS: [
|
DISTANCE_UNITS: [
|
||||||
"[Metric]", "Nanometres (nm)", "Micrometres (µm)", "Millimetres (mm)", "Centimetres (cm)", "Metres (m)", "Kilometers (km)", "[/Metric]",
|
'[Metric]', 'Nanometres (nm)', 'Micrometres (µm)', 'Millimetres (mm)', 'Centimetres (cm)', 'Metres (m)', 'Kilometers (km)', '[/Metric]',
|
||||||
"[Imperial]", "Thou (th)", "Inches (in)", "Feet (ft)", "Yards (yd)", "Chains (ch)", "Furlongs (fur)", "Miles (mi)", "Leagues (lea)", "[/Imperial]",
|
'[Imperial]', 'Thou (th)', 'Inches (in)', 'Feet (ft)', 'Yards (yd)', 'Chains (ch)', 'Furlongs (fur)', 'Miles (mi)', 'Leagues (lea)', '[/Imperial]',
|
||||||
"[Maritime]", "Fathoms (ftm)", "Cables", "Nautical miles", "[/Maritime]",
|
'[Maritime]', 'Fathoms (ftm)', 'Cables', 'Nautical miles', '[/Maritime]',
|
||||||
"[Comparisons]", "Cars (4m)", "Buses (8.4m)", "American football fields (91m)", "Football pitches (105m)", "[/Comparisons]",
|
'[Comparisons]', 'Cars (4m)', 'Buses (8.4m)', 'American football fields (91m)', 'Football pitches (105m)', '[/Comparisons]',
|
||||||
"[Astronomical]", "Earth-to-Moons", "Earth's equators", "Astronomical units (au)", "Light-years (ly)", "Parsecs (pc)", "[/Astronomical]",
|
'[Astronomical]', 'Earth-to-Moons', "Earth's equators", 'Astronomical units (au)', 'Light-years (ly)', 'Parsecs (pc)', '[/Astronomical]',
|
||||||
],
|
],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
DISTANCE_FACTOR: { // Multiples of a metre
|
DISTANCE_FACTOR: { // Multiples of a metre
|
||||||
"Nanometres (nm)" : 1e-9,
|
'Nanometres (nm)': 1e-9,
|
||||||
"Micrometres (µm)" : 1e-6,
|
'Micrometres (µm)': 1e-6,
|
||||||
"Millimetres (mm)" : 1e-3,
|
'Millimetres (mm)': 1e-3,
|
||||||
"Centimetres (cm)" : 1e-2,
|
'Centimetres (cm)': 1e-2,
|
||||||
"Metres (m)" : 1,
|
'Metres (m)': 1,
|
||||||
"Kilometers (km)" : 1e3,
|
'Kilometers (km)': 1e3,
|
||||||
|
|
||||||
"Thou (th)" : 0.0000254,
|
'Thou (th)': 0.0000254,
|
||||||
"Inches (in)" : 0.0254,
|
'Inches (in)': 0.0254,
|
||||||
"Feet (ft)" : 0.3048,
|
'Feet (ft)': 0.3048,
|
||||||
"Yards (yd)" : 0.9144,
|
'Yards (yd)': 0.9144,
|
||||||
"Chains (ch)" : 20.1168,
|
'Chains (ch)': 20.1168,
|
||||||
"Furlongs (fur)" : 201.168,
|
'Furlongs (fur)': 201.168,
|
||||||
"Miles (mi)" : 1609.344,
|
'Miles (mi)': 1609.344,
|
||||||
"Leagues (lea)" : 4828.032,
|
'Leagues (lea)': 4828.032,
|
||||||
|
|
||||||
"Fathoms (ftm)" : 1.853184,
|
'Fathoms (ftm)': 1.853184,
|
||||||
"Cables" : 185.3184,
|
Cables: 185.3184,
|
||||||
"Nautical miles" : 1853.184,
|
'Nautical miles': 1853.184,
|
||||||
|
|
||||||
"Cars (4m)" : 4,
|
'Cars (4m)': 4,
|
||||||
"Buses (8.4m)" : 8.4,
|
'Buses (8.4m)': 8.4,
|
||||||
"American football fields (91m)": 91,
|
'American football fields (91m)': 91,
|
||||||
"Football pitches (105m)": 105,
|
'Football pitches (105m)': 105,
|
||||||
|
|
||||||
"Earth-to-Moons" : 380000000,
|
'Earth-to-Moons': 380000000,
|
||||||
"Earth's equators" : 40075016.686,
|
"Earth's equators": 40075016.686,
|
||||||
"Astronomical units (au)": 149597870700,
|
'Astronomical units (au)': 149597870700,
|
||||||
"Light-years (ly)" : 9460730472580800,
|
'Light-years (ly)': 9460730472580800,
|
||||||
"Parsecs (pc)" : 3.0856776e16
|
'Parsecs (pc)': 3.0856776e16,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert distance operation.
|
* Convert distance operation.
|
||||||
|
@ -64,79 +64,79 @@ var Convert = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
run_distance: function (input, args) {
|
run_distance(input, args) {
|
||||||
var input_units = args[0],
|
let input_units = args[0],
|
||||||
output_units = args[1];
|
output_units = args[1];
|
||||||
|
|
||||||
input = input * Convert.DISTANCE_FACTOR[input_units];
|
input *= Convert.DISTANCE_FACTOR[input_units];
|
||||||
return input / Convert.DISTANCE_FACTOR[output_units];
|
return input / Convert.DISTANCE_FACTOR[output_units];
|
||||||
// TODO Remove rounding errors (e.g. 1.000000000001)
|
// TODO Remove rounding errors (e.g. 1.000000000001)
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
DATA_UNITS: [
|
DATA_UNITS: [
|
||||||
"Bits (b)", "Nibbles", "Octets", "Bytes (B)",
|
'Bits (b)', 'Nibbles', 'Octets', 'Bytes (B)',
|
||||||
"[Binary bits (2^n)]", "Kibibits (Kib)", "Mebibits (Mib)", "Gibibits (Gib)", "Tebibits (Tib)", "Pebibits (Pib)", "Exbibits (Eib)", "Zebibits (Zib)", "Yobibits (Yib)", "[/Binary bits (2^n)]",
|
'[Binary bits (2^n)]', 'Kibibits (Kib)', 'Mebibits (Mib)', 'Gibibits (Gib)', 'Tebibits (Tib)', 'Pebibits (Pib)', 'Exbibits (Eib)', 'Zebibits (Zib)', 'Yobibits (Yib)', '[/Binary bits (2^n)]',
|
||||||
"[Decimal bits (10^n)]", "Decabits", "Hectobits", "Kilobits (kb)", "Megabits (Mb)", "Gigabits (Gb)", "Terabits (Tb)", "Petabits (Pb)", "Exabits (Eb)", "Zettabits (Zb)", "Yottabits (Yb)", "[/Decimal bits (10^n)]",
|
'[Decimal bits (10^n)]', 'Decabits', 'Hectobits', 'Kilobits (kb)', 'Megabits (Mb)', 'Gigabits (Gb)', 'Terabits (Tb)', 'Petabits (Pb)', 'Exabits (Eb)', 'Zettabits (Zb)', 'Yottabits (Yb)', '[/Decimal bits (10^n)]',
|
||||||
"[Binary bytes (8 x 2^n)]", "Kibibytes (KiB)", "Mebibytes (MiB)", "Gibibytes (GiB)", "Tebibytes (TiB)", "Pebibytes (PiB)", "Exbibytes (EiB)", "Zebibytes (ZiB)", "Yobibytes (YiB)", "[/Binary bytes (8 x 2^n)]",
|
'[Binary bytes (8 x 2^n)]', 'Kibibytes (KiB)', 'Mebibytes (MiB)', 'Gibibytes (GiB)', 'Tebibytes (TiB)', 'Pebibytes (PiB)', 'Exbibytes (EiB)', 'Zebibytes (ZiB)', 'Yobibytes (YiB)', '[/Binary bytes (8 x 2^n)]',
|
||||||
"[Decimal bytes (8 x 10^n)]", "Kilobytes (KB)", "Megabytes (MB)", "Gigabytes (GB)", "Terabytes (TB)", "Petabytes (PB)", "Exabytes (EB)", "Zettabytes (ZB)", "Yottabytes (YB)", "[/Decimal bytes (8 x 10^n)]"
|
'[Decimal bytes (8 x 10^n)]', 'Kilobytes (KB)', 'Megabytes (MB)', 'Gigabytes (GB)', 'Terabytes (TB)', 'Petabytes (PB)', 'Exabytes (EB)', 'Zettabytes (ZB)', 'Yottabytes (YB)', '[/Decimal bytes (8 x 10^n)]',
|
||||||
],
|
],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
DATA_FACTOR: { // Multiples of a bit
|
DATA_FACTOR: { // Multiples of a bit
|
||||||
"Bits (b)" : 1,
|
'Bits (b)': 1,
|
||||||
"Nibbles" : 4,
|
Nibbles: 4,
|
||||||
"Octets" : 8,
|
Octets: 8,
|
||||||
"Bytes (B)" : 8,
|
'Bytes (B)': 8,
|
||||||
|
|
||||||
// Binary bits (2^n)
|
// Binary bits (2^n)
|
||||||
"Kibibits (Kib)" : 1024,
|
'Kibibits (Kib)': 1024,
|
||||||
"Mebibits (Mib)" : 1048576,
|
'Mebibits (Mib)': 1048576,
|
||||||
"Gibibits (Gib)" : 1073741824,
|
'Gibibits (Gib)': 1073741824,
|
||||||
"Tebibits (Tib)" : 1099511627776,
|
'Tebibits (Tib)': 1099511627776,
|
||||||
"Pebibits (Pib)" : 1125899906842624,
|
'Pebibits (Pib)': 1125899906842624,
|
||||||
"Exbibits (Eib)" : 1152921504606846976,
|
'Exbibits (Eib)': 1152921504606846976,
|
||||||
"Zebibits (Zib)" : 1180591620717411303424,
|
'Zebibits (Zib)': 1180591620717411303424,
|
||||||
"Yobibits (Yib)" : 1208925819614629174706176,
|
'Yobibits (Yib)': 1208925819614629174706176,
|
||||||
|
|
||||||
// Decimal bits (10^n)
|
// Decimal bits (10^n)
|
||||||
"Decabits" : 10,
|
Decabits: 10,
|
||||||
"Hectobits" : 100,
|
Hectobits: 100,
|
||||||
"Kilobits (Kb)" : 1e3,
|
'Kilobits (Kb)': 1e3,
|
||||||
"Megabits (Mb)" : 1e6,
|
'Megabits (Mb)': 1e6,
|
||||||
"Gigabits (Gb)" : 1e9,
|
'Gigabits (Gb)': 1e9,
|
||||||
"Terabits (Tb)" : 1e12,
|
'Terabits (Tb)': 1e12,
|
||||||
"Petabits (Pb)" : 1e15,
|
'Petabits (Pb)': 1e15,
|
||||||
"Exabits (Eb)" : 1e18,
|
'Exabits (Eb)': 1e18,
|
||||||
"Zettabits (Zb)" : 1e21,
|
'Zettabits (Zb)': 1e21,
|
||||||
"Yottabits (Yb)" : 1e24,
|
'Yottabits (Yb)': 1e24,
|
||||||
|
|
||||||
// Binary bytes (8 x 2^n)
|
// Binary bytes (8 x 2^n)
|
||||||
"Kibibytes (KiB)" : 8192,
|
'Kibibytes (KiB)': 8192,
|
||||||
"Mebibytes (MiB)" : 8388608,
|
'Mebibytes (MiB)': 8388608,
|
||||||
"Gibibytes (GiB)" : 8589934592,
|
'Gibibytes (GiB)': 8589934592,
|
||||||
"Tebibytes (TiB)" : 8796093022208,
|
'Tebibytes (TiB)': 8796093022208,
|
||||||
"Pebibytes (PiB)" : 9007199254740992,
|
'Pebibytes (PiB)': 9007199254740992,
|
||||||
"Exbibytes (EiB)" : 9223372036854775808,
|
'Exbibytes (EiB)': 9223372036854775808,
|
||||||
"Zebibytes (ZiB)" : 9444732965739290427392,
|
'Zebibytes (ZiB)': 9444732965739290427392,
|
||||||
"Yobibytes (YiB)" : 9671406556917033397649408,
|
'Yobibytes (YiB)': 9671406556917033397649408,
|
||||||
|
|
||||||
// Decimal bytes (8 x 10^n)
|
// Decimal bytes (8 x 10^n)
|
||||||
"Kilobytes (KB)" : 8e3,
|
'Kilobytes (KB)': 8e3,
|
||||||
"Megabytes (MB)" : 8e6,
|
'Megabytes (MB)': 8e6,
|
||||||
"Gigabytes (GB)" : 8e9,
|
'Gigabytes (GB)': 8e9,
|
||||||
"Terabytes (TB)" : 8e12,
|
'Terabytes (TB)': 8e12,
|
||||||
"Petabytes (PB)" : 8e15,
|
'Petabytes (PB)': 8e15,
|
||||||
"Exabytes (EB)" : 8e18,
|
'Exabytes (EB)': 8e18,
|
||||||
"Zettabytes (ZB)" : 8e21,
|
'Zettabytes (ZB)': 8e21,
|
||||||
"Yottabytes (YB)" : 8e24,
|
'Yottabytes (YB)': 8e24,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert data units operation.
|
* Convert data units operation.
|
||||||
|
@ -145,78 +145,78 @@ var Convert = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
run_data_size: function (input, args) {
|
run_data_size(input, args) {
|
||||||
var input_units = args[0],
|
let input_units = args[0],
|
||||||
output_units = args[1];
|
output_units = args[1];
|
||||||
|
|
||||||
input = input * Convert.DATA_FACTOR[input_units];
|
input *= Convert.DATA_FACTOR[input_units];
|
||||||
return input / Convert.DATA_FACTOR[output_units];
|
return input / Convert.DATA_FACTOR[output_units];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
AREA_UNITS: [
|
AREA_UNITS: [
|
||||||
"[Metric]", "Square metre (sq m)", "Square kilometre (sq km)", "Centiare (ca)", "Deciare (da)", "Are (a)", "Decare (daa)", "Hectare (ha)", "[/Metric]",
|
'[Metric]', 'Square metre (sq m)', 'Square kilometre (sq km)', 'Centiare (ca)', 'Deciare (da)', 'Are (a)', 'Decare (daa)', 'Hectare (ha)', '[/Metric]',
|
||||||
"[Imperial]", "Square inch (sq in)", "Square foot (sq ft)", "Square yard (sq yd)", "Square mile (sq mi)", "Perch (sq per)", "Rood (ro)", "International acre (ac)", "[/Imperial]",
|
'[Imperial]', 'Square inch (sq in)', 'Square foot (sq ft)', 'Square yard (sq yd)', 'Square mile (sq mi)', 'Perch (sq per)', 'Rood (ro)', 'International acre (ac)', '[/Imperial]',
|
||||||
"[US customary units]", "US survey acre (ac)", "US survey square mile (sq mi)", "US survey township", "[/US customary units]",
|
'[US customary units]', 'US survey acre (ac)', 'US survey square mile (sq mi)', 'US survey township', '[/US customary units]',
|
||||||
"[Nuclear physics]", "Yoctobarn (yb)", "Zeptobarn (zb)", "Attobarn (ab)", "Femtobarn (fb)", "Picobarn (pb)", "Nanobarn (nb)", "Microbarn (μb)", "Millibarn (mb)", "Barn (b)", "Kilobarn (kb)", "Megabarn (Mb)", "Outhouse", "Shed", "Planck area", "[/Nuclear physics]",
|
'[Nuclear physics]', 'Yoctobarn (yb)', 'Zeptobarn (zb)', 'Attobarn (ab)', 'Femtobarn (fb)', 'Picobarn (pb)', 'Nanobarn (nb)', 'Microbarn (μb)', 'Millibarn (mb)', 'Barn (b)', 'Kilobarn (kb)', 'Megabarn (Mb)', 'Outhouse', 'Shed', 'Planck area', '[/Nuclear physics]',
|
||||||
"[Comparisons]", "Washington D.C.", "Isle of Wight", "Wales", "Texas", "[/Comparisons]",
|
'[Comparisons]', 'Washington D.C.', 'Isle of Wight', 'Wales', 'Texas', '[/Comparisons]',
|
||||||
],
|
],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
AREA_FACTOR: { // Multiples of a square metre
|
AREA_FACTOR: { // Multiples of a square metre
|
||||||
// Metric
|
// Metric
|
||||||
"Square metre (sq m)" : 1,
|
'Square metre (sq m)': 1,
|
||||||
"Square kilometre (sq km)" : 1e6,
|
'Square kilometre (sq km)': 1e6,
|
||||||
|
|
||||||
"Centiare (ca)" : 1,
|
'Centiare (ca)': 1,
|
||||||
"Deciare (da)" : 10,
|
'Deciare (da)': 10,
|
||||||
"Are (a)" : 100,
|
'Are (a)': 100,
|
||||||
"Decare (daa)" : 1e3,
|
'Decare (daa)': 1e3,
|
||||||
"Hectare (ha)" : 1e4,
|
'Hectare (ha)': 1e4,
|
||||||
|
|
||||||
// Imperial
|
// Imperial
|
||||||
"Square inch (sq in)" : 0.00064516,
|
'Square inch (sq in)': 0.00064516,
|
||||||
"Square foot (sq ft)" : 0.09290304,
|
'Square foot (sq ft)': 0.09290304,
|
||||||
"Square yard (sq yd)" : 0.83612736,
|
'Square yard (sq yd)': 0.83612736,
|
||||||
"Square mile (sq mi)" : 2589988.110336,
|
'Square mile (sq mi)': 2589988.110336,
|
||||||
"Perch (sq per)" : 42.21,
|
'Perch (sq per)': 42.21,
|
||||||
"Rood (ro)" : 1011,
|
'Rood (ro)': 1011,
|
||||||
"International acre (ac)" : 4046.8564224,
|
'International acre (ac)': 4046.8564224,
|
||||||
|
|
||||||
// US customary units
|
// US customary units
|
||||||
"US survey acre (ac)" : 4046.87261,
|
'US survey acre (ac)': 4046.87261,
|
||||||
"US survey square mile (sq mi)" : 2589998.470305239,
|
'US survey square mile (sq mi)': 2589998.470305239,
|
||||||
"US survey township" : 93239944.9309886,
|
'US survey township': 93239944.9309886,
|
||||||
|
|
||||||
// Nuclear physics
|
// Nuclear physics
|
||||||
"Yoctobarn (yb)" : 1e-52,
|
'Yoctobarn (yb)': 1e-52,
|
||||||
"Zeptobarn (zb)" : 1e-49,
|
'Zeptobarn (zb)': 1e-49,
|
||||||
"Attobarn (ab)" : 1e-46,
|
'Attobarn (ab)': 1e-46,
|
||||||
"Femtobarn (fb)" : 1e-43,
|
'Femtobarn (fb)': 1e-43,
|
||||||
"Picobarn (pb)" : 1e-40,
|
'Picobarn (pb)': 1e-40,
|
||||||
"Nanobarn (nb)" : 1e-37,
|
'Nanobarn (nb)': 1e-37,
|
||||||
"Microbarn (μb)" : 1e-34,
|
'Microbarn (μb)': 1e-34,
|
||||||
"Millibarn (mb)" : 1e-31,
|
'Millibarn (mb)': 1e-31,
|
||||||
"Barn (b)" : 1e-28,
|
'Barn (b)': 1e-28,
|
||||||
"Kilobarn (kb)" : 1e-25,
|
'Kilobarn (kb)': 1e-25,
|
||||||
"Megabarn (Mb)" : 1e-22,
|
'Megabarn (Mb)': 1e-22,
|
||||||
|
|
||||||
"Planck area" : 2.6e-70,
|
'Planck area': 2.6e-70,
|
||||||
"Shed" : 1e-52,
|
Shed: 1e-52,
|
||||||
"Outhouse" : 1e-34,
|
Outhouse: 1e-34,
|
||||||
|
|
||||||
// Comparisons
|
// Comparisons
|
||||||
"Washington D.C." : 176119191.502848,
|
'Washington D.C.': 176119191.502848,
|
||||||
"Isle of Wight" : 380000000,
|
'Isle of Wight': 380000000,
|
||||||
"Wales" : 20779000000,
|
Wales: 20779000000,
|
||||||
"Texas" : 696241000000,
|
Texas: 696241000000,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert area operation.
|
* Convert area operation.
|
||||||
|
@ -225,109 +225,109 @@ var Convert = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
run_area: function (input, args) {
|
run_area(input, args) {
|
||||||
var input_units = args[0],
|
let input_units = args[0],
|
||||||
output_units = args[1];
|
output_units = args[1];
|
||||||
|
|
||||||
input = input * Convert.AREA_FACTOR[input_units];
|
input *= Convert.AREA_FACTOR[input_units];
|
||||||
return input / Convert.AREA_FACTOR[output_units];
|
return input / Convert.AREA_FACTOR[output_units];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
MASS_UNITS: [
|
MASS_UNITS: [
|
||||||
"[Metric]", "Yoctogram (yg)", "Zeptogram (zg)", "Attogram (ag)", "Femtogram (fg)", "Picogram (pg)", "Nanogram (ng)", "Microgram (μg)", "Milligram (mg)", "Centigram (cg)", "Decigram (dg)", "Gram (g)", "Decagram (dag)", "Hectogram (hg)", "Kilogram (kg)", "Megagram (Mg)", "Tonne (t)", "Gigagram (Gg)", "Teragram (Tg)", "Petagram (Pg)", "Exagram (Eg)", "Zettagram (Zg)", "Yottagram (Yg)", "[/Metric]",
|
'[Metric]', 'Yoctogram (yg)', 'Zeptogram (zg)', 'Attogram (ag)', 'Femtogram (fg)', 'Picogram (pg)', 'Nanogram (ng)', 'Microgram (μg)', 'Milligram (mg)', 'Centigram (cg)', 'Decigram (dg)', 'Gram (g)', 'Decagram (dag)', 'Hectogram (hg)', 'Kilogram (kg)', 'Megagram (Mg)', 'Tonne (t)', 'Gigagram (Gg)', 'Teragram (Tg)', 'Petagram (Pg)', 'Exagram (Eg)', 'Zettagram (Zg)', 'Yottagram (Yg)', '[/Metric]',
|
||||||
"[Imperial Avoirdupois]", "Grain (gr)", "Dram (dr)", "Ounce (oz)", "Pound (lb)", "Nail", "Stone (st)", "Quarter (gr)", "Tod", "US hundredweight (cwt)", "Imperial hundredweight (cwt)", "US ton (t)", "Imperial ton (t)", "[/Imperial Avoirdupois]",
|
'[Imperial Avoirdupois]', 'Grain (gr)', 'Dram (dr)', 'Ounce (oz)', 'Pound (lb)', 'Nail', 'Stone (st)', 'Quarter (gr)', 'Tod', 'US hundredweight (cwt)', 'Imperial hundredweight (cwt)', 'US ton (t)', 'Imperial ton (t)', '[/Imperial Avoirdupois]',
|
||||||
"[Imperial Troy]", "Grain (gr)", "Pennyweight (dwt)", "Troy dram (dr t)", "Troy ounce (oz t)", "Troy pound (lb t)", "Mark", "[/Imperial Troy]",
|
'[Imperial Troy]', 'Grain (gr)', 'Pennyweight (dwt)', 'Troy dram (dr t)', 'Troy ounce (oz t)', 'Troy pound (lb t)', 'Mark', '[/Imperial Troy]',
|
||||||
"[Archaic]", "Wey", "Wool wey", "Suffolk wey", "Wool sack", "Coal sack", "Load", "Last", "Flax or feather last", "Gunpowder last", "Picul", "Rice last", "[/Archaic]",
|
'[Archaic]', 'Wey', 'Wool wey', 'Suffolk wey', 'Wool sack', 'Coal sack', 'Load', 'Last', 'Flax or feather last', 'Gunpowder last', 'Picul', 'Rice last', '[/Archaic]',
|
||||||
"[Comparisons]", "Big Ben (14 tonnes)", "Blue whale (180 tonnes)", "International Space Station (417 tonnes)", "Space Shuttle (2,041 tonnes)", "RMS Titanic (52,000 tonnes)", "Great Pyramid of Giza (6,000,000 tonnes)", "Earth's oceans (1.4 yottagrams)", "[/Comparisons]",
|
'[Comparisons]', 'Big Ben (14 tonnes)', 'Blue whale (180 tonnes)', 'International Space Station (417 tonnes)', 'Space Shuttle (2,041 tonnes)', 'RMS Titanic (52,000 tonnes)', 'Great Pyramid of Giza (6,000,000 tonnes)', "Earth's oceans (1.4 yottagrams)", '[/Comparisons]',
|
||||||
"[Astronomical]", "A teaspoon of neutron star (5,500 million tonnes)", "Lunar mass (ML)", "Earth mass (M⊕)", "Jupiter mass (MJ)", "Solar mass (M☉)", "Sagittarius A* (7.5 x 10^36 kgs-ish)", "Milky Way galaxy (1.2 x 10^42 kgs)", "The observable universe (1.45 x 10^53 kgs)", "[/Astronomical]",
|
'[Astronomical]', 'A teaspoon of neutron star (5,500 million tonnes)', 'Lunar mass (ML)', 'Earth mass (M⊕)', 'Jupiter mass (MJ)', 'Solar mass (M☉)', 'Sagittarius A* (7.5 x 10^36 kgs-ish)', 'Milky Way galaxy (1.2 x 10^42 kgs)', 'The observable universe (1.45 x 10^53 kgs)', '[/Astronomical]',
|
||||||
],
|
],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
MASS_FACTOR: { // Multiples of a gram
|
MASS_FACTOR: { // Multiples of a gram
|
||||||
// Metric
|
// Metric
|
||||||
"Yoctogram (yg)" : 1e-24,
|
'Yoctogram (yg)': 1e-24,
|
||||||
"Zeptogram (zg)" : 1e-21,
|
'Zeptogram (zg)': 1e-21,
|
||||||
"Attogram (ag)" : 1e-18,
|
'Attogram (ag)': 1e-18,
|
||||||
"Femtogram (fg)" : 1e-15,
|
'Femtogram (fg)': 1e-15,
|
||||||
"Picogram (pg)" : 1e-12,
|
'Picogram (pg)': 1e-12,
|
||||||
"Nanogram (ng)" : 1e-9,
|
'Nanogram (ng)': 1e-9,
|
||||||
"Microgram (μg)" : 1e-6,
|
'Microgram (μg)': 1e-6,
|
||||||
"Milligram (mg)" : 1e-3,
|
'Milligram (mg)': 1e-3,
|
||||||
"Centigram (cg)" : 1e-2,
|
'Centigram (cg)': 1e-2,
|
||||||
"Decigram (dg)" : 1e-1,
|
'Decigram (dg)': 1e-1,
|
||||||
"Gram (g)" : 1,
|
'Gram (g)': 1,
|
||||||
"Decagram (dag)" : 10,
|
'Decagram (dag)': 10,
|
||||||
"Hectogram (hg)" : 100,
|
'Hectogram (hg)': 100,
|
||||||
"Kilogram (kg)" : 1000,
|
'Kilogram (kg)': 1000,
|
||||||
"Megagram (Mg)" : 1e6,
|
'Megagram (Mg)': 1e6,
|
||||||
"Tonne (t)" : 1e6,
|
'Tonne (t)': 1e6,
|
||||||
"Gigagram (Gg)" : 1e9,
|
'Gigagram (Gg)': 1e9,
|
||||||
"Teragram (Tg)" : 1e12,
|
'Teragram (Tg)': 1e12,
|
||||||
"Petagram (Pg)" : 1e15,
|
'Petagram (Pg)': 1e15,
|
||||||
"Exagram (Eg)" : 1e18,
|
'Exagram (Eg)': 1e18,
|
||||||
"Zettagram (Zg)" : 1e21,
|
'Zettagram (Zg)': 1e21,
|
||||||
"Yottagram (Yg)" : 1e24,
|
'Yottagram (Yg)': 1e24,
|
||||||
|
|
||||||
// Imperial Avoirdupois
|
// Imperial Avoirdupois
|
||||||
"Grain (gr)" : 64.79891e-3,
|
'Grain (gr)': 64.79891e-3,
|
||||||
"Dram (dr)" : 1.7718451953125,
|
'Dram (dr)': 1.7718451953125,
|
||||||
"Ounce (oz)" : 28.349523125,
|
'Ounce (oz)': 28.349523125,
|
||||||
"Pound (lb)" : 453.59237,
|
'Pound (lb)': 453.59237,
|
||||||
"Nail" : 3175.14659,
|
Nail: 3175.14659,
|
||||||
"Stone (st)" : 6.35029318e3,
|
'Stone (st)': 6.35029318e3,
|
||||||
"Quarter (gr)" : 12700.58636,
|
'Quarter (gr)': 12700.58636,
|
||||||
"Tod" : 12700.58636,
|
Tod: 12700.58636,
|
||||||
"US hundredweight (cwt)" : 45.359237e3,
|
'US hundredweight (cwt)': 45.359237e3,
|
||||||
"Imperial hundredweight (cwt)" : 50.80234544e3,
|
'Imperial hundredweight (cwt)': 50.80234544e3,
|
||||||
"US ton (t)" : 907.18474e3,
|
'US ton (t)': 907.18474e3,
|
||||||
"Imperial ton (t)" : 1016.0469088e3,
|
'Imperial ton (t)': 1016.0469088e3,
|
||||||
|
|
||||||
// Imperial Troy
|
// Imperial Troy
|
||||||
"Pennyweight (dwt)" : 1.55517384,
|
'Pennyweight (dwt)': 1.55517384,
|
||||||
"Troy dram (dr t)" : 3.8879346,
|
'Troy dram (dr t)': 3.8879346,
|
||||||
"Troy ounce (oz t)" : 31.1034768,
|
'Troy ounce (oz t)': 31.1034768,
|
||||||
"Troy pound (lb t)" : 373.2417216,
|
'Troy pound (lb t)': 373.2417216,
|
||||||
"Mark" : 248.8278144,
|
Mark: 248.8278144,
|
||||||
|
|
||||||
// Archaic
|
// Archaic
|
||||||
"Wey" : 76.5e3,
|
Wey: 76.5e3,
|
||||||
"Wool wey" : 101.7e3,
|
'Wool wey': 101.7e3,
|
||||||
"Suffolk wey" : 161.5e3,
|
'Suffolk wey': 161.5e3,
|
||||||
"Wool sack" : 153000,
|
'Wool sack': 153000,
|
||||||
"Coal sack" : 50.80234544e3,
|
'Coal sack': 50.80234544e3,
|
||||||
"Load" : 918000,
|
Load: 918000,
|
||||||
"Last" : 1836000,
|
Last: 1836000,
|
||||||
"Flax or feather last" : 770e3,
|
'Flax or feather last': 770e3,
|
||||||
"Gunpowder last" : 1090e3,
|
'Gunpowder last': 1090e3,
|
||||||
"Picul" : 60.478982e3,
|
Picul: 60.478982e3,
|
||||||
"Rice last" : 1200e3,
|
'Rice last': 1200e3,
|
||||||
|
|
||||||
// Comparisons
|
// Comparisons
|
||||||
"Big Ben (14 tonnes)" : 14e6,
|
'Big Ben (14 tonnes)': 14e6,
|
||||||
"Blue whale (180 tonnes)" : 180e6,
|
'Blue whale (180 tonnes)': 180e6,
|
||||||
"International Space Station (417 tonnes)" : 417e6,
|
'International Space Station (417 tonnes)': 417e6,
|
||||||
"Space Shuttle (2,041 tonnes)" : 2041e6,
|
'Space Shuttle (2,041 tonnes)': 2041e6,
|
||||||
"RMS Titanic (52,000 tonnes)" : 52000e6,
|
'RMS Titanic (52,000 tonnes)': 52000e6,
|
||||||
"Great Pyramid of Giza (6,000,000 tonnes)" : 6e12,
|
'Great Pyramid of Giza (6,000,000 tonnes)': 6e12,
|
||||||
"Earth's oceans (1.4 yottagrams)" : 1.4e24,
|
"Earth's oceans (1.4 yottagrams)": 1.4e24,
|
||||||
|
|
||||||
// Astronomical
|
// Astronomical
|
||||||
"A teaspoon of neutron star (5,500 million tonnes)" : 5.5e15,
|
'A teaspoon of neutron star (5,500 million tonnes)': 5.5e15,
|
||||||
"Lunar mass (ML)" : 7.342e25,
|
'Lunar mass (ML)': 7.342e25,
|
||||||
"Earth mass (M⊕)" : 5.97219e27,
|
'Earth mass (M⊕)': 5.97219e27,
|
||||||
"Jupiter mass (MJ)" : 1.8981411476999997e30,
|
'Jupiter mass (MJ)': 1.8981411476999997e30,
|
||||||
"Solar mass (M☉)" : 1.98855e33,
|
'Solar mass (M☉)': 1.98855e33,
|
||||||
"Sagittarius A* (7.5 x 10^36 kgs-ish)" : 7.5e39,
|
'Sagittarius A* (7.5 x 10^36 kgs-ish)': 7.5e39,
|
||||||
"Milky Way galaxy (1.2 x 10^42 kgs)" : 1.2e45,
|
'Milky Way galaxy (1.2 x 10^42 kgs)': 1.2e45,
|
||||||
"The observable universe (1.45 x 10^53 kgs)" : 1.45e56,
|
'The observable universe (1.45 x 10^53 kgs)': 1.45e56,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert mass operation.
|
* Convert mass operation.
|
||||||
|
@ -336,63 +336,63 @@ var Convert = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
run_mass: function (input, args) {
|
run_mass(input, args) {
|
||||||
var input_units = args[0],
|
let input_units = args[0],
|
||||||
output_units = args[1];
|
output_units = args[1];
|
||||||
|
|
||||||
input = input * Convert.MASS_FACTOR[input_units];
|
input *= Convert.MASS_FACTOR[input_units];
|
||||||
return input / Convert.MASS_FACTOR[output_units];
|
return input / Convert.MASS_FACTOR[output_units];
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
SPEED_UNITS: [
|
SPEED_UNITS: [
|
||||||
"[Metric]", "Metres per second (m/s)", "Kilometres per hour (km/h)", "[/Metric]",
|
'[Metric]', 'Metres per second (m/s)', 'Kilometres per hour (km/h)', '[/Metric]',
|
||||||
"[Imperial]", "Miles per hour (mph)", "Knots (kn)", "[/Imperial]",
|
'[Imperial]', 'Miles per hour (mph)', 'Knots (kn)', '[/Imperial]',
|
||||||
"[Comparisons]", "Human hair growth rate", "Bamboo growth rate", "World's fastest snail", "Usain Bolt's top speed", "Jet airliner cruising speed", "Concorde", "SR-71 Blackbird", "Space Shuttle", "International Space Station", "[/Comparisons]",
|
'[Comparisons]', 'Human hair growth rate', 'Bamboo growth rate', "World's fastest snail", "Usain Bolt's top speed", 'Jet airliner cruising speed', 'Concorde', 'SR-71 Blackbird', 'Space Shuttle', 'International Space Station', '[/Comparisons]',
|
||||||
"[Scientific]", "Sound in standard atmosphere", "Sound in water", "Lunar escape velocity", "Earth escape velocity", "Earth's solar orbit", "Solar system's Milky Way orbit", "Milky Way relative to the cosmic microwave background", "Solar escape velocity", "Neutron star escape velocity (0.3c)", "Light in a diamond (0.4136c)", "Signal in an optical fibre (0.667c)", "Light (c)", "[/Scientific]",
|
'[Scientific]', 'Sound in standard atmosphere', 'Sound in water', 'Lunar escape velocity', 'Earth escape velocity', "Earth's solar orbit", "Solar system's Milky Way orbit", 'Milky Way relative to the cosmic microwave background', 'Solar escape velocity', 'Neutron star escape velocity (0.3c)', 'Light in a diamond (0.4136c)', 'Signal in an optical fibre (0.667c)', 'Light (c)', '[/Scientific]',
|
||||||
],
|
],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
SPEED_FACTOR: { // Multiples of m/s
|
SPEED_FACTOR: { // Multiples of m/s
|
||||||
// Metric
|
// Metric
|
||||||
"Metres per second (m/s)" : 1,
|
'Metres per second (m/s)': 1,
|
||||||
"Kilometres per hour (km/h)" : 0.2778,
|
'Kilometres per hour (km/h)': 0.2778,
|
||||||
|
|
||||||
// Imperial
|
// Imperial
|
||||||
"Miles per hour (mph)" : 0.44704,
|
'Miles per hour (mph)': 0.44704,
|
||||||
"Knots (kn)" : 0.5144,
|
'Knots (kn)': 0.5144,
|
||||||
|
|
||||||
// Comparisons
|
// Comparisons
|
||||||
"Human hair growth rate" : 4.8e-9,
|
'Human hair growth rate': 4.8e-9,
|
||||||
"Bamboo growth rate" : 1.4e-5,
|
'Bamboo growth rate': 1.4e-5,
|
||||||
"World's fastest snail" : 0.00275,
|
"World's fastest snail": 0.00275,
|
||||||
"Usain Bolt's top speed" : 12.42,
|
"Usain Bolt's top speed": 12.42,
|
||||||
"Jet airliner cruising speed" : 250,
|
'Jet airliner cruising speed': 250,
|
||||||
"Concorde" : 603,
|
Concorde: 603,
|
||||||
"SR-71 Blackbird" : 981,
|
'SR-71 Blackbird': 981,
|
||||||
"Space Shuttle" : 1400,
|
'Space Shuttle': 1400,
|
||||||
"International Space Station" : 7700,
|
'International Space Station': 7700,
|
||||||
|
|
||||||
// Scientific
|
// Scientific
|
||||||
"Sound in standard atmosphere" : 340.3,
|
'Sound in standard atmosphere': 340.3,
|
||||||
"Sound in water" : 1500,
|
'Sound in water': 1500,
|
||||||
"Lunar escape velocity" : 2375,
|
'Lunar escape velocity': 2375,
|
||||||
"Earth escape velocity" : 11200,
|
'Earth escape velocity': 11200,
|
||||||
"Earth's solar orbit" : 29800,
|
"Earth's solar orbit": 29800,
|
||||||
"Solar system's Milky Way orbit" : 200000,
|
"Solar system's Milky Way orbit": 200000,
|
||||||
"Milky Way relative to the cosmic microwave background" : 552000,
|
'Milky Way relative to the cosmic microwave background': 552000,
|
||||||
"Solar escape velocity" : 617700,
|
'Solar escape velocity': 617700,
|
||||||
"Neutron star escape velocity (0.3c)" : 100000000,
|
'Neutron star escape velocity (0.3c)': 100000000,
|
||||||
"Light in a diamond (0.4136c)" : 124000000,
|
'Light in a diamond (0.4136c)': 124000000,
|
||||||
"Signal in an optical fibre (0.667c)" : 200000000,
|
'Signal in an optical fibre (0.667c)': 200000000,
|
||||||
"Light (c)" : 299792458,
|
'Light (c)': 299792458,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert speed operation.
|
* Convert speed operation.
|
||||||
|
@ -401,12 +401,12 @@ var Convert = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
run_speed: function (input, args) {
|
run_speed(input, args) {
|
||||||
var input_units = args[0],
|
let input_units = args[0],
|
||||||
output_units = args[1];
|
output_units = args[1];
|
||||||
|
|
||||||
input = input * Convert.SPEED_FACTOR[input_units];
|
input *= Convert.SPEED_FACTOR[input_units];
|
||||||
return input / Convert.SPEED_FACTOR[output_units];
|
return input / Convert.SPEED_FACTOR[output_units];
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,13 +9,13 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var DateTime = {
|
const DateTime = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
UNITS: ["Seconds (s)", "Milliseconds (ms)", "Microseconds (μs)", "Nanoseconds (ns)"],
|
UNITS: ['Seconds (s)', 'Milliseconds (ms)', 'Microseconds (μs)', 'Nanoseconds (ns)'],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* From UNIX Timestamp operation.
|
* From UNIX Timestamp operation.
|
||||||
|
@ -24,28 +24,28 @@ var DateTime = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_from_unix_timestamp: function(input, args) {
|
run_from_unix_timestamp(input, args) {
|
||||||
var units = args[0],
|
let units = args[0],
|
||||||
d;
|
d;
|
||||||
|
|
||||||
input = parseFloat(input);
|
input = parseFloat(input);
|
||||||
|
|
||||||
if (units == "Seconds (s)") {
|
if (units == 'Seconds (s)') {
|
||||||
d = moment.unix(input);
|
d = moment.unix(input);
|
||||||
return d.tz("UTC").format("ddd D MMMM YYYY HH:mm:ss") + " UTC";
|
return `${d.tz('UTC').format('ddd D MMMM YYYY HH:mm:ss')} UTC`;
|
||||||
} else if (units == "Milliseconds (ms)") {
|
} else if (units == 'Milliseconds (ms)') {
|
||||||
d = moment(input);
|
d = moment(input);
|
||||||
return d.tz("UTC").format("ddd D MMMM YYYY HH:mm:ss.SSS") + " UTC";
|
return `${d.tz('UTC').format('ddd D MMMM YYYY HH:mm:ss.SSS')} UTC`;
|
||||||
} else if (units == "Microseconds (μs)") {
|
} else if (units == 'Microseconds (μs)') {
|
||||||
d = moment(input / 1000);
|
d = moment(input / 1000);
|
||||||
return d.tz("UTC").format("ddd D MMMM YYYY HH:mm:ss.SSS") + " UTC";
|
return `${d.tz('UTC').format('ddd D MMMM YYYY HH:mm:ss.SSS')} UTC`;
|
||||||
} else if (units == "Nanoseconds (ns)") {
|
} else if (units == 'Nanoseconds (ns)') {
|
||||||
d = moment(input / 1000000);
|
d = moment(input / 1000000);
|
||||||
return d.tz("UTC").format("ddd D MMMM YYYY HH:mm:ss.SSS") + " UTC";
|
return `${d.tz('UTC').format('ddd D MMMM YYYY HH:mm:ss.SSS')} UTC`;
|
||||||
} else {
|
} else {
|
||||||
throw "Unrecognised unit";
|
throw 'Unrecognised unit';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,73 +55,73 @@ var DateTime = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
run_to_unix_timestamp: function(input, args) {
|
run_to_unix_timestamp(input, args) {
|
||||||
var units = args[0],
|
let units = args[0],
|
||||||
d = moment(input);
|
d = moment(input);
|
||||||
|
|
||||||
if (units == "Seconds (s)") {
|
if (units == 'Seconds (s)') {
|
||||||
return d.unix();
|
return d.unix();
|
||||||
} else if (units == "Milliseconds (ms)") {
|
} else if (units == 'Milliseconds (ms)') {
|
||||||
return d.valueOf();
|
return d.valueOf();
|
||||||
} else if (units == "Microseconds (μs)") {
|
} else if (units == 'Microseconds (μs)') {
|
||||||
return d.valueOf() * 1000;
|
return d.valueOf() * 1000;
|
||||||
} else if (units == "Nanoseconds (ns)") {
|
} else if (units == 'Nanoseconds (ns)') {
|
||||||
return d.valueOf() * 1000000;
|
return d.valueOf() * 1000000;
|
||||||
} else {
|
} else {
|
||||||
throw "Unrecognised unit";
|
throw 'Unrecognised unit';
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @constant
|
||||||
|
* @default
|
||||||
|
*/
|
||||||
|
DATETIME_FORMATS: [
|
||||||
|
{
|
||||||
|
name: 'Standard date and time',
|
||||||
|
value: 'DD/MM/YYYY HH:mm:ss',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
name: 'American-style date and time',
|
||||||
|
value: 'MM/DD/YYYY HH:mm:ss',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'International date and time',
|
||||||
|
value: 'YYYY-MM-DD HH:mm:ss',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Verbose date and time',
|
||||||
|
value: 'dddd Do MMMM YYYY HH:mm:ss Z z',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'UNIX timestamp (seconds)',
|
||||||
|
value: 'X',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'UNIX timestamp offset (milliseconds)',
|
||||||
|
value: 'x',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Automatic',
|
||||||
|
value: '',
|
||||||
|
},
|
||||||
|
],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
DATETIME_FORMATS: [
|
INPUT_FORMAT_STRING: 'DD/MM/YYYY HH:mm:ss',
|
||||||
{
|
|
||||||
name: "Standard date and time",
|
|
||||||
value: "DD/MM/YYYY HH:mm:ss"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "American-style date and time",
|
|
||||||
value: "MM/DD/YYYY HH:mm:ss"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "International date and time",
|
|
||||||
value: "YYYY-MM-DD HH:mm:ss"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Verbose date and time",
|
|
||||||
value: "dddd Do MMMM YYYY HH:mm:ss Z z"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "UNIX timestamp (seconds)",
|
|
||||||
value: "X"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "UNIX timestamp offset (milliseconds)",
|
|
||||||
value: "x"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Automatic",
|
|
||||||
value: ""
|
|
||||||
},
|
|
||||||
],
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
INPUT_FORMAT_STRING: "DD/MM/YYYY HH:mm:ss",
|
OUTPUT_FORMAT_STRING: 'dddd Do MMMM YYYY HH:mm:ss Z z',
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
OUTPUT_FORMAT_STRING: "dddd Do MMMM YYYY HH:mm:ss Z z",
|
TIMEZONES: ['UTC'].concat(moment.tz.names()),
|
||||||
/**
|
|
||||||
* @constant
|
|
||||||
* @default
|
|
||||||
*/
|
|
||||||
TIMEZONES: ["UTC"].concat(moment.tz.names()),
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Translate DateTime Format operation.
|
* Translate DateTime Format operation.
|
||||||
|
@ -130,22 +130,22 @@ var DateTime = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {html}
|
* @returns {html}
|
||||||
*/
|
*/
|
||||||
run_translate_format: function(input, args) {
|
run_translate_format(input, args) {
|
||||||
var input_format = args[1],
|
let input_format = args[1],
|
||||||
input_timezone = args[2],
|
input_timezone = args[2],
|
||||||
output_format = args[3],
|
output_format = args[3],
|
||||||
output_timezone = args[4],
|
output_timezone = args[4],
|
||||||
date;
|
date;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
date = moment.tz(input, input_format, input_timezone);
|
date = moment.tz(input, input_format, input_timezone);
|
||||||
if (!date || date.format() == "Invalid date") throw Error;
|
if (!date || date.format() == 'Invalid date') throw Error;
|
||||||
} catch(err) {
|
} catch (err) {
|
||||||
return "Invalid format.\n\n" + DateTime.FORMAT_EXAMPLES;
|
return `Invalid format.\n\n${DateTime.FORMAT_EXAMPLES}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return date.tz(output_timezone).format(output_format);
|
return date.tz(output_timezone).format(output_format);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -155,39 +155,39 @@ var DateTime = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {html}
|
* @returns {html}
|
||||||
*/
|
*/
|
||||||
run_parse: function(input, args) {
|
run_parse(input, args) {
|
||||||
var input_format = args[1],
|
let input_format = args[1],
|
||||||
input_timezone = args[2],
|
input_timezone = args[2],
|
||||||
date,
|
date,
|
||||||
output = "";
|
output = '';
|
||||||
|
|
||||||
try {
|
try {
|
||||||
date = moment.tz(input, input_format, input_timezone);
|
date = moment.tz(input, input_format, input_timezone);
|
||||||
if (!date || date.format() == "Invalid date") throw Error;
|
if (!date || date.format() == 'Invalid date') throw Error;
|
||||||
} catch(err) {
|
} catch (err) {
|
||||||
return "Invalid format.\n\n" + DateTime.FORMAT_EXAMPLES;
|
return `Invalid format.\n\n${DateTime.FORMAT_EXAMPLES}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
output += "Date: " + date.format("dddd Do MMMM YYYY") +
|
output += `Date: ${date.format('dddd Do MMMM YYYY')
|
||||||
"\nTime: " + date.format("HH:mm:ss") +
|
}\nTime: ${date.format('HH:mm:ss')
|
||||||
"\nPeriod: " + date.format("A") +
|
}\nPeriod: ${date.format('A')
|
||||||
"\nTimezone: " + date.format("z") +
|
}\nTimezone: ${date.format('z')
|
||||||
"\nUTC offset: " + date.format("ZZ") +
|
}\nUTC offset: ${date.format('ZZ')
|
||||||
"\n\nDaylight Saving Time: " + date.isDST() +
|
}\n\nDaylight Saving Time: ${date.isDST()
|
||||||
"\nLeap year: " + date.isLeapYear() +
|
}\nLeap year: ${date.isLeapYear()
|
||||||
"\nDays in this month: " + date.daysInMonth() +
|
}\nDays in this month: ${date.daysInMonth()
|
||||||
"\n\nDay of year: " + date.dayOfYear() +
|
}\n\nDay of year: ${date.dayOfYear()
|
||||||
"\nWeek number: " + date.weekYear() +
|
}\nWeek number: ${date.weekYear()
|
||||||
"\nQuarter: " + date.quarter();
|
}\nQuarter: ${date.quarter()}`;
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
*/
|
*/
|
||||||
FORMAT_EXAMPLES: "Format string tokens:\n\n\
|
FORMAT_EXAMPLES: "Format string tokens:\n\n\
|
||||||
<table class='table table-striped table-hover table-condensed table-bordered' style='font-family: sans-serif'>\
|
<table class='table table-striped table-hover table-condensed table-bordered' style='font-family: sans-serif'>\
|
||||||
<thead>\
|
<thead>\
|
||||||
<tr>\
|
<tr>\
|
||||||
|
|
|
@ -7,23 +7,23 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var Endian = {
|
const Endian = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
DATA_FORMAT: ["Hex", "Raw"],
|
DATA_FORMAT: ['Hex', 'Raw'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
WORD_LENGTH: 4,
|
WORD_LENGTH: 4,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
PAD_INCOMPLETE_WORDS: true,
|
PAD_INCOMPLETE_WORDS: true,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Swap endianness operation.
|
* Swap endianness operation.
|
||||||
|
@ -32,63 +32,63 @@ var Endian = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_swap_endianness: function(input, args) {
|
run_swap_endianness(input, args) {
|
||||||
var data_format = args[0],
|
let data_format = args[0],
|
||||||
word_length = args[1],
|
word_length = args[1],
|
||||||
pad_incomplete_words = args[2],
|
pad_incomplete_words = args[2],
|
||||||
data = [],
|
data = [],
|
||||||
result = [],
|
result = [],
|
||||||
words = [],
|
words = [],
|
||||||
i = 0,
|
i = 0,
|
||||||
j = 0;
|
j = 0;
|
||||||
|
|
||||||
if (word_length <= 0) {
|
if (word_length <= 0) {
|
||||||
return "Word length must be greater than 0";
|
return 'Word length must be greater than 0';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert input to raw data based on specified data format
|
// Convert input to raw data based on specified data format
|
||||||
switch (data_format) {
|
switch (data_format) {
|
||||||
case "Hex":
|
case 'Hex':
|
||||||
data = Utils.from_hex(input);
|
data = Utils.from_hex(input);
|
||||||
break;
|
break;
|
||||||
case "Raw":
|
case 'Raw':
|
||||||
data = Utils.str_to_byte_array(input);
|
data = Utils.str_to_byte_array(input);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
data = input;
|
data = input;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split up into words
|
// Split up into words
|
||||||
for (i = 0; i < data.length; i += word_length) {
|
for (i = 0; i < data.length; i += word_length) {
|
||||||
var word = data.slice(i, i + word_length);
|
const word = data.slice(i, i + word_length);
|
||||||
|
|
||||||
// Pad word if too short
|
// Pad word if too short
|
||||||
if (pad_incomplete_words && word.length < word_length){
|
if (pad_incomplete_words && word.length < word_length) {
|
||||||
for (j = word.length; j < word_length; j++) {
|
for (j = word.length; j < word_length; j++) {
|
||||||
word.push(0);
|
word.push(0);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
words.push(word);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
words.push(word);
|
||||||
|
}
|
||||||
|
|
||||||
// Swap endianness and flatten
|
// Swap endianness and flatten
|
||||||
for (i = 0; i < words.length; i++) {
|
for (i = 0; i < words.length; i++) {
|
||||||
j = words[i].length;
|
j = words[i].length;
|
||||||
while (j--) {
|
while (j--) {
|
||||||
result.push(words[i][j]);
|
result.push(words[i][j]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert data back to specified data format
|
// Convert data back to specified data format
|
||||||
switch (data_format) {
|
switch (data_format) {
|
||||||
case "Hex":
|
case 'Hex':
|
||||||
return Utils.to_hex(result);
|
return Utils.to_hex(result);
|
||||||
case "Raw":
|
case 'Raw':
|
||||||
return Utils.byte_array_to_utf8(result);
|
return Utils.byte_array_to_utf8(result);
|
||||||
default:
|
default:
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,13 +7,13 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var Entropy = {
|
const Entropy = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
CHUNK_SIZE: 1000,
|
CHUNK_SIZE: 1000,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entropy operation.
|
* Entropy operation.
|
||||||
|
@ -22,21 +22,21 @@ var Entropy = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {html}
|
* @returns {html}
|
||||||
*/
|
*/
|
||||||
run_entropy: function(input, args) {
|
run_entropy(input, args) {
|
||||||
var chunk_size = args[0],
|
let chunk_size = args[0],
|
||||||
output = "",
|
output = '',
|
||||||
entropy = Entropy._calc_entropy(input);
|
entropy = Entropy._calc_entropy(input);
|
||||||
|
|
||||||
output += "Shannon entropy: " + entropy + "\n" +
|
output += `Shannon entropy: ${entropy}\n` +
|
||||||
"<br><canvas id='chart-area'></canvas><br>\n" +
|
'<br><canvas id=\'chart-area\'></canvas><br>\n' +
|
||||||
"- 0 represents no randomness (i.e. all the bytes in the data have the same value) whereas 8, the maximum, represents a completely random string.\n" +
|
'- 0 represents no randomness (i.e. all the bytes in the data have the same value) whereas 8, the maximum, represents a completely random string.\n' +
|
||||||
"- Standard English text usually falls somewhere between 3.5 and 5.\n" +
|
'- Standard English text usually falls somewhere between 3.5 and 5.\n' +
|
||||||
"- Properly encrypted or compressed data of a reasonable length should have an entropy of over 7.5.\n\n" +
|
'- Properly encrypted or compressed data of a reasonable length should have an entropy of over 7.5.\n\n' +
|
||||||
"The following results show the entropy of chunks of the input data. Chunks with particularly high entropy could suggest encrypted or compressed sections.\n\n" +
|
'The following results show the entropy of chunks of the input data. Chunks with particularly high entropy could suggest encrypted or compressed sections.\n\n' +
|
||||||
"<br><script>\
|
`<br><script>\
|
||||||
var canvas = document.getElementById('chart-area'),\
|
var canvas = document.getElementById('chart-area'),\
|
||||||
parent_rect = canvas.parentNode.getBoundingClientRect(),\
|
parent_rect = canvas.parentNode.getBoundingClientRect(),\
|
||||||
entropy = " + entropy + ",\
|
entropy = ${entropy},\
|
||||||
height = parent_rect.height * 0.25;\
|
height = parent_rect.height * 0.25;\
|
||||||
\
|
\
|
||||||
canvas.width = parent_rect.width * 0.95;\
|
canvas.width = parent_rect.width * 0.95;\
|
||||||
|
@ -53,27 +53,27 @@ var Entropy = {
|
||||||
max: 8\
|
max: 8\
|
||||||
}\
|
}\
|
||||||
]);\
|
]);\
|
||||||
</script>";
|
</script>`;
|
||||||
|
|
||||||
var chunk_entropy = 0;
|
let chunk_entropy = 0;
|
||||||
if (chunk_size !== 0) {
|
if (chunk_size !== 0) {
|
||||||
for (var i = 0; i < input.length; i += chunk_size) {
|
for (let i = 0; i < input.length; i += chunk_size) {
|
||||||
chunk_entropy = Entropy._calc_entropy(input.slice(i, i+chunk_size));
|
chunk_entropy = Entropy._calc_entropy(input.slice(i, i + chunk_size));
|
||||||
output += "Bytes " + i + " to " + (i+chunk_size) + ": " + chunk_entropy + "\n";
|
output += `Bytes ${i} to ${i + chunk_size}: ${chunk_entropy}\n`;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
output += "Chunk size cannot be 0.";
|
output += 'Chunk size cannot be 0.';
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
FREQ_ZEROS: false,
|
FREQ_ZEROS: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Frequency distribution operation.
|
* Frequency distribution operation.
|
||||||
|
@ -82,58 +82,58 @@ var Entropy = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {html}
|
* @returns {html}
|
||||||
*/
|
*/
|
||||||
run_freq_distrib: function (input, args) {
|
run_freq_distrib(input, args) {
|
||||||
if (!input.length) return "No data";
|
if (!input.length) return 'No data';
|
||||||
|
|
||||||
var distrib = new Array(256),
|
let distrib = new Array(256),
|
||||||
percentages = new Array(256),
|
percentages = new Array(256),
|
||||||
len = input.length,
|
len = input.length,
|
||||||
show_zeroes = args[0];
|
show_zeroes = args[0];
|
||||||
|
|
||||||
// Initialise distrib to 0
|
// Initialise distrib to 0
|
||||||
for (var i = 0; i < 256; i++) {
|
for (var i = 0; i < 256; i++) {
|
||||||
distrib[i] = 0;
|
distrib[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Count bytes
|
// Count bytes
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
distrib[input[i]]++;
|
distrib[input[i]]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate percentages
|
// Calculate percentages
|
||||||
var repr = 0;
|
let repr = 0;
|
||||||
for (i = 0; i < 256; i++) {
|
for (i = 0; i < 256; i++) {
|
||||||
if (distrib[i] > 0) repr++;
|
if (distrib[i] > 0) repr++;
|
||||||
percentages[i] = distrib[i] / len * 100;
|
percentages[i] = distrib[i] / len * 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Print
|
// Print
|
||||||
var output = "<canvas id='chart-area'></canvas><br>" +
|
let output = `${"<canvas id='chart-area'></canvas><br>" +
|
||||||
"Total data length: " + len +
|
'Total data length: '}${len
|
||||||
"\nNumber of bytes represented: " + repr +
|
}\nNumber of bytes represented: ${repr
|
||||||
"\nNumber of bytes not represented: " + (256-repr) +
|
}\nNumber of bytes not represented: ${256 - repr
|
||||||
"\n\nByte Percentage\n" +
|
}\n\nByte Percentage\n` +
|
||||||
"<script>\
|
`<script>\
|
||||||
var canvas = document.getElementById('chart-area'),\
|
var canvas = document.getElementById('chart-area'),\
|
||||||
parent_rect = canvas.parentNode.getBoundingClientRect(),\
|
parent_rect = canvas.parentNode.getBoundingClientRect(),\
|
||||||
scores = " + JSON.stringify(percentages) + ";\
|
scores = ${JSON.stringify(percentages)};\
|
||||||
\
|
\
|
||||||
canvas.width = parent_rect.width * 0.95;\
|
canvas.width = parent_rect.width * 0.95;\
|
||||||
canvas.height = parent_rect.height * 0.9;\
|
canvas.height = parent_rect.height * 0.9;\
|
||||||
\
|
\
|
||||||
CanvasComponents.draw_bar_chart(canvas, scores, 'Byte', 'Frequency %', 16, 6);\
|
CanvasComponents.draw_bar_chart(canvas, scores, 'Byte', 'Frequency %', 16, 6);\
|
||||||
</script>";
|
</script>`;
|
||||||
|
|
||||||
for (i = 0; i < 256; i++) {
|
for (i = 0; i < 256; i++) {
|
||||||
if (distrib[i] || show_zeroes) {
|
if (distrib[i] || show_zeroes) {
|
||||||
output += " " + Utils.hex(i, 2) + " (" +
|
output += ` ${Utils.hex(i, 2)} (${
|
||||||
Utils.pad_right(percentages[i].toFixed(2).replace(".00", "") + "%)", 8) +
|
Utils.pad_right(`${percentages[i].toFixed(2).replace('.00', '')}%)`, 8)
|
||||||
Array(Math.ceil(percentages[i])+1).join("|") + "\n";
|
}${Array(Math.ceil(percentages[i]) + 1).join('|')}\n`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -143,24 +143,24 @@ var Entropy = {
|
||||||
* @param {byte_array} data
|
* @param {byte_array} data
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
_calc_entropy: function(data) {
|
_calc_entropy(data) {
|
||||||
var prob = [],
|
let prob = [],
|
||||||
uniques = data.unique(),
|
uniques = data.unique(),
|
||||||
str = Utils.byte_array_to_chars(data);
|
str = Utils.byte_array_to_chars(data);
|
||||||
|
|
||||||
for (var i = 0; i < uniques.length; i++) {
|
for (var i = 0; i < uniques.length; i++) {
|
||||||
prob.push(str.count(Utils.chr(uniques[i])) / data.length);
|
prob.push(str.count(Utils.chr(uniques[i])) / data.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
var entropy = 0,
|
let entropy = 0,
|
||||||
p;
|
p;
|
||||||
|
|
||||||
for (i = 0; i < prob.length; i++) {
|
for (i = 0; i < prob.length; i++) {
|
||||||
p = prob[i];
|
p = prob[i];
|
||||||
entropy += p * Math.log(p) / Math.log(2);
|
entropy += p * Math.log(p) / Math.log(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
return -entropy;
|
return -entropy;
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var Extract = {
|
const Extract = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs search operations across the input data using refular expressions.
|
* Runs search operations across the input data using refular expressions.
|
||||||
|
@ -20,35 +20,37 @@ var Extract = {
|
||||||
* @param {boolean} include_total - Whether or not to include the total number of results
|
* @param {boolean} include_total - Whether or not to include the total number of results
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
_search: function(input, search_regex, remove_regex, include_total) {
|
_search(input, search_regex, remove_regex, include_total) {
|
||||||
var output = "",
|
let output = '',
|
||||||
total = 0,
|
total = 0,
|
||||||
match;
|
match;
|
||||||
|
|
||||||
while (!!(match = search_regex.exec(input))) {
|
while (match = search_regex.exec(input)) {
|
||||||
if (remove_regex && remove_regex.test(match[0]))
|
if (remove_regex && remove_regex.test(match[0])) {
|
||||||
continue;
|
continue;
|
||||||
total++;
|
}
|
||||||
output += match[0] + "\n";
|
total++;
|
||||||
}
|
output += `${match[0]}\n`;
|
||||||
|
}
|
||||||
|
|
||||||
if (include_total)
|
if (include_total) {
|
||||||
output = "Total found: " + total + "\n\n" + output;
|
output = `Total found: ${total}\n\n${output}`;
|
||||||
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
MIN_STRING_LEN: 3,
|
MIN_STRING_LEN: 3,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
DISPLAY_TOTAL: false,
|
DISPLAY_TOTAL: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strings operation.
|
* Strings operation.
|
||||||
|
@ -57,31 +59,31 @@ var Extract = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_strings: function(input, args) {
|
run_strings(input, args) {
|
||||||
var min_len = args[0] || Extract.MIN_STRING_LEN,
|
let min_len = args[0] || Extract.MIN_STRING_LEN,
|
||||||
display_total = args[1],
|
display_total = args[1],
|
||||||
strings = "[A-Z\\d/\\-:.,_$%'\"()<>= !\\[\\]{}@]",
|
strings = "[A-Z\\d/\\-:.,_$%'\"()<>= !\\[\\]{}@]",
|
||||||
regex = new RegExp(strings + "{" + min_len + ",}", "ig");
|
regex = new RegExp(`${strings}{${min_len},}`, 'ig');
|
||||||
|
|
||||||
return Extract._search(input, regex, null, display_total);
|
return Extract._search(input, regex, null, display_total);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
INCLUDE_IPV4: true,
|
INCLUDE_IPV4: true,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
INCLUDE_IPV6: false,
|
INCLUDE_IPV6: false,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
REMOVE_LOCAL: false,
|
REMOVE_LOCAL: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract IP addresses operation.
|
* Extract IP addresses operation.
|
||||||
|
@ -90,42 +92,42 @@ var Extract = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_ip: function(input, args) {
|
run_ip(input, args) {
|
||||||
var include_ipv4 = args[0],
|
let include_ipv4 = args[0],
|
||||||
include_ipv6 = args[1],
|
include_ipv6 = args[1],
|
||||||
remove_local = args[2],
|
remove_local = args[2],
|
||||||
display_total = args[3],
|
display_total = args[3],
|
||||||
ipv4 = "(?:(?:\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d|\\d)(?:\\/\\d{1,2})?",
|
ipv4 = '(?:(?:\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d|\\d)(?:\\/\\d{1,2})?',
|
||||||
ipv6 = "((?=.*::)(?!.*::.+::)(::)?([\\dA-F]{1,4}:(:|\\b)|){5}|([\\dA-F]{1,4}:){6})((([\\dA-F]{1,4}((?!\\3)::|:\\b|(?![\\dA-F])))|(?!\\2\\3)){2}|(((2[0-4]|1\\d|[1-9])?\\d|25[0-5])\\.?\\b){4})",
|
ipv6 = '((?=.*::)(?!.*::.+::)(::)?([\\dA-F]{1,4}:(:|\\b)|){5}|([\\dA-F]{1,4}:){6})((([\\dA-F]{1,4}((?!\\3)::|:\\b|(?![\\dA-F])))|(?!\\2\\3)){2}|(((2[0-4]|1\\d|[1-9])?\\d|25[0-5])\\.?\\b){4})',
|
||||||
ips = "";
|
ips = '';
|
||||||
|
|
||||||
if (include_ipv4 && include_ipv6) {
|
if (include_ipv4 && include_ipv6) {
|
||||||
ips = ipv4 + "|" + ipv6;
|
ips = `${ipv4}|${ipv6}`;
|
||||||
} else if (include_ipv4) {
|
} else if (include_ipv4) {
|
||||||
ips = ipv4;
|
ips = ipv4;
|
||||||
} else if (include_ipv6) {
|
} else if (include_ipv6) {
|
||||||
ips = ipv6;
|
ips = ipv6;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ips) {
|
if (ips) {
|
||||||
var regex = new RegExp(ips, "ig");
|
const regex = new RegExp(ips, 'ig');
|
||||||
|
|
||||||
if (remove_local) {
|
if (remove_local) {
|
||||||
var ten = "10\\..+",
|
let ten = '10\\..+',
|
||||||
oneninetwo = "192\\.168\\..+",
|
oneninetwo = '192\\.168\\..+',
|
||||||
oneseventwo = "172\\.(?:1[6-9]|2\\d|3[01])\\..+",
|
oneseventwo = '172\\.(?:1[6-9]|2\\d|3[01])\\..+',
|
||||||
onetwoseven = "127\\..+",
|
onetwoseven = '127\\..+',
|
||||||
remove_regex = new RegExp("^(?:" + ten + "|" + oneninetwo +
|
remove_regex = new RegExp(`^(?:${ten}|${oneninetwo
|
||||||
"|" + oneseventwo + "|" + onetwoseven + ")");
|
}|${oneseventwo}|${onetwoseven})`);
|
||||||
|
|
||||||
return Extract._search(input, regex, remove_regex, display_total);
|
return Extract._search(input, regex, remove_regex, display_total);
|
||||||
} else {
|
} else {
|
||||||
return Extract._search(input, regex, null, display_total);
|
return Extract._search(input, regex, null, display_total);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return "";
|
return '';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -135,12 +137,12 @@ var Extract = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_email: function(input, args) {
|
run_email(input, args) {
|
||||||
var display_total = args[0],
|
let display_total = args[0],
|
||||||
regex = /\w[-.\w]*@[-\w]+(?:\.[-\w]+)*\.[A-Z]{2,4}/ig;
|
regex = /\w[-.\w]*@[-\w]+(?:\.[-\w]+)*\.[A-Z]{2,4}/ig;
|
||||||
|
|
||||||
return Extract._search(input, regex, null, display_total);
|
return Extract._search(input, regex, null, display_total);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -150,12 +152,12 @@ var Extract = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_mac: function(input, args) {
|
run_mac(input, args) {
|
||||||
var display_total = args[0],
|
let display_total = args[0],
|
||||||
regex = /[A-F\d]{2}(?:[:-][A-F\d]{2}){5}/ig;
|
regex = /[A-F\d]{2}(?:[:-][A-F\d]{2}){5}/ig;
|
||||||
|
|
||||||
return Extract._search(input, regex, null, display_total);
|
return Extract._search(input, regex, null, display_total);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -165,18 +167,18 @@ var Extract = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_urls: function(input, args) {
|
run_urls(input, args) {
|
||||||
var display_total = args[0],
|
let display_total = args[0],
|
||||||
protocol = "[A-Z]+://",
|
protocol = '[A-Z]+://',
|
||||||
hostname = "[-\\w]+(?:\\.\\w[-\\w]*)+",
|
hostname = '[-\\w]+(?:\\.\\w[-\\w]*)+',
|
||||||
port = ":\\d+",
|
port = ':\\d+',
|
||||||
path = "/[^.!,?;\"'<>()\\[\\]{}\\s\\x7F-\\xFF]*";
|
path = "/[^.!,?;\"'<>()\\[\\]{}\\s\\x7F-\\xFF]*";
|
||||||
|
|
||||||
path += "(?:[.!,?]+[^.!,?;\"'<>()\\[\\]{}\\s\\x7F-\\xFF]+)*";
|
path += "(?:[.!,?]+[^.!,?;\"'<>()\\[\\]{}\\s\\x7F-\\xFF]+)*";
|
||||||
var regex = new RegExp(protocol + hostname + "(?:" + port +
|
const regex = new RegExp(`${protocol + hostname}(?:${port
|
||||||
")?(?:" + path + ")?", "ig");
|
})?(?:${path})?`, 'ig');
|
||||||
return Extract._search(input, regex, null, display_total);
|
return Extract._search(input, regex, null, display_total);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -186,27 +188,27 @@ var Extract = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_domains: function(input, args) {
|
run_domains(input, args) {
|
||||||
var display_total = args[0],
|
let display_total = args[0],
|
||||||
protocol = "https?://",
|
protocol = 'https?://',
|
||||||
hostname = "[-\\w\\.]+",
|
hostname = '[-\\w\\.]+',
|
||||||
tld = "\\.(?:com|net|org|biz|info|co|uk|onion|int|mobi|name|edu|gov|mil|eu|ac|ae|af|de|ca|ch|cn|cy|es|gb|hk|il|in|io|tv|me|nl|no|nz|ro|ru|tr|us|az|ir|kz|uz|pk)+",
|
tld = '\\.(?:com|net|org|biz|info|co|uk|onion|int|mobi|name|edu|gov|mil|eu|ac|ae|af|de|ca|ch|cn|cy|es|gb|hk|il|in|io|tv|me|nl|no|nz|ro|ru|tr|us|az|ir|kz|uz|pk)+',
|
||||||
regex = new RegExp("(?:" + protocol + ")?" + hostname + tld, "ig");
|
regex = new RegExp(`(?:${protocol})?${hostname}${tld}`, 'ig');
|
||||||
|
|
||||||
return Extract._search(input, regex, null, display_total);
|
return Extract._search(input, regex, null, display_total);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
INCLUDE_WIN_PATH: true,
|
INCLUDE_WIN_PATH: true,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
INCLUDE_UNIX_PATH: true,
|
INCLUDE_UNIX_PATH: true,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extract file paths operation.
|
* Extract file paths operation.
|
||||||
|
@ -215,33 +217,33 @@ var Extract = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_file_paths: function(input, args) {
|
run_file_paths(input, args) {
|
||||||
var include_win_path = args[0],
|
let include_win_path = args[0],
|
||||||
include_unix_path = args[1],
|
include_unix_path = args[1],
|
||||||
display_total = args[2],
|
display_total = args[2],
|
||||||
win_drive = "[A-Z]:\\\\",
|
win_drive = '[A-Z]:\\\\',
|
||||||
win_name = "[A-Z\\d][A-Z\\d\\- '_\\(\\)]{0,61}",
|
win_name = "[A-Z\\d][A-Z\\d\\- '_\\(\\)]{0,61}",
|
||||||
win_ext = "[A-Z\\d]{1,6}",
|
win_ext = '[A-Z\\d]{1,6}',
|
||||||
win_path = win_drive + "(?:" + win_name + "\\\\?)*" + win_name +
|
win_path = `${win_drive}(?:${win_name}\\\\?)*${win_name
|
||||||
"(?:\\." + win_ext + ")?",
|
}(?:\\.${win_ext})?`,
|
||||||
unix_path = "(?:/[A-Z\\d.][A-Z\\d\\-.]{0,61})+",
|
unix_path = '(?:/[A-Z\\d.][A-Z\\d\\-.]{0,61})+',
|
||||||
file_paths = "";
|
file_paths = '';
|
||||||
|
|
||||||
if (include_win_path && include_unix_path) {
|
if (include_win_path && include_unix_path) {
|
||||||
file_paths = win_path + "|" + unix_path;
|
file_paths = `${win_path}|${unix_path}`;
|
||||||
} else if (include_win_path) {
|
} else if (include_win_path) {
|
||||||
file_paths = win_path;
|
file_paths = win_path;
|
||||||
} else if (include_unix_path) {
|
} else if (include_unix_path) {
|
||||||
file_paths = unix_path;
|
file_paths = unix_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_paths) {
|
if (file_paths) {
|
||||||
var regex = new RegExp(file_paths, "ig");
|
const regex = new RegExp(file_paths, 'ig');
|
||||||
return Extract._search(input, regex, null, display_total);
|
return Extract._search(input, regex, null, display_total);
|
||||||
} else {
|
} else {
|
||||||
return "";
|
return '';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -251,15 +253,15 @@ var Extract = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_dates: function(input, args) {
|
run_dates(input, args) {
|
||||||
var display_total = args[0],
|
let display_total = args[0],
|
||||||
date1 = "(?:19|20)\\d\\d[- /.](?:0[1-9]|1[012])[- /.](?:0[1-9]|[12][0-9]|3[01])", // yyyy-mm-dd
|
date1 = '(?:19|20)\\d\\d[- /.](?:0[1-9]|1[012])[- /.](?:0[1-9]|[12][0-9]|3[01])', // yyyy-mm-dd
|
||||||
date2 = "(?:0[1-9]|[12][0-9]|3[01])[- /.](?:0[1-9]|1[012])[- /.](?:19|20)\\d\\d", // dd/mm/yyyy
|
date2 = '(?:0[1-9]|[12][0-9]|3[01])[- /.](?:0[1-9]|1[012])[- /.](?:19|20)\\d\\d', // dd/mm/yyyy
|
||||||
date3 = "(?:0[1-9]|1[012])[- /.](?:0[1-9]|[12][0-9]|3[01])[- /.](?:19|20)\\d\\d", // mm/dd/yyyy
|
date3 = '(?:0[1-9]|1[012])[- /.](?:0[1-9]|[12][0-9]|3[01])[- /.](?:19|20)\\d\\d', // mm/dd/yyyy
|
||||||
regex = new RegExp(date1 + "|" + date2 + "|" + date3, "ig");
|
regex = new RegExp(`${date1}|${date2}|${date3}`, 'ig');
|
||||||
|
|
||||||
return Extract._search(input, regex, null, display_total);
|
return Extract._search(input, regex, null, display_total);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -269,29 +271,29 @@ var Extract = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_all_idents: function(input, args) {
|
run_all_idents(input, args) {
|
||||||
var output = "";
|
let output = '';
|
||||||
output += "IP addresses\n";
|
output += 'IP addresses\n';
|
||||||
output += Extract.run_ip(input, [true, true, false]);
|
output += Extract.run_ip(input, [true, true, false]);
|
||||||
|
|
||||||
output += "\nEmail addresses\n";
|
output += '\nEmail addresses\n';
|
||||||
output += Extract.run_email(input, []);
|
output += Extract.run_email(input, []);
|
||||||
|
|
||||||
output += "\nMAC addresses\n";
|
output += '\nMAC addresses\n';
|
||||||
output += Extract.run_mac(input, []);
|
output += Extract.run_mac(input, []);
|
||||||
|
|
||||||
output += "\nURLs\n";
|
output += '\nURLs\n';
|
||||||
output += Extract.run_urls(input, []);
|
output += Extract.run_urls(input, []);
|
||||||
|
|
||||||
output += "\nDomain names\n";
|
output += '\nDomain names\n';
|
||||||
output += Extract.run_domains(input, []);
|
output += Extract.run_domains(input, []);
|
||||||
|
|
||||||
output += "\nFile paths\n";
|
output += '\nFile paths\n';
|
||||||
output += Extract.run_file_paths(input, [true, true]);
|
output += Extract.run_file_paths(input, [true, true]);
|
||||||
|
|
||||||
output += "\nDates\n";
|
output += '\nDates\n';
|
||||||
output += Extract.run_dates(input, []);
|
output += Extract.run_dates(input, []);
|
||||||
return output;
|
return output;
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var FileType = {
|
const FileType = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detect File Type operation.
|
* Detect File Type operation.
|
||||||
|
@ -16,29 +16,29 @@ var FileType = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_detect: function(input, args) {
|
run_detect(input, args) {
|
||||||
var type = FileType._magic_type(input);
|
const type = FileType._magic_type(input);
|
||||||
|
|
||||||
if (!type) {
|
if (!type) {
|
||||||
return "Unknown file type. Have you tried checking the entropy of this data to determine whether it might be encrypted or compressed?";
|
return 'Unknown file type. Have you tried checking the entropy of this data to determine whether it might be encrypted or compressed?';
|
||||||
} else {
|
} else {
|
||||||
var output = "File extension: " + type.ext + "\n" +
|
let output = `File extension: ${type.ext}\n` +
|
||||||
"MIME type: " + type.mime;
|
`MIME type: ${type.mime}`;
|
||||||
|
|
||||||
if (type.desc && type.desc.length) {
|
if (type.desc && type.desc.length) {
|
||||||
output += "\nDescription: " + type.desc;
|
output += `\nDescription: ${type.desc}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
IGNORE_COMMON_BYTE_SEQUENCES: true,
|
IGNORE_COMMON_BYTE_SEQUENCES: true,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Scan for Embedded Files operation.
|
* Scan for Embedded Files operation.
|
||||||
|
@ -47,46 +47,46 @@ var FileType = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_scan_for_embedded_files: function(input, args) {
|
run_scan_for_embedded_files(input, args) {
|
||||||
var 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 suffiently long file is likely to contain these magic bytes coincidentally.\n",
|
||||||
type,
|
type,
|
||||||
ignore_common = args[0],
|
ignore_common = args[0],
|
||||||
common_exts = ["ico", "ttf", ""],
|
common_exts = ['ico', 'ttf', ''],
|
||||||
num_found = 0,
|
num_found = 0,
|
||||||
num_common_found = 0;
|
num_common_found = 0;
|
||||||
|
|
||||||
for (var i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
type = FileType._magic_type(input.slice(i));
|
type = FileType._magic_type(input.slice(i));
|
||||||
if (type) {
|
if (type) {
|
||||||
if (ignore_common && common_exts.indexOf(type.ext) > -1) {
|
if (ignore_common && common_exts.indexOf(type.ext) > -1) {
|
||||||
num_common_found++;
|
num_common_found++;
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
num_found++;
|
|
||||||
output += "\nOffset " + i + " (0x" + Utils.hex(i) + "):\n" +
|
|
||||||
" File extension: " + type.ext + "\n" +
|
|
||||||
" MIME type: " + type.mime + "\n";
|
|
||||||
|
|
||||||
if (type.desc && type.desc.length) {
|
|
||||||
output += " Description: " + type.desc + "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
num_found++;
|
||||||
|
output += `\nOffset ${i} (0x${Utils.hex(i)}):\n` +
|
||||||
|
` File extension: ${type.ext}\n` +
|
||||||
|
` MIME type: ${type.mime}\n`;
|
||||||
|
|
||||||
if (num_found === 0) {
|
if (type.desc && type.desc.length) {
|
||||||
output += "\nNo embedded files were found.";
|
output += ` Description: ${type.desc}\n`;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (num_common_found > 0) {
|
if (num_found === 0) {
|
||||||
output += "\n\n" + num_common_found;
|
output += '\nNo embedded files were found.';
|
||||||
output += num_common_found == 1 ?
|
}
|
||||||
" file type was detected that has a common byte sequence. This is likely to be a false positive." :
|
|
||||||
" file types were detected that have common byte sequences. These are likely to be false positives.";
|
|
||||||
output += " Run this operation with the 'Ignore common byte sequences' option unchecked to see details.";
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
if (num_common_found > 0) {
|
||||||
},
|
output += `\n\n${num_common_found}`;
|
||||||
|
output += num_common_found == 1 ?
|
||||||
|
' file type was detected that has a common byte sequence. This is likely to be a false positive.' :
|
||||||
|
' file types were detected that have common byte sequences. These are likely to be false positives.';
|
||||||
|
output += " Run this operation with the 'Ignore common byte sequences' option unchecked to see details.";
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -100,427 +100,427 @@ var FileType = {
|
||||||
* @returns {string} type.mime - Mime type
|
* @returns {string} type.mime - Mime type
|
||||||
* @returns {string} [type.desc] - Description
|
* @returns {string} [type.desc] - Description
|
||||||
*/
|
*/
|
||||||
_magic_type: function (buf) {
|
_magic_type(buf) {
|
||||||
if (!(buf && buf.length > 1)) {
|
if (!(buf && buf.length > 1)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0xFF && buf[1] === 0xD8 && buf[2] === 0xFF) {
|
if (buf[0] === 0xFF && buf[1] === 0xD8 && buf[2] === 0xFF) {
|
||||||
return {
|
return {
|
||||||
ext: 'jpg',
|
ext: 'jpg',
|
||||||
mime: 'image/jpeg'
|
mime: 'image/jpeg',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x89 && buf[1] === 0x50 && buf[2] === 0x4E && buf[3] === 0x47) {
|
if (buf[0] === 0x89 && buf[1] === 0x50 && buf[2] === 0x4E && buf[3] === 0x47) {
|
||||||
return {
|
return {
|
||||||
ext: 'png',
|
ext: 'png',
|
||||||
mime: 'image/png'
|
mime: 'image/png',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x47 && buf[1] === 0x49 && buf[2] === 0x46) {
|
if (buf[0] === 0x47 && buf[1] === 0x49 && buf[2] === 0x46) {
|
||||||
return {
|
return {
|
||||||
ext: 'gif',
|
ext: 'gif',
|
||||||
mime: 'image/gif'
|
mime: 'image/gif',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[8] === 0x57 && buf[9] === 0x45 && buf[10] === 0x42 && buf[11] === 0x50) {
|
if (buf[8] === 0x57 && buf[9] === 0x45 && buf[10] === 0x42 && buf[11] === 0x50) {
|
||||||
return {
|
return {
|
||||||
ext: 'webp',
|
ext: 'webp',
|
||||||
mime: 'image/webp'
|
mime: 'image/webp',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// needs to be before `tif` check
|
// needs to be before `tif` check
|
||||||
if (((buf[0] === 0x49 && buf[1] === 0x49 && buf[2] === 0x2A && buf[3] === 0x0) || (buf[0] === 0x4D && buf[1] === 0x4D && buf[2] === 0x0 && buf[3] === 0x2A)) && buf[8] === 0x43 && buf[9] === 0x52) {
|
if (((buf[0] === 0x49 && buf[1] === 0x49 && buf[2] === 0x2A && buf[3] === 0x0) || (buf[0] === 0x4D && buf[1] === 0x4D && buf[2] === 0x0 && buf[3] === 0x2A)) && buf[8] === 0x43 && buf[9] === 0x52) {
|
||||||
return {
|
return {
|
||||||
ext: 'cr2',
|
ext: 'cr2',
|
||||||
mime: 'image/x-canon-cr2'
|
mime: 'image/x-canon-cr2',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((buf[0] === 0x49 && buf[1] === 0x49 && buf[2] === 0x2A && buf[3] === 0x0) || (buf[0] === 0x4D && buf[1] === 0x4D && buf[2] === 0x0 && buf[3] === 0x2A)) {
|
if ((buf[0] === 0x49 && buf[1] === 0x49 && buf[2] === 0x2A && buf[3] === 0x0) || (buf[0] === 0x4D && buf[1] === 0x4D && buf[2] === 0x0 && buf[3] === 0x2A)) {
|
||||||
return {
|
return {
|
||||||
ext: 'tif',
|
ext: 'tif',
|
||||||
mime: 'image/tiff'
|
mime: 'image/tiff',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x42 && buf[1] === 0x4D) {
|
if (buf[0] === 0x42 && buf[1] === 0x4D) {
|
||||||
return {
|
return {
|
||||||
ext: 'bmp',
|
ext: 'bmp',
|
||||||
mime: 'image/bmp'
|
mime: 'image/bmp',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x49 && buf[1] === 0x49 && buf[2] === 0xBC) {
|
if (buf[0] === 0x49 && buf[1] === 0x49 && buf[2] === 0xBC) {
|
||||||
return {
|
return {
|
||||||
ext: 'jxr',
|
ext: 'jxr',
|
||||||
mime: 'image/vnd.ms-photo'
|
mime: 'image/vnd.ms-photo',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x38 && buf[1] === 0x42 && buf[2] === 0x50 && buf[3] === 0x53) {
|
if (buf[0] === 0x38 && buf[1] === 0x42 && buf[2] === 0x50 && buf[3] === 0x53) {
|
||||||
return {
|
return {
|
||||||
ext: 'psd',
|
ext: 'psd',
|
||||||
mime: 'image/vnd.adobe.photoshop'
|
mime: 'image/vnd.adobe.photoshop',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// needs to be before `zip` check
|
// needs to be before `zip` check
|
||||||
if (buf[0] === 0x50 && buf[1] === 0x4B && buf[2] === 0x3 && buf[3] === 0x4 && buf[30] === 0x6D && buf[31] === 0x69 && buf[32] === 0x6D && buf[33] === 0x65 && buf[34] === 0x74 && buf[35] === 0x79 && buf[36] === 0x70 && buf[37] === 0x65 && buf[38] === 0x61 && buf[39] === 0x70 && buf[40] === 0x70 && buf[41] === 0x6C && buf[42] === 0x69 && buf[43] === 0x63 && buf[44] === 0x61 && buf[45] === 0x74 && buf[46] === 0x69 && buf[47] === 0x6F && buf[48] === 0x6E && buf[49] === 0x2F && buf[50] === 0x65 && buf[51] === 0x70 && buf[52] === 0x75 && buf[53] === 0x62 && buf[54] === 0x2B && buf[55] === 0x7A && buf[56] === 0x69 && buf[57] === 0x70) {
|
if (buf[0] === 0x50 && buf[1] === 0x4B && buf[2] === 0x3 && buf[3] === 0x4 && buf[30] === 0x6D && buf[31] === 0x69 && buf[32] === 0x6D && buf[33] === 0x65 && buf[34] === 0x74 && buf[35] === 0x79 && buf[36] === 0x70 && buf[37] === 0x65 && buf[38] === 0x61 && buf[39] === 0x70 && buf[40] === 0x70 && buf[41] === 0x6C && buf[42] === 0x69 && buf[43] === 0x63 && buf[44] === 0x61 && buf[45] === 0x74 && buf[46] === 0x69 && buf[47] === 0x6F && buf[48] === 0x6E && buf[49] === 0x2F && buf[50] === 0x65 && buf[51] === 0x70 && buf[52] === 0x75 && buf[53] === 0x62 && buf[54] === 0x2B && buf[55] === 0x7A && buf[56] === 0x69 && buf[57] === 0x70) {
|
||||||
return {
|
return {
|
||||||
ext: 'epub',
|
ext: 'epub',
|
||||||
mime: 'application/epub+zip'
|
mime: 'application/epub+zip',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x50 && buf[1] === 0x4B && (buf[2] === 0x3 || buf[2] === 0x5 || buf[2] === 0x7) && (buf[3] === 0x4 || buf[3] === 0x6 || buf[3] === 0x8)) {
|
if (buf[0] === 0x50 && buf[1] === 0x4B && (buf[2] === 0x3 || buf[2] === 0x5 || buf[2] === 0x7) && (buf[3] === 0x4 || buf[3] === 0x6 || buf[3] === 0x8)) {
|
||||||
return {
|
return {
|
||||||
ext: 'zip',
|
ext: 'zip',
|
||||||
mime: 'application/zip'
|
mime: 'application/zip',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[257] === 0x75 && buf[258] === 0x73 && buf[259] === 0x74 && buf[260] === 0x61 && buf[261] === 0x72) {
|
if (buf[257] === 0x75 && buf[258] === 0x73 && buf[259] === 0x74 && buf[260] === 0x61 && buf[261] === 0x72) {
|
||||||
return {
|
return {
|
||||||
ext: 'tar',
|
ext: 'tar',
|
||||||
mime: 'application/x-tar'
|
mime: 'application/x-tar',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x52 && buf[1] === 0x61 && buf[2] === 0x72 && buf[3] === 0x21 && buf[4] === 0x1A && buf[5] === 0x7 && (buf[6] === 0x0 || buf[6] === 0x1)) {
|
if (buf[0] === 0x52 && buf[1] === 0x61 && buf[2] === 0x72 && buf[3] === 0x21 && buf[4] === 0x1A && buf[5] === 0x7 && (buf[6] === 0x0 || buf[6] === 0x1)) {
|
||||||
return {
|
return {
|
||||||
ext: 'rar',
|
ext: 'rar',
|
||||||
mime: 'application/x-rar-compressed'
|
mime: 'application/x-rar-compressed',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x1F && buf[1] === 0x8B && buf[2] === 0x8) {
|
if (buf[0] === 0x1F && buf[1] === 0x8B && buf[2] === 0x8) {
|
||||||
return {
|
return {
|
||||||
ext: 'gz',
|
ext: 'gz',
|
||||||
mime: 'application/gzip'
|
mime: 'application/gzip',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x42 && buf[1] === 0x5A && buf[2] === 0x68) {
|
if (buf[0] === 0x42 && buf[1] === 0x5A && buf[2] === 0x68) {
|
||||||
return {
|
return {
|
||||||
ext: 'bz2',
|
ext: 'bz2',
|
||||||
mime: 'application/x-bzip2'
|
mime: 'application/x-bzip2',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x37 && buf[1] === 0x7A && buf[2] === 0xBC && buf[3] === 0xAF && buf[4] === 0x27 && buf[5] === 0x1C) {
|
if (buf[0] === 0x37 && buf[1] === 0x7A && buf[2] === 0xBC && buf[3] === 0xAF && buf[4] === 0x27 && buf[5] === 0x1C) {
|
||||||
return {
|
return {
|
||||||
ext: '7z',
|
ext: '7z',
|
||||||
mime: 'application/x-7z-compressed'
|
mime: 'application/x-7z-compressed',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x78 && buf[1] === 0x01) {
|
if (buf[0] === 0x78 && buf[1] === 0x01) {
|
||||||
return {
|
return {
|
||||||
ext: 'dmg',
|
ext: 'dmg',
|
||||||
mime: 'application/x-apple-diskimage'
|
mime: 'application/x-apple-diskimage',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((buf[0] === 0x0 && buf[1] === 0x0 && buf[2] === 0x0 && (buf[3] === 0x18 || buf[3] === 0x20) && buf[4] === 0x66 && buf[5] === 0x74 && buf[6] === 0x79 && buf[7] === 0x70) || (buf[0] === 0x33 && buf[1] === 0x67 && buf[2] === 0x70 && buf[3] === 0x35) || (buf[0] === 0x0 && buf[1] === 0x0 && buf[2] === 0x0 && buf[3] === 0x1C && buf[4] === 0x66 && buf[5] === 0x74 && buf[6] === 0x79 && buf[7] === 0x70 && buf[8] === 0x6D && buf[9] === 0x70 && buf[10] === 0x34 && buf[11] === 0x32 && buf[16] === 0x6D && buf[17] === 0x70 && buf[18] === 0x34 && buf[19] === 0x31 && buf[20] === 0x6D && buf[21] === 0x70 && buf[22] === 0x34 && buf[23] === 0x32 && buf[24] === 0x69 && buf[25] === 0x73 && buf[26] === 0x6F && buf[27] === 0x6D)) {
|
if ((buf[0] === 0x0 && buf[1] === 0x0 && buf[2] === 0x0 && (buf[3] === 0x18 || buf[3] === 0x20) && buf[4] === 0x66 && buf[5] === 0x74 && buf[6] === 0x79 && buf[7] === 0x70) || (buf[0] === 0x33 && buf[1] === 0x67 && buf[2] === 0x70 && buf[3] === 0x35) || (buf[0] === 0x0 && buf[1] === 0x0 && buf[2] === 0x0 && buf[3] === 0x1C && buf[4] === 0x66 && buf[5] === 0x74 && buf[6] === 0x79 && buf[7] === 0x70 && buf[8] === 0x6D && buf[9] === 0x70 && buf[10] === 0x34 && buf[11] === 0x32 && buf[16] === 0x6D && buf[17] === 0x70 && buf[18] === 0x34 && buf[19] === 0x31 && buf[20] === 0x6D && buf[21] === 0x70 && buf[22] === 0x34 && buf[23] === 0x32 && buf[24] === 0x69 && buf[25] === 0x73 && buf[26] === 0x6F && buf[27] === 0x6D)) {
|
||||||
return {
|
return {
|
||||||
ext: 'mp4',
|
ext: 'mp4',
|
||||||
mime: 'video/mp4'
|
mime: 'video/mp4',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((buf[0] === 0x0 && buf[1] === 0x0 && buf[2] === 0x0 && buf[3] === 0x1C && buf[4] === 0x66 && buf[5] === 0x74 && buf[6] === 0x79 && buf[7] === 0x70 && buf[8] === 0x4D && buf[9] === 0x34 && buf[10] === 0x56)) {
|
if ((buf[0] === 0x0 && buf[1] === 0x0 && buf[2] === 0x0 && buf[3] === 0x1C && buf[4] === 0x66 && buf[5] === 0x74 && buf[6] === 0x79 && buf[7] === 0x70 && buf[8] === 0x4D && buf[9] === 0x34 && buf[10] === 0x56)) {
|
||||||
return {
|
return {
|
||||||
ext: 'm4v',
|
ext: 'm4v',
|
||||||
mime: 'video/x-m4v'
|
mime: 'video/x-m4v',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x4D && buf[1] === 0x54 && buf[2] === 0x68 && buf[3] === 0x64) {
|
if (buf[0] === 0x4D && buf[1] === 0x54 && buf[2] === 0x68 && buf[3] === 0x64) {
|
||||||
return {
|
return {
|
||||||
ext: 'mid',
|
ext: 'mid',
|
||||||
mime: 'audio/midi'
|
mime: 'audio/midi',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// needs to be before the `webm` check
|
// needs to be before the `webm` check
|
||||||
if (buf[31] === 0x6D && buf[32] === 0x61 && buf[33] === 0x74 && buf[34] === 0x72 && buf[35] === 0x6f && buf[36] === 0x73 && buf[37] === 0x6B && buf[38] === 0x61) {
|
if (buf[31] === 0x6D && buf[32] === 0x61 && buf[33] === 0x74 && buf[34] === 0x72 && buf[35] === 0x6f && buf[36] === 0x73 && buf[37] === 0x6B && buf[38] === 0x61) {
|
||||||
return {
|
return {
|
||||||
ext: 'mkv',
|
ext: 'mkv',
|
||||||
mime: 'video/x-matroska'
|
mime: 'video/x-matroska',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x1A && buf[1] === 0x45 && buf[2] === 0xDF && buf[3] === 0xA3) {
|
if (buf[0] === 0x1A && buf[1] === 0x45 && buf[2] === 0xDF && buf[3] === 0xA3) {
|
||||||
return {
|
return {
|
||||||
ext: 'webm',
|
ext: 'webm',
|
||||||
mime: 'video/webm'
|
mime: 'video/webm',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x0 && buf[1] === 0x0 && buf[2] === 0x0 && buf[3] === 0x14 && buf[4] === 0x66 && buf[5] === 0x74 && buf[6] === 0x79 && buf[7] === 0x70) {
|
if (buf[0] === 0x0 && buf[1] === 0x0 && buf[2] === 0x0 && buf[3] === 0x14 && buf[4] === 0x66 && buf[5] === 0x74 && buf[6] === 0x79 && buf[7] === 0x70) {
|
||||||
return {
|
return {
|
||||||
ext: 'mov',
|
ext: 'mov',
|
||||||
mime: 'video/quicktime'
|
mime: 'video/quicktime',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x52 && buf[1] === 0x49 && buf[2] === 0x46 && buf[3] === 0x46 && buf[8] === 0x41 && buf[9] === 0x56 && buf[10] === 0x49) {
|
if (buf[0] === 0x52 && buf[1] === 0x49 && buf[2] === 0x46 && buf[3] === 0x46 && buf[8] === 0x41 && buf[9] === 0x56 && buf[10] === 0x49) {
|
||||||
return {
|
return {
|
||||||
ext: 'avi',
|
ext: 'avi',
|
||||||
mime: 'video/x-msvideo'
|
mime: 'video/x-msvideo',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x30 && buf[1] === 0x26 && buf[2] === 0xB2 && buf[3] === 0x75 && buf[4] === 0x8E && buf[5] === 0x66 && buf[6] === 0xCF && buf[7] === 0x11 && buf[8] === 0xA6 && buf[9] === 0xD9) {
|
if (buf[0] === 0x30 && buf[1] === 0x26 && buf[2] === 0xB2 && buf[3] === 0x75 && buf[4] === 0x8E && buf[5] === 0x66 && buf[6] === 0xCF && buf[7] === 0x11 && buf[8] === 0xA6 && buf[9] === 0xD9) {
|
||||||
return {
|
return {
|
||||||
ext: 'wmv',
|
ext: 'wmv',
|
||||||
mime: 'video/x-ms-wmv'
|
mime: 'video/x-ms-wmv',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x0 && buf[1] === 0x0 && buf[2] === 0x1 && buf[3].toString(16)[0] === 'b') {
|
if (buf[0] === 0x0 && buf[1] === 0x0 && buf[2] === 0x1 && buf[3].toString(16)[0] === 'b') {
|
||||||
return {
|
return {
|
||||||
ext: 'mpg',
|
ext: 'mpg',
|
||||||
mime: 'video/mpeg'
|
mime: 'video/mpeg',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((buf[0] === 0x49 && buf[1] === 0x44 && buf[2] === 0x33) || (buf[0] === 0xFF && buf[1] === 0xfb)) {
|
if ((buf[0] === 0x49 && buf[1] === 0x44 && buf[2] === 0x33) || (buf[0] === 0xFF && buf[1] === 0xfb)) {
|
||||||
return {
|
return {
|
||||||
ext: 'mp3',
|
ext: 'mp3',
|
||||||
mime: 'audio/mpeg'
|
mime: 'audio/mpeg',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((buf[4] === 0x66 && buf[5] === 0x74 && buf[6] === 0x79 && buf[7] === 0x70 && buf[8] === 0x4D && buf[9] === 0x34 && buf[10] === 0x41) || (buf[0] === 0x4D && buf[1] === 0x34 && buf[2] === 0x41 && buf[3] === 0x20)) {
|
if ((buf[4] === 0x66 && buf[5] === 0x74 && buf[6] === 0x79 && buf[7] === 0x70 && buf[8] === 0x4D && buf[9] === 0x34 && buf[10] === 0x41) || (buf[0] === 0x4D && buf[1] === 0x34 && buf[2] === 0x41 && buf[3] === 0x20)) {
|
||||||
return {
|
return {
|
||||||
ext: 'm4a',
|
ext: 'm4a',
|
||||||
mime: 'audio/m4a'
|
mime: 'audio/m4a',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x4F && buf[1] === 0x67 && buf[2] === 0x67 && buf[3] === 0x53) {
|
if (buf[0] === 0x4F && buf[1] === 0x67 && buf[2] === 0x67 && buf[3] === 0x53) {
|
||||||
return {
|
return {
|
||||||
ext: 'ogg',
|
ext: 'ogg',
|
||||||
mime: 'audio/ogg'
|
mime: 'audio/ogg',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x66 && buf[1] === 0x4C && buf[2] === 0x61 && buf[3] === 0x43) {
|
if (buf[0] === 0x66 && buf[1] === 0x4C && buf[2] === 0x61 && buf[3] === 0x43) {
|
||||||
return {
|
return {
|
||||||
ext: 'flac',
|
ext: 'flac',
|
||||||
mime: 'audio/x-flac'
|
mime: 'audio/x-flac',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x52 && buf[1] === 0x49 && buf[2] === 0x46 && buf[3] === 0x46 && buf[8] === 0x57 && buf[9] === 0x41 && buf[10] === 0x56 && buf[11] === 0x45) {
|
if (buf[0] === 0x52 && buf[1] === 0x49 && buf[2] === 0x46 && buf[3] === 0x46 && buf[8] === 0x57 && buf[9] === 0x41 && buf[10] === 0x56 && buf[11] === 0x45) {
|
||||||
return {
|
return {
|
||||||
ext: 'wav',
|
ext: 'wav',
|
||||||
mime: 'audio/x-wav'
|
mime: 'audio/x-wav',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x23 && buf[1] === 0x21 && buf[2] === 0x41 && buf[3] === 0x4D && buf[4] === 0x52 && buf[5] === 0x0A) {
|
if (buf[0] === 0x23 && buf[1] === 0x21 && buf[2] === 0x41 && buf[3] === 0x4D && buf[4] === 0x52 && buf[5] === 0x0A) {
|
||||||
return {
|
return {
|
||||||
ext: 'amr',
|
ext: 'amr',
|
||||||
mime: 'audio/amr'
|
mime: 'audio/amr',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x25 && buf[1] === 0x50 && buf[2] === 0x44 && buf[3] === 0x46) {
|
if (buf[0] === 0x25 && buf[1] === 0x50 && buf[2] === 0x44 && buf[3] === 0x46) {
|
||||||
return {
|
return {
|
||||||
ext: 'pdf',
|
ext: 'pdf',
|
||||||
mime: 'application/pdf'
|
mime: 'application/pdf',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x4D && buf[1] === 0x5A) {
|
if (buf[0] === 0x4D && buf[1] === 0x5A) {
|
||||||
return {
|
return {
|
||||||
ext: 'exe',
|
ext: 'exe',
|
||||||
mime: 'application/x-msdownload'
|
mime: 'application/x-msdownload',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((buf[0] === 0x43 || buf[0] === 0x46) && buf[1] === 0x57 && buf[2] === 0x53) {
|
if ((buf[0] === 0x43 || buf[0] === 0x46) && buf[1] === 0x57 && buf[2] === 0x53) {
|
||||||
return {
|
return {
|
||||||
ext: 'swf',
|
ext: 'swf',
|
||||||
mime: 'application/x-shockwave-flash'
|
mime: 'application/x-shockwave-flash',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x7B && buf[1] === 0x5C && buf[2] === 0x72 && buf[3] === 0x74 && buf[4] === 0x66) {
|
if (buf[0] === 0x7B && buf[1] === 0x5C && buf[2] === 0x72 && buf[3] === 0x74 && buf[4] === 0x66) {
|
||||||
return {
|
return {
|
||||||
ext: 'rtf',
|
ext: 'rtf',
|
||||||
mime: 'application/rtf'
|
mime: 'application/rtf',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x77 && buf[1] === 0x4F && buf[2] === 0x46 && buf[3] === 0x46 && buf[4] === 0x00 && buf[5] === 0x01 && buf[6] === 0x00 && buf[7] === 0x00) {
|
if (buf[0] === 0x77 && buf[1] === 0x4F && buf[2] === 0x46 && buf[3] === 0x46 && buf[4] === 0x00 && buf[5] === 0x01 && buf[6] === 0x00 && buf[7] === 0x00) {
|
||||||
return {
|
return {
|
||||||
ext: 'woff',
|
ext: 'woff',
|
||||||
mime: 'application/font-woff'
|
mime: 'application/font-woff',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x77 && buf[1] === 0x4F && buf[2] === 0x46 && buf[3] === 0x32 && buf[4] === 0x00 && buf[5] === 0x01 && buf[6] === 0x00 && buf[7] === 0x00) {
|
if (buf[0] === 0x77 && buf[1] === 0x4F && buf[2] === 0x46 && buf[3] === 0x32 && buf[4] === 0x00 && buf[5] === 0x01 && buf[6] === 0x00 && buf[7] === 0x00) {
|
||||||
return {
|
return {
|
||||||
ext: 'woff2',
|
ext: 'woff2',
|
||||||
mime: 'application/font-woff'
|
mime: 'application/font-woff',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[34] === 0x4C && buf[35] === 0x50 && ((buf[8] === 0x02 && buf[9] === 0x00 && buf[10] === 0x01) || (buf[8] === 0x01 && buf[9] === 0x00 && buf[10] === 0x00) || (buf[8] === 0x02 && buf[9] === 0x00 && buf[10] === 0x02))) {
|
if (buf[34] === 0x4C && buf[35] === 0x50 && ((buf[8] === 0x02 && buf[9] === 0x00 && buf[10] === 0x01) || (buf[8] === 0x01 && buf[9] === 0x00 && buf[10] === 0x00) || (buf[8] === 0x02 && buf[9] === 0x00 && buf[10] === 0x02))) {
|
||||||
return {
|
return {
|
||||||
ext: 'eot',
|
ext: 'eot',
|
||||||
mime: 'application/octet-stream'
|
mime: 'application/octet-stream',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x00 && buf[1] === 0x01 && buf[2] === 0x00 && buf[3] === 0x00 && buf[4] === 0x00) {
|
if (buf[0] === 0x00 && buf[1] === 0x01 && buf[2] === 0x00 && buf[3] === 0x00 && buf[4] === 0x00) {
|
||||||
return {
|
return {
|
||||||
ext: 'ttf',
|
ext: 'ttf',
|
||||||
mime: 'application/font-sfnt'
|
mime: 'application/font-sfnt',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x4F && buf[1] === 0x54 && buf[2] === 0x54 && buf[3] === 0x4F && buf[4] === 0x00) {
|
if (buf[0] === 0x4F && buf[1] === 0x54 && buf[2] === 0x54 && buf[3] === 0x4F && buf[4] === 0x00) {
|
||||||
return {
|
return {
|
||||||
ext: 'otf',
|
ext: 'otf',
|
||||||
mime: 'application/font-sfnt'
|
mime: 'application/font-sfnt',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x00 && buf[1] === 0x00 && buf[2] === 0x01 && buf[3] === 0x00) {
|
if (buf[0] === 0x00 && buf[1] === 0x00 && buf[2] === 0x01 && buf[3] === 0x00) {
|
||||||
return {
|
return {
|
||||||
ext: 'ico',
|
ext: 'ico',
|
||||||
mime: 'image/x-icon'
|
mime: 'image/x-icon',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x46 && buf[1] === 0x4C && buf[2] === 0x56 && buf[3] === 0x01) {
|
if (buf[0] === 0x46 && buf[1] === 0x4C && buf[2] === 0x56 && buf[3] === 0x01) {
|
||||||
return {
|
return {
|
||||||
ext: 'flv',
|
ext: 'flv',
|
||||||
mime: 'video/x-flv'
|
mime: 'video/x-flv',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x25 && buf[1] === 0x21) {
|
if (buf[0] === 0x25 && buf[1] === 0x21) {
|
||||||
return {
|
return {
|
||||||
ext: 'ps',
|
ext: 'ps',
|
||||||
mime: 'application/postscript'
|
mime: 'application/postscript',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0xFD && buf[1] === 0x37 && buf[2] === 0x7A && buf[3] === 0x58 && buf[4] === 0x5A && buf[5] === 0x00) {
|
if (buf[0] === 0xFD && buf[1] === 0x37 && buf[2] === 0x7A && buf[3] === 0x58 && buf[4] === 0x5A && buf[5] === 0x00) {
|
||||||
return {
|
return {
|
||||||
ext: 'xz',
|
ext: 'xz',
|
||||||
mime: 'application/x-xz'
|
mime: 'application/x-xz',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x53 && buf[1] === 0x51 && buf[2] === 0x4C && buf[3] === 0x69) {
|
if (buf[0] === 0x53 && buf[1] === 0x51 && buf[2] === 0x4C && buf[3] === 0x69) {
|
||||||
return {
|
return {
|
||||||
ext: 'sqlite',
|
ext: 'sqlite',
|
||||||
mime: 'application/x-sqlite3'
|
mime: 'application/x-sqlite3',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Added by n1474335 [n1474335@gmail.com] from here on
|
// Added by n1474335 [n1474335@gmail.com] from here on
|
||||||
// ################################################################## //
|
// ################################################################## //
|
||||||
if ((buf[0] === 0x1F && buf[1] === 0x9D) || (buf[0] === 0x1F && buf[1] === 0xA0)) {
|
if ((buf[0] === 0x1F && buf[1] === 0x9D) || (buf[0] === 0x1F && buf[1] === 0xA0)) {
|
||||||
return {
|
return {
|
||||||
ext: 'z, tar.z',
|
ext: 'z, tar.z',
|
||||||
mime: 'application/x-gtar'
|
mime: 'application/x-gtar',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x7F && buf[1] === 0x45 && buf[2] === 0x4C && buf[3] === 0x46) {
|
if (buf[0] === 0x7F && buf[1] === 0x45 && buf[2] === 0x4C && buf[3] === 0x46) {
|
||||||
return {
|
return {
|
||||||
ext: 'none, axf, bin, elf, o, prx, puff, so',
|
ext: 'none, axf, bin, elf, o, prx, puff, so',
|
||||||
mime: 'application/x-executable',
|
mime: 'application/x-executable',
|
||||||
desc: 'Executable and Linkable Format file. No standard file extension.'
|
desc: 'Executable and Linkable Format file. No standard file extension.',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0xCA && buf[1] === 0xFE && buf[2] === 0xBA && buf[3] === 0xBE) {
|
if (buf[0] === 0xCA && buf[1] === 0xFE && buf[2] === 0xBA && buf[3] === 0xBE) {
|
||||||
return {
|
return {
|
||||||
ext: 'class',
|
ext: 'class',
|
||||||
mime: 'application/java-vm'
|
mime: 'application/java-vm',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0xEF && buf[1] === 0xBB && buf[2] === 0xBF) {
|
if (buf[0] === 0xEF && buf[1] === 0xBB && buf[2] === 0xBF) {
|
||||||
return {
|
return {
|
||||||
ext: 'txt',
|
ext: 'txt',
|
||||||
mime: 'text/plain',
|
mime: 'text/plain',
|
||||||
desc: 'UTF-8 encoded Unicode byte order mark detected, commonly but not exclusively seen in text files.'
|
desc: 'UTF-8 encoded Unicode byte order mark detected, commonly but not exclusively seen in text files.',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// Must be before Little-endian UTF-16 BOM
|
// Must be before Little-endian UTF-16 BOM
|
||||||
if (buf[0] === 0xFF && buf[1] === 0xFE && buf[2] === 0x00 && buf[3] === 0x00) {
|
if (buf[0] === 0xFF && buf[1] === 0xFE && buf[2] === 0x00 && buf[3] === 0x00) {
|
||||||
return {
|
return {
|
||||||
ext: '',
|
ext: '',
|
||||||
mime: '',
|
mime: '',
|
||||||
desc: 'Little-endian UTF-32 encoded Unicode byte order mark detected.'
|
desc: 'Little-endian UTF-32 encoded Unicode byte order mark detected.',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0xFF && buf[1] === 0xFE) {
|
if (buf[0] === 0xFF && buf[1] === 0xFE) {
|
||||||
return {
|
return {
|
||||||
ext: '',
|
ext: '',
|
||||||
mime: '',
|
mime: '',
|
||||||
desc: 'Little-endian UTF-16 encoded Unicode byte order mark detected.'
|
desc: 'Little-endian UTF-16 encoded Unicode byte order mark detected.',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((buf[0x8001] === 0x43 && buf[0x8002] === 0x44 && buf[0x8003] === 0x30 && buf[0x8004] === 0x30 && buf[0x8005] === 0x31) ||
|
if ((buf[0x8001] === 0x43 && buf[0x8002] === 0x44 && buf[0x8003] === 0x30 && buf[0x8004] === 0x30 && buf[0x8005] === 0x31) ||
|
||||||
(buf[0x8801] === 0x43 && buf[0x8802] === 0x44 && buf[0x8803] === 0x30 && buf[0x8804] === 0x30 && buf[0x8805] === 0x31) ||
|
(buf[0x8801] === 0x43 && buf[0x8802] === 0x44 && buf[0x8803] === 0x30 && buf[0x8804] === 0x30 && buf[0x8805] === 0x31) ||
|
||||||
(buf[0x9001] === 0x43 && buf[0x9002] === 0x44 && buf[0x9003] === 0x30 && buf[0x9004] === 0x30 && buf[0x9005] === 0x31)) {
|
(buf[0x9001] === 0x43 && buf[0x9002] === 0x44 && buf[0x9003] === 0x30 && buf[0x9004] === 0x30 && buf[0x9005] === 0x31)) {
|
||||||
return {
|
return {
|
||||||
ext: 'iso',
|
ext: 'iso',
|
||||||
mime: 'application/octet-stream',
|
mime: 'application/octet-stream',
|
||||||
desc: 'ISO 9660 CD/DVD image file'
|
desc: 'ISO 9660 CD/DVD image file',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0xD0 && buf[1] === 0xCF && buf[2] === 0x11 && buf[3] === 0xE0 && buf[4] === 0xA1 && buf[5] === 0xB1 && buf[6] === 0x1A && buf[7] === 0xE1) {
|
if (buf[0] === 0xD0 && buf[1] === 0xCF && buf[2] === 0x11 && buf[3] === 0xE0 && buf[4] === 0xA1 && buf[5] === 0xB1 && buf[6] === 0x1A && buf[7] === 0xE1) {
|
||||||
return {
|
return {
|
||||||
ext: 'doc, xls, ppt',
|
ext: 'doc, xls, ppt',
|
||||||
mime: 'application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint',
|
mime: 'application/msword, application/vnd.ms-excel, application/vnd.ms-powerpoint',
|
||||||
desc: 'Microsoft Office documents'
|
desc: 'Microsoft Office documents',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x64 && buf[1] === 0x65 && buf[2] === 0x78 && buf[3] === 0x0A && buf[4] === 0x30 && buf[5] === 0x33 && buf[6] === 0x35 && buf[7] === 0x00) {
|
if (buf[0] === 0x64 && buf[1] === 0x65 && buf[2] === 0x78 && buf[3] === 0x0A && buf[4] === 0x30 && buf[5] === 0x33 && buf[6] === 0x35 && buf[7] === 0x00) {
|
||||||
return {
|
return {
|
||||||
ext: 'dex',
|
ext: 'dex',
|
||||||
mime: 'application/octet-stream',
|
mime: 'application/octet-stream',
|
||||||
desc: 'Dalvik Executable (Android)'
|
desc: 'Dalvik Executable (Android)',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x4B && buf[1] === 0x44 && buf[2] === 0x4D) {
|
if (buf[0] === 0x4B && buf[1] === 0x44 && buf[2] === 0x4D) {
|
||||||
return {
|
return {
|
||||||
ext: 'vmdk',
|
ext: 'vmdk',
|
||||||
mime: 'application/vmdk, application/x-virtualbox-vmdk'
|
mime: 'application/vmdk, application/x-virtualbox-vmdk',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buf[0] === 0x43 && buf[1] === 0x72 && buf[2] === 0x32 && buf[3] == 0x34) {
|
if (buf[0] === 0x43 && buf[1] === 0x72 && buf[2] === 0x32 && buf[3] == 0x34) {
|
||||||
return {
|
return {
|
||||||
ext: 'crx',
|
ext: 'crx',
|
||||||
mime: 'application/crx',
|
mime: 'application/crx',
|
||||||
desc: 'Google Chrome extension or packaged app'
|
desc: 'Google Chrome extension or packaged app',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -9,7 +9,7 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var HTTP = {
|
const HTTP = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strip HTTP headers operation.
|
* Strip HTTP headers operation.
|
||||||
|
@ -18,12 +18,12 @@ var HTTP = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_strip_headers: function(input, args) {
|
run_strip_headers(input, args) {
|
||||||
var header_end = input.indexOf("\r\n\r\n") +
|
const header_end = input.indexOf('\r\n\r\n') +
|
||||||
(header_end < 0) ? input.indexOf("\n\n") + 2 : header_end + 4;
|
(header_end < 0) ? input.indexOf('\n\n') + 2 : header_end + 4;
|
||||||
|
|
||||||
return (header_end < 2) ? input : input.slice(header_end, input.length);
|
return (header_end < 2) ? input : input.slice(header_end, input.length);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,21 +33,21 @@ var HTTP = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_parse_user_agent: function(input, args) {
|
run_parse_user_agent(input, args) {
|
||||||
var ua = UAS_parser.parse(input);
|
const ua = UAS_parser.parse(input);
|
||||||
|
|
||||||
return "Type: " + ua.type + "\n" +
|
return `Type: ${ua.type}\n` +
|
||||||
"Family: " + ua.uaFamily + "\n" +
|
`Family: ${ua.uaFamily}\n` +
|
||||||
"Name: " + ua.uaName + "\n" +
|
`Name: ${ua.uaName}\n` +
|
||||||
"URL: " + ua.uaUrl + "\n" +
|
`URL: ${ua.uaUrl}\n` +
|
||||||
"Company: " + ua.uaCompany + "\n" +
|
`Company: ${ua.uaCompany}\n` +
|
||||||
"Company URL: " + ua.uaCompanyUrl + "\n\n" +
|
`Company URL: ${ua.uaCompanyUrl}\n\n` +
|
||||||
"OS Family: " + ua.osFamily + "\n" +
|
`OS Family: ${ua.osFamily}\n` +
|
||||||
"OS Name: " + ua.osName + "\n" +
|
`OS Name: ${ua.osName}\n` +
|
||||||
"OS URL: " + ua.osUrl + "\n" +
|
`OS URL: ${ua.osUrl}\n` +
|
||||||
"OS Company: " + ua.osCompany + "\n" +
|
`OS Company: ${ua.osCompany}\n` +
|
||||||
"OS Company URL: " + ua.osCompanyUrl + "\n" +
|
`OS Company URL: ${ua.osCompanyUrl}\n` +
|
||||||
"Device Type: " + ua.deviceType + "\n";
|
`Device Type: ${ua.deviceType}\n`;
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var Hash = {
|
const Hash = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MD5 operation.
|
* MD5 operation.
|
||||||
|
@ -18,10 +18,10 @@ var Hash = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_md5: function (input, args) {
|
run_md5(input, args) {
|
||||||
input = CryptoJS.enc.Latin1.parse(input); // Cast to WordArray
|
input = CryptoJS.enc.Latin1.parse(input); // Cast to WordArray
|
||||||
return CryptoJS.MD5(input).toString(CryptoJS.enc.Hex);
|
return CryptoJS.MD5(input).toString(CryptoJS.enc.Hex);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -31,10 +31,10 @@ var Hash = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_sha1: function (input, args) {
|
run_sha1(input, args) {
|
||||||
input = CryptoJS.enc.Latin1.parse(input);
|
input = CryptoJS.enc.Latin1.parse(input);
|
||||||
return CryptoJS.SHA1(input).toString(CryptoJS.enc.Hex);
|
return CryptoJS.SHA1(input).toString(CryptoJS.enc.Hex);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,10 +44,10 @@ var Hash = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_sha224: function (input, args) {
|
run_sha224(input, args) {
|
||||||
input = CryptoJS.enc.Latin1.parse(input);
|
input = CryptoJS.enc.Latin1.parse(input);
|
||||||
return CryptoJS.SHA224(input).toString(CryptoJS.enc.Hex);
|
return CryptoJS.SHA224(input).toString(CryptoJS.enc.Hex);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,10 +57,10 @@ var Hash = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_sha256: function (input, args) {
|
run_sha256(input, args) {
|
||||||
input = CryptoJS.enc.Latin1.parse(input);
|
input = CryptoJS.enc.Latin1.parse(input);
|
||||||
return CryptoJS.SHA256(input).toString(CryptoJS.enc.Hex);
|
return CryptoJS.SHA256(input).toString(CryptoJS.enc.Hex);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -70,10 +70,10 @@ var Hash = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_sha384: function (input, args) {
|
run_sha384(input, args) {
|
||||||
input = CryptoJS.enc.Latin1.parse(input);
|
input = CryptoJS.enc.Latin1.parse(input);
|
||||||
return CryptoJS.SHA384(input).toString(CryptoJS.enc.Hex);
|
return CryptoJS.SHA384(input).toString(CryptoJS.enc.Hex);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -83,17 +83,17 @@ var Hash = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_sha512: function (input, args) {
|
run_sha512(input, args) {
|
||||||
input = CryptoJS.enc.Latin1.parse(input);
|
input = CryptoJS.enc.Latin1.parse(input);
|
||||||
return CryptoJS.SHA512(input).toString(CryptoJS.enc.Hex);
|
return CryptoJS.SHA512(input).toString(CryptoJS.enc.Hex);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
SHA3_LENGTH: ["512", "384", "256", "224"],
|
SHA3_LENGTH: ['512', '384', '256', '224'],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SHA3 operation.
|
* SHA3 operation.
|
||||||
|
@ -102,14 +102,14 @@ var Hash = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_sha3: function (input, args) {
|
run_sha3(input, args) {
|
||||||
input = CryptoJS.enc.Latin1.parse(input);
|
input = CryptoJS.enc.Latin1.parse(input);
|
||||||
var sha3_length = args[0],
|
let sha3_length = args[0],
|
||||||
options = {
|
options = {
|
||||||
outputLength: parseInt(sha3_length, 10)
|
outputLength: parseInt(sha3_length, 10),
|
||||||
};
|
};
|
||||||
return CryptoJS.SHA3(input, options).toString(CryptoJS.enc.Hex);
|
return CryptoJS.SHA3(input, options).toString(CryptoJS.enc.Hex);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -119,17 +119,17 @@ var Hash = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_ripemd160: function (input, args) {
|
run_ripemd160(input, args) {
|
||||||
input = CryptoJS.enc.Latin1.parse(input);
|
input = CryptoJS.enc.Latin1.parse(input);
|
||||||
return CryptoJS.RIPEMD160(input).toString(CryptoJS.enc.Hex);
|
return CryptoJS.RIPEMD160(input).toString(CryptoJS.enc.Hex);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
HMAC_FUNCTIONS: ["MD5", "SHA1", "SHA224", "SHA256", "SHA384", "SHA512", "SHA3", "RIPEMD-160"],
|
HMAC_FUNCTIONS: ['MD5', 'SHA1', 'SHA224', 'SHA256', 'SHA384', 'SHA512', 'SHA3', 'RIPEMD-160'],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HMAC operation.
|
* HMAC operation.
|
||||||
|
@ -138,21 +138,21 @@ var Hash = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_hmac: function (input, args) {
|
run_hmac(input, args) {
|
||||||
var hash_func = args[1];
|
const hash_func = args[1];
|
||||||
input = CryptoJS.enc.Latin1.parse(input);
|
input = CryptoJS.enc.Latin1.parse(input);
|
||||||
var execute = {
|
const execute = {
|
||||||
"MD5": CryptoJS.HmacMD5(input, args[0]),
|
MD5: CryptoJS.HmacMD5(input, args[0]),
|
||||||
"SHA1": CryptoJS.HmacSHA1(input, args[0]),
|
SHA1: CryptoJS.HmacSHA1(input, args[0]),
|
||||||
"SHA224": CryptoJS.HmacSHA224(input, args[0]),
|
SHA224: CryptoJS.HmacSHA224(input, args[0]),
|
||||||
"SHA256": CryptoJS.HmacSHA256(input, args[0]),
|
SHA256: CryptoJS.HmacSHA256(input, args[0]),
|
||||||
"SHA384": CryptoJS.HmacSHA384(input, args[0]),
|
SHA384: CryptoJS.HmacSHA384(input, args[0]),
|
||||||
"SHA512": CryptoJS.HmacSHA512(input, args[0]),
|
SHA512: CryptoJS.HmacSHA512(input, args[0]),
|
||||||
"SHA3": CryptoJS.HmacSHA3(input, args[0]),
|
SHA3: CryptoJS.HmacSHA3(input, args[0]),
|
||||||
"RIPEMD-160": CryptoJS.HmacRIPEMD160(input, args[0]),
|
'RIPEMD-160': CryptoJS.HmacRIPEMD160(input, args[0]),
|
||||||
};
|
};
|
||||||
return execute[hash_func].toString(CryptoJS.enc.Hex);
|
return execute[hash_func].toString(CryptoJS.enc.Hex);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -162,26 +162,26 @@ var Hash = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_all: function (input, args) {
|
run_all(input, args) {
|
||||||
var byte_array = Utils.str_to_byte_array(input),
|
let byte_array = Utils.str_to_byte_array(input),
|
||||||
output = "MD5: " + Hash.run_md5(input, []) +
|
output = `MD5: ${Hash.run_md5(input, [])
|
||||||
"\nSHA1: " + Hash.run_sha1(input, []) +
|
}\nSHA1: ${Hash.run_sha1(input, [])
|
||||||
"\nSHA2 224: " + Hash.run_sha224(input, []) +
|
}\nSHA2 224: ${Hash.run_sha224(input, [])
|
||||||
"\nSHA2 256: " + Hash.run_sha256(input, []) +
|
}\nSHA2 256: ${Hash.run_sha256(input, [])
|
||||||
"\nSHA2 384: " + Hash.run_sha384(input, []) +
|
}\nSHA2 384: ${Hash.run_sha384(input, [])
|
||||||
"\nSHA2 512: " + Hash.run_sha512(input, []) +
|
}\nSHA2 512: ${Hash.run_sha512(input, [])
|
||||||
"\nSHA3 224: " + Hash.run_sha3(input, ["224"]) +
|
}\nSHA3 224: ${Hash.run_sha3(input, ['224'])
|
||||||
"\nSHA3 256: " + Hash.run_sha3(input, ["256"]) +
|
}\nSHA3 256: ${Hash.run_sha3(input, ['256'])
|
||||||
"\nSHA3 384: " + Hash.run_sha3(input, ["384"]) +
|
}\nSHA3 384: ${Hash.run_sha3(input, ['384'])
|
||||||
"\nSHA3 512: " + Hash.run_sha3(input, ["512"]) +
|
}\nSHA3 512: ${Hash.run_sha3(input, ['512'])
|
||||||
"\nRIPEMD-160: " + Hash.run_ripemd160(input, []) +
|
}\nRIPEMD-160: ${Hash.run_ripemd160(input, [])
|
||||||
"\n\nChecksums:" +
|
}\n\nChecksums:` +
|
||||||
"\nFletcher-16: " + Checksum.run_fletcher16(byte_array, []) +
|
`\nFletcher-16: ${Checksum.run_fletcher16(byte_array, [])
|
||||||
"\nAdler-32: " + Checksum.run_adler32(byte_array, []) +
|
}\nAdler-32: ${Checksum.run_adler32(byte_array, [])
|
||||||
"\nCRC-32: " + Checksum.run_crc32(byte_array, []);
|
}\nCRC-32: ${Checksum.run_crc32(byte_array, [])}`;
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -191,151 +191,151 @@ var Hash = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_analyse: function(input, args) {
|
run_analyse(input, args) {
|
||||||
input = input.replace(/\s/g, "");
|
input = input.replace(/\s/g, '');
|
||||||
|
|
||||||
var output = "",
|
let output = '',
|
||||||
byte_length = input.length / 2,
|
byte_length = input.length / 2,
|
||||||
bit_length = byte_length * 8,
|
bit_length = byte_length * 8,
|
||||||
possible_hash_functions = [];
|
possible_hash_functions = [];
|
||||||
|
|
||||||
if (!/^[a-f0-9]+$/i.test(input)) {
|
if (!/^[a-f0-9]+$/i.test(input)) {
|
||||||
return "Invalid hash";
|
return 'Invalid hash';
|
||||||
}
|
}
|
||||||
|
|
||||||
output += "Hash length: " + input.length + "\n" +
|
output += `Hash length: ${input.length}\n` +
|
||||||
"Byte length: " + byte_length + "\n" +
|
`Byte length: ${byte_length}\n` +
|
||||||
"Bit length: " + bit_length + "\n\n" +
|
`Bit length: ${bit_length}\n\n` +
|
||||||
"Based on the length, this hash could have been generated by one of the following hashing functions:\n";
|
'Based on the length, this hash could have been generated by one of the following hashing functions:\n';
|
||||||
|
|
||||||
switch (bit_length) {
|
switch (bit_length) {
|
||||||
case 4:
|
case 4:
|
||||||
possible_hash_functions = [
|
possible_hash_functions = [
|
||||||
"Fletcher-4",
|
'Fletcher-4',
|
||||||
"Luhn algorithm",
|
'Luhn algorithm',
|
||||||
"Verhoeff algorithm",
|
'Verhoeff algorithm',
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
possible_hash_functions = [
|
possible_hash_functions = [
|
||||||
"Fletcher-8",
|
'Fletcher-8',
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
case 16:
|
case 16:
|
||||||
possible_hash_functions = [
|
possible_hash_functions = [
|
||||||
"BSD checksum",
|
'BSD checksum',
|
||||||
"CRC-16",
|
'CRC-16',
|
||||||
"SYSV checksum",
|
'SYSV checksum',
|
||||||
"Fletcher-16"
|
'Fletcher-16',
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
case 32:
|
case 32:
|
||||||
possible_hash_functions = [
|
possible_hash_functions = [
|
||||||
"CRC-32",
|
'CRC-32',
|
||||||
"Fletcher-32",
|
'Fletcher-32',
|
||||||
"Adler-32",
|
'Adler-32',
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
case 64:
|
case 64:
|
||||||
possible_hash_functions = [
|
possible_hash_functions = [
|
||||||
"CRC-64",
|
'CRC-64',
|
||||||
"RIPEMD-64",
|
'RIPEMD-64',
|
||||||
"SipHash",
|
'SipHash',
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
case 128:
|
case 128:
|
||||||
possible_hash_functions = [
|
possible_hash_functions = [
|
||||||
"MD5",
|
'MD5',
|
||||||
"MD4",
|
'MD4',
|
||||||
"MD2",
|
'MD2',
|
||||||
"HAVAL-128",
|
'HAVAL-128',
|
||||||
"RIPEMD-128",
|
'RIPEMD-128',
|
||||||
"Snefru",
|
'Snefru',
|
||||||
"Tiger-128",
|
'Tiger-128',
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
case 160:
|
case 160:
|
||||||
possible_hash_functions = [
|
possible_hash_functions = [
|
||||||
"SHA-1",
|
'SHA-1',
|
||||||
"SHA-0",
|
'SHA-0',
|
||||||
"FSB-160",
|
'FSB-160',
|
||||||
"HAS-160",
|
'HAS-160',
|
||||||
"HAVAL-160",
|
'HAVAL-160',
|
||||||
"RIPEMD-160",
|
'RIPEMD-160',
|
||||||
"Tiger-160",
|
'Tiger-160',
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
case 192:
|
case 192:
|
||||||
possible_hash_functions = [
|
possible_hash_functions = [
|
||||||
"Tiger",
|
'Tiger',
|
||||||
"HAVAL-192",
|
'HAVAL-192',
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
case 224:
|
case 224:
|
||||||
possible_hash_functions = [
|
possible_hash_functions = [
|
||||||
"SHA-224",
|
'SHA-224',
|
||||||
"SHA3-224",
|
'SHA3-224',
|
||||||
"ECOH-224",
|
'ECOH-224',
|
||||||
"FSB-224",
|
'FSB-224',
|
||||||
"HAVAL-224",
|
'HAVAL-224',
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
case 256:
|
case 256:
|
||||||
possible_hash_functions = [
|
possible_hash_functions = [
|
||||||
"SHA-256",
|
'SHA-256',
|
||||||
"SHA3-256",
|
'SHA3-256',
|
||||||
"BLAKE-256",
|
'BLAKE-256',
|
||||||
"ECOH-256",
|
'ECOH-256',
|
||||||
"FSB-256",
|
'FSB-256',
|
||||||
"GOST",
|
'GOST',
|
||||||
"Grøstl-256",
|
'Grøstl-256',
|
||||||
"HAVAL-256",
|
'HAVAL-256',
|
||||||
"PANAMA",
|
'PANAMA',
|
||||||
"RIPEMD-256",
|
'RIPEMD-256',
|
||||||
"Snefru",
|
'Snefru',
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
case 320:
|
case 320:
|
||||||
possible_hash_functions = [
|
possible_hash_functions = [
|
||||||
"RIPEMD-320",
|
'RIPEMD-320',
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
case 384:
|
case 384:
|
||||||
possible_hash_functions = [
|
possible_hash_functions = [
|
||||||
"SHA-384",
|
'SHA-384',
|
||||||
"SHA3-384",
|
'SHA3-384',
|
||||||
"ECOH-384",
|
'ECOH-384',
|
||||||
"FSB-384",
|
'FSB-384',
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
case 512:
|
case 512:
|
||||||
possible_hash_functions = [
|
possible_hash_functions = [
|
||||||
"SHA-512",
|
'SHA-512',
|
||||||
"SHA3-512",
|
'SHA3-512',
|
||||||
"BLAKE-512",
|
'BLAKE-512',
|
||||||
"ECOH-512",
|
'ECOH-512',
|
||||||
"FSB-512",
|
'FSB-512',
|
||||||
"Grøstl-512",
|
'Grøstl-512',
|
||||||
"JH",
|
'JH',
|
||||||
"MD6",
|
'MD6',
|
||||||
"Spectral Hash",
|
'Spectral Hash',
|
||||||
"SWIFFT",
|
'SWIFFT',
|
||||||
"Whirlpool",
|
'Whirlpool',
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
case 1024:
|
case 1024:
|
||||||
possible_hash_functions = [
|
possible_hash_functions = [
|
||||||
"Fowler-Noll-Vo",
|
'Fowler-Noll-Vo',
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
possible_hash_functions = [
|
possible_hash_functions = [
|
||||||
"Unknown"
|
'Unknown',
|
||||||
];
|
];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return output + possible_hash_functions.join("\n");
|
return output + possible_hash_functions.join('\n');
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,23 +9,23 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var Hexdump = {
|
const Hexdump = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
WIDTH: 16,
|
WIDTH: 16,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
UPPER_CASE: false,
|
UPPER_CASE: false,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
INCLUDE_FINAL_LENGTH: false,
|
INCLUDE_FINAL_LENGTH: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To Hexdump operation.
|
* To Hexdump operation.
|
||||||
|
@ -34,37 +34,38 @@ var Hexdump = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_to: function(input, args) {
|
run_to(input, args) {
|
||||||
var length = args[0] || Hexdump.WIDTH;
|
const length = args[0] || Hexdump.WIDTH;
|
||||||
var upper_case = args[1];
|
const upper_case = args[1];
|
||||||
var include_final_length = args[2];
|
const include_final_length = args[2];
|
||||||
|
|
||||||
var output = "", padding = 2;
|
let output = '',
|
||||||
for (var i = 0; i < input.length; i += length) {
|
padding = 2;
|
||||||
var buff = input.slice(i, i+length);
|
for (let i = 0; i < input.length; i += length) {
|
||||||
var hexa = "";
|
const buff = input.slice(i, i + length);
|
||||||
for (var j = 0; j < buff.length; j++) {
|
let hexa = '';
|
||||||
hexa += Utils.hex(buff[j], padding) + " ";
|
for (let j = 0; j < buff.length; j++) {
|
||||||
}
|
hexa += `${Utils.hex(buff[j], padding)} `;
|
||||||
|
}
|
||||||
|
|
||||||
var line_no = Utils.hex(i, 8);
|
let line_no = Utils.hex(i, 8);
|
||||||
|
|
||||||
if (upper_case) {
|
if (upper_case) {
|
||||||
hexa = hexa.toUpperCase();
|
hexa = hexa.toUpperCase();
|
||||||
line_no = line_no.toUpperCase();
|
line_no = line_no.toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
output += line_no + " " +
|
output += `${line_no} ${
|
||||||
Utils.pad_right(hexa, (length*(padding+1))) +
|
Utils.pad_right(hexa, (length * (padding + 1)))
|
||||||
" |" + Utils.pad_right(Utils.printable(Utils.byte_array_to_chars(buff)), buff.length) + "|\n";
|
} |${Utils.pad_right(Utils.printable(Utils.byte_array_to_chars(buff)), buff.length)}|\n`;
|
||||||
|
|
||||||
if (include_final_length && i+buff.length == input.length) {
|
if (include_final_length && i + buff.length == input.length) {
|
||||||
output += Utils.hex(i+buff.length, 8) + "\n";
|
output += `${Utils.hex(i + buff.length, 8)}\n`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return output.slice(0, -1);
|
return output.slice(0, -1);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,26 +75,27 @@ var Hexdump = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_from: function(input, args) {
|
run_from(input, args) {
|
||||||
var output = [],
|
let output = [],
|
||||||
regex = /^\s*(?:[\dA-F]{4,16}:?)?\s*((?:[\dA-F]{2}\s){1,8}(?:\s|[\dA-F]{2}-)(?:[\dA-F]{2}\s){1,8}|(?:[\dA-F]{2}\s|[\dA-F]{4}\s)+)/igm,
|
regex = /^\s*(?:[\dA-F]{4,16}:?)?\s*((?:[\dA-F]{2}\s){1,8}(?:\s|[\dA-F]{2}-)(?:[\dA-F]{2}\s){1,8}|(?:[\dA-F]{2}\s|[\dA-F]{4}\s)+)/igm,
|
||||||
block, line;
|
block,
|
||||||
|
line;
|
||||||
|
|
||||||
while (!!(block = regex.exec(input))) {
|
while (block = regex.exec(input)) {
|
||||||
line = Utils.from_hex(block[1].replace(/-/g, " "));
|
line = Utils.from_hex(block[1].replace(/-/g, ' '));
|
||||||
for (var i = 0; i < line.length; i++) {
|
for (let i = 0; i < line.length; i++) {
|
||||||
output.push(line[i]);
|
output.push(line[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Is this a CyberChef hexdump or is it from a different tool?
|
// Is this a CyberChef hexdump or is it from a different tool?
|
||||||
var width = input.indexOf("\n");
|
const width = input.indexOf('\n');
|
||||||
var 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) {
|
||||||
app.options.attempt_highlight = false;
|
app.options.attempt_highlight = false;
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -105,53 +107,54 @@ var Hexdump = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {Object[]} pos
|
* @returns {Object[]} pos
|
||||||
*/
|
*/
|
||||||
highlight_to: function(pos, args) {
|
highlight_to(pos, args) {
|
||||||
// Calculate overall selection
|
// Calculate overall selection
|
||||||
var w = args[0] || 16,
|
let w = args[0] || 16,
|
||||||
width = 14 + (w*4),
|
width = 14 + (w * 4),
|
||||||
line = Math.floor(pos[0].start / w),
|
line = Math.floor(pos[0].start / w),
|
||||||
offset = pos[0].start % w,
|
offset = pos[0].start % w,
|
||||||
start = 0,
|
start = 0,
|
||||||
end = 0;
|
end = 0;
|
||||||
|
|
||||||
pos[0].start = line*width + 10 + offset*3;
|
pos[0].start = line * width + 10 + offset * 3;
|
||||||
|
|
||||||
line = Math.floor(pos[0].end / w);
|
line = Math.floor(pos[0].end / w);
|
||||||
offset = pos[0].end % w;
|
offset = pos[0].end % w;
|
||||||
if (offset === 0) { line--; offset = w; }
|
if (offset === 0) { line--; offset = w; }
|
||||||
pos[0].end = line*width + 10 + offset*3 - 1;
|
pos[0].end = line * width + 10 + offset * 3 - 1;
|
||||||
|
|
||||||
// Set up multiple selections for bytes
|
// Set up multiple selections for bytes
|
||||||
var start_line_num = Math.floor(pos[0].start / width);
|
let start_line_num = Math.floor(pos[0].start / width);
|
||||||
var end_line_num = Math.floor(pos[0].end / width);
|
const end_line_num = Math.floor(pos[0].end / width);
|
||||||
|
|
||||||
if (start_line_num == end_line_num) {
|
if (start_line_num == end_line_num) {
|
||||||
pos.push(pos[0]);
|
pos.push(pos[0]);
|
||||||
} else {
|
} else {
|
||||||
start = pos[0].start;
|
start = pos[0].start;
|
||||||
end = (start_line_num+1) * width - w - 5;
|
end = (start_line_num + 1) * width - w - 5;
|
||||||
pos.push({ start: start, end: end });
|
pos.push({ start, end });
|
||||||
while (end < pos[0].end) {
|
while (end < pos[0].end) {
|
||||||
start_line_num++;
|
start_line_num++;
|
||||||
start = start_line_num * width + 10;
|
start = start_line_num * width + 10;
|
||||||
end = (start_line_num+1) * width - w - 5;
|
end = (start_line_num + 1) * width - w - 5;
|
||||||
if (end > pos[0].end) end = pos[0].end;
|
if (end > pos[0].end) end = pos[0].end;
|
||||||
pos.push({ start: start, end: end });
|
pos.push({ start, end });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up multiple selections for ASCII
|
// Set up multiple selections for ASCII
|
||||||
var len = pos.length, line_num = 0;
|
let len = pos.length,
|
||||||
start = 0;
|
line_num = 0;
|
||||||
end = 0;
|
start = 0;
|
||||||
for (var i = 1; i < len; i++) {
|
end = 0;
|
||||||
line_num = Math.floor(pos[i].start / width);
|
for (let i = 1; i < len; i++) {
|
||||||
start = (((pos[i].start - (line_num * width)) - 10) / 3) + (width - w -2) + (line_num * width);
|
line_num = Math.floor(pos[i].start / width);
|
||||||
end = (((pos[i].end + 1 - (line_num * width)) - 10) / 3) + (width - w -2) + (line_num * width);
|
start = (((pos[i].start - (line_num * width)) - 10) / 3) + (width - w - 2) + (line_num * width);
|
||||||
pos.push({ start: start, end: end });
|
end = (((pos[i].end + 1 - (line_num * width)) - 10) / 3) + (width - w - 2) + (line_num * width);
|
||||||
}
|
pos.push({ start, end });
|
||||||
return pos;
|
}
|
||||||
},
|
return pos;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -163,33 +166,33 @@ var Hexdump = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {Object[]} pos
|
* @returns {Object[]} pos
|
||||||
*/
|
*/
|
||||||
highlight_from: function(pos, args) {
|
highlight_from(pos, args) {
|
||||||
var w = args[0] || 16;
|
const w = args[0] || 16;
|
||||||
var width = 14 + (w*4);
|
const width = 14 + (w * 4);
|
||||||
|
|
||||||
var line = Math.floor(pos[0].start / width);
|
let line = Math.floor(pos[0].start / width);
|
||||||
var offset = pos[0].start % width;
|
let offset = pos[0].start % width;
|
||||||
|
|
||||||
if (offset < 10) { // In line number section
|
if (offset < 10) { // In line number section
|
||||||
pos[0].start = line*w;
|
pos[0].start = line * w;
|
||||||
} else if (offset > 10+(w*3)) { // In ASCII section
|
} else if (offset > 10 + (w * 3)) { // In ASCII section
|
||||||
pos[0].start = (line+1)*w;
|
pos[0].start = (line + 1) * w;
|
||||||
} else { // In byte section
|
} else { // In byte section
|
||||||
pos[0].start = line*w + Math.floor((offset-10)/3);
|
pos[0].start = line * w + Math.floor((offset - 10) / 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
line = Math.floor(pos[0].end / width);
|
line = Math.floor(pos[0].end / width);
|
||||||
offset = pos[0].end % width;
|
offset = pos[0].end % width;
|
||||||
|
|
||||||
if (offset < 10) { // In line number section
|
if (offset < 10) { // In line number section
|
||||||
pos[0].end = line*w;
|
pos[0].end = line * w;
|
||||||
} else if (offset > 10+(w*3)) { // In ASCII section
|
} else if (offset > 10 + (w * 3)) { // In ASCII section
|
||||||
pos[0].end = (line+1)*w;
|
pos[0].end = (line + 1) * w;
|
||||||
} else { // In byte section
|
} else { // In byte section
|
||||||
pos[0].end = line*w + Math.ceil((offset-10)/3);
|
pos[0].end = line * w + Math.ceil((offset - 10) / 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
return pos;
|
return pos;
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -9,33 +9,33 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var JS = {
|
const JS = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
PARSE_LOC: false,
|
PARSE_LOC: false,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
PARSE_RANGE: false,
|
PARSE_RANGE: false,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
PARSE_TOKENS: false,
|
PARSE_TOKENS: false,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
PARSE_COMMENT: false,
|
PARSE_COMMENT: false,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
PARSE_TOLERANT: false,
|
PARSE_TOLERANT: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JavaScript Parser operation.
|
* JavaScript Parser operation.
|
||||||
|
@ -44,46 +44,46 @@ var JS = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_parse: function (input, args) {
|
run_parse(input, args) {
|
||||||
var parse_loc = args[0],
|
let parse_loc = args[0],
|
||||||
parse_range = args[1],
|
parse_range = args[1],
|
||||||
parse_tokens = args[2],
|
parse_tokens = args[2],
|
||||||
parse_comment = args[3],
|
parse_comment = args[3],
|
||||||
parse_tolerant = args[4],
|
parse_tolerant = args[4],
|
||||||
result = {},
|
result = {},
|
||||||
options = {
|
options = {
|
||||||
loc: parse_loc,
|
loc: parse_loc,
|
||||||
range: parse_range,
|
range: parse_range,
|
||||||
tokens: parse_tokens,
|
tokens: parse_tokens,
|
||||||
comment: parse_comment,
|
comment: parse_comment,
|
||||||
tolerant: parse_tolerant
|
tolerant: parse_tolerant,
|
||||||
};
|
};
|
||||||
|
|
||||||
result = esprima.parse(input, options);
|
result = esprima.parse(input, options);
|
||||||
return JSON.stringify(result, null, 2);
|
return JSON.stringify(result, null, 2);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
BEAUTIFY_INDENT: "\\t",
|
BEAUTIFY_INDENT: '\\t',
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
BEAUTIFY_QUOTES: ["Auto", "Single", "Double"],
|
BEAUTIFY_QUOTES: ['Auto', 'Single', 'Double'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
BEAUTIFY_SEMICOLONS: true,
|
BEAUTIFY_SEMICOLONS: true,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
BEAUTIFY_COMMENT: true,
|
BEAUTIFY_COMMENT: true,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JavaScript Beautify operation.
|
* JavaScript Beautify operation.
|
||||||
|
@ -92,42 +92,43 @@ var JS = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_beautify: function(input, args) {
|
run_beautify(input, args) {
|
||||||
var beautify_indent = args[0] || JS.BEAUTIFY_INDENT,
|
let beautify_indent = args[0] || JS.BEAUTIFY_INDENT,
|
||||||
quotes = args[1].toLowerCase(),
|
quotes = args[1].toLowerCase(),
|
||||||
beautify_semicolons = args[2],
|
beautify_semicolons = args[2],
|
||||||
beautify_comment = args[3],
|
beautify_comment = args[3],
|
||||||
result = "",
|
result = '',
|
||||||
AST;
|
AST;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
AST = esprima.parse(input, {
|
AST = esprima.parse(input, {
|
||||||
range: true,
|
range: true,
|
||||||
tokens: true,
|
tokens: true,
|
||||||
comment: true
|
comment: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
var options = {
|
const options = {
|
||||||
format: {
|
format: {
|
||||||
indent: {
|
indent: {
|
||||||
style: beautify_indent
|
style: beautify_indent,
|
||||||
},
|
},
|
||||||
quotes: quotes,
|
quotes,
|
||||||
semicolons: beautify_semicolons,
|
semicolons: beautify_semicolons,
|
||||||
},
|
},
|
||||||
comment: beautify_comment
|
comment: beautify_comment,
|
||||||
};
|
};
|
||||||
|
|
||||||
if (options.comment)
|
if (options.comment) {
|
||||||
AST = escodegen.attachComments(AST, AST.comments, AST.tokens);
|
AST = escodegen.attachComments(AST, AST.comments, AST.tokens);
|
||||||
|
}
|
||||||
|
|
||||||
result = escodegen.generate(AST, options);
|
result = escodegen.generate(AST, options);
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
// Leave original error so the user can see the detail
|
// Leave original error so the user can see the detail
|
||||||
throw "Unable to parse JavaScript.<br>" + e.message;
|
throw `Unable to parse JavaScript.<br>${e.message}`;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -137,23 +138,23 @@ var JS = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_minify: function(input, args) {
|
run_minify(input, args) {
|
||||||
var result = "",
|
let result = '',
|
||||||
AST = esprima.parse(input),
|
AST = esprima.parse(input),
|
||||||
optimised_AST = esmangle.optimize(AST, null),
|
optimised_AST = esmangle.optimize(AST, null),
|
||||||
mangled_AST = esmangle.mangle(optimised_AST);
|
mangled_AST = esmangle.mangle(optimised_AST);
|
||||||
|
|
||||||
result = escodegen.generate(mangled_AST, {
|
result = escodegen.generate(mangled_AST, {
|
||||||
format: {
|
format: {
|
||||||
renumber: true,
|
renumber: true,
|
||||||
hexadecimal: true,
|
hexadecimal: true,
|
||||||
escapeless: true,
|
escapeless: true,
|
||||||
compact: true,
|
compact: true,
|
||||||
semicolons: false,
|
semicolons: false,
|
||||||
parentheses: false
|
parentheses: false,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,33 +7,33 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var MAC = {
|
const MAC = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
OUTPUT_CASE: ["Both", "Upper only", "Lower only"],
|
OUTPUT_CASE: ['Both', 'Upper only', 'Lower only'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
NO_DELIM: true,
|
NO_DELIM: true,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
DASH_DELIM: true,
|
DASH_DELIM: true,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
COLON_DELIM: true,
|
COLON_DELIM: true,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
CISCO_STYLE: false,
|
CISCO_STYLE: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format MAC addresses operation.
|
* Format MAC addresses operation.
|
||||||
|
@ -42,47 +42,47 @@ var MAC = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_format: function(input, args) {
|
run_format(input, args) {
|
||||||
if (!input) return "";
|
if (!input) return '';
|
||||||
|
|
||||||
var output_case = args[0],
|
let output_case = args[0],
|
||||||
no_delim = args[1],
|
no_delim = args[1],
|
||||||
dash_delim = args[2],
|
dash_delim = args[2],
|
||||||
colon_delim = args[3],
|
colon_delim = args[3],
|
||||||
cisco_style = args[4],
|
cisco_style = args[4],
|
||||||
output_list = [],
|
output_list = [],
|
||||||
macs = input.toLowerCase().split(/[,\s\r\n]+/);
|
macs = input.toLowerCase().split(/[,\s\r\n]+/);
|
||||||
|
|
||||||
macs.forEach(function(mac) {
|
macs.forEach((mac) => {
|
||||||
var cleanMac = mac.replace(/[:.-]+/g, ''),
|
let cleanMac = mac.replace(/[:.-]+/g, ''),
|
||||||
macHyphen = cleanMac.replace(/(.{2}(?=.))/g, '$1-'),
|
macHyphen = cleanMac.replace(/(.{2}(?=.))/g, '$1-'),
|
||||||
macColon = cleanMac.replace(/(.{2}(?=.))/g, '$1:'),
|
macColon = cleanMac.replace(/(.{2}(?=.))/g, '$1:'),
|
||||||
macCisco = cleanMac.replace(/(.{4}(?=.))/g, '$1.');
|
macCisco = cleanMac.replace(/(.{4}(?=.))/g, '$1.');
|
||||||
|
|
||||||
if (output_case == "Lower only") {
|
if (output_case == 'Lower only') {
|
||||||
if (no_delim) output_list.push(cleanMac);
|
if (no_delim) output_list.push(cleanMac);
|
||||||
if (dash_delim) output_list.push(macHyphen);
|
if (dash_delim) output_list.push(macHyphen);
|
||||||
if (colon_delim) output_list.push(macColon);
|
if (colon_delim) output_list.push(macColon);
|
||||||
if (cisco_style) output_list.push(macCisco);
|
if (cisco_style) output_list.push(macCisco);
|
||||||
} else if (output_case == "Upper only") {
|
} else if (output_case == 'Upper only') {
|
||||||
if (no_delim) output_list.push(cleanMac.toUpperCase());
|
if (no_delim) output_list.push(cleanMac.toUpperCase());
|
||||||
if (dash_delim) output_list.push(macHyphen.toUpperCase());
|
if (dash_delim) output_list.push(macHyphen.toUpperCase());
|
||||||
if (colon_delim) output_list.push(macColon.toUpperCase());
|
if (colon_delim) output_list.push(macColon.toUpperCase());
|
||||||
if (cisco_style) output_list.push(macCisco.toUpperCase());
|
if (cisco_style) output_list.push(macCisco.toUpperCase());
|
||||||
} else {
|
} else {
|
||||||
if (no_delim) output_list.push(cleanMac, cleanMac.toUpperCase());
|
if (no_delim) output_list.push(cleanMac, cleanMac.toUpperCase());
|
||||||
if (dash_delim) output_list.push(macHyphen, macHyphen.toUpperCase());
|
if (dash_delim) output_list.push(macHyphen, macHyphen.toUpperCase());
|
||||||
if (colon_delim) output_list.push(macColon, macColon.toUpperCase());
|
if (colon_delim) output_list.push(macColon, macColon.toUpperCase());
|
||||||
if (cisco_style) output_list.push(macCisco, macCisco.toUpperCase());
|
if (cisco_style) output_list.push(macCisco, macCisco.toUpperCase());
|
||||||
}
|
}
|
||||||
|
|
||||||
output_list.push(
|
output_list.push(
|
||||||
"" // Empty line to delimit groups
|
'', // Empty line to delimit groups
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Return the data as a string
|
// Return the data as a string
|
||||||
return output_list.join('\n');
|
return output_list.join('\n');
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
* @author Unknown Male 282
|
* @author Unknown Male 282
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var Numberwang = {
|
const Numberwang = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Numberwang operation. Remain indoors.
|
* Numberwang operation. Remain indoors.
|
||||||
|
@ -13,15 +13,15 @@ var Numberwang = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run: function(input, args) {
|
run(input, args) {
|
||||||
if (!input) return "Let's play Wangernumb!";
|
if (!input) return "Let's play Wangernumb!";
|
||||||
var match = input.match(/\d+/);
|
const match = input.match(/\d+/);
|
||||||
if (match) {
|
if (match) {
|
||||||
return match[0] + "! That's Numberwang!";
|
return `${match[0]}! That's Numberwang!`;
|
||||||
} else {
|
} else {
|
||||||
// That's a bad miss!
|
// That's a bad miss!
|
||||||
return "Sorry, that's not Numberwang. Let's rotate the board!";
|
return "Sorry, that's not Numberwang. Let's rotate the board!";
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var OS = {
|
const OS = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse UNIX file permissions operation.
|
* Parse UNIX file permissions operation.
|
||||||
|
@ -16,182 +16,182 @@ var OS = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_parse_unix_perms: function(input, args) {
|
run_parse_unix_perms(input, args) {
|
||||||
var perms = {
|
let perms = {
|
||||||
d : false, // directory
|
d: false, // directory
|
||||||
sl : false, // symbolic link
|
sl: false, // symbolic link
|
||||||
np : false, // named pipe
|
np: false, // named pipe
|
||||||
s : false, // socket
|
s: false, // socket
|
||||||
cd : false, // character device
|
cd: false, // character device
|
||||||
bd : false, // block device
|
bd: false, // block device
|
||||||
dr : false, // door
|
dr: false, // door
|
||||||
sb : false, // sticky bit
|
sb: false, // sticky bit
|
||||||
su : false, // setuid
|
su: false, // setuid
|
||||||
sg : false, // setgid
|
sg: false, // setgid
|
||||||
ru : false, // read user
|
ru: false, // read user
|
||||||
wu : false, // write user
|
wu: false, // write user
|
||||||
eu : false, // execute user
|
eu: false, // execute user
|
||||||
rg : false, // read group
|
rg: false, // read group
|
||||||
wg : false, // write group
|
wg: false, // write group
|
||||||
eg : false, // execute group
|
eg: false, // execute group
|
||||||
ro : false, // read other
|
ro: false, // read other
|
||||||
wo : false, // write other
|
wo: false, // write other
|
||||||
eo : false // execute other
|
eo: false, // execute other
|
||||||
},
|
},
|
||||||
d = 0,
|
d = 0,
|
||||||
u = 0,
|
u = 0,
|
||||||
g = 0,
|
g = 0,
|
||||||
o = 0,
|
o = 0,
|
||||||
output = "",
|
output = '',
|
||||||
octal = null,
|
octal = null,
|
||||||
textual = null;
|
textual = null;
|
||||||
|
|
||||||
if (input.search(/\s*[0-7]{1,4}\s*/i) === 0) {
|
if (input.search(/\s*[0-7]{1,4}\s*/i) === 0) {
|
||||||
// Input is octal
|
// Input is octal
|
||||||
octal = input.match(/\s*([0-7]{1,4})\s*/i)[1];
|
octal = input.match(/\s*([0-7]{1,4})\s*/i)[1];
|
||||||
|
|
||||||
if (octal.length == 4) {
|
if (octal.length == 4) {
|
||||||
d = parseInt(octal[0], 8);
|
d = parseInt(octal[0], 8);
|
||||||
u = parseInt(octal[1], 8);
|
u = parseInt(octal[1], 8);
|
||||||
g = parseInt(octal[2], 8);
|
g = parseInt(octal[2], 8);
|
||||||
o = parseInt(octal[3], 8);
|
o = parseInt(octal[3], 8);
|
||||||
} else {
|
} else {
|
||||||
if (octal.length > 0) u = parseInt(octal[0], 8);
|
if (octal.length > 0) u = parseInt(octal[0], 8);
|
||||||
if (octal.length > 1) g = parseInt(octal[1], 8);
|
if (octal.length > 1) g = parseInt(octal[1], 8);
|
||||||
if (octal.length > 2) o = parseInt(octal[2], 8);
|
if (octal.length > 2) o = parseInt(octal[2], 8);
|
||||||
}
|
}
|
||||||
|
|
||||||
perms.su = d >> 2 & 0x1;
|
perms.su = d >> 2 & 0x1;
|
||||||
perms.sg = d >> 1 & 0x1;
|
perms.sg = d >> 1 & 0x1;
|
||||||
perms.sb = d & 0x1;
|
perms.sb = d & 0x1;
|
||||||
|
|
||||||
perms.ru = u >> 2 & 0x1;
|
perms.ru = u >> 2 & 0x1;
|
||||||
perms.wu = u >> 1 & 0x1;
|
perms.wu = u >> 1 & 0x1;
|
||||||
perms.eu = u & 0x1;
|
perms.eu = u & 0x1;
|
||||||
|
|
||||||
perms.rg = g >> 2 & 0x1;
|
perms.rg = g >> 2 & 0x1;
|
||||||
perms.wg = g >> 1 & 0x1;
|
perms.wg = g >> 1 & 0x1;
|
||||||
perms.eg = g & 0x1;
|
perms.eg = g & 0x1;
|
||||||
|
|
||||||
perms.ro = o >> 2 & 0x1;
|
perms.ro = o >> 2 & 0x1;
|
||||||
perms.wo = o >> 1 & 0x1;
|
perms.wo = o >> 1 & 0x1;
|
||||||
perms.eo = o & 0x1;
|
perms.eo = o & 0x1;
|
||||||
} else if (input.search(/\s*[dlpcbDrwxsStT-]{1,10}\s*/) === 0) {
|
} else if (input.search(/\s*[dlpcbDrwxsStT-]{1,10}\s*/) === 0) {
|
||||||
// Input is textual
|
// Input is textual
|
||||||
textual = input.match(/\s*([dlpcbDrwxsStT-]{1,10})\s*/)[1];
|
textual = input.match(/\s*([dlpcbDrwxsStT-]{1,10})\s*/)[1];
|
||||||
|
|
||||||
switch (textual[0]) {
|
switch (textual[0]) {
|
||||||
case "d":
|
case 'd':
|
||||||
perms.d = true;
|
perms.d = true;
|
||||||
break;
|
break;
|
||||||
case "l":
|
case 'l':
|
||||||
perms.sl = true;
|
perms.sl = true;
|
||||||
break;
|
break;
|
||||||
case "p":
|
case 'p':
|
||||||
perms.np = true;
|
perms.np = true;
|
||||||
break;
|
break;
|
||||||
case "s":
|
case 's':
|
||||||
perms.s = true;
|
perms.s = true;
|
||||||
break;
|
break;
|
||||||
case "c":
|
case 'c':
|
||||||
perms.cd = true;
|
perms.cd = true;
|
||||||
break;
|
break;
|
||||||
case "b":
|
case 'b':
|
||||||
perms.bd = true;
|
perms.bd = true;
|
||||||
break;
|
break;
|
||||||
case "D":
|
case 'D':
|
||||||
perms.dr = true;
|
perms.dr = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (textual.length > 1) perms.ru = textual[1] == "r";
|
if (textual.length > 1) perms.ru = textual[1] == 'r';
|
||||||
if (textual.length > 2) perms.wu = textual[2] == "w";
|
if (textual.length > 2) perms.wu = textual[2] == 'w';
|
||||||
if (textual.length > 3) {
|
if (textual.length > 3) {
|
||||||
switch (textual[3]) {
|
switch (textual[3]) {
|
||||||
case "x":
|
case 'x':
|
||||||
perms.eu = true;
|
perms.eu = true;
|
||||||
break;
|
break;
|
||||||
case "s":
|
case 's':
|
||||||
perms.eu = true;
|
perms.eu = true;
|
||||||
perms.su = true;
|
perms.su = true;
|
||||||
break;
|
break;
|
||||||
case "S":
|
case 'S':
|
||||||
perms.su = true;
|
perms.su = true;
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (textual.length > 4) perms.rg = textual[4] == "r";
|
|
||||||
if (textual.length > 5) perms.wg = textual[5] == "w";
|
|
||||||
if (textual.length > 6) {
|
|
||||||
switch (textual[6]) {
|
|
||||||
case "x":
|
|
||||||
perms.eg = true;
|
|
||||||
break;
|
|
||||||
case "s":
|
|
||||||
perms.eg = true;
|
|
||||||
perms.sg = true;
|
|
||||||
break;
|
|
||||||
case "S":
|
|
||||||
perms.sg = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (textual.length > 7) perms.ro = textual[7] == "r";
|
|
||||||
if (textual.length > 8) perms.wo = textual[8] == "w";
|
|
||||||
if (textual.length > 9) {
|
|
||||||
switch (textual[9]) {
|
|
||||||
case "x":
|
|
||||||
perms.eo = true;
|
|
||||||
break;
|
|
||||||
case "t":
|
|
||||||
perms.eo = true;
|
|
||||||
perms.sb = true;
|
|
||||||
break;
|
|
||||||
case "T":
|
|
||||||
perms.sb = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return "Invalid input format.\nPlease enter the permissions in either octal (e.g. 755) or textual (e.g. drwxr-xr-x) format.";
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
output += "Textual representation: " + OS._perms_to_str(perms);
|
if (textual.length > 4) perms.rg = textual[4] == 'r';
|
||||||
output += "\nOctal representation: " + OS._perms_to_octal(perms);
|
if (textual.length > 5) perms.wg = textual[5] == 'w';
|
||||||
|
if (textual.length > 6) {
|
||||||
|
switch (textual[6]) {
|
||||||
|
case 'x':
|
||||||
|
perms.eg = true;
|
||||||
|
break;
|
||||||
|
case 's':
|
||||||
|
perms.eg = true;
|
||||||
|
perms.sg = true;
|
||||||
|
break;
|
||||||
|
case 'S':
|
||||||
|
perms.sg = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (textual.length > 7) perms.ro = textual[7] == 'r';
|
||||||
|
if (textual.length > 8) perms.wo = textual[8] == 'w';
|
||||||
|
if (textual.length > 9) {
|
||||||
|
switch (textual[9]) {
|
||||||
|
case 'x':
|
||||||
|
perms.eo = true;
|
||||||
|
break;
|
||||||
|
case 't':
|
||||||
|
perms.eo = true;
|
||||||
|
perms.sb = true;
|
||||||
|
break;
|
||||||
|
case 'T':
|
||||||
|
perms.sb = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return 'Invalid input format.\nPlease enter the permissions in either octal (e.g. 755) or textual (e.g. drwxr-xr-x) format.';
|
||||||
|
}
|
||||||
|
|
||||||
|
output += `Textual representation: ${OS._perms_to_str(perms)}`;
|
||||||
|
output += `\nOctal representation: ${OS._perms_to_octal(perms)}`;
|
||||||
|
|
||||||
// File type
|
// File type
|
||||||
if (textual) {
|
if (textual) {
|
||||||
output += "\nFile type: " + OS._ft_from_perms(perms);
|
output += `\nFile type: ${OS._ft_from_perms(perms)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// setuid, setgid
|
// setuid, setgid
|
||||||
if (perms.su) {
|
if (perms.su) {
|
||||||
output += "\nThe setuid flag is set";
|
output += '\nThe setuid flag is set';
|
||||||
}
|
}
|
||||||
if (perms.sg) {
|
if (perms.sg) {
|
||||||
output += "\nThe setgid flag is set";
|
output += '\nThe setgid flag is set';
|
||||||
}
|
}
|
||||||
|
|
||||||
// sticky bit
|
// sticky bit
|
||||||
if (perms.sb) {
|
if (perms.sb) {
|
||||||
output += "\nThe sticky bit is set";
|
output += '\nThe sticky bit is set';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Permission matrix
|
// Permission matrix
|
||||||
output += "\n\n +---------+-------+-------+-------+\n" +
|
output += `${'\n\n +---------+-------+-------+-------+\n' +
|
||||||
" | | User | Group | Other |\n" +
|
' | | User | Group | Other |\n' +
|
||||||
" +---------+-------+-------+-------+\n" +
|
' +---------+-------+-------+-------+\n' +
|
||||||
" | Read | " + (perms.ru ? "X" : " ") + " | " + (perms.rg ? "X" : " ") + " | " + (perms.ro ? "X" : " ") + " |\n" +
|
' | Read | '}${perms.ru ? 'X' : ' '} | ${perms.rg ? 'X' : ' '} | ${perms.ro ? 'X' : ' '} |\n` +
|
||||||
" +---------+-------+-------+-------+\n" +
|
' +---------+-------+-------+-------+\n' +
|
||||||
" | Write | " + (perms.wu ? "X" : " ") + " | " + (perms.wg ? "X" : " ") + " | " + (perms.wo ? "X" : " ") + " |\n" +
|
` | Write | ${perms.wu ? 'X' : ' '} | ${perms.wg ? 'X' : ' '} | ${perms.wo ? 'X' : ' '} |\n` +
|
||||||
" +---------+-------+-------+-------+\n" +
|
' +---------+-------+-------+-------+\n' +
|
||||||
" | Execute | " + (perms.eu ? "X" : " ") + " | " + (perms.eg ? "X" : " ") + " | " + (perms.eo ? "X" : " ") + " |\n" +
|
` | Execute | ${perms.eu ? 'X' : ' '} | ${perms.eg ? 'X' : ' '} | ${perms.eo ? 'X' : ' '} |\n` +
|
||||||
" +---------+-------+-------+-------+\n";
|
' +---------+-------+-------+-------+\n';
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -201,58 +201,58 @@ var OS = {
|
||||||
* @param {Object} perms
|
* @param {Object} perms
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
_perms_to_str: function(perms) {
|
_perms_to_str(perms) {
|
||||||
var str = "",
|
let str = '',
|
||||||
type = "-";
|
type = '-';
|
||||||
|
|
||||||
if (perms.d) type = "d";
|
if (perms.d) type = 'd';
|
||||||
if (perms.sl) type = "l";
|
if (perms.sl) type = 'l';
|
||||||
if (perms.np) type = "p";
|
if (perms.np) type = 'p';
|
||||||
if (perms.s) type = "s";
|
if (perms.s) type = 's';
|
||||||
if (perms.cd) type = "c";
|
if (perms.cd) type = 'c';
|
||||||
if (perms.bd) type = "b";
|
if (perms.bd) type = 'b';
|
||||||
if (perms.dr) type = "D";
|
if (perms.dr) type = 'D';
|
||||||
|
|
||||||
str = type;
|
str = type;
|
||||||
|
|
||||||
str += perms.ru ? "r" : "-";
|
str += perms.ru ? 'r' : '-';
|
||||||
str += perms.wu ? "w" : "-";
|
str += perms.wu ? 'w' : '-';
|
||||||
if (perms.eu && perms.su) {
|
if (perms.eu && perms.su) {
|
||||||
str += "s";
|
str += 's';
|
||||||
} else if (perms.su) {
|
} else if (perms.su) {
|
||||||
str += "S";
|
str += 'S';
|
||||||
} else if (perms.eu) {
|
} else if (perms.eu) {
|
||||||
str += "x";
|
str += 'x';
|
||||||
} else {
|
} else {
|
||||||
str += "-";
|
str += '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
str += perms.rg ? "r" : "-";
|
str += perms.rg ? 'r' : '-';
|
||||||
str += perms.wg ? "w" : "-";
|
str += perms.wg ? 'w' : '-';
|
||||||
if (perms.eg && perms.sg) {
|
if (perms.eg && perms.sg) {
|
||||||
str += "s";
|
str += 's';
|
||||||
} else if (perms.sg) {
|
} else if (perms.sg) {
|
||||||
str += "S";
|
str += 'S';
|
||||||
} else if (perms.eg) {
|
} else if (perms.eg) {
|
||||||
str += "x";
|
str += 'x';
|
||||||
} else {
|
} else {
|
||||||
str += "-";
|
str += '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
str += perms.ro ? "r" : "-";
|
str += perms.ro ? 'r' : '-';
|
||||||
str += perms.wo ? "w" : "-";
|
str += perms.wo ? 'w' : '-';
|
||||||
if (perms.eo && perms.sb) {
|
if (perms.eo && perms.sb) {
|
||||||
str += "t";
|
str += 't';
|
||||||
} else if (perms.sb) {
|
} else if (perms.sb) {
|
||||||
str += "T";
|
str += 'T';
|
||||||
} else if (perms.eo) {
|
} else if (perms.eo) {
|
||||||
str += "x";
|
str += 'x';
|
||||||
} else {
|
} else {
|
||||||
str += "-";
|
str += '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -262,30 +262,30 @@ var OS = {
|
||||||
* @param {Object} perms
|
* @param {Object} perms
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
_perms_to_octal: function(perms) {
|
_perms_to_octal(perms) {
|
||||||
var d = 0,
|
let d = 0,
|
||||||
u = 0,
|
u = 0,
|
||||||
g = 0,
|
g = 0,
|
||||||
o = 0;
|
o = 0;
|
||||||
|
|
||||||
if (perms.su) d += 4;
|
if (perms.su) d += 4;
|
||||||
if (perms.sg) d += 2;
|
if (perms.sg) d += 2;
|
||||||
if (perms.sb) d += 1;
|
if (perms.sb) d += 1;
|
||||||
|
|
||||||
if (perms.ru) u += 4;
|
if (perms.ru) u += 4;
|
||||||
if (perms.wu) u += 2;
|
if (perms.wu) u += 2;
|
||||||
if (perms.eu) u += 1;
|
if (perms.eu) u += 1;
|
||||||
|
|
||||||
if (perms.rg) g += 4;
|
if (perms.rg) g += 4;
|
||||||
if (perms.wg) g += 2;
|
if (perms.wg) g += 2;
|
||||||
if (perms.eg) g += 1;
|
if (perms.eg) g += 1;
|
||||||
|
|
||||||
if (perms.ro) o += 4;
|
if (perms.ro) o += 4;
|
||||||
if (perms.wo) o += 2;
|
if (perms.wo) o += 2;
|
||||||
if (perms.eo) o += 1;
|
if (perms.eo) o += 1;
|
||||||
|
|
||||||
return d.toString() + u.toString() + g.toString() + o.toString();
|
return d.toString() + u.toString() + g.toString() + o.toString();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -295,15 +295,15 @@ var OS = {
|
||||||
* @param {Object} perms
|
* @param {Object} perms
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
_ft_from_perms: function(perms) {
|
_ft_from_perms(perms) {
|
||||||
if (perms.d) return "Directory";
|
if (perms.d) return 'Directory';
|
||||||
if (perms.sl) return "Symbolic link";
|
if (perms.sl) return 'Symbolic link';
|
||||||
if (perms.np) return "Named pipe";
|
if (perms.np) return 'Named pipe';
|
||||||
if (perms.s) return "Socket";
|
if (perms.s) return 'Socket';
|
||||||
if (perms.cd) return "Character device";
|
if (perms.cd) return 'Character device';
|
||||||
if (perms.bd) return "Block device";
|
if (perms.bd) return 'Block device';
|
||||||
if (perms.dr) return "Door";
|
if (perms.dr) return 'Door';
|
||||||
return "Regular file";
|
return 'Regular file';
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -9,13 +9,13 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var Punycode = {
|
const Punycode = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
IDN: false,
|
IDN: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To Punycode operation.
|
* To Punycode operation.
|
||||||
|
@ -24,15 +24,15 @@ var Punycode = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_to_ascii: function(input, args) {
|
run_to_ascii(input, args) {
|
||||||
var idn = args[0];
|
const idn = args[0];
|
||||||
|
|
||||||
if (idn) {
|
if (idn) {
|
||||||
return punycode.ToASCII(input);
|
return punycode.ToASCII(input);
|
||||||
} else {
|
} else {
|
||||||
return punycode.encode(input);
|
return punycode.encode(input);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -42,14 +42,14 @@ var Punycode = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_to_unicode: function(input, args) {
|
run_to_unicode(input, args) {
|
||||||
var idn = args[0];
|
const idn = args[0];
|
||||||
|
|
||||||
if (idn) {
|
if (idn) {
|
||||||
return punycode.ToUnicode(input);
|
return punycode.ToUnicode(input);
|
||||||
} else {
|
} else {
|
||||||
return punycode.decode(input);
|
return punycode.decode(input);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var QuotedPrintable = {
|
const QuotedPrintable = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To Quoted Printable operation.
|
* To Quoted Printable operation.
|
||||||
|
@ -39,18 +39,14 @@ var QuotedPrintable = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_to: function (input, args) {
|
run_to(input, args) {
|
||||||
var mimeEncodedStr = QuotedPrintable.mimeEncode(input);
|
let mimeEncodedStr = QuotedPrintable.mimeEncode(input);
|
||||||
|
|
||||||
// fix line breaks
|
// fix line breaks
|
||||||
mimeEncodedStr = mimeEncodedStr.replace(/\r?\n|\r/g, function() {
|
mimeEncodedStr = mimeEncodedStr.replace(/\r?\n|\r/g, () => '\r\n').replace(/[\t ]+$/gm, spaces => spaces.replace(/ /g, '=20').replace(/\t/g, '=09'));
|
||||||
return "\r\n";
|
|
||||||
}).replace(/[\t ]+$/gm, function(spaces) {
|
|
||||||
return spaces.replace(/ /g, "=20").replace(/\t/g, "=09");
|
|
||||||
});
|
|
||||||
|
|
||||||
return QuotedPrintable._addSoftLinebreaks(mimeEncodedStr, "qp");
|
return QuotedPrintable._addSoftLinebreaks(mimeEncodedStr, 'qp');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,10 +56,10 @@ var QuotedPrintable = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_from: function (input, args) {
|
run_from(input, args) {
|
||||||
var str = input.replace(/\=(?:\r?\n|$)/g, "");
|
const str = input.replace(/\=(?:\r?\n|$)/g, '');
|
||||||
return QuotedPrintable.mimeDecode(str);
|
return QuotedPrintable.mimeDecode(str);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -72,25 +68,26 @@ var QuotedPrintable = {
|
||||||
* @param {string} str
|
* @param {string} str
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
mimeDecode: function(str) {
|
mimeDecode(str) {
|
||||||
var encodedBytesCount = (str.match(/\=[\da-fA-F]{2}/g) || []).length,
|
let encodedBytesCount = (str.match(/\=[\da-fA-F]{2}/g) || []).length,
|
||||||
bufferLength = str.length - encodedBytesCount * 2,
|
bufferLength = str.length - encodedBytesCount * 2,
|
||||||
chr, hex,
|
chr,
|
||||||
buffer = new Array(bufferLength),
|
hex,
|
||||||
bufferPos = 0;
|
buffer = new Array(bufferLength),
|
||||||
|
bufferPos = 0;
|
||||||
|
|
||||||
for (var i = 0, len = str.length; i < len; i++) {
|
for (let i = 0, len = str.length; i < len; i++) {
|
||||||
chr = str.charAt(i);
|
chr = str.charAt(i);
|
||||||
if (chr == "=" && (hex = str.substr(i + 1, 2)) && /[\da-fA-F]{2}/.test(hex)) {
|
if (chr == '=' && (hex = str.substr(i + 1, 2)) && /[\da-fA-F]{2}/.test(hex)) {
|
||||||
buffer[bufferPos++] = parseInt(hex, 16);
|
buffer[bufferPos++] = parseInt(hex, 16);
|
||||||
i += 2;
|
i += 2;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
buffer[bufferPos++] = chr.charCodeAt(0);
|
buffer[bufferPos++] = chr.charCodeAt(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return buffer;
|
return buffer;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -99,8 +96,8 @@ var QuotedPrintable = {
|
||||||
* @param {byte_array} buffer
|
* @param {byte_array} buffer
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
mimeEncode: function(buffer) {
|
mimeEncode(buffer) {
|
||||||
var ranges = [
|
let ranges = [
|
||||||
[0x09],
|
[0x09],
|
||||||
[0x0A],
|
[0x0A],
|
||||||
[0x0D],
|
[0x0D],
|
||||||
|
@ -109,20 +106,20 @@ var QuotedPrintable = {
|
||||||
[0x23, 0x3C],
|
[0x23, 0x3C],
|
||||||
[0x3E],
|
[0x3E],
|
||||||
[0x40, 0x5E],
|
[0x40, 0x5E],
|
||||||
[0x60, 0x7E]
|
[0x60, 0x7E],
|
||||||
],
|
],
|
||||||
result = "";
|
result = '';
|
||||||
|
|
||||||
for (var i = 0, len = buffer.length; i < len; i++) {
|
for (let i = 0, len = buffer.length; i < len; i++) {
|
||||||
if (this._checkRanges(buffer[i], ranges)) {
|
if (this._checkRanges(buffer[i], ranges)) {
|
||||||
result += String.fromCharCode(buffer[i]);
|
result += String.fromCharCode(buffer[i]);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
result += "=" + (buffer[i] < 0x10 ? "0" : "") + buffer[i].toString(16).toUpperCase();
|
result += `=${buffer[i] < 0x10 ? '0' : ''}${buffer[i].toString(16).toUpperCase()}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -133,17 +130,20 @@ var QuotedPrintable = {
|
||||||
* @param {byte_array[]} ranges
|
* @param {byte_array[]} ranges
|
||||||
* @returns {bolean}
|
* @returns {bolean}
|
||||||
*/
|
*/
|
||||||
_checkRanges: function(nr, ranges) {
|
_checkRanges(nr, ranges) {
|
||||||
for (var i = ranges.length - 1; i >= 0; i--) {
|
for (let i = ranges.length - 1; i >= 0; i--) {
|
||||||
if (!ranges[i].length)
|
if (!ranges[i].length) {
|
||||||
continue;
|
continue;
|
||||||
if (ranges[i].length == 1 && nr == ranges[i][0])
|
}
|
||||||
return true;
|
if (ranges[i].length == 1 && nr == ranges[i][0]) {
|
||||||
if (ranges[i].length == 2 && nr >= ranges[i][0] && nr <= ranges[i][1])
|
return true;
|
||||||
return true;
|
}
|
||||||
}
|
if (ranges[i].length == 2 && nr >= ranges[i][0] && nr <= ranges[i][1]) {
|
||||||
return false;
|
return true;
|
||||||
},
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -156,17 +156,17 @@ var QuotedPrintable = {
|
||||||
* @param {string} encoding
|
* @param {string} encoding
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
_addSoftLinebreaks: function(str, encoding) {
|
_addSoftLinebreaks(str, encoding) {
|
||||||
var lineLengthMax = 76;
|
const lineLengthMax = 76;
|
||||||
|
|
||||||
encoding = (encoding || "base64").toString().toLowerCase().trim();
|
encoding = (encoding || 'base64').toString().toLowerCase().trim();
|
||||||
|
|
||||||
if (encoding == "qp") {
|
if (encoding == 'qp') {
|
||||||
return this._addQPSoftLinebreaks(str, lineLengthMax);
|
return this._addQPSoftLinebreaks(str, lineLengthMax);
|
||||||
} else {
|
} else {
|
||||||
return this._addBase64SoftLinebreaks(str, lineLengthMax);
|
return this._addBase64SoftLinebreaks(str, lineLengthMax);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -177,10 +177,10 @@ var QuotedPrintable = {
|
||||||
* @param {number} lineLengthMax
|
* @param {number} lineLengthMax
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
_addBase64SoftLinebreaks: function(base64EncodedStr, lineLengthMax) {
|
_addBase64SoftLinebreaks(base64EncodedStr, lineLengthMax) {
|
||||||
base64EncodedStr = (base64EncodedStr || "").toString().trim();
|
base64EncodedStr = (base64EncodedStr || '').toString().trim();
|
||||||
return base64EncodedStr.replace(new RegExp(".{" + lineLengthMax + "}", "g"), "$&\r\n").trim();
|
return base64EncodedStr.replace(new RegExp(`.{${lineLengthMax}}`, 'g'), '$&\r\n').trim();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -191,80 +191,78 @@ var QuotedPrintable = {
|
||||||
* @param {number} lineLengthMax
|
* @param {number} lineLengthMax
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
_addQPSoftLinebreaks: function(mimeEncodedStr, lineLengthMax) {
|
_addQPSoftLinebreaks(mimeEncodedStr, lineLengthMax) {
|
||||||
var pos = 0,
|
let pos = 0,
|
||||||
len = mimeEncodedStr.length,
|
len = mimeEncodedStr.length,
|
||||||
match, code, line,
|
match,
|
||||||
lineMargin = Math.floor(lineLengthMax / 3),
|
code,
|
||||||
result = "";
|
line,
|
||||||
|
lineMargin = Math.floor(lineLengthMax / 3),
|
||||||
|
result = '';
|
||||||
|
|
||||||
// insert soft linebreaks where needed
|
// insert soft linebreaks where needed
|
||||||
while (pos < len) {
|
while (pos < len) {
|
||||||
line = mimeEncodedStr.substr(pos, lineLengthMax);
|
line = mimeEncodedStr.substr(pos, lineLengthMax);
|
||||||
if ((match = line.match(/\r\n/))) {
|
if ((match = line.match(/\r\n/))) {
|
||||||
line = line.substr(0, match.index + match[0].length);
|
line = line.substr(0, match.index + match[0].length);
|
||||||
result += line;
|
result += line;
|
||||||
pos += line.length;
|
pos += line.length;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (line.substr(-1) == "\n") {
|
if (line.substr(-1) == '\n') {
|
||||||
// nothing to change here
|
// nothing to change here
|
||||||
result += line;
|
result += line;
|
||||||
pos += line.length;
|
pos += line.length;
|
||||||
continue;
|
continue;
|
||||||
} else if ((match = line.substr(-lineMargin).match(/\n.*?$/))) {
|
} else if ((match = line.substr(-lineMargin).match(/\n.*?$/))) {
|
||||||
// truncate to nearest line break
|
// truncate to nearest line break
|
||||||
line = line.substr(0, line.length - (match[0].length - 1));
|
line = line.substr(0, line.length - (match[0].length - 1));
|
||||||
result += line;
|
result += line;
|
||||||
pos += line.length;
|
pos += line.length;
|
||||||
continue;
|
continue;
|
||||||
} else if (line.length > lineLengthMax - lineMargin && (match = line.substr(-lineMargin).match(/[ \t\.,!\?][^ \t\.,!\?]*$/))) {
|
} else if (line.length > lineLengthMax - lineMargin && (match = line.substr(-lineMargin).match(/[ \t\.,!\?][^ \t\.,!\?]*$/))) {
|
||||||
// truncate to nearest space
|
// truncate to nearest space
|
||||||
line = line.substr(0, line.length - (match[0].length - 1));
|
line = line.substr(0, line.length - (match[0].length - 1));
|
||||||
} else if (line.substr(-1) == "\r") {
|
} else if (line.substr(-1) == '\r') {
|
||||||
line = line.substr(0, line.length - 1);
|
line = line.substr(0, line.length - 1);
|
||||||
} else {
|
} else if (line.match(/\=[\da-f]{0,2}$/i)) {
|
||||||
if (line.match(/\=[\da-f]{0,2}$/i)) {
|
|
||||||
|
|
||||||
// push incomplete encoding sequences to the next line
|
// push incomplete encoding sequences to the next line
|
||||||
if ((match = line.match(/\=[\da-f]{0,1}$/i))) {
|
if ((match = line.match(/\=[\da-f]{0,1}$/i))) {
|
||||||
line = line.substr(0, line.length - match[0].length);
|
line = line.substr(0, line.length - match[0].length);
|
||||||
}
|
|
||||||
|
|
||||||
// ensure that utf-8 sequences are not split
|
|
||||||
while (line.length > 3 && line.length < len - pos && !line.match(/^(?:=[\da-f]{2}){1,4}$/i) && (match = line.match(/\=[\da-f]{2}$/ig))) {
|
|
||||||
code = parseInt(match[0].substr(1, 2), 16);
|
|
||||||
if (code < 128) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
line = line.substr(0, line.length - 3);
|
|
||||||
|
|
||||||
if (code >= 0xC0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pos + line.length < len && line.substr(-1) != "\n") {
|
|
||||||
if (line.length == 76 && line.match(/\=[\da-f]{2}$/i)) {
|
|
||||||
line = line.substr(0, line.length - 3);
|
|
||||||
} else if (line.length == 76) {
|
|
||||||
line = line.substr(0, line.length - 1);
|
|
||||||
}
|
|
||||||
pos += line.length;
|
|
||||||
line += "=\r\n";
|
|
||||||
} else {
|
|
||||||
pos += line.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
result += line;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
// ensure that utf-8 sequences are not split
|
||||||
},
|
while (line.length > 3 && line.length < len - pos && !line.match(/^(?:=[\da-f]{2}){1,4}$/i) && (match = line.match(/\=[\da-f]{2}$/ig))) {
|
||||||
|
code = parseInt(match[0].substr(1, 2), 16);
|
||||||
|
if (code < 128) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
line = line.substr(0, line.length - 3);
|
||||||
|
|
||||||
|
if (code >= 0xC0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pos + line.length < len && line.substr(-1) != '\n') {
|
||||||
|
if (line.length == 76 && line.match(/\=[\da-f]{2}$/i)) {
|
||||||
|
line = line.substr(0, line.length - 3);
|
||||||
|
} else if (line.length == 76) {
|
||||||
|
line = line.substr(0, line.length - 1);
|
||||||
|
}
|
||||||
|
pos += line.length;
|
||||||
|
line += '=\r\n';
|
||||||
|
} else {
|
||||||
|
pos += line.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
result += line;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,18 +9,18 @@
|
||||||
*
|
*
|
||||||
* @todo Support for UTF16
|
* @todo Support for UTF16
|
||||||
*/
|
*/
|
||||||
var Rotate = {
|
const Rotate = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
ROTATE_AMOUNT: 1,
|
ROTATE_AMOUNT: 1,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
ROTATE_WHOLE: false,
|
ROTATE_WHOLE: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs rotation operations across the input data.
|
* Runs rotation operations across the input data.
|
||||||
|
@ -31,17 +31,17 @@ var Rotate = {
|
||||||
* @param {function} algo - The rotation operation to carry out
|
* @param {function} algo - The rotation operation to carry out
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
_rot: function(data, amount, algo) {
|
_rot(data, amount, algo) {
|
||||||
var result = [];
|
const result = [];
|
||||||
for (var i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
var b = data[i];
|
let b = data[i];
|
||||||
for (var j = 0; j < amount; j++) {
|
for (let j = 0; j < amount; j++) {
|
||||||
b = algo(b);
|
b = algo(b);
|
||||||
}
|
}
|
||||||
result.push(b);
|
result.push(b);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -51,13 +51,13 @@ var Rotate = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_rotr: function(input, args) {
|
run_rotr(input, args) {
|
||||||
if (args[1]) {
|
if (args[1]) {
|
||||||
return Rotate._rotr_whole(input, args[0]);
|
return Rotate._rotr_whole(input, args[0]);
|
||||||
} else {
|
} else {
|
||||||
return Rotate._rot(input, args[0], Rotate._rotr);
|
return Rotate._rot(input, args[0], Rotate._rotr);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -67,30 +67,30 @@ var Rotate = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_rotl: function(input, args) {
|
run_rotl(input, args) {
|
||||||
if (args[1]) {
|
if (args[1]) {
|
||||||
return Rotate._rotl_whole(input, args[0]);
|
return Rotate._rotl_whole(input, args[0]);
|
||||||
} else {
|
} else {
|
||||||
return Rotate._rot(input, args[0], Rotate._rotl);
|
return Rotate._rot(input, args[0], Rotate._rotl);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
ROT13_AMOUNT: 13,
|
ROT13_AMOUNT: 13,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
ROT13_LOWERCASE: true,
|
ROT13_LOWERCASE: true,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
ROT13_UPPERCASE: true,
|
ROT13_UPPERCASE: true,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ROT13 operation.
|
* ROT13 operation.
|
||||||
|
@ -99,31 +99,31 @@ var Rotate = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_rot13: function(input, args) {
|
run_rot13(input, args) {
|
||||||
var amount = args[2],
|
let amount = args[2],
|
||||||
output = input,
|
output = input,
|
||||||
chr,
|
chr,
|
||||||
rot13_lowercase = args[0],
|
rot13_lowercase = args[0],
|
||||||
rot13_upperacse = args[1];
|
rot13_upperacse = args[1];
|
||||||
|
|
||||||
if (amount) {
|
if (amount) {
|
||||||
if (amount < 0) {
|
if (amount < 0) {
|
||||||
amount = 26 - (Math.abs(amount) % 26);
|
amount = 26 - (Math.abs(amount) % 26);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
chr = input[i];
|
chr = input[i];
|
||||||
if (rot13_upperacse && chr >= 65 && chr <= 90) { // Upper case
|
if (rot13_upperacse && chr >= 65 && chr <= 90) { // Upper case
|
||||||
chr = (chr - 65 + amount) % 26;
|
chr = (chr - 65 + amount) % 26;
|
||||||
output[i] = chr + 65;
|
output[i] = chr + 65;
|
||||||
} else if (rot13_lowercase && chr >= 97 && chr <= 122) { // Lower case
|
} else if (rot13_lowercase && chr >= 97 && chr <= 122) { // Lower case
|
||||||
chr = (chr - 97 + amount) % 26;
|
chr = (chr - 97 + amount) % 26;
|
||||||
output[i] = chr + 97;
|
output[i] = chr + 97;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return output;
|
}
|
||||||
},
|
}
|
||||||
|
return output;
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -133,10 +133,10 @@ var Rotate = {
|
||||||
* @param {byte} b
|
* @param {byte} b
|
||||||
* @returns {byte}
|
* @returns {byte}
|
||||||
*/
|
*/
|
||||||
_rotr: function(b) {
|
_rotr(b) {
|
||||||
var bit = (b & 1) << 7;
|
const bit = (b & 1) << 7;
|
||||||
return (b >> 1) | bit;
|
return (b >> 1) | bit;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -146,10 +146,10 @@ var Rotate = {
|
||||||
* @param {byte} b
|
* @param {byte} b
|
||||||
* @returns {byte}
|
* @returns {byte}
|
||||||
*/
|
*/
|
||||||
_rotl: function(b) {
|
_rotl(b) {
|
||||||
var bit = (b >> 7) & 1;
|
const bit = (b >> 7) & 1;
|
||||||
return ((b << 1) | bit) & 0xFF;
|
return ((b << 1) | bit) & 0xFF;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -161,21 +161,21 @@ var Rotate = {
|
||||||
* @param {number} amount
|
* @param {number} amount
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
_rotr_whole: function(data, amount) {
|
_rotr_whole(data, amount) {
|
||||||
var carry_bits = 0,
|
let carry_bits = 0,
|
||||||
new_byte,
|
new_byte,
|
||||||
result = [];
|
result = [];
|
||||||
|
|
||||||
amount = amount % 8;
|
amount %= 8;
|
||||||
for (var i = 0; i < data.length; i++) {
|
for (let i = 0; i < data.length; i++) {
|
||||||
var old_byte = data[i] >>> 0;
|
const old_byte = data[i] >>> 0;
|
||||||
new_byte = (old_byte >> amount) | carry_bits;
|
new_byte = (old_byte >> amount) | carry_bits;
|
||||||
carry_bits = (old_byte & (Math.pow(2, amount)-1)) << (8-amount);
|
carry_bits = (old_byte & (Math.pow(2, amount) - 1)) << (8 - amount);
|
||||||
result.push(new_byte);
|
result.push(new_byte);
|
||||||
}
|
}
|
||||||
result[0] |= carry_bits;
|
result[0] |= carry_bits;
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -187,20 +187,20 @@ var Rotate = {
|
||||||
* @param {number} amount
|
* @param {number} amount
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
_rotl_whole: function(data, amount) {
|
_rotl_whole(data, amount) {
|
||||||
var carry_bits = 0,
|
let carry_bits = 0,
|
||||||
new_byte,
|
new_byte,
|
||||||
result = [];
|
result = [];
|
||||||
|
|
||||||
amount = amount % 8;
|
amount %= 8;
|
||||||
for (var i = data.length-1; i >= 0; i--) {
|
for (let i = data.length - 1; i >= 0; i--) {
|
||||||
var old_byte = data[i];
|
const old_byte = data[i];
|
||||||
new_byte = ((old_byte << amount) | carry_bits) & 0xFF;
|
new_byte = ((old_byte << amount) | carry_bits) & 0xFF;
|
||||||
carry_bits = (old_byte >> (8-amount)) & (Math.pow(2, amount)-1);
|
carry_bits = (old_byte >> (8 - amount)) & (Math.pow(2, amount) - 1);
|
||||||
result[i] = (new_byte);
|
result[i] = (new_byte);
|
||||||
}
|
}
|
||||||
result[data.length-1] = result[data.length-1] | carry_bits;
|
result[data.length - 1] = result[data.length - 1] | carry_bits;
|
||||||
return result;
|
return result;
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,23 +7,23 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var SeqUtils = {
|
const SeqUtils = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
DELIMITER_OPTIONS: ["Line feed", "CRLF", "Space", "Comma", "Semi-colon", "Colon", "Nothing (separate chars)"],
|
DELIMITER_OPTIONS: ['Line feed', 'CRLF', 'Space', 'Comma', 'Semi-colon', 'Colon', 'Nothing (separate chars)'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
SORT_REVERSE: false,
|
SORT_REVERSE: false,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
SORT_ORDER: ["Alphabetical (case sensitive)", "Alphabetical (case insensitive)", "IP address"],
|
SORT_ORDER: ['Alphabetical (case sensitive)', 'Alphabetical (case insensitive)', 'IP address'],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort operation.
|
* Sort operation.
|
||||||
|
@ -32,23 +32,23 @@ var SeqUtils = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_sort: function (input, args) {
|
run_sort(input, args) {
|
||||||
var delim = Utils.char_rep[args[0]],
|
let delim = Utils.char_rep[args[0]],
|
||||||
sort_reverse = args[1],
|
sort_reverse = args[1],
|
||||||
order = args[2],
|
order = args[2],
|
||||||
sorted = input.split(delim);
|
sorted = input.split(delim);
|
||||||
|
|
||||||
if (order == "Alphabetical (case sensitive)") {
|
if (order == 'Alphabetical (case sensitive)') {
|
||||||
sorted = sorted.sort();
|
sorted = sorted.sort();
|
||||||
} else if (order == "Alphabetical (case insensitive)") {
|
} else if (order == 'Alphabetical (case insensitive)') {
|
||||||
sorted = sorted.sort(SeqUtils._case_insensitive_sort);
|
sorted = sorted.sort(SeqUtils._case_insensitive_sort);
|
||||||
} else if (order == "IP address") {
|
} else if (order == 'IP address') {
|
||||||
sorted = sorted.sort(SeqUtils._ip_sort);
|
sorted = sorted.sort(SeqUtils._ip_sort);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sort_reverse) sorted.reverse();
|
if (sort_reverse) sorted.reverse();
|
||||||
return sorted.join(delim);
|
return sorted.join(delim);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -58,17 +58,17 @@ var SeqUtils = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_unique: function (input, args) {
|
run_unique(input, args) {
|
||||||
var delim = Utils.char_rep[args[0]];
|
const delim = Utils.char_rep[args[0]];
|
||||||
return input.split(delim).unique().join(delim);
|
return input.split(delim).unique().join(delim);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
SEARCH_TYPE: ["Regex", "Extended (\\n, \\t, \\x...)", "Simple string"],
|
SEARCH_TYPE: ['Regex', 'Extended (\\n, \\t, \\x...)', 'Simple string'],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Count occurrences operation.
|
* Count occurrences operation.
|
||||||
|
@ -77,34 +77,34 @@ var SeqUtils = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
run_count: function(input, args) {
|
run_count(input, args) {
|
||||||
var search = args[0].string,
|
let search = args[0].string,
|
||||||
type = args[0].option;
|
type = args[0].option;
|
||||||
|
|
||||||
if (type == "Regex" && search) {
|
if (type == 'Regex' && search) {
|
||||||
try {
|
try {
|
||||||
var regex = new RegExp(search, "gi"),
|
let regex = new RegExp(search, 'gi'),
|
||||||
matches = input.match(regex);
|
matches = input.match(regex);
|
||||||
return matches.length;
|
return matches.length;
|
||||||
} catch(err) {
|
} catch (err) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
} else if (search) {
|
} else if (search) {
|
||||||
if (type.indexOf("Extended") === 0) {
|
if (type.indexOf('Extended') === 0) {
|
||||||
search = Utils.parse_escaped_chars(search);
|
search = Utils.parse_escaped_chars(search);
|
||||||
}
|
}
|
||||||
return input.count(search);
|
return input.count(search);
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
REVERSE_BY: ["Character", "Line"],
|
REVERSE_BY: ['Character', 'Line'],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverse operation.
|
* Reverse operation.
|
||||||
|
@ -113,30 +113,30 @@ var SeqUtils = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_reverse: function (input, args) {
|
run_reverse(input, args) {
|
||||||
if (args[0] == "Line") {
|
if (args[0] == 'Line') {
|
||||||
var lines = [],
|
let lines = [],
|
||||||
line = [],
|
line = [],
|
||||||
result = [];
|
result = [];
|
||||||
for (var i = 0; i < input.length; i++) {
|
for (var i = 0; i < input.length; i++) {
|
||||||
if (input[i] == 0x0a) {
|
if (input[i] == 0x0a) {
|
||||||
lines.push(line);
|
lines.push(line);
|
||||||
line = [];
|
line = [];
|
||||||
} else {
|
|
||||||
line.push(input[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
lines.push(line);
|
|
||||||
lines.reverse();
|
|
||||||
for (i = 0; i < lines.length; i++) {
|
|
||||||
result = result.concat(lines[i]);
|
|
||||||
result.push(0x0a);
|
|
||||||
}
|
|
||||||
return result.slice(0, input.length);
|
|
||||||
} else {
|
} else {
|
||||||
return input.reverse();
|
line.push(input[i]);
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
|
lines.push(line);
|
||||||
|
lines.reverse();
|
||||||
|
for (i = 0; i < lines.length; i++) {
|
||||||
|
result = result.concat(lines[i]);
|
||||||
|
result.push(0x0a);
|
||||||
|
}
|
||||||
|
return result.slice(0, input.length);
|
||||||
|
} else {
|
||||||
|
return input.reverse();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -146,16 +146,16 @@ var SeqUtils = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_add_line_numbers: function(input, args) {
|
run_add_line_numbers(input, args) {
|
||||||
var lines = input.split("\n"),
|
let lines = input.split('\n'),
|
||||||
output = "",
|
output = '',
|
||||||
width = lines.length.toString().length;
|
width = lines.length.toString().length;
|
||||||
|
|
||||||
for (var n = 0; n < lines.length; n++) {
|
for (let n = 0; n < lines.length; n++) {
|
||||||
output += Utils.pad((n+1).toString(), width, " ") + " " + lines[n] + "\n";
|
output += `${Utils.pad((n + 1).toString(), width, ' ')} ${lines[n]}\n`;
|
||||||
}
|
}
|
||||||
return output.slice(0, output.length-1);
|
return output.slice(0, output.length - 1);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -165,9 +165,9 @@ var SeqUtils = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_remove_line_numbers: function(input, args) {
|
run_remove_line_numbers(input, args) {
|
||||||
return input.replace(/^[ \t]{0,5}\d+[\s:|\-,.)\]]/gm, "");
|
return input.replace(/^[ \t]{0,5}\d+[\s:|\-,.)\]]/gm, '');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -177,9 +177,9 @@ var SeqUtils = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_expand_alph_range: function(input, args) {
|
run_expand_alph_range(input, args) {
|
||||||
return Utils.expand_alph_range(input).join(args[0]);
|
return Utils.expand_alph_range(input).join(args[0]);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -190,9 +190,9 @@ var SeqUtils = {
|
||||||
* @param {string} b
|
* @param {string} b
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
_case_insensitive_sort: function(a, b) {
|
_case_insensitive_sort(a, b) {
|
||||||
return a.toLowerCase().localeCompare(b.toLowerCase());
|
return a.toLowerCase().localeCompare(b.toLowerCase());
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -203,18 +203,18 @@ var SeqUtils = {
|
||||||
* @param {string} b
|
* @param {string} b
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
_ip_sort: function(a, b) {
|
_ip_sort(a, b) {
|
||||||
var a_ = a.split("."),
|
let a_ = a.split('.'),
|
||||||
b_ = b.split(".");
|
b_ = b.split('.');
|
||||||
|
|
||||||
a_ = a_[0] * 0x1000000 + a_[1] * 0x10000 + a_[2] * 0x100 + a_[3] * 1;
|
a_ = a_[0] * 0x1000000 + a_[1] * 0x10000 + a_[2] * 0x100 + a_[3] * 1;
|
||||||
b_ = b_[0] * 0x1000000 + b_[1] * 0x10000 + b_[2] * 0x100 + b_[3] * 1;
|
b_ = b_[0] * 0x1000000 + b_[1] * 0x10000 + b_[2] * 0x100 + b_[3] * 1;
|
||||||
|
|
||||||
if (isNaN(a_) && !isNaN(b_)) return 1;
|
if (isNaN(a_) && !isNaN(b_)) return 1;
|
||||||
if (!isNaN(a_) && isNaN(b_)) return -1;
|
if (!isNaN(a_) && isNaN(b_)) return -1;
|
||||||
if (isNaN(a_) && isNaN(b_)) return a.localeCompare(b);
|
if (isNaN(a_) && isNaN(b_)) return a.localeCompare(b);
|
||||||
|
|
||||||
return a_ - b_;
|
return a_ - b_;
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,86 +9,86 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var StrUtils = {
|
const StrUtils = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
REGEX_PRE_POPULATE: [
|
REGEX_PRE_POPULATE: [
|
||||||
{
|
{
|
||||||
name: "User defined",
|
name: 'User defined',
|
||||||
value: ""
|
value: '',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "IPv4 address",
|
name: 'IPv4 address',
|
||||||
value: "(?:(?:\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d|\\d)(?:\\/\\d{1,2})?"
|
value: '(?:(?:\\d|[01]?\\d\\d|2[0-4]\\d|25[0-5])\\.){3}(?:25[0-5]|2[0-4]\\d|[01]?\\d\\d|\\d)(?:\\/\\d{1,2})?',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "IPv6 address",
|
name: 'IPv6 address',
|
||||||
value: "((?=.*::)(?!.*::.+::)(::)?([\\dA-Fa-f]{1,4}:(:|\\b)|){5}|([\\dA-Fa-f]{1,4}:){6})((([\\dA-Fa-f]{1,4}((?!\\3)::|:\\b|(?![\\dA-Fa-f])))|(?!\\2\\3)){2}|(((2[0-4]|1\\d|[1-9])?\\d|25[0-5])\\.?\\b){4})"
|
value: '((?=.*::)(?!.*::.+::)(::)?([\\dA-Fa-f]{1,4}:(:|\\b)|){5}|([\\dA-Fa-f]{1,4}:){6})((([\\dA-Fa-f]{1,4}((?!\\3)::|:\\b|(?![\\dA-Fa-f])))|(?!\\2\\3)){2}|(((2[0-4]|1\\d|[1-9])?\\d|25[0-5])\\.?\\b){4})',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Email address",
|
name: 'Email address',
|
||||||
value: "(\\w[-.\\w]*)@([-\\w]+(?:\\.[-\\w]+)*)\\.([A-Za-z]{2,4})"
|
value: '(\\w[-.\\w]*)@([-\\w]+(?:\\.[-\\w]+)*)\\.([A-Za-z]{2,4})',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "URL",
|
name: 'URL',
|
||||||
value: "([A-Za-z]+://)([-\\w]+(?:\\.\\w[-\\w]*)+)(:\\d+)?(/[^.!,?;\"\\x27<>()\\[\\]{}\\s\\x7F-\\xFF]*(?:[.!,?]+[^.!,?;\"\\x27<>()\\[\\]{}\\s\\x7F-\\xFF]+)*)?"
|
value: '([A-Za-z]+://)([-\\w]+(?:\\.\\w[-\\w]*)+)(:\\d+)?(/[^.!,?;"\\x27<>()\\[\\]{}\\s\\x7F-\\xFF]*(?:[.!,?]+[^.!,?;"\\x27<>()\\[\\]{}\\s\\x7F-\\xFF]+)*)?',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Domain",
|
name: 'Domain',
|
||||||
value: "(?:(https?):\\/\\/)?([-\\w.]+)\\.(com|net|org|biz|info|co|uk|onion|int|mobi|name|edu|gov|mil|eu|ac|ae|af|de|ca|ch|cn|cy|es|gb|hk|il|in|io|tv|me|nl|no|nz|ro|ru|tr|us|az|ir|kz|uz|pk)+"
|
value: '(?:(https?):\\/\\/)?([-\\w.]+)\\.(com|net|org|biz|info|co|uk|onion|int|mobi|name|edu|gov|mil|eu|ac|ae|af|de|ca|ch|cn|cy|es|gb|hk|il|in|io|tv|me|nl|no|nz|ro|ru|tr|us|az|ir|kz|uz|pk)+',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Windows file path",
|
name: 'Windows file path',
|
||||||
value: "([A-Za-z]):\\\\((?:[A-Za-z\\d][A-Za-z\\d\\- \\x27_\\(\\)]{0,61}\\\\?)*[A-Za-z\\d][A-Za-z\\d\\- \\x27_\\(\\)]{0,61})(\\.[A-Za-z\\d]{1,6})?"
|
value: '([A-Za-z]):\\\\((?:[A-Za-z\\d][A-Za-z\\d\\- \\x27_\\(\\)]{0,61}\\\\?)*[A-Za-z\\d][A-Za-z\\d\\- \\x27_\\(\\)]{0,61})(\\.[A-Za-z\\d]{1,6})?',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "UNIX file path",
|
name: 'UNIX file path',
|
||||||
value: "(?:/[A-Za-z\\d.][A-Za-z\\d\\-.]{0,61})+"
|
value: '(?:/[A-Za-z\\d.][A-Za-z\\d\\-.]{0,61})+',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "MAC address",
|
name: 'MAC address',
|
||||||
value: "[A-Fa-f\\d]{2}(?:[:-][A-Fa-f\\d]{2}){5}"
|
value: '[A-Fa-f\\d]{2}(?:[:-][A-Fa-f\\d]{2}){5}',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Date (yyyy-mm-dd)",
|
name: 'Date (yyyy-mm-dd)',
|
||||||
value: "((?:19|20)\\d\\d)[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])"
|
value: '((?:19|20)\\d\\d)[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Date (dd/mm/yyyy)",
|
name: 'Date (dd/mm/yyyy)',
|
||||||
value: "(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.]((?:19|20)\\d\\d)"
|
value: '(0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.]((?:19|20)\\d\\d)',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Date (mm/dd/yyyy)",
|
name: 'Date (mm/dd/yyyy)',
|
||||||
value: "(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.]((?:19|20)\\d\\d)"
|
value: '(0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])[- /.]((?:19|20)\\d\\d)',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Strings",
|
name: 'Strings',
|
||||||
value: "[A-Za-z\\d/\\-:.,_$%\\x27\"()<>= !\\[\\]{}@]{4,}"
|
value: '[A-Za-z\\d/\\-:.,_$%\\x27"()<>= !\\[\\]{}@]{4,}',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
REGEX_CASE_INSENSITIVE: true,
|
REGEX_CASE_INSENSITIVE: true,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
REGEX_MULTILINE_MATCHING: true,
|
REGEX_MULTILINE_MATCHING: true,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
OUTPUT_FORMAT: ["Highlight matches", "List matches", "List capture groups", "List matches with capture groups"],
|
OUTPUT_FORMAT: ['Highlight matches', 'List matches', 'List capture groups', 'List matches with capture groups'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
DISPLAY_TOTAL: false,
|
DISPLAY_TOTAL: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Regular expression operation.
|
* Regular expression operation.
|
||||||
|
@ -97,47 +97,47 @@ var StrUtils = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {html}
|
* @returns {html}
|
||||||
*/
|
*/
|
||||||
run_regex: function(input, args) {
|
run_regex(input, args) {
|
||||||
var user_regex = args[1],
|
let user_regex = args[1],
|
||||||
i = args[2],
|
i = args[2],
|
||||||
m = args[3],
|
m = args[3],
|
||||||
display_total = args[4],
|
display_total = args[4],
|
||||||
output_format = args[5],
|
output_format = args[5],
|
||||||
modifiers = "g";
|
modifiers = 'g';
|
||||||
|
|
||||||
if (i) modifiers += "i";
|
if (i) modifiers += 'i';
|
||||||
if (m) modifiers += "m";
|
if (m) modifiers += 'm';
|
||||||
|
|
||||||
if (user_regex && user_regex != "^" && user_regex != "$") {
|
if (user_regex && user_regex != '^' && user_regex != '$') {
|
||||||
try {
|
try {
|
||||||
var regex = new RegExp(user_regex, modifiers);
|
const regex = new RegExp(user_regex, modifiers);
|
||||||
|
|
||||||
switch (output_format) {
|
switch (output_format) {
|
||||||
case "Highlight matches":
|
case 'Highlight matches':
|
||||||
return StrUtils._regex_highlight(input, regex, display_total);
|
return StrUtils._regex_highlight(input, regex, display_total);
|
||||||
case "List matches":
|
case 'List matches':
|
||||||
return Utils.escape_html(StrUtils._regex_list(input, regex, display_total, true, false));
|
return Utils.escape_html(StrUtils._regex_list(input, regex, display_total, true, false));
|
||||||
case "List capture groups":
|
case 'List capture groups':
|
||||||
return Utils.escape_html(StrUtils._regex_list(input, regex, display_total, false, true));
|
return Utils.escape_html(StrUtils._regex_list(input, regex, display_total, false, true));
|
||||||
case "List matches with capture groups":
|
case 'List matches with capture groups':
|
||||||
return Utils.escape_html(StrUtils._regex_list(input, regex, display_total, true, true));
|
return Utils.escape_html(StrUtils._regex_list(input, regex, display_total, true, true));
|
||||||
default:
|
default:
|
||||||
return "Error: Invalid output format";
|
return 'Error: Invalid output format';
|
||||||
}
|
|
||||||
} catch (err) {
|
|
||||||
return "Invalid regex. Details: " + err.message;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return Utils.escape_html(input);
|
|
||||||
}
|
}
|
||||||
},
|
} catch (err) {
|
||||||
|
return `Invalid regex. Details: ${err.message}`;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return Utils.escape_html(input);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
CASE_SCOPE: ["All", "Word", "Sentence", "Paragraph"],
|
CASE_SCOPE: ['All', 'Word', 'Sentence', 'Paragraph'],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To Upper case operation.
|
* To Upper case operation.
|
||||||
|
@ -146,28 +146,22 @@ var StrUtils = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_upper: function (input, args) {
|
run_upper(input, args) {
|
||||||
var scope = args[0];
|
const scope = args[0];
|
||||||
|
|
||||||
switch (scope) {
|
switch (scope) {
|
||||||
case "Word":
|
case 'Word':
|
||||||
return input.replace(/(\b\w)/gi, function(m) {
|
return input.replace(/(\b\w)/gi, m => m.toUpperCase());
|
||||||
return m.toUpperCase();
|
case 'Sentence':
|
||||||
});
|
return input.replace(/(?:\.|^)\s*(\b\w)/gi, m => m.toUpperCase());
|
||||||
case "Sentence":
|
case 'Paragraph':
|
||||||
return input.replace(/(?:\.|^)\s*(\b\w)/gi, function(m) {
|
return input.replace(/(?:\n|^)\s*(\b\w)/gi, m => m.toUpperCase());
|
||||||
return m.toUpperCase();
|
case 'All':
|
||||||
});
|
|
||||||
case "Paragraph":
|
|
||||||
return input.replace(/(?:\n|^)\s*(\b\w)/gi, function(m) {
|
|
||||||
return m.toUpperCase();
|
|
||||||
});
|
|
||||||
case "All":
|
|
||||||
/* falls through */
|
/* falls through */
|
||||||
default:
|
default:
|
||||||
return input.toUpperCase();
|
return input.toUpperCase();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -177,31 +171,31 @@ var StrUtils = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_lower: function (input, args) {
|
run_lower(input, args) {
|
||||||
return input.toLowerCase();
|
return input.toLowerCase();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
SEARCH_TYPE: ["Regex", "Extended (\\n, \\t, \\x...)", "Simple string"],
|
SEARCH_TYPE: ['Regex', 'Extended (\\n, \\t, \\x...)', 'Simple string'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
FIND_REPLACE_GLOBAL : true,
|
FIND_REPLACE_GLOBAL: true,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
FIND_REPLACE_CASE : false,
|
FIND_REPLACE_CASE: false,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
FIND_REPLACE_MULTILINE : true,
|
FIND_REPLACE_MULTILINE: true,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find / Replace operation.
|
* Find / Replace operation.
|
||||||
|
@ -210,42 +204,42 @@ var StrUtils = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_find_replace: function(input, args) {
|
run_find_replace(input, args) {
|
||||||
var find = args[0].string,
|
let find = args[0].string,
|
||||||
type = args[0].option,
|
type = args[0].option,
|
||||||
replace = args[1],
|
replace = args[1],
|
||||||
g = args[2],
|
g = args[2],
|
||||||
i = args[3],
|
i = args[3],
|
||||||
m = args[4],
|
m = args[4],
|
||||||
modifiers = "";
|
modifiers = '';
|
||||||
|
|
||||||
if (g) modifiers += "g";
|
if (g) modifiers += 'g';
|
||||||
if (i) modifiers += "i";
|
if (i) modifiers += 'i';
|
||||||
if (m) modifiers += "m";
|
if (m) modifiers += 'm';
|
||||||
|
|
||||||
if (type == "Regex") {
|
if (type == 'Regex') {
|
||||||
find = new RegExp(find, modifiers);
|
find = new RegExp(find, modifiers);
|
||||||
} else if (type.indexOf("Extended") === 0) {
|
} else if (type.indexOf('Extended') === 0) {
|
||||||
find = Utils.parse_escaped_chars(find);
|
find = Utils.parse_escaped_chars(find);
|
||||||
}
|
}
|
||||||
|
|
||||||
return input.replace(find, replace, modifiers);
|
return input.replace(find, replace, modifiers);
|
||||||
// Non-standard addition of flags in the third argument. This will work in Firefox but
|
// Non-standard addition of flags in the third argument. This will work in Firefox but
|
||||||
// probably nowhere else. The purpose is to allow global matching when the `find` parameter
|
// probably nowhere else. The purpose is to allow global matching when the `find` parameter
|
||||||
// is just a string.
|
// is just a string.
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
SPLIT_DELIM: ",",
|
SPLIT_DELIM: ',',
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
DELIMITER_OPTIONS: ["Line feed", "CRLF", "Space", "Comma", "Semi-colon", "Colon", "Nothing (separate chars)"],
|
DELIMITER_OPTIONS: ['Line feed', 'CRLF', 'Space', 'Comma', 'Semi-colon', 'Colon', 'Nothing (separate chars)'],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Split operation.
|
* Split operation.
|
||||||
|
@ -254,25 +248,25 @@ var StrUtils = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_split: function(input, args) {
|
run_split(input, args) {
|
||||||
var split_delim = args[0] || StrUtils.SPLIT_DELIM,
|
let split_delim = args[0] || StrUtils.SPLIT_DELIM,
|
||||||
join_delim = Utils.char_rep[args[1]],
|
join_delim = Utils.char_rep[args[1]],
|
||||||
sections = input.split(split_delim);
|
sections = input.split(split_delim);
|
||||||
|
|
||||||
return sections.join(join_delim);
|
return sections.join(join_delim);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
DIFF_SAMPLE_DELIMITER: "\\n\\n",
|
DIFF_SAMPLE_DELIMITER: '\\n\\n',
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
DIFF_BY: ["Character", "Word", "Line", "Sentence", "CSS", "JSON"],
|
DIFF_BY: ['Character', 'Word', 'Line', 'Sentence', 'CSS', 'JSON'],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Diff operation.
|
* Diff operation.
|
||||||
|
@ -281,70 +275,70 @@ var StrUtils = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {html}
|
* @returns {html}
|
||||||
*/
|
*/
|
||||||
run_diff: function(input, args) {
|
run_diff(input, args) {
|
||||||
var sample_delim = args[0],
|
let sample_delim = args[0],
|
||||||
diff_by = args[1],
|
diff_by = args[1],
|
||||||
show_added = args[2],
|
show_added = args[2],
|
||||||
show_removed = args[3],
|
show_removed = args[3],
|
||||||
ignore_whitespace = args[4],
|
ignore_whitespace = args[4],
|
||||||
samples = input.split(sample_delim),
|
samples = input.split(sample_delim),
|
||||||
output = "",
|
output = '',
|
||||||
diff;
|
diff;
|
||||||
|
|
||||||
if (!samples || samples.length != 2) {
|
if (!samples || samples.length != 2) {
|
||||||
return "Incorrect number of samples, perhaps you need to modify the sample delimiter or add more samples?";
|
return 'Incorrect number of samples, perhaps you need to modify the sample delimiter or add more samples?';
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (diff_by) {
|
||||||
|
case 'Character':
|
||||||
|
diff = JsDiff.diffChars(samples[0], samples[1]);
|
||||||
|
break;
|
||||||
|
case 'Word':
|
||||||
|
if (ignore_whitespace) {
|
||||||
|
diff = JsDiff.diffWords(samples[0], samples[1]);
|
||||||
|
} else {
|
||||||
|
diff = JsDiff.diffWordsWithSpace(samples[0], samples[1]);
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
switch (diff_by) {
|
case 'Line':
|
||||||
case "Character":
|
if (ignore_whitespace) {
|
||||||
diff = JsDiff.diffChars(samples[0], samples[1]);
|
diff = JsDiff.diffTrimmedLines(samples[0], samples[1]);
|
||||||
break;
|
} else {
|
||||||
case "Word":
|
diff = JsDiff.diffLines(samples[0], samples[1]);
|
||||||
if (ignore_whitespace) {
|
|
||||||
diff = JsDiff.diffWords(samples[0], samples[1]);
|
|
||||||
} else {
|
|
||||||
diff = JsDiff.diffWordsWithSpace(samples[0], samples[1]);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "Line":
|
|
||||||
if (ignore_whitespace) {
|
|
||||||
diff = JsDiff.diffTrimmedLines(samples[0], samples[1]);
|
|
||||||
} else {
|
|
||||||
diff = JsDiff.diffLines(samples[0], samples[1]);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "Sentence":
|
|
||||||
diff = JsDiff.diffSentences(samples[0], samples[1]);
|
|
||||||
break;
|
|
||||||
case "CSS":
|
|
||||||
diff = JsDiff.diffCss(samples[0], samples[1]);
|
|
||||||
break;
|
|
||||||
case "JSON":
|
|
||||||
diff = JsDiff.diffJson(samples[0], samples[1]);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
return "Invalid 'Diff by' option.";
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case 'Sentence':
|
||||||
|
diff = JsDiff.diffSentences(samples[0], samples[1]);
|
||||||
|
break;
|
||||||
|
case 'CSS':
|
||||||
|
diff = JsDiff.diffCss(samples[0], samples[1]);
|
||||||
|
break;
|
||||||
|
case 'JSON':
|
||||||
|
diff = JsDiff.diffJson(samples[0], samples[1]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return "Invalid 'Diff by' option.";
|
||||||
|
}
|
||||||
|
|
||||||
for (var i = 0; i < diff.length; i++) {
|
for (let i = 0; i < diff.length; i++) {
|
||||||
if (diff[i].added) {
|
if (diff[i].added) {
|
||||||
if (show_added) output += "<span class='hlgreen'>" + Utils.escape_html(diff[i].value) + "</span>";
|
if (show_added) output += `<span class='hlgreen'>${Utils.escape_html(diff[i].value)}</span>`;
|
||||||
} else if (diff[i].removed) {
|
} else if (diff[i].removed) {
|
||||||
if (show_removed) output += "<span class='hlred'>" + Utils.escape_html(diff[i].value) + "</span>";
|
if (show_removed) output += `<span class='hlred'>${Utils.escape_html(diff[i].value)}</span>`;
|
||||||
} else {
|
} else {
|
||||||
output += Utils.escape_html(diff[i].value);
|
output += Utils.escape_html(diff[i].value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
OFF_CHK_SAMPLE_DELIMITER: "\\n\\n",
|
OFF_CHK_SAMPLE_DELIMITER: '\\n\\n',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Offset checker operation.
|
* Offset checker operation.
|
||||||
|
@ -353,71 +347,71 @@ var StrUtils = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {html}
|
* @returns {html}
|
||||||
*/
|
*/
|
||||||
run_offset_checker: function(input, args) {
|
run_offset_checker(input, args) {
|
||||||
var sample_delim = args[0],
|
let sample_delim = args[0],
|
||||||
samples = input.split(sample_delim),
|
samples = input.split(sample_delim),
|
||||||
outputs = [],
|
outputs = [],
|
||||||
i = 0,
|
i = 0,
|
||||||
s = 0,
|
s = 0,
|
||||||
match = false,
|
match = false,
|
||||||
in_match = false,
|
in_match = false,
|
||||||
chr;
|
chr;
|
||||||
|
|
||||||
if (!samples || samples.length < 2) {
|
if (!samples || samples.length < 2) {
|
||||||
return "Not enough samples, perhaps you need to modify the sample delimiter or add more data?";
|
return 'Not enough samples, perhaps you need to modify the sample delimiter or add more data?';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialise output strings
|
// Initialise output strings
|
||||||
for (s = 0; s < samples.length; s++) {
|
for (s = 0; s < samples.length; s++) {
|
||||||
outputs[s] = "";
|
outputs[s] = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loop through each character in the first sample
|
// Loop through each character in the first sample
|
||||||
for (i = 0; i < samples[0].length; i++) {
|
for (i = 0; i < samples[0].length; i++) {
|
||||||
chr = samples[0][i];
|
chr = samples[0][i];
|
||||||
match = false;
|
match = false;
|
||||||
|
|
||||||
// Loop through each sample to see if the chars are the same
|
// Loop through each sample to see if the chars are the same
|
||||||
for (s = 1; s < samples.length; s++) {
|
for (s = 1; s < samples.length; s++) {
|
||||||
if (samples[s][i] != chr) {
|
if (samples[s][i] != chr) {
|
||||||
match = false;
|
match = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
match = true;
|
match = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write output for each sample
|
// Write output for each sample
|
||||||
for (s = 0; s < samples.length; s++) {
|
for (s = 0; s < samples.length; s++) {
|
||||||
if (samples[s].length <= i) {
|
if (samples[s].length <= i) {
|
||||||
if (in_match) outputs[s] += "</span>";
|
if (in_match) outputs[s] += '</span>';
|
||||||
if (s == samples.length - 1) in_match = false;
|
if (s == samples.length - 1) in_match = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
if (match && !in_match) {
|
|
||||||
outputs[s] += "<span class='hlgreen'>" + Utils.escape_html(samples[s][i]);
|
|
||||||
if (samples[s].length == i + 1) outputs[s] += "</span>";
|
|
||||||
if (s == samples.length - 1) in_match = true;
|
|
||||||
} else if (!match && in_match) {
|
|
||||||
outputs[s] += "</span>" + Utils.escape_html(samples[s][i]);
|
|
||||||
if (s == samples.length - 1) in_match = false;
|
|
||||||
} else {
|
|
||||||
outputs[s] += Utils.escape_html(samples[s][i]);
|
|
||||||
if (in_match && samples[s].length == i + 1) {
|
|
||||||
outputs[s] += "</span>";
|
|
||||||
if (samples[s].length - 1 != i) in_match = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (samples[0].length - 1 == i) {
|
|
||||||
if (in_match) outputs[s] += "</span>";
|
|
||||||
outputs[s] += Utils.escape_html(samples[s].substring(i + 1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return outputs.join(sample_delim);
|
if (match && !in_match) {
|
||||||
},
|
outputs[s] += `<span class='hlgreen'>${Utils.escape_html(samples[s][i])}`;
|
||||||
|
if (samples[s].length == i + 1) outputs[s] += '</span>';
|
||||||
|
if (s == samples.length - 1) in_match = true;
|
||||||
|
} else if (!match && in_match) {
|
||||||
|
outputs[s] += `</span>${Utils.escape_html(samples[s][i])}`;
|
||||||
|
if (s == samples.length - 1) in_match = false;
|
||||||
|
} else {
|
||||||
|
outputs[s] += Utils.escape_html(samples[s][i]);
|
||||||
|
if (in_match && samples[s].length == i + 1) {
|
||||||
|
outputs[s] += '</span>';
|
||||||
|
if (samples[s].length - 1 != i) in_match = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (samples[0].length - 1 == i) {
|
||||||
|
if (in_match) outputs[s] += '</span>';
|
||||||
|
outputs[s] += Utils.escape_html(samples[s].substring(i + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return outputs.join(sample_delim);
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -427,9 +421,9 @@ var StrUtils = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_parse_escaped_string: function(input, args) {
|
run_parse_escaped_string(input, args) {
|
||||||
return Utils.parse_escaped_chars(input);
|
return Utils.parse_escaped_chars(input);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -441,35 +435,34 @@ var StrUtils = {
|
||||||
* @param {boolean} display_total
|
* @param {boolean} display_total
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
_regex_highlight: function(input, regex, display_total) {
|
_regex_highlight(input, regex, display_total) {
|
||||||
var output = "",
|
let output = '',
|
||||||
m,
|
m,
|
||||||
hl = 1,
|
hl = 1,
|
||||||
i = 0,
|
i = 0,
|
||||||
total = 0;
|
total = 0;
|
||||||
|
|
||||||
while (!!(m = regex.exec(input))) {
|
while (m = regex.exec(input)) {
|
||||||
// Add up to match
|
// Add up to match
|
||||||
output += Utils.escape_html(input.slice(i, m.index));
|
output += Utils.escape_html(input.slice(i, m.index));
|
||||||
|
|
||||||
// Add match with highlighting
|
// Add match with highlighting
|
||||||
output += "<span class='hl"+hl+"'>" + Utils.escape_html(m[0]) + "</span>";
|
output += `<span class='hl${hl}'>${Utils.escape_html(m[0])}</span>`;
|
||||||
|
|
||||||
// Switch highlight
|
// Switch highlight
|
||||||
hl = hl == 1 ? 2 : 1;
|
hl = hl == 1 ? 2 : 1;
|
||||||
|
|
||||||
i = regex.lastIndex;
|
i = regex.lastIndex;
|
||||||
total++;
|
total++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add all after final match
|
// Add all after final match
|
||||||
output += Utils.escape_html(input.slice(i, input.length));
|
output += Utils.escape_html(input.slice(i, input.length));
|
||||||
|
|
||||||
if (display_total)
|
if (display_total) { output = `Total found: ${total}\n\n${output}`; }
|
||||||
output = "Total found: " + total + "\n\n" + output;
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -483,30 +476,29 @@ var StrUtils = {
|
||||||
* @param {boolean} capture_groups - Display each of the capture groups separately
|
* @param {boolean} capture_groups - Display each of the capture groups separately
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
_regex_list: function(input, regex, display_total, matches, capture_groups) {
|
_regex_list(input, regex, display_total, matches, capture_groups) {
|
||||||
var output = "",
|
let output = '',
|
||||||
total = 0,
|
total = 0,
|
||||||
match;
|
match;
|
||||||
|
|
||||||
while (!!(match = regex.exec(input))) {
|
while (match = regex.exec(input)) {
|
||||||
total++;
|
total++;
|
||||||
if (matches) {
|
if (matches) {
|
||||||
output += match[0] + "\n";
|
output += `${match[0]}\n`;
|
||||||
}
|
}
|
||||||
if (capture_groups) {
|
if (capture_groups) {
|
||||||
for (var i = 1; i < match.length; i++) {
|
for (let i = 1; i < match.length; i++) {
|
||||||
if (matches) {
|
if (matches) {
|
||||||
output += " Group " + i + ": ";
|
output += ` Group ${i}: `;
|
||||||
}
|
}
|
||||||
output += match[i] + "\n";
|
output += `${match[i]}\n`;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (display_total)
|
if (display_total) { output = `Total found: ${total}\n\n${output}`; }
|
||||||
output = "Total found: " + total + "\n\n" + output;
|
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,38 +7,38 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var Tidy = {
|
const Tidy = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
REMOVE_SPACES : true,
|
REMOVE_SPACES: true,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
REMOVE_CARIAGE_RETURNS : true,
|
REMOVE_CARIAGE_RETURNS: true,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
REMOVE_LINE_FEEDS : true,
|
REMOVE_LINE_FEEDS: true,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
REMOVE_TABS : true,
|
REMOVE_TABS: true,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
REMOVE_FORM_FEEDS : true,
|
REMOVE_FORM_FEEDS: true,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
REMOVE_FULL_STOPS : false,
|
REMOVE_FULL_STOPS: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove whitespace operation.
|
* Remove whitespace operation.
|
||||||
|
@ -47,23 +47,23 @@ var Tidy = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_remove_whitespace: function (input, args) {
|
run_remove_whitespace(input, args) {
|
||||||
var remove_spaces = args[0],
|
let remove_spaces = args[0],
|
||||||
remove_cariage_returns = args[1],
|
remove_cariage_returns = args[1],
|
||||||
remove_line_feeds = args[2],
|
remove_line_feeds = args[2],
|
||||||
remove_tabs = args[3],
|
remove_tabs = args[3],
|
||||||
remove_form_feeds = args[4],
|
remove_form_feeds = args[4],
|
||||||
remove_full_stops = args[5],
|
remove_full_stops = args[5],
|
||||||
data = input;
|
data = input;
|
||||||
|
|
||||||
if (remove_spaces) data = data.replace(/ /g, "");
|
if (remove_spaces) data = data.replace(/ /g, '');
|
||||||
if (remove_cariage_returns) data = data.replace(/\r/g, "");
|
if (remove_cariage_returns) data = data.replace(/\r/g, '');
|
||||||
if (remove_line_feeds) data = data.replace(/\n/g, "");
|
if (remove_line_feeds) data = data.replace(/\n/g, '');
|
||||||
if (remove_tabs) data = data.replace(/\t/g, "");
|
if (remove_tabs) data = data.replace(/\t/g, '');
|
||||||
if (remove_form_feeds) data = data.replace(/\f/g, "");
|
if (remove_form_feeds) data = data.replace(/\f/g, '');
|
||||||
if (remove_full_stops) data = data.replace(/\./g, "");
|
if (remove_full_stops) data = data.replace(/\./g, '');
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,30 +73,30 @@ var Tidy = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_remove_nulls: function (input, args) {
|
run_remove_nulls(input, args) {
|
||||||
var output = [];
|
const output = [];
|
||||||
for (var i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
if (input[i] !== 0) output.push(input[i]);
|
if (input[i] !== 0) output.push(input[i]);
|
||||||
}
|
}
|
||||||
return output;
|
return output;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
APPLY_TO_EACH_LINE : false,
|
APPLY_TO_EACH_LINE: false,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
DROP_START : 0,
|
DROP_START: 0,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
DROP_LENGTH : 5,
|
DROP_LENGTH: 5,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Drop bytes operation.
|
* Drop bytes operation.
|
||||||
|
@ -105,50 +105,52 @@ var Tidy = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_drop_bytes: function(input, args) {
|
run_drop_bytes(input, args) {
|
||||||
var start = args[0],
|
let start = args[0],
|
||||||
length = args[1],
|
length = args[1],
|
||||||
apply_to_each_line = args[2];
|
apply_to_each_line = args[2];
|
||||||
|
|
||||||
if (start < 0 || length < 0)
|
if (start < 0 || length < 0) {
|
||||||
throw "Error: Invalid value";
|
throw 'Error: Invalid value';
|
||||||
|
}
|
||||||
|
|
||||||
if (!apply_to_each_line)
|
if (!apply_to_each_line) {
|
||||||
return input.slice(0, start).concat(input.slice(start+length, input.length));
|
return input.slice(0, start).concat(input.slice(start + length, input.length));
|
||||||
|
}
|
||||||
|
|
||||||
// Split input into lines
|
// Split input into lines
|
||||||
var lines = [],
|
let lines = [],
|
||||||
line = [];
|
line = [];
|
||||||
|
|
||||||
for (var i = 0; i < input.length; i++) {
|
for (var i = 0; i < input.length; i++) {
|
||||||
if (input[i] == 0x0a) {
|
if (input[i] == 0x0a) {
|
||||||
lines.push(line);
|
|
||||||
line = [];
|
|
||||||
} else {
|
|
||||||
line.push(input[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
lines.push(line);
|
lines.push(line);
|
||||||
|
line = [];
|
||||||
|
} else {
|
||||||
|
line.push(input[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lines.push(line);
|
||||||
|
|
||||||
var output = [];
|
let output = [];
|
||||||
for (i = 0; i < lines.length; i++) {
|
for (i = 0; i < lines.length; i++) {
|
||||||
output = output.concat(lines[i].slice(0, start).concat(lines[i].slice(start+length, lines[i].length)));
|
output = output.concat(lines[i].slice(0, start).concat(lines[i].slice(start + length, lines[i].length)));
|
||||||
output.push(0x0a);
|
output.push(0x0a);
|
||||||
}
|
}
|
||||||
return output.slice(0, output.length-1);
|
return output.slice(0, output.length - 1);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
TAKE_START: 0,
|
TAKE_START: 0,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
TAKE_LENGTH: 5,
|
TAKE_LENGTH: 5,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Take bytes operation.
|
* Take bytes operation.
|
||||||
|
@ -157,55 +159,57 @@ var Tidy = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {byte_array}
|
* @returns {byte_array}
|
||||||
*/
|
*/
|
||||||
run_take_bytes: function(input, args) {
|
run_take_bytes(input, args) {
|
||||||
var start = args[0],
|
let start = args[0],
|
||||||
length = args[1],
|
length = args[1],
|
||||||
apply_to_each_line = args[2];
|
apply_to_each_line = args[2];
|
||||||
|
|
||||||
if (start < 0 || length < 0)
|
if (start < 0 || length < 0) {
|
||||||
throw "Error: Invalid value";
|
throw 'Error: Invalid value';
|
||||||
|
}
|
||||||
|
|
||||||
if (!apply_to_each_line)
|
if (!apply_to_each_line) {
|
||||||
return input.slice(start, start+length);
|
return input.slice(start, start + length);
|
||||||
|
}
|
||||||
|
|
||||||
// Split input into lines
|
// Split input into lines
|
||||||
var lines = [],
|
let lines = [],
|
||||||
line = [];
|
line = [];
|
||||||
|
|
||||||
for (var i = 0; i < input.length; i++) {
|
for (var i = 0; i < input.length; i++) {
|
||||||
if (input[i] == 0x0a) {
|
if (input[i] == 0x0a) {
|
||||||
lines.push(line);
|
|
||||||
line = [];
|
|
||||||
} else {
|
|
||||||
line.push(input[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
lines.push(line);
|
lines.push(line);
|
||||||
|
line = [];
|
||||||
|
} else {
|
||||||
|
line.push(input[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lines.push(line);
|
||||||
|
|
||||||
var output = [];
|
let output = [];
|
||||||
for (i = 0; i < lines.length; i++) {
|
for (i = 0; i < lines.length; i++) {
|
||||||
output = output.concat(lines[i].slice(start, start+length));
|
output = output.concat(lines[i].slice(start, start + length));
|
||||||
output.push(0x0a);
|
output.push(0x0a);
|
||||||
}
|
}
|
||||||
return output.slice(0, output.length-1);
|
return output.slice(0, output.length - 1);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
PAD_POSITION : ["Start", "End"],
|
PAD_POSITION: ['Start', 'End'],
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
PAD_LENGTH : 5,
|
PAD_LENGTH: 5,
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
PAD_CHAR : " ",
|
PAD_CHAR: ' ',
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pad lines operation.
|
* Pad lines operation.
|
||||||
|
@ -214,25 +218,25 @@ var Tidy = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_pad: function(input, args) {
|
run_pad(input, args) {
|
||||||
var position = args[0],
|
let position = args[0],
|
||||||
len = args[1],
|
len = args[1],
|
||||||
chr = args[2],
|
chr = args[2],
|
||||||
lines = input.split("\n"),
|
lines = input.split('\n'),
|
||||||
output = "",
|
output = '',
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
if (position == "Start") {
|
if (position == 'Start') {
|
||||||
for (i = 0; i < lines.length; i++) {
|
for (i = 0; i < lines.length; i++) {
|
||||||
output += Utils.pad_left(lines[i], lines[i].length+len, chr) + "\n";
|
output += `${Utils.pad_left(lines[i], lines[i].length + len, chr)}\n`;
|
||||||
}
|
}
|
||||||
} else if (position == "End") {
|
} else if (position == 'End') {
|
||||||
for (i = 0; i < lines.length; i++) {
|
for (i = 0; i < lines.length; i++) {
|
||||||
output += Utils.pad_right(lines[i], lines[i].length+len, chr) + "\n";
|
output += `${Utils.pad_right(lines[i], lines[i].length + len, chr)}\n`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return output.slice(0, output.length-1);
|
return output.slice(0, output.length - 1);
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,13 +10,13 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var URL_ = {
|
const URL_ = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
ENCODE_ALL: false,
|
ENCODE_ALL: false,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL Encode operation.
|
* URL Encode operation.
|
||||||
|
@ -25,10 +25,10 @@ var URL_ = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_to: function(input, args) {
|
run_to(input, args) {
|
||||||
var encode_all = args[0];
|
const encode_all = args[0];
|
||||||
return encode_all ? URL_._encode_all_chars(input) : encodeURI(input);
|
return encode_all ? URL_._encode_all_chars(input) : encodeURI(input);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -38,14 +38,14 @@ var URL_ = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_from: function(input, args) {
|
run_from(input, args) {
|
||||||
var data = input.replace(/\+/g, "%20");
|
const data = input.replace(/\+/g, '%20');
|
||||||
try {
|
try {
|
||||||
return decodeURIComponent(data);
|
return decodeURIComponent(data);
|
||||||
} catch(err) {
|
} catch (err) {
|
||||||
return unescape(data);
|
return unescape(data);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,54 +55,57 @@ var URL_ = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_parse: function(input, args) {
|
run_parse(input, args) {
|
||||||
var a = document.createElement("a");
|
const a = document.createElement('a');
|
||||||
|
|
||||||
// Overwrite base href which will be the current CyberChef URL to reduce confusion.
|
// Overwrite base href which will be the current CyberChef URL to reduce confusion.
|
||||||
a.href = "http://example.com/";
|
a.href = 'http://example.com/';
|
||||||
a.href = input;
|
a.href = input;
|
||||||
|
|
||||||
if (a.protocol) {
|
if (a.protocol) {
|
||||||
var output = "";
|
let output = '';
|
||||||
if (a.hostname != window.location.hostname) {
|
if (a.hostname != window.location.hostname) {
|
||||||
output = "Protocol:\t" + a.protocol + "\n";
|
output = `Protocol:\t${a.protocol}\n`;
|
||||||
if (a.hostname) output += "Hostname:\t" + a.hostname + "\n";
|
if (a.hostname) output += `Hostname:\t${a.hostname}\n`;
|
||||||
if (a.port) output += "Port:\t\t" + a.port + "\n";
|
if (a.port) output += `Port:\t\t${a.port}\n`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (a.pathname) {
|
if (a.pathname) {
|
||||||
var pathname = a.pathname;
|
let pathname = a.pathname;
|
||||||
if (pathname.indexOf(window.location.pathname) === 0)
|
if (pathname.indexOf(window.location.pathname) === 0) {
|
||||||
pathname = pathname.replace(window.location.pathname, "");
|
pathname = pathname.replace(window.location.pathname, '');
|
||||||
if (pathname)
|
|
||||||
output += "Path name:\t" + pathname + "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (a.hash) {
|
|
||||||
output += "Hash:\t\t" + a.hash + "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (a.search) {
|
|
||||||
output += "Arguments:\n";
|
|
||||||
var args_ = (a.search.slice(1, a.search.length)).split("&");
|
|
||||||
var split_args = [], padding = 0;
|
|
||||||
for (var i = 0; i < args_.length; i++) {
|
|
||||||
split_args.push(args_[i].split("="));
|
|
||||||
padding = (split_args[i][0].length > padding) ? split_args[i][0].length : padding;
|
|
||||||
}
|
|
||||||
for (i = 0; i < split_args.length; i++) {
|
|
||||||
output += "\t" + Utils.pad_right(split_args[i][0], padding);
|
|
||||||
if (split_args[i].length > 1 && split_args[i][1].length)
|
|
||||||
output += " = " + split_args[i][1] + "\n";
|
|
||||||
else output += "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
}
|
||||||
|
if (pathname) {
|
||||||
|
output += `Path name:\t${pathname}\n`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return "Invalid URI";
|
if (a.hash) {
|
||||||
},
|
output += `Hash:\t\t${a.hash}\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a.search) {
|
||||||
|
output += 'Arguments:\n';
|
||||||
|
const args_ = (a.search.slice(1, a.search.length)).split('&');
|
||||||
|
let split_args = [],
|
||||||
|
padding = 0;
|
||||||
|
for (var i = 0; i < args_.length; i++) {
|
||||||
|
split_args.push(args_[i].split('='));
|
||||||
|
padding = (split_args[i][0].length > padding) ? split_args[i][0].length : padding;
|
||||||
|
}
|
||||||
|
for (i = 0; i < split_args.length; i++) {
|
||||||
|
output += `\t${Utils.pad_right(split_args[i][0], padding)}`;
|
||||||
|
if (split_args[i].length > 1 && split_args[i][1].length) {
|
||||||
|
output += ` = ${split_args[i][1]}\n`;
|
||||||
|
} else output += '\n';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 'Invalid URI';
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,19 +115,19 @@ var URL_ = {
|
||||||
* @param {string} str
|
* @param {string} str
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
_encode_all_chars: function(str) {
|
_encode_all_chars(str) {
|
||||||
//TODO Do this programatically
|
// TODO Do this programatically
|
||||||
return encodeURIComponent(str)
|
return encodeURIComponent(str)
|
||||||
.replace(/!/g, "%21")
|
.replace(/!/g, '%21')
|
||||||
.replace(/#/g, "%23")
|
.replace(/#/g, '%23')
|
||||||
.replace(/'/g, "%27")
|
.replace(/'/g, '%27')
|
||||||
.replace(/\(/g, "%28")
|
.replace(/\(/g, '%28')
|
||||||
.replace(/\)/g, "%29")
|
.replace(/\)/g, '%29')
|
||||||
.replace(/\*/g, "%2A")
|
.replace(/\*/g, '%2A')
|
||||||
.replace(/\-/g, "%2D")
|
.replace(/\-/g, '%2D')
|
||||||
.replace(/\./g, "%2E")
|
.replace(/\./g, '%2E')
|
||||||
.replace(/_/g, "%5F")
|
.replace(/_/g, '%5F')
|
||||||
.replace(/~/g, "%7E");
|
.replace(/~/g, '%7E');
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var UUID = {
|
const UUID = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate UUID operation.
|
* Generate UUID operation.
|
||||||
|
@ -16,24 +16,24 @@ var UUID = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_generate_v4: function(input, args) {
|
run_generate_v4(input, args) {
|
||||||
if (typeof(window.crypto) !== 'undefined' && typeof(window.crypto.getRandomValues) !== 'undefined') {
|
if (typeof (window.crypto) !== 'undefined' && typeof (window.crypto.getRandomValues) !== 'undefined') {
|
||||||
var buf = new Uint32Array(4),
|
let buf = new Uint32Array(4),
|
||||||
i = 0;
|
i = 0;
|
||||||
window.crypto.getRandomValues(buf);
|
window.crypto.getRandomValues(buf);
|
||||||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
||||||
var r = (buf[i >> 3] >> ((i % 8) * 4)) & 0xf,
|
let r = (buf[i >> 3] >> ((i % 8) * 4)) & 0xf,
|
||||||
v = c === "x" ? r : (r & 0x3 | 0x8);
|
v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||||
i++;
|
i++;
|
||||||
return v.toString(16);
|
return v.toString(16);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
||||||
var r = Math.random() * 16 | 0,
|
let r = Math.random() * 16 | 0,
|
||||||
v = c === "x" ? r : (r & 0x3 | 0x8);
|
v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||||
return v.toString(16);
|
return v.toString(16);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,13 +7,13 @@
|
||||||
*
|
*
|
||||||
* @namespace
|
* @namespace
|
||||||
*/
|
*/
|
||||||
var Unicode = {
|
const Unicode = {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
* @default
|
* @default
|
||||||
*/
|
*/
|
||||||
PREFIXES: ["\\u", "%u", "U+"],
|
PREFIXES: ['\\u', '%u', 'U+'],
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Unescape Unicode Characters operation.
|
* Unescape Unicode Characters operation.
|
||||||
|
@ -22,29 +22,29 @@ var Unicode = {
|
||||||
* @param {Object[]} args
|
* @param {Object[]} args
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run_unescape: function(input, args) {
|
run_unescape(input, args) {
|
||||||
var prefix = Unicode._prefix_to_regex[args[0]],
|
let prefix = Unicode._prefix_to_regex[args[0]],
|
||||||
regex = new RegExp(prefix+"([a-f\\d]{4,6})", "ig"),
|
regex = new RegExp(`${prefix}([a-f\\d]{4,6})`, 'ig'),
|
||||||
output = "",
|
output = '',
|
||||||
m,
|
m,
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
while (!!(m = regex.exec(input))) {
|
while (m = regex.exec(input)) {
|
||||||
// Add up to match
|
// Add up to match
|
||||||
output += input.slice(i, m.index);
|
output += input.slice(i, m.index);
|
||||||
i = m.index;
|
i = m.index;
|
||||||
|
|
||||||
// Add match
|
// Add match
|
||||||
output += Utils.chr(parseInt(m[1], 16));
|
output += Utils.chr(parseInt(m[1], 16));
|
||||||
|
|
||||||
i = regex.lastIndex;
|
i = regex.lastIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add all after final match
|
// Add all after final match
|
||||||
output += input.slice(i, input.length);
|
output += input.slice(i, input.length);
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,10 +53,10 @@ var Unicode = {
|
||||||
* @private
|
* @private
|
||||||
* @constant
|
* @constant
|
||||||
*/
|
*/
|
||||||
_prefix_to_regex: {
|
_prefix_to_regex: {
|
||||||
"\\u": "\\\\u",
|
'\\u': '\\\\u',
|
||||||
"%u": "%u",
|
'%u': '%u',
|
||||||
"U+": "U\\+"
|
'U+': 'U\\+',
|
||||||
},
|
},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,9 +9,9 @@
|
||||||
* @param {HTMLApp} app - The main view object for CyberChef.
|
* @param {HTMLApp} app - The main view object for CyberChef.
|
||||||
* @param {Manager} manager - The CyberChef event manager.
|
* @param {Manager} manager - The CyberChef event manager.
|
||||||
*/
|
*/
|
||||||
var ControlsWaiter = function(app, manager) {
|
const ControlsWaiter = function (app, manager) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -19,41 +19,41 @@ var ControlsWaiter = function(app, manager) {
|
||||||
* Adjusts the display properties of the control buttons so that they fit within the current width
|
* Adjusts the display properties of the control buttons so that they fit within the current width
|
||||||
* without wrapping or overflowing.
|
* without wrapping or overflowing.
|
||||||
*/
|
*/
|
||||||
ControlsWaiter.prototype.adjust_width = function() {
|
ControlsWaiter.prototype.adjust_width = function () {
|
||||||
var controls = document.getElementById("controls"),
|
let controls = document.getElementById('controls'),
|
||||||
step = document.getElementById("step"),
|
step = document.getElementById('step'),
|
||||||
clr_breaks = document.getElementById("clr-breaks"),
|
clr_breaks = document.getElementById('clr-breaks'),
|
||||||
save_img = document.querySelector("#save img"),
|
save_img = document.querySelector('#save img'),
|
||||||
load_img = document.querySelector("#load img"),
|
load_img = document.querySelector('#load img'),
|
||||||
step_img = document.querySelector("#step img"),
|
step_img = document.querySelector('#step img'),
|
||||||
clr_recip_img = document.querySelector("#clr-recipe img"),
|
clr_recip_img = document.querySelector('#clr-recipe img'),
|
||||||
clr_breaks_img = document.querySelector("#clr-breaks img");
|
clr_breaks_img = document.querySelector('#clr-breaks img');
|
||||||
|
|
||||||
if (controls.clientWidth < 470) {
|
if (controls.clientWidth < 470) {
|
||||||
step.childNodes[1].nodeValue = " Step";
|
step.childNodes[1].nodeValue = ' Step';
|
||||||
} else {
|
} else {
|
||||||
step.childNodes[1].nodeValue = " Step through";
|
step.childNodes[1].nodeValue = ' Step through';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (controls.clientWidth < 400) {
|
if (controls.clientWidth < 400) {
|
||||||
save_img.style.display = "none";
|
save_img.style.display = 'none';
|
||||||
load_img.style.display = "none";
|
load_img.style.display = 'none';
|
||||||
step_img.style.display = "none";
|
step_img.style.display = 'none';
|
||||||
clr_recip_img.style.display = "none";
|
clr_recip_img.style.display = 'none';
|
||||||
clr_breaks_img.style.display = "none";
|
clr_breaks_img.style.display = 'none';
|
||||||
} else {
|
} else {
|
||||||
save_img.style.display = "inline";
|
save_img.style.display = 'inline';
|
||||||
load_img.style.display = "inline";
|
load_img.style.display = 'inline';
|
||||||
step_img.style.display = "inline";
|
step_img.style.display = 'inline';
|
||||||
clr_recip_img.style.display = "inline";
|
clr_recip_img.style.display = 'inline';
|
||||||
clr_breaks_img.style.display = "inline";
|
clr_breaks_img.style.display = 'inline';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (controls.clientWidth < 330) {
|
if (controls.clientWidth < 330) {
|
||||||
clr_breaks.childNodes[1].nodeValue = " Clear breaks";
|
clr_breaks.childNodes[1].nodeValue = ' Clear breaks';
|
||||||
} else {
|
} else {
|
||||||
clr_breaks.childNodes[1].nodeValue = " Clear breakpoints";
|
clr_breaks.childNodes[1].nodeValue = ' Clear breakpoints';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,57 +62,57 @@ ControlsWaiter.prototype.adjust_width = function() {
|
||||||
*
|
*
|
||||||
* @param {boolean} value - The new value for Auto Bake.
|
* @param {boolean} value - The new value for Auto Bake.
|
||||||
*/
|
*/
|
||||||
ControlsWaiter.prototype.set_auto_bake = function(value) {
|
ControlsWaiter.prototype.set_auto_bake = function (value) {
|
||||||
var auto_bake_checkbox = document.getElementById("auto-bake");
|
const auto_bake_checkbox = document.getElementById('auto-bake');
|
||||||
|
|
||||||
if (auto_bake_checkbox.checked != value) {
|
if (auto_bake_checkbox.checked != value) {
|
||||||
auto_bake_checkbox.click();
|
auto_bake_checkbox.click();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler to trigger baking.
|
* Handler to trigger baking.
|
||||||
*/
|
*/
|
||||||
ControlsWaiter.prototype.bake_click = function() {
|
ControlsWaiter.prototype.bake_click = function () {
|
||||||
this.app.bake();
|
this.app.bake();
|
||||||
$("#output-text").selectRange(0);
|
$('#output-text').selectRange(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for the 'Step through' command. Executes the next step of the recipe.
|
* Handler for the 'Step through' command. Executes the next step of the recipe.
|
||||||
*/
|
*/
|
||||||
ControlsWaiter.prototype.step_click = function() {
|
ControlsWaiter.prototype.step_click = function () {
|
||||||
this.app.bake(true);
|
this.app.bake(true);
|
||||||
$("#output-text").selectRange(0);
|
$('#output-text').selectRange(0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for changes made to the Auto Bake checkbox.
|
* Handler for changes made to the Auto Bake checkbox.
|
||||||
*/
|
*/
|
||||||
ControlsWaiter.prototype.auto_bake_change = function() {
|
ControlsWaiter.prototype.auto_bake_change = function () {
|
||||||
var auto_bake_label = document.getElementById("auto-bake-label"),
|
let auto_bake_label = document.getElementById('auto-bake-label'),
|
||||||
auto_bake_checkbox = document.getElementById("auto-bake");
|
auto_bake_checkbox = document.getElementById('auto-bake');
|
||||||
|
|
||||||
this.app.auto_bake_ = auto_bake_checkbox.checked;
|
this.app.auto_bake_ = auto_bake_checkbox.checked;
|
||||||
|
|
||||||
if (auto_bake_checkbox.checked) {
|
if (auto_bake_checkbox.checked) {
|
||||||
auto_bake_label.classList.remove("btn-default");
|
auto_bake_label.classList.remove('btn-default');
|
||||||
auto_bake_label.classList.add("btn-success");
|
auto_bake_label.classList.add('btn-success');
|
||||||
} else {
|
} else {
|
||||||
auto_bake_label.classList.remove("btn-success");
|
auto_bake_label.classList.remove('btn-success');
|
||||||
auto_bake_label.classList.add("btn-default");
|
auto_bake_label.classList.add('btn-default');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for the 'Clear recipe' command. Removes all operations from the recipe.
|
* Handler for the 'Clear recipe' command. Removes all operations from the recipe.
|
||||||
*/
|
*/
|
||||||
ControlsWaiter.prototype.clear_recipe_click = function() {
|
ControlsWaiter.prototype.clear_recipe_click = function () {
|
||||||
this.manager.recipe.clear_recipe();
|
this.manager.recipe.clear_recipe();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -120,13 +120,13 @@ ControlsWaiter.prototype.clear_recipe_click = function() {
|
||||||
* Handler for the 'Clear breakpoints' command. Removes all breakpoints from operations in the
|
* Handler for the 'Clear breakpoints' command. Removes all breakpoints from operations in the
|
||||||
* recipe.
|
* recipe.
|
||||||
*/
|
*/
|
||||||
ControlsWaiter.prototype.clear_breaks_click = function() {
|
ControlsWaiter.prototype.clear_breaks_click = function () {
|
||||||
var bps = document.querySelectorAll("#rec_list li.operation .breakpoint");
|
const bps = document.querySelectorAll('#rec_list li.operation .breakpoint');
|
||||||
|
|
||||||
for (var i = 0; i < bps.length; i++) {
|
for (let i = 0; i < bps.length; i++) {
|
||||||
bps[i].setAttribute("break", "false");
|
bps[i].setAttribute('break', 'false');
|
||||||
bps[i].classList.remove("breakpoint-selected");
|
bps[i].classList.remove('breakpoint-selected');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -135,18 +135,18 @@ ControlsWaiter.prototype.clear_breaks_click = function() {
|
||||||
*
|
*
|
||||||
* @param {Object[]} [recipe_config] - The recipe configuration object array.
|
* @param {Object[]} [recipe_config] - The recipe configuration object array.
|
||||||
*/
|
*/
|
||||||
ControlsWaiter.prototype.initialise_save_link = function(recipe_config) {
|
ControlsWaiter.prototype.initialise_save_link = function (recipe_config) {
|
||||||
recipe_config = recipe_config || this.app.get_recipe_config();
|
recipe_config = recipe_config || this.app.get_recipe_config();
|
||||||
|
|
||||||
var recipe_str = JSON.stringify(recipe_config),
|
let recipe_str = JSON.stringify(recipe_config),
|
||||||
input_str = Utils.to_base64(this.app.get_input()),
|
input_str = Utils.to_base64(this.app.get_input()),
|
||||||
include_recipe = document.getElementById("save-link-recipe-checkbox").checked,
|
include_recipe = document.getElementById('save-link-recipe-checkbox').checked,
|
||||||
include_input = document.getElementById("save-link-input-checkbox").checked,
|
include_input = document.getElementById('save-link-input-checkbox').checked,
|
||||||
save_link_el = document.getElementById("save-link"),
|
save_link_el = document.getElementById('save-link'),
|
||||||
save_link = this.generate_state_url(include_recipe, include_input, recipe_config);
|
save_link = this.generate_state_url(include_recipe, include_input, recipe_config);
|
||||||
|
|
||||||
save_link_el.innerHTML = Utils.truncate(save_link, 120);
|
save_link_el.innerHTML = Utils.truncate(save_link, 120);
|
||||||
save_link_el.setAttribute("href", save_link);
|
save_link_el.setAttribute('href', save_link);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -158,183 +158,179 @@ ControlsWaiter.prototype.initialise_save_link = function(recipe_config) {
|
||||||
* @param {Object[]} [recipe_config] - The recipe configuration object array.
|
* @param {Object[]} [recipe_config] - The recipe configuration object array.
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
ControlsWaiter.prototype.generate_state_url = function(include_recipe, include_input, recipe_config) {
|
ControlsWaiter.prototype.generate_state_url = function (include_recipe, include_input, recipe_config) {
|
||||||
recipe_config = recipe_config || this.app.get_recipe_config();
|
recipe_config = recipe_config || this.app.get_recipe_config();
|
||||||
|
|
||||||
var link = window.location.protocol + "//" +
|
let link = `${window.location.protocol}//${
|
||||||
window.location.host +
|
window.location.host
|
||||||
window.location.pathname,
|
}${window.location.pathname}`,
|
||||||
recipe_str = JSON.stringify(recipe_config),
|
recipe_str = JSON.stringify(recipe_config),
|
||||||
input_str = Utils.to_base64(this.app.get_input(), "A-Za-z0-9+/"); // B64 alphabet with no padding
|
input_str = Utils.to_base64(this.app.get_input(), 'A-Za-z0-9+/'); // B64 alphabet with no padding
|
||||||
|
|
||||||
include_recipe = include_recipe && (recipe_config.length > 0);
|
include_recipe = include_recipe && (recipe_config.length > 0);
|
||||||
include_input = include_input && (input_str.length > 0) && (input_str.length < 8000);
|
include_input = include_input && (input_str.length > 0) && (input_str.length < 8000);
|
||||||
|
|
||||||
if (include_recipe) {
|
if (include_recipe) {
|
||||||
link += "?recipe=" + encodeURIComponent(recipe_str);
|
link += `?recipe=${encodeURIComponent(recipe_str)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (include_recipe && include_input) {
|
if (include_recipe && include_input) {
|
||||||
link += "&input=" + encodeURIComponent(input_str);
|
link += `&input=${encodeURIComponent(input_str)}`;
|
||||||
} else if (include_input) {
|
} else if (include_input) {
|
||||||
link += "?input=" + encodeURIComponent(input_str);
|
link += `?input=${encodeURIComponent(input_str)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
return link;
|
return link;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for changes made to the save dialog text area. Re-initialises the save link.
|
* Handler for changes made to the save dialog text area. Re-initialises the save link.
|
||||||
*/
|
*/
|
||||||
ControlsWaiter.prototype.save_text_change = function() {
|
ControlsWaiter.prototype.save_text_change = function () {
|
||||||
try {
|
try {
|
||||||
var recipe_config = JSON.parse(document.getElementById("save-text").value);
|
const recipe_config = JSON.parse(document.getElementById('save-text').value);
|
||||||
this.initialise_save_link(recipe_config);
|
this.initialise_save_link(recipe_config);
|
||||||
} catch(err) {}
|
} catch (err) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for the 'Save' command. Pops up the save dialog box.
|
* Handler for the 'Save' command. Pops up the save dialog box.
|
||||||
*/
|
*/
|
||||||
ControlsWaiter.prototype.save_click = function() {
|
ControlsWaiter.prototype.save_click = function () {
|
||||||
var recipe_config = this.app.get_recipe_config();
|
const recipe_config = this.app.get_recipe_config();
|
||||||
var recipe_str = JSON.stringify(recipe_config).replace(/},{/g, '},\n{');
|
const recipe_str = JSON.stringify(recipe_config).replace(/},{/g, '},\n{');
|
||||||
document.getElementById("save-text").value = recipe_str;
|
document.getElementById('save-text').value = recipe_str;
|
||||||
|
|
||||||
this.initialise_save_link(recipe_config);
|
this.initialise_save_link(recipe_config);
|
||||||
$("#save-modal").modal();
|
$('#save-modal').modal();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for the save link recipe checkbox change event.
|
* Handler for the save link recipe checkbox change event.
|
||||||
*/
|
*/
|
||||||
ControlsWaiter.prototype.slr_check_change = function() {
|
ControlsWaiter.prototype.slr_check_change = function () {
|
||||||
this.initialise_save_link();
|
this.initialise_save_link();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for the save link input checkbox change event.
|
* Handler for the save link input checkbox change event.
|
||||||
*/
|
*/
|
||||||
ControlsWaiter.prototype.sli_check_change = function() {
|
ControlsWaiter.prototype.sli_check_change = function () {
|
||||||
this.initialise_save_link();
|
this.initialise_save_link();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for the 'Load' command. Pops up the load dialog box.
|
* Handler for the 'Load' command. Pops up the load dialog box.
|
||||||
*/
|
*/
|
||||||
ControlsWaiter.prototype.load_click = function() {
|
ControlsWaiter.prototype.load_click = function () {
|
||||||
this.populate_load_recipes_list();
|
this.populate_load_recipes_list();
|
||||||
$("#load-modal").modal();
|
$('#load-modal').modal();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the recipe specified in the save textarea to local storage.
|
* Saves the recipe specified in the save textarea to local storage.
|
||||||
*/
|
*/
|
||||||
ControlsWaiter.prototype.save_button_click = function() {
|
ControlsWaiter.prototype.save_button_click = function () {
|
||||||
var recipe_name = document.getElementById("save-name").value,
|
let recipe_name = document.getElementById('save-name').value,
|
||||||
recipe_str = document.getElementById("save-text").value;
|
recipe_str = document.getElementById('save-text').value;
|
||||||
|
|
||||||
if (!recipe_name) {
|
if (!recipe_name) {
|
||||||
this.app.alert("Please enter a recipe name", "danger", 2000);
|
this.app.alert('Please enter a recipe name', 'danger', 2000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var saved_recipes = localStorage.saved_recipes ?
|
let saved_recipes = localStorage.saved_recipes ?
|
||||||
JSON.parse(localStorage.saved_recipes) : [],
|
JSON.parse(localStorage.saved_recipes) : [],
|
||||||
recipe_id = localStorage.recipe_id || 0;
|
recipe_id = localStorage.recipe_id || 0;
|
||||||
|
|
||||||
saved_recipes.push({
|
saved_recipes.push({
|
||||||
id: ++recipe_id,
|
id: ++recipe_id,
|
||||||
name: recipe_name,
|
name: recipe_name,
|
||||||
recipe: recipe_str
|
recipe: recipe_str,
|
||||||
});
|
});
|
||||||
|
|
||||||
localStorage.saved_recipes = JSON.stringify(saved_recipes);
|
localStorage.saved_recipes = JSON.stringify(saved_recipes);
|
||||||
localStorage.recipe_id = recipe_id;
|
localStorage.recipe_id = recipe_id;
|
||||||
|
|
||||||
this.app.alert("Recipe saved as \"" + recipe_name + "\".", "success", 2000);
|
this.app.alert(`Recipe saved as "${recipe_name}".`, 'success', 2000);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Populates the list of saved recipes in the load dialog box from local storage.
|
* Populates the list of saved recipes in the load dialog box from local storage.
|
||||||
*/
|
*/
|
||||||
ControlsWaiter.prototype.populate_load_recipes_list = function() {
|
ControlsWaiter.prototype.populate_load_recipes_list = function () {
|
||||||
var load_name_el = document.getElementById("load-name");
|
const load_name_el = document.getElementById('load-name');
|
||||||
|
|
||||||
// Remove current recipes from select
|
// Remove current recipes from select
|
||||||
var i = load_name_el.options.length;
|
let i = load_name_el.options.length;
|
||||||
while (i--) {
|
while (i--) {
|
||||||
load_name_el.remove(i);
|
load_name_el.remove(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add recipes to select
|
// Add recipes to select
|
||||||
var saved_recipes = localStorage.saved_recipes ?
|
const saved_recipes = localStorage.saved_recipes ?
|
||||||
JSON.parse(localStorage.saved_recipes) : [];
|
JSON.parse(localStorage.saved_recipes) : [];
|
||||||
|
|
||||||
for (i = 0; i < saved_recipes.length; i++) {
|
for (i = 0; i < saved_recipes.length; i++) {
|
||||||
var opt = document.createElement("option");
|
const opt = document.createElement('option');
|
||||||
opt.value = saved_recipes[i].id;
|
opt.value = saved_recipes[i].id;
|
||||||
opt.innerHTML = saved_recipes[i].name;
|
opt.innerHTML = saved_recipes[i].name;
|
||||||
|
|
||||||
load_name_el.appendChild(opt);
|
load_name_el.appendChild(opt);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate textarea with first recipe
|
// Populate textarea with first recipe
|
||||||
document.getElementById("load-text").value = saved_recipes.length ? saved_recipes[0].recipe : "";
|
document.getElementById('load-text').value = saved_recipes.length ? saved_recipes[0].recipe : '';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes the currently selected recipe from local storage.
|
* Removes the currently selected recipe from local storage.
|
||||||
*/
|
*/
|
||||||
ControlsWaiter.prototype.load_delete_click = function() {
|
ControlsWaiter.prototype.load_delete_click = function () {
|
||||||
var id = document.getElementById("load-name").value,
|
let id = document.getElementById('load-name').value,
|
||||||
saved_recipes = localStorage.saved_recipes ?
|
saved_recipes = localStorage.saved_recipes ?
|
||||||
JSON.parse(localStorage.saved_recipes) : [];
|
JSON.parse(localStorage.saved_recipes) : [];
|
||||||
|
|
||||||
saved_recipes = saved_recipes.filter(function(r) {
|
saved_recipes = saved_recipes.filter(r => r.id != id);
|
||||||
return r.id != id;
|
|
||||||
});
|
|
||||||
|
|
||||||
localStorage.saved_recipes = JSON.stringify(saved_recipes);
|
localStorage.saved_recipes = JSON.stringify(saved_recipes);
|
||||||
this.populate_load_recipes_list();
|
this.populate_load_recipes_list();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays the selected recipe in the load text box.
|
* Displays the selected recipe in the load text box.
|
||||||
*/
|
*/
|
||||||
ControlsWaiter.prototype.load_name_change = function(e) {
|
ControlsWaiter.prototype.load_name_change = function (e) {
|
||||||
var el = e.target,
|
let el = e.target,
|
||||||
saved_recipes = localStorage.saved_recipes ?
|
saved_recipes = localStorage.saved_recipes ?
|
||||||
JSON.parse(localStorage.saved_recipes) : [],
|
JSON.parse(localStorage.saved_recipes) : [],
|
||||||
id = parseInt(el.value, 10);
|
id = parseInt(el.value, 10);
|
||||||
|
|
||||||
var recipe = saved_recipes.filter(function(r) {
|
const recipe = saved_recipes.filter(r => r.id == id)[0];
|
||||||
return r.id == id;
|
|
||||||
})[0];
|
|
||||||
|
|
||||||
document.getElementById("load-text").value = recipe.recipe;
|
document.getElementById('load-text').value = recipe.recipe;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads the selected recipe and populates the Recipe with its operations.
|
* Loads the selected recipe and populates the Recipe with its operations.
|
||||||
*/
|
*/
|
||||||
ControlsWaiter.prototype.load_button_click = function() {
|
ControlsWaiter.prototype.load_button_click = function () {
|
||||||
try {
|
try {
|
||||||
var recipe_config = JSON.parse(document.getElementById("load-text").value);
|
const recipe_config = JSON.parse(document.getElementById('load-text').value);
|
||||||
this.app.set_recipe_config(recipe_config);
|
this.app.set_recipe_config(recipe_config);
|
||||||
|
|
||||||
$("#rec_list [data-toggle=popover]").popover();
|
$('#rec_list [data-toggle=popover]').popover();
|
||||||
} catch(e) {
|
} catch (e) {
|
||||||
this.app.alert("Invalid recipe", "danger", 2000);
|
this.app.alert('Invalid recipe', 'danger', 2000);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,21 +14,21 @@
|
||||||
* @param {String[]} default_favourites - A list of default favourite operations.
|
* @param {String[]} default_favourites - A list of default favourite operations.
|
||||||
* @param {Object} options - Default setting for app options.
|
* @param {Object} options - Default setting for app options.
|
||||||
*/
|
*/
|
||||||
var HTMLApp = function(categories, operations, default_favourites, default_options) {
|
const HTMLApp = function (categories, operations, default_favourites, default_options) {
|
||||||
this.categories = categories;
|
this.categories = categories;
|
||||||
this.operations = operations;
|
this.operations = operations;
|
||||||
this.dfavourites = default_favourites;
|
this.dfavourites = default_favourites;
|
||||||
this.doptions = default_options;
|
this.doptions = default_options;
|
||||||
this.options = Utils.extend({}, default_options);
|
this.options = Utils.extend({}, default_options);
|
||||||
|
|
||||||
this.chef = new Chef();
|
this.chef = new Chef();
|
||||||
this.manager = new Manager(this);
|
this.manager = new Manager(this);
|
||||||
|
|
||||||
this.auto_bake_ = false;
|
this.auto_bake_ = false;
|
||||||
this.progress = 0;
|
this.progress = 0;
|
||||||
this.ing_id = 0;
|
this.ing_id = 0;
|
||||||
|
|
||||||
window.chef = this.chef;
|
window.chef = this.chef;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,15 +37,15 @@ var HTMLApp = function(categories, operations, default_favourites, default_optio
|
||||||
*
|
*
|
||||||
* @fires Manager#appstart
|
* @fires Manager#appstart
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.setup = function() {
|
HTMLApp.prototype.setup = function () {
|
||||||
document.dispatchEvent(this.manager.appstart);
|
document.dispatchEvent(this.manager.appstart);
|
||||||
this.initialise_splitter();
|
this.initialise_splitter();
|
||||||
this.load_local_storage();
|
this.load_local_storage();
|
||||||
this.populate_operations_list();
|
this.populate_operations_list();
|
||||||
this.manager.setup();
|
this.manager.setup();
|
||||||
this.reset_layout();
|
this.reset_layout();
|
||||||
this.set_compile_message();
|
this.set_compile_message();
|
||||||
this.load_URI_params();
|
this.load_URI_params();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -54,10 +54,10 @@ HTMLApp.prototype.setup = function() {
|
||||||
*
|
*
|
||||||
* @param {Error} err
|
* @param {Error} err
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.handle_error = function(err) {
|
HTMLApp.prototype.handle_error = function (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
var msg = err.display_str || err.toString();
|
const msg = err.display_str || err.toString();
|
||||||
this.alert(msg, "danger", this.options.error_timeout, !this.options.show_errors);
|
this.alert(msg, 'danger', this.options.error_timeout, !this.options.show_errors);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,48 +67,48 @@ HTMLApp.prototype.handle_error = function(err) {
|
||||||
* @param {boolean} [step] - Set to true if we should only execute one operation instead of the
|
* @param {boolean} [step] - Set to true if we should only execute one operation instead of the
|
||||||
* whole recipe.
|
* whole recipe.
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.bake = function(step) {
|
HTMLApp.prototype.bake = function (step) {
|
||||||
var response;
|
let response;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
response = this.chef.bake(
|
response = this.chef.bake(
|
||||||
this.get_input(), // The user's input
|
this.get_input(), // The user's input
|
||||||
this.get_recipe_config(), // The configuration of the recipe
|
this.get_recipe_config(), // The configuration of the recipe
|
||||||
this.options, // Options set by the user
|
this.options, // Options set by the user
|
||||||
this.progress, // The current position in the recipe
|
this.progress, // The current position in the recipe
|
||||||
step // Whether or not to take one step or execute the whole recipe
|
step, // Whether or not to take one step or execute the whole recipe
|
||||||
);
|
);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.handle_error(err);
|
this.handle_error(err);
|
||||||
} finally {
|
} finally {
|
||||||
if (!response) return;
|
if (!response) return;
|
||||||
|
|
||||||
if (response.error) {
|
if (response.error) {
|
||||||
this.handle_error(response.error);
|
this.handle_error(response.error);
|
||||||
}
|
}
|
||||||
this.options = response.options;
|
this.options = response.options;
|
||||||
this.dish_str = response.type == "html" ? Utils.strip_html_tags(response.result, true) : response.result;
|
this.dish_str = response.type == 'html' ? Utils.strip_html_tags(response.result, true) : response.result;
|
||||||
this.progress = response.progress;
|
this.progress = response.progress;
|
||||||
this.manager.recipe.update_breakpoint_indicator(response.progress);
|
this.manager.recipe.update_breakpoint_indicator(response.progress);
|
||||||
this.manager.output.set(response.result, response.type, response.duration);
|
this.manager.output.set(response.result, response.type, response.duration);
|
||||||
|
|
||||||
// If baking took too long, disable auto-bake
|
// If baking took too long, disable auto-bake
|
||||||
if (response.duration > this.options.auto_bake_threshold && this.auto_bake_) {
|
if (response.duration > this.options.auto_bake_threshold && this.auto_bake_) {
|
||||||
this.manager.controls.set_auto_bake(false);
|
this.manager.controls.set_auto_bake(false);
|
||||||
this.alert("Baking took longer than " + this.options.auto_bake_threshold +
|
this.alert(`Baking took longer than ${this.options.auto_bake_threshold
|
||||||
"ms, Auto Bake has been disabled.", "warning", 5000);
|
}ms, Auto Bake has been disabled.`, 'warning', 5000);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs Auto Bake if it is set.
|
* Runs Auto Bake if it is set.
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.auto_bake = function() {
|
HTMLApp.prototype.auto_bake = function () {
|
||||||
if (this.auto_bake_) {
|
if (this.auto_bake_) {
|
||||||
this.bake();
|
this.bake();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -121,15 +121,15 @@ HTMLApp.prototype.auto_bake = function() {
|
||||||
*
|
*
|
||||||
* @returns {number} - The number of miliseconds it took to run the silent bake.
|
* @returns {number} - The number of miliseconds it took to run the silent bake.
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.silent_bake = function() {
|
HTMLApp.prototype.silent_bake = function () {
|
||||||
var start_time = new Date().getTime(),
|
let start_time = new Date().getTime(),
|
||||||
recipe_config = this.get_recipe_config();
|
recipe_config = this.get_recipe_config();
|
||||||
|
|
||||||
if (this.auto_bake_) {
|
if (this.auto_bake_) {
|
||||||
this.chef.silent_bake(recipe_config);
|
this.chef.silent_bake(recipe_config);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Date().getTime() - start_time;
|
return new Date().getTime() - start_time;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -138,14 +138,14 @@ HTMLApp.prototype.silent_bake = function() {
|
||||||
*
|
*
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.get_input = function() {
|
HTMLApp.prototype.get_input = function () {
|
||||||
var input = this.manager.input.get();
|
const input = this.manager.input.get();
|
||||||
|
|
||||||
// Save to session storage in case we need to restore it later
|
// Save to session storage in case we need to restore it later
|
||||||
sessionStorage.setItem("input_length", input.length);
|
sessionStorage.setItem('input_length', input.length);
|
||||||
sessionStorage.setItem("input", input);
|
sessionStorage.setItem('input', input);
|
||||||
|
|
||||||
return input;
|
return input;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -154,10 +154,10 @@ HTMLApp.prototype.get_input = function() {
|
||||||
*
|
*
|
||||||
* @param {string} input - The string to set the input to
|
* @param {string} input - The string to set the input to
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.set_input = function(input) {
|
HTMLApp.prototype.set_input = function (input) {
|
||||||
sessionStorage.setItem("input_length", input.length);
|
sessionStorage.setItem('input_length', input.length);
|
||||||
sessionStorage.setItem("input", input);
|
sessionStorage.setItem('input', input);
|
||||||
this.manager.input.set(input);
|
this.manager.input.set(input);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -167,56 +167,56 @@ HTMLApp.prototype.set_input = function(input) {
|
||||||
*
|
*
|
||||||
* @fires Manager#oplistcreate
|
* @fires Manager#oplistcreate
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.populate_operations_list = function() {
|
HTMLApp.prototype.populate_operations_list = function () {
|
||||||
// Move edit button away before we overwrite it
|
// Move edit button away before we overwrite it
|
||||||
document.body.appendChild(document.getElementById("edit-favourites"));
|
document.body.appendChild(document.getElementById('edit-favourites'));
|
||||||
|
|
||||||
var html = "";
|
let html = '';
|
||||||
|
|
||||||
for (var i = 0; i < this.categories.length; i++) {
|
for (var i = 0; i < this.categories.length; i++) {
|
||||||
var cat_conf = this.categories[i],
|
let cat_conf = this.categories[i],
|
||||||
selected = i === 0,
|
selected = i === 0,
|
||||||
cat = new HTMLCategory(cat_conf.name, selected);
|
cat = new HTMLCategory(cat_conf.name, selected);
|
||||||
|
|
||||||
for (var j = 0; j < cat_conf.ops.length; j++) {
|
for (let j = 0; j < cat_conf.ops.length; j++) {
|
||||||
var op_name = cat_conf.ops[j],
|
let op_name = cat_conf.ops[j],
|
||||||
op = new HTMLOperation(op_name, this.operations[op_name], this, this.manager);
|
op = new HTMLOperation(op_name, this.operations[op_name], this, this.manager);
|
||||||
cat.add_operation(op);
|
cat.add_operation(op);
|
||||||
}
|
|
||||||
|
|
||||||
html += cat.to_html();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
document.getElementById("categories").innerHTML = html;
|
html += cat.to_html();
|
||||||
|
}
|
||||||
|
|
||||||
var op_lists = document.querySelectorAll("#categories .op_list");
|
document.getElementById('categories').innerHTML = html;
|
||||||
|
|
||||||
for (i = 0; i < op_lists.length; i++) {
|
const op_lists = document.querySelectorAll('#categories .op_list');
|
||||||
op_lists[i].dispatchEvent(this.manager.oplistcreate);
|
|
||||||
}
|
for (i = 0; i < op_lists.length; i++) {
|
||||||
|
op_lists[i].dispatchEvent(this.manager.oplistcreate);
|
||||||
|
}
|
||||||
|
|
||||||
// Add edit button to first category (Favourites)
|
// Add edit button to first category (Favourites)
|
||||||
document.querySelector("#categories a").appendChild(document.getElementById("edit-favourites"));
|
document.querySelector('#categories a').appendChild(document.getElementById('edit-favourites'));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up the adjustable splitter to allow the user to resize areas of the page.
|
* Sets up the adjustable splitter to allow the user to resize areas of the page.
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.initialise_splitter = function() {
|
HTMLApp.prototype.initialise_splitter = function () {
|
||||||
Split(["#operations", "#recipe", "#IO"], {
|
Split(['#operations', '#recipe', '#IO'], {
|
||||||
sizes: [20, 30, 50],
|
sizes: [20, 30, 50],
|
||||||
minSize: [240, 325, 500],
|
minSize: [240, 325, 500],
|
||||||
gutterSize: 4,
|
gutterSize: 4,
|
||||||
onDrag: this.manager.controls.adjust_width.bind(this.manager.controls)
|
onDrag: this.manager.controls.adjust_width.bind(this.manager.controls),
|
||||||
});
|
});
|
||||||
|
|
||||||
Split(["#input", "#output"], {
|
Split(['#input', '#output'], {
|
||||||
direction: "vertical",
|
direction: 'vertical',
|
||||||
gutterSize: 4,
|
gutterSize: 4,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.reset_layout();
|
this.reset_layout();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -224,16 +224,16 @@ HTMLApp.prototype.initialise_splitter = function() {
|
||||||
* Loads the information previously saved to the HTML5 local storage object so that user options
|
* Loads the information previously saved to the HTML5 local storage object so that user options
|
||||||
* and favourites can be restored.
|
* and favourites can be restored.
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.load_local_storage = function() {
|
HTMLApp.prototype.load_local_storage = function () {
|
||||||
// Load options
|
// Load options
|
||||||
var l_options;
|
let l_options;
|
||||||
if (localStorage.options !== undefined) {
|
if (localStorage.options !== undefined) {
|
||||||
l_options = JSON.parse(localStorage.options);
|
l_options = JSON.parse(localStorage.options);
|
||||||
}
|
}
|
||||||
this.manager.options.load(l_options);
|
this.manager.options.load(l_options);
|
||||||
|
|
||||||
// Load favourites
|
// Load favourites
|
||||||
this.load_favourites();
|
this.load_favourites();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -242,27 +242,25 @@ HTMLApp.prototype.load_local_storage = function() {
|
||||||
* Favourites category with them.
|
* Favourites category with them.
|
||||||
* If the user currently has no saved favourites, the defaults from the view constructor are used.
|
* If the user currently has no saved favourites, the defaults from the view constructor are used.
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.load_favourites = function() {
|
HTMLApp.prototype.load_favourites = function () {
|
||||||
var favourites = localStorage.favourites &&
|
let favourites = localStorage.favourites &&
|
||||||
localStorage.favourites.length > 2 ?
|
localStorage.favourites.length > 2 ?
|
||||||
JSON.parse(localStorage.favourites) :
|
JSON.parse(localStorage.favourites) :
|
||||||
this.dfavourites;
|
this.dfavourites;
|
||||||
|
|
||||||
favourites = this.valid_favourites(favourites);
|
favourites = this.valid_favourites(favourites);
|
||||||
this.save_favourites(favourites);
|
this.save_favourites(favourites);
|
||||||
|
|
||||||
var fav_cat = this.categories.filter(function(c) {
|
const fav_cat = this.categories.filter(c => c.name == 'Favourites')[0];
|
||||||
return c.name == "Favourites";
|
|
||||||
})[0];
|
|
||||||
|
|
||||||
if (fav_cat) {
|
if (fav_cat) {
|
||||||
fav_cat.ops = favourites;
|
fav_cat.ops = favourites;
|
||||||
} else {
|
} else {
|
||||||
this.categories.unshift({
|
this.categories.unshift({
|
||||||
name: "Favourites",
|
name: 'Favourites',
|
||||||
ops: favourites
|
ops: favourites,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -273,17 +271,17 @@ HTMLApp.prototype.load_favourites = function() {
|
||||||
* @param {string[]} favourites - A list of the user's favourite operations
|
* @param {string[]} favourites - A list of the user's favourite operations
|
||||||
* @returns {string[]} A list of the valid favourites
|
* @returns {string[]} A list of the valid favourites
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.valid_favourites = function(favourites) {
|
HTMLApp.prototype.valid_favourites = function (favourites) {
|
||||||
var valid_favs = [];
|
const valid_favs = [];
|
||||||
for (var i = 0; i < favourites.length; i++) {
|
for (let i = 0; i < favourites.length; i++) {
|
||||||
if (this.operations.hasOwnProperty(favourites[i])) {
|
if (this.operations.hasOwnProperty(favourites[i])) {
|
||||||
valid_favs.push(favourites[i]);
|
valid_favs.push(favourites[i]);
|
||||||
} else {
|
} else {
|
||||||
this.alert("The operation \"" + favourites[i] + "\" is no longer " +
|
this.alert(`The operation "${favourites[i]}" is no longer ` +
|
||||||
"available. It has been removed from your favourites.", "info");
|
'available. It has been removed from your favourites.', 'info');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return valid_favs;
|
}
|
||||||
|
return valid_favs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -292,8 +290,8 @@ HTMLApp.prototype.valid_favourites = function(favourites) {
|
||||||
*
|
*
|
||||||
* @param {string[]} favourites - A list of the user's favourite operations
|
* @param {string[]} favourites - A list of the user's favourite operations
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.save_favourites = function(favourites) {
|
HTMLApp.prototype.save_favourites = function (favourites) {
|
||||||
localStorage.setItem("favourites", JSON.stringify(this.valid_favourites(favourites)));
|
localStorage.setItem('favourites', JSON.stringify(this.valid_favourites(favourites)));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -301,11 +299,11 @@ HTMLApp.prototype.save_favourites = function(favourites) {
|
||||||
* Resets favourite operations back to the default as specified in the view constructor and
|
* Resets favourite operations back to the default as specified in the view constructor and
|
||||||
* refreshes the operation list.
|
* refreshes the operation list.
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.reset_favourites = function() {
|
HTMLApp.prototype.reset_favourites = function () {
|
||||||
this.save_favourites(this.dfavourites);
|
this.save_favourites(this.dfavourites);
|
||||||
this.load_favourites();
|
this.load_favourites();
|
||||||
this.populate_operations_list();
|
this.populate_operations_list();
|
||||||
this.manager.recipe.initialise_operation_drag_n_drop();
|
this.manager.recipe.initialise_operation_drag_n_drop();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -314,82 +312,82 @@ HTMLApp.prototype.reset_favourites = function() {
|
||||||
*
|
*
|
||||||
* @param {string} name - The name of the operation
|
* @param {string} name - The name of the operation
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.add_favourite = function(name) {
|
HTMLApp.prototype.add_favourite = function (name) {
|
||||||
var favourites = JSON.parse(localStorage.favourites);
|
const favourites = JSON.parse(localStorage.favourites);
|
||||||
|
|
||||||
if (favourites.indexOf(name) >= 0) {
|
if (favourites.indexOf(name) >= 0) {
|
||||||
this.alert("'" + name + "' is already in your favourites", "info", 2000);
|
this.alert(`'${name}' is already in your favourites`, 'info', 2000);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
favourites.push(name);
|
favourites.push(name);
|
||||||
this.save_favourites(favourites);
|
this.save_favourites(favourites);
|
||||||
this.load_favourites();
|
this.load_favourites();
|
||||||
this.populate_operations_list();
|
this.populate_operations_list();
|
||||||
this.manager.recipe.initialise_operation_drag_n_drop();
|
this.manager.recipe.initialise_operation_drag_n_drop();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks for input and recipe in the URI parameters and loads them if present.
|
* Checks for input and recipe in the URI parameters and loads them if present.
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.load_URI_params = function() {
|
HTMLApp.prototype.load_URI_params = function () {
|
||||||
// Load query string from URI
|
// Load query string from URI
|
||||||
this.query_string = (function(a) {
|
this.query_string = (function (a) {
|
||||||
if (a === "") return {};
|
if (a === '') return {};
|
||||||
var b = {};
|
const b = {};
|
||||||
for (var i = 0; i < a.length; i++) {
|
for (let i = 0; i < a.length; i++) {
|
||||||
var p = a[i].split('=');
|
const p = a[i].split('=');
|
||||||
if (p.length != 2) {
|
if (p.length != 2) {
|
||||||
b[a[i]] = true;
|
b[a[i]] = true;
|
||||||
} else {
|
} else {
|
||||||
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
|
b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, ' '));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return b;
|
return b;
|
||||||
})(window.location.search.substr(1).split('&'));
|
}(window.location.search.substr(1).split('&')));
|
||||||
|
|
||||||
// Turn off auto-bake while loading
|
// Turn off auto-bake while loading
|
||||||
var auto_bake_val = this.auto_bake_;
|
const auto_bake_val = this.auto_bake_;
|
||||||
this.auto_bake_ = false;
|
this.auto_bake_ = false;
|
||||||
|
|
||||||
// Read in recipe from query string
|
// Read in recipe from query string
|
||||||
if (this.query_string.recipe) {
|
if (this.query_string.recipe) {
|
||||||
try {
|
try {
|
||||||
var recipe_config = JSON.parse(this.query_string.recipe);
|
const recipe_config = JSON.parse(this.query_string.recipe);
|
||||||
this.set_recipe_config(recipe_config);
|
this.set_recipe_config(recipe_config);
|
||||||
} catch(err) {}
|
} catch (err) {}
|
||||||
} else if (this.query_string.op) {
|
} else if (this.query_string.op) {
|
||||||
// If there's no recipe, look for single operations
|
// If there's no recipe, look for single operations
|
||||||
this.manager.recipe.clear_recipe();
|
this.manager.recipe.clear_recipe();
|
||||||
try {
|
try {
|
||||||
this.manager.recipe.add_operation(this.query_string.op);
|
this.manager.recipe.add_operation(this.query_string.op);
|
||||||
} catch(err) {
|
} catch (err) {
|
||||||
// If no exact match, search for nearest match and add that
|
// If no exact match, search for nearest match and add that
|
||||||
var matched_ops = this.manager.ops.filter_operations(this.query_string.op, false);
|
const matched_ops = this.manager.ops.filter_operations(this.query_string.op, false);
|
||||||
if (matched_ops.length) {
|
if (matched_ops.length) {
|
||||||
this.manager.recipe.add_operation(matched_ops[0].name);
|
this.manager.recipe.add_operation(matched_ops[0].name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Populate search with the string
|
// Populate search with the string
|
||||||
var search = document.getElementById("search");
|
const search = document.getElementById('search');
|
||||||
|
|
||||||
search.value = this.query_string.op;
|
search.value = this.query_string.op;
|
||||||
search.dispatchEvent(new Event("search"));
|
search.dispatchEvent(new Event('search'));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Read in input data from query string
|
// Read in input data from query string
|
||||||
if (this.query_string.input) {
|
if (this.query_string.input) {
|
||||||
try {
|
try {
|
||||||
var input_data = Utils.from_base64(this.query_string.input);
|
const input_data = Utils.from_base64(this.query_string.input);
|
||||||
this.set_input(input_data);
|
this.set_input(input_data);
|
||||||
} catch(err) {}
|
} catch (err) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Restore auto-bake state
|
// Restore auto-bake state
|
||||||
this.auto_bake_ = auto_bake_val;
|
this.auto_bake_ = auto_bake_val;
|
||||||
this.auto_bake();
|
this.auto_bake();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -398,8 +396,8 @@ HTMLApp.prototype.load_URI_params = function() {
|
||||||
*
|
*
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.next_ing_id = function() {
|
HTMLApp.prototype.next_ing_id = function () {
|
||||||
return this.ing_id++;
|
return this.ing_id++;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -408,10 +406,10 @@ HTMLApp.prototype.next_ing_id = function() {
|
||||||
*
|
*
|
||||||
* @returns {Object[]}
|
* @returns {Object[]}
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.get_recipe_config = function() {
|
HTMLApp.prototype.get_recipe_config = function () {
|
||||||
var recipe_config = this.manager.recipe.get_config();
|
const recipe_config = this.manager.recipe.get_config();
|
||||||
sessionStorage.setItem("recipe_config", JSON.stringify(recipe_config));
|
sessionStorage.setItem('recipe_config', JSON.stringify(recipe_config));
|
||||||
return recipe_config;
|
return recipe_config;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -420,73 +418,73 @@ HTMLApp.prototype.get_recipe_config = function() {
|
||||||
*
|
*
|
||||||
* @param {Object[]} recipe_config - The recipe configuration
|
* @param {Object[]} recipe_config - The recipe configuration
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.set_recipe_config = function(recipe_config) {
|
HTMLApp.prototype.set_recipe_config = function (recipe_config) {
|
||||||
sessionStorage.setItem("recipe_config", JSON.stringify(recipe_config));
|
sessionStorage.setItem('recipe_config', JSON.stringify(recipe_config));
|
||||||
document.getElementById("rec_list").innerHTML = null;
|
document.getElementById('rec_list').innerHTML = null;
|
||||||
|
|
||||||
for (var i = 0; i < recipe_config.length; i++) {
|
for (let i = 0; i < recipe_config.length; i++) {
|
||||||
var item = this.manager.recipe.add_operation(recipe_config[i].op);
|
const item = this.manager.recipe.add_operation(recipe_config[i].op);
|
||||||
|
|
||||||
// Populate arguments
|
// Populate arguments
|
||||||
var args = item.querySelectorAll(".arg");
|
const args = item.querySelectorAll('.arg');
|
||||||
for (var j = 0; j < args.length; j++) {
|
for (let j = 0; j < args.length; j++) {
|
||||||
if (args[j].getAttribute("type") == "checkbox") {
|
if (args[j].getAttribute('type') == 'checkbox') {
|
||||||
// checkbox
|
// checkbox
|
||||||
args[j].checked = recipe_config[i].args[j];
|
args[j].checked = recipe_config[i].args[j];
|
||||||
} else if (args[j].classList.contains("toggle-string")) {
|
} else if (args[j].classList.contains('toggle-string')) {
|
||||||
// toggle_string
|
// toggle_string
|
||||||
args[j].value = recipe_config[i].args[j].string;
|
args[j].value = recipe_config[i].args[j].string;
|
||||||
args[j].previousSibling.children[0].innerHTML = recipe_config[i].args[j].option +
|
args[j].previousSibling.children[0].innerHTML = `${recipe_config[i].args[j].option
|
||||||
" <span class='caret'></span>";
|
} <span class='caret'></span>`;
|
||||||
} else {
|
} else {
|
||||||
// all others
|
// all others
|
||||||
args[j].value = recipe_config[i].args[j];
|
args[j].value = recipe_config[i].args[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set disabled and breakpoint
|
// Set disabled and breakpoint
|
||||||
if (recipe_config[i].disabled) {
|
if (recipe_config[i].disabled) {
|
||||||
item.querySelector(".disable-icon").click();
|
item.querySelector('.disable-icon').click();
|
||||||
}
|
|
||||||
if (recipe_config[i].breakpoint) {
|
|
||||||
item.querySelector(".breakpoint").click();
|
|
||||||
}
|
|
||||||
|
|
||||||
this.progress = 0;
|
|
||||||
}
|
}
|
||||||
|
if (recipe_config[i].breakpoint) {
|
||||||
|
item.querySelector('.breakpoint').click();
|
||||||
|
}
|
||||||
|
|
||||||
|
this.progress = 0;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets the splitter positions to default.
|
* Resets the splitter positions to default.
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.reset_layout = function() {
|
HTMLApp.prototype.reset_layout = function () {
|
||||||
document.getElementById("operations").style.width = "calc(20% - 2px)";
|
document.getElementById('operations').style.width = 'calc(20% - 2px)';
|
||||||
document.getElementById("recipe").style.width = "calc(30% - 4px)";
|
document.getElementById('recipe').style.width = 'calc(30% - 4px)';
|
||||||
document.getElementById("IO").style.width = "calc(50% - 2px)";
|
document.getElementById('IO').style.width = 'calc(50% - 2px)';
|
||||||
document.getElementById("input").style.height = "calc(50% - 2px)";
|
document.getElementById('input').style.height = 'calc(50% - 2px)';
|
||||||
document.getElementById("output").style.height = "calc(50% - 2px)";
|
document.getElementById('output').style.height = 'calc(50% - 2px)';
|
||||||
|
|
||||||
this.manager.controls.adjust_width();
|
this.manager.controls.adjust_width();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the compile message.
|
* Sets the compile message.
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.set_compile_message = function() {
|
HTMLApp.prototype.set_compile_message = function () {
|
||||||
// Display time since last build and compile message
|
// Display time since last build and compile message
|
||||||
var now = new Date(),
|
let now = new Date(),
|
||||||
time_since_compile = Utils.fuzzy_time(now.getTime() - window.compile_time),
|
time_since_compile = Utils.fuzzy_time(now.getTime() - window.compile_time),
|
||||||
compile_info = "<span style=\"font-weight: normal\">Last build: " +
|
compile_info = `<span style="font-weight: normal">Last build: ${
|
||||||
time_since_compile.substr(0,1).toUpperCase() + time_since_compile.substr(1) + " ago";
|
time_since_compile.substr(0, 1).toUpperCase()}${time_since_compile.substr(1)} ago`;
|
||||||
|
|
||||||
if (window.compile_message !== "") {
|
if (window.compile_message !== '') {
|
||||||
compile_info += " - " + window.compile_message;
|
compile_info += ` - ${window.compile_message}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
compile_info += "</span>";
|
compile_info += '</span>';
|
||||||
document.getElementById("notice").innerHTML = compile_info;
|
document.getElementById('notice').innerHTML = compile_info;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -513,44 +511,44 @@ HTMLApp.prototype.set_compile_message = function() {
|
||||||
* // that will disappear after 5 seconds.
|
* // that will disappear after 5 seconds.
|
||||||
* this.alert("Happy Christmas!", "info", 5000);
|
* this.alert("Happy Christmas!", "info", 5000);
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.alert = function(str, style, timeout, silent) {
|
HTMLApp.prototype.alert = function (str, style, timeout, silent) {
|
||||||
var time = new Date();
|
const time = new Date();
|
||||||
|
|
||||||
console.log("[" + time.toLocaleString() + "] " + str);
|
console.log(`[${time.toLocaleString()}] ${str}`);
|
||||||
if (silent) return;
|
if (silent) return;
|
||||||
|
|
||||||
style = style || "danger";
|
style = style || 'danger';
|
||||||
timeout = timeout || 0;
|
timeout = timeout || 0;
|
||||||
|
|
||||||
var alert_el = document.getElementById("alert"),
|
let alert_el = document.getElementById('alert'),
|
||||||
alert_content = document.getElementById("alert-content");
|
alert_content = document.getElementById('alert-content');
|
||||||
|
|
||||||
alert_el.classList.remove("alert-danger");
|
alert_el.classList.remove('alert-danger');
|
||||||
alert_el.classList.remove("alert-warning");
|
alert_el.classList.remove('alert-warning');
|
||||||
alert_el.classList.remove("alert-info");
|
alert_el.classList.remove('alert-info');
|
||||||
alert_el.classList.remove("alert-success");
|
alert_el.classList.remove('alert-success');
|
||||||
alert_el.classList.add("alert-" + style);
|
alert_el.classList.add(`alert-${style}`);
|
||||||
|
|
||||||
// If the box hasn't been closed, append to it rather than replacing
|
// If the box hasn't been closed, append to it rather than replacing
|
||||||
if (alert_el.style.display == "block") {
|
if (alert_el.style.display == 'block') {
|
||||||
alert_content.innerHTML +=
|
alert_content.innerHTML +=
|
||||||
"<br><br>[" + time.toLocaleTimeString() + "] " + str;
|
`<br><br>[${time.toLocaleTimeString()}] ${str}`;
|
||||||
} else {
|
} else {
|
||||||
alert_content.innerHTML =
|
alert_content.innerHTML =
|
||||||
"[" + time.toLocaleTimeString() + "] " + str;
|
`[${time.toLocaleTimeString()}] ${str}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop the animation if it is in progress
|
// Stop the animation if it is in progress
|
||||||
$("#alert").stop();
|
$('#alert').stop();
|
||||||
alert_el.style.display = "block";
|
alert_el.style.display = 'block';
|
||||||
alert_el.style.opacity = 1;
|
alert_el.style.opacity = 1;
|
||||||
|
|
||||||
if (timeout > 0) {
|
if (timeout > 0) {
|
||||||
clearTimeout(this.alert_timeout);
|
clearTimeout(this.alert_timeout);
|
||||||
this.alert_timeout = setTimeout(function(){
|
this.alert_timeout = setTimeout(() => {
|
||||||
$("#alert").slideUp(100);
|
$('#alert').slideUp(100);
|
||||||
}, timeout);
|
}, timeout);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -567,27 +565,26 @@ HTMLApp.prototype.alert = function(str, style, timeout, silent) {
|
||||||
* // Pops up a box asking if the user would like a cookie. Prints the answer to the console.
|
* // Pops up a box asking if the user would like a cookie. Prints the answer to the console.
|
||||||
* this.confirm("Question", "Would you like a cookie?", function(answer) {console.log(answer);});
|
* this.confirm("Question", "Would you like a cookie?", function(answer) {console.log(answer);});
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.confirm = function(title, body, callback, scope) {
|
HTMLApp.prototype.confirm = function (title, body, callback, scope) {
|
||||||
scope = scope || this;
|
scope = scope || this;
|
||||||
document.getElementById("confirm-title").innerHTML = title;
|
document.getElementById('confirm-title').innerHTML = title;
|
||||||
document.getElementById("confirm-body").innerHTML = body;
|
document.getElementById('confirm-body').innerHTML = body;
|
||||||
document.getElementById("confirm-modal").style.display = "block";
|
document.getElementById('confirm-modal').style.display = 'block';
|
||||||
|
|
||||||
this.confirm_closed = false;
|
this.confirm_closed = false;
|
||||||
$("#confirm-modal").modal()
|
$('#confirm-modal').modal()
|
||||||
.one("show.bs.modal", function(e) {
|
.one('show.bs.modal', (e) => {
|
||||||
this.confirm_closed = false;
|
this.confirm_closed = false;
|
||||||
}.bind(this))
|
})
|
||||||
.one("click", "#confirm-yes", function() {
|
.one('click', '#confirm-yes', () => {
|
||||||
this.confirm_closed = true;
|
this.confirm_closed = true;
|
||||||
callback.bind(scope)(true);
|
callback.bind(scope)(true);
|
||||||
$("#confirm-modal").modal("hide");
|
$('#confirm-modal').modal('hide');
|
||||||
}.bind(this))
|
})
|
||||||
.one("hide.bs.modal", function(e) {
|
.one('hide.bs.modal', (e) => {
|
||||||
if (!this.confirm_closed)
|
if (!this.confirm_closed) { callback.bind(scope)(false); }
|
||||||
callback.bind(scope)(false);
|
this.confirm_closed = true;
|
||||||
this.confirm_closed = true;
|
});
|
||||||
}.bind(this));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -595,8 +592,8 @@ HTMLApp.prototype.confirm = function(title, body, callback, scope) {
|
||||||
* Handler for the alert close button click event.
|
* Handler for the alert close button click event.
|
||||||
* Closes the alert box.
|
* Closes the alert box.
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.alert_close_click = function() {
|
HTMLApp.prototype.alert_close_click = function () {
|
||||||
document.getElementById("alert").style.display = "none";
|
document.getElementById('alert').style.display = 'none';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -607,14 +604,14 @@ HTMLApp.prototype.alert_close_click = function() {
|
||||||
* @listens Manager#statechange
|
* @listens Manager#statechange
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.state_change = function(e) {
|
HTMLApp.prototype.state_change = function (e) {
|
||||||
this.auto_bake();
|
this.auto_bake();
|
||||||
|
|
||||||
// Update the current history state (not creating a new one)
|
// Update the current history state (not creating a new one)
|
||||||
if (this.options.update_url) {
|
if (this.options.update_url) {
|
||||||
this.last_state_url = this.manager.controls.generate_state_url(true, true);
|
this.last_state_url = this.manager.controls.generate_state_url(true, true);
|
||||||
window.history.replaceState({}, "CyberChef", this.last_state_url);
|
window.history.replaceState({}, 'CyberChef', this.last_state_url);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -624,44 +621,44 @@ HTMLApp.prototype.state_change = function(e) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.pop_state = function(e) {
|
HTMLApp.prototype.pop_state = function (e) {
|
||||||
if (window.location.href.split("#")[0] !== this.last_state_url) {
|
if (window.location.href.split('#')[0] !== this.last_state_url) {
|
||||||
this.load_URI_params();
|
this.load_URI_params();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to call an external API from this view.
|
* Function to call an external API from this view.
|
||||||
*/
|
*/
|
||||||
HTMLApp.prototype.call_api = function(url, type, data, data_type, content_type) {
|
HTMLApp.prototype.call_api = function (url, type, data, data_type, content_type) {
|
||||||
type = type || "POST";
|
type = type || 'POST';
|
||||||
data = data || {};
|
data = data || {};
|
||||||
data_type = data_type || undefined;
|
data_type = data_type || undefined;
|
||||||
content_type = content_type || "application/json";
|
content_type = content_type || 'application/json';
|
||||||
|
|
||||||
var response = null,
|
let response = null,
|
||||||
success = false;
|
success = false;
|
||||||
|
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: url,
|
url,
|
||||||
async: false,
|
async: false,
|
||||||
type: type,
|
type,
|
||||||
data: data,
|
data,
|
||||||
dataType: data_type,
|
dataType: data_type,
|
||||||
contentType: content_type,
|
contentType: content_type,
|
||||||
success: function(data) {
|
success(data) {
|
||||||
success = true;
|
success = true;
|
||||||
response = data;
|
response = data;
|
||||||
},
|
},
|
||||||
error: function(data) {
|
error(data) {
|
||||||
success = false;
|
success = false;
|
||||||
response = data;
|
response = data;
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
success: success,
|
success,
|
||||||
response: response
|
response,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,10 +9,10 @@
|
||||||
* @param {string} name - The name of the category.
|
* @param {string} name - The name of the category.
|
||||||
* @param {boolean} selected - Whether this category is pre-selected or not.
|
* @param {boolean} selected - Whether this category is pre-selected or not.
|
||||||
*/
|
*/
|
||||||
var HTMLCategory = function(name, selected) {
|
const HTMLCategory = function (name, selected) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.selected = selected;
|
this.selected = selected;
|
||||||
this.op_list = [];
|
this.op_list = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,8 +21,8 @@ var HTMLCategory = function(name, selected) {
|
||||||
*
|
*
|
||||||
* @param {HTMLOperation} operation - The operation to add.
|
* @param {HTMLOperation} operation - The operation to add.
|
||||||
*/
|
*/
|
||||||
HTMLCategory.prototype.add_operation = function(operation) {
|
HTMLCategory.prototype.add_operation = function (operation) {
|
||||||
this.op_list.push(operation);
|
this.op_list.push(operation);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,20 +31,20 @@ HTMLCategory.prototype.add_operation = function(operation) {
|
||||||
*
|
*
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
HTMLCategory.prototype.to_html = function() {
|
HTMLCategory.prototype.to_html = function () {
|
||||||
var cat_name = "cat" + this.name.replace(/[\s/-:_]/g, "");
|
const cat_name = `cat${this.name.replace(/[\s/-:_]/g, '')}`;
|
||||||
var html = "<div class='panel category'>\
|
let html = `<div class='panel category'>\
|
||||||
<a class='category-title' data-toggle='collapse'\
|
<a class='category-title' data-toggle='collapse'\
|
||||||
data-parent='#categories' href='#" + cat_name + "'>\
|
data-parent='#categories' href='#${cat_name}'>\
|
||||||
" + this.name + "\
|
${this.name}\
|
||||||
</a>\
|
</a>\
|
||||||
<div id='" + cat_name + "' class='panel-collapse collapse\
|
<div id='${cat_name}' class='panel-collapse collapse\
|
||||||
" + (this.selected ? " in" : "") + "'><ul class='op_list'>";
|
${this.selected ? ' in' : ''}'><ul class='op_list'>`;
|
||||||
|
|
||||||
for (var i = 0; i < this.op_list.length; i++) {
|
for (let i = 0; i < this.op_list.length; i++) {
|
||||||
html += this.op_list[i].to_stub_html();
|
html += this.op_list[i].to_stub_html();
|
||||||
}
|
}
|
||||||
|
|
||||||
html += "</ul></div></div>";
|
html += '</ul></div></div>';
|
||||||
return html;
|
return html;
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,19 +10,19 @@
|
||||||
* @param {HTMLApp} app - The main view object for CyberChef.
|
* @param {HTMLApp} app - The main view object for CyberChef.
|
||||||
* @param {Manager} manager - The CyberChef event manager.
|
* @param {Manager} manager - The CyberChef event manager.
|
||||||
*/
|
*/
|
||||||
var HTMLIngredient = function(config, app, manager) {
|
const HTMLIngredient = function (config, app, manager) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
|
|
||||||
this.name = config.name;
|
this.name = config.name;
|
||||||
this.type = config.type;
|
this.type = config.type;
|
||||||
this.value = config.value;
|
this.value = config.value;
|
||||||
this.disabled = config.disabled || false;
|
this.disabled = config.disabled || false;
|
||||||
this.disable_args = config.disable_args || false;
|
this.disable_args = config.disable_args || false;
|
||||||
this.placeholder = config.placeholder || false;
|
this.placeholder = config.placeholder || false;
|
||||||
this.target = config.target;
|
this.target = config.target;
|
||||||
this.toggle_values = config.toggle_values;
|
this.toggle_values = config.toggle_values;
|
||||||
this.id = "ing-" + this.app.next_ing_id();
|
this.id = `ing-${this.app.next_ing_id()}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,123 +31,124 @@ var HTMLIngredient = function(config, app, manager) {
|
||||||
*
|
*
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
HTMLIngredient.prototype.to_html = function() {
|
HTMLIngredient.prototype.to_html = function () {
|
||||||
var inline = (this.type == "boolean" ||
|
let inline = (this.type == 'boolean' ||
|
||||||
this.type == "number" ||
|
this.type == 'number' ||
|
||||||
this.type == "option" ||
|
this.type == 'option' ||
|
||||||
this.type == "short_string" ||
|
this.type == 'short_string' ||
|
||||||
this.type == "binary_short_string"),
|
this.type == 'binary_short_string'),
|
||||||
html = inline ? "" : "<div class='clearfix'> </div>",
|
html = inline ? '' : "<div class='clearfix'> </div>",
|
||||||
i, m;
|
i,
|
||||||
|
m;
|
||||||
|
|
||||||
html += "<div class='arg-group" + (inline ? " inline-args" : "") +
|
html += `<div class='arg-group${inline ? ' inline-args' : ''
|
||||||
(this.type == "text" ? " arg-group-text" : "") + "'><label class='arg-label' for='" +
|
}${this.type == 'text' ? ' arg-group-text' : ''}'><label class='arg-label' for='${
|
||||||
this.id + "'>" + this.name + "</label>";
|
this.id}'>${this.name}</label>`;
|
||||||
|
|
||||||
switch (this.type) {
|
switch (this.type) {
|
||||||
case "string":
|
case 'string':
|
||||||
case "binary_string":
|
case 'binary_string':
|
||||||
case "byte_array":
|
case 'byte_array':
|
||||||
html += "<input type='text' id='" + this.id + "' class='arg arg-input' arg_name='" +
|
html += `<input type='text' id='${this.id}' class='arg arg-input' arg_name='${
|
||||||
this.name + "' value='" + this.value + "'" +
|
this.name}' value='${this.value}'${
|
||||||
(this.disabled ? " disabled='disabled'" : "") +
|
this.disabled ? " disabled='disabled'" : ''
|
||||||
(this.placeholder ? " placeholder='" + this.placeholder + "'" : "") + ">";
|
}${this.placeholder ? ` placeholder='${this.placeholder}'` : ''}>`;
|
||||||
break;
|
break;
|
||||||
case "short_string":
|
case 'short_string':
|
||||||
case "binary_short_string":
|
case 'binary_short_string':
|
||||||
html += "<input type='text' id='" + this.id +
|
html += `<input type='text' id='${this.id
|
||||||
"'class='arg arg-input short-string' arg_name='" + this.name + "'value='" +
|
}'class='arg arg-input short-string' arg_name='${this.name}'value='${
|
||||||
this.value + "'" + (this.disabled ? " disabled='disabled'" : "") +
|
this.value}'${this.disabled ? " disabled='disabled'" : ''
|
||||||
(this.placeholder ? " placeholder='" + this.placeholder + "'" : "") + ">";
|
}${this.placeholder ? ` placeholder='${this.placeholder}'` : ''}>`;
|
||||||
break;
|
break;
|
||||||
case "toggle_string":
|
case 'toggle_string':
|
||||||
html += "<div class='input-group'><div class='input-group-btn'>\
|
html += `<div class='input-group'><div class='input-group-btn'>\
|
||||||
<button type='button' class='btn btn-default dropdown-toggle' data-toggle='dropdown'\
|
<button type='button' class='btn btn-default dropdown-toggle' data-toggle='dropdown'\
|
||||||
aria-haspopup='true' aria-expanded='false'" +
|
aria-haspopup='true' aria-expanded='false'${
|
||||||
(this.disabled ? " disabled='disabled'" : "") + ">" + this.toggle_values[0] +
|
this.disabled ? " disabled='disabled'" : ''}>${this.toggle_values[0]
|
||||||
" <span class='caret'></span></button><ul class='dropdown-menu'>";
|
} <span class='caret'></span></button><ul class='dropdown-menu'>`;
|
||||||
for (i = 0; i < this.toggle_values.length; i++) {
|
for (i = 0; i < this.toggle_values.length; i++) {
|
||||||
html += "<li><a href='#'>" + this.toggle_values[i] + "</a></li>";
|
html += `<li><a href='#'>${this.toggle_values[i]}</a></li>`;
|
||||||
}
|
}
|
||||||
html += "</ul></div><input type='text' class='arg arg-input toggle-string'" +
|
html += `</ul></div><input type='text' class='arg arg-input toggle-string'${
|
||||||
(this.disabled ? " disabled='disabled'" : "") +
|
this.disabled ? " disabled='disabled'" : ''
|
||||||
(this.placeholder ? " placeholder='" + this.placeholder + "'" : "") + "></div>";
|
}${this.placeholder ? ` placeholder='${this.placeholder}'` : ''}></div>`;
|
||||||
break;
|
break;
|
||||||
case "number":
|
case 'number':
|
||||||
html += "<input type='number' id='" + this.id + "'class='arg arg-input' arg_name='" +
|
html += `<input type='number' id='${this.id}'class='arg arg-input' arg_name='${
|
||||||
this.name + "'value='" + this.value + "'" +
|
this.name}'value='${this.value}'${
|
||||||
(this.disabled ? " disabled='disabled'" : "") +
|
this.disabled ? " disabled='disabled'" : ''
|
||||||
(this.placeholder ? " placeholder='" + this.placeholder + "'" : "") + ">";
|
}${this.placeholder ? ` placeholder='${this.placeholder}'` : ''}>`;
|
||||||
break;
|
break;
|
||||||
case "boolean":
|
case 'boolean':
|
||||||
html += "<input type='checkbox' id='" + this.id + "'class='arg' arg_name='" +
|
html += `<input type='checkbox' id='${this.id}'class='arg' arg_name='${
|
||||||
this.name + "'" + (this.value ? " checked='checked' " : "") +
|
this.name}'${this.value ? " checked='checked' " : ''
|
||||||
(this.disabled ? " disabled='disabled'" : "") + ">";
|
}${this.disabled ? " disabled='disabled'" : ''}>`;
|
||||||
|
|
||||||
if (this.disable_args) {
|
if (this.disable_args) {
|
||||||
this.manager.add_dynamic_listener("#" + this.id, "click", this.toggle_disable_args, this);
|
this.manager.add_dynamic_listener(`#${this.id}`, 'click', this.toggle_disable_args, this);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "option":
|
case 'option':
|
||||||
html += "<select class='arg' id='" + this.id + "'arg_name='" + this.name + "'" +
|
html += `<select class='arg' id='${this.id}'arg_name='${this.name}'${
|
||||||
(this.disabled ? " disabled='disabled'" : "") + ">";
|
this.disabled ? " disabled='disabled'" : ''}>`;
|
||||||
for (i = 0; i < this.value.length; i++) {
|
for (i = 0; i < this.value.length; i++) {
|
||||||
if (!!(m = this.value[i].match(/\[([a-z0-9 -()^]+)\]/i))) {
|
if (m = this.value[i].match(/\[([a-z0-9 -()^]+)\]/i)) {
|
||||||
html += "<optgroup label='" + m[1] + "'>";
|
html += `<optgroup label='${m[1]}'>`;
|
||||||
} else if (!!(m = this.value[i].match(/\[\/([a-z0-9 -()^]+)\]/i))) {
|
} else if (m = this.value[i].match(/\[\/([a-z0-9 -()^]+)\]/i)) {
|
||||||
html += "</optgroup>";
|
html += '</optgroup>';
|
||||||
} else {
|
} else {
|
||||||
html += "<option>" + this.value[i] + "</option>";
|
html += `<option>${this.value[i]}</option>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
html += "</select>";
|
html += '</select>';
|
||||||
break;
|
break;
|
||||||
case "populate_option":
|
case 'populate_option':
|
||||||
html += "<select class='arg' id='" + this.id + "'arg_name='" + this.name + "'" +
|
html += `<select class='arg' id='${this.id}'arg_name='${this.name}'${
|
||||||
(this.disabled ? " disabled='disabled'" : "") + ">";
|
this.disabled ? " disabled='disabled'" : ''}>`;
|
||||||
for (i = 0; i < this.value.length; i++) {
|
for (i = 0; i < this.value.length; i++) {
|
||||||
if (!!(m = this.value[i].name.match(/\[([a-z0-9 -()^]+)\]/i))) {
|
if (m = this.value[i].name.match(/\[([a-z0-9 -()^]+)\]/i)) {
|
||||||
html += "<optgroup label='" + m[1] + "'>";
|
html += `<optgroup label='${m[1]}'>`;
|
||||||
} else if (!!(m = this.value[i].name.match(/\[\/([a-z0-9 -()^]+)\]/i))) {
|
} else if (m = this.value[i].name.match(/\[\/([a-z0-9 -()^]+)\]/i)) {
|
||||||
html += "</optgroup>";
|
html += '</optgroup>';
|
||||||
} else {
|
} else {
|
||||||
html += "<option populate-value='" + this.value[i].value + "'>" +
|
html += `<option populate-value='${this.value[i].value}'>${
|
||||||
this.value[i].name + "</option>";
|
this.value[i].name}</option>`;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
html += "</select>";
|
html += '</select>';
|
||||||
|
|
||||||
this.manager.add_dynamic_listener("#" + this.id, "change", this.populate_option_change, this);
|
this.manager.add_dynamic_listener(`#${this.id}`, 'change', this.populate_option_change, this);
|
||||||
break;
|
break;
|
||||||
case "editable_option":
|
case 'editable_option':
|
||||||
html += "<div class='editable-option'>";
|
html += "<div class='editable-option'>";
|
||||||
html += "<select class='editable-option-select' id='sel-" + this.id + "'" +
|
html += `<select class='editable-option-select' id='sel-${this.id}'${
|
||||||
(this.disabled ? " disabled='disabled'" : "") + ">";
|
this.disabled ? " disabled='disabled'" : ''}>`;
|
||||||
for (i = 0; i < this.value.length; i++) {
|
for (i = 0; i < this.value.length; i++) {
|
||||||
html += "<option value='" + this.value[i].value + "'>" + this.value[i].name + "</option>";
|
html += `<option value='${this.value[i].value}'>${this.value[i].name}</option>`;
|
||||||
}
|
}
|
||||||
html += "</select>";
|
html += '</select>';
|
||||||
html += "<input class='arg arg-input editable-option-input' id='" + this.id +
|
html += `<input class='arg arg-input editable-option-input' id='${this.id
|
||||||
"'arg_name='" + this.name + "'" + " value='" + this.value[0].value + "'" +
|
}'arg_name='${this.name}'` + ` value='${this.value[0].value}'${
|
||||||
(this.disabled ? " disabled='disabled'" : "") +
|
this.disabled ? " disabled='disabled'" : ''
|
||||||
(this.placeholder ? " placeholder='" + this.placeholder + "'" : "") + ">";
|
}${this.placeholder ? ` placeholder='${this.placeholder}'` : ''}>`;
|
||||||
html += "</div>";
|
html += '</div>';
|
||||||
|
|
||||||
|
|
||||||
this.manager.add_dynamic_listener("#sel-" + this.id, "change", this.editable_option_change, this);
|
this.manager.add_dynamic_listener(`#sel-${this.id}`, 'change', this.editable_option_change, this);
|
||||||
break;
|
break;
|
||||||
case "text":
|
case 'text':
|
||||||
html += "<textarea id='" + this.id + "' class='arg' arg_name='" +
|
html += `<textarea id='${this.id}' class='arg' arg_name='${
|
||||||
this.name + "'" + (this.disabled ? " disabled='disabled'" : "") +
|
this.name}'${this.disabled ? " disabled='disabled'" : ''
|
||||||
(this.placeholder ? " placeholder='" + this.placeholder + "'" : "") + ">" +
|
}${this.placeholder ? ` placeholder='${this.placeholder}'` : ''}>${
|
||||||
this.value + "</textarea>";
|
this.value}</textarea>`;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
html += "</div>";
|
html += '</div>';
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -157,25 +158,25 @@ HTMLIngredient.prototype.to_html = function() {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
HTMLIngredient.prototype.toggle_disable_args = function(e) {
|
HTMLIngredient.prototype.toggle_disable_args = function (e) {
|
||||||
var el = e.target,
|
let el = e.target,
|
||||||
op = el.parentNode.parentNode,
|
op = el.parentNode.parentNode,
|
||||||
args = op.querySelectorAll(".arg-group"),
|
args = op.querySelectorAll('.arg-group'),
|
||||||
els;
|
els;
|
||||||
|
|
||||||
for (var i = 0; i < this.disable_args.length; i++) {
|
for (let i = 0; i < this.disable_args.length; i++) {
|
||||||
els = args[this.disable_args[i]].querySelectorAll("input, select, button");
|
els = args[this.disable_args[i]].querySelectorAll('input, select, button');
|
||||||
|
|
||||||
for (var j = 0; j < els.length; j++) {
|
for (let j = 0; j < els.length; j++) {
|
||||||
if (els[j].getAttribute("disabled")) {
|
if (els[j].getAttribute('disabled')) {
|
||||||
els[j].removeAttribute("disabled");
|
els[j].removeAttribute('disabled');
|
||||||
} else {
|
} else {
|
||||||
els[j].setAttribute("disabled", "disabled");
|
els[j].setAttribute('disabled', 'disabled');
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this.manager.recipe.ing_change();
|
this.manager.recipe.ing_change();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -185,14 +186,14 @@ HTMLIngredient.prototype.toggle_disable_args = function(e) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
HTMLIngredient.prototype.populate_option_change = function(e) {
|
HTMLIngredient.prototype.populate_option_change = function (e) {
|
||||||
var el = e.target,
|
let el = e.target,
|
||||||
op = el.parentNode.parentNode,
|
op = el.parentNode.parentNode,
|
||||||
target = op.querySelectorAll(".arg-group")[this.target].querySelector("input, select, textarea");
|
target = op.querySelectorAll('.arg-group')[this.target].querySelector('input, select, textarea');
|
||||||
|
|
||||||
target.value = el.childNodes[el.selectedIndex].getAttribute("populate-value");
|
target.value = el.childNodes[el.selectedIndex].getAttribute('populate-value');
|
||||||
|
|
||||||
this.manager.recipe.ing_change();
|
this.manager.recipe.ing_change();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -202,11 +203,11 @@ HTMLIngredient.prototype.populate_option_change = function(e) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
HTMLIngredient.prototype.editable_option_change = function(e) {
|
HTMLIngredient.prototype.editable_option_change = function (e) {
|
||||||
var select = e.target,
|
let select = e.target,
|
||||||
input = select.nextSibling;
|
input = select.nextSibling;
|
||||||
|
|
||||||
input.value = select.childNodes[select.selectedIndex].value;
|
input.value = select.childNodes[select.selectedIndex].value;
|
||||||
|
|
||||||
this.manager.recipe.ing_change();
|
this.manager.recipe.ing_change();
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,31 +11,31 @@
|
||||||
* @param {HTMLApp} app - The main view object for CyberChef.
|
* @param {HTMLApp} app - The main view object for CyberChef.
|
||||||
* @param {Manager} manager - The CyberChef event manager.
|
* @param {Manager} manager - The CyberChef event manager.
|
||||||
*/
|
*/
|
||||||
var HTMLOperation = function(name, config, app, manager) {
|
const HTMLOperation = function (name, config, app, manager) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
|
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.description = config.description;
|
this.description = config.description;
|
||||||
this.manual_bake = config.manual_bake || false;
|
this.manual_bake = config.manual_bake || false;
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.ing_list = [];
|
this.ing_list = [];
|
||||||
|
|
||||||
for (var i = 0; i < config.args.length; i++) {
|
for (let i = 0; i < config.args.length; i++) {
|
||||||
var ing = new HTMLIngredient(config.args[i], this.app, this.manager);
|
const ing = new HTMLIngredient(config.args[i], this.app, this.manager);
|
||||||
this.ing_list.push(ing);
|
this.ing_list.push(ing);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
*/
|
*/
|
||||||
HTMLOperation.INFO_ICON = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAByElEQVR4XqVTzWoaYRQ9KZJmoVaS1J1QiYTIuOgqi9lEugguQhYhdGs3hTyAi0CWJTvJIks30ZBNsimUtlqkVLoQCuJsphRriyFjabWtEyf/Rv3iWcwwymTlgQuH851z5hu43wRGkEwmXwCIA4hiGAUAmUQikQbhEHwyGCWVSglVVUW73RYmyKnxjB56ncJ6NpsVxHGrI/ZLuniVb3DIqQmCHnrNkgcggNeSJPlisRgyJR2b737j/TcDsQUPwv6H5NR4BnroZcb6Z16N2PvyX6yna9Z8qp6JQ0Uf0ughmGHWBSAuyzJqrQ7eqKewY/dzE363C71e39LoWQq5wUwul4uzIBoIBHD01RgyrkZ8eDbvwUWnj623v2DHx4qB51IAzLIAXq8XP/7W0bUVVJtXWIk8wvlN364TA+/1IDMLwmWK/Hq3axmhaBdoGLeklm73ElaBYRgIzkyifHIOO4QQJKM3oJcZq6CgaVp0OTyHw9K/kQI4FiyHfdC0n2CWe5ApFosIPZ7C2tNpXpcDOehGyD/FIbd0euhlhllzFxRzC3fydbG4XRYbB9/tQ41n9m1U7l3lyp9LkfygiZeZCoecmtMqj/+Yxn7Od3v0j50qCO3zAAAAAElFTkSuQmCC";
|
HTMLOperation.INFO_ICON = 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAByElEQVR4XqVTzWoaYRQ9KZJmoVaS1J1QiYTIuOgqi9lEugguQhYhdGs3hTyAi0CWJTvJIks30ZBNsimUtlqkVLoQCuJsphRriyFjabWtEyf/Rv3iWcwwymTlgQuH851z5hu43wRGkEwmXwCIA4hiGAUAmUQikQbhEHwyGCWVSglVVUW73RYmyKnxjB56ncJ6NpsVxHGrI/ZLuniVb3DIqQmCHnrNkgcggNeSJPlisRgyJR2b737j/TcDsQUPwv6H5NR4BnroZcb6Z16N2PvyX6yna9Z8qp6JQ0Uf0ughmGHWBSAuyzJqrQ7eqKewY/dzE363C71e39LoWQq5wUwul4uzIBoIBHD01RgyrkZ8eDbvwUWnj623v2DHx4qB51IAzLIAXq8XP/7W0bUVVJtXWIk8wvlN364TA+/1IDMLwmWK/Hq3axmhaBdoGLeklm73ElaBYRgIzkyifHIOO4QQJKM3oJcZq6CgaVp0OTyHw9K/kQI4FiyHfdC0n2CWe5ApFosIPZ7C2tNpXpcDOehGyD/FIbd0euhlhllzFxRzC3fydbG4XRYbB9/tQ41n9m1U7l3lyp9LkfygiZeZCoecmtMqj/+Yxn7Od3v0j50qCO3zAAAAAElFTkSuQmCC';
|
||||||
/**
|
/**
|
||||||
* @constant
|
* @constant
|
||||||
*/
|
*/
|
||||||
HTMLOperation.REMOVE_ICON = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABwklEQVR42qRTPU8CQRB9K2CCMRJ6NTQajOUaqfxIbLCRghhjQixosLAgFNBQ3l8wsabxLxBJbCyVUBiMCVQEQkOEKBbCnefM3p4eohWXzM3uvHlv52b2hG3bmOWZw4yPn1/XQkCQ9wFxcgZZ0QLKpifpN8Z1n1L13griBBjHhYK0nMT4b+wom53ClAAFQacZJ/m8rNfrSOZy0vxJjPP6IJ2WzWYTO6mUwiwtILiJJSHUKVSWkchkZK1WQzQaxU2pVGUglkjIbreLUCiEx0qlStlFCpfPiPstYDtVKJH9ZFI2Gw1FGA6H6LTbCAaDeGu1FJl6UuYjpwTGzucokZW1NfnS66kyfT4fXns9RaZmlgNcuhZQU+jowLzuOK/HgwEW3E5ZlhLXVWKk11P3wNYNWw+HZdA0sUgx1zjGmD05nckx0ilGjBJdUq3fr7K5e8bGf43RdL7fOPSQb4lI8SLbrUfkUIuY32VTI1bJn5BqDnh4Dodt9ryPUDzyD7aquWoKQohl2i9sAbubwPkTcHkP3FHsg+yT+7sN7G0AF3Xg6sHB3onbdgWWKBDQg/BcTuVt51dQA/JrnIcyIu6rmPV3/hJgACPc0BMEYTg+AAAAAElFTkSuQmCC";
|
HTMLOperation.REMOVE_ICON = 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABwklEQVR42qRTPU8CQRB9K2CCMRJ6NTQajOUaqfxIbLCRghhjQixosLAgFNBQ3l8wsabxLxBJbCyVUBiMCVQEQkOEKBbCnefM3p4eohWXzM3uvHlv52b2hG3bmOWZw4yPn1/XQkCQ9wFxcgZZ0QLKpifpN8Z1n1L13griBBjHhYK0nMT4b+wom53ClAAFQacZJ/m8rNfrSOZy0vxJjPP6IJ2WzWYTO6mUwiwtILiJJSHUKVSWkchkZK1WQzQaxU2pVGUglkjIbreLUCiEx0qlStlFCpfPiPstYDtVKJH9ZFI2Gw1FGA6H6LTbCAaDeGu1FJl6UuYjpwTGzucokZW1NfnS66kyfT4fXns9RaZmlgNcuhZQU+jowLzuOK/HgwEW3E5ZlhLXVWKk11P3wNYNWw+HZdA0sUgx1zjGmD05nckx0ilGjBJdUq3fr7K5e8bGf43RdL7fOPSQb4lI8SLbrUfkUIuY32VTI1bJn5BqDnh4Dodt9ryPUDzyD7aquWoKQohl2i9sAbubwPkTcHkP3FHsg+yT+7sN7G0AF3Xg6sHB3onbdgWWKBDQg/BcTuVt51dQA/JrnIcyIu6rmPV3/hJgACPc0BMEYTg+AAAAAElFTkSuQmCC';
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,28 +43,28 @@ HTMLOperation.REMOVE_ICON = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABwkl
|
||||||
*
|
*
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
HTMLOperation.prototype.to_stub_html = function(remove_icon) {
|
HTMLOperation.prototype.to_stub_html = function (remove_icon) {
|
||||||
var html = "<li class='operation'";
|
let html = "<li class='operation'";
|
||||||
|
|
||||||
if (this.description) {
|
if (this.description) {
|
||||||
html += " data-container='body' data-toggle='popover' data-placement='auto right'\
|
html += ` data-container='body' data-toggle='popover' data-placement='auto right'\
|
||||||
data-content=\"" + this.description + "\" data-html='true' data-trigger='hover'";
|
data-content="${this.description}" data-html='true' data-trigger='hover'`;
|
||||||
}
|
}
|
||||||
|
|
||||||
html += ">" + this.name;
|
html += `>${this.name}`;
|
||||||
|
|
||||||
if (remove_icon) {
|
if (remove_icon) {
|
||||||
html += "<img src='data:image/png;base64," + HTMLOperation.REMOVE_ICON +
|
html += `<img src='data:image/png;base64,${HTMLOperation.REMOVE_ICON
|
||||||
"' class='op-icon remove-icon'>";
|
}' class='op-icon remove-icon'>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.description) {
|
if (this.description) {
|
||||||
html += "<img src='data:image/png;base64," + HTMLOperation.INFO_ICON + "' class='op-icon'>";
|
html += `<img src='data:image/png;base64,${HTMLOperation.INFO_ICON}' class='op-icon'>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
html += "</li>";
|
html += '</li>';
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,22 +73,22 @@ HTMLOperation.prototype.to_stub_html = function(remove_icon) {
|
||||||
*
|
*
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
HTMLOperation.prototype.to_full_html = function() {
|
HTMLOperation.prototype.to_full_html = function () {
|
||||||
var html = "<div class='arg-title'>" + this.name + "</div>";
|
let html = `<div class='arg-title'>${this.name}</div>`;
|
||||||
|
|
||||||
for (var i = 0; i < this.ing_list.length; i++) {
|
for (let i = 0; i < this.ing_list.length; i++) {
|
||||||
html += this.ing_list[i].to_html();
|
html += this.ing_list[i].to_html();
|
||||||
}
|
}
|
||||||
|
|
||||||
html += "<div class='recip-icons'>\
|
html += "<div class='recip-icons'>\
|
||||||
<div class='breakpoint' title='Set breakpoint' break='false'></div>\
|
<div class='breakpoint' title='Set breakpoint' break='false'></div>\
|
||||||
<div class='disable-icon recip-icon' title='Disable operation'\
|
<div class='disable-icon recip-icon' title='Disable operation'\
|
||||||
disabled='false'></div>";
|
disabled='false'></div>";
|
||||||
|
|
||||||
html += "</div>\
|
html += "</div>\
|
||||||
<div class='clearfix'> </div>";
|
<div class='clearfix'> </div>";
|
||||||
|
|
||||||
return html;
|
return html;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -99,16 +99,16 @@ HTMLOperation.prototype.to_full_html = function() {
|
||||||
* @param {number} name_pos - The position of the search string in the operation name
|
* @param {number} name_pos - The position of the search string in the operation name
|
||||||
* @param {number} desc_pos - The position of the search string in the operation description
|
* @param {number} desc_pos - The position of the search string in the operation description
|
||||||
*/
|
*/
|
||||||
HTMLOperation.prototype.highlight_search_string = function(search_str, name_pos, desc_pos) {
|
HTMLOperation.prototype.highlight_search_string = function (search_str, name_pos, desc_pos) {
|
||||||
if (name_pos >= 0) {
|
if (name_pos >= 0) {
|
||||||
this.name = this.name.slice(0, name_pos) + "<b><u>" +
|
this.name = `${this.name.slice(0, name_pos)}<b><u>${
|
||||||
this.name.slice(name_pos, name_pos + search_str.length) + "</u></b>" +
|
this.name.slice(name_pos, name_pos + search_str.length)}</u></b>${
|
||||||
this.name.slice(name_pos + search_str.length);
|
this.name.slice(name_pos + search_str.length)}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.description && desc_pos >= 0) {
|
if (this.description && desc_pos >= 0) {
|
||||||
this.description = this.description.slice(0, desc_pos) + "<b><u>" +
|
this.description = `${this.description.slice(0, desc_pos)}<b><u>${
|
||||||
this.description.slice(desc_pos, desc_pos + search_str.length) + "</u></b>" +
|
this.description.slice(desc_pos, desc_pos + search_str.length)}</u></b>${
|
||||||
this.description.slice(desc_pos + search_str.length);
|
this.description.slice(desc_pos + search_str.length)}`;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,11 +8,11 @@
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {HTMLApp} app - The main view object for CyberChef.
|
* @param {HTMLApp} app - The main view object for CyberChef.
|
||||||
*/
|
*/
|
||||||
var HighlighterWaiter = function(app) {
|
const HighlighterWaiter = function (app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
|
||||||
this.mouse_button_down = false;
|
this.mouse_button_down = false;
|
||||||
this.mouse_target = null;
|
this.mouse_target = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ var HighlighterWaiter = function(app) {
|
||||||
* @readonly
|
* @readonly
|
||||||
* @enum
|
* @enum
|
||||||
*/
|
*/
|
||||||
HighlighterWaiter.INPUT = 0;
|
HighlighterWaiter.INPUT = 0;
|
||||||
/**
|
/**
|
||||||
* HighlighterWaiter data type enum for the output.
|
* HighlighterWaiter data type enum for the output.
|
||||||
* @readonly
|
* @readonly
|
||||||
|
@ -37,18 +37,18 @@ HighlighterWaiter.OUTPUT = 1;
|
||||||
* @private
|
* @private
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
HighlighterWaiter.prototype._is_selection_backwards = function() {
|
HighlighterWaiter.prototype._is_selection_backwards = function () {
|
||||||
var backwards = false,
|
let backwards = false,
|
||||||
sel = window.getSelection();
|
sel = window.getSelection();
|
||||||
|
|
||||||
if (!sel.isCollapsed) {
|
if (!sel.isCollapsed) {
|
||||||
var range = document.createRange();
|
const range = document.createRange();
|
||||||
range.setStart(sel.anchorNode, sel.anchorOffset);
|
range.setStart(sel.anchorNode, sel.anchorOffset);
|
||||||
range.setEnd(sel.focusNode, sel.focusOffset);
|
range.setEnd(sel.focusNode, sel.focusOffset);
|
||||||
backwards = range.collapsed;
|
backwards = range.collapsed;
|
||||||
range.detach();
|
range.detach();
|
||||||
}
|
}
|
||||||
return backwards;
|
return backwards;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,16 +60,16 @@ HighlighterWaiter.prototype._is_selection_backwards = function() {
|
||||||
* @param {number} offset - The offset since the last HTML element.
|
* @param {number} offset - The offset since the last HTML element.
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
HighlighterWaiter.prototype._get_output_html_offset = function(node, offset) {
|
HighlighterWaiter.prototype._get_output_html_offset = function (node, offset) {
|
||||||
var sel = window.getSelection(),
|
let sel = window.getSelection(),
|
||||||
range = document.createRange();
|
range = document.createRange();
|
||||||
|
|
||||||
range.selectNodeContents(document.getElementById("output-html"));
|
range.selectNodeContents(document.getElementById('output-html'));
|
||||||
range.setEnd(node, offset);
|
range.setEnd(node, offset);
|
||||||
sel.removeAllRanges();
|
sel.removeAllRanges();
|
||||||
sel.addRange(range);
|
sel.addRange(range);
|
||||||
|
|
||||||
return sel.toString().length;
|
return sel.toString().length;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,33 +81,33 @@ HighlighterWaiter.prototype._get_output_html_offset = function(node, offset) {
|
||||||
* @returns {number} pos.start
|
* @returns {number} pos.start
|
||||||
* @returns {number} pos.end
|
* @returns {number} pos.end
|
||||||
*/
|
*/
|
||||||
HighlighterWaiter.prototype._get_output_html_selection_offsets = function() {
|
HighlighterWaiter.prototype._get_output_html_selection_offsets = function () {
|
||||||
var sel = window.getSelection(),
|
let sel = window.getSelection(),
|
||||||
range,
|
range,
|
||||||
start = 0,
|
start = 0,
|
||||||
end = 0,
|
end = 0,
|
||||||
backwards = false;
|
backwards = false;
|
||||||
|
|
||||||
if (sel.rangeCount) {
|
if (sel.rangeCount) {
|
||||||
range = sel.getRangeAt(sel.rangeCount - 1);
|
range = sel.getRangeAt(sel.rangeCount - 1);
|
||||||
backwards = this._is_selection_backwards();
|
backwards = this._is_selection_backwards();
|
||||||
start = this._get_output_html_offset(range.startContainer, range.startOffset);
|
start = this._get_output_html_offset(range.startContainer, range.startOffset);
|
||||||
end = this._get_output_html_offset(range.endContainer, range.endOffset);
|
end = this._get_output_html_offset(range.endContainer, range.endOffset);
|
||||||
sel.removeAllRanges();
|
sel.removeAllRanges();
|
||||||
sel.addRange(range);
|
sel.addRange(range);
|
||||||
|
|
||||||
if (backwards) {
|
if (backwards) {
|
||||||
// If selecting backwards, reverse the start and end offsets for the selection to
|
// If selecting backwards, reverse the start and end offsets for the selection to
|
||||||
// prevent deselecting as the drag continues.
|
// prevent deselecting as the drag continues.
|
||||||
sel.collapseToEnd();
|
sel.collapseToEnd();
|
||||||
sel.extend(sel.anchorNode, range.startOffset);
|
sel.extend(sel.anchorNode, range.startOffset);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
start: start,
|
start,
|
||||||
end: end
|
end,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,10 +117,10 @@ HighlighterWaiter.prototype._get_output_html_selection_offsets = function() {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
HighlighterWaiter.prototype.input_scroll = function(e) {
|
HighlighterWaiter.prototype.input_scroll = function (e) {
|
||||||
var el = e.target;
|
const el = e.target;
|
||||||
document.getElementById("input-highlighter").scrollTop = el.scrollTop;
|
document.getElementById('input-highlighter').scrollTop = el.scrollTop;
|
||||||
document.getElementById("input-highlighter").scrollLeft = el.scrollLeft;
|
document.getElementById('input-highlighter').scrollLeft = el.scrollLeft;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -130,10 +130,10 @@ HighlighterWaiter.prototype.input_scroll = function(e) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
HighlighterWaiter.prototype.output_scroll = function(e) {
|
HighlighterWaiter.prototype.output_scroll = function (e) {
|
||||||
var el = e.target;
|
const el = e.target;
|
||||||
document.getElementById("output-highlighter").scrollTop = el.scrollTop;
|
document.getElementById('output-highlighter').scrollTop = el.scrollTop;
|
||||||
document.getElementById("output-highlighter").scrollLeft = el.scrollLeft;
|
document.getElementById('output-highlighter').scrollLeft = el.scrollLeft;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -143,19 +143,19 @@ HighlighterWaiter.prototype.output_scroll = function(e) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
HighlighterWaiter.prototype.input_mousedown = function(e) {
|
HighlighterWaiter.prototype.input_mousedown = function (e) {
|
||||||
this.mouse_button_down = true;
|
this.mouse_button_down = true;
|
||||||
this.mouse_target = HighlighterWaiter.INPUT;
|
this.mouse_target = HighlighterWaiter.INPUT;
|
||||||
this.remove_highlights();
|
this.remove_highlights();
|
||||||
|
|
||||||
var el = e.target,
|
let el = e.target,
|
||||||
start = el.selectionStart,
|
start = el.selectionStart,
|
||||||
end = el.selectionEnd;
|
end = el.selectionEnd;
|
||||||
|
|
||||||
if (start !== 0 || end !== 0) {
|
if (start !== 0 || end !== 0) {
|
||||||
document.getElementById("input-selection-info").innerHTML = this.selection_info(start, end);
|
document.getElementById('input-selection-info').innerHTML = this.selection_info(start, end);
|
||||||
this.highlight_output([{start: start, end: end}]);
|
this.highlight_output([{ start, end }]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -165,19 +165,19 @@ HighlighterWaiter.prototype.input_mousedown = function(e) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
HighlighterWaiter.prototype.output_mousedown = function(e) {
|
HighlighterWaiter.prototype.output_mousedown = function (e) {
|
||||||
this.mouse_button_down = true;
|
this.mouse_button_down = true;
|
||||||
this.mouse_target = HighlighterWaiter.OUTPUT;
|
this.mouse_target = HighlighterWaiter.OUTPUT;
|
||||||
this.remove_highlights();
|
this.remove_highlights();
|
||||||
|
|
||||||
var el = e.target,
|
let el = e.target,
|
||||||
start = el.selectionStart,
|
start = el.selectionStart,
|
||||||
end = el.selectionEnd;
|
end = el.selectionEnd;
|
||||||
|
|
||||||
if (start !== 0 || end !== 0) {
|
if (start !== 0 || end !== 0) {
|
||||||
document.getElementById("output-selection-info").innerHTML = this.selection_info(start, end);
|
document.getElementById('output-selection-info').innerHTML = this.selection_info(start, end);
|
||||||
this.highlight_input([{start: start, end: end}]);
|
this.highlight_input([{ start, end }]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -187,14 +187,14 @@ HighlighterWaiter.prototype.output_mousedown = function(e) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
HighlighterWaiter.prototype.output_html_mousedown = function(e) {
|
HighlighterWaiter.prototype.output_html_mousedown = function (e) {
|
||||||
this.mouse_button_down = true;
|
this.mouse_button_down = true;
|
||||||
this.mouse_target = HighlighterWaiter.OUTPUT;
|
this.mouse_target = HighlighterWaiter.OUTPUT;
|
||||||
|
|
||||||
var sel = this._get_output_html_selection_offsets();
|
const sel = this._get_output_html_selection_offsets();
|
||||||
if (sel.start !== 0 || sel.end !== 0) {
|
if (sel.start !== 0 || sel.end !== 0) {
|
||||||
document.getElementById("output-selection-info").innerHTML = this.selection_info(sel.start, sel.end);
|
document.getElementById('output-selection-info').innerHTML = this.selection_info(sel.start, sel.end);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -203,8 +203,8 @@ HighlighterWaiter.prototype.output_html_mousedown = function(e) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
HighlighterWaiter.prototype.input_mouseup = function(e) {
|
HighlighterWaiter.prototype.input_mouseup = function (e) {
|
||||||
this.mouse_button_down = false;
|
this.mouse_button_down = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -213,8 +213,8 @@ HighlighterWaiter.prototype.input_mouseup = function(e) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
HighlighterWaiter.prototype.output_mouseup = function(e) {
|
HighlighterWaiter.prototype.output_mouseup = function (e) {
|
||||||
this.mouse_button_down = false;
|
this.mouse_button_down = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -223,8 +223,8 @@ HighlighterWaiter.prototype.output_mouseup = function(e) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
HighlighterWaiter.prototype.output_html_mouseup = function(e) {
|
HighlighterWaiter.prototype.output_html_mouseup = function (e) {
|
||||||
this.mouse_button_down = false;
|
this.mouse_button_down = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -234,21 +234,20 @@ HighlighterWaiter.prototype.output_html_mouseup = function(e) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
HighlighterWaiter.prototype.input_mousemove = function(e) {
|
HighlighterWaiter.prototype.input_mousemove = function (e) {
|
||||||
// Check that the left mouse button is pressed
|
// Check that the left mouse button is pressed
|
||||||
if (!this.mouse_button_down ||
|
if (!this.mouse_button_down ||
|
||||||
e.which != 1 ||
|
e.which != 1 ||
|
||||||
this.mouse_target != HighlighterWaiter.INPUT)
|
this.mouse_target != HighlighterWaiter.INPUT) { return; }
|
||||||
return;
|
|
||||||
|
|
||||||
var el = e.target,
|
let el = e.target,
|
||||||
start = el.selectionStart,
|
start = el.selectionStart,
|
||||||
end = el.selectionEnd;
|
end = el.selectionEnd;
|
||||||
|
|
||||||
if (start !== 0 || end !== 0) {
|
if (start !== 0 || end !== 0) {
|
||||||
document.getElementById("input-selection-info").innerHTML = this.selection_info(start, end);
|
document.getElementById('input-selection-info').innerHTML = this.selection_info(start, end);
|
||||||
this.highlight_output([{start: start, end: end}]);
|
this.highlight_output([{ start, end }]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -258,21 +257,20 @@ HighlighterWaiter.prototype.input_mousemove = function(e) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
HighlighterWaiter.prototype.output_mousemove = function(e) {
|
HighlighterWaiter.prototype.output_mousemove = function (e) {
|
||||||
// Check that the left mouse button is pressed
|
// Check that the left mouse button is pressed
|
||||||
if (!this.mouse_button_down ||
|
if (!this.mouse_button_down ||
|
||||||
e.which != 1 ||
|
e.which != 1 ||
|
||||||
this.mouse_target != HighlighterWaiter.OUTPUT)
|
this.mouse_target != HighlighterWaiter.OUTPUT) { return; }
|
||||||
return;
|
|
||||||
|
|
||||||
var el = e.target,
|
let el = e.target,
|
||||||
start = el.selectionStart,
|
start = el.selectionStart,
|
||||||
end = el.selectionEnd;
|
end = el.selectionEnd;
|
||||||
|
|
||||||
if (start !== 0 || end !== 0) {
|
if (start !== 0 || end !== 0) {
|
||||||
document.getElementById("output-selection-info").innerHTML = this.selection_info(start, end);
|
document.getElementById('output-selection-info').innerHTML = this.selection_info(start, end);
|
||||||
this.highlight_input([{start: start, end: end}]);
|
this.highlight_input([{ start, end }]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -282,17 +280,16 @@ HighlighterWaiter.prototype.output_mousemove = function(e) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
HighlighterWaiter.prototype.output_html_mousemove = function(e) {
|
HighlighterWaiter.prototype.output_html_mousemove = function (e) {
|
||||||
// Check that the left mouse button is pressed
|
// Check that the left mouse button is pressed
|
||||||
if (!this.mouse_button_down ||
|
if (!this.mouse_button_down ||
|
||||||
e.which != 1 ||
|
e.which != 1 ||
|
||||||
this.mouse_target != HighlighterWaiter.OUTPUT)
|
this.mouse_target != HighlighterWaiter.OUTPUT) { return; }
|
||||||
return;
|
|
||||||
|
|
||||||
var sel = this._get_output_html_selection_offsets();
|
const sel = this._get_output_html_selection_offsets();
|
||||||
if (sel.start !== 0 || sel.end !== 0) {
|
if (sel.start !== 0 || sel.end !== 0) {
|
||||||
document.getElementById("output-selection-info").innerHTML = this.selection_info(sel.start, sel.end);
|
document.getElementById('output-selection-info').innerHTML = this.selection_info(sel.start, sel.end);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -304,25 +301,25 @@ HighlighterWaiter.prototype.output_html_mousemove = function(e) {
|
||||||
* @param {number} end - The end offset.
|
* @param {number} end - The end offset.
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
HighlighterWaiter.prototype.selection_info = function(start, end) {
|
HighlighterWaiter.prototype.selection_info = function (start, end) {
|
||||||
var width = end.toString().length;
|
let width = end.toString().length;
|
||||||
width = width < 2 ? 2 : width;
|
width = width < 2 ? 2 : width;
|
||||||
var start_str = Utils.pad(start.toString(), width, " ").replace(/ /g, " "),
|
let start_str = Utils.pad(start.toString(), width, ' ').replace(/ /g, ' '),
|
||||||
end_str = Utils.pad(end.toString(), width, " ").replace(/ /g, " "),
|
end_str = Utils.pad(end.toString(), width, ' ').replace(/ /g, ' '),
|
||||||
len_str = Utils.pad((end-start).toString(), width, " ").replace(/ /g, " ");
|
len_str = Utils.pad((end - start).toString(), width, ' ').replace(/ /g, ' ');
|
||||||
|
|
||||||
return "start: " + start_str + "<br>end: " + end_str + "<br>length: " + len_str;
|
return `start: ${start_str}<br>end: ${end_str}<br>length: ${len_str}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes highlighting and selection information.
|
* Removes highlighting and selection information.
|
||||||
*/
|
*/
|
||||||
HighlighterWaiter.prototype.remove_highlights = function() {
|
HighlighterWaiter.prototype.remove_highlights = function () {
|
||||||
document.getElementById("input-highlighter").innerHTML = "";
|
document.getElementById('input-highlighter').innerHTML = '';
|
||||||
document.getElementById("output-highlighter").innerHTML = "";
|
document.getElementById('output-highlighter').innerHTML = '';
|
||||||
document.getElementById("input-selection-info").innerHTML = "";
|
document.getElementById('input-selection-info').innerHTML = '';
|
||||||
document.getElementById("output-selection-info").innerHTML = "";
|
document.getElementById('output-selection-info').innerHTML = '';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -335,29 +332,29 @@ HighlighterWaiter.prototype.remove_highlights = function() {
|
||||||
* @returns {function} highlights[].b
|
* @returns {function} highlights[].b
|
||||||
* @returns {Object[]} highlights[].args
|
* @returns {Object[]} highlights[].args
|
||||||
*/
|
*/
|
||||||
HighlighterWaiter.prototype.generate_highlight_list = function() {
|
HighlighterWaiter.prototype.generate_highlight_list = function () {
|
||||||
var recipe_config = this.app.get_recipe_config(),
|
let recipe_config = this.app.get_recipe_config(),
|
||||||
highlights = [];
|
highlights = [];
|
||||||
|
|
||||||
for (var i = 0; i < recipe_config.length; i++) {
|
for (let i = 0; i < recipe_config.length; i++) {
|
||||||
if (recipe_config[i].disabled) continue;
|
if (recipe_config[i].disabled) continue;
|
||||||
|
|
||||||
// If any breakpoints are set, do not attempt to highlight
|
// If any breakpoints are set, do not attempt to highlight
|
||||||
if (recipe_config[i].breakpoint) return false;
|
if (recipe_config[i].breakpoint) return false;
|
||||||
|
|
||||||
var op = this.app.operations[recipe_config[i].op];
|
const op = this.app.operations[recipe_config[i].op];
|
||||||
|
|
||||||
// If any of the operations do not support highlighting, fail immediately.
|
// If any of the operations do not support highlighting, fail immediately.
|
||||||
if (op.highlight === false || op.highlight === undefined) return false;
|
if (op.highlight === false || op.highlight === undefined) return false;
|
||||||
|
|
||||||
highlights.push({
|
highlights.push({
|
||||||
f: op.highlight,
|
f: op.highlight,
|
||||||
b: op.highlight_reverse,
|
b: op.highlight_reverse,
|
||||||
args: recipe_config[i].args
|
args: recipe_config[i].args,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return highlights;
|
return highlights;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -372,26 +369,26 @@ HighlighterWaiter.prototype.generate_highlight_list = function() {
|
||||||
* @param {number} pos.start - The start offset.
|
* @param {number} pos.start - The start offset.
|
||||||
* @param {number} pos.end - The end offset.
|
* @param {number} pos.end - The end offset.
|
||||||
*/
|
*/
|
||||||
HighlighterWaiter.prototype.highlight_output = function(pos) {
|
HighlighterWaiter.prototype.highlight_output = function (pos) {
|
||||||
var highlights = this.generate_highlight_list();
|
const highlights = this.generate_highlight_list();
|
||||||
|
|
||||||
if (!highlights || !this.app.auto_bake_) {
|
if (!highlights || !this.app.auto_bake_) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < highlights.length; i++) {
|
for (let i = 0; i < highlights.length; i++) {
|
||||||
// Remove multiple highlights before processing again
|
// Remove multiple highlights before processing again
|
||||||
pos = [pos[0]];
|
pos = [pos[0]];
|
||||||
|
|
||||||
if (typeof highlights[i].f == "function") {
|
if (typeof highlights[i].f === 'function') {
|
||||||
pos = highlights[i].f(pos, highlights[i].args);
|
pos = highlights[i].f(pos, highlights[i].args);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
document.getElementById("output-selection-info").innerHTML = this.selection_info(pos[0].start, pos[0].end);
|
document.getElementById('output-selection-info').innerHTML = this.selection_info(pos[0].start, pos[0].end);
|
||||||
this.highlight(
|
this.highlight(
|
||||||
document.getElementById("output-text"),
|
document.getElementById('output-text'),
|
||||||
document.getElementById("output-highlighter"),
|
document.getElementById('output-highlighter'),
|
||||||
pos);
|
pos);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -407,26 +404,26 @@ HighlighterWaiter.prototype.highlight_output = function(pos) {
|
||||||
* @param {number} pos.start - The start offset.
|
* @param {number} pos.start - The start offset.
|
||||||
* @param {number} pos.end - The end offset.
|
* @param {number} pos.end - The end offset.
|
||||||
*/
|
*/
|
||||||
HighlighterWaiter.prototype.highlight_input = function(pos) {
|
HighlighterWaiter.prototype.highlight_input = function (pos) {
|
||||||
var highlights = this.generate_highlight_list();
|
const highlights = this.generate_highlight_list();
|
||||||
|
|
||||||
if (!highlights || !this.app.auto_bake_) {
|
if (!highlights || !this.app.auto_bake_) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < highlights.length; i++) {
|
for (let i = 0; i < highlights.length; i++) {
|
||||||
// Remove multiple highlights before processing again
|
// Remove multiple highlights before processing again
|
||||||
pos = [pos[0]];
|
pos = [pos[0]];
|
||||||
|
|
||||||
if (typeof highlights[i].b == "function") {
|
if (typeof highlights[i].b === 'function') {
|
||||||
pos = highlights[i].b(pos, highlights[i].args);
|
pos = highlights[i].b(pos, highlights[i].args);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
document.getElementById("input-selection-info").innerHTML = this.selection_info(pos[0].start, pos[0].end);
|
document.getElementById('input-selection-info').innerHTML = this.selection_info(pos[0].start, pos[0].end);
|
||||||
this.highlight(
|
this.highlight(
|
||||||
document.getElementById("input-text"),
|
document.getElementById('input-text'),
|
||||||
document.getElementById("input-highlighter"),
|
document.getElementById('input-highlighter'),
|
||||||
pos);
|
pos);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -441,66 +438,66 @@ HighlighterWaiter.prototype.highlight_input = function(pos) {
|
||||||
* @param {number} pos.start - The start offset.
|
* @param {number} pos.start - The start offset.
|
||||||
* @param {number} pos.end - The end offset.
|
* @param {number} pos.end - The end offset.
|
||||||
*/
|
*/
|
||||||
HighlighterWaiter.prototype.highlight = function(textarea, highlighter, pos) {
|
HighlighterWaiter.prototype.highlight = function (textarea, highlighter, pos) {
|
||||||
if (!this.app.options.show_highlighter) return false;
|
if (!this.app.options.show_highlighter) return false;
|
||||||
if (!this.app.options.attempt_highlight) return false;
|
if (!this.app.options.attempt_highlight) return false;
|
||||||
|
|
||||||
// Check if there is a carriage return in the output dish as this will not
|
// Check if there is a carriage return in the output dish as this will not
|
||||||
// be displayed by the HTML textarea and will mess up highlighting offsets.
|
// be displayed by the HTML textarea and will mess up highlighting offsets.
|
||||||
if (!this.app.dish_str || this.app.dish_str.indexOf("\r") >= 0) return false;
|
if (!this.app.dish_str || this.app.dish_str.indexOf('\r') >= 0) return false;
|
||||||
|
|
||||||
var start_placeholder = "[start_highlight]",
|
let start_placeholder = '[start_highlight]',
|
||||||
start_placeholder_regex = /\[start_highlight\]/g,
|
start_placeholder_regex = /\[start_highlight\]/g,
|
||||||
end_placeholder = "[end_highlight]",
|
end_placeholder = '[end_highlight]',
|
||||||
end_placeholder_regex = /\[end_highlight\]/g,
|
end_placeholder_regex = /\[end_highlight\]/g,
|
||||||
text = textarea.value;
|
text = textarea.value;
|
||||||
|
|
||||||
// Put placeholders in position
|
// Put placeholders in position
|
||||||
// If there's only one value, select that
|
// If there's only one value, select that
|
||||||
// If there are multiple, ignore the first one and select all others
|
// If there are multiple, ignore the first one and select all others
|
||||||
if (pos.length == 1) {
|
if (pos.length == 1) {
|
||||||
if (pos[0].end < pos[0].start) return;
|
if (pos[0].end < pos[0].start) return;
|
||||||
text = text.slice(0, pos[0].start) +
|
text = text.slice(0, pos[0].start) +
|
||||||
start_placeholder + text.slice(pos[0].start, pos[0].end) + end_placeholder +
|
start_placeholder + text.slice(pos[0].start, pos[0].end) + end_placeholder +
|
||||||
text.slice(pos[0].end, text.length);
|
text.slice(pos[0].end, text.length);
|
||||||
} else {
|
} else {
|
||||||
// O(n^2) - Can anyone improve this without overwriting placeholders?
|
// O(n^2) - Can anyone improve this without overwriting placeholders?
|
||||||
var result = "",
|
let result = '',
|
||||||
end_placed = true;
|
end_placed = true;
|
||||||
|
|
||||||
for (var i = 0; i < text.length; i++) {
|
for (let i = 0; i < text.length; i++) {
|
||||||
for (var j = 1; j < pos.length; j++) {
|
for (let j = 1; j < pos.length; j++) {
|
||||||
if (pos[j].end < pos[j].start) continue;
|
if (pos[j].end < pos[j].start) continue;
|
||||||
if (pos[j].start == i) {
|
if (pos[j].start == i) {
|
||||||
result += start_placeholder;
|
result += start_placeholder;
|
||||||
end_placed = false;
|
end_placed = false;
|
||||||
}
|
|
||||||
if (pos[j].end == i) {
|
|
||||||
result += end_placeholder;
|
|
||||||
end_placed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result += text[i];
|
|
||||||
}
|
}
|
||||||
if (!end_placed) result += end_placeholder;
|
if (pos[j].end == i) {
|
||||||
text = result;
|
result += end_placeholder;
|
||||||
|
end_placed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result += text[i];
|
||||||
}
|
}
|
||||||
|
if (!end_placed) result += end_placeholder;
|
||||||
|
text = result;
|
||||||
|
}
|
||||||
|
|
||||||
var css_class = "hl1";
|
const css_class = 'hl1';
|
||||||
//if (colour) css_class += "-"+colour;
|
// if (colour) css_class += "-"+colour;
|
||||||
|
|
||||||
// Remove HTML tags
|
// Remove HTML tags
|
||||||
text = text.replace(/&/g, "&")
|
text = `${text.replace(/&/g, '&')
|
||||||
.replace(/</g, "<")
|
.replace(/</g, '<')
|
||||||
.replace(/>/g, ">")
|
.replace(/>/g, '>')
|
||||||
.replace(/\n/g, " ")
|
.replace(/\n/g, ' ')
|
||||||
// Convert placeholders to tags
|
// Convert placeholders to tags
|
||||||
.replace(start_placeholder_regex, "<span class=\""+css_class+"\">")
|
.replace(start_placeholder_regex, `<span class="${css_class}">`)
|
||||||
.replace(end_placeholder_regex, "</span>") + " ";
|
.replace(end_placeholder_regex, '</span>')} `;
|
||||||
|
|
||||||
// Adjust width to allow for scrollbars
|
// Adjust width to allow for scrollbars
|
||||||
highlighter.style.width = textarea.clientWidth + "px";
|
highlighter.style.width = `${textarea.clientWidth}px`;
|
||||||
highlighter.innerHTML = text;
|
highlighter.innerHTML = text;
|
||||||
highlighter.scrollTop = textarea.scrollTop;
|
highlighter.scrollTop = textarea.scrollTop;
|
||||||
highlighter.scrollLeft = textarea.scrollLeft;
|
highlighter.scrollLeft = textarea.scrollLeft;
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,27 +9,27 @@
|
||||||
* @param {HTMLApp} app - The main view object for CyberChef.
|
* @param {HTMLApp} app - The main view object for CyberChef.
|
||||||
* @param {Manager} manager - The CyberChef event manager.
|
* @param {Manager} manager - The CyberChef event manager.
|
||||||
*/
|
*/
|
||||||
var InputWaiter = function(app, manager) {
|
const InputWaiter = function (app, manager) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
|
|
||||||
// Define keys that don't change the input so we don't have to autobake when they are pressed
|
// Define keys that don't change the input so we don't have to autobake when they are pressed
|
||||||
this.bad_keys = [
|
this.bad_keys = [
|
||||||
16, //Shift
|
16, // Shift
|
||||||
17, //Ctrl
|
17, // Ctrl
|
||||||
18, //Alt
|
18, // Alt
|
||||||
19, //Pause
|
19, // Pause
|
||||||
20, //Caps
|
20, // Caps
|
||||||
27, //Esc
|
27, // Esc
|
||||||
33,34,35,36, //PgUp, PgDn, End, Home
|
33, 34, 35, 36, // PgUp, PgDn, End, Home
|
||||||
37,38,39,40, //Directional
|
37, 38, 39, 40, // Directional
|
||||||
44, //PrntScrn
|
44, // PrntScrn
|
||||||
91,92, //Win
|
91, 92, // Win
|
||||||
93, //Context
|
93, // Context
|
||||||
112,113,114,115,116,117,118,119,120,121,122,123, //F1-12
|
112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, // F1-12
|
||||||
144, //Num
|
144, // Num
|
||||||
145, //Scroll
|
145, //Scroll
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,8 +38,8 @@ var InputWaiter = function(app, manager) {
|
||||||
*
|
*
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
InputWaiter.prototype.get = function() {
|
InputWaiter.prototype.get = function () {
|
||||||
return document.getElementById("input-text").value;
|
return document.getElementById('input-text').value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -50,9 +50,9 @@ InputWaiter.prototype.get = function() {
|
||||||
*
|
*
|
||||||
* @fires Manager#statechange
|
* @fires Manager#statechange
|
||||||
*/
|
*/
|
||||||
InputWaiter.prototype.set = function(input) {
|
InputWaiter.prototype.set = function (input) {
|
||||||
document.getElementById("input-text").value = input;
|
document.getElementById('input-text').value = input;
|
||||||
window.dispatchEvent(this.manager.statechange);
|
window.dispatchEvent(this.manager.statechange);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -62,14 +62,14 @@ InputWaiter.prototype.set = function(input) {
|
||||||
* @param {number} length - The length of the current input string
|
* @param {number} length - The length of the current input string
|
||||||
* @param {number} lines - The number of the lines in the current input string
|
* @param {number} lines - The number of the lines in the current input string
|
||||||
*/
|
*/
|
||||||
InputWaiter.prototype.set_input_info = function(length, lines) {
|
InputWaiter.prototype.set_input_info = function (length, lines) {
|
||||||
var width = length.toString().length;
|
let width = length.toString().length;
|
||||||
width = width < 2 ? 2 : width;
|
width = width < 2 ? 2 : width;
|
||||||
|
|
||||||
var length_str = Utils.pad(length.toString(), width, " ").replace(/ /g, " ");
|
const length_str = Utils.pad(length.toString(), width, ' ').replace(/ /g, ' ');
|
||||||
var lines_str = Utils.pad(lines.toString(), width, " ").replace(/ /g, " ");
|
const lines_str = Utils.pad(lines.toString(), width, ' ').replace(/ /g, ' ');
|
||||||
|
|
||||||
document.getElementById("input-info").innerHTML = "length: " + length_str + "<br>lines: " + lines_str;
|
document.getElementById('input-info').innerHTML = `length: ${length_str}<br>lines: ${lines_str}`;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -81,24 +81,24 @@ InputWaiter.prototype.set_input_info = function(length, lines) {
|
||||||
*
|
*
|
||||||
* @fires Manager#statechange
|
* @fires Manager#statechange
|
||||||
*/
|
*/
|
||||||
InputWaiter.prototype.input_change = function(e) {
|
InputWaiter.prototype.input_change = function (e) {
|
||||||
// Remove highlighting from input and output panes as the offsets might be different now
|
// Remove highlighting from input and output panes as the offsets might be different now
|
||||||
this.manager.highlighter.remove_highlights();
|
this.manager.highlighter.remove_highlights();
|
||||||
|
|
||||||
// Reset recipe progress as any previous processing will be redundant now
|
// Reset recipe progress as any previous processing will be redundant now
|
||||||
this.app.progress = 0;
|
this.app.progress = 0;
|
||||||
|
|
||||||
// Update the input metadata info
|
// Update the input metadata info
|
||||||
var input_text = this.get(),
|
let input_text = this.get(),
|
||||||
lines = input_text.count("\n") + 1;
|
lines = input_text.count('\n') + 1;
|
||||||
|
|
||||||
this.set_input_info(input_text.length, lines);
|
this.set_input_info(input_text.length, lines);
|
||||||
|
|
||||||
|
|
||||||
if (this.bad_keys.indexOf(e.keyCode) < 0) {
|
if (this.bad_keys.indexOf(e.keyCode) < 0) {
|
||||||
// Fire the statechange event as the input has been modified
|
// Fire the statechange event as the input has been modified
|
||||||
window.dispatchEvent(this.manager.statechange);
|
window.dispatchEvent(this.manager.statechange);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -108,14 +108,15 @@ InputWaiter.prototype.input_change = function(e) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
InputWaiter.prototype.input_dragover = function(e) {
|
InputWaiter.prototype.input_dragover = function (e) {
|
||||||
// This will be set if we're dragging an operation
|
// This will be set if we're dragging an operation
|
||||||
if (e.dataTransfer.effectAllowed === "move")
|
if (e.dataTransfer.effectAllowed === 'move') {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.target.classList.add("dropping-file");
|
e.target.classList.add('dropping-file');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -125,10 +126,10 @@ InputWaiter.prototype.input_dragover = function(e) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
InputWaiter.prototype.input_dragleave = function(e) {
|
InputWaiter.prototype.input_dragleave = function (e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.target.classList.remove("dropping-file");
|
e.target.classList.remove('dropping-file');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -138,64 +139,65 @@ InputWaiter.prototype.input_dragleave = function(e) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
InputWaiter.prototype.input_drop = function(e) {
|
InputWaiter.prototype.input_drop = function (e) {
|
||||||
// This will be set if we're dragging an operation
|
// This will be set if we're dragging an operation
|
||||||
if (e.dataTransfer.effectAllowed === "move")
|
if (e.dataTransfer.effectAllowed === 'move') {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
var el = e.target,
|
let el = e.target,
|
||||||
file = e.dataTransfer.files[0],
|
file = e.dataTransfer.files[0],
|
||||||
text = e.dataTransfer.getData("Text"),
|
text = e.dataTransfer.getData('Text'),
|
||||||
reader = new FileReader(),
|
reader = new FileReader(),
|
||||||
input_charcode = "",
|
input_charcode = '',
|
||||||
offset = 0,
|
offset = 0,
|
||||||
CHUNK_SIZE = 20480; // 20KB
|
CHUNK_SIZE = 20480; // 20KB
|
||||||
|
|
||||||
var set_input = function() {
|
const set_input = function () {
|
||||||
if (input_charcode.length > 100000 && this.app.auto_bake_) {
|
if (input_charcode.length > 100000 && this.app.auto_bake_) {
|
||||||
this.manager.controls.set_auto_bake(false);
|
this.manager.controls.set_auto_bake(false);
|
||||||
this.app.alert("Turned off Auto Bake as the input is large", "warning", 5000);
|
this.app.alert('Turned off Auto Bake as the input is large', 'warning', 5000);
|
||||||
}
|
|
||||||
|
|
||||||
this.set(input_charcode);
|
|
||||||
var recipe_config = this.app.get_recipe_config();
|
|
||||||
if (!recipe_config[0] || recipe_config[0].op != "From Hex") {
|
|
||||||
recipe_config.unshift({op:"From Hex",args:["Space"]});
|
|
||||||
this.app.set_recipe_config(recipe_config);
|
|
||||||
}
|
|
||||||
|
|
||||||
el.classList.remove("loading_file");
|
|
||||||
}.bind(this);
|
|
||||||
|
|
||||||
var seek = function() {
|
|
||||||
if (offset >= file.size) {
|
|
||||||
set_input();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
el.value = "Processing... " + Math.round(offset / file.size * 100) + "%";
|
|
||||||
var slice = file.slice(offset, offset + CHUNK_SIZE);
|
|
||||||
reader.readAsArrayBuffer(slice);
|
|
||||||
}.bind(this);
|
|
||||||
|
|
||||||
reader.onload = function(e) {
|
|
||||||
var data = new Uint8Array(reader.result);
|
|
||||||
input_charcode += Utils.to_hex_fast(data);
|
|
||||||
offset += CHUNK_SIZE;
|
|
||||||
seek();
|
|
||||||
}.bind(this);
|
|
||||||
|
|
||||||
|
|
||||||
el.classList.remove("dropping-file");
|
|
||||||
|
|
||||||
if (file) {
|
|
||||||
el.classList.add("loading_file");
|
|
||||||
seek();
|
|
||||||
} else if (text) {
|
|
||||||
this.set(text);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.set(input_charcode);
|
||||||
|
const recipe_config = this.app.get_recipe_config();
|
||||||
|
if (!recipe_config[0] || recipe_config[0].op != 'From Hex') {
|
||||||
|
recipe_config.unshift({ op: 'From Hex', args: ['Space'] });
|
||||||
|
this.app.set_recipe_config(recipe_config);
|
||||||
|
}
|
||||||
|
|
||||||
|
el.classList.remove('loading_file');
|
||||||
|
}.bind(this);
|
||||||
|
|
||||||
|
const seek = function () {
|
||||||
|
if (offset >= file.size) {
|
||||||
|
set_input();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
el.value = `Processing... ${Math.round(offset / file.size * 100)}%`;
|
||||||
|
const slice = file.slice(offset, offset + CHUNK_SIZE);
|
||||||
|
reader.readAsArrayBuffer(slice);
|
||||||
|
};
|
||||||
|
|
||||||
|
reader.onload = function (e) {
|
||||||
|
const data = new Uint8Array(reader.result);
|
||||||
|
input_charcode += Utils.to_hex_fast(data);
|
||||||
|
offset += CHUNK_SIZE;
|
||||||
|
seek();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
el.classList.remove('dropping-file');
|
||||||
|
|
||||||
|
if (file) {
|
||||||
|
el.classList.add('loading_file');
|
||||||
|
seek();
|
||||||
|
} else if (text) {
|
||||||
|
this.set(text);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -205,13 +207,13 @@ InputWaiter.prototype.input_drop = function(e) {
|
||||||
*
|
*
|
||||||
* @fires Manager#statechange
|
* @fires Manager#statechange
|
||||||
*/
|
*/
|
||||||
InputWaiter.prototype.clear_io_click = function() {
|
InputWaiter.prototype.clear_io_click = function () {
|
||||||
this.manager.highlighter.remove_highlights();
|
this.manager.highlighter.remove_highlights();
|
||||||
document.getElementById("input-text").value = "";
|
document.getElementById('input-text').value = '';
|
||||||
document.getElementById("output-text").value = "";
|
document.getElementById('output-text').value = '';
|
||||||
document.getElementById("input-info").innerHTML = "";
|
document.getElementById('input-info').innerHTML = '';
|
||||||
document.getElementById("output-info").innerHTML = "";
|
document.getElementById('output-info').innerHTML = '';
|
||||||
document.getElementById("input-selection-info").innerHTML = "";
|
document.getElementById('input-selection-info').innerHTML = '';
|
||||||
document.getElementById("output-selection-info").innerHTML = "";
|
document.getElementById('output-selection-info').innerHTML = '';
|
||||||
window.dispatchEvent(this.manager.statechange);
|
window.dispatchEvent(this.manager.statechange);
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,142 +8,142 @@
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {HTMLApp} app - The main view object for CyberChef.
|
* @param {HTMLApp} app - The main view object for CyberChef.
|
||||||
*/
|
*/
|
||||||
var Manager = function(app) {
|
const Manager = function (app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
|
|
||||||
// Define custom events
|
// Define custom events
|
||||||
/**
|
/**
|
||||||
* @event Manager#appstart
|
* @event Manager#appstart
|
||||||
*/
|
*/
|
||||||
this.appstart = new CustomEvent("appstart", {bubbles: true});
|
this.appstart = new CustomEvent('appstart', { bubbles: true });
|
||||||
/**
|
/**
|
||||||
* @event Manager#operationadd
|
* @event Manager#operationadd
|
||||||
*/
|
*/
|
||||||
this.operationadd = new CustomEvent("operationadd", {bubbles: true});
|
this.operationadd = new CustomEvent('operationadd', { bubbles: true });
|
||||||
/**
|
/**
|
||||||
* @event Manager#operationremove
|
* @event Manager#operationremove
|
||||||
*/
|
*/
|
||||||
this.operationremove = new CustomEvent("operationremove", {bubbles: true});
|
this.operationremove = new CustomEvent('operationremove', { bubbles: true });
|
||||||
/**
|
/**
|
||||||
* @event Manager#oplistcreate
|
* @event Manager#oplistcreate
|
||||||
*/
|
*/
|
||||||
this.oplistcreate = new CustomEvent("oplistcreate", {bubbles: true});
|
this.oplistcreate = new CustomEvent('oplistcreate', { bubbles: true });
|
||||||
/**
|
/**
|
||||||
* @event Manager#statechange
|
* @event Manager#statechange
|
||||||
*/
|
*/
|
||||||
this.statechange = new CustomEvent("statechange", {bubbles: true});
|
this.statechange = new CustomEvent('statechange', { bubbles: true });
|
||||||
|
|
||||||
// Define Waiter objects to handle various areas
|
// Define Waiter objects to handle various areas
|
||||||
this.window = new WindowWaiter(this.app);
|
this.window = new WindowWaiter(this.app);
|
||||||
this.controls = new ControlsWaiter(this.app, this);
|
this.controls = new ControlsWaiter(this.app, this);
|
||||||
this.recipe = new RecipeWaiter(this.app, this);
|
this.recipe = new RecipeWaiter(this.app, this);
|
||||||
this.ops = new OperationsWaiter(this.app, this);
|
this.ops = new OperationsWaiter(this.app, this);
|
||||||
this.input = new InputWaiter(this.app, this);
|
this.input = new InputWaiter(this.app, this);
|
||||||
this.output = new OutputWaiter(this.app, this);
|
this.output = new OutputWaiter(this.app, this);
|
||||||
this.options = new OptionsWaiter(this.app);
|
this.options = new OptionsWaiter(this.app);
|
||||||
this.highlighter = new HighlighterWaiter(this.app);
|
this.highlighter = new HighlighterWaiter(this.app);
|
||||||
this.seasonal = new SeasonalWaiter(this.app, this);
|
this.seasonal = new SeasonalWaiter(this.app, this);
|
||||||
|
|
||||||
// Object to store dynamic handlers to fire on elements that may not exist yet
|
// Object to store dynamic handlers to fire on elements that may not exist yet
|
||||||
this.dynamic_handlers = {};
|
this.dynamic_handlers = {};
|
||||||
|
|
||||||
this.initialise_event_listeners();
|
this.initialise_event_listeners();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up the various components and listeners.
|
* Sets up the various components and listeners.
|
||||||
*/
|
*/
|
||||||
Manager.prototype.setup = function() {
|
Manager.prototype.setup = function () {
|
||||||
this.recipe.initialise_operation_drag_n_drop();
|
this.recipe.initialise_operation_drag_n_drop();
|
||||||
this.controls.auto_bake_change();
|
this.controls.auto_bake_change();
|
||||||
this.seasonal.load();
|
this.seasonal.load();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main function to handle the creation of the event listeners.
|
* Main function to handle the creation of the event listeners.
|
||||||
*/
|
*/
|
||||||
Manager.prototype.initialise_event_listeners = function() {
|
Manager.prototype.initialise_event_listeners = function () {
|
||||||
// Global
|
// Global
|
||||||
window.addEventListener("resize", this.window.window_resize.bind(this.window));
|
window.addEventListener('resize', this.window.window_resize.bind(this.window));
|
||||||
window.addEventListener("blur", this.window.window_blur.bind(this.window));
|
window.addEventListener('blur', this.window.window_blur.bind(this.window));
|
||||||
window.addEventListener("focus", this.window.window_focus.bind(this.window));
|
window.addEventListener('focus', this.window.window_focus.bind(this.window));
|
||||||
window.addEventListener("statechange", this.app.state_change.bind(this.app));
|
window.addEventListener('statechange', this.app.state_change.bind(this.app));
|
||||||
window.addEventListener("popstate", this.app.pop_state.bind(this.app));
|
window.addEventListener('popstate', this.app.pop_state.bind(this.app));
|
||||||
|
|
||||||
// Controls
|
// Controls
|
||||||
document.getElementById("bake").addEventListener("click", this.controls.bake_click.bind(this.controls));
|
document.getElementById('bake').addEventListener('click', this.controls.bake_click.bind(this.controls));
|
||||||
document.getElementById("auto-bake").addEventListener("change", this.controls.auto_bake_change.bind(this.controls));
|
document.getElementById('auto-bake').addEventListener('change', this.controls.auto_bake_change.bind(this.controls));
|
||||||
document.getElementById("step").addEventListener("click", this.controls.step_click.bind(this.controls));
|
document.getElementById('step').addEventListener('click', this.controls.step_click.bind(this.controls));
|
||||||
document.getElementById("clr-recipe").addEventListener("click", this.controls.clear_recipe_click.bind(this.controls));
|
document.getElementById('clr-recipe').addEventListener('click', this.controls.clear_recipe_click.bind(this.controls));
|
||||||
document.getElementById("clr-breaks").addEventListener("click", this.controls.clear_breaks_click.bind(this.controls));
|
document.getElementById('clr-breaks').addEventListener('click', this.controls.clear_breaks_click.bind(this.controls));
|
||||||
document.getElementById("save").addEventListener("click", this.controls.save_click.bind(this.controls));
|
document.getElementById('save').addEventListener('click', this.controls.save_click.bind(this.controls));
|
||||||
document.getElementById("save-button").addEventListener("click", this.controls.save_button_click.bind(this.controls));
|
document.getElementById('save-button').addEventListener('click', this.controls.save_button_click.bind(this.controls));
|
||||||
document.getElementById("save-link-recipe-checkbox").addEventListener("change", this.controls.slr_check_change.bind(this.controls));
|
document.getElementById('save-link-recipe-checkbox').addEventListener('change', this.controls.slr_check_change.bind(this.controls));
|
||||||
document.getElementById("save-link-input-checkbox").addEventListener("change", this.controls.sli_check_change.bind(this.controls));
|
document.getElementById('save-link-input-checkbox').addEventListener('change', this.controls.sli_check_change.bind(this.controls));
|
||||||
document.getElementById("load").addEventListener("click", this.controls.load_click.bind(this.controls));
|
document.getElementById('load').addEventListener('click', this.controls.load_click.bind(this.controls));
|
||||||
document.getElementById("load-delete-button").addEventListener("click", this.controls.load_delete_click.bind(this.controls));
|
document.getElementById('load-delete-button').addEventListener('click', this.controls.load_delete_click.bind(this.controls));
|
||||||
document.getElementById("load-name").addEventListener("change", this.controls.load_name_change.bind(this.controls));
|
document.getElementById('load-name').addEventListener('change', this.controls.load_name_change.bind(this.controls));
|
||||||
document.getElementById("load-button").addEventListener("click", this.controls.load_button_click.bind(this.controls));
|
document.getElementById('load-button').addEventListener('click', this.controls.load_button_click.bind(this.controls));
|
||||||
this.add_multi_event_listener("#save-text", "keyup paste", this.controls.save_text_change, this.controls);
|
this.add_multi_event_listener('#save-text', 'keyup paste', this.controls.save_text_change, this.controls);
|
||||||
|
|
||||||
// Operations
|
// Operations
|
||||||
this.add_multi_event_listener("#search", "keyup paste search", this.ops.search_operations, this.ops);
|
this.add_multi_event_listener('#search', 'keyup paste search', this.ops.search_operations, this.ops);
|
||||||
this.add_dynamic_listener(".op_list li.operation", "dblclick", this.ops.operation_dblclick, this.ops);
|
this.add_dynamic_listener('.op_list li.operation', 'dblclick', this.ops.operation_dblclick, this.ops);
|
||||||
document.getElementById("edit-favourites").addEventListener("click", this.ops.edit_favourites_click.bind(this.ops));
|
document.getElementById('edit-favourites').addEventListener('click', this.ops.edit_favourites_click.bind(this.ops));
|
||||||
document.getElementById("save-favourites").addEventListener("click", this.ops.save_favourites_click.bind(this.ops));
|
document.getElementById('save-favourites').addEventListener('click', this.ops.save_favourites_click.bind(this.ops));
|
||||||
document.getElementById("reset-favourites").addEventListener("click", this.ops.reset_favourites_click.bind(this.ops));
|
document.getElementById('reset-favourites').addEventListener('click', this.ops.reset_favourites_click.bind(this.ops));
|
||||||
this.add_dynamic_listener(".op_list .op-icon", "mouseover", this.ops.op_icon_mouseover, this.ops);
|
this.add_dynamic_listener('.op_list .op-icon', 'mouseover', this.ops.op_icon_mouseover, this.ops);
|
||||||
this.add_dynamic_listener(".op_list .op-icon", "mouseleave", this.ops.op_icon_mouseleave, this.ops);
|
this.add_dynamic_listener('.op_list .op-icon', 'mouseleave', this.ops.op_icon_mouseleave, this.ops);
|
||||||
this.add_dynamic_listener(".op_list", "oplistcreate", this.ops.op_list_create, this.ops);
|
this.add_dynamic_listener('.op_list', 'oplistcreate', this.ops.op_list_create, this.ops);
|
||||||
this.add_dynamic_listener("li.operation", "operationadd", this.recipe.op_add.bind(this.recipe));
|
this.add_dynamic_listener('li.operation', 'operationadd', this.recipe.op_add.bind(this.recipe));
|
||||||
|
|
||||||
// Recipe
|
// Recipe
|
||||||
this.add_dynamic_listener(".arg", "keyup", this.recipe.ing_change, this.recipe);
|
this.add_dynamic_listener('.arg', 'keyup', this.recipe.ing_change, this.recipe);
|
||||||
this.add_dynamic_listener(".arg", "change", this.recipe.ing_change, this.recipe);
|
this.add_dynamic_listener('.arg', 'change', this.recipe.ing_change, this.recipe);
|
||||||
this.add_dynamic_listener(".disable-icon", "click", this.recipe.disable_click, this.recipe);
|
this.add_dynamic_listener('.disable-icon', 'click', this.recipe.disable_click, this.recipe);
|
||||||
this.add_dynamic_listener(".breakpoint", "click", this.recipe.breakpoint_click, this.recipe);
|
this.add_dynamic_listener('.breakpoint', 'click', this.recipe.breakpoint_click, this.recipe);
|
||||||
this.add_dynamic_listener("#rec_list li.operation", "dblclick", this.recipe.operation_dblclick, this.recipe);
|
this.add_dynamic_listener('#rec_list li.operation', 'dblclick', this.recipe.operation_dblclick, this.recipe);
|
||||||
this.add_dynamic_listener("#rec_list li.operation > div", "dblclick", this.recipe.operation_child_dblclick, this.recipe);
|
this.add_dynamic_listener('#rec_list li.operation > div', 'dblclick', this.recipe.operation_child_dblclick, this.recipe);
|
||||||
this.add_dynamic_listener("#rec_list .input-group .dropdown-menu a", "click", this.recipe.dropdown_toggle_click, this.recipe);
|
this.add_dynamic_listener('#rec_list .input-group .dropdown-menu a', 'click', this.recipe.dropdown_toggle_click, this.recipe);
|
||||||
this.add_dynamic_listener("#rec_list", "operationremove", this.recipe.op_remove.bind(this.recipe));
|
this.add_dynamic_listener('#rec_list', 'operationremove', this.recipe.op_remove.bind(this.recipe));
|
||||||
|
|
||||||
// Input
|
// Input
|
||||||
this.add_multi_event_listener("#input-text", "keyup paste", this.input.input_change, this.input);
|
this.add_multi_event_listener('#input-text', 'keyup paste', this.input.input_change, this.input);
|
||||||
document.getElementById("reset-layout").addEventListener("click", this.app.reset_layout.bind(this.app));
|
document.getElementById('reset-layout').addEventListener('click', this.app.reset_layout.bind(this.app));
|
||||||
document.getElementById("clr-io").addEventListener("click", this.input.clear_io_click.bind(this.input));
|
document.getElementById('clr-io').addEventListener('click', this.input.clear_io_click.bind(this.input));
|
||||||
document.getElementById("input-text").addEventListener("dragover", this.input.input_dragover.bind(this.input));
|
document.getElementById('input-text').addEventListener('dragover', this.input.input_dragover.bind(this.input));
|
||||||
document.getElementById("input-text").addEventListener("dragleave", this.input.input_dragleave.bind(this.input));
|
document.getElementById('input-text').addEventListener('dragleave', this.input.input_dragleave.bind(this.input));
|
||||||
document.getElementById("input-text").addEventListener("drop", this.input.input_drop.bind(this.input));
|
document.getElementById('input-text').addEventListener('drop', this.input.input_drop.bind(this.input));
|
||||||
document.getElementById("input-text").addEventListener("scroll", this.highlighter.input_scroll.bind(this.highlighter));
|
document.getElementById('input-text').addEventListener('scroll', this.highlighter.input_scroll.bind(this.highlighter));
|
||||||
document.getElementById("input-text").addEventListener("mouseup", this.highlighter.input_mouseup.bind(this.highlighter));
|
document.getElementById('input-text').addEventListener('mouseup', this.highlighter.input_mouseup.bind(this.highlighter));
|
||||||
document.getElementById("input-text").addEventListener("mousemove", this.highlighter.input_mousemove.bind(this.highlighter));
|
document.getElementById('input-text').addEventListener('mousemove', this.highlighter.input_mousemove.bind(this.highlighter));
|
||||||
this.add_multi_event_listener("#input-text", "mousedown dblclick select", this.highlighter.input_mousedown, this.highlighter);
|
this.add_multi_event_listener('#input-text', 'mousedown dblclick select', this.highlighter.input_mousedown, this.highlighter);
|
||||||
|
|
||||||
// Output
|
// Output
|
||||||
document.getElementById("save-to-file").addEventListener("click", this.output.save_click.bind(this.output));
|
document.getElementById('save-to-file').addEventListener('click', this.output.save_click.bind(this.output));
|
||||||
document.getElementById("switch").addEventListener("click", this.output.switch_click.bind(this.output));
|
document.getElementById('switch').addEventListener('click', this.output.switch_click.bind(this.output));
|
||||||
document.getElementById("undo-switch").addEventListener("click", this.output.undo_switch_click.bind(this.output));
|
document.getElementById('undo-switch').addEventListener('click', this.output.undo_switch_click.bind(this.output));
|
||||||
document.getElementById("output-text").addEventListener("scroll", this.highlighter.output_scroll.bind(this.highlighter));
|
document.getElementById('output-text').addEventListener('scroll', this.highlighter.output_scroll.bind(this.highlighter));
|
||||||
document.getElementById("output-text").addEventListener("mouseup", this.highlighter.output_mouseup.bind(this.highlighter));
|
document.getElementById('output-text').addEventListener('mouseup', this.highlighter.output_mouseup.bind(this.highlighter));
|
||||||
document.getElementById("output-text").addEventListener("mousemove", this.highlighter.output_mousemove.bind(this.highlighter));
|
document.getElementById('output-text').addEventListener('mousemove', this.highlighter.output_mousemove.bind(this.highlighter));
|
||||||
document.getElementById("output-html").addEventListener("mouseup", this.highlighter.output_html_mouseup.bind(this.highlighter));
|
document.getElementById('output-html').addEventListener('mouseup', this.highlighter.output_html_mouseup.bind(this.highlighter));
|
||||||
document.getElementById("output-html").addEventListener("mousemove", this.highlighter.output_html_mousemove.bind(this.highlighter));
|
document.getElementById('output-html').addEventListener('mousemove', this.highlighter.output_html_mousemove.bind(this.highlighter));
|
||||||
this.add_multi_event_listener("#output-text", "mousedown dblclick select", this.highlighter.output_mousedown, this.highlighter);
|
this.add_multi_event_listener('#output-text', 'mousedown dblclick select', this.highlighter.output_mousedown, this.highlighter);
|
||||||
this.add_multi_event_listener("#output-html", "mousedown dblclick select", this.highlighter.output_html_mousedown, this.highlighter);
|
this.add_multi_event_listener('#output-html', 'mousedown dblclick select', this.highlighter.output_html_mousedown, this.highlighter);
|
||||||
|
|
||||||
// Options
|
// Options
|
||||||
document.getElementById("options").addEventListener("click", this.options.options_click.bind(this.options));
|
document.getElementById('options').addEventListener('click', this.options.options_click.bind(this.options));
|
||||||
document.getElementById("reset-options").addEventListener("click", this.options.reset_options_click.bind(this.options));
|
document.getElementById('reset-options').addEventListener('click', this.options.reset_options_click.bind(this.options));
|
||||||
$(".option-item input:checkbox").on("switchChange.bootstrapSwitch", this.options.switch_change.bind(this.options));
|
$('.option-item input:checkbox').on('switchChange.bootstrapSwitch', this.options.switch_change.bind(this.options));
|
||||||
$(".option-item input:checkbox").on("switchChange.bootstrapSwitch", this.options.set_word_wrap.bind(this.options));
|
$('.option-item input:checkbox').on('switchChange.bootstrapSwitch', this.options.set_word_wrap.bind(this.options));
|
||||||
this.add_dynamic_listener(".option-item input[type=number]", "keyup", this.options.number_change, this.options);
|
this.add_dynamic_listener('.option-item input[type=number]', 'keyup', this.options.number_change, this.options);
|
||||||
this.add_dynamic_listener(".option-item input[type=number]", "change", this.options.number_change, this.options);
|
this.add_dynamic_listener('.option-item input[type=number]', 'change', this.options.number_change, this.options);
|
||||||
this.add_dynamic_listener(".option-item select", "change", this.options.select_change, this.options);
|
this.add_dynamic_listener('.option-item select', 'change', this.options.select_change, this.options);
|
||||||
|
|
||||||
// Misc
|
// Misc
|
||||||
document.getElementById("alert-close").addEventListener("click", this.app.alert_close_click.bind(this.app));
|
document.getElementById('alert-close').addEventListener('click', this.app.alert_close_click.bind(this.app));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -160,11 +160,11 @@ Manager.prototype.initialise_event_listeners = function() {
|
||||||
* // Calls the clickable function whenever any element with the .clickable class is clicked
|
* // Calls the clickable function whenever any element with the .clickable class is clicked
|
||||||
* this.add_listeners(".clickable", "click", this.clickable, this);
|
* this.add_listeners(".clickable", "click", this.clickable, this);
|
||||||
*/
|
*/
|
||||||
Manager.prototype.add_listeners = function(selector, event_type, callback, scope) {
|
Manager.prototype.add_listeners = function (selector, event_type, callback, scope) {
|
||||||
scope = scope || this;
|
scope = scope || this;
|
||||||
[].forEach.call(document.querySelectorAll(selector), function(el) {
|
[].forEach.call(document.querySelectorAll(selector), (el) => {
|
||||||
el.addEventListener(event_type, callback.bind(scope));
|
el.addEventListener(event_type, callback.bind(scope));
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -181,11 +181,11 @@ Manager.prototype.add_listeners = function(selector, event_type, callback, scope
|
||||||
* // search element
|
* // search element
|
||||||
* this.add_multi_event_listener("search", "keyup paste search", this.search, this);
|
* this.add_multi_event_listener("search", "keyup paste search", this.search, this);
|
||||||
*/
|
*/
|
||||||
Manager.prototype.add_multi_event_listener = function(selector, event_types, callback, scope) {
|
Manager.prototype.add_multi_event_listener = function (selector, event_types, callback, scope) {
|
||||||
var evs = event_types.split(" ");
|
const evs = event_types.split(' ');
|
||||||
for (var i = 0; i < evs.length; i++) {
|
for (let i = 0; i < evs.length; i++) {
|
||||||
document.querySelector(selector).addEventListener(evs[i], callback.bind(scope));
|
document.querySelector(selector).addEventListener(evs[i], callback.bind(scope));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -202,11 +202,11 @@ Manager.prototype.add_multi_event_listener = function(selector, event_types, cal
|
||||||
* // with the .saveable class
|
* // with the .saveable class
|
||||||
* this.add_multi_event_listener(".saveable", "keyup paste", this.save, this);
|
* this.add_multi_event_listener(".saveable", "keyup paste", this.save, this);
|
||||||
*/
|
*/
|
||||||
Manager.prototype.add_multi_event_listeners = function(selector, event_types, callback, scope) {
|
Manager.prototype.add_multi_event_listeners = function (selector, event_types, callback, scope) {
|
||||||
var evs = event_types.split(" ");
|
const evs = event_types.split(' ');
|
||||||
for (var i = 0; i < evs.length; i++) {
|
for (let i = 0; i < evs.length; i++) {
|
||||||
this.add_listeners(selector, evs[i], callback, scope);
|
this.add_listeners(selector, evs[i], callback, scope);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -224,20 +224,20 @@ Manager.prototype.add_multi_event_listeners = function(selector, event_types, ca
|
||||||
* // listener is created
|
* // listener is created
|
||||||
* this.add_dynamic_listener("button", "click", alert, this);
|
* this.add_dynamic_listener("button", "click", alert, this);
|
||||||
*/
|
*/
|
||||||
Manager.prototype.add_dynamic_listener = function(selector, event_type, callback, scope) {
|
Manager.prototype.add_dynamic_listener = function (selector, event_type, callback, scope) {
|
||||||
var event_config = {
|
const event_config = {
|
||||||
selector: selector,
|
selector,
|
||||||
callback: callback.bind(scope || this)
|
callback: callback.bind(scope || this),
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.dynamic_handlers.hasOwnProperty(event_type)) {
|
if (this.dynamic_handlers.hasOwnProperty(event_type)) {
|
||||||
// Listener already exists, add new handler to the appropriate list
|
// Listener already exists, add new handler to the appropriate list
|
||||||
this.dynamic_handlers[event_type].push(event_config);
|
this.dynamic_handlers[event_type].push(event_config);
|
||||||
} else {
|
} else {
|
||||||
this.dynamic_handlers[event_type] = [event_config];
|
this.dynamic_handlers[event_type] = [event_config];
|
||||||
// Set up listener for this new type
|
// Set up listener for this new type
|
||||||
document.addEventListener(event_type, this.dynamic_listener_handler.bind(this));
|
document.addEventListener(event_type, this.dynamic_listener_handler.bind(this));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -247,17 +247,17 @@ Manager.prototype.add_dynamic_listener = function(selector, event_type, callback
|
||||||
*
|
*
|
||||||
* @param {Event} e - The event to be handled
|
* @param {Event} e - The event to be handled
|
||||||
*/
|
*/
|
||||||
Manager.prototype.dynamic_listener_handler = function(e) {
|
Manager.prototype.dynamic_listener_handler = function (e) {
|
||||||
var handlers = this.dynamic_handlers[e.type],
|
let handlers = this.dynamic_handlers[e.type],
|
||||||
matches = e.target.matches ||
|
matches = e.target.matches ||
|
||||||
e.target.webkitMatchesSelector ||
|
e.target.webkitMatchesSelector ||
|
||||||
e.target.mozMatchesSelector ||
|
e.target.mozMatchesSelector ||
|
||||||
e.target.msMatchesSelector ||
|
e.target.msMatchesSelector ||
|
||||||
e.target.oMatchesSelector;
|
e.target.oMatchesSelector;
|
||||||
|
|
||||||
for (var i = 0; i < handlers.length; i++) {
|
for (let i = 0; i < handlers.length; i++) {
|
||||||
if (matches && e.target[matches.name](handlers[i].selector)) {
|
if (matches && e.target[matches.name](handlers[i].selector)) {
|
||||||
handlers[i].callback(e);
|
handlers[i].callback(e);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,12 +11,12 @@
|
||||||
* @param {HTMLApp} app - The main view object for CyberChef.
|
* @param {HTMLApp} app - The main view object for CyberChef.
|
||||||
* @param {Manager} manager - The CyberChef event manager.
|
* @param {Manager} manager - The CyberChef event manager.
|
||||||
*/
|
*/
|
||||||
var OperationsWaiter = function(app, manager) {
|
const OperationsWaiter = function (app, manager) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
|
|
||||||
this.options = {};
|
this.options = {};
|
||||||
this.remove_intent = false;
|
this.remove_intent = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -26,67 +26,68 @@ var OperationsWaiter = function(app, manager) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
OperationsWaiter.prototype.search_operations = function(e) {
|
OperationsWaiter.prototype.search_operations = function (e) {
|
||||||
var ops, selected;
|
let ops,
|
||||||
|
selected;
|
||||||
|
|
||||||
if (e.type == "search") { // Search
|
if (e.type == 'search') { // Search
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
ops = document.querySelectorAll("#search-results li");
|
ops = document.querySelectorAll('#search-results li');
|
||||||
if (ops.length) {
|
if (ops.length) {
|
||||||
selected = this.get_selected_op(ops);
|
selected = this.get_selected_op(ops);
|
||||||
if (selected > -1) {
|
if (selected > -1) {
|
||||||
this.manager.recipe.add_operation(ops[selected].innerHTML);
|
this.manager.recipe.add_operation(ops[selected].innerHTML);
|
||||||
this.app.auto_bake();
|
this.app.auto_bake();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e.keyCode == 13) { // Return
|
||||||
|
e.preventDefault();
|
||||||
|
} else if (e.keyCode == 40) { // Down
|
||||||
|
e.preventDefault();
|
||||||
|
ops = document.querySelectorAll('#search-results li');
|
||||||
|
if (ops.length) {
|
||||||
|
selected = this.get_selected_op(ops);
|
||||||
|
if (selected > -1) {
|
||||||
|
ops[selected].classList.remove('selected-op');
|
||||||
|
}
|
||||||
|
if (selected == ops.length - 1) selected = -1;
|
||||||
|
ops[selected + 1].classList.add('selected-op');
|
||||||
|
}
|
||||||
|
} else if (e.keyCode == 38) { // Up
|
||||||
|
e.preventDefault();
|
||||||
|
ops = document.querySelectorAll('#search-results li');
|
||||||
|
if (ops.length) {
|
||||||
|
selected = this.get_selected_op(ops);
|
||||||
|
if (selected > -1) {
|
||||||
|
ops[selected].classList.remove('selected-op');
|
||||||
|
}
|
||||||
|
if (selected === 0) selected = ops.length;
|
||||||
|
ops[selected - 1].classList.add('selected-op');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
let search_results_el = document.getElementById('search-results'),
|
||||||
|
el = e.target,
|
||||||
|
str = el.value;
|
||||||
|
|
||||||
|
while (search_results_el.firstChild) {
|
||||||
|
search_results_el.removeChild(search_results_el.firstChild);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (e.keyCode == 13) { // Return
|
$('#categories .in').collapse('hide');
|
||||||
e.preventDefault();
|
if (str) {
|
||||||
} else if (e.keyCode == 40) { // Down
|
let matched_ops = this.filter_operations(str, true),
|
||||||
e.preventDefault();
|
matched_ops_html = '';
|
||||||
ops = document.querySelectorAll("#search-results li");
|
|
||||||
if (ops.length) {
|
|
||||||
selected = this.get_selected_op(ops);
|
|
||||||
if (selected > -1) {
|
|
||||||
ops[selected].classList.remove("selected-op");
|
|
||||||
}
|
|
||||||
if (selected == ops.length-1) selected = -1;
|
|
||||||
ops[selected+1].classList.add("selected-op");
|
|
||||||
}
|
|
||||||
} else if (e.keyCode == 38) { // Up
|
|
||||||
e.preventDefault();
|
|
||||||
ops = document.querySelectorAll("#search-results li");
|
|
||||||
if (ops.length) {
|
|
||||||
selected = this.get_selected_op(ops);
|
|
||||||
if (selected > -1) {
|
|
||||||
ops[selected].classList.remove("selected-op");
|
|
||||||
}
|
|
||||||
if (selected === 0) selected = ops.length;
|
|
||||||
ops[selected-1].classList.add("selected-op");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
var search_results_el = document.getElementById("search-results"),
|
|
||||||
el = e.target,
|
|
||||||
str = el.value;
|
|
||||||
|
|
||||||
while (search_results_el.firstChild) {
|
for (let i = 0; i < matched_ops.length; i++) {
|
||||||
search_results_el.removeChild(search_results_el.firstChild);
|
matched_ops_html += matched_ops[i].to_stub_html();
|
||||||
}
|
}
|
||||||
|
|
||||||
$("#categories .in").collapse("hide");
|
search_results_el.innerHTML = matched_ops_html;
|
||||||
if (str) {
|
search_results_el.dispatchEvent(this.manager.oplistcreate);
|
||||||
var matched_ops = this.filter_operations(str, true),
|
|
||||||
matched_ops_html = "";
|
|
||||||
|
|
||||||
for (var i = 0; i < matched_ops.length; i++) {
|
|
||||||
matched_ops_html += matched_ops[i].to_stub_html();
|
|
||||||
}
|
|
||||||
|
|
||||||
search_results_el.innerHTML = matched_ops_html;
|
|
||||||
search_results_el.dispatchEvent(this.manager.oplistcreate);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -98,32 +99,32 @@ OperationsWaiter.prototype.search_operations = function(e) {
|
||||||
* name and description
|
* name and description
|
||||||
* @returns {string[]}
|
* @returns {string[]}
|
||||||
*/
|
*/
|
||||||
OperationsWaiter.prototype.filter_operations = function(search_str, highlight) {
|
OperationsWaiter.prototype.filter_operations = function (search_str, highlight) {
|
||||||
var matched_ops = [],
|
let matched_ops = [],
|
||||||
matched_descs = [];
|
matched_descs = [];
|
||||||
|
|
||||||
search_str = search_str.toLowerCase();
|
search_str = search_str.toLowerCase();
|
||||||
|
|
||||||
for (var op_name in this.app.operations) {
|
for (const op_name in this.app.operations) {
|
||||||
var op = this.app.operations[op_name],
|
let op = this.app.operations[op_name],
|
||||||
name_pos = op_name.toLowerCase().indexOf(search_str),
|
name_pos = op_name.toLowerCase().indexOf(search_str),
|
||||||
desc_pos = op.description.toLowerCase().indexOf(search_str);
|
desc_pos = op.description.toLowerCase().indexOf(search_str);
|
||||||
|
|
||||||
if (name_pos >= 0 || desc_pos >= 0) {
|
if (name_pos >= 0 || desc_pos >= 0) {
|
||||||
var operation = new HTMLOperation(op_name, this.app.operations[op_name], this.app, this.manager);
|
const operation = new HTMLOperation(op_name, this.app.operations[op_name], this.app, this.manager);
|
||||||
if (highlight) {
|
if (highlight) {
|
||||||
operation.highlight_search_string(search_str, name_pos, desc_pos);
|
operation.highlight_search_string(search_str, name_pos, desc_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (name_pos < 0) {
|
if (name_pos < 0) {
|
||||||
matched_ops.push(operation);
|
matched_ops.push(operation);
|
||||||
} else {
|
} else {
|
||||||
matched_descs.push(operation);
|
matched_descs.push(operation);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return matched_descs.concat(matched_ops);
|
return matched_descs.concat(matched_ops);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -134,13 +135,13 @@ OperationsWaiter.prototype.filter_operations = function(search_str, highlight) {
|
||||||
* @param {element[]} ops
|
* @param {element[]} ops
|
||||||
* @returns {number}
|
* @returns {number}
|
||||||
*/
|
*/
|
||||||
OperationsWaiter.prototype.get_selected_op = function(ops) {
|
OperationsWaiter.prototype.get_selected_op = function (ops) {
|
||||||
for (var i = 0; i < ops.length; i++) {
|
for (let i = 0; i < ops.length; i++) {
|
||||||
if (ops[i].classList.contains("selected-op")) {
|
if (ops[i].classList.contains('selected-op')) {
|
||||||
return i;
|
return i;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return -1;
|
}
|
||||||
|
return -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -150,9 +151,9 @@ OperationsWaiter.prototype.get_selected_op = function(ops) {
|
||||||
* @listens Manager#oplistcreate
|
* @listens Manager#oplistcreate
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
OperationsWaiter.prototype.op_list_create = function(e) {
|
OperationsWaiter.prototype.op_list_create = function (e) {
|
||||||
this.manager.recipe.create_sortable_seed_list(e.target);
|
this.manager.recipe.create_sortable_seed_list(e.target);
|
||||||
$("[data-toggle=popover]").popover();
|
$('[data-toggle=popover]').popover();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -162,11 +163,11 @@ OperationsWaiter.prototype.op_list_create = function(e) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
OperationsWaiter.prototype.operation_dblclick = function(e) {
|
OperationsWaiter.prototype.operation_dblclick = function (e) {
|
||||||
var li = e.target;
|
const li = e.target;
|
||||||
|
|
||||||
this.manager.recipe.add_operation(li.textContent);
|
this.manager.recipe.add_operation(li.textContent);
|
||||||
this.app.auto_bake();
|
this.app.auto_bake();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -176,50 +177,48 @@ OperationsWaiter.prototype.operation_dblclick = function(e) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
OperationsWaiter.prototype.edit_favourites_click = function(e) {
|
OperationsWaiter.prototype.edit_favourites_click = function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
|
|
||||||
// Add favourites to modal
|
// Add favourites to modal
|
||||||
var fav_cat = this.app.categories.filter(function(c) {
|
const fav_cat = this.app.categories.filter(c => c.name == 'Favourites')[0];
|
||||||
return c.name == "Favourites";
|
|
||||||
})[0];
|
|
||||||
|
|
||||||
var html = "";
|
let html = '';
|
||||||
for (var i = 0; i < fav_cat.ops.length; i++) {
|
for (let i = 0; i < fav_cat.ops.length; i++) {
|
||||||
var op_name = fav_cat.ops[i];
|
const op_name = fav_cat.ops[i];
|
||||||
var operation = new HTMLOperation(op_name, this.app.operations[op_name], this.app, this.manager);
|
const operation = new HTMLOperation(op_name, this.app.operations[op_name], this.app, this.manager);
|
||||||
html += operation.to_stub_html(true);
|
html += operation.to_stub_html(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
var edit_favourites_list = document.getElementById("edit-favourites-list");
|
const edit_favourites_list = document.getElementById('edit-favourites-list');
|
||||||
edit_favourites_list.innerHTML = html;
|
edit_favourites_list.innerHTML = html;
|
||||||
|
this.remove_intent = false;
|
||||||
|
|
||||||
|
const editable_list = Sortable.create(edit_favourites_list, {
|
||||||
|
filter: '.remove-icon',
|
||||||
|
onFilter(evt) {
|
||||||
|
const el = editable_list.closest(evt.item);
|
||||||
|
if (el) {
|
||||||
|
$(el).popover('destroy');
|
||||||
|
el.parentNode.removeChild(el);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onEnd: function (evt) {
|
||||||
|
if (this.remove_intent) evt.item.remove();
|
||||||
|
}.bind(this),
|
||||||
|
});
|
||||||
|
|
||||||
|
Sortable.utils.on(edit_favourites_list, 'dragleave', () => {
|
||||||
|
this.remove_intent = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
Sortable.utils.on(edit_favourites_list, 'dragover', () => {
|
||||||
this.remove_intent = false;
|
this.remove_intent = false;
|
||||||
|
});
|
||||||
|
|
||||||
var editable_list = Sortable.create(edit_favourites_list, {
|
$('#edit-favourites-list [data-toggle=popover]').popover();
|
||||||
filter: '.remove-icon',
|
$('#favourites-modal').modal();
|
||||||
onFilter: function (evt) {
|
|
||||||
var el = editable_list.closest(evt.item);
|
|
||||||
if (el) {
|
|
||||||
$(el).popover("destroy");
|
|
||||||
el.parentNode.removeChild(el);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
onEnd: function(evt) {
|
|
||||||
if (this.remove_intent) evt.item.remove();
|
|
||||||
}.bind(this),
|
|
||||||
});
|
|
||||||
|
|
||||||
Sortable.utils.on(edit_favourites_list, "dragleave", function() {
|
|
||||||
this.remove_intent = true;
|
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
Sortable.utils.on(edit_favourites_list, "dragover", function() {
|
|
||||||
this.remove_intent = false;
|
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
$("#edit-favourites-list [data-toggle=popover]").popover();
|
|
||||||
$("#favourites-modal").modal();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -227,18 +226,18 @@ OperationsWaiter.prototype.edit_favourites_click = function(e) {
|
||||||
* Handler for save favourites click events.
|
* Handler for save favourites click events.
|
||||||
* Saves the selected favourites and reloads them.
|
* Saves the selected favourites and reloads them.
|
||||||
*/
|
*/
|
||||||
OperationsWaiter.prototype.save_favourites_click = function() {
|
OperationsWaiter.prototype.save_favourites_click = function () {
|
||||||
var favourites_list = [],
|
let favourites_list = [],
|
||||||
favs = document.querySelectorAll("#edit-favourites-list li");
|
favs = document.querySelectorAll('#edit-favourites-list li');
|
||||||
|
|
||||||
for (var i = 0; i < favs.length; i++) {
|
for (let i = 0; i < favs.length; i++) {
|
||||||
favourites_list.push(favs[i].textContent);
|
favourites_list.push(favs[i].textContent);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.app.save_favourites(favourites_list);
|
this.app.save_favourites(favourites_list);
|
||||||
this.app.load_favourites();
|
this.app.load_favourites();
|
||||||
this.app.populate_operations_list();
|
this.app.populate_operations_list();
|
||||||
this.manager.recipe.initialise_operation_drag_n_drop();
|
this.manager.recipe.initialise_operation_drag_n_drop();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -246,8 +245,8 @@ OperationsWaiter.prototype.save_favourites_click = function() {
|
||||||
* Handler for reset favourites click events.
|
* Handler for reset favourites click events.
|
||||||
* Resets favourites to their defaults.
|
* Resets favourites to their defaults.
|
||||||
*/
|
*/
|
||||||
OperationsWaiter.prototype.reset_favourites_click = function() {
|
OperationsWaiter.prototype.reset_favourites_click = function () {
|
||||||
this.app.reset_favourites();
|
this.app.reset_favourites();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -257,11 +256,11 @@ OperationsWaiter.prototype.reset_favourites_click = function() {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
OperationsWaiter.prototype.op_icon_mouseover = function(e) {
|
OperationsWaiter.prototype.op_icon_mouseover = function (e) {
|
||||||
var op_el = e.target.parentNode;
|
const op_el = e.target.parentNode;
|
||||||
if (e.target.getAttribute("data-toggle") == "popover") {
|
if (e.target.getAttribute('data-toggle') == 'popover') {
|
||||||
$(op_el).popover("hide");
|
$(op_el).popover('hide');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -272,11 +271,11 @@ OperationsWaiter.prototype.op_icon_mouseover = function(e) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
OperationsWaiter.prototype.op_icon_mouseleave = function(e) {
|
OperationsWaiter.prototype.op_icon_mouseleave = function (e) {
|
||||||
var op_el = e.target.parentNode,
|
let op_el = e.target.parentNode,
|
||||||
to_el = e.toElement || e.relatedElement;
|
to_el = e.toElement || e.relatedElement;
|
||||||
|
|
||||||
if (e.target.getAttribute("data-toggle") == "popover" && to_el === op_el) {
|
if (e.target.getAttribute('data-toggle') == 'popover' && to_el === op_el) {
|
||||||
$(op_el).popover("show");
|
$(op_el).popover('show');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {HTMLApp} app - The main view object for CyberChef.
|
* @param {HTMLApp} app - The main view object for CyberChef.
|
||||||
*/
|
*/
|
||||||
var OptionsWaiter = function(app) {
|
const OptionsWaiter = function (app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,33 +18,33 @@ var OptionsWaiter = function(app) {
|
||||||
*
|
*
|
||||||
* @param {Object} options
|
* @param {Object} options
|
||||||
*/
|
*/
|
||||||
OptionsWaiter.prototype.load = function(options) {
|
OptionsWaiter.prototype.load = function (options) {
|
||||||
$(".option-item input:checkbox").bootstrapSwitch({
|
$('.option-item input:checkbox').bootstrapSwitch({
|
||||||
size: "small",
|
size: 'small',
|
||||||
animate: false,
|
animate: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
for (var option in options) {
|
for (const option in options) {
|
||||||
this.app.options[option] = options[option];
|
this.app.options[option] = options[option];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set options to match object
|
// Set options to match object
|
||||||
var cboxes = document.querySelectorAll("#options-body input[type=checkbox]");
|
const cboxes = document.querySelectorAll('#options-body input[type=checkbox]');
|
||||||
for (var i = 0; i < cboxes.length; i++) {
|
for (var i = 0; i < cboxes.length; i++) {
|
||||||
$(cboxes[i]).bootstrapSwitch("state", this.app.options[cboxes[i].getAttribute("option")]);
|
$(cboxes[i]).bootstrapSwitch('state', this.app.options[cboxes[i].getAttribute('option')]);
|
||||||
}
|
}
|
||||||
|
|
||||||
var nboxes = document.querySelectorAll("#options-body input[type=number]");
|
const nboxes = document.querySelectorAll('#options-body input[type=number]');
|
||||||
for (i = 0; i < nboxes.length; i++) {
|
for (i = 0; i < nboxes.length; i++) {
|
||||||
nboxes[i].value = this.app.options[nboxes[i].getAttribute("option")];
|
nboxes[i].value = this.app.options[nboxes[i].getAttribute('option')];
|
||||||
nboxes[i].dispatchEvent(new CustomEvent("change", {bubbles: true}));
|
nboxes[i].dispatchEvent(new CustomEvent('change', { bubbles: true }));
|
||||||
}
|
}
|
||||||
|
|
||||||
var selects = document.querySelectorAll("#options-body select");
|
const selects = document.querySelectorAll('#options-body select');
|
||||||
for (i = 0; i < selects.length; i++) {
|
for (i = 0; i < selects.length; i++) {
|
||||||
selects[i].value = this.app.options[selects[i].getAttribute("option")];
|
selects[i].value = this.app.options[selects[i].getAttribute('option')];
|
||||||
selects[i].dispatchEvent(new CustomEvent("change", {bubbles: true}));
|
selects[i].dispatchEvent(new CustomEvent('change', { bubbles: true }));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,8 +52,8 @@ OptionsWaiter.prototype.load = function(options) {
|
||||||
* Handler for options click events.
|
* Handler for options click events.
|
||||||
* Dispays the options pane.
|
* Dispays the options pane.
|
||||||
*/
|
*/
|
||||||
OptionsWaiter.prototype.options_click = function() {
|
OptionsWaiter.prototype.options_click = function () {
|
||||||
$("#options-modal").modal();
|
$('#options-modal').modal();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -61,8 +61,8 @@ OptionsWaiter.prototype.options_click = function() {
|
||||||
* Handler for reset options click events.
|
* Handler for reset options click events.
|
||||||
* Resets options back to their default values.
|
* Resets options back to their default values.
|
||||||
*/
|
*/
|
||||||
OptionsWaiter.prototype.reset_options_click = function() {
|
OptionsWaiter.prototype.reset_options_click = function () {
|
||||||
this.load(this.app.doptions);
|
this.load(this.app.doptions);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,12 +73,12 @@ OptionsWaiter.prototype.reset_options_click = function() {
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
* @param {boolean} state
|
* @param {boolean} state
|
||||||
*/
|
*/
|
||||||
OptionsWaiter.prototype.switch_change = function(e, state) {
|
OptionsWaiter.prototype.switch_change = function (e, state) {
|
||||||
var el = e.target,
|
let el = e.target,
|
||||||
option = el.getAttribute("option");
|
option = el.getAttribute('option');
|
||||||
|
|
||||||
this.app.options[option] = state;
|
this.app.options[option] = state;
|
||||||
localStorage.setItem("options", JSON.stringify(this.app.options));
|
localStorage.setItem('options', JSON.stringify(this.app.options));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,12 +88,12 @@ OptionsWaiter.prototype.switch_change = function(e, state) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
OptionsWaiter.prototype.number_change = function(e) {
|
OptionsWaiter.prototype.number_change = function (e) {
|
||||||
var el = e.target,
|
let el = e.target,
|
||||||
option = el.getAttribute("option");
|
option = el.getAttribute('option');
|
||||||
|
|
||||||
this.app.options[option] = parseInt(el.value, 10);
|
this.app.options[option] = parseInt(el.value, 10);
|
||||||
localStorage.setItem("options", JSON.stringify(this.app.options));
|
localStorage.setItem('options', JSON.stringify(this.app.options));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -103,30 +103,30 @@ OptionsWaiter.prototype.number_change = function(e) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
OptionsWaiter.prototype.select_change = function(e) {
|
OptionsWaiter.prototype.select_change = function (e) {
|
||||||
var el = e.target,
|
let el = e.target,
|
||||||
option = el.getAttribute("option");
|
option = el.getAttribute('option');
|
||||||
|
|
||||||
this.app.options[option] = el.value;
|
this.app.options[option] = el.value;
|
||||||
localStorage.setItem("options", JSON.stringify(this.app.options));
|
localStorage.setItem('options', JSON.stringify(this.app.options));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets or unsets word wrap on the input and output depending on the word_wrap option value.
|
* Sets or unsets word wrap on the input and output depending on the word_wrap option value.
|
||||||
*/
|
*/
|
||||||
OptionsWaiter.prototype.set_word_wrap = function() {
|
OptionsWaiter.prototype.set_word_wrap = function () {
|
||||||
document.getElementById("input-text").classList.remove("word-wrap");
|
document.getElementById('input-text').classList.remove('word-wrap');
|
||||||
document.getElementById("output-text").classList.remove("word-wrap");
|
document.getElementById('output-text').classList.remove('word-wrap');
|
||||||
document.getElementById("output-html").classList.remove("word-wrap");
|
document.getElementById('output-html').classList.remove('word-wrap');
|
||||||
document.getElementById("input-highlighter").classList.remove("word-wrap");
|
document.getElementById('input-highlighter').classList.remove('word-wrap');
|
||||||
document.getElementById("output-highlighter").classList.remove("word-wrap");
|
document.getElementById('output-highlighter').classList.remove('word-wrap');
|
||||||
|
|
||||||
if (!this.app.options.word_wrap) {
|
if (!this.app.options.word_wrap) {
|
||||||
document.getElementById("input-text").classList.add("word-wrap");
|
document.getElementById('input-text').classList.add('word-wrap');
|
||||||
document.getElementById("output-text").classList.add("word-wrap");
|
document.getElementById('output-text').classList.add('word-wrap');
|
||||||
document.getElementById("output-html").classList.add("word-wrap");
|
document.getElementById('output-html').classList.add('word-wrap');
|
||||||
document.getElementById("input-highlighter").classList.add("word-wrap");
|
document.getElementById('input-highlighter').classList.add('word-wrap');
|
||||||
document.getElementById("output-highlighter").classList.add("word-wrap");
|
document.getElementById('output-highlighter').classList.add('word-wrap');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,9 +9,9 @@
|
||||||
* @param {HTMLApp} app - The main view object for CyberChef.
|
* @param {HTMLApp} app - The main view object for CyberChef.
|
||||||
* @param {Manager} manager - The CyberChef event manager.
|
* @param {Manager} manager - The CyberChef event manager.
|
||||||
*/
|
*/
|
||||||
var OutputWaiter = function(app, manager) {
|
const OutputWaiter = function (app, manager) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,8 +20,8 @@ var OutputWaiter = function(app, manager) {
|
||||||
*
|
*
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
OutputWaiter.prototype.get = function() {
|
OutputWaiter.prototype.get = function () {
|
||||||
return document.getElementById("output-text").value;
|
return document.getElementById('output-text').value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,43 +32,43 @@ OutputWaiter.prototype.get = function() {
|
||||||
* @param {string} type - The data type of the output
|
* @param {string} type - The data type of the output
|
||||||
* @param {number} duration - The length of time (ms) it took to generate the output
|
* @param {number} duration - The length of time (ms) it took to generate the output
|
||||||
*/
|
*/
|
||||||
OutputWaiter.prototype.set = function(data_str, type, duration) {
|
OutputWaiter.prototype.set = function (data_str, type, duration) {
|
||||||
var output_text = document.getElementById("output-text"),
|
let output_text = document.getElementById('output-text'),
|
||||||
output_html = document.getElementById("output-html"),
|
output_html = document.getElementById('output-html'),
|
||||||
output_highlighter = document.getElementById("output-highlighter"),
|
output_highlighter = document.getElementById('output-highlighter'),
|
||||||
input_highlighter = document.getElementById("input-highlighter");
|
input_highlighter = document.getElementById('input-highlighter');
|
||||||
|
|
||||||
if (type == "html") {
|
if (type == 'html') {
|
||||||
output_text.style.display = "none";
|
output_text.style.display = 'none';
|
||||||
output_html.style.display = "block";
|
output_html.style.display = 'block';
|
||||||
output_highlighter.display = "none";
|
output_highlighter.display = 'none';
|
||||||
input_highlighter.display = "none";
|
input_highlighter.display = 'none';
|
||||||
|
|
||||||
output_text.value = "";
|
output_text.value = '';
|
||||||
output_html.innerHTML = data_str;
|
output_html.innerHTML = data_str;
|
||||||
|
|
||||||
// Execute script sections
|
// Execute script sections
|
||||||
var script_elements = output_html.querySelectorAll("script");
|
const script_elements = output_html.querySelectorAll('script');
|
||||||
for (var i = 0; i < script_elements.length; i++) {
|
for (let i = 0; i < script_elements.length; i++) {
|
||||||
try {
|
try {
|
||||||
eval(script_elements[i].innerHTML); // jshint ignore:line
|
eval(script_elements[i].innerHTML); // jshint ignore:line
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
output_text.style.display = "block";
|
|
||||||
output_html.style.display = "none";
|
|
||||||
output_highlighter.display = "block";
|
|
||||||
input_highlighter.display = "block";
|
|
||||||
|
|
||||||
output_text.value = Utils.printable(data_str, true);
|
|
||||||
output_html.innerHTML = "";
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
output_text.style.display = 'block';
|
||||||
|
output_html.style.display = 'none';
|
||||||
|
output_highlighter.display = 'block';
|
||||||
|
input_highlighter.display = 'block';
|
||||||
|
|
||||||
this.manager.highlighter.remove_highlights();
|
output_text.value = Utils.printable(data_str, true);
|
||||||
var lines = data_str.count("\n") + 1;
|
output_html.innerHTML = '';
|
||||||
this.set_output_info(data_str.length, lines, duration);
|
}
|
||||||
|
|
||||||
|
this.manager.highlighter.remove_highlights();
|
||||||
|
const lines = data_str.count('\n') + 1;
|
||||||
|
this.set_output_info(data_str.length, lines, duration);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -79,19 +79,19 @@ OutputWaiter.prototype.set = function(data_str, type, duration) {
|
||||||
* @param {number} lines - The number of the lines in the current output string
|
* @param {number} lines - The number of the lines in the current output string
|
||||||
* @param {number} duration - The length of time (ms) it took to generate the output
|
* @param {number} duration - The length of time (ms) it took to generate the output
|
||||||
*/
|
*/
|
||||||
OutputWaiter.prototype.set_output_info = function(length, lines, duration) {
|
OutputWaiter.prototype.set_output_info = function (length, lines, duration) {
|
||||||
var width = length.toString().length;
|
let width = length.toString().length;
|
||||||
width = width < 4 ? 4 : width;
|
width = width < 4 ? 4 : width;
|
||||||
|
|
||||||
var length_str = Utils.pad(length.toString(), width, " ").replace(/ /g, " ");
|
const length_str = Utils.pad(length.toString(), width, ' ').replace(/ /g, ' ');
|
||||||
var lines_str = Utils.pad(lines.toString(), width, " ").replace(/ /g, " ");
|
const lines_str = Utils.pad(lines.toString(), width, ' ').replace(/ /g, ' ');
|
||||||
var time_str = Utils.pad(duration.toString() + "ms", width, " ").replace(/ /g, " ");
|
const time_str = Utils.pad(`${duration.toString()}ms`, width, ' ').replace(/ /g, ' ');
|
||||||
|
|
||||||
document.getElementById("output-info").innerHTML = "time: " + time_str +
|
document.getElementById('output-info').innerHTML = `time: ${time_str
|
||||||
"<br>length: " + length_str +
|
}<br>length: ${length_str
|
||||||
"<br>lines: " + lines_str;
|
}<br>lines: ${lines_str}`;
|
||||||
document.getElementById("input-selection-info").innerHTML = "";
|
document.getElementById('input-selection-info').innerHTML = '';
|
||||||
document.getElementById("output-selection-info").innerHTML = "";
|
document.getElementById('output-selection-info').innerHTML = '';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -99,22 +99,22 @@ OutputWaiter.prototype.set_output_info = function(length, lines, duration) {
|
||||||
* Handler for save click events.
|
* Handler for save click events.
|
||||||
* Saves the current output to a file, downloaded as a URL octet stream.
|
* Saves the current output to a file, downloaded as a URL octet stream.
|
||||||
*/
|
*/
|
||||||
OutputWaiter.prototype.save_click = function() {
|
OutputWaiter.prototype.save_click = function () {
|
||||||
var data = Utils.to_base64(this.app.dish_str),
|
let data = Utils.to_base64(this.app.dish_str),
|
||||||
filename = window.prompt("Please enter a filename:", "download.dat");
|
filename = window.prompt('Please enter a filename:', 'download.dat');
|
||||||
|
|
||||||
if (filename) {
|
if (filename) {
|
||||||
var el = document.createElement("a");
|
const el = document.createElement('a');
|
||||||
el.setAttribute("href", "data:application/octet-stream;base64;charset=utf-8," + data);
|
el.setAttribute('href', `data:application/octet-stream;base64;charset=utf-8,${data}`);
|
||||||
el.setAttribute("download", filename);
|
el.setAttribute('download', filename);
|
||||||
|
|
||||||
// Firefox requires that the element be added to the DOM before it can be clicked
|
// Firefox requires that the element be added to the DOM before it can be clicked
|
||||||
el.style.display = "none";
|
el.style.display = 'none';
|
||||||
document.body.appendChild(el);
|
document.body.appendChild(el);
|
||||||
|
|
||||||
el.click();
|
el.click();
|
||||||
el.remove();
|
el.remove();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -122,10 +122,10 @@ OutputWaiter.prototype.save_click = function() {
|
||||||
* Handler for switch click events.
|
* Handler for switch click events.
|
||||||
* Moves the current output into the input textarea.
|
* Moves the current output into the input textarea.
|
||||||
*/
|
*/
|
||||||
OutputWaiter.prototype.switch_click = function() {
|
OutputWaiter.prototype.switch_click = function () {
|
||||||
this.switch_orig_data = this.manager.input.get();
|
this.switch_orig_data = this.manager.input.get();
|
||||||
document.getElementById("undo-switch").disabled = false;
|
document.getElementById('undo-switch').disabled = false;
|
||||||
this.app.set_input(this.app.dish_str);
|
this.app.set_input(this.app.dish_str);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -133,7 +133,7 @@ OutputWaiter.prototype.switch_click = function() {
|
||||||
* Handler for undo switch click events.
|
* Handler for undo switch click events.
|
||||||
* Removes the output from the input and replaces the input that was removed.
|
* Removes the output from the input and replaces the input that was removed.
|
||||||
*/
|
*/
|
||||||
OutputWaiter.prototype.undo_switch_click = function() {
|
OutputWaiter.prototype.undo_switch_click = function () {
|
||||||
this.app.set_input(this.switch_orig_data);
|
this.app.set_input(this.switch_orig_data);
|
||||||
document.getElementById("undo-switch").disabled = true;
|
document.getElementById('undo-switch').disabled = true;
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,52 +11,52 @@
|
||||||
* @param {HTMLApp} app - The main view object for CyberChef.
|
* @param {HTMLApp} app - The main view object for CyberChef.
|
||||||
* @param {Manager} manager - The CyberChef event manager.
|
* @param {Manager} manager - The CyberChef event manager.
|
||||||
*/
|
*/
|
||||||
var RecipeWaiter = function(app, manager) {
|
const RecipeWaiter = function (app, manager) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
this.remove_intent = false;
|
this.remove_intent = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets up the drag and drop capability for operations in the operations and recipe areas.
|
* Sets up the drag and drop capability for operations in the operations and recipe areas.
|
||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.initialise_operation_drag_n_drop = function() {
|
RecipeWaiter.prototype.initialise_operation_drag_n_drop = function () {
|
||||||
var rec_list = document.getElementById("rec_list"),
|
let rec_list = document.getElementById('rec_list'),
|
||||||
op_lists = document.querySelectorAll(".category .op_list");
|
op_lists = document.querySelectorAll('.category .op_list');
|
||||||
|
|
||||||
|
|
||||||
// Recipe list
|
// Recipe list
|
||||||
Sortable.create(rec_list, {
|
Sortable.create(rec_list, {
|
||||||
group: "recipe",
|
group: 'recipe',
|
||||||
sort: true,
|
sort: true,
|
||||||
animation: 0,
|
animation: 0,
|
||||||
delay: 0,
|
delay: 0,
|
||||||
filter: ".arg-input,.arg", // Relies on commenting out a line in Sortable.js which calls evt.preventDefault()
|
filter: '.arg-input,.arg', // Relies on commenting out a line in Sortable.js which calls evt.preventDefault()
|
||||||
setData: function(dataTransfer, drag_el) {
|
setData(dataTransfer, drag_el) {
|
||||||
dataTransfer.setData("Text", drag_el.querySelector(".arg-title").textContent);
|
dataTransfer.setData('Text', drag_el.querySelector('.arg-title').textContent);
|
||||||
},
|
},
|
||||||
onEnd: function(evt) {
|
onEnd: function (evt) {
|
||||||
if (this.remove_intent) {
|
if (this.remove_intent) {
|
||||||
evt.item.remove();
|
evt.item.remove();
|
||||||
evt.target.dispatchEvent(this.manager.operationremove);
|
evt.target.dispatchEvent(this.manager.operationremove);
|
||||||
}
|
}
|
||||||
}.bind(this)
|
}.bind(this),
|
||||||
});
|
});
|
||||||
|
|
||||||
Sortable.utils.on(rec_list, "dragover", function() {
|
Sortable.utils.on(rec_list, 'dragover', () => {
|
||||||
this.remove_intent = false;
|
this.remove_intent = false;
|
||||||
}.bind(this));
|
});
|
||||||
|
|
||||||
Sortable.utils.on(rec_list, "dragleave", function() {
|
Sortable.utils.on(rec_list, 'dragleave', () => {
|
||||||
this.remove_intent = true;
|
this.remove_intent = true;
|
||||||
this.app.progress = 0;
|
this.app.progress = 0;
|
||||||
}.bind(this));
|
});
|
||||||
|
|
||||||
// Favourites category
|
// Favourites category
|
||||||
document.querySelector("#categories a").addEventListener("dragover", this.fav_dragover.bind(this));
|
document.querySelector('#categories a').addEventListener('dragover', this.fav_dragover.bind(this));
|
||||||
document.querySelector("#categories a").addEventListener("dragleave", this.fav_dragleave.bind(this));
|
document.querySelector('#categories a').addEventListener('dragleave', this.fav_dragleave.bind(this));
|
||||||
document.querySelector("#categories a").addEventListener("drop", this.fav_drop.bind(this));
|
document.querySelector('#categories a').addEventListener('drop', this.fav_drop.bind(this));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -65,23 +65,23 @@ RecipeWaiter.prototype.initialise_operation_drag_n_drop = function() {
|
||||||
*
|
*
|
||||||
* @param {element} list_el - The list the initialise
|
* @param {element} list_el - The list the initialise
|
||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.create_sortable_seed_list = function(list_el) {
|
RecipeWaiter.prototype.create_sortable_seed_list = function (list_el) {
|
||||||
Sortable.create(list_el, {
|
Sortable.create(list_el, {
|
||||||
group: {
|
group: {
|
||||||
name: "recipe",
|
name: 'recipe',
|
||||||
pull: "clone",
|
pull: 'clone',
|
||||||
put: false
|
put: false,
|
||||||
},
|
},
|
||||||
sort: false,
|
sort: false,
|
||||||
setData: function(dataTransfer, drag_el) {
|
setData(dataTransfer, drag_el) {
|
||||||
dataTransfer.setData("Text", drag_el.textContent);
|
dataTransfer.setData('Text', drag_el.textContent);
|
||||||
},
|
},
|
||||||
onStart: function(evt) {
|
onStart(evt) {
|
||||||
$(evt.item).popover("destroy");
|
$(evt.item).popover('destroy');
|
||||||
evt.item.setAttribute("data-toggle", "popover-disabled");
|
evt.item.setAttribute('data-toggle', 'popover-disabled');
|
||||||
},
|
},
|
||||||
onEnd: this.op_sort_end.bind(this)
|
onEnd: this.op_sort_end.bind(this),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -93,25 +93,25 @@ RecipeWaiter.prototype.create_sortable_seed_list = function(list_el) {
|
||||||
* @fires Manager#operationadd
|
* @fires Manager#operationadd
|
||||||
* @param {event} evt
|
* @param {event} evt
|
||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.op_sort_end = function(evt) {
|
RecipeWaiter.prototype.op_sort_end = function (evt) {
|
||||||
if (this.remove_intent) {
|
if (this.remove_intent) {
|
||||||
if (evt.item.parentNode.id == "rec_list") {
|
if (evt.item.parentNode.id == 'rec_list') {
|
||||||
evt.item.remove();
|
evt.item.remove();
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Reinitialise the popover on the original element in the ops list because for some reason it
|
// Reinitialise the popover on the original element in the ops list because for some reason it
|
||||||
// gets destroyed and recreated.
|
// gets destroyed and recreated.
|
||||||
$(evt.clone).popover();
|
$(evt.clone).popover();
|
||||||
$(evt.clone).children("[data-toggle=popover]").popover();
|
$(evt.clone).children('[data-toggle=popover]').popover();
|
||||||
|
|
||||||
if (evt.item.parentNode.id !== "rec_list") {
|
if (evt.item.parentNode.id !== 'rec_list') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.build_recipe_operation(evt.item);
|
this.build_recipe_operation(evt.item);
|
||||||
evt.item.dispatchEvent(this.manager.operationadd);
|
evt.item.dispatchEvent(this.manager.operationadd);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -122,22 +122,23 @@ RecipeWaiter.prototype.op_sort_end = function(evt) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.fav_dragover = function(e) {
|
RecipeWaiter.prototype.fav_dragover = function (e) {
|
||||||
if (e.dataTransfer.effectAllowed !== "move")
|
if (e.dataTransfer.effectAllowed !== 'move') {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
if (e.target.className && e.target.className.indexOf("category-title") > -1) {
|
if (e.target.className && e.target.className.indexOf('category-title') > -1) {
|
||||||
// Hovering over the a
|
// Hovering over the a
|
||||||
e.target.classList.add("favourites-hover");
|
e.target.classList.add('favourites-hover');
|
||||||
} else if (e.target.parentNode.className && e.target.parentNode.className.indexOf("category-title") > -1) {
|
} else if (e.target.parentNode.className && e.target.parentNode.className.indexOf('category-title') > -1) {
|
||||||
// Hovering over the Edit button
|
// Hovering over the Edit button
|
||||||
e.target.parentNode.classList.add("favourites-hover");
|
e.target.parentNode.classList.add('favourites-hover');
|
||||||
} else if (e.target.parentNode.parentNode.className && e.target.parentNode.parentNode.className.indexOf("category-title") > -1) {
|
} else if (e.target.parentNode.parentNode.className && e.target.parentNode.parentNode.className.indexOf('category-title') > -1) {
|
||||||
// Hovering over the image on the Edit button
|
// Hovering over the image on the Edit button
|
||||||
e.target.parentNode.parentNode.classList.add("favourites-hover");
|
e.target.parentNode.parentNode.classList.add('favourites-hover');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -147,10 +148,10 @@ RecipeWaiter.prototype.fav_dragover = function(e) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.fav_dragleave = function(e) {
|
RecipeWaiter.prototype.fav_dragleave = function (e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
document.querySelector("#categories a").classList.remove("favourites-hover");
|
document.querySelector('#categories a').classList.remove('favourites-hover');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -160,13 +161,13 @@ RecipeWaiter.prototype.fav_dragleave = function(e) {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.fav_drop = function(e) {
|
RecipeWaiter.prototype.fav_drop = function (e) {
|
||||||
e.stopPropagation();
|
e.stopPropagation();
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
e.target.classList.remove("favourites-hover");
|
e.target.classList.remove('favourites-hover');
|
||||||
|
|
||||||
var op_name = e.dataTransfer.getData("Text");
|
const op_name = e.dataTransfer.getData('Text');
|
||||||
this.app.add_favourite(op_name);
|
this.app.add_favourite(op_name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -175,8 +176,8 @@ RecipeWaiter.prototype.fav_drop = function(e) {
|
||||||
*
|
*
|
||||||
* @fires Manager#statechange
|
* @fires Manager#statechange
|
||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.ing_change = function() {
|
RecipeWaiter.prototype.ing_change = function () {
|
||||||
window.dispatchEvent(this.manager.statechange);
|
window.dispatchEvent(this.manager.statechange);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -187,21 +188,21 @@ RecipeWaiter.prototype.ing_change = function() {
|
||||||
* @fires Manager#statechange
|
* @fires Manager#statechange
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.disable_click = function(e) {
|
RecipeWaiter.prototype.disable_click = function (e) {
|
||||||
var icon = e.target;
|
const icon = e.target;
|
||||||
|
|
||||||
if (icon.getAttribute("disabled") == "false") {
|
if (icon.getAttribute('disabled') == 'false') {
|
||||||
icon.setAttribute("disabled", "true");
|
icon.setAttribute('disabled', 'true');
|
||||||
icon.classList.add("disable-icon-selected");
|
icon.classList.add('disable-icon-selected');
|
||||||
icon.parentNode.parentNode.classList.add("disabled");
|
icon.parentNode.parentNode.classList.add('disabled');
|
||||||
} else {
|
} else {
|
||||||
icon.setAttribute("disabled", "false");
|
icon.setAttribute('disabled', 'false');
|
||||||
icon.classList.remove("disable-icon-selected");
|
icon.classList.remove('disable-icon-selected');
|
||||||
icon.parentNode.parentNode.classList.remove("disabled");
|
icon.parentNode.parentNode.classList.remove('disabled');
|
||||||
}
|
}
|
||||||
|
|
||||||
this.app.progress = 0;
|
this.app.progress = 0;
|
||||||
window.dispatchEvent(this.manager.statechange);
|
window.dispatchEvent(this.manager.statechange);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -212,18 +213,18 @@ RecipeWaiter.prototype.disable_click = function(e) {
|
||||||
* @fires Manager#statechange
|
* @fires Manager#statechange
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.breakpoint_click = function(e) {
|
RecipeWaiter.prototype.breakpoint_click = function (e) {
|
||||||
var bp = e.target;
|
const bp = e.target;
|
||||||
|
|
||||||
if (bp.getAttribute("break") == "false") {
|
if (bp.getAttribute('break') == 'false') {
|
||||||
bp.setAttribute("break", "true");
|
bp.setAttribute('break', 'true');
|
||||||
bp.classList.add("breakpoint-selected");
|
bp.classList.add('breakpoint-selected');
|
||||||
} else {
|
} else {
|
||||||
bp.setAttribute("break", "false");
|
bp.setAttribute('break', 'false');
|
||||||
bp.classList.remove("breakpoint-selected");
|
bp.classList.remove('breakpoint-selected');
|
||||||
}
|
}
|
||||||
|
|
||||||
window.dispatchEvent(this.manager.statechange);
|
window.dispatchEvent(this.manager.statechange);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -234,9 +235,9 @@ RecipeWaiter.prototype.breakpoint_click = function(e) {
|
||||||
* @fires Manager#statechange
|
* @fires Manager#statechange
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.operation_dblclick = function(e) {
|
RecipeWaiter.prototype.operation_dblclick = function (e) {
|
||||||
e.target.remove();
|
e.target.remove();
|
||||||
window.dispatchEvent(this.manager.statechange);
|
window.dispatchEvent(this.manager.statechange);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -247,9 +248,9 @@ RecipeWaiter.prototype.operation_dblclick = function(e) {
|
||||||
* @fires Manager#statechange
|
* @fires Manager#statechange
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.operation_child_dblclick = function(e) {
|
RecipeWaiter.prototype.operation_child_dblclick = function (e) {
|
||||||
e.target.parentNode.remove();
|
e.target.parentNode.remove();
|
||||||
window.dispatchEvent(this.manager.statechange);
|
window.dispatchEvent(this.manager.statechange);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -258,49 +259,54 @@ RecipeWaiter.prototype.operation_child_dblclick = function(e) {
|
||||||
*
|
*
|
||||||
* @returns {recipe_config}
|
* @returns {recipe_config}
|
||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.get_config = function() {
|
RecipeWaiter.prototype.get_config = function () {
|
||||||
var config = [], ingredients, ing_list, disabled, bp, item,
|
let config = [],
|
||||||
operations = document.querySelectorAll("#rec_list li.operation");
|
ingredients,
|
||||||
|
ing_list,
|
||||||
|
disabled,
|
||||||
|
bp,
|
||||||
|
item,
|
||||||
|
operations = document.querySelectorAll('#rec_list li.operation');
|
||||||
|
|
||||||
for (var i = 0; i < operations.length; i++) {
|
for (let i = 0; i < operations.length; i++) {
|
||||||
ingredients = [];
|
ingredients = [];
|
||||||
disabled = operations[i].querySelector(".disable-icon");
|
disabled = operations[i].querySelector('.disable-icon');
|
||||||
bp = operations[i].querySelector(".breakpoint");
|
bp = operations[i].querySelector('.breakpoint');
|
||||||
ing_list = operations[i].querySelectorAll(".arg");
|
ing_list = operations[i].querySelectorAll('.arg');
|
||||||
|
|
||||||
for (var j = 0; j < ing_list.length; j++) {
|
for (let j = 0; j < ing_list.length; j++) {
|
||||||
if (ing_list[j].getAttribute("type") == "checkbox") {
|
if (ing_list[j].getAttribute('type') == 'checkbox') {
|
||||||
// checkbox
|
// checkbox
|
||||||
ingredients[j] = ing_list[j].checked;
|
ingredients[j] = ing_list[j].checked;
|
||||||
} else if (ing_list[j].classList.contains("toggle-string")) {
|
} else if (ing_list[j].classList.contains('toggle-string')) {
|
||||||
// toggle_string
|
// toggle_string
|
||||||
ingredients[j] = {
|
ingredients[j] = {
|
||||||
option: ing_list[j].previousSibling.children[0].textContent.slice(0, -1),
|
option: ing_list[j].previousSibling.children[0].textContent.slice(0, -1),
|
||||||
string: ing_list[j].value
|
string: ing_list[j].value,
|
||||||
};
|
|
||||||
} else {
|
|
||||||
// all others
|
|
||||||
ingredients[j] = ing_list[j].value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
item = {
|
|
||||||
op: operations[i].querySelector(".arg-title").textContent,
|
|
||||||
args: ingredients
|
|
||||||
};
|
};
|
||||||
|
} else {
|
||||||
if (disabled && disabled.getAttribute("disabled") == "true") {
|
// all others
|
||||||
item.disabled = true;
|
ingredients[j] = ing_list[j].value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bp && bp.getAttribute("break") == "true") {
|
|
||||||
item.breakpoint = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
config.push(item);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return config;
|
item = {
|
||||||
|
op: operations[i].querySelector('.arg-title').textContent,
|
||||||
|
args: ingredients,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (disabled && disabled.getAttribute('disabled') == 'true') {
|
||||||
|
item.disabled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bp && bp.getAttribute('break') == 'true') {
|
||||||
|
item.breakpoint = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
config.push(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
return config;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -309,15 +315,15 @@ RecipeWaiter.prototype.get_config = function() {
|
||||||
*
|
*
|
||||||
* @param {number} position
|
* @param {number} position
|
||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.update_breakpoint_indicator = function(position) {
|
RecipeWaiter.prototype.update_breakpoint_indicator = function (position) {
|
||||||
var operations = document.querySelectorAll("#rec_list li.operation");
|
const operations = document.querySelectorAll('#rec_list li.operation');
|
||||||
for (var i = 0; i < operations.length; i++) {
|
for (let i = 0; i < operations.length; i++) {
|
||||||
if (i == position) {
|
if (i == position) {
|
||||||
operations[i].classList.add("break");
|
operations[i].classList.add('break');
|
||||||
} else {
|
} else {
|
||||||
operations[i].classList.remove("break");
|
operations[i].classList.remove('break');
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -327,21 +333,21 @@ RecipeWaiter.prototype.update_breakpoint_indicator = function(position) {
|
||||||
*
|
*
|
||||||
* @param {element} el - The operation stub element from the operations pane
|
* @param {element} el - The operation stub element from the operations pane
|
||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.build_recipe_operation = function(el) {
|
RecipeWaiter.prototype.build_recipe_operation = function (el) {
|
||||||
var op_name = el.textContent;
|
const op_name = el.textContent;
|
||||||
var op = new HTMLOperation(op_name, this.app.operations[op_name], this.app, this.manager);
|
const op = new HTMLOperation(op_name, this.app.operations[op_name], this.app, this.manager);
|
||||||
el.innerHTML = op.to_full_html();
|
el.innerHTML = op.to_full_html();
|
||||||
|
|
||||||
if (this.app.operations[op_name].flow_control) {
|
if (this.app.operations[op_name].flow_control) {
|
||||||
el.classList.add("flow-control-op");
|
el.classList.add('flow-control-op');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Disable auto-bake if this is a manual op - this should be moved to the 'operationadd'
|
// Disable auto-bake if this is a manual op - this should be moved to the 'operationadd'
|
||||||
// handler after event restructuring
|
// handler after event restructuring
|
||||||
if (op.manual_bake && this.app.auto_bake_) {
|
if (op.manual_bake && this.app.auto_bake_) {
|
||||||
this.manager.controls.set_auto_bake(false);
|
this.manager.controls.set_auto_bake(false);
|
||||||
this.app.alert("Auto-Bake is disabled by default when using this operation.", "info", 5000);
|
this.app.alert('Auto-Bake is disabled by default when using this operation.', 'info', 5000);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -351,15 +357,15 @@ RecipeWaiter.prototype.build_recipe_operation = function(el) {
|
||||||
* @param {string} name - The name of the operation to add
|
* @param {string} name - The name of the operation to add
|
||||||
* @returns {element}
|
* @returns {element}
|
||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.add_operation = function(name) {
|
RecipeWaiter.prototype.add_operation = function (name) {
|
||||||
var item = document.createElement("li");
|
const item = document.createElement('li');
|
||||||
item.classList.add("operation");
|
item.classList.add('operation');
|
||||||
item.innerHTML = name;
|
item.innerHTML = name;
|
||||||
this.build_recipe_operation(item);
|
this.build_recipe_operation(item);
|
||||||
document.getElementById("rec_list").appendChild(item);
|
document.getElementById('rec_list').appendChild(item);
|
||||||
|
|
||||||
item.dispatchEvent(this.manager.operationadd);
|
item.dispatchEvent(this.manager.operationadd);
|
||||||
return item;
|
return item;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -368,12 +374,12 @@ RecipeWaiter.prototype.add_operation = function(name) {
|
||||||
*
|
*
|
||||||
* @fires Manager#operationremove
|
* @fires Manager#operationremove
|
||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.clear_recipe = function() {
|
RecipeWaiter.prototype.clear_recipe = function () {
|
||||||
var rec_list = document.getElementById("rec_list");
|
const rec_list = document.getElementById('rec_list');
|
||||||
while (rec_list.firstChild) {
|
while (rec_list.firstChild) {
|
||||||
rec_list.removeChild(rec_list.firstChild);
|
rec_list.removeChild(rec_list.firstChild);
|
||||||
}
|
}
|
||||||
rec_list.dispatchEvent(this.manager.operationremove);
|
rec_list.dispatchEvent(this.manager.operationremove);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -383,12 +389,12 @@ RecipeWaiter.prototype.clear_recipe = function() {
|
||||||
*
|
*
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.dropdown_toggle_click = function(e) {
|
RecipeWaiter.prototype.dropdown_toggle_click = function (e) {
|
||||||
var el = e.target,
|
let el = e.target,
|
||||||
button = el.parentNode.parentNode.previousSibling;
|
button = el.parentNode.parentNode.previousSibling;
|
||||||
|
|
||||||
button.innerHTML = el.textContent + " <span class='caret'></span>";
|
button.innerHTML = `${el.textContent} <span class='caret'></span>`;
|
||||||
this.ing_change();
|
this.ing_change();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -399,8 +405,8 @@ RecipeWaiter.prototype.dropdown_toggle_click = function(e) {
|
||||||
* @fires Manager#statechange
|
* @fires Manager#statechange
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.op_add = function(e) {
|
RecipeWaiter.prototype.op_add = function (e) {
|
||||||
window.dispatchEvent(this.manager.statechange);
|
window.dispatchEvent(this.manager.statechange);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -411,6 +417,6 @@ RecipeWaiter.prototype.op_add = function(e) {
|
||||||
* @fires Manager#statechange
|
* @fires Manager#statechange
|
||||||
* @param {event} e
|
* @param {event} e
|
||||||
*/
|
*/
|
||||||
RecipeWaiter.prototype.op_remove = function(e) {
|
RecipeWaiter.prototype.op_remove = function (e) {
|
||||||
window.dispatchEvent(this.manager.statechange);
|
window.dispatchEvent(this.manager.statechange);
|
||||||
};
|
};
|
|
@ -9,27 +9,27 @@
|
||||||
* @param {HTMLApp} app - The main view object for CyberChef.
|
* @param {HTMLApp} app - The main view object for CyberChef.
|
||||||
* @param {Manager} manager - The CyberChef event manager.
|
* @param {Manager} manager - The CyberChef event manager.
|
||||||
*/
|
*/
|
||||||
var SeasonalWaiter = function(app, manager) {
|
const SeasonalWaiter = function (app, manager) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
this.manager = manager;
|
this.manager = manager;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Loads all relevant items depending on the current date.
|
* Loads all relevant items depending on the current date.
|
||||||
*/
|
*/
|
||||||
SeasonalWaiter.prototype.load = function() {
|
SeasonalWaiter.prototype.load = function () {
|
||||||
var now = new Date();
|
const now = new Date();
|
||||||
|
|
||||||
// Snowfall
|
// Snowfall
|
||||||
if (now.getMonth() == 11 && now.getDate() > 12) { // Dec 13 -> Dec 31
|
if (now.getMonth() == 11 && now.getDate() > 12) { // Dec 13 -> Dec 31
|
||||||
this.app.options.snow = false;
|
this.app.options.snow = false;
|
||||||
this.create_snow_option();
|
this.create_snow_option();
|
||||||
this.manager.add_dynamic_listener(".option-item input:checkbox[option='snow']", "switchChange.bootstrapSwitch", this.let_it_snow, this);
|
this.manager.add_dynamic_listener(".option-item input:checkbox[option='snow']", 'switchChange.bootstrapSwitch', this.let_it_snow, this);
|
||||||
this.manager.add_window_listener("resize", this.let_it_snow, this);
|
this.manager.add_window_listener('resize', this.let_it_snow, this);
|
||||||
this.manager.add_listeners(".btn", "click", this.shake_off_snow, this);
|
this.manager.add_listeners('.btn', 'click', this.shake_off_snow, this);
|
||||||
if (now.getDate() == 25) this.let_it_snow();
|
if (now.getDate() == 25) this.let_it_snow();
|
||||||
}
|
}
|
||||||
|
|
||||||
// SpiderChef
|
// SpiderChef
|
||||||
// if (now.getMonth() == 3 && now.getDate() == 1) { // Apr 1
|
// if (now.getMonth() == 3 && now.getDate() == 1) { // Apr 1
|
||||||
|
@ -38,8 +38,8 @@ SeasonalWaiter.prototype.load = function() {
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// Konami code
|
// Konami code
|
||||||
this.kkeys = [];
|
this.kkeys = [];
|
||||||
window.addEventListener("keydown", this.konami_code_listener.bind(this));
|
window.addEventListener('keydown', this.konami_code_listener.bind(this));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -47,19 +47,19 @@ SeasonalWaiter.prototype.load = function() {
|
||||||
* Replaces chef icons with spider icons.
|
* Replaces chef icons with spider icons.
|
||||||
* #spiderchef
|
* #spiderchef
|
||||||
*/
|
*/
|
||||||
SeasonalWaiter.prototype.insert_spider_icons = function() {
|
SeasonalWaiter.prototype.insert_spider_icons = function () {
|
||||||
var spider16 = "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAB3UlEQVQ4y2NgGJaAmYGBgVnf0oKJgYGBobWtXamqqoYTn2I4CI+LTzM2NTulpKbu+vPHz2dV5RWlluZmi3j5+KqFJSSEzpw8uQPdAEYYIzo5Kfjrl28rWFlZzjAzMYuEBQao3Lh+g+HGvbsMzExMDN++fWf4/PXLBzY2tqYNK1f2+4eHM2xcuRLigsT09Igf3384MTExbf767etBI319jU8fPsi+//jx/72HDxh5uLkZ7ty7y/Dz1687Avz8n2UUFR3Z2NjOySoqfmdhYGBg+PbtuwI7O8e5H79+8X379t357PnzYo+ePP7y6cuXc9++f69nYGRsvf/w4XdtLS2R799/bBUWFHr57sP7Jbs3b/ZkzswvUP3165fZ7z9//r988WIVAyPDr8tXr576+u3bpb9//7YwMjKeV1dV41NWVGoVEhDgPH761DJREeHaz1+/lqlpafUx6+jrRfz4+fPy+w8fTu/fsf3uw7t3L39+//4cv7DwGQYGhpdPbt9m4BcRFlNWVJC4fuvWASszs4C379792Ldt2xZBUdEdDP5hYSqQGIjDGa965uYKCalpZQwMDAxhMTG9DAwMDLaurhIkJY7A8IgGBgYGBgd3Dz2yUpeFo6O4rasrA9T24ZRxAAMTwMpgEJwLAAAAAElFTkSuQmCC",
|
let spider16 = 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAABmJLR0QA/wD/AP+gvaeTAAAACXBIWXMAAAsTAAALEwEAmpwYAAAB3UlEQVQ4y2NgGJaAmYGBgVnf0oKJgYGBobWtXamqqoYTn2I4CI+LTzM2NTulpKbu+vPHz2dV5RWlluZmi3j5+KqFJSSEzpw8uQPdAEYYIzo5Kfjrl28rWFlZzjAzMYuEBQao3Lh+g+HGvbsMzExMDN++fWf4/PXLBzY2tqYNK1f2+4eHM2xcuRLigsT09Igf3384MTExbf767etBI319jU8fPsi+//jx/72HDxh5uLkZ7ty7y/Dz1687Avz8n2UUFR3Z2NjOySoqfmdhYGBg+PbtuwI7O8e5H79+8X379t357PnzYo+ePP7y6cuXc9++f69nYGRsvf/w4XdtLS2R799/bBUWFHr57sP7Jbs3b/ZkzswvUP3165fZ7z9//r988WIVAyPDr8tXr576+u3bpb9//7YwMjKeV1dV41NWVGoVEhDgPH761DJREeHaz1+/lqlpafUx6+jrRfz4+fPy+w8fTu/fsf3uw7t3L39+//4cv7DwGQYGhpdPbt9m4BcRFlNWVJC4fuvWASszs4C379792Ldt2xZBUdEdDP5hYSqQGIjDGa965uYKCalpZQwMDAxhMTG9DAwMDLaurhIkJY7A8IgGBgYGBgd3Dz2yUpeFo6O4rasrA9T24ZRxAAMTwMpgEJwLAAAAAElFTkSuQmCC',
|
||||||
spider32 = "iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAACYVBMVEUAAAAcJSU2Pz85QkM9RUWEhIWMjI2MkJEcJSU2Pz85QkM9RUWWlpc9RUVXXl4cJSU2Pz85QkM8REU9RUVRWFh6ens9RUVCSkpNVFRdY2McJSU5QkM7REQ9RUVGTk5KUlJQVldcY2Rla2uTk5WampscJSVUWltZX2BrcHF1e3scJSUjLCw9RUVASEhFTU1HTk9bYWJeZGRma2xudHV1eHiZmZocJSUyOjpJUFFQVldSWlpTWVpXXl5YXl5rb3B9fX6RkZIcJSUmLy8tNTU9RUVFTU1IT1BOVldRV1hTWlp0enocJSUfKChJUFBWXV1hZ2hnbGwcJSVETExLUlJLU1NNVVVPVlZYXl9cY2RiaGlobW5rcXFyd3h0eHgcJSUpMTFDS0tQV1dRV1hSWFlWXF1bYWJma2tobW5uc3SsrK0cJSVJUFBMVFROVlZVW1xZX2BdYmNhZ2hjaGhla2tqcHBscHE4Pz9KUlJRWVlSWVlXXF1aYGFbYWFfZWZlampqbW4cJSUgKSkiKysuNjY0PD01PT07QkNES0tHTk5JUFBMUlNMU1NOU1ROVVVPVVZRVlZRV1dSWVlWXFxXXV5aX2BbYWFbYWJcYmJcYmNcY2RdYmNgZmZhZmdkaWpkampkamtlamtla2tma2tma2xnbG1obW5pbG1pb3Bqb3Brb3BtcXJudHVvcHFvcXJvc3NwcXNwdXVxc3RzeXl1eXp2eXl3ent6e3x+gYKAhISBg4SKi4yLi4yWlpeampudnZ6fn6CkpaanqKiur6+vr7C4uLm6urq6u7u8vLy9vb3Av8DR0dL2b74UAAAAgHRSTlMAEBAQEBAQECAgICAgMDBAQEBAQEBAUFBQUGBgYGBgYGBgYGBgcHBwcHCAgICAgICAgICAgICPj4+Pj4+Pj4+Pj5+fn5+fn5+fn5+vr6+vr6+/v7+/v7+/v7+/v7+/z8/Pz8/Pz8/Pz8/P39/f39/f39/f39/f7+/v7+/v7+/v78x6RlYAAAGBSURBVDjLY2AYWUCSgUGAk4GBTdlUhQebvP7yjIgCPQbWzBMnjx5wwJSX37Rwfm1isqj9/iPHTuxYlyeMJi+yunfptBkZOw/uWj9h3vatcycu8eRGlldb3Vsts3ph/cFTh7fN3bCoe2Vf8+TZoQhTvBa6REozVC7cuPvQnmULJm1e2z+308eyJieEBSLPXbKQIUqQIczk+N6eNaumtnZMaWhaHM89m8XVCqJA02Y5w0xmga6yfVsamtrN4xoXNzS0JTHkK3CXy4EVFMumcxUy2LbENTVkZfEzMDAudtJyTmNwS2XQreAFyvOlK9louDNVaXurmjkGgnTMkWDgXswtNouFISEX6Awv+RihQi5OcYY4DtVARpCCFCMGhiJ1hjwFBpagEAaWEpFoC0WQOCOjFMRRwXYMDB4BDLJ+QLYsg7GBGjtasLnEMjCIrWBgyAZ7058FI9x1SoFEnTCDsCyIhynPILYYSFgbYpUDA5bpQBluXzxpI1yYAbd2sCMYRhwAAHB9ZPztbuMUAAAAAElFTkSuQmCC",
|
spider32 = 'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAACYVBMVEUAAAAcJSU2Pz85QkM9RUWEhIWMjI2MkJEcJSU2Pz85QkM9RUWWlpc9RUVXXl4cJSU2Pz85QkM8REU9RUVRWFh6ens9RUVCSkpNVFRdY2McJSU5QkM7REQ9RUVGTk5KUlJQVldcY2Rla2uTk5WampscJSVUWltZX2BrcHF1e3scJSUjLCw9RUVASEhFTU1HTk9bYWJeZGRma2xudHV1eHiZmZocJSUyOjpJUFFQVldSWlpTWVpXXl5YXl5rb3B9fX6RkZIcJSUmLy8tNTU9RUVFTU1IT1BOVldRV1hTWlp0enocJSUfKChJUFBWXV1hZ2hnbGwcJSVETExLUlJLU1NNVVVPVlZYXl9cY2RiaGlobW5rcXFyd3h0eHgcJSUpMTFDS0tQV1dRV1hSWFlWXF1bYWJma2tobW5uc3SsrK0cJSVJUFBMVFROVlZVW1xZX2BdYmNhZ2hjaGhla2tqcHBscHE4Pz9KUlJRWVlSWVlXXF1aYGFbYWFfZWZlampqbW4cJSUgKSkiKysuNjY0PD01PT07QkNES0tHTk5JUFBMUlNMU1NOU1ROVVVPVVZRVlZRV1dSWVlWXFxXXV5aX2BbYWFbYWJcYmJcYmNcY2RdYmNgZmZhZmdkaWpkampkamtlamtla2tma2tma2xnbG1obW5pbG1pb3Bqb3Brb3BtcXJudHVvcHFvcXJvc3NwcXNwdXVxc3RzeXl1eXp2eXl3ent6e3x+gYKAhISBg4SKi4yLi4yWlpeampudnZ6fn6CkpaanqKiur6+vr7C4uLm6urq6u7u8vLy9vb3Av8DR0dL2b74UAAAAgHRSTlMAEBAQEBAQECAgICAgMDBAQEBAQEBAUFBQUGBgYGBgYGBgYGBgcHBwcHCAgICAgICAgICAgICPj4+Pj4+Pj4+Pj5+fn5+fn5+fn5+vr6+vr6+/v7+/v7+/v7+/v7+/z8/Pz8/Pz8/Pz8/P39/f39/f39/f39/f7+/v7+/v7+/v78x6RlYAAAGBSURBVDjLY2AYWUCSgUGAk4GBTdlUhQebvP7yjIgCPQbWzBMnjx5wwJSX37Rwfm1isqj9/iPHTuxYlyeMJi+yunfptBkZOw/uWj9h3vatcycu8eRGlldb3Vsts3ph/cFTh7fN3bCoe2Vf8+TZoQhTvBa6REozVC7cuPvQnmULJm1e2z+308eyJieEBSLPXbKQIUqQIczk+N6eNaumtnZMaWhaHM89m8XVCqJA02Y5w0xmga6yfVsamtrN4xoXNzS0JTHkK3CXy4EVFMumcxUy2LbENTVkZfEzMDAudtJyTmNwS2XQreAFyvOlK9louDNVaXurmjkGgnTMkWDgXswtNouFISEX6Awv+RihQi5OcYY4DtVARpCCFCMGhiJ1hjwFBpagEAaWEpFoC0WQOCOjFMRRwXYMDB4BDLJ+QLYsg7GBGjtasLnEMjCIrWBgyAZ7058FI9x1SoFEnTCDsCyIhynPILYYSFgbYpUDA5bpQBluXzxpI1yYAbd2sCMYRhwAAHB9ZPztbuMUAAAAAElFTkSuQmCC',
|
||||||
spider64 = "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAJZUlEQVR42u1ZaXMU1xXlJ+gHpFITOy5sAcnIYCi2aIL2bTSSZrSP1NpHK41kISQBHgFaQIJBCMwi4TFUGYcPzggwEMcxHVGxQaag5QR/np/QP+Hmnsdr0hpmtEACwulb9aq7p7d3zz333Pt61q2zzTbbbLPNNttss80222yzzTbbVmu7MzKcJRWVkXjntqam6jyURPeGQqeTpqbOqp+evxC5dGlam5m5rE3PzGi8Hzx/4aLzbXDe09HdYxwZHaPc4mLFXVoW9pRXGNv3pDngeHlNLfE2Ljjj4xPOUGjSYKfpq6/+TLdv36bbX39Nt27epGvXvqSLl6bp3LlPtdOnz7jWrPNZ7kLCKCovp5bOTmP/4EHq6vmYMtzuSKbbbQCAHE8Rxd47MjrmuHjxkjF3/z4tLCzQkyc6PX78mB49ekQPHjygub/P0d27f6FrX/6JpqbO0YkT48E1R/sCr9cYHZ+gqrp64mPq+riXcoqKKC0vP9q6VyV/fQOiH+LrsPVY7z82PBKZnb1Bd+7cpfn5eQbgCT1hAADC/MN5uj83R99881eanZ2lL5gN/nrxjihAXwvOJ7l9vuiBQ4dF9LEtLC0V+2rv/ijTX6luaCS3rxT57wADAMTBQ4c9PIIDg4PBwYOHaHhklM5MnSWkwLff/o0+v3qVHv34Iz344QEDc4d8VVXUEAhQXXMzVdQqzKweKq6oABARzOGNOZ+Wl6fD6T25ubQrPT0E5xF93o82tbdjkkZ+iZfAAgbD6fZ6o339A8S0p7HjJ2h4eIQOHf6EujlV9nX3UOj0JDXzfXje+KlTdOPGDeF0T1+fGHg+2JSen08tHZ0CiPySEoPn8vq1IaOgIAzneQK0UzjcQd6qaqrlCVfV1+tpubnRnv5+2p2ZqYMF/oZGPTh0xLhy5Sr9wLn9j++/p5nLn9FxBoLZQJ1dKrkys6iYNeTExEnx3PqWFuF4W9deKq2upkEGCyzyMBC709MFC7r391Fjayv9MSdHZyCU1xJ5FjrNdN6VnU1KS4CjU4Yoh/m8CsezCguFJgAMV05ueP+BfhF5OL+gL9A/f/qJ7t3TaPLMFB09eoy6mTkMGg2PjTELOsS20OcTACgMKqJugqA0NtE7ycn0202b6A+ZmYIVAAKApGZlgRHB/0lqQPAqFEVE9hntM0R0ZblTzeswWdCeU8HAtYW+Uu0AUx+0f/jwoXD+56c/073v7tHU2XMiFbrUfVTNAtfL10FIAQL2QftsBrOEnavld5kg7E7PoF+99x79ev162rJrV9RMi6a2dvKUlQsR5uAgII7/ivMsbEE4g2hggjzC7LQL1OftovoO0WJKUn0gYEAn2hmMXo4QHIXQIfLfsfOXPwuLvB86cpQqamooyEzg1BLMwv04RkoE+B3B4BBBMHEcCwIP0N+ByJdUVhpgBJ7j4WvdANDjeTUglOaWEChfJF7uJzPX2HEPaj1vg7EAbHO5QnAeIPgqKvUB7gtAdbBgcvKMqOnc/NAIVwCcq21qElFnCgvaI9cBBFKhlSPbPzBIbbzduGULpWzfLkDAdZs++sgEwSlZqoIJMg2CzFSNGzODwdBfOi26+w4YTCm9LhDQwQDzdzguFf4FALjciTws8/u1yyx2N2/dovPnL9DRY8PkZ204xtuhoSM0wI7V8DEiirQCCHD+99u2CUdx3Lmvmz7kfemoGDgPEDr4HNKAf1MlAC4wgMGLWFJXQUrklZSEX6rLE2rOyDIQGlhgBUAyYFEZkm2vAGVi4qQ+x83M0389pevXr6OToy07d4qcR+krr/KzqpeJ/IfjGO+npDx3FCKHVPjd1q2LAMBI3ryZ9vL7U56BEzLfD80ACFba876OlGCQV9dAcT0Pyw7PgWij6zPP5Xt9EYgg+n3LosdVzdfz5CI8KY1LH31+5Yro9KanZwjHmPzmHTsoOeVDemfDBuE8dGVnWpqx3unUrE4CDLCAG64XAHB88IFgQV5xMY7DFmc16A6CZvnNBYYVcW+yKj0A/VHTsQ8dwMPNc6X+Gg0VIGbVpzYGWundjRujmGQWi9Eol7+TJ0/R2Nhx2sNlM9YJRPDdDRsM5DGPJB4KHOIhngHhAwixAGAAuDZ2lsuiYnFWBQOYrdEYNochilyiV6YHoH+rRNJkAG+fUw31PzU7Z1EFKPD69CIuQ1Bm6URoh8tFmVym3nc6rZOPyi0cD8HxeHPg3x2InNrbS79JTsYzNXmPuBclsO3ZvKwAOJEGsmI5rT0M+gSf3y9K5LIA1LUEIlL1k0AhCYBH5r9TCqBqib4D+c/1PyInGOThkvuaHCYALhlpbQWBMGR/4IpzTqlpbKQyf0045vdoe0zATHagSYMeWFMkbscnHRYPZjoFJaIiUkz9EJy15j/X3qCsAIqMcFjSWrNE1Iygg0fEmrtLzEUTdT/OhBFht9fHDVCbEUt3LJxi08B8Xj6vTDESriq9lVWqBECgHujqiqAUmufb1X3cfRXoluhjZWiwkOnSUcUS6ZD8LUmmhks6b5j1ezkAkAKZBe5QvPPcNBnoCawMwT66Qxk0R2xwwRAui2iSDGuaPDcubzo3EJq8wcx/9Vmk3QryH42QBQCFF0UagIiJtjX6DskIXTLEucJSHIIIMuO0BOcjn3A3ybU/lu5RCUBc5qA0Ih0Q2EWiCPRk7VfMNhjLW1zETic1tLYZDMKyuSsdfh5l6bwho5+0il4kyA0VohlNcF5FP8DlWo/VB16HYB2hJ0pzgIe2mcXxP2IOumPRY17U0tll8KIkZNb+sppafOxYkQPSaYfchyYoL9GMqWYpTLRIq1QUcT4O3aPQgqVqPwIOIMwDhzX6mQUFIQAgo+9MzcrWrML3mj6+YIKiFCZyhL87RqVQKrEskF+P1BUvfLCAkfRwoPUtq6l5o5+lZb5SolJo6oT8avTCl+c9OTmat6pKW8mLkvBpGzlvsiGuQr4ZEEwA1EQgoR/gNtxIxKBluz+OtMJiF31jHxqXBiAqAUj4WRxpADFM0DCFlv1khvX7Wol4vF4AIldVVxdZqlrIfiCYQPHDy6bAGv7nKYRVY6JewExZVAP+ey5Rv+Ba97aaUHMW5NauLmMZFkegBb/EP14d6NoS9QLWFSzWBmuZza8CQmSpXsAqmGtVy14VALWuuYWWy+W3OteXa4jwceQX6+BKG6J1/8+2VCNkm2222WabbbbZZpttttlmm22rt38DCdA0vq3bcAkAAAAASUVORK5CYII=";
|
spider64 = 'iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAYAAACqaXHeAAAJZUlEQVR42u1ZaXMU1xXlJ+gHpFITOy5sAcnIYCi2aIL2bTSSZrSP1NpHK41kISQBHgFaQIJBCMwi4TFUGYcPzggwEMcxHVGxQaag5QR/np/QP+Hmnsdr0hpmtEACwulb9aq7p7d3zz333Pt61q2zzTbbbLPNNttss80222yzzTbbVmu7MzKcJRWVkXjntqam6jyURPeGQqeTpqbOqp+evxC5dGlam5m5rE3PzGi8Hzx/4aLzbXDe09HdYxwZHaPc4mLFXVoW9pRXGNv3pDngeHlNLfE2Ljjj4xPOUGjSYKfpq6/+TLdv36bbX39Nt27epGvXvqSLl6bp3LlPtdOnz7jWrPNZ7kLCKCovp5bOTmP/4EHq6vmYMtzuSKbbbQCAHE8Rxd47MjrmuHjxkjF3/z4tLCzQkyc6PX78mB49ekQPHjygub/P0d27f6FrX/6JpqbO0YkT48E1R/sCr9cYHZ+gqrp64mPq+riXcoqKKC0vP9q6VyV/fQOiH+LrsPVY7z82PBKZnb1Bd+7cpfn5eQbgCT1hAADC/MN5uj83R99881eanZ2lL5gN/nrxjihAXwvOJ7l9vuiBQ4dF9LEtLC0V+2rv/ijTX6luaCS3rxT57wADAMTBQ4c9PIIDg4PBwYOHaHhklM5MnSWkwLff/o0+v3qVHv34Iz344QEDc4d8VVXUEAhQXXMzVdQqzKweKq6oABARzOGNOZ+Wl6fD6T25ubQrPT0E5xF93o82tbdjkkZ+iZfAAgbD6fZ6o339A8S0p7HjJ2h4eIQOHf6EujlV9nX3UOj0JDXzfXje+KlTdOPGDeF0T1+fGHg+2JSen08tHZ0CiPySEoPn8vq1IaOgIAzneQK0UzjcQd6qaqrlCVfV1+tpubnRnv5+2p2ZqYMF/oZGPTh0xLhy5Sr9wLn9j++/p5nLn9FxBoLZQJ1dKrkys6iYNeTExEnx3PqWFuF4W9deKq2upkEGCyzyMBC709MFC7r391Fjayv9MSdHZyCU1xJ5FjrNdN6VnU1KS4CjU4Yoh/m8CsezCguFJgAMV05ueP+BfhF5OL+gL9A/f/qJ7t3TaPLMFB09eoy6mTkMGg2PjTELOsS20OcTACgMKqJugqA0NtE7ycn0202b6A+ZmYIVAAKApGZlgRHB/0lqQPAqFEVE9hntM0R0ZblTzeswWdCeU8HAtYW+Uu0AUx+0f/jwoXD+56c/073v7tHU2XMiFbrUfVTNAtfL10FIAQL2QftsBrOEnavld5kg7E7PoF+99x79ev162rJrV9RMi6a2dvKUlQsR5uAgII7/ivMsbEE4g2hggjzC7LQL1OftovoO0WJKUn0gYEAn2hmMXo4QHIXQIfLfsfOXPwuLvB86cpQqamooyEzg1BLMwv04RkoE+B3B4BBBMHEcCwIP0N+ByJdUVhpgBJ7j4WvdANDjeTUglOaWEChfJF7uJzPX2HEPaj1vg7EAbHO5QnAeIPgqKvUB7gtAdbBgcvKMqOnc/NAIVwCcq21qElFnCgvaI9cBBFKhlSPbPzBIbbzduGULpWzfLkDAdZs++sgEwSlZqoIJMg2CzFSNGzODwdBfOi26+w4YTCm9LhDQwQDzdzguFf4FALjciTws8/u1yyx2N2/dovPnL9DRY8PkZ204xtuhoSM0wI7V8DEiirQCCHD+99u2CUdx3Lmvmz7kfemoGDgPEDr4HNKAf1MlAC4wgMGLWFJXQUrklZSEX6rLE2rOyDIQGlhgBUAyYFEZkm2vAGVi4qQ+x83M0389pevXr6OToy07d4qcR+krr/KzqpeJ/IfjGO+npDx3FCKHVPjd1q2LAMBI3ryZ9vL7U56BEzLfD80ACFba876OlGCQV9dAcT0Pyw7PgWij6zPP5Xt9EYgg+n3LosdVzdfz5CI8KY1LH31+5Yro9KanZwjHmPzmHTsoOeVDemfDBuE8dGVnWpqx3unUrE4CDLCAG64XAHB88IFgQV5xMY7DFmc16A6CZvnNBYYVcW+yKj0A/VHTsQ8dwMPNc6X+Gg0VIGbVpzYGWundjRujmGQWi9Eol7+TJ0/R2Nhx2sNlM9YJRPDdDRsM5DGPJB4KHOIhngHhAwixAGAAuDZ2lsuiYnFWBQOYrdEYNochilyiV6YHoH+rRNJkAG+fUw31PzU7Z1EFKPD69CIuQ1Bm6URoh8tFmVym3nc6rZOPyi0cD8HxeHPg3x2InNrbS79JTsYzNXmPuBclsO3ZvKwAOJEGsmI5rT0M+gSf3y9K5LIA1LUEIlL1k0AhCYBH5r9TCqBqib4D+c/1PyInGOThkvuaHCYALhlpbQWBMGR/4IpzTqlpbKQyf0045vdoe0zATHagSYMeWFMkbscnHRYPZjoFJaIiUkz9EJy15j/X3qCsAIqMcFjSWrNE1Iygg0fEmrtLzEUTdT/OhBFht9fHDVCbEUt3LJxi08B8Xj6vTDESriq9lVWqBECgHujqiqAUmufb1X3cfRXoluhjZWiwkOnSUcUS6ZD8LUmmhks6b5j1ezkAkAKZBe5QvPPcNBnoCawMwT66Qxk0R2xwwRAui2iSDGuaPDcubzo3EJq8wcx/9Vmk3QryH42QBQCFF0UagIiJtjX6DskIXTLEucJSHIIIMuO0BOcjn3A3ybU/lu5RCUBc5qA0Ih0Q2EWiCPRk7VfMNhjLW1zETic1tLYZDMKyuSsdfh5l6bwho5+0il4kyA0VohlNcF5FP8DlWo/VB16HYB2hJ0pzgIe2mcXxP2IOumPRY17U0tll8KIkZNb+sppafOxYkQPSaYfchyYoL9GMqWYpTLRIq1QUcT4O3aPQgqVqPwIOIMwDhzX6mQUFIQAgo+9MzcrWrML3mj6+YIKiFCZyhL87RqVQKrEskF+P1BUvfLCAkfRwoPUtq6l5o5+lZb5SolJo6oT8avTCl+c9OTmat6pKW8mLkvBpGzlvsiGuQr4ZEEwA1EQgoR/gNtxIxKBluz+OtMJiF31jHxqXBiAqAUj4WRxpADFM0DCFlv1khvX7Wol4vF4AIldVVxdZqlrIfiCYQPHDy6bAGv7nKYRVY6JewExZVAP+ey5Rv+Ba97aaUHMW5NauLmMZFkegBb/EP14d6NoS9QLWFSzWBmuZza8CQmSpXsAqmGtVy14VALWuuYWWy+W3OteXa4jwceQX6+BKG6J1/8+2VCNkm2222WabbbbZZpttttlmm22rt38DCdA0vq3bcAkAAAAASUVORK5CYII=';
|
||||||
|
|
||||||
// Favicon
|
// Favicon
|
||||||
document.querySelector("link[rel=icon]").setAttribute("href", "data:image/png;base64," + spider16);
|
document.querySelector('link[rel=icon]').setAttribute('href', `data:image/png;base64,${spider16}`);
|
||||||
|
|
||||||
// Bake button
|
// Bake button
|
||||||
document.querySelector("#bake img").setAttribute("src", "data:image/png;base64," + spider32);
|
document.querySelector('#bake img').setAttribute('src', `data:image/png;base64,${spider32}`);
|
||||||
|
|
||||||
// About box
|
// About box
|
||||||
document.querySelector(".about-img-left").setAttribute("src", "data:image/png;base64," + spider64);
|
document.querySelector('.about-img-left').setAttribute('src', `data:image/png;base64,${spider64}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -67,28 +67,28 @@ SeasonalWaiter.prototype.insert_spider_icons = function() {
|
||||||
* Replaces all instances of the word "cyber" with "spider".
|
* Replaces all instances of the word "cyber" with "spider".
|
||||||
* #spiderchef
|
* #spiderchef
|
||||||
*/
|
*/
|
||||||
SeasonalWaiter.prototype.insert_spider_text = function() {
|
SeasonalWaiter.prototype.insert_spider_text = function () {
|
||||||
// Title
|
// Title
|
||||||
document.title = document.title.replace(/Cyber/g, "Spider");
|
document.title = document.title.replace(/Cyber/g, 'Spider');
|
||||||
|
|
||||||
// Body
|
// Body
|
||||||
SeasonalWaiter.tree_walk(document.body, function(node) {
|
SeasonalWaiter.tree_walk(document.body, (node) => {
|
||||||
// process only text nodes
|
// process only text nodes
|
||||||
if (node.nodeType == 3) {
|
if (node.nodeType == 3) {
|
||||||
node.nodeValue = node.nodeValue.replace(/Cyber/g, "Spider");
|
node.nodeValue = node.nodeValue.replace(/Cyber/g, 'Spider');
|
||||||
}
|
}
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
// Bake button
|
// Bake button
|
||||||
SeasonalWaiter.tree_walk(document.getElementById("bake-group"), function(node) {
|
SeasonalWaiter.tree_walk(document.getElementById('bake-group'), (node) => {
|
||||||
// process only text nodes
|
// process only text nodes
|
||||||
if (node.nodeType == 3) {
|
if (node.nodeType == 3) {
|
||||||
node.nodeValue = node.nodeValue.replace(/Bake/g, "Spin");
|
node.nodeValue = node.nodeValue.replace(/Bake/g, 'Spin');
|
||||||
}
|
}
|
||||||
}, true);
|
}, true);
|
||||||
|
|
||||||
// Recipe title
|
// Recipe title
|
||||||
document.querySelector("#recipe .title").innerHTML = "Web";
|
document.querySelector('#recipe .title').innerHTML = 'Web';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -96,17 +96,17 @@ SeasonalWaiter.prototype.insert_spider_text = function() {
|
||||||
* Adds an option to make it snow.
|
* Adds an option to make it snow.
|
||||||
* #letitsnow
|
* #letitsnow
|
||||||
*/
|
*/
|
||||||
SeasonalWaiter.prototype.create_snow_option = function() {
|
SeasonalWaiter.prototype.create_snow_option = function () {
|
||||||
var options_body = document.getElementById("options-body"),
|
let options_body = document.getElementById('options-body'),
|
||||||
option_item = document.createElement("div");
|
option_item = document.createElement('div');
|
||||||
|
|
||||||
option_item.className = "option-item";
|
option_item.className = 'option-item';
|
||||||
option_item.innerHTML =
|
option_item.innerHTML =
|
||||||
"<input type='checkbox' option='snow' checked />\
|
"<input type='checkbox' option='snow' checked />\
|
||||||
Let it snow";
|
Let it snow";
|
||||||
options_body.appendChild(option_item);
|
options_body.appendChild(option_item);
|
||||||
|
|
||||||
this.manager.options.load();
|
this.manager.options.load();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -114,73 +114,73 @@ SeasonalWaiter.prototype.create_snow_option = function() {
|
||||||
* Initialises a snowstorm.
|
* Initialises a snowstorm.
|
||||||
* #letitsnow
|
* #letitsnow
|
||||||
*/
|
*/
|
||||||
SeasonalWaiter.prototype.let_it_snow = function() {
|
SeasonalWaiter.prototype.let_it_snow = function () {
|
||||||
$(document).snowfall("clear");
|
$(document).snowfall('clear');
|
||||||
if (!this.app.options.snow) return;
|
if (!this.app.options.snow) return;
|
||||||
|
|
||||||
var options = {},
|
let options = {},
|
||||||
firefox_version = navigator.userAgent.match(/Firefox\/(\d\d?)/);
|
firefox_version = navigator.userAgent.match(/Firefox\/(\d\d?)/);
|
||||||
|
|
||||||
if (firefox_version && parseInt(firefox_version[1], 10) < 30) {
|
if (firefox_version && parseInt(firefox_version[1], 10) < 30) {
|
||||||
// Firefox < 30
|
// Firefox < 30
|
||||||
options = {
|
options = {
|
||||||
flakeCount : 10,
|
flakeCount: 10,
|
||||||
flakeColor : '#fff',
|
flakeColor: '#fff',
|
||||||
flakePosition: 'absolute',
|
flakePosition: 'absolute',
|
||||||
minSize : 1,
|
minSize: 1,
|
||||||
maxSize : 2,
|
maxSize: 2,
|
||||||
minSpeed : 1,
|
minSpeed: 1,
|
||||||
maxSpeed : 5,
|
maxSpeed: 5,
|
||||||
round : false,
|
round: false,
|
||||||
shadow : false,
|
shadow: false,
|
||||||
collection : false,
|
collection: false,
|
||||||
collectionHeight : 20,
|
collectionHeight: 20,
|
||||||
deviceorientation : true
|
deviceorientation: true,
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
// All other browsers
|
// All other browsers
|
||||||
options = {
|
options = {
|
||||||
flakeCount : 35, //35
|
flakeCount: 35, // 35
|
||||||
flakeColor : '#fff',
|
flakeColor: '#fff',
|
||||||
flakePosition: 'absolute',
|
flakePosition: 'absolute',
|
||||||
minSize : 5,
|
minSize: 5,
|
||||||
maxSize : 8,
|
maxSize: 8,
|
||||||
minSpeed : 1,
|
minSpeed: 1,
|
||||||
maxSpeed : 5,
|
maxSpeed: 5,
|
||||||
round : true,
|
round: true,
|
||||||
shadow : true,
|
shadow: true,
|
||||||
collection : ".btn",
|
collection: '.btn',
|
||||||
collectionHeight : 20,
|
collectionHeight: 20,
|
||||||
deviceorientation : true
|
deviceorientation: true,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
$(document).snowfall(options);
|
$(document).snowfall(options);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When a button is clicked, shake the snow off that button.
|
* When a button is clicked, shake the snow off that button.
|
||||||
* #letitsnow
|
* #letitsnow
|
||||||
*/
|
*/
|
||||||
SeasonalWaiter.prototype.shake_off_snow = function(e) {
|
SeasonalWaiter.prototype.shake_off_snow = function (e) {
|
||||||
var el = e.target,
|
let el = e.target,
|
||||||
rect = el.getBoundingClientRect(),
|
rect = el.getBoundingClientRect(),
|
||||||
canvases = document.querySelectorAll("canvas.snowfall-canvas"),
|
canvases = document.querySelectorAll('canvas.snowfall-canvas'),
|
||||||
canvas = null,
|
canvas = null,
|
||||||
remove_func = function() {
|
remove_func = function () {
|
||||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||||
$(this).fadeIn();
|
$(this).fadeIn();
|
||||||
};
|
};
|
||||||
|
|
||||||
for (var i = 0; i < canvases.length; i++) {
|
for (let i = 0; i < canvases.length; i++) {
|
||||||
canvas = canvases[i];
|
canvas = canvases[i];
|
||||||
if (canvas.style.left == rect.left + "px" && canvas.style.top == (rect.top - 20) + "px") {
|
if (canvas.style.left == `${rect.left}px` && canvas.style.top == `${rect.top - 20}px`) {
|
||||||
var ctx = canvas.getContext("2d");
|
var ctx = canvas.getContext('2d');
|
||||||
|
|
||||||
$(canvas).fadeOut("slow", remove_func);
|
$(canvas).fadeOut('slow', remove_func);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -189,19 +189,19 @@ SeasonalWaiter.prototype.shake_off_snow = function(e) {
|
||||||
* sequence.
|
* sequence.
|
||||||
* #konamicode
|
* #konamicode
|
||||||
*/
|
*/
|
||||||
SeasonalWaiter.prototype.konami_code_listener = function(e) {
|
SeasonalWaiter.prototype.konami_code_listener = function (e) {
|
||||||
this.kkeys.push(e.keyCode);
|
this.kkeys.push(e.keyCode);
|
||||||
var konami = [38,38,40,40,37,39,37,39,66,65];
|
const konami = [38, 38, 40, 40, 37, 39, 37, 39, 66, 65];
|
||||||
for (var i = 0; i < this.kkeys.length; i++) {
|
for (let i = 0; i < this.kkeys.length; i++) {
|
||||||
if (this.kkeys[i] != konami[i]) {
|
if (this.kkeys[i] != konami[i]) {
|
||||||
this.kkeys = [];
|
this.kkeys = [];
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
if (i == konami.length - 1) {
|
|
||||||
$("body").children().toggleClass("konami");
|
|
||||||
this.kkeys = [];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (i == konami.length - 1) {
|
||||||
|
$('body').children().toggleClass('konami');
|
||||||
|
this.kkeys = [];
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -213,42 +213,42 @@ SeasonalWaiter.prototype.konami_code_listener = function(e) {
|
||||||
* @param {Function} fn - The callback function to operate on each node
|
* @param {Function} fn - The callback function to operate on each node
|
||||||
* @param {booleam} all_nodes - Whether to operate on every node or not
|
* @param {booleam} all_nodes - Whether to operate on every node or not
|
||||||
*/
|
*/
|
||||||
SeasonalWaiter.tree_walk = (function() {
|
SeasonalWaiter.tree_walk = (function () {
|
||||||
// Create closure for constants
|
// Create closure for constants
|
||||||
var skipTags = {
|
const skipTags = {
|
||||||
"SCRIPT": true, "IFRAME": true, "OBJECT": true,
|
SCRIPT: true, IFRAME: true, OBJECT: true,
|
||||||
"EMBED": true, "STYLE": true, "LINK": true, "META": true
|
EMBED: true, STYLE: true, LINK: true, META: true,
|
||||||
};
|
};
|
||||||
|
|
||||||
return function(parent, fn, all_nodes) {
|
return function (parent, fn, all_nodes) {
|
||||||
var node = parent.firstChild;
|
let node = parent.firstChild;
|
||||||
|
|
||||||
while (node && node != parent) {
|
while (node && node != parent) {
|
||||||
if (all_nodes || node.nodeType === 1) {
|
if (all_nodes || node.nodeType === 1) {
|
||||||
if (fn(node) === false) {
|
if (fn(node) === false) {
|
||||||
return(false);
|
return (false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// If it's an element &&
|
// If it's an element &&
|
||||||
// has children &&
|
// has children &&
|
||||||
// has a tagname && is not in the skipTags list
|
// has a tagname && is not in the skipTags list
|
||||||
// then, we can enumerate children
|
// then, we can enumerate children
|
||||||
if (node.nodeType === 1 &&
|
if (node.nodeType === 1 &&
|
||||||
node.firstChild &&
|
node.firstChild &&
|
||||||
!(node.tagName && skipTags[node.tagName])) {
|
!(node.tagName && skipTags[node.tagName])) {
|
||||||
node = node.firstChild;
|
node = node.firstChild;
|
||||||
} else if (node.nextSibling) {
|
} else if (node.nextSibling) {
|
||||||
node = node.nextSibling;
|
node = node.nextSibling;
|
||||||
} else {
|
} else {
|
||||||
// No child and no nextsibling
|
// No child and no nextsibling
|
||||||
// Find parent that has a nextSibling
|
// Find parent that has a nextSibling
|
||||||
while ((node = node.parentNode) != parent) {
|
while ((node = node.parentNode) != parent) {
|
||||||
if (node.nextSibling) {
|
if (node.nextSibling) {
|
||||||
node = node.nextSibling;
|
node = node.nextSibling;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
})();
|
}
|
||||||
|
};
|
||||||
|
}());
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {HTMLApp} app - The main view object for CyberChef.
|
* @param {HTMLApp} app - The main view object for CyberChef.
|
||||||
*/
|
*/
|
||||||
var WindowWaiter = function(app) {
|
const WindowWaiter = function (app) {
|
||||||
this.app = app;
|
this.app = app;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,9 +18,9 @@ var WindowWaiter = function(app) {
|
||||||
* Resets the layout of CyberChef's panes after 200ms (so that continuous resizing doesn't cause
|
* Resets the layout of CyberChef's panes after 200ms (so that continuous resizing doesn't cause
|
||||||
* continuous resetting).
|
* continuous resetting).
|
||||||
*/
|
*/
|
||||||
WindowWaiter.prototype.window_resize = function() {
|
WindowWaiter.prototype.window_resize = function () {
|
||||||
clearTimeout(this.reset_layout_timeout);
|
clearTimeout(this.reset_layout_timeout);
|
||||||
this.reset_layout_timeout = setTimeout(this.app.reset_layout.bind(this.app), 200);
|
this.reset_layout_timeout = setTimeout(this.app.reset_layout.bind(this.app), 200);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@ WindowWaiter.prototype.window_resize = function() {
|
||||||
* Saves the current time so that we can calculate how long the window was unfocussed for when
|
* Saves the current time so that we can calculate how long the window was unfocussed for when
|
||||||
* focus is returned.
|
* focus is returned.
|
||||||
*/
|
*/
|
||||||
WindowWaiter.prototype.window_blur = function() {
|
WindowWaiter.prototype.window_blur = function () {
|
||||||
this.window_blur_time = new Date().getTime();
|
this.window_blur_time = new Date().getTime();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -44,9 +44,9 @@ WindowWaiter.prototype.window_blur = function() {
|
||||||
* This will stop baking taking a long time when the CyberChef browser tab has been unfocused for
|
* This will stop baking taking a long time when the CyberChef browser tab has been unfocused for
|
||||||
* a long time and the browser has swapped out all its memory.
|
* a long time and the browser has swapped out all its memory.
|
||||||
*/
|
*/
|
||||||
WindowWaiter.prototype.window_focus = function() {
|
WindowWaiter.prototype.window_focus = function () {
|
||||||
var unfocused_time = new Date().getTime() - this.window_blur_time;
|
const unfocused_time = new Date().getTime() - this.window_blur_time;
|
||||||
if (unfocused_time > 60000) {
|
if (unfocused_time > 60000) {
|
||||||
this.app.silent_bake();
|
this.app.silent_bake();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,41 +9,41 @@
|
||||||
/**
|
/**
|
||||||
* Main function used to build the CyberChef web app.
|
* Main function used to build the CyberChef web app.
|
||||||
*/
|
*/
|
||||||
var main = function() {
|
const main = function () {
|
||||||
var default_favourites = [
|
const default_favourites = [
|
||||||
"To Base64",
|
'To Base64',
|
||||||
"From Base64",
|
'From Base64',
|
||||||
"To Hex",
|
'To Hex',
|
||||||
"From Hex",
|
'From Hex',
|
||||||
"To Hexdump",
|
'To Hexdump',
|
||||||
"From Hexdump",
|
'From Hexdump',
|
||||||
"URL Decode",
|
'URL Decode',
|
||||||
"Regular expression",
|
'Regular expression',
|
||||||
"Entropy",
|
'Entropy',
|
||||||
"Fork"
|
'Fork',
|
||||||
];
|
];
|
||||||
|
|
||||||
var default_options = {
|
const default_options = {
|
||||||
update_url : true,
|
update_url: true,
|
||||||
show_highlighter : true,
|
show_highlighter: true,
|
||||||
treat_as_utf8 : true,
|
treat_as_utf8: true,
|
||||||
word_wrap : true,
|
word_wrap: true,
|
||||||
show_errors : true,
|
show_errors: true,
|
||||||
error_timeout : 4000,
|
error_timeout: 4000,
|
||||||
auto_bake_threshold : 200,
|
auto_bake_threshold: 200,
|
||||||
attempt_highlight : true,
|
attempt_highlight: true,
|
||||||
snow : false,
|
snow: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
document.removeEventListener("DOMContentLoaded", main, false);
|
document.removeEventListener('DOMContentLoaded', main, false);
|
||||||
window.app = new HTMLApp(Categories, OperationConfig, default_favourites, default_options);
|
window.app = new HTMLApp(Categories, OperationConfig, default_favourites, default_options);
|
||||||
window.app.setup();
|
window.app.setup();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Fix issues with browsers that don't support console.log()
|
// Fix issues with browsers that don't support console.log()
|
||||||
window.console = console || {log: function() {}, error: function() {}};
|
window.console = console || { log() {}, error() {} };
|
||||||
|
|
||||||
window.compile_time = moment.tz("<%= grunt.template.today() %>", "ddd MMM D YYYY HH:mm:ss", "UTC").valueOf();
|
window.compile_time = moment.tz('<%= grunt.template.today() %>', 'ddd MMM D YYYY HH:mm:ss', 'UTC').valueOf();
|
||||||
window.compile_message = "<%= compile_msg %>";
|
window.compile_message = '<%= compile_msg %>';
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", main, false);
|
document.addEventListener('DOMContentLoaded', main, false);
|
||||||
|
|
|
@ -76,7 +76,7 @@ export default {
|
||||||
[
|
[
|
||||||
'env', {
|
'env', {
|
||||||
modules: false,
|
modules: false,
|
||||||
targets: { chrome: 55, firefox: 50}
|
targets: { chrome: 55, firefox: 50 },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
|
@ -105,7 +105,7 @@ export default {
|
||||||
test: /\.svg(\?[^/]*)?$/,
|
test: /\.svg(\?[^/]*)?$/,
|
||||||
loader: fontLoader,
|
loader: fontLoader,
|
||||||
},
|
},
|
||||||
].concat(cssConfig.loaders)
|
].concat(cssConfig.loaders),
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
cssConfig.plugin,
|
cssConfig.plugin,
|
||||||
|
@ -113,6 +113,6 @@ export default {
|
||||||
template: './src/html/index.html',
|
template: './src/html/index.html',
|
||||||
filename: 'index.html',
|
filename: 'index.html',
|
||||||
compileTime: new Date().toISOString(),
|
compileTime: new Date().toISOString(),
|
||||||
})
|
}),
|
||||||
]
|
],
|
||||||
}
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue