Variable names changed from underscore to CamelCase. Eslint rules updated. #64

This commit is contained in:
n1474335 2017-01-31 18:24:56 +00:00
parent f8193797fa
commit e3c977934b
66 changed files with 3176 additions and 3172 deletions

View file

@ -22,7 +22,7 @@ var Base = {
* @param {Object[]} args
* @returns {string}
*/
run_to: function(input, args) {
runTo: function(input, args) {
if (!input) {
throw ("Error: Input must be a number");
}
@ -41,7 +41,7 @@ var Base = {
* @param {Object[]} args
* @returns {number}
*/
run_from: function(input, args) {
runFrom: function(input, args) {
var radix = args[0] || Base.DEFAULT_RADIX;
if (radix < 2 || radix > 36) {
throw "Error: Radix argument must be between 2 and 36";

View file

@ -36,13 +36,13 @@ var Base64 = {
/**
* To Base64 operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run_to: function(input, args) {
runTo: function(input, args) {
var alphabet = args[0] || Base64.ALPHABET;
return Utils.to_base64(input, alphabet);
return Utils.toBase64(input, alphabet);
},
@ -57,13 +57,13 @@ var Base64 = {
*
* @param {string} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_from: function(input, args) {
runFrom: function(input, args) {
var alphabet = args[0] || Base64.ALPHABET,
remove_non_alph_chars = args[1];
removeNonAlphChars = args[1];
return Utils.from_base64(input, alphabet, "byte_array", remove_non_alph_chars);
return Utils.fromBase64(input, alphabet, "byteArray", removeNonAlphChars);
},
@ -76,15 +76,15 @@ var Base64 = {
/**
* To Base32 operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run_to_32: function(input, args) {
runTo32: function(input, args) {
if (!input) return "";
var alphabet = args[0] ?
Utils.expand_alph_range(args[0]).join("") : "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
Utils.expandAlphRange(args[0]).join("") : "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
output = "",
chr1, chr2, chr3, chr4, chr5,
enc1, enc2, enc3, enc4, enc5, enc6, enc7, enc8,
@ -130,21 +130,21 @@ var Base64 = {
*
* @param {string} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_from_32: function(input, args) {
runFrom32: function(input, args) {
if (!input) return [];
var alphabet = args[0] ?
Utils.expand_alph_range(args[0]).join("") : "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
remove_non_alph_chars = args[0];
Utils.expandAlphRange(args[0]).join("") : "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",
removeNonAlphChars = args[0];
var output = [],
chr1, chr2, chr3, chr4, chr5,
enc1, enc2, enc3, enc4, enc5, enc6, enc7, enc8,
i = 0;
if (remove_non_alph_chars) {
if (removeNonAlphChars) {
var re = new RegExp("[^" + alphabet.replace(/[\]\\\-^]/g, "\\$&") + "]", "g");
input = input.replace(re, "");
}
@ -190,21 +190,21 @@ var Base64 = {
/**
* Show Base64 offsets operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {html}
*/
run_offsets: function(input, args) {
runOffsets: function(input, args) {
var alphabet = args[0] || Base64.ALPHABET,
show_variable = args[1],
offset0 = Utils.to_base64(input, alphabet),
offset1 = Utils.to_base64([0].concat(input), alphabet),
offset2 = Utils.to_base64([0, 0].concat(input), alphabet),
showVariable = args[1],
offset0 = Utils.toBase64(input, alphabet),
offset1 = Utils.toBase64([0].concat(input), alphabet),
offset2 = Utils.toBase64([0, 0].concat(input), alphabet),
len0 = offset0.indexOf("="),
len1 = offset1.indexOf("="),
len2 = offset2.indexOf("="),
script = "<script type='application/javascript'>$('[data-toggle=\"tooltip\"]').tooltip()</script>",
static_section = "",
staticSection = "",
padding = "";
if (input.length < 1) {
@ -213,28 +213,28 @@ var Base64 = {
// Highlight offset 0
if (len0 % 4 === 2) {
static_section = offset0.slice(0, -3);
staticSection = offset0.slice(0, -3);
offset0 = "<span data-toggle='tooltip' data-placement='top' title='" +
Utils.escape_html(Utils.from_base64(static_section, alphabet).slice(0, -2)) + "'>" +
static_section + "</span>" +
Utils.escapeHtml(Utils.fromBase64(staticSection, alphabet).slice(0, -2)) + "'>" +
staticSection + "</span>" +
"<span class='hlgreen'>" + offset0.substr(offset0.length - 3, 1) + "</span>" +
"<span class='hlred'>" + offset0.substr(offset0.length - 2) + "</span>";
} else if (len0 % 4 === 3) {
static_section = offset0.slice(0, -2);
staticSection = offset0.slice(0, -2);
offset0 = "<span data-toggle='tooltip' data-placement='top' title='" +
Utils.escape_html(Utils.from_base64(static_section, alphabet).slice(0, -1)) + "'>" +
static_section + "</span>" +
Utils.escapeHtml(Utils.fromBase64(staticSection, alphabet).slice(0, -1)) + "'>" +
staticSection + "</span>" +
"<span class='hlgreen'>" + offset0.substr(offset0.length - 2, 1) + "</span>" +
"<span class='hlred'>" + offset0.substr(offset0.length - 1) + "</span>";
} else {
static_section = offset0;
staticSection = offset0;
offset0 = "<span data-toggle='tooltip' data-placement='top' title='" +
Utils.escape_html(Utils.from_base64(static_section, alphabet)) + "'>" +
static_section + "</span>";
Utils.escapeHtml(Utils.fromBase64(staticSection, alphabet)) + "'>" +
staticSection + "</span>";
}
if (!show_variable) {
offset0 = static_section;
if (!showVariable) {
offset0 = staticSection;
}
@ -243,28 +243,28 @@ var Base64 = {
"<span class='hlgreen'>" + offset1.substr(1, 1) + "</span>";
offset1 = offset1.substr(2);
if (len1 % 4 === 2) {
static_section = offset1.slice(0, -3);
staticSection = offset1.slice(0, -3);
offset1 = padding + "<span data-toggle='tooltip' data-placement='top' title='" +
Utils.escape_html(Utils.from_base64("AA" + static_section, alphabet).slice(1, -2)) + "'>" +
static_section + "</span>" +
Utils.escapeHtml(Utils.fromBase64("AA" + staticSection, alphabet).slice(1, -2)) + "'>" +
staticSection + "</span>" +
"<span class='hlgreen'>" + offset1.substr(offset1.length - 3, 1) + "</span>" +
"<span class='hlred'>" + offset1.substr(offset1.length - 2) + "</span>";
} else if (len1 % 4 === 3) {
static_section = offset1.slice(0, -2);
staticSection = offset1.slice(0, -2);
offset1 = padding + "<span data-toggle='tooltip' data-placement='top' title='" +
Utils.escape_html(Utils.from_base64("AA" + static_section, alphabet).slice(1, -1)) + "'>" +
static_section + "</span>" +
Utils.escapeHtml(Utils.fromBase64("AA" + staticSection, alphabet).slice(1, -1)) + "'>" +
staticSection + "</span>" +
"<span class='hlgreen'>" + offset1.substr(offset1.length - 2, 1) + "</span>" +
"<span class='hlred'>" + offset1.substr(offset1.length - 1) + "</span>";
} else {
static_section = offset1;
staticSection = offset1;
offset1 = padding + "<span data-toggle='tooltip' data-placement='top' title='" +
Utils.escape_html(Utils.from_base64("AA" + static_section, alphabet).slice(1)) + "'>" +
static_section + "</span>";
Utils.escapeHtml(Utils.fromBase64("AA" + staticSection, alphabet).slice(1)) + "'>" +
staticSection + "</span>";
}
if (!show_variable) {
offset1 = static_section;
if (!showVariable) {
offset1 = staticSection;
}
// Highlight offset 2
@ -272,31 +272,31 @@ var Base64 = {
"<span class='hlgreen'>" + offset2.substr(2, 1) + "</span>";
offset2 = offset2.substr(3);
if (len2 % 4 === 2) {
static_section = offset2.slice(0, -3);
staticSection = offset2.slice(0, -3);
offset2 = padding + "<span data-toggle='tooltip' data-placement='top' title='" +
Utils.escape_html(Utils.from_base64("AAA" + static_section, alphabet).slice(2, -2)) + "'>" +
static_section + "</span>" +
Utils.escapeHtml(Utils.fromBase64("AAA" + staticSection, alphabet).slice(2, -2)) + "'>" +
staticSection + "</span>" +
"<span class='hlgreen'>" + offset2.substr(offset2.length - 3, 1) + "</span>" +
"<span class='hlred'>" + offset2.substr(offset2.length - 2) + "</span>";
} else if (len2 % 4 === 3) {
static_section = offset2.slice(0, -2);
staticSection = offset2.slice(0, -2);
offset2 = padding + "<span data-toggle='tooltip' data-placement='top' title='" +
Utils.escape_html(Utils.from_base64("AAA" + static_section, alphabet).slice(2, -2)) + "'>" +
static_section + "</span>" +
Utils.escapeHtml(Utils.fromBase64("AAA" + staticSection, alphabet).slice(2, -2)) + "'>" +
staticSection + "</span>" +
"<span class='hlgreen'>" + offset2.substr(offset2.length - 2, 1) + "</span>" +
"<span class='hlred'>" + offset2.substr(offset2.length - 1) + "</span>";
} else {
static_section = offset2;
staticSection = offset2;
offset2 = padding + "<span data-toggle='tooltip' data-placement='top' title='" +
Utils.escape_html(Utils.from_base64("AAA" + static_section, alphabet).slice(2)) + "'>" +
static_section + "</span>";
Utils.escapeHtml(Utils.fromBase64("AAA" + staticSection, alphabet).slice(2)) + "'>" +
staticSection + "</span>";
}
if (!show_variable) {
offset2 = static_section;
if (!showVariable) {
offset2 = staticSection;
}
return (show_variable ? "Characters highlighted in <span class='hlgreen'>green</span> could change if the input is surrounded by more data." +
return (showVariable ? "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." +
"\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" +
@ -317,7 +317,7 @@ var Base64 = {
* @param {Object[]} args
* @returns {Object[]} pos
*/
highlight_to: function(pos, args) {
highlightTo: function(pos, args) {
pos[0].start = Math.floor(pos[0].start / 3 * 4);
pos[0].end = Math.ceil(pos[0].end / 3 * 4);
return pos;
@ -332,7 +332,7 @@ var Base64 = {
* @param {Object[]} args
* @returns {Object[]} pos
*/
highlight_from: function(pos, args) {
highlightFrom: function(pos, args) {
pos[0].start = Math.ceil(pos[0].start / 4 * 3);
pos[0].end = Math.floor(pos[0].end / 4 * 3);
return pos;

View file

@ -15,14 +15,14 @@ var BitwiseOp = {
* Runs bitwise operations across the input data.
*
* @private
* @param {byte_array} input
* @param {byte_array} key
* @param {byteArray} input
* @param {byteArray} key
* @param {function} func - The bitwise calculation to carry out
* @param {boolean} null_preserving
* @param {boolean} nullPreserving
* @param {string} scheme
* @returns {byte_array}
* @returns {byteArray}
*/
_bit_op: function (input, key, func, null_preserving, scheme) {
_bitOp: function (input, key, func, nullPreserving, scheme) {
if (!key || !key.length) key = [0];
var result = [],
x = null,
@ -32,9 +32,9 @@ var BitwiseOp = {
for (var i = 0; i < input.length; i++) {
k = key[i % key.length];
o = input[i];
x = null_preserving && (o === 0 || o === k) ? o : func(o, k);
x = nullPreserving && (o === 0 || o === k) ? o : func(o, k);
result.push(x);
if (scheme !== "Standard" && !(null_preserving && (o === 0 || o === k))) {
if (scheme !== "Standard" && !(nullPreserving && (o === 0 || o === k))) {
switch (scheme) {
case "Input differential":
key[i % key.length] = x;
@ -69,18 +69,18 @@ var BitwiseOp = {
/**
* XOR operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_xor: function (input, args) {
runXor: function (input, args) {
var key = Utils.format[args[0].option].parse(args[0].string || ""),
scheme = args[1],
null_preserving = args[2];
nullPreserving = args[2];
key = Utils.word_array_to_byte_array(key);
key = Utils.wordArrayToByteArray(key);
return BitwiseOp._bit_op(input, key, BitwiseOp._xor, null_preserving, scheme);
return BitwiseOp._bitOp(input, key, BitwiseOp._xor, nullPreserving, scheme);
},
@ -113,42 +113,42 @@ var BitwiseOp = {
/**
* XOR Brute Force operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run_xor_brute: function (input, args) {
var key_length = parseInt(args[0], 10),
sample_length = args[1],
sample_offset = args[2],
null_preserving = args[3],
runXorBrute: function (input, args) {
var keyLength = parseInt(args[0], 10),
sampleLength = args[1],
sampleOffset = args[2],
nullPreserving = args[3],
differential = args[4],
crib = args[5],
print_key = args[6],
output_hex = args[7],
printKey = args[6],
outputHex = args[7],
regex;
var output = "",
result,
result_utf8;
resultUtf8;
input = input.slice(sample_offset, sample_offset + sample_length);
input = input.slice(sampleOffset, sampleOffset + sampleLength);
if (crib !== "") {
regex = new RegExp(crib, "im");
}
for (var 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_utf8 = Utils.byte_array_to_utf8(result);
if (crib !== "" && result_utf8.search(regex) === -1) continue;
if (print_key) output += "Key = " + Utils.hex(key, (2*key_length)) + ": ";
if (output_hex)
output += Utils.byte_array_to_hex(result) + "\n";
for (var key = 1, l = Math.pow(256, keyLength); key < l; key++) {
result = BitwiseOp._bitOp(input, Utils.hexToByteArray(key.toString(16)), BitwiseOp._xor, nullPreserving, differential);
resultUtf8 = Utils.byteArrayToUtf8(result);
if (crib !== "" && resultUtf8.search(regex) === -1) continue;
if (printKey) output += "Key = " + Utils.hex(key, (2*keyLength)) + ": ";
if (outputHex)
output += Utils.byteArrayToHex(result) + "\n";
else
output += Utils.printable(result_utf8, false) + "\n";
if (print_key) output += "\n";
output += Utils.printable(resultUtf8, false) + "\n";
if (printKey) output += "\n";
}
return output;
},
@ -157,72 +157,72 @@ var BitwiseOp = {
/**
* NOT operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_not: function (input, args) {
return BitwiseOp._bit_op(input, null, BitwiseOp._not);
runNot: function (input, args) {
return BitwiseOp._bitOp(input, null, BitwiseOp._not);
},
/**
* AND operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_and: function (input, args) {
runAnd: function (input, args) {
var key = Utils.format[args[0].option].parse(args[0].string || "");
key = Utils.word_array_to_byte_array(key);
key = Utils.wordArrayToByteArray(key);
return BitwiseOp._bit_op(input, key, BitwiseOp._and);
return BitwiseOp._bitOp(input, key, BitwiseOp._and);
},
/**
* OR operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_or: function (input, args) {
runOr: function (input, args) {
var key = Utils.format[args[0].option].parse(args[0].string || "");
key = Utils.word_array_to_byte_array(key);
key = Utils.wordArrayToByteArray(key);
return BitwiseOp._bit_op(input, key, BitwiseOp._or);
return BitwiseOp._bitOp(input, key, BitwiseOp._or);
},
/**
* ADD operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_add: function (input, args) {
runAdd: function (input, args) {
var key = Utils.format[args[0].option].parse(args[0].string || "");
key = Utils.word_array_to_byte_array(key);
key = Utils.wordArrayToByteArray(key);
return BitwiseOp._bit_op(input, key, BitwiseOp._add);
return BitwiseOp._bitOp(input, key, BitwiseOp._add);
},
/**
* SUB operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_sub: function (input, args) {
runSub: function (input, args) {
var key = Utils.format[args[0].option].parse(args[0].string || "");
key = Utils.word_array_to_byte_array(key);
key = Utils.wordArrayToByteArray(key);
return BitwiseOp._bit_op(input, key, BitwiseOp._sub);
return BitwiseOp._bitOp(input, key, BitwiseOp._sub);
},

View file

@ -30,13 +30,13 @@ var ByteRepr = {
/**
* To Hex operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run_to_hex: function(input, args) {
var delim = Utils.char_rep[args[0] || "Space"];
return Utils.to_hex(input, delim, 2);
runToHex: function(input, args) {
var delim = Utils.charRep[args[0] || "Space"];
return Utils.toHex(input, delim, 2);
},
@ -45,11 +45,11 @@ var ByteRepr = {
*
* @param {string} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_from_hex: function(input, args) {
runFromHex: function(input, args) {
var delim = args[0] || "Space";
return Utils.from_hex(input, delim, 2);
return Utils.fromHex(input, delim, 2);
},
@ -66,8 +66,8 @@ var ByteRepr = {
* @param {Object[]} args
* @returns {string}
*/
run_to_charcode: function(input, args) {
var delim = Utils.char_rep[args[0] || "Space"],
runToCharcode: function(input, args) {
var delim = Utils.charRep[args[0] || "Space"],
base = args[1],
output = "",
padding = 2,
@ -87,11 +87,11 @@ var ByteRepr = {
else if (ordinal < 4294967296) padding = 8;
else padding = 2;
if (padding > 2) app.options.attempt_highlight = false;
if (padding > 2) app.options.attemptHighlight = false;
output += Utils.hex(ordinal, padding) + delim;
} else {
app.options.attempt_highlight = false;
app.options.attemptHighlight = false;
output += ordinal.toString(base) + delim;
}
}
@ -105,10 +105,10 @@ var ByteRepr = {
*
* @param {string} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_from_charcode: function(input, args) {
var delim = Utils.char_rep[args[0] || "Space"],
runFromCharcode: function(input, args) {
var delim = Utils.charRep[args[0] || "Space"],
base = args[1],
bites = input.split(delim),
i = 0;
@ -118,7 +118,7 @@ var ByteRepr = {
}
if (base !== 16) {
app.options.attempt_highlight = false;
app.options.attemptHighlight = false;
}
// Split into groups of 2 if the whole string is concatenated and
@ -134,7 +134,7 @@ var ByteRepr = {
for (i = 0; i < bites.length; i++) {
latin1 += Utils.chr(parseInt(bites[i], base));
}
return Utils.str_to_byte_array(latin1);
return Utils.strToByteArray(latin1);
},
@ -147,8 +147,8 @@ var ByteRepr = {
* @param {Object[]} args
* @returns {Object[]} pos
*/
highlight_to: function(pos, args) {
var delim = Utils.char_rep[args[0] || "Space"],
highlightTo: function(pos, args) {
var delim = Utils.charRep[args[0] || "Space"],
len = delim === "\r\n" ? 1 : delim.length;
pos[0].start = pos[0].start * (2 + len);
@ -172,8 +172,8 @@ var ByteRepr = {
* @param {Object[]} args
* @returns {Object[]} pos
*/
highlight_from: function(pos, args) {
var delim = Utils.char_rep[args[0] || "Space"],
highlightFrom: function(pos, args) {
var delim = Utils.charRep[args[0] || "Space"],
len = delim === "\r\n" ? 1 : delim.length,
width = len + 2;
@ -194,12 +194,12 @@ var ByteRepr = {
/**
* To Decimal operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run_to_decimal: function(input, args) {
var delim = Utils.char_rep[args[0]];
runToDecimal: function(input, args) {
var delim = Utils.charRep[args[0]];
return input.join(delim);
},
@ -209,16 +209,16 @@ var ByteRepr = {
*
* @param {string} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_from_decimal: function(input, args) {
var delim = Utils.char_rep[args[0]];
var byte_str = input.split(delim), output = [];
if (byte_str[byte_str.length-1] === "")
byte_str = byte_str.slice(0, byte_str.length-1);
runFromDecimal: function(input, args) {
var delim = Utils.charRep[args[0]];
var byteStr = input.split(delim), output = [];
if (byteStr[byteStr.length-1] === "")
byteStr = byteStr.slice(0, byteStr.length-1);
for (var i = 0; i < byte_str.length; i++) {
output[i] = parseInt(byte_str[i], 10);
for (var i = 0; i < byteStr.length; i++) {
output[i] = parseInt(byteStr[i], 10);
}
return output;
},
@ -227,12 +227,12 @@ var ByteRepr = {
/**
* To Binary operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run_to_binary: function(input, args) {
var delim = Utils.char_rep[args[0] || "Space"],
runToBinary: function(input, args) {
var delim = Utils.charRep[args[0] || "Space"],
output = "",
padding = 8;
@ -253,18 +253,18 @@ var ByteRepr = {
*
* @param {string} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_from_binary: function(input, args) {
runFromBinary: function(input, args) {
if (args[0] !== "None") {
var delim_regex = Utils.regex_rep[args[0] || "Space"];
input = input.replace(delim_regex, "");
var delimRegex = Utils.regexRep[args[0] || "Space"];
input = input.replace(delimRegex, "");
}
var output = [];
var byte_len = 8;
for (var i = 0; i < input.length; i += byte_len) {
output.push(parseInt(input.substr(i, byte_len), 2));
var byteLen = 8;
for (var i = 0; i < input.length; i += byteLen) {
output.push(parseInt(input.substr(i, byteLen), 2));
}
return output;
},
@ -279,8 +279,8 @@ var ByteRepr = {
* @param {Object[]} args
* @returns {Object[]} pos
*/
highlight_to_binary: function(pos, args) {
var delim = Utils.char_rep[args[0] || "Space"];
highlightToBinary: function(pos, args) {
var delim = Utils.charRep[args[0] || "Space"];
pos[0].start = pos[0].start * (8 + delim.length);
pos[0].end = pos[0].end * (8 + delim.length) - delim.length;
return pos;
@ -296,8 +296,8 @@ var ByteRepr = {
* @param {Object[]} args
* @returns {Object[]} pos
*/
highlight_from_binary: function(pos, args) {
var delim = Utils.char_rep[args[0] || "Space"];
highlightFromBinary: function(pos, args) {
var delim = Utils.charRep[args[0] || "Space"];
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));
return pos;
@ -318,40 +318,40 @@ var ByteRepr = {
/**
* To Hex Content operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run_to_hex_content: function(input, args) {
runToHexContent: function(input, args) {
var convert = args[0];
var spaces = args[1];
if (convert === "All chars") {
var result = "|" + Utils.to_hex(input) + "|";
var result = "|" + Utils.toHex(input) + "|";
if (!spaces) result = result.replace(/ /g, "");
return result;
}
var output = "",
in_hex = false,
convert_spaces = convert === "Only special chars including spaces",
inHex = false,
convertSpaces = convert === "Only special chars including spaces",
b;
for (var i = 0; i < input.length; i++) {
b = input[i];
if ((b === 32 && convert_spaces) || (b < 48 && b !== 32) || (b > 57 && b < 65) || (b > 90 && b < 97) || b > 122) {
if (!in_hex) {
if ((b === 32 && convertSpaces) || (b < 48 && b !== 32) || (b > 57 && b < 65) || (b > 90 && b < 97) || b > 122) {
if (!inHex) {
output += "|";
in_hex = true;
inHex = true;
} else if (spaces) output += " ";
output += Utils.to_hex([b]);
output += Utils.toHex([b]);
} else {
if (in_hex) {
if (inHex) {
output += "|";
in_hex = false;
inHex = false;
}
output += Utils.chr(input[i]);
}
}
if (in_hex) output += "|";
if (inHex) output += "|";
return output;
},
@ -361,9 +361,9 @@ var ByteRepr = {
*
* @param {string} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_from_hex_content: function(input, args) {
runFromHexContent: function(input, args) {
var regex = /\|([a-f\d ]{2,})\|/gi;
var output = [], m, i = 0;
while ((m = regex.exec(input))) {
@ -372,7 +372,7 @@ var ByteRepr = {
output.push(Utils.ord(input[i++]));
// Add match
var bytes = Utils.from_hex(m[1]);
var bytes = Utils.fromHex(m[1]);
if (bytes) {
for (var a = 0; a < bytes.length;)
output.push(bytes[a++]);

View file

@ -25,21 +25,21 @@ var CharEnc = {
* @returns {string}
*/
run: function(input, args) {
var input_format = args[0],
output_format = args[1];
var inputFormat = args[0],
outputFormat = args[1];
if (input_format === "Windows-1251") {
input = Utils.win1251_to_unicode(input);
if (inputFormat === "Windows-1251") {
input = Utils.win1251ToUnicode(input);
input = CryptoJS.enc.Utf8.parse(input);
} else {
input = Utils.format[input_format].parse(input);
input = Utils.format[inputFormat].parse(input);
}
if (output_format === "Windows-1251") {
if (outputFormat === "Windows-1251") {
input = CryptoJS.enc.Utf8.stringify(input);
return Utils.unicode_to_win1251(input);
return Utils.unicodeToWin1251(input);
} else {
return Utils.format[output_format].stringify(input);
return Utils.format[outputFormat].stringify(input);
}
},

View file

@ -12,11 +12,11 @@ var Checksum = {
/**
* Fletcher-8 Checksum operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run_fletcher8: function(input, args) {
runFletcher8: function(input, args) {
var a = 0,
b = 0;
@ -32,11 +32,11 @@ var Checksum = {
/**
* Fletcher-16 Checksum operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run_fletcher16: function(input, args) {
runFletcher16: function(input, args) {
var a = 0,
b = 0;
@ -52,11 +52,11 @@ var Checksum = {
/**
* Fletcher-32 Checksum operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run_fletcher32: function(input, args) {
runFletcher32: function(input, args) {
var a = 0,
b = 0;
@ -72,11 +72,11 @@ var Checksum = {
/**
* Fletcher-64 Checksum operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run_fletcher64: function(input, args) {
runFletcher64: function(input, args) {
var a = 0,
b = 0;
@ -92,11 +92,11 @@ var Checksum = {
/**
* Adler-32 Checksum operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run_adler32: function(input, args) {
runAdler32: function(input, args) {
var MOD_ADLER = 65521,
a = 1,
b = 0;
@ -116,16 +116,16 @@ var Checksum = {
/**
* CRC-32 Checksum operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run_crc32: function(input, args) {
var crc_table = window.crc_table || (window.crc_table = Checksum._gen_crc_table()),
runCRC32: function(input, args) {
var crcTable = window.crcTable || (window.crcTable = Checksum._genCRCTable()),
crc = 0 ^ (-1);
for (var i = 0; i < input.length; i++) {
crc = (crc >>> 8) ^ crc_table[(crc ^ input[i]) & 0xff];
crc = (crc >>> 8) ^ crcTable[(crc ^ input[i]) & 0xff];
}
return Utils.hex((crc ^ (-1)) >>> 0);
@ -136,20 +136,20 @@ var Checksum = {
* TCP/IP Checksum operation.
*
* @author GCHQ Contributor [1]
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*
* @example
* // returns '3f2c'
* Checksum.run_tcp_ip([0x45,0x00,0x00,0x87,0xa3,0x1b,0x40,0x00,0x40,0x06,
* Checksum.runTcpIp([0x45,0x00,0x00,0x87,0xa3,0x1b,0x40,0x00,0x40,0x06,
* 0x00,0x00,0xac,0x11,0x00,0x04,0xac,0x11,0x00,0x03])
*
* // returns 'a249'
* Checksum.run_tcp_ip([0x45,0x00,0x01,0x11,0x3f,0x74,0x40,0x00,0x40,0x06,
* Checksum.runTcpIp([0x45,0x00,0x01,0x11,0x3f,0x74,0x40,0x00,0x40,0x06,
* 0x00,0x00,0xac,0x11,0x00,0x03,0xac,0x11,0x00,0x04])
*/
run_tcp_ip: function(input, args) {
runTCPIP: function(input, args) {
var csum = 0;
for (var i = 0; i < input.length; i++) {
@ -172,19 +172,19 @@ var Checksum = {
* @private
* @returns {array}
*/
_gen_crc_table: function() {
_genCRCTable: function() {
var c,
crc_table = [];
crcTable = [];
for (var n = 0; n < 256; n++) {
c = n;
for (var k = 0; k < 8; k++) {
c = ((c & 1) ? (0xEDB88320 ^ (c >>> 1)) : (c >>> 1));
}
crc_table[n] = c;
crcTable[n] = c;
}
return crc_table;
return crcTable;
},
};

View file

@ -53,7 +53,7 @@ var Cipher = {
*
* @private
* @param {function} algo - The CryptoJS algorithm to use
* @param {byte_array} input
* @param {byteArray} input
* @param {function} args
* @returns {string}
*/
@ -63,8 +63,8 @@ var Cipher = {
salt = Utils.format[args[2].option].parse(args[2].string || ""),
mode = CryptoJS.mode[args[3]],
padding = CryptoJS.pad[args[4]],
result_option = args[5].toLowerCase(),
output_format = args[6];
resultOption = args[5].toLowerCase(),
outputFormat = args[6];
if (iv.sigBytes === 0) {
// Use passphrase rather than key. Need to convert it to a string.
@ -79,13 +79,13 @@ var Cipher = {
});
var result = "";
if (result_option === "show all") {
result += "Key: " + encrypted.key.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]);
result += "\n\nCiphertext: " + encrypted.ciphertext.toString(Utils.format[output_format]);
if (resultOption === "show all") {
result += "Key: " + encrypted.key.toString(Utils.format[outputFormat]);
result += "\nIV: " + encrypted.iv.toString(Utils.format[outputFormat]);
if (encrypted.salt) result += "\nSalt: " + encrypted.salt.toString(Utils.format[outputFormat]);
result += "\n\nCiphertext: " + encrypted.ciphertext.toString(Utils.format[outputFormat]);
} else {
result = encrypted[result_option].toString(Utils.format[output_format]);
result = encrypted[resultOption].toString(Utils.format[outputFormat]);
}
return result;
@ -97,7 +97,7 @@ var Cipher = {
*
* @private
* @param {function} algo - The CryptoJS algorithm to use
* @param {byte_array} input
* @param {byteArray} input
* @param {function} args
* @returns {string}
*/
@ -107,15 +107,15 @@ var Cipher = {
salt = Utils.format[args[2].option].parse(args[2].string || ""),
mode = CryptoJS.mode[args[3]],
padding = CryptoJS.pad[args[4]],
input_format = args[5],
output_format = args[6];
inputFormat = args[5],
outputFormat = args[6];
// The ZeroPadding option causes a crash when the input length is 0
if (!input.length) {
return "No input";
}
var ciphertext = Utils.format[input_format].parse(input);
var ciphertext = Utils.format[inputFormat].parse(input);
if (iv.sigBytes === 0) {
// Use passphrase rather than key. Need to convert it to a string.
@ -133,7 +133,7 @@ var Cipher = {
var result;
try {
result = decrypted.toString(Utils.format[output_format]);
result = decrypted.toString(Utils.format[outputFormat]);
} catch (err) {
result = "Decrypt error: " + err.message;
}
@ -149,7 +149,7 @@ var Cipher = {
* @param {Object[]} args
* @returns {string}
*/
run_aes_enc: function (input, args) {
runAesEnc: function (input, args) {
return Cipher._enc(CryptoJS.AES, input, args);
},
@ -161,7 +161,7 @@ var Cipher = {
* @param {Object[]} args
* @returns {string}
*/
run_aes_dec: function (input, args) {
runAesDec: function (input, args) {
return Cipher._dec(CryptoJS.AES, input, args);
},
@ -173,7 +173,7 @@ var Cipher = {
* @param {Object[]} args
* @returns {string}
*/
run_des_enc: function (input, args) {
runDesEnc: function (input, args) {
return Cipher._enc(CryptoJS.DES, input, args);
},
@ -185,7 +185,7 @@ var Cipher = {
* @param {Object[]} args
* @returns {string}
*/
run_des_dec: function (input, args) {
runDesDec: function (input, args) {
return Cipher._dec(CryptoJS.DES, input, args);
},
@ -197,7 +197,7 @@ var Cipher = {
* @param {Object[]} args
* @returns {string}
*/
run_triple_des_enc: function (input, args) {
runTripleDesEnc: function (input, args) {
return Cipher._enc(CryptoJS.TripleDES, input, args);
},
@ -209,7 +209,7 @@ var Cipher = {
* @param {Object[]} args
* @returns {string}
*/
run_triple_des_dec: function (input, args) {
runTripleDesDec: function (input, args) {
return Cipher._dec(CryptoJS.TripleDES, input, args);
},
@ -221,7 +221,7 @@ var Cipher = {
* @param {Object[]} args
* @returns {string}
*/
run_rabbit_enc: function (input, args) {
runRabbitEnc: function (input, args) {
return Cipher._enc(CryptoJS.Rabbit, input, args);
},
@ -233,7 +233,7 @@ var Cipher = {
* @param {Object[]} args
* @returns {string}
*/
run_rabbit_dec: function (input, args) {
runRabbitDec: function (input, args) {
return Cipher._dec(CryptoJS.Rabbit, input, args);
},
@ -256,20 +256,20 @@ var Cipher = {
* @param {Object[]} args
* @returns {string}
*/
run_blowfish_enc: function (input, args) {
runBlowfishEnc: function (input, args) {
var key = Utils.format[args[0].option].parse(args[0].string).toString(Utils.format.Latin1),
mode = args[1],
output_format = args[2];
outputFormat = args[2];
if (key.length === 0) return "Enter a key";
var enc_hex = blowfish.encrypt(input, key, {
var encHex = blowfish.encrypt(input, key, {
outputType: 1,
cipherMode: Cipher.BLOWFISH_MODES.indexOf(mode)
}),
enc = CryptoJS.enc.Hex.parse(enc_hex);
enc = CryptoJS.enc.Hex.parse(encHex);
return enc.toString(Utils.format[output_format]);
return enc.toString(Utils.format[outputFormat]);
},
@ -280,14 +280,14 @@ var Cipher = {
* @param {Object[]} args
* @returns {string}
*/
run_blowfish_dec: function (input, args) {
runBlowfishDec: function (input, args) {
var key = Utils.format[args[0].option].parse(args[0].string).toString(Utils.format.Latin1),
mode = args[1],
input_format = args[2];
inputFormat = args[2];
if (key.length === 0) return "Enter a key";
input = Utils.format[input_format].parse(input);
input = Utils.format[inputFormat].parse(input);
return blowfish.decrypt(input.toString(CryptoJS.enc.Base64), key, {
outputType: 0, // This actually means inputType. The library is weird.
@ -314,16 +314,16 @@ var Cipher = {
* @param {Object[]} args
* @returns {string}
*/
run_pbkdf2: function (input, args) {
var key_size = args[0] / 32,
runPbkdf2: function (input, args) {
var keySize = args[0] / 32,
iterations = args[1],
salt = CryptoJS.enc.Hex.parse(args[2] || ""),
input_format = args[3],
output_format = args[4],
passphrase = Utils.format[input_format].parse(input),
key = CryptoJS.PBKDF2(passphrase, salt, { keySize: key_size, iterations: iterations });
inputFormat = args[3],
outputFormat = args[4],
passphrase = Utils.format[inputFormat].parse(input),
key = CryptoJS.PBKDF2(passphrase, salt, { keySize: keySize, iterations: iterations });
return key.toString(Utils.format[output_format]);
return key.toString(Utils.format[outputFormat]);
},
@ -334,16 +334,16 @@ var Cipher = {
* @param {Object[]} args
* @returns {string}
*/
run_evpkdf: function (input, args) {
var key_size = args[0] / 32,
runEvpkdf: function (input, args) {
var keySize = args[0] / 32,
iterations = args[1],
salt = CryptoJS.enc.Hex.parse(args[2] || ""),
input_format = args[3],
output_format = args[4],
passphrase = Utils.format[input_format].parse(input),
key = CryptoJS.EvpKDF(passphrase, salt, { keySize: key_size, iterations: iterations });
inputFormat = args[3],
outputFormat = args[4],
passphrase = Utils.format[inputFormat].parse(input),
key = CryptoJS.EvpKDF(passphrase, salt, { keySize: keySize, iterations: iterations });
return key.toString(Utils.format[output_format]);
return key.toString(Utils.format[outputFormat]);
},
@ -354,7 +354,7 @@ var Cipher = {
* @param {Object[]} args
* @returns {string}
*/
run_rc4: function (input, args) {
runRc4: function (input, args) {
var message = Utils.format[args[1]].parse(input),
passphrase = Utils.format[args[0].option].parse(args[0].string),
encrypted = CryptoJS.RC4.encrypt(message, passphrase);
@ -376,7 +376,7 @@ var Cipher = {
* @param {Object[]} args
* @returns {string}
*/
run_rc4drop: function (input, args) {
runRc4drop: function (input, args) {
var message = Utils.format[args[1]].parse(input),
passphrase = Utils.format[args[0].option].parse(args[0].string),
drop = args[3],
@ -394,13 +394,13 @@ var Cipher = {
* @param {Object[]} args
* @returns {string}
*/
run_vigenere_enc: function (input, args) {
runVigenereEnc: function (input, args) {
var alphabet = "abcdefghijklmnopqrstuvwxyz",
key = args[0].toLowerCase(),
output = "",
fail = 0,
key_index,
msg_index,
keyIndex,
msgIndex,
chr;
if (!key) return "No key entered";
@ -412,17 +412,17 @@ var Cipher = {
// for chars not in alphabet
chr = key[(i - fail) % key.length];
// Get the location in the vigenere square of the key char
key_index = alphabet.indexOf(chr);
keyIndex = alphabet.indexOf(chr);
// Get the location in the vigenere square of the message char
msg_index = alphabet.indexOf(input[i]);
msgIndex = alphabet.indexOf(input[i]);
// Get the encoded letter by finding the sum of indexes modulo 26 and finding
// the letter corresponding to that
output += alphabet[(key_index + msg_index) % 26];
output += alphabet[(keyIndex + msgIndex) % 26];
} else if (alphabet.indexOf(input[i].toLowerCase()) >= 0) {
chr = key[(i - fail) % key.length].toLowerCase();
key_index = alphabet.indexOf(chr);
msg_index = alphabet.indexOf(input[i].toLowerCase());
output += alphabet[(key_index + msg_index) % 26].toUpperCase();
keyIndex = alphabet.indexOf(chr);
msgIndex = alphabet.indexOf(input[i].toLowerCase());
output += alphabet[(keyIndex + msgIndex) % 26].toUpperCase();
} else {
output += input[i];
fail++;
@ -441,13 +441,13 @@ var Cipher = {
* @param {Object[]} args
* @returns {string}
*/
run_vigenere_dec: function (input, args) {
runVigenereDec: function (input, args) {
var alphabet = "abcdefghijklmnopqrstuvwxyz",
key = args[0].toLowerCase(),
output = "",
fail = 0,
key_index,
msg_index,
keyIndex,
msgIndex,
chr;
if (!key) return "No key entered";
@ -456,16 +456,16 @@ var Cipher = {
for (var i = 0; i < input.length; i++) {
if (alphabet.indexOf(input[i]) >= 0) {
chr = key[(i - fail) % key.length];
key_index = alphabet.indexOf(chr);
msg_index = alphabet.indexOf(input[i]);
keyIndex = alphabet.indexOf(chr);
msgIndex = alphabet.indexOf(input[i]);
// Subtract indexes from each other, add 26 just in case the value is negative,
// modulo to remove if neccessary
output += alphabet[(msg_index - key_index + alphabet.length ) % 26];
output += alphabet[(msgIndex - keyIndex + alphabet.length ) % 26];
} else if (alphabet.indexOf(input[i].toLowerCase()) >= 0) {
chr = key[(i - fail) % key.length].toLowerCase();
key_index = alphabet.indexOf(chr);
msg_index = alphabet.indexOf(input[i].toLowerCase());
output += alphabet[(msg_index + alphabet.length - key_index) % 26].toUpperCase();
keyIndex = alphabet.indexOf(chr);
msgIndex = alphabet.indexOf(input[i].toLowerCase());
output += alphabet[(msgIndex + alphabet.length - keyIndex) % 26].toUpperCase();
} else {
output += input[i];
fail++;
@ -490,18 +490,18 @@ var Cipher = {
/**
* Substitute operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_substitute: function (input, args) {
var plaintext = Utils.str_to_byte_array(Utils.expand_alph_range(args[0]).join()),
ciphertext = Utils.str_to_byte_array(Utils.expand_alph_range(args[1]).join()),
runSubstitute: function (input, args) {
var plaintext = Utils.strToByteArray(Utils.expandAlphRange(args[0]).join()),
ciphertext = Utils.strToByteArray(Utils.expandAlphRange(args[1]).join()),
output = [],
index = -1;
if (plaintext.length !== ciphertext.length) {
output = Utils.str_to_byte_array("Warning: Plaintext and Ciphertext lengths differ\n\n");
output = Utils.strToByteArray("Warning: Plaintext and Ciphertext lengths differ\n\n");
}
for (var i = 0; i < input.length; i++) {

View file

@ -29,10 +29,10 @@ var Code = {
* @param {Object[]} args
* @returns {html}
*/
run_syntax_highlight: function(input, args) {
runSyntaxHighlight: function(input, args) {
var language = args[0],
line_nums = args[1];
return "<code class='prettyprint'>" + prettyPrintOne(Utils.escape_html(input), language, line_nums) + "</code>";
lineNums = args[1];
return "<code class='prettyprint'>" + prettyPrintOne(Utils.escapeHtml(input), language, lineNums) + "</code>";
},
@ -49,9 +49,9 @@ var Code = {
* @param {Object[]} args
* @returns {string}
*/
run_xml_beautify: function(input, args) {
var indent_str = args[0];
return vkbeautify.xml(input, indent_str);
runXmlBeautify: function(input, args) {
var indentStr = args[0];
return vkbeautify.xml(input, indentStr);
},
@ -62,10 +62,10 @@ var Code = {
* @param {Object[]} args
* @returns {string}
*/
run_json_beautify: function(input, args) {
var indent_str = args[0];
runJsonBeautify: function(input, args) {
var indentStr = args[0];
if (!input) return "";
return vkbeautify.json(input, indent_str);
return vkbeautify.json(input, indentStr);
},
@ -76,9 +76,9 @@ var Code = {
* @param {Object[]} args
* @returns {string}
*/
run_css_beautify: function(input, args) {
var indent_str = args[0];
return vkbeautify.css(input, indent_str);
runCssBeautify: function(input, args) {
var indentStr = args[0];
return vkbeautify.css(input, indentStr);
},
@ -89,9 +89,9 @@ var Code = {
* @param {Object[]} args
* @returns {string}
*/
run_sql_beautify: function(input, args) {
var indent_str = args[0];
return vkbeautify.sql(input, indent_str);
runSqlBeautify: function(input, args) {
var indentStr = args[0];
return vkbeautify.sql(input, indentStr);
},
@ -108,9 +108,9 @@ var Code = {
* @param {Object[]} args
* @returns {string}
*/
run_xml_minify: function(input, args) {
var preserve_comments = args[0];
return vkbeautify.xmlmin(input, preserve_comments);
runXmlMinify: function(input, args) {
var preserveComments = args[0];
return vkbeautify.xmlmin(input, preserveComments);
},
@ -121,7 +121,7 @@ var Code = {
* @param {Object[]} args
* @returns {string}
*/
run_json_minify: function(input, args) {
runJsonMinify: function(input, args) {
if (!input) return "";
return vkbeautify.jsonmin(input);
},
@ -134,9 +134,9 @@ var Code = {
* @param {Object[]} args
* @returns {string}
*/
run_css_minify: function(input, args) {
var preserve_comments = args[0];
return vkbeautify.cssmin(input, preserve_comments);
runCssMinify: function(input, args) {
var preserveComments = args[0];
return vkbeautify.cssmin(input, preserveComments);
},
@ -147,7 +147,7 @@ var Code = {
* @param {Object[]} args
* @returns {string}
*/
run_sql_minify: function(input, args) {
runSqlMinify: function(input, args) {
return vkbeautify.sqlmin(input);
},
@ -175,48 +175,48 @@ var Code = {
* @param {Object[]} args
* @returns {string}
*/
run_generic_beautify: function(input, args) {
runGenericBeautify: function(input, args) {
var code = input,
t = 0,
preserved_tokens = [],
preservedTokens = [],
m;
// Remove strings
var sstrings = /'([^'\\]|\\.)*'/g;
while ((m = sstrings.exec(code))) {
code = preserve_token(code, m, t++);
code = preserveToken(code, m, t++);
sstrings.lastIndex = m.index;
}
var dstrings = /"([^"\\]|\\.)*"/g;
while ((m = dstrings.exec(code))) {
code = preserve_token(code, m, t++);
code = preserveToken(code, m, t++);
dstrings.lastIndex = m.index;
}
// Remove comments
var scomments = /\/\/[^\n\r]*/g;
while ((m = scomments.exec(code))) {
code = preserve_token(code, m, t++);
code = preserveToken(code, m, t++);
scomments.lastIndex = m.index;
}
var mcomments = /\/\*[\s\S]*?\*\//gm;
while ((m = mcomments.exec(code))) {
code = preserve_token(code, m, t++);
code = preserveToken(code, m, t++);
mcomments.lastIndex = m.index;
}
var hcomments = /(^|\n)#[^\n\r#]+/g;
while ((m = hcomments.exec(code))) {
code = preserve_token(code, m, t++);
code = preserveToken(code, m, t++);
hcomments.lastIndex = m.index;
}
// Remove regexes
var regexes = /\/.*?[^\\]\/[gim]{0,3}/gi;
while ((m = regexes.exec(code))) {
code = preserve_token(code, m, t++);
code = preserveToken(code, m, t++);
regexes.lastIndex = m.index;
}
@ -287,19 +287,19 @@ var Code = {
// Replace preserved tokens
var ptokens = /###preserved_token(\d+)###/g;
var ptokens = /###preservedToken(\d+)###/g;
while ((m = ptokens.exec(code))) {
var ti = parseInt(m[1], 10);
code = code.substring(0, m.index) + preserved_tokens[ti] + code.substring(m.index + m[0].length);
code = code.substring(0, m.index) + preservedTokens[ti] + code.substring(m.index + m[0].length);
ptokens.lastIndex = m.index;
}
return code;
function preserve_token(str, match, t) {
preserved_tokens[t] = match[0];
function preserveToken(str, match, t) {
preservedTokens[t] = match[0];
return str.substring(0, match.index) +
"###preserved_token" + t + "###" +
"###preservedToken" + t + "###" +
str.substring(match.index + match[0].length);
}
},
@ -325,7 +325,7 @@ var Code = {
* @param {Object[]} args
* @returns {string}
*/
run_xpath:function(input, args) {
runXpath:function(input, args) {
var query = args[0],
delimiter = args[1];
@ -344,7 +344,7 @@ var Code = {
}
var serializer = new XMLSerializer();
var node_to_string = function(node) {
var nodeToString = function(node) {
switch (node.nodeType) {
case Node.ELEMENT_NODE: return serializer.serializeToString(node);
case Node.ATTRIBUTE_NODE: return node.value;
@ -357,7 +357,7 @@ var Code = {
return Object.keys(result).map(function(key) {
return result[key];
}).slice(0, -1) // all values except last (length)
.map(node_to_string)
.map(nodeToString)
.join(delimiter);
},
@ -382,7 +382,7 @@ var Code = {
* @param {Object[]} args
* @returns {string}
*/
run_css_query: function(input, args) {
runCssQuery: function(input, args) {
var query = args[0],
delimiter = args[1];
@ -400,7 +400,7 @@ var Code = {
return "Invalid CSS Selector. Details:\n" + err.message;
}
var node_to_string = function(node) {
var nodeToString = function(node) {
switch (node.nodeType) {
case Node.ELEMENT_NODE: return node.outerHTML;
case Node.ATTRIBUTE_NODE: return node.value;
@ -415,7 +415,7 @@ var Code = {
.map(function(_, i) {
return result[i];
})
.map(node_to_string)
.map(nodeToString)
.join(delimiter);
},

View file

@ -44,11 +44,11 @@ var Compress = {
/**
* Raw Deflate operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_raw_deflate: function(input, args) {
runRawDeflate: function(input, args) {
var deflate = new Zlib.RawDeflate(input, {
compressionType: Compress.RAW_COMPRESSION_TYPE_LOOKUP[args[0]]
});
@ -81,20 +81,20 @@ var Compress = {
* @default
*/
RAW_BUFFER_TYPE_LOOKUP: {
"Adaptive" : Zlib.RawInflate.BufferType.ADAPTIVE,
"Block" : Zlib.RawInflate.BufferType.BLOCK,
"Adaptive" : Zlib.RawInflate.BufferType.ADAPTIVE,
"Block" : Zlib.RawInflate.BufferType.BLOCK,
},
/**
* Raw Inflate operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_raw_inflate: function(input, args) {
runRawInflate: function(input, args) {
// Deal with character encoding issues
input = Utils.str_to_byte_array(Utils.byte_array_to_utf8(input));
input = Utils.strToByteArray(Utils.byteArrayToUtf8(input));
var inflate = new Zlib.RawInflate(input, {
index: args[0],
bufferSize: args[1],
@ -140,11 +140,11 @@ var Compress = {
/**
* Zlib Deflate operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_zlib_deflate: function(input, args) {
runZlibDeflate: function(input, args) {
var deflate = new Zlib.Deflate(input, {
compressionType: Compress.ZLIB_COMPRESSION_TYPE_LOOKUP[args[0]]
});
@ -164,13 +164,13 @@ var Compress = {
/**
* Zlib Inflate operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_zlib_inflate: function(input, args) {
runZlibInflate: function(input, args) {
// Deal with character encoding issues
input = Utils.str_to_byte_array(Utils.byte_array_to_utf8(input));
input = Utils.strToByteArray(Utils.byteArrayToUtf8(input));
var inflate = new Zlib.Inflate(input, {
index: args[0],
bufferSize: args[1],
@ -191,11 +191,11 @@ var Compress = {
/**
* Gzip operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_gzip: function(input, args) {
runGzip: function(input, args) {
var filename = args[1],
comment = args[2],
options = {
@ -224,13 +224,13 @@ var Compress = {
/**
* Gunzip operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_gunzip: function(input, args) {
runGunzip: function(input, args) {
// Deal with character encoding issues
input = Utils.str_to_byte_array(Utils.byte_array_to_utf8(input));
input = Utils.strToByteArray(Utils.byteArrayToUtf8(input));
var gunzip = new Zlib.Gunzip(input);
return Array.prototype.slice.call(gunzip.decompress());
},
@ -262,15 +262,15 @@ var Compress = {
/**
* Zip operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_pkzip: function(input, args) {
var password = Utils.str_to_byte_array(args[2]),
runPkzip: function(input, args) {
var password = Utils.strToByteArray(args[2]),
options = {
filename: Utils.str_to_byte_array(args[0]),
comment: Utils.str_to_byte_array(args[1]),
filename: Utils.strToByteArray(args[0]),
comment: Utils.strToByteArray(args[1]),
compressionMethod: Compress.ZIP_COMPRESSION_METHOD_LOOKUP[args[3]],
os: Compress.ZIP_OS_LOOKUP[args[4]],
deflateOption: {
@ -295,13 +295,13 @@ var Compress = {
/**
* Unzip operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run_pkunzip: function(input, args) {
runPkunzip: function(input, args) {
var options = {
password: Utils.str_to_byte_array(args[0]),
password: Utils.strToByteArray(args[0]),
verify: args[1]
},
file = "",
@ -313,7 +313,7 @@ var Compress = {
window.uzip = unzip;
for (var i = 0; i < filenames.length; i++) {
file = Utils.byte_array_to_utf8(unzip.decompress(filenames[i]));
file = Utils.byteArrayToUtf8(unzip.decompress(filenames[i]));
output += "<div class='panel panel-default'>" +
"<div class='panel-heading' role='tab' id='heading" + i + "'>" +
"<h4 class='panel-title'>" +
@ -322,7 +322,7 @@ var Compress = {
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 class='panel-body'>" +
Utils.escape_html(file) + "</div></div></div>";
Utils.escapeHtml(file) + "</div></div></div>";
}
return output + "</div>";
@ -332,17 +332,17 @@ var Compress = {
/**
* Bzip2 Decompress operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run_bzip2_decompress: function(input, args) {
runBzip2Decompress: function(input, args) {
var compressed = new Uint8Array(input),
bzip2_reader,
bzip2Reader,
plain = "";
bzip2_reader = bzip2.array(compressed);
plain = bzip2.simple(bzip2_reader);
bzip2Reader = bzip2.array(compressed);
plain = bzip2.simple(bzip2Reader);
return plain;
},

View file

@ -64,12 +64,12 @@ var Convert = {
* @param {Object[]} args
* @returns {number}
*/
run_distance: function (input, args) {
var input_units = args[0],
output_units = args[1];
runDistance: function (input, args) {
var inputUnits = args[0],
outputUnits = args[1];
input = input * Convert.DISTANCE_FACTOR[input_units];
return input / Convert.DISTANCE_FACTOR[output_units];
input = input * Convert.DISTANCE_FACTOR[inputUnits];
return input / Convert.DISTANCE_FACTOR[outputUnits];
// TODO Remove rounding errors (e.g. 1.000000000001)
},
@ -145,12 +145,12 @@ var Convert = {
* @param {Object[]} args
* @returns {number}
*/
run_data_size: function (input, args) {
var input_units = args[0],
output_units = args[1];
runDataSize: function (input, args) {
var inputUnits = args[0],
outputUnits = args[1];
input = input * Convert.DATA_FACTOR[input_units];
return input / Convert.DATA_FACTOR[output_units];
input = input * Convert.DATA_FACTOR[inputUnits];
return input / Convert.DATA_FACTOR[outputUnits];
},
@ -225,12 +225,12 @@ var Convert = {
* @param {Object[]} args
* @returns {number}
*/
run_area: function (input, args) {
var input_units = args[0],
output_units = args[1];
runArea: function (input, args) {
var inputUnits = args[0],
outputUnits = args[1];
input = input * Convert.AREA_FACTOR[input_units];
return input / Convert.AREA_FACTOR[output_units];
input = input * Convert.AREA_FACTOR[inputUnits];
return input / Convert.AREA_FACTOR[outputUnits];
},
@ -336,12 +336,12 @@ var Convert = {
* @param {Object[]} args
* @returns {number}
*/
run_mass: function (input, args) {
var input_units = args[0],
output_units = args[1];
runMass: function (input, args) {
var inputUnits = args[0],
outputUnits = args[1];
input = input * Convert.MASS_FACTOR[input_units];
return input / Convert.MASS_FACTOR[output_units];
input = input * Convert.MASS_FACTOR[inputUnits];
return input / Convert.MASS_FACTOR[outputUnits];
},
@ -401,12 +401,12 @@ var Convert = {
* @param {Object[]} args
* @returns {number}
*/
run_speed: function (input, args) {
var input_units = args[0],
output_units = args[1];
runSpeed: function (input, args) {
var inputUnits = args[0],
outputUnits = args[1];
input = input * Convert.SPEED_FACTOR[input_units];
return input / Convert.SPEED_FACTOR[output_units];
input = input * Convert.SPEED_FACTOR[inputUnits];
return input / Convert.SPEED_FACTOR[outputUnits];
},
};

View file

@ -24,7 +24,7 @@ var DateTime = {
* @param {Object[]} args
* @returns {string}
*/
run_from_unix_timestamp: function(input, args) {
runFromUnixTimestamp: function(input, args) {
var units = args[0],
d;
@ -55,7 +55,7 @@ var DateTime = {
* @param {Object[]} args
* @returns {number}
*/
run_to_unix_timestamp: function(input, args) {
runToUnixTimestamp: function(input, args) {
var units = args[0],
d = moment(input);
@ -130,21 +130,21 @@ var DateTime = {
* @param {Object[]} args
* @returns {html}
*/
run_translate_format: function(input, args) {
var input_format = args[1],
input_timezone = args[2],
output_format = args[3],
output_timezone = args[4],
runTranslateFormat: function(input, args) {
var inputFormat = args[1],
inputTimezone = args[2],
outputFormat = args[3],
outputTimezone = args[4],
date;
try {
date = moment.tz(input, input_format, input_timezone);
date = moment.tz(input, inputFormat, inputTimezone);
if (!date || date.format() === "Invalid date") throw Error;
} catch(err) {
return "Invalid format.\n\n" + DateTime.FORMAT_EXAMPLES;
}
return date.tz(output_timezone).format(output_format);
return date.tz(outputTimezone).format(outputFormat);
},
@ -155,14 +155,14 @@ var DateTime = {
* @param {Object[]} args
* @returns {html}
*/
run_parse: function(input, args) {
var input_format = args[1],
input_timezone = args[2],
runParse: function(input, args) {
var inputFormat = args[1],
inputTimezone = args[2],
date,
output = "";
try {
date = moment.tz(input, input_format, input_timezone);
date = moment.tz(input, inputFormat, inputTimezone);
if (!date || date.format() === "Invalid date") throw Error;
} catch(err) {
return "Invalid format.\n\n" + DateTime.FORMAT_EXAMPLES;

View file

@ -32,39 +32,39 @@ var Endian = {
* @param {Object[]} args
* @returns {string}
*/
run_swap_endianness: function(input, args) {
var data_format = args[0],
word_length = args[1],
pad_incomplete_words = args[2],
runSwapEndianness: function(input, args) {
var dataFormat = args[0],
wordLength = args[1],
padIncompleteWords = args[2],
data = [],
result = [],
words = [],
i = 0,
j = 0;
if (word_length <= 0) {
if (wordLength <= 0) {
return "Word length must be greater than 0";
}
// Convert input to raw data based on specified data format
switch (data_format) {
switch (dataFormat) {
case "Hex":
data = Utils.from_hex(input);
data = Utils.fromHex(input);
break;
case "Raw":
data = Utils.str_to_byte_array(input);
data = Utils.strToByteArray(input);
break;
default:
data = input;
}
// Split up into words
for (i = 0; i < data.length; i += word_length) {
var word = data.slice(i, i + word_length);
for (i = 0; i < data.length; i += wordLength) {
var word = data.slice(i, i + wordLength);
// Pad word if too short
if (pad_incomplete_words && word.length < word_length){
for (j = word.length; j < word_length; j++) {
if (padIncompleteWords && word.length < wordLength){
for (j = word.length; j < wordLength; j++) {
word.push(0);
}
}
@ -81,11 +81,11 @@ var Endian = {
}
// Convert data back to specified data format
switch (data_format) {
switch (dataFormat) {
case "Hex":
return Utils.to_hex(result);
return Utils.toHex(result);
case "Raw":
return Utils.byte_array_to_utf8(result);
return Utils.byteArrayToUtf8(result);
default:
return result;
}

View file

@ -18,14 +18,14 @@ var Entropy = {
/**
* Entropy operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {html}
*/
run_entropy: function(input, args) {
var chunk_size = args[0],
runEntropy: function(input, args) {
var chunkSize = args[0],
output = "",
entropy = Entropy._calc_entropy(input);
entropy = Entropy._calcEntropy(input);
output += "Shannon entropy: " + entropy + "\n" +
"<br><canvas id='chart-area'></canvas><br>\n" +
@ -35,14 +35,14 @@ var Entropy = {
"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>\
var canvas = document.getElementById('chart-area'),\
parent_rect = canvas.parentNode.getBoundingClientRect(),\
parentRect = canvas.parentNode.getBoundingClientRect(),\
entropy = " + entropy + ",\
height = parent_rect.height * 0.25;\
height = parentRect.height * 0.25;\
\
canvas.width = parent_rect.width * 0.95;\
canvas.width = parentRect.width * 0.95;\
canvas.height = height > 150 ? 150 : height;\
\
CanvasComponents.draw_scale_bar(canvas, entropy, 8, [\
CanvasComponents.drawScaleBar(canvas, entropy, 8, [\
{\
label: 'English text',\
min: 3.5,\
@ -55,11 +55,11 @@ var Entropy = {
]);\
</script>";
var chunk_entropy = 0;
if (chunk_size !== 0) {
for (var i = 0; i < input.length; i += chunk_size) {
chunk_entropy = Entropy._calc_entropy(input.slice(i, i+chunk_size));
output += "Bytes " + i + " to " + (i+chunk_size) + ": " + chunk_entropy + "\n";
var chunkEntropy = 0;
if (chunkSize !== 0) {
for (var i = 0; i < input.length; i += chunkSize) {
chunkEntropy = Entropy._calcEntropy(input.slice(i, i+chunkSize));
output += "Bytes " + i + " to " + (i+chunkSize) + ": " + chunkEntropy + "\n";
}
} else {
output += "Chunk size cannot be 0.";
@ -78,17 +78,17 @@ var Entropy = {
/**
* Frequency distribution operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {html}
*/
run_freq_distrib: function (input, args) {
runFreqDistrib: function (input, args) {
if (!input.length) return "No data";
var distrib = new Array(256),
percentages = new Array(256),
len = input.length,
show_zeroes = args[0];
showZeroes = args[0];
// Initialise distrib to 0
for (var i = 0; i < 256; i++) {
@ -115,19 +115,19 @@ var Entropy = {
"\n\nByte Percentage\n" +
"<script>\
var canvas = document.getElementById('chart-area'),\
parent_rect = canvas.parentNode.getBoundingClientRect(),\
parentRect = canvas.parentNode.getBoundingClientRect(),\
scores = " + JSON.stringify(percentages) + ";\
\
canvas.width = parent_rect.width * 0.95;\
canvas.height = parent_rect.height * 0.9;\
canvas.width = parentRect.width * 0.95;\
canvas.height = parentRect.height * 0.9;\
\
CanvasComponents.draw_bar_chart(canvas, scores, 'Byte', 'Frequency %', 16, 6);\
CanvasComponents.drawBarChart(canvas, scores, 'Byte', 'Frequency %', 16, 6);\
</script>";
for (i = 0; i < 256; i++) {
if (distrib[i] || show_zeroes) {
if (distrib[i] || showZeroes) {
output += " " + Utils.hex(i, 2) + " (" +
Utils.pad_right(percentages[i].toFixed(2).replace(".00", "") + "%)", 8) +
Utils.padRight(percentages[i].toFixed(2).replace(".00", "") + "%)", 8) +
Array(Math.ceil(percentages[i])+1).join("|") + "\n";
}
}
@ -140,13 +140,13 @@ var Entropy = {
* Calculates the Shannon entropy for a given chunk of data.
*
* @private
* @param {byte_array} data
* @param {byteArray} data
* @returns {number}
*/
_calc_entropy: function(data) {
_calcEntropy: function(data) {
var prob = [],
uniques = data.unique(),
str = Utils.byte_array_to_chars(data);
str = Utils.byteArrayToChars(data);
for (var i = 0; i < uniques.length; i++) {
prob.push(str.count(Utils.chr(uniques[i])) / data.length);

View file

@ -14,25 +14,25 @@ var Extract = {
*
* @private
* @param {string} input
* @param {RegExp} search_regex
* @param {RegExp} remove_regex - A regular expression defining results to remove from the
* @param {RegExp} searchRegex
* @param {RegExp} removeRegex - A regular expression defining results to remove from the
* final list
* @param {boolean} include_total - Whether or not to include the total number of results
* @param {boolean} includeTotal - Whether or not to include the total number of results
* @returns {string}
*/
_search: function(input, search_regex, remove_regex, include_total) {
_search: function(input, searchRegex, removeRegex, includeTotal) {
var output = "",
total = 0,
match;
while ((match = search_regex.exec(input))) {
if (remove_regex && remove_regex.test(match[0]))
while ((match = searchRegex.exec(input))) {
if (removeRegex && removeRegex.test(match[0]))
continue;
total++;
output += match[0] + "\n";
}
if (include_total)
if (includeTotal)
output = "Total found: " + total + "\n\n" + output;
return output;
@ -57,13 +57,13 @@ var Extract = {
* @param {Object[]} args
* @returns {string}
*/
run_strings: function(input, args) {
var min_len = args[0] || Extract.MIN_STRING_LEN,
display_total = args[1],
runStrings: function(input, args) {
var minLen = args[0] || Extract.MIN_STRING_LEN,
displayTotal = args[1],
strings = "[A-Z\\d/\\-:.,_$%'\"()<>= !\\[\\]{}@]",
regex = new RegExp(strings + "{" + min_len + ",}", "ig");
regex = new RegExp(strings + "{" + minLen + ",}", "ig");
return Extract._search(input, regex, null, display_total);
return Extract._search(input, regex, null, displayTotal);
},
@ -90,37 +90,37 @@ var Extract = {
* @param {Object[]} args
* @returns {string}
*/
run_ip: function(input, args) {
var include_ipv4 = args[0],
include_ipv6 = args[1],
remove_local = args[2],
display_total = args[3],
runIp: function(input, args) {
var includeIpv4 = args[0],
includeIpv6 = args[1],
removeLocal = args[2],
displayTotal = 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})?",
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 = "";
if (include_ipv4 && include_ipv6) {
if (includeIpv4 && includeIpv6) {
ips = ipv4 + "|" + ipv6;
} else if (include_ipv4) {
} else if (includeIpv4) {
ips = ipv4;
} else if (include_ipv6) {
} else if (includeIpv6) {
ips = ipv6;
}
if (ips) {
var regex = new RegExp(ips, "ig");
if (remove_local) {
if (removeLocal) {
var ten = "10\\..+",
oneninetwo = "192\\.168\\..+",
oneseventwo = "172\\.(?:1[6-9]|2\\d|3[01])\\..+",
onetwoseven = "127\\..+",
remove_regex = new RegExp("^(?:" + ten + "|" + oneninetwo +
removeRegex = new RegExp("^(?:" + ten + "|" + oneninetwo +
"|" + oneseventwo + "|" + onetwoseven + ")");
return Extract._search(input, regex, remove_regex, display_total);
return Extract._search(input, regex, removeRegex, displayTotal);
} else {
return Extract._search(input, regex, null, display_total);
return Extract._search(input, regex, null, displayTotal);
}
} else {
return "";
@ -135,11 +135,11 @@ var Extract = {
* @param {Object[]} args
* @returns {string}
*/
run_email: function(input, args) {
var display_total = args[0],
runEmail: function(input, args) {
var displayTotal = args[0],
regex = /\w[-.\w]*@[-\w]+(?:\.[-\w]+)*\.[A-Z]{2,4}/ig;
return Extract._search(input, regex, null, display_total);
return Extract._search(input, regex, null, displayTotal);
},
@ -150,11 +150,11 @@ var Extract = {
* @param {Object[]} args
* @returns {string}
*/
run_mac: function(input, args) {
var display_total = args[0],
runMac: function(input, args) {
var displayTotal = args[0],
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, displayTotal);
},
@ -165,8 +165,8 @@ var Extract = {
* @param {Object[]} args
* @returns {string}
*/
run_urls: function(input, args) {
var display_total = args[0],
runUrls: function(input, args) {
var displayTotal = args[0],
protocol = "[A-Z]+://",
hostname = "[-\\w]+(?:\\.\\w[-\\w]*)+",
port = ":\\d+",
@ -175,7 +175,7 @@ var Extract = {
path += "(?:[.!,?]+[^.!,?;\"'<>()\\[\\]{}\\s\\x7F-\\xFF]+)*";
var regex = new RegExp(protocol + hostname + "(?:" + port +
")?(?:" + path + ")?", "ig");
return Extract._search(input, regex, null, display_total);
return Extract._search(input, regex, null, displayTotal);
},
@ -186,14 +186,14 @@ var Extract = {
* @param {Object[]} args
* @returns {string}
*/
run_domains: function(input, args) {
var display_total = args[0],
runDomains: function(input, args) {
var displayTotal = args[0],
protocol = "https?://",
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)+",
regex = new RegExp("(?:" + protocol + ")?" + hostname + tld, "ig");
return Extract._search(input, regex, null, display_total);
return Extract._search(input, regex, null, displayTotal);
},
@ -215,29 +215,29 @@ var Extract = {
* @param {Object[]} args
* @returns {string}
*/
run_file_paths: function(input, args) {
var include_win_path = args[0],
include_unix_path = args[1],
display_total = args[2],
win_drive = "[A-Z]:\\\\",
win_name = "[A-Z\\d][A-Z\\d\\- '_\\(\\)]{0,61}",
win_ext = "[A-Z\\d]{1,6}",
win_path = win_drive + "(?:" + win_name + "\\\\?)*" + win_name +
"(?:\\." + win_ext + ")?",
unix_path = "(?:/[A-Z\\d.][A-Z\\d\\-.]{0,61})+",
file_paths = "";
runFilePaths: function(input, args) {
var includeWinPath = args[0],
includeUnixPath = args[1],
displayTotal = args[2],
winDrive = "[A-Z]:\\\\",
winName = "[A-Z\\d][A-Z\\d\\- '_\\(\\)]{0,61}",
winExt = "[A-Z\\d]{1,6}",
winPath = winDrive + "(?:" + winName + "\\\\?)*" + winName +
"(?:\\." + winExt + ")?",
unixPath = "(?:/[A-Z\\d.][A-Z\\d\\-.]{0,61})+",
filePaths = "";
if (include_win_path && include_unix_path) {
file_paths = win_path + "|" + unix_path;
} else if (include_win_path) {
file_paths = win_path;
} else if (include_unix_path) {
file_paths = unix_path;
if (includeWinPath && includeUnixPath) {
filePaths = winPath + "|" + unixPath;
} else if (includeWinPath) {
filePaths = winPath;
} else if (includeUnixPath) {
filePaths = unixPath;
}
if (file_paths) {
var regex = new RegExp(file_paths, "ig");
return Extract._search(input, regex, null, display_total);
if (filePaths) {
var regex = new RegExp(filePaths, "ig");
return Extract._search(input, regex, null, displayTotal);
} else {
return "";
}
@ -251,14 +251,14 @@ var Extract = {
* @param {Object[]} args
* @returns {string}
*/
run_dates: function(input, args) {
var display_total = args[0],
runDates: function(input, args) {
var displayTotal = args[0],
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
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");
return Extract._search(input, regex, null, display_total);
return Extract._search(input, regex, null, displayTotal);
},
@ -269,28 +269,28 @@ var Extract = {
* @param {Object[]} args
* @returns {string}
*/
run_all_idents: function(input, args) {
runAllIdents: function(input, args) {
var output = "";
output += "IP addresses\n";
output += Extract.run_ip(input, [true, true, false]);
output += Extract.runIp(input, [true, true, false]);
output += "\nEmail addresses\n";
output += Extract.run_email(input, []);
output += Extract.runEmail(input, []);
output += "\nMAC addresses\n";
output += Extract.run_mac(input, []);
output += Extract.runMac(input, []);
output += "\nURLs\n";
output += Extract.run_urls(input, []);
output += Extract.runUrls(input, []);
output += "\nDomain names\n";
output += Extract.run_domains(input, []);
output += Extract.runDomains(input, []);
output += "\nFile paths\n";
output += Extract.run_file_paths(input, [true, true]);
output += Extract.runFilePaths(input, [true, true]);
output += "\nDates\n";
output += Extract.run_dates(input, []);
output += Extract.runDates(input, []);
return output;
},

View file

@ -12,12 +12,12 @@ var FileType = {
/**
* Detect File Type operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run_detect: function(input, args) {
var type = FileType._magic_type(input);
runDetect: function(input, args) {
var type = FileType._magicType(input);
if (!type) {
return "Unknown file type. Have you tried checking the entropy of this data to determine whether it might be encrypted or compressed?";
@ -43,26 +43,26 @@ var FileType = {
/**
* Scan for Embedded Files operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run_scan_for_embedded_files: function(input, args) {
runScanForEmbeddedFiles: function(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",
type,
ignore_common = args[0],
common_exts = ["ico", "ttf", ""],
num_found = 0,
num_common_found = 0;
ignoreCommon = args[0],
commonExts = ["ico", "ttf", ""],
numFound = 0,
numCommonFound = 0;
for (var i = 0; i < input.length; i++) {
type = FileType._magic_type(input.slice(i));
type = FileType._magicType(input.slice(i));
if (type) {
if (ignore_common && common_exts.indexOf(type.ext) > -1) {
num_common_found++;
if (ignoreCommon && commonExts.indexOf(type.ext) > -1) {
numCommonFound++;
continue;
}
num_found++;
numFound++;
output += "\nOffset " + i + " (0x" + Utils.hex(i) + "):\n" +
" File extension: " + type.ext + "\n" +
" MIME type: " + type.mime + "\n";
@ -73,13 +73,13 @@ var FileType = {
}
}
if (num_found === 0) {
if (numFound === 0) {
output += "\nNo embedded files were found.";
}
if (num_common_found > 0) {
output += "\n\n" + num_common_found;
output += num_common_found === 1 ?
if (numCommonFound > 0) {
output += "\n\n" + numCommonFound;
output += numCommonFound === 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.";
@ -94,13 +94,13 @@ var FileType = {
* extension and mime type.
*
* @private
* @param {byte_array} buf
* @param {byteArray} buf
* @returns {Object} type
* @returns {string} type.ext - File extension
* @returns {string} type.mime - Mime type
* @returns {string} [type.desc] - Description
*/
_magic_type: function (buf) {
_magicType: function (buf) {
if (!(buf && buf.length > 1)) {
return null;
}

View file

@ -27,35 +27,35 @@ var HTML = {
* @param {Object[]} args
* @returns {string}
*/
run_to_entity: function(input, args) {
var convert_all = args[0],
runToEntity: function(input, args) {
var convertAll = args[0],
numeric = args[1] === "Numeric entities",
hexa = args[1] === "Hex entities";
var charcodes = Utils.str_to_charcode(input);
var charcodes = Utils.strToCharcode(input);
var output = "";
for (var i = 0; i < charcodes.length; i++) {
if (convert_all && numeric) {
if (convertAll && numeric) {
output += "&#" + charcodes[i] + ";";
} else if (convert_all && hexa) {
} else if (convertAll && hexa) {
output += "&#x" + Utils.hex(charcodes[i]) + ";";
} else if (convert_all) {
output += HTML._byte_to_entity[charcodes[i]] || "&#" + charcodes[i] + ";";
} else if (convertAll) {
output += HTML._byteToEntity[charcodes[i]] || "&#" + charcodes[i] + ";";
} else if (numeric) {
if (charcodes[i] > 255 || HTML._byte_to_entity.hasOwnProperty(charcodes[i])) {
if (charcodes[i] > 255 || HTML._byteToEntity.hasOwnProperty(charcodes[i])) {
output += "&#" + charcodes[i] + ";";
} else {
output += Utils.chr(charcodes[i]);
}
} else if (hexa) {
if (charcodes[i] > 255 || HTML._byte_to_entity.hasOwnProperty(charcodes[i])) {
if (charcodes[i] > 255 || HTML._byteToEntity.hasOwnProperty(charcodes[i])) {
output += "&#x" + Utils.hex(charcodes[i]) + ";";
} else {
output += Utils.chr(charcodes[i]);
}
} else {
output += HTML._byte_to_entity[charcodes[i]] || (
output += HTML._byteToEntity[charcodes[i]] || (
charcodes[i] > 255 ?
"&#" + charcodes[i] + ";" :
Utils.chr(charcodes[i])
@ -73,7 +73,7 @@ var HTML = {
* @param {Object[]} args
* @returns {string}
*/
run_from_entity: function(input, args) {
runFromEntity: function(input, args) {
var regex = /&(#?x?[a-zA-Z0-9]{1,8});/g,
output = "",
m,
@ -85,7 +85,7 @@ var HTML = {
output += input[i++];
// Add match
var bite = HTML._entity_to_byte[m[1]];
var bite = HTML._entityToByte[m[1]];
if (bite) {
output += Utils.chr(bite);
} else if (!bite && m[1][0] === "#" && m[1].length > 1 && /^#\d{1,5}$/.test(m[1])) {
@ -130,17 +130,17 @@ var HTML = {
* @param {Object[]} args
* @returns {string}
*/
run_strip_tags: function(input, args) {
var remove_indentation = args[0],
remove_line_breaks = args[1];
runStripTags: function(input, args) {
var removeIndentation = args[0],
removeLineBreaks = args[1];
input = Utils.strip_html_tags(input);
input = Utils.stripHtmlTags(input);
if (remove_indentation) {
if (removeIndentation) {
input = input.replace(/\n[ \f\t]+/g, "\n");
}
if (remove_line_breaks) {
if (removeLineBreaks) {
input = input.replace(/^\s*\n/, "") // first line
.replace(/(\n\s*){2,}/g, "\n"); // all others
}
@ -156,7 +156,7 @@ var HTML = {
* @param {Object[]} args
* @returns {html}
*/
run_parse_colour_code: function(input, args) {
runParseColourCode: function(input, args) {
var m = null,
r = 0, g = 0, b = 0, a = 1;
@ -177,7 +177,7 @@ var HTML = {
var h_ = parseFloat(m[1]) / 360,
s_ = parseFloat(m[2]) / 100,
l_ = parseFloat(m[3]) / 100,
rgb_ = HTML._hsl_to_rgb(h_, s_, l_);
rgb_ = HTML._hslToRgb(h_, s_, l_);
r = rgb_[0];
g = rgb_[1];
@ -195,7 +195,7 @@ var HTML = {
b = Math.round(255 * (1 - y_) * (1 - k_));
}
var hsl_ = HTML._rgb_to_hsl(r, g, b),
var hsl_ = HTML._rgbToHsl(r, g, b),
h = Math.round(hsl_[0] * 360),
s = Math.round(hsl_[1] * 100),
l = Math.round(hsl_[2] * 100),
@ -210,9 +210,9 @@ var HTML = {
k = k.toFixed(2);
var hex = "#" +
Utils.pad_left(Math.round(r).toString(16), 2) +
Utils.pad_left(Math.round(g).toString(16), 2) +
Utils.pad_left(Math.round(b).toString(16), 2),
Utils.padLeft(Math.round(r).toString(16), 2) +
Utils.padLeft(Math.round(g).toString(16), 2) +
Utils.padLeft(Math.round(b).toString(16), 2),
rgb = "rgb(" + r + ", " + g + ", " + b + ")",
rgba = "rgba(" + r + ", " + g + ", " + b + ", " + a + ")",
hsl = "hsl(" + h + ", " + s + "%, " + l + "%)",
@ -237,7 +237,7 @@ var HTML = {
var color = e.color.toRGB();\
document.getElementById('input-text').value = 'rgba(' +\
color.r + ', ' + color.g + ', ' + color.b + ', ' + color.a + ')';\
window.app.auto_bake();\
window.app.autoBake();\
});\
</script>";
},
@ -246,7 +246,7 @@ var HTML = {
/**
* Converts an HSL color value to RGB. Conversion formula
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
* adapted from http://en.wikipedia.org/wiki/HSL_colorSpace.
* Assumes h, s, and l are contained in the set [0, 1] and
* returns r, g, and b in the set [0, 255].
*
@ -258,7 +258,7 @@ var HTML = {
* @param {number} l - The lightness
* @return {Array} The RGB representation
*/
_hsl_to_rgb: function(h, s, l){
_hslToRgb: function(h, s, l){
var r, g, b;
if (s === 0){
@ -286,7 +286,7 @@ var HTML = {
/**
* Converts an RGB color value to HSL. Conversion formula
* adapted from http://en.wikipedia.org/wiki/HSL_color_space.
* adapted from http://en.wikipedia.org/wiki/HSL_colorSpace.
* Assumes r, g, and b are contained in the set [0, 255] and
* returns h, s, and l in the set [0, 1].
*
@ -298,7 +298,7 @@ var HTML = {
* @param {number} b - The blue color value
* @return {Array} The HSL representation
*/
_rgb_to_hsl: function(r, g, b) {
_rgbToHsl: function(r, g, b) {
r /= 255; g /= 255; b /= 255;
var max = Math.max(r, g, b),
min = Math.min(r, g, b),
@ -327,7 +327,7 @@ var HTML = {
* @private
* @constant
*/
_byte_to_entity: {
_byteToEntity: {
34 : "&quot;",
38 : "&amp;",
39 : "&apos;",
@ -591,7 +591,7 @@ var HTML = {
* @private
* @constant
*/
_entity_to_byte : {
_entityToByte : {
"quot" : 34,
"amp" : 38,
"apos" : 39,

View file

@ -18,11 +18,11 @@ var HTTP = {
* @param {Object[]} args
* @returns {string}
*/
run_strip_headers: function(input, args) {
var header_end = input.indexOf("\r\n\r\n") +
(header_end < 0) ? input.indexOf("\n\n") + 2 : header_end + 4;
runStripHeaders: function(input, args) {
var headerEnd = input.indexOf("\r\n\r\n") +
(headerEnd < 0) ? input.indexOf("\n\n") + 2 : headerEnd + 4;
return (header_end < 2) ? input : input.slice(header_end, input.length);
return (headerEnd < 2) ? input : input.slice(headerEnd, input.length);
},
@ -33,8 +33,8 @@ var HTTP = {
* @param {Object[]} args
* @returns {string}
*/
run_parse_user_agent: function(input, args) {
var ua = UAS_parser.parse(input);
runParseUserAgent: function(input, args) {
var ua = UAS_parser.parse(input); // eslint-disable-line camelcase
return "Type: " + ua.type + "\n" +
"Family: " + ua.uaFamily + "\n" +

View file

@ -18,8 +18,8 @@ var Hash = {
* @param {Object[]} args
* @returns {string}
*/
run_md2: function (input, args) {
return Utils.to_hex_fast(CryptoApi.hash("md2", input, {}));
runMD2: function (input, args) {
return Utils.toHexFast(CryptoApi.hash("md2", input, {}));
},
@ -30,8 +30,8 @@ var Hash = {
* @param {Object[]} args
* @returns {string}
*/
run_md4: function (input, args) {
return Utils.to_hex_fast(CryptoApi.hash("md4", input, {}));
runMD4: function (input, args) {
return Utils.toHexFast(CryptoApi.hash("md4", input, {}));
},
@ -42,7 +42,7 @@ var Hash = {
* @param {Object[]} args
* @returns {string}
*/
run_md5: function (input, args) {
runMD5: function (input, args) {
input = CryptoJS.enc.Latin1.parse(input); // Cast to WordArray
return CryptoJS.MD5(input).toString(CryptoJS.enc.Hex);
},
@ -55,8 +55,8 @@ var Hash = {
* @param {Object[]} args
* @returns {string}
*/
run_sha0: function (input, args) {
return Utils.to_hex_fast(CryptoApi.hash("sha0", input, {}));
runSHA0: function (input, args) {
return Utils.toHexFast(CryptoApi.hash("sha0", input, {}));
},
@ -67,7 +67,7 @@ var Hash = {
* @param {Object[]} args
* @returns {string}
*/
run_sha1: function (input, args) {
runSHA1: function (input, args) {
input = CryptoJS.enc.Latin1.parse(input);
return CryptoJS.SHA1(input).toString(CryptoJS.enc.Hex);
},
@ -80,7 +80,7 @@ var Hash = {
* @param {Object[]} args
* @returns {string}
*/
run_sha224: function (input, args) {
runSHA224: function (input, args) {
input = CryptoJS.enc.Latin1.parse(input);
return CryptoJS.SHA224(input).toString(CryptoJS.enc.Hex);
},
@ -93,7 +93,7 @@ var Hash = {
* @param {Object[]} args
* @returns {string}
*/
run_sha256: function (input, args) {
runSHA256: function (input, args) {
input = CryptoJS.enc.Latin1.parse(input);
return CryptoJS.SHA256(input).toString(CryptoJS.enc.Hex);
},
@ -106,7 +106,7 @@ var Hash = {
* @param {Object[]} args
* @returns {string}
*/
run_sha384: function (input, args) {
runSHA384: function (input, args) {
input = CryptoJS.enc.Latin1.parse(input);
return CryptoJS.SHA384(input).toString(CryptoJS.enc.Hex);
},
@ -119,7 +119,7 @@ var Hash = {
* @param {Object[]} args
* @returns {string}
*/
run_sha512: function (input, args) {
runSHA512: function (input, args) {
input = CryptoJS.enc.Latin1.parse(input);
return CryptoJS.SHA512(input).toString(CryptoJS.enc.Hex);
},
@ -138,11 +138,11 @@ var Hash = {
* @param {Object[]} args
* @returns {string}
*/
run_sha3: function (input, args) {
runSHA3: function (input, args) {
input = CryptoJS.enc.Latin1.parse(input);
var sha3_length = args[0],
var sha3Length = args[0],
options = {
outputLength: parseInt(sha3_length, 10)
outputLength: parseInt(sha3Length, 10)
};
return CryptoJS.SHA3(input, options).toString(CryptoJS.enc.Hex);
},
@ -155,7 +155,7 @@ var Hash = {
* @param {Object[]} args
* @returns {string}
*/
run_ripemd160: function (input, args) {
runRIPEMD160: function (input, args) {
input = CryptoJS.enc.Latin1.parse(input);
return CryptoJS.RIPEMD160(input).toString(CryptoJS.enc.Hex);
},
@ -174,8 +174,8 @@ var Hash = {
* @param {Object[]} args
* @returns {string}
*/
run_hmac: function (input, args) {
var hash_func = args[1];
runHMAC: function (input, args) {
var hashFunc = args[1];
input = CryptoJS.enc.Latin1.parse(input);
var execute = {
"MD5": CryptoJS.HmacMD5(input, args[0]),
@ -187,7 +187,7 @@ var Hash = {
"SHA3": CryptoJS.HmacSHA3(input, args[0]),
"RIPEMD-160": CryptoJS.HmacRIPEMD160(input, args[0]),
};
return execute[hash_func].toString(CryptoJS.enc.Hex);
return execute[hashFunc].toString(CryptoJS.enc.Hex);
},
@ -198,29 +198,29 @@ var Hash = {
* @param {Object[]} args
* @returns {string}
*/
run_all: function (input, args) {
var byte_array = Utils.str_to_byte_array(input),
output = "MD2: " + Hash.run_md2(input, []) +
"\nMD4: " + Hash.run_md4(input, []) +
"\nMD5: " + Hash.run_md5(input, []) +
"\nSHA0: " + Hash.run_sha0(input, []) +
"\nSHA1: " + Hash.run_sha1(input, []) +
"\nSHA2 224: " + Hash.run_sha224(input, []) +
"\nSHA2 256: " + Hash.run_sha256(input, []) +
"\nSHA2 384: " + Hash.run_sha384(input, []) +
"\nSHA2 512: " + Hash.run_sha512(input, []) +
"\nSHA3 224: " + Hash.run_sha3(input, ["224"]) +
"\nSHA3 256: " + Hash.run_sha3(input, ["256"]) +
"\nSHA3 384: " + Hash.run_sha3(input, ["384"]) +
"\nSHA3 512: " + Hash.run_sha3(input, ["512"]) +
"\nRIPEMD-160: " + Hash.run_ripemd160(input, []) +
runAll: function (input, args) {
var byteArray = Utils.strToByteArray(input),
output = "MD2: " + Hash.runMD2(input, []) +
"\nMD4: " + Hash.runMD4(input, []) +
"\nMD5: " + Hash.runMD5(input, []) +
"\nSHA0: " + Hash.runSHA0(input, []) +
"\nSHA1: " + Hash.runSHA1(input, []) +
"\nSHA2 224: " + Hash.runSHA224(input, []) +
"\nSHA2 256: " + Hash.runSHA256(input, []) +
"\nSHA2 384: " + Hash.runSHA384(input, []) +
"\nSHA2 512: " + Hash.runSHA512(input, []) +
"\nSHA3 224: " + Hash.runSHA3(input, ["224"]) +
"\nSHA3 256: " + Hash.runSHA3(input, ["256"]) +
"\nSHA3 384: " + Hash.runSHA3(input, ["384"]) +
"\nSHA3 512: " + Hash.runSHA3(input, ["512"]) +
"\nRIPEMD-160: " + Hash.runRIPEMD160(input, []) +
"\n\nChecksums:" +
"\nFletcher-8: " + Checksum.run_fletcher8(byte_array, []) +
"\nFletcher-16: " + Checksum.run_fletcher16(byte_array, []) +
"\nFletcher-32: " + Checksum.run_fletcher32(byte_array, []) +
"\nFletcher-64: " + Checksum.run_fletcher64(byte_array, []) +
"\nAdler-32: " + Checksum.run_adler32(byte_array, []) +
"\nCRC-32: " + Checksum.run_crc32(byte_array, []);
"\nFletcher-8: " + Checksum.runFletcher8(byteArray, []) +
"\nFletcher-16: " + Checksum.runFletcher16(byteArray, []) +
"\nFletcher-32: " + Checksum.runFletcher32(byteArray, []) +
"\nFletcher-64: " + Checksum.runFletcher64(byteArray, []) +
"\nAdler-32: " + Checksum.runAdler32(byteArray, []) +
"\nCRC-32: " + Checksum.runCRC32(byteArray, []);
return output;
},
@ -233,38 +233,38 @@ var Hash = {
* @param {Object[]} args
* @returns {string}
*/
run_analyse: function(input, args) {
runAnalyse: function(input, args) {
input = input.replace(/\s/g, "");
var output = "",
byte_length = input.length / 2,
bit_length = byte_length * 8,
possible_hash_functions = [];
byteLength = input.length / 2,
bitLength = byteLength * 8,
possibleHashFunctions = [];
if (!/^[a-f0-9]+$/i.test(input)) {
return "Invalid hash";
}
output += "Hash length: " + input.length + "\n" +
"Byte length: " + byte_length + "\n" +
"Bit length: " + bit_length + "\n\n" +
"Byte length: " + byteLength + "\n" +
"Bit length: " + bitLength + "\n\n" +
"Based on the length, this hash could have been generated by one of the following hashing functions:\n";
switch (bit_length) {
switch (bitLength) {
case 4:
possible_hash_functions = [
possibleHashFunctions = [
"Fletcher-4",
"Luhn algorithm",
"Verhoeff algorithm",
];
break;
case 8:
possible_hash_functions = [
possibleHashFunctions = [
"Fletcher-8",
];
break;
case 16:
possible_hash_functions = [
possibleHashFunctions = [
"BSD checksum",
"CRC-16",
"SYSV checksum",
@ -272,21 +272,21 @@ var Hash = {
];
break;
case 32:
possible_hash_functions = [
possibleHashFunctions = [
"CRC-32",
"Fletcher-32",
"Adler-32",
];
break;
case 64:
possible_hash_functions = [
possibleHashFunctions = [
"CRC-64",
"RIPEMD-64",
"SipHash",
];
break;
case 128:
possible_hash_functions = [
possibleHashFunctions = [
"MD5",
"MD4",
"MD2",
@ -297,7 +297,7 @@ var Hash = {
];
break;
case 160:
possible_hash_functions = [
possibleHashFunctions = [
"SHA-1",
"SHA-0",
"FSB-160",
@ -308,13 +308,13 @@ var Hash = {
];
break;
case 192:
possible_hash_functions = [
possibleHashFunctions = [
"Tiger",
"HAVAL-192",
];
break;
case 224:
possible_hash_functions = [
possibleHashFunctions = [
"SHA-224",
"SHA3-224",
"ECOH-224",
@ -323,7 +323,7 @@ var Hash = {
];
break;
case 256:
possible_hash_functions = [
possibleHashFunctions = [
"SHA-256",
"SHA3-256",
"BLAKE-256",
@ -338,12 +338,12 @@ var Hash = {
];
break;
case 320:
possible_hash_functions = [
possibleHashFunctions = [
"RIPEMD-320",
];
break;
case 384:
possible_hash_functions = [
possibleHashFunctions = [
"SHA-384",
"SHA3-384",
"ECOH-384",
@ -351,7 +351,7 @@ var Hash = {
];
break;
case 512:
possible_hash_functions = [
possibleHashFunctions = [
"SHA-512",
"SHA3-512",
"BLAKE-512",
@ -366,18 +366,18 @@ var Hash = {
];
break;
case 1024:
possible_hash_functions = [
possibleHashFunctions = [
"Fowler-Noll-Vo",
];
break;
default:
possible_hash_functions = [
possibleHashFunctions = [
"Unknown"
];
break;
}
return output + possible_hash_functions.join("\n");
return output + possibleHashFunctions.join("\n");
},
};

View file

@ -30,14 +30,14 @@ var Hexdump = {
/**
* To Hexdump operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run_to: function(input, args) {
runTo: function(input, args) {
var length = args[0] || Hexdump.WIDTH;
var upper_case = args[1];
var include_final_length = args[2];
var upperCase = args[1];
var includeFinalLength = args[2];
var output = "", padding = 2;
for (var i = 0; i < input.length; i += length) {
@ -47,18 +47,18 @@ var Hexdump = {
hexa += Utils.hex(buff[j], padding) + " ";
}
var line_no = Utils.hex(i, 8);
var lineNo = Utils.hex(i, 8);
if (upper_case) {
if (upperCase) {
hexa = hexa.toUpperCase();
line_no = line_no.toUpperCase();
lineNo = lineNo.toUpperCase();
}
output += line_no + " " +
Utils.pad_right(hexa, (length*(padding+1))) +
" |" + Utils.pad_right(Utils.printable(Utils.byte_array_to_chars(buff)), buff.length) + "|\n";
output += lineNo + " " +
Utils.padRight(hexa, (length*(padding+1))) +
" |" + Utils.padRight(Utils.printable(Utils.byteArrayToChars(buff)), buff.length) + "|\n";
if (include_final_length && i+buff.length === input.length) {
if (includeFinalLength && i+buff.length === input.length) {
output += Utils.hex(i+buff.length, 8) + "\n";
}
}
@ -72,15 +72,15 @@ var Hexdump = {
*
* @param {string} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_from: function(input, args) {
runFrom: function(input, args) {
var 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,
block, line;
while ((block = regex.exec(input))) {
line = Utils.from_hex(block[1].replace(/-/g, " "));
line = Utils.fromHex(block[1].replace(/-/g, " "));
for (var i = 0; i < line.length; i++) {
output.push(line[i]);
}
@ -90,7 +90,7 @@ var Hexdump = {
var w = (width - 13) / 4;
// w should be the specified width of the hexdump and therefore a round number
if (Math.floor(w) !== w || input.indexOf("\r") !== -1 || output.indexOf(13) !== -1) {
app.options.attempt_highlight = false;
app.options.attemptHighlight = false;
}
return output;
},
@ -105,7 +105,7 @@ var Hexdump = {
* @param {Object[]} args
* @returns {Object[]} pos
*/
highlight_to: function(pos, args) {
highlightTo: function(pos, args) {
// Calculate overall selection
var w = args[0] || 16,
width = 14 + (w*4),
@ -125,32 +125,32 @@ var Hexdump = {
pos[0].end = line*width + 10 + offset*3 - 1;
// Set up multiple selections for bytes
var start_line_num = Math.floor(pos[0].start / width);
var end_line_num = Math.floor(pos[0].end / width);
var startLineNum = Math.floor(pos[0].start / width);
var endLineNum = Math.floor(pos[0].end / width);
if (start_line_num === end_line_num) {
if (startLineNum === endLineNum) {
pos.push(pos[0]);
} else {
start = pos[0].start;
end = (start_line_num+1) * width - w - 5;
end = (startLineNum+1) * width - w - 5;
pos.push({ start: start, end: end });
while (end < pos[0].end) {
start_line_num++;
start = start_line_num * width + 10;
end = (start_line_num+1) * width - w - 5;
startLineNum++;
start = startLineNum * width + 10;
end = (startLineNum+1) * width - w - 5;
if (end > pos[0].end) end = pos[0].end;
pos.push({ start: start, end: end });
}
}
// Set up multiple selections for ASCII
var len = pos.length, line_num = 0;
var len = pos.length, lineNum = 0;
start = 0;
end = 0;
for (var i = 1; i < len; i++) {
line_num = Math.floor(pos[i].start / width);
start = (((pos[i].start - (line_num * width)) - 10) / 3) + (width - w -2) + (line_num * width);
end = (((pos[i].end + 1 - (line_num * width)) - 10) / 3) + (width - w -2) + (line_num * width);
lineNum = Math.floor(pos[i].start / width);
start = (((pos[i].start - (lineNum * width)) - 10) / 3) + (width - w -2) + (lineNum * width);
end = (((pos[i].end + 1 - (lineNum * width)) - 10) / 3) + (width - w -2) + (lineNum * width);
pos.push({ start: start, end: end });
}
return pos;
@ -166,7 +166,7 @@ var Hexdump = {
* @param {Object[]} args
* @returns {Object[]} pos
*/
highlight_from: function(pos, args) {
highlightFrom: function(pos, args) {
var w = args[0] || 16;
var width = 14 + (w*4);

View file

@ -34,26 +34,26 @@ var IP = {
* @param {Object[]} args
* @returns {string}
*/
run_parse_ip_range: function (input, args) {
var include_network_info = args[0],
enumerate_addresses = args[1],
allow_large_list = args[2];
runParseIpRange: function (input, args) {
var includeNetworkInfo = args[0],
enumerateAddresses = args[1],
allowLargeList = args[2];
// Check what type of input we are looking at
var ipv4_cidr_regex = /^\s*((?:\d{1,3}\.){3}\d{1,3})\/(\d\d?)\s*$/,
ipv4_range_regex = /^\s*((?:\d{1,3}\.){3}\d{1,3})\s*-\s*((?:\d{1,3}\.){3}\d{1,3})\s*$/,
ipv6_cidr_regex = /^\s*(((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\4)::|:\b|(?![\dA-F])))|(?!\3\4)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\/(\d\d?\d?)\s*$/i,
ipv6_range_regex = /^\s*(((?=.*::)(?!.*::[^-]+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\4)::|:\b|(?![\dA-F])))|(?!\3\4)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\s*-\s*(((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\17)::|:\b|(?![\dA-F])))|(?!\16\17)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\s*$/i,
var ipv4CidrRegex = /^\s*((?:\d{1,3}\.){3}\d{1,3})\/(\d\d?)\s*$/,
ipv4RangeRegex = /^\s*((?:\d{1,3}\.){3}\d{1,3})\s*-\s*((?:\d{1,3}\.){3}\d{1,3})\s*$/,
ipv6CidrRegex = /^\s*(((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\4)::|:\b|(?![\dA-F])))|(?!\3\4)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\/(\d\d?\d?)\s*$/i,
ipv6RangeRegex = /^\s*(((?=.*::)(?!.*::[^-]+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\4)::|:\b|(?![\dA-F])))|(?!\3\4)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\s*-\s*(((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\17)::|:\b|(?![\dA-F])))|(?!\16\17)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\s*$/i,
match;
if ((match = ipv4_cidr_regex.exec(input))) {
return IP._ipv4_cidr_range(match, include_network_info, enumerate_addresses, allow_large_list);
} else if ((match = ipv4_range_regex.exec(input))) {
return IP._ipv4_hyphenated_range(match, include_network_info, enumerate_addresses, allow_large_list);
} else if ((match = ipv6_cidr_regex.exec(input))) {
return IP._ipv6_cidr_range(match, include_network_info);
} else if ((match = ipv6_range_regex.exec(input))) {
return IP._ipv6_hyphenated_range(match, include_network_info);
if ((match = ipv4CidrRegex.exec(input))) {
return IP._ipv4CidrRange(match, includeNetworkInfo, enumerateAddresses, allowLargeList);
} else if ((match = ipv4RangeRegex.exec(input))) {
return IP._ipv4HyphenatedRange(match, includeNetworkInfo, enumerateAddresses, allowLargeList);
} else if ((match = ipv6CidrRegex.exec(input))) {
return IP._ipv6CidrRange(match, includeNetworkInfo);
} else if ((match = ipv6RangeRegex.exec(input))) {
return IP._ipv6HyphenatedRange(match, includeNetworkInfo);
} else {
return "Invalid input.\n\nEnter either a CIDR range (e.g. 10.0.0.0/24) or a hyphenated range (e.g. 10.0.0.0 - 10.0.1.0). IPv6 also supported.";
}
@ -64,12 +64,12 @@ var IP = {
* @constant
* @default
*/
IPv4_REGEX: /^\s*((?:\d{1,3}\.){3}\d{1,3})\s*$/,
IPV4_REGEX: /^\s*((?:\d{1,3}\.){3}\d{1,3})\s*$/,
/**
* @constant
* @default
*/
IPv6_REGEX: /^\s*(((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\4)::|:\b|(?![\dA-F])))|(?!\3\4)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\s*$/i,
IPV6_REGEX: /^\s*(((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\4)::|:\b|(?![\dA-F])))|(?!\3\4)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4}))\s*$/i,
/**
* Parse IPv6 address operation.
@ -78,14 +78,14 @@ var IP = {
* @param {Object[]} args
* @returns {string}
*/
run_parse_ipv6: function (input, args) {
runParseIpv6: function (input, args) {
var match,
output = "";
if ((match = IP.IPv6_REGEX.exec(input))) {
var ipv6 = IP._str_to_ipv6(match[1]),
longhand = IP._ipv6_to_str(ipv6),
shorthand = IP._ipv6_to_str(ipv6, true);
if ((match = IP.IPV6_REGEX.exec(input))) {
var ipv6 = IP._strToIpv6(match[1]),
longhand = IP._ipv6ToStr(ipv6),
shorthand = IP._ipv6ToStr(ipv6, true);
output += "Longhand: " + longhand + "\nShorthand: " + shorthand + "\n";
@ -102,13 +102,13 @@ var IP = {
ipv6[3] === 0 && ipv6[4] === 0 && ipv6[5] === 0xffff) {
// IPv4-mapped IPv6 address
output += "\nIPv4-mapped IPv6 address detected. IPv6 clients will be handled natively by default, and IPv4 clients appear as IPv6 clients at their IPv4-mapped IPv6 address.";
output += "\nMapped IPv4 address: " + IP._ipv4_to_str((ipv6[6] << 16) + ipv6[7]);
output += "\nMapped IPv4 address: " + IP._ipv4ToStr((ipv6[6] << 16) + ipv6[7]);
output += "\nIPv4-mapped IPv6 addresses range: ::ffff:0:0/96";
} else if (ipv6[0] === 0 && ipv6[1] === 0 && ipv6[2] === 0 &&
ipv6[3] === 0 && ipv6[4] === 0xffff && ipv6[5] === 0) {
// IPv4-translated address
output += "\nIPv4-translated address detected. Used by Stateless IP/ICMP Translation (SIIT). See RFCs 6145 and 6052 for more details.";
output += "\nTranslated IPv4 address: " + IP._ipv4_to_str((ipv6[6] << 16) + ipv6[7]);
output += "\nTranslated IPv4 address: " + IP._ipv4ToStr((ipv6[6] << 16) + ipv6[7]);
output += "\nIPv4-translated addresses range: ::ffff:0:0:0/96";
} else if (ipv6[0] === 0x100) {
// Discard prefix per RFC 6666
@ -118,50 +118,50 @@ var IP = {
ipv6[3] === 0 && ipv6[4] === 0 && ipv6[5] === 0) {
// IPv4/IPv6 translation per RFC 6052
output += "\n'Well-Known' prefix for IPv4/IPv6 translation detected. See RFC 6052 for more details.";
output += "\nTranslated IPv4 address: " + IP._ipv4_to_str((ipv6[6] << 16) + ipv6[7]);
output += "\nTranslated IPv4 address: " + IP._ipv4ToStr((ipv6[6] << 16) + ipv6[7]);
output += "\n'Well-Known prefix range: 64:ff9b::/96";
} else if (ipv6[0] === 0x2001 && ipv6[1] === 0) {
// Teredo tunneling
output += "\nTeredo tunneling IPv6 address detected\n";
var server_ipv4 = (ipv6[2] << 16) + ipv6[3],
udp_port = (~ipv6[5]) & 0xffff,
client_ipv4 = ~((ipv6[6] << 16) + ipv6[7]),
flag_cone = (ipv6[4] >>> 15) & 1,
flag_r = (ipv6[4] >>> 14) & 1,
flag_random1 = (ipv6[4] >>> 10) & 15,
flag_ug = (ipv6[4] >>> 8) & 3,
flag_random2 = ipv6[4] & 255;
var serverIpv4 = (ipv6[2] << 16) + ipv6[3],
udpPort = (~ipv6[5]) & 0xffff,
clientIpv4 = ~((ipv6[6] << 16) + ipv6[7]),
flagCone = (ipv6[4] >>> 15) & 1,
flagR = (ipv6[4] >>> 14) & 1,
flagRandom1 = (ipv6[4] >>> 10) & 15,
flagUg = (ipv6[4] >>> 8) & 3,
flagRandom2 = ipv6[4] & 255;
output += "\nServer IPv4 address: " + IP._ipv4_to_str(server_ipv4) +
"\nClient IPv4 address: " + IP._ipv4_to_str(client_ipv4) +
"\nClient UDP port: " + udp_port +
output += "\nServer IPv4 address: " + IP._ipv4ToStr(serverIpv4) +
"\nClient IPv4 address: " + IP._ipv4ToStr(clientIpv4) +
"\nClient UDP port: " + udpPort +
"\nFlags:" +
"\n\tCone: " + flag_cone;
"\n\tCone: " + flagCone;
if (flag_cone) {
if (flagCone) {
output += " (Client is behind a cone NAT)";
} else {
output += " (Client is not behind a cone NAT)";
}
output += "\n\tR: " + flag_r;
output += "\n\tR: " + flagR;
if (flag_r) {
if (flagR) {
output += " Error: This flag should be set to 0. See RFC 5991 and RFC 4380.";
}
output += "\n\tRandom1: " + Utils.bin(flag_random1, 4) +
"\n\tUG: " + Utils.bin(flag_ug, 2);
output += "\n\tRandom1: " + Utils.bin(flagRandom1, 4) +
"\n\tUG: " + Utils.bin(flagUg, 2);
if (flag_ug) {
if (flagUg) {
output += " Error: This flag should be set to 00. See RFC 4380.";
}
output += "\n\tRandom2: " + Utils.bin(flag_random2, 8);
output += "\n\tRandom2: " + Utils.bin(flagRandom2, 8);
if (!flag_r && !flag_ug && flag_random1 && flag_random2) {
if (!flagR && !flagUg && flagRandom1 && flagRandom2) {
output += "\n\nThis is a valid Teredo address which complies with RFC 4380 and RFC 5991.";
} else if (!flag_r && !flag_ug) {
} else if (!flagR && !flagUg) {
output += "\n\nThis is a valid Teredo address which complies with RFC 4380, however it does not comply with RFC 5991 (Teredo Security Updates) as there are no randomised bits in the flag field.";
} else {
output += "\n\nThis is an invalid Teredo address.";
@ -187,15 +187,15 @@ var IP = {
output += "\n6to4 transition IPv6 address detected. See RFC 3056 for more details." +
"\n6to4 prefix range: 2002::/16";
var v4_addr = IP._ipv4_to_str((ipv6[1] << 16) + ipv6[2]),
sla_id = ipv6[3],
interface_id_str = ipv6[4].toString(16) + ipv6[5].toString(16) + ipv6[6].toString(16) + ipv6[7].toString(16),
interface_id = new BigInteger(interface_id_str, 16);
var v4Addr = IP._ipv4ToStr((ipv6[1] << 16) + ipv6[2]),
slaId = ipv6[3],
interfaceIdStr = ipv6[4].toString(16) + ipv6[5].toString(16) + ipv6[6].toString(16) + ipv6[7].toString(16),
interfaceId = new BigInteger(interfaceIdStr, 16);
output += "\n\nEncapsulated IPv4 address: " + v4_addr +
"\nSLA ID: " + sla_id +
"\nInterface ID (base 16): " + interface_id_str +
"\nInterface ID (base 10): " + interface_id.toString();
output += "\n\nEncapsulated IPv4 address: " + v4Addr +
"\nSLA ID: " + slaId +
"\nInterface ID (base 16): " + interfaceIdStr +
"\nInterface ID (base 10): " + interfaceId.toString();
} else if (ipv6[0] >= 0xfc00 && ipv6[0] <= 0xfdff) {
// Unique local address
output += "\nThis is a unique local address comparable to the IPv4 private addresses 10.0.0.0/8, 172.16.0.0/12 and 192.168.0.0/16. See RFC 4193 for more details.";
@ -229,9 +229,9 @@ var IP = {
* @param {Object[]} args
* @returns {string}
*/
run_change_ip_format: function(input, args) {
var in_format = args[0],
out_format = args[1],
runChangeIpFormat: function(input, args) {
var inFormat = args[0],
outFormat = args[1],
lines = input.split("\n"),
output = "",
j = 0;
@ -239,54 +239,54 @@ var IP = {
for (var i = 0; i < lines.length; i++) {
if (lines[i] === "") continue;
var ba_ip = [];
var baIp = [];
if (in_format === out_format) {
if (inFormat === outFormat) {
output += lines[i] + "\n";
continue;
}
// Convert to byte array IP from input format
switch (in_format) {
switch (inFormat) {
case "Dotted Decimal":
var octets = lines[i].split(".");
for (j = 0; j < octets.length; j++) {
ba_ip.push(parseInt(octets[j], 10));
baIp.push(parseInt(octets[j], 10));
}
break;
case "Decimal":
var decimal = lines[i].toString();
ba_ip.push(decimal >> 24 & 255);
ba_ip.push(decimal >> 16 & 255);
ba_ip.push(decimal >> 8 & 255);
ba_ip.push(decimal & 255);
baIp.push(decimal >> 24 & 255);
baIp.push(decimal >> 16 & 255);
baIp.push(decimal >> 8 & 255);
baIp.push(decimal & 255);
break;
case "Hex":
ba_ip = Utils.hex_to_byte_array(lines[i]);
baIp = Utils.hexToByteArray(lines[i]);
break;
default:
throw "Unsupported input IP format";
}
// Convert byte array IP to output format
switch (out_format) {
switch (outFormat) {
case "Dotted Decimal":
var dd_ip = "";
for (j = 0; j < ba_ip.length; j++) {
dd_ip += ba_ip[j] + ".";
var ddIp = "";
for (j = 0; j < baIp.length; j++) {
ddIp += baIp[j] + ".";
}
output += dd_ip.slice(0, dd_ip.length-1) + "\n";
output += ddIp.slice(0, ddIp.length-1) + "\n";
break;
case "Decimal":
var dec_ip = ((ba_ip[0] << 24) | (ba_ip[1] << 16) | (ba_ip[2] << 8) | ba_ip[3]) >>> 0;
output += dec_ip.toString() + "\n";
var decIp = ((baIp[0] << 24) | (baIp[1] << 16) | (baIp[2] << 8) | baIp[3]) >>> 0;
output += decIp.toString() + "\n";
break;
case "Hex":
var hex_ip = "";
for (j = 0; j < ba_ip.length; j++) {
hex_ip += Utils.hex(ba_ip[j]);
var hexIp = "";
for (j = 0; j < baIp.length; j++) {
hexIp += Utils.hex(baIp[j]);
}
output += hex_ip + "\n";
output += hexIp + "\n";
break;
default:
throw "Unsupported output IP format";
@ -320,20 +320,20 @@ var IP = {
* @param {Object[]} args
* @returns {string}
*/
run_group_ips: function(input, args) {
var delim = Utils.char_rep[args[0]],
runGroupIps: function(input, args) {
var delim = Utils.charRep[args[0]],
cidr = args[1],
only_subnets = args[2],
ipv4_mask = cidr < 32 ? ~(0xFFFFFFFF >>> cidr) : 0xFFFFFFFF,
ipv6_mask = IP._gen_ipv6_mask(cidr),
onlySubnets = args[2],
ipv4Mask = cidr < 32 ? ~(0xFFFFFFFF >>> cidr) : 0xFFFFFFFF,
ipv6Mask = IP._genIpv6Mask(cidr),
ips = input.split(delim),
ipv4_networks = {},
ipv6_networks = {},
ipv4Networks = {},
ipv6Networks = {},
match = null,
output = "",
ip = null,
network = null,
network_str = "";
networkStr = "";
if (cidr < 0 || cidr > 127) {
return "CIDR must be less than 32 for IPv4 or 128 for IPv6";
@ -341,57 +341,57 @@ var IP = {
// Parse all IPs and add to network dictionary
for (var i = 0; i < ips.length; i++) {
if ((match = IP.IPv4_REGEX.exec(ips[i]))) {
ip = IP._str_to_ipv4(match[1]) >>> 0;
network = ip & ipv4_mask;
if ((match = IP.IPV4_REGEX.exec(ips[i]))) {
ip = IP._strToIpv4(match[1]) >>> 0;
network = ip & ipv4Mask;
if (ipv4_networks.hasOwnProperty(network)) {
ipv4_networks[network].push(ip);
if (ipv4Networks.hasOwnProperty(network)) {
ipv4Networks[network].push(ip);
} else {
ipv4_networks[network] = [ip];
ipv4Networks[network] = [ip];
}
} else if ((match = IP.IPv6_REGEX.exec(ips[i]))) {
ip = IP._str_to_ipv6(match[1]);
} else if ((match = IP.IPV6_REGEX.exec(ips[i]))) {
ip = IP._strToIpv6(match[1]);
network = [];
network_str = "";
networkStr = "";
for (var j = 0; j < 8; j++) {
network.push(ip[j] & ipv6_mask[j]);
network.push(ip[j] & ipv6Mask[j]);
}
network_str = IP._ipv6_to_str(network, true);
networkStr = IP._ipv6ToStr(network, true);
if (ipv6_networks.hasOwnProperty(network_str)) {
ipv6_networks[network_str].push(ip);
if (ipv6Networks.hasOwnProperty(networkStr)) {
ipv6Networks[networkStr].push(ip);
} else {
ipv6_networks[network_str] = [ip];
ipv6Networks[networkStr] = [ip];
}
}
}
// Sort IPv4 network dictionaries and print
for (network in ipv4_networks) {
ipv4_networks[network] = ipv4_networks[network].sort();
for (network in ipv4Networks) {
ipv4Networks[network] = ipv4Networks[network].sort();
output += IP._ipv4_to_str(network) + "/" + cidr + "\n";
output += IP._ipv4ToStr(network) + "/" + cidr + "\n";
if (!only_subnets) {
for (i = 0; i < ipv4_networks[network].length; i++) {
output += " " + IP._ipv4_to_str(ipv4_networks[network][i]) + "\n";
if (!onlySubnets) {
for (i = 0; i < ipv4Networks[network].length; i++) {
output += " " + IP._ipv4ToStr(ipv4Networks[network][i]) + "\n";
}
output += "\n";
}
}
// Sort IPv6 network dictionaries and print
for (network_str in ipv6_networks) {
//ipv6_networks[network_str] = ipv6_networks[network_str].sort(); TODO
for (networkStr in ipv6Networks) {
//ipv6Networks[networkStr] = ipv6Networks[networkStr].sort(); TODO
output += network_str + "/" + cidr + "\n";
output += networkStr + "/" + cidr + "\n";
if (!only_subnets) {
for (i = 0; i < ipv6_networks[network_str].length; i++) {
output += " " + IP._ipv6_to_str(ipv6_networks[network_str][i], true) + "\n";
if (!onlySubnets) {
for (i = 0; i < ipv6Networks[networkStr].length; i++) {
output += " " + IP._ipv6ToStr(ipv6Networks[networkStr][i], true) + "\n";
}
output += "\n";
}
@ -413,35 +413,35 @@ var IP = {
*
* @private
* @param {RegExp} cidr
* @param {boolean} include_network_info
* @param {boolean} enumerate_addresses
* @param {boolean} allow_large_list
* @param {boolean} includeNetworkInfo
* @param {boolean} enumerateAddresses
* @param {boolean} allowLargeList
* @returns {string}
*/
_ipv4_cidr_range: function(cidr, include_network_info, enumerate_addresses, allow_large_list) {
_ipv4CidrRange: function(cidr, includeNetworkInfo, enumerateAddresses, allowLargeList) {
var output = "",
network = IP._str_to_ipv4(cidr[1]),
cidr_range = parseInt(cidr[2], 10);
network = IP._strToIpv4(cidr[1]),
cidrRange = parseInt(cidr[2], 10);
if (cidr_range < 0 || cidr_range > 31) {
if (cidrRange < 0 || cidrRange > 31) {
return "IPv4 CIDR must be less than 32";
}
var mask = ~(0xFFFFFFFF >>> cidr_range),
var mask = ~(0xFFFFFFFF >>> cidrRange),
ip1 = network & mask,
ip2 = ip1 | ~mask;
if (include_network_info) {
output += "Network: " + IP._ipv4_to_str(network) + "\n";
output += "CIDR: " + cidr_range + "\n";
output += "Mask: " + IP._ipv4_to_str(mask) + "\n";
output += "Range: " + IP._ipv4_to_str(ip1) + " - " + IP._ipv4_to_str(ip2) + "\n";
if (includeNetworkInfo) {
output += "Network: " + IP._ipv4ToStr(network) + "\n";
output += "CIDR: " + cidrRange + "\n";
output += "Mask: " + IP._ipv4ToStr(mask) + "\n";
output += "Range: " + IP._ipv4ToStr(ip1) + " - " + IP._ipv4ToStr(ip2) + "\n";
output += "Total addresses in range: " + (((ip2 - ip1) >>> 0) + 1) + "\n\n";
}
if (enumerate_addresses) {
if (cidr_range >= 16 || allow_large_list) {
output += IP._generate_ipv4_range(ip1, ip2).join("\n");
if (enumerateAddresses) {
if (cidrRange >= 16 || allowLargeList) {
output += IP._generateIpv4Range(ip1, ip2).join("\n");
} else {
output += IP._LARGE_RANGE_ERROR;
}
@ -455,42 +455,42 @@ var IP = {
*
* @private
* @param {RegExp} cidr
* @param {boolean} include_network_info
* @param {boolean} includeNetworkInfo
* @returns {string}
*/
_ipv6_cidr_range: function(cidr, include_network_info) {
_ipv6CidrRange: function(cidr, includeNetworkInfo) {
var output = "",
network = IP._str_to_ipv6(cidr[1]),
cidr_range = parseInt(cidr[cidr.length-1], 10);
network = IP._strToIpv6(cidr[1]),
cidrRange = parseInt(cidr[cidr.length-1], 10);
if (cidr_range < 0 || cidr_range > 127) {
if (cidrRange < 0 || cidrRange > 127) {
return "IPv6 CIDR must be less than 128";
}
var mask = IP._gen_ipv6_mask(cidr_range),
var mask = IP._genIpv6Mask(cidrRange),
ip1 = new Array(8),
ip2 = new Array(8),
total_diff = "",
totalDiff = "",
total = new Array(128);
for (var i = 0; i < 8; i++) {
ip1[i] = network[i] & mask[i];
ip2[i] = ip1[i] | (~mask[i] & 0x0000FFFF);
total_diff = (ip2[i] - ip1[i]).toString(2);
totalDiff = (ip2[i] - ip1[i]).toString(2);
if (total_diff !== "0") {
for (var n = 0; n < total_diff.length; n++) {
total[i*16 + 16-(total_diff.length-n)] = total_diff[n];
if (totalDiff !== "0") {
for (var n = 0; n < totalDiff.length; n++) {
total[i*16 + 16-(totalDiff.length-n)] = totalDiff[n];
}
}
}
if (include_network_info) {
output += "Network: " + IP._ipv6_to_str(network) + "\n";
output += "Shorthand: " + IP._ipv6_to_str(network, true) + "\n";
output += "CIDR: " + cidr_range + "\n";
output += "Mask: " + IP._ipv6_to_str(mask) + "\n";
output += "Range: " + IP._ipv6_to_str(ip1) + " - " + IP._ipv6_to_str(ip2) + "\n";
if (includeNetworkInfo) {
output += "Network: " + IP._ipv6ToStr(network) + "\n";
output += "Shorthand: " + IP._ipv6ToStr(network, true) + "\n";
output += "CIDR: " + cidrRange + "\n";
output += "Mask: " + IP._ipv6ToStr(mask) + "\n";
output += "Range: " + IP._ipv6ToStr(ip1) + " - " + IP._ipv6ToStr(ip2) + "\n";
output += "Total addresses in range: " + (parseInt(total.join(""), 2) + 1) + "\n\n";
}
@ -505,7 +505,7 @@ var IP = {
* @param {number} cidr
* @returns {number[]}
*/
_gen_ipv6_mask: function(cidr) {
_genIpv6Mask: function(cidr) {
var mask = new Array(8),
shift;
@ -529,15 +529,15 @@ var IP = {
*
* @private
* @param {RegExp} range
* @param {boolean} include_network_info
* @param {boolean} enumerate_addresses
* @param {boolean} allow_large_list
* @param {boolean} includeNetworkInfo
* @param {boolean} enumerateAddresses
* @param {boolean} allowLargeList
* @returns {string}
*/
_ipv4_hyphenated_range: function(range, include_network_info, enumerate_addresses, allow_large_list) {
_ipv4HyphenatedRange: function(range, includeNetworkInfo, enumerateAddresses, allowLargeList) {
var output = "",
ip1 = IP._str_to_ipv4(range[1]),
ip2 = IP._str_to_ipv4(range[2]);
ip1 = IP._strToIpv4(range[1]),
ip2 = IP._strToIpv4(range[2]);
// Calculate mask
var diff = ip1 ^ ip2,
@ -552,23 +552,23 @@ var IP = {
mask = ~mask >>> 0;
var network = ip1 & mask,
sub_ip1 = network & mask,
sub_ip2 = sub_ip1 | ~mask;
subIp1 = network & mask,
subIp2 = subIp1 | ~mask;
if (include_network_info) {
if (includeNetworkInfo) {
output += "Minimum subnet required to hold this range:\n";
output += "\tNetwork: " + IP._ipv4_to_str(network) + "\n";
output += "\tNetwork: " + IP._ipv4ToStr(network) + "\n";
output += "\tCIDR: " + cidr + "\n";
output += "\tMask: " + IP._ipv4_to_str(mask) + "\n";
output += "\tSubnet range: " + IP._ipv4_to_str(sub_ip1) + " - " + IP._ipv4_to_str(sub_ip2) + "\n";
output += "\tTotal addresses in subnet: " + (((sub_ip2 - sub_ip1) >>> 0) + 1) + "\n\n";
output += "Range: " + IP._ipv4_to_str(ip1) + " - " + IP._ipv4_to_str(ip2) + "\n";
output += "\tMask: " + IP._ipv4ToStr(mask) + "\n";
output += "\tSubnet range: " + IP._ipv4ToStr(subIp1) + " - " + IP._ipv4ToStr(subIp2) + "\n";
output += "\tTotal addresses in subnet: " + (((subIp2 - subIp1) >>> 0) + 1) + "\n\n";
output += "Range: " + IP._ipv4ToStr(ip1) + " - " + IP._ipv4ToStr(ip2) + "\n";
output += "Total addresses in range: " + (((ip2 - ip1) >>> 0) + 1) + "\n\n";
}
if (enumerate_addresses) {
if (((ip2 - ip1) >>> 0) <= 65536 || allow_large_list) {
output += IP._generate_ipv4_range(ip1, ip2).join("\n");
if (enumerateAddresses) {
if (((ip2 - ip1) >>> 0) <= 65536 || allowLargeList) {
output += IP._generateIpv4Range(ip1, ip2).join("\n");
} else {
output += IP._LARGE_RANGE_ERROR;
}
@ -582,13 +582,13 @@ var IP = {
*
* @private
* @param {RegExp} range
* @param {boolean} include_network_info
* @param {boolean} includeNetworkInfo
* @returns {string}
*/
_ipv6_hyphenated_range: function(range, include_network_info) {
_ipv6HyphenatedRange: function(range, includeNetworkInfo) {
var output = "",
ip1 = IP._str_to_ipv6(range[1]),
ip2 = IP._str_to_ipv6(range[14]);
ip1 = IP._strToIpv6(range[1]),
ip2 = IP._strToIpv6(range[14]);
var t = "",
total = new Array(128);
@ -606,9 +606,9 @@ var IP = {
}
}
if (include_network_info) {
output += "Range: " + IP._ipv6_to_str(ip1) + " - " + IP._ipv6_to_str(ip2) + "\n";
output += "Shorthand range: " + IP._ipv6_to_str(ip1, true) + " - " + IP._ipv6_to_str(ip2, true) + "\n";
if (includeNetworkInfo) {
output += "Range: " + IP._ipv6ToStr(ip1) + " - " + IP._ipv6ToStr(ip2) + "\n";
output += "Shorthand range: " + IP._ipv6ToStr(ip1, true) + " - " + IP._ipv6ToStr(ip2, true) + "\n";
output += "Total addresses in range: " + (parseInt(total.join(""), 2) + 1) + "\n\n";
}
@ -620,36 +620,36 @@ var IP = {
* Converts an IPv4 address from string format to numerical format.
*
* @private
* @param {string} ip_str
* @param {string} ipStr
* @returns {number}
*
* @example
* // returns 168427520
* IP._str_to_ipv4("10.10.0.0");
* IP._strToIpv4("10.10.0.0");
*/
_str_to_ipv4: function (ip_str) {
var blocks = ip_str.split("."),
num_blocks = parse_blocks(blocks),
_strToIpv4: function (ipStr) {
var blocks = ipStr.split("."),
numBlocks = parseBlocks(blocks),
result = 0;
result += num_blocks[0] << 24;
result += num_blocks[1] << 16;
result += num_blocks[2] << 8;
result += num_blocks[3];
result += numBlocks[0] << 24;
result += numBlocks[1] << 16;
result += numBlocks[2] << 8;
result += numBlocks[3];
return result;
function parse_blocks(blocks) {
function parseBlocks(blocks) {
if (blocks.length !== 4)
throw "More than 4 blocks.";
var num_blocks = [];
var numBlocks = [];
for (var i = 0; i < 4; i++) {
num_blocks[i] = parseInt(blocks[i], 10);
if (num_blocks[i] < 0 || num_blocks[i] > 255)
numBlocks[i] = parseInt(blocks[i], 10);
if (numBlocks[i] < 0 || numBlocks[i] > 255)
throw "Block out of range.";
}
return num_blocks;
return numBlocks;
}
},
@ -658,18 +658,18 @@ var IP = {
* Converts an IPv4 address from numerical format to string format.
*
* @private
* @param {number} ip_int
* @param {number} ipInt
* @returns {string}
*
* @example
* // returns "10.10.0.0"
* IP._ipv4_to_str(168427520);
* IP._ipv4ToStr(168427520);
*/
_ipv4_to_str: function(ip_int) {
var blockA = (ip_int >> 24) & 255,
blockB = (ip_int >> 16) & 255,
blockC = (ip_int >> 8) & 255,
blockD = ip_int & 255;
_ipv4ToStr: function(ipInt) {
var blockA = (ipInt >> 24) & 255,
blockB = (ipInt >> 16) & 255,
blockC = (ipInt >> 8) & 255,
blockD = ipInt & 255;
return blockA + "." + blockB + "." + blockC + "." + blockD;
},
@ -679,40 +679,40 @@ var IP = {
* Converts an IPv6 address from string format to numerical array format.
*
* @private
* @param {string} ip_str
* @param {string} ipStr
* @returns {number[]}
*
* @example
* // returns [65280, 0, 0, 0, 0, 0, 4369, 8738]
* IP._str_to_ipv6("ff00::1111:2222");
* IP._strToIpv6("ff00::1111:2222");
*/
_str_to_ipv6: function(ip_str) {
var blocks = ip_str.split(":"),
num_blocks = parse_blocks(blocks),
_strToIpv6: function(ipStr) {
var blocks = ipStr.split(":"),
numBlocks = parseBlocks(blocks),
j = 0,
ipv6 = new Array(8);
for (var i = 0; i < 8; i++) {
if (isNaN(num_blocks[j])) {
if (isNaN(numBlocks[j])) {
ipv6[i] = 0;
if (i === (8-num_blocks.slice(j).length)) j++;
if (i === (8-numBlocks.slice(j).length)) j++;
} else {
ipv6[i] = num_blocks[j];
ipv6[i] = numBlocks[j];
j++;
}
}
return ipv6;
function parse_blocks(blocks) {
function parseBlocks(blocks) {
if (blocks.length < 3 || blocks.length > 8)
throw "Badly formatted IPv6 address.";
var num_blocks = [];
var numBlocks = [];
for (var i = 0; i < blocks.length; i++) {
num_blocks[i] = parseInt(blocks[i], 16);
if (num_blocks[i] < 0 || num_blocks[i] > 65535)
numBlocks[i] = parseInt(blocks[i], 16);
if (numBlocks[i] < 0 || numBlocks[i] > 65535)
throw "Block out of range.";
}
return num_blocks;
return numBlocks;
}
},
@ -727,12 +727,12 @@ var IP = {
*
* @example
* // returns "ff00::1111:2222"
* IP._ipv6_to_str([65280, 0, 0, 0, 0, 0, 4369, 8738], true);
* IP._ipv6ToStr([65280, 0, 0, 0, 0, 0, 4369, 8738], true);
*
* // returns "ff00:0000:0000:0000:0000:0000:1111:2222"
* IP._ipv6_to_str([65280, 0, 0, 0, 0, 0, 4369, 8738], false);
* IP._ipv6ToStr([65280, 0, 0, 0, 0, 0, 4369, 8738], false);
*/
_ipv6_to_str: function(ipv6, compact) {
_ipv6ToStr: function(ipv6, compact) {
var output = "",
i = 0;
@ -779,18 +779,18 @@ var IP = {
*
* @private
* @param {number} ip
* @param {number} end_ip
* @param {number} endIp
* @returns {string[]}
*
* @example
* // returns ["0.0.0.1", "0.0.0.2", "0.0.0.3"]
* IP._generate_ipv4_range(1, 3);
* IP._generateIpv4Range(1, 3);
*/
_generate_ipv4_range: function(ip, end_ip) {
_generateIpv4Range: function(ip, endIp) {
var range = [];
if (end_ip >= ip) {
for (; ip <= end_ip; ip++) {
range.push(IP._ipv4_to_str(ip));
if (endIp >= ip) {
for (; ip <= endIp; ip++) {
range.push(IP._ipv4ToStr(ip));
}
} else {
range[0] = "Second IP address smaller than first.";

View file

@ -44,19 +44,19 @@ var JS = {
* @param {Object[]} args
* @returns {string}
*/
run_parse: function (input, args) {
var parse_loc = args[0],
parse_range = args[1],
parse_tokens = args[2],
parse_comment = args[3],
parse_tolerant = args[4],
runParse: function (input, args) {
var parseLoc = args[0],
parseRange = args[1],
parseTokens = args[2],
parseComment = args[3],
parseTolerant = args[4],
result = {},
options = {
loc: parse_loc,
range: parse_range,
tokens: parse_tokens,
comment: parse_comment,
tolerant: parse_tolerant
loc: parseLoc,
range: parseRange,
tokens: parseTokens,
comment: parseComment,
tolerant: parseTolerant
};
result = esprima.parse(input, options);
@ -92,11 +92,11 @@ var JS = {
* @param {Object[]} args
* @returns {string}
*/
run_beautify: function(input, args) {
var beautify_indent = args[0] || JS.BEAUTIFY_INDENT,
runBeautify: function(input, args) {
var beautifyIndent = args[0] || JS.BEAUTIFY_INDENT,
quotes = args[1].toLowerCase(),
beautify_semicolons = args[2],
beautify_comment = args[3],
beautifySemicolons = args[2],
beautifyComment = args[3],
result = "",
AST;
@ -110,12 +110,12 @@ var JS = {
var options = {
format: {
indent: {
style: beautify_indent
style: beautifyIndent
},
quotes: quotes,
semicolons: beautify_semicolons,
semicolons: beautifySemicolons,
},
comment: beautify_comment
comment: beautifyComment
};
if (options.comment)
@ -137,13 +137,13 @@ var JS = {
* @param {Object[]} args
* @returns {string}
*/
run_minify: function(input, args) {
runMinify: function(input, args) {
var result = "",
AST = esprima.parse(input),
optimised_AST = esmangle.optimize(AST, null),
mangled_AST = esmangle.mangle(optimised_AST);
optimisedAST = esmangle.optimize(AST, null),
mangledAST = esmangle.mangle(optimisedAST);
result = escodegen.generate(mangled_AST, {
result = escodegen.generate(mangledAST, {
format: {
renumber: true,
hexadecimal: true,

View file

@ -42,15 +42,15 @@ var MAC = {
* @param {Object[]} args
* @returns {string}
*/
run_format: function(input, args) {
runFormat: function(input, args) {
if (!input) return "";
var output_case = args[0],
no_delim = args[1],
dash_delim = args[2],
colon_delim = args[3],
cisco_style = args[4],
output_list = [],
var outputCase = args[0],
noDelim = args[1],
dashDelim = args[2],
colonDelim = args[3],
ciscoStyle = args[4],
outputList = [],
macs = input.toLowerCase().split(/[,\s\r\n]+/);
macs.forEach(function(mac) {
@ -59,30 +59,30 @@ var MAC = {
macColon = cleanMac.replace(/(.{2}(?=.))/g, "$1:"),
macCisco = cleanMac.replace(/(.{4}(?=.))/g, "$1.");
if (output_case === "Lower only") {
if (no_delim) output_list.push(cleanMac);
if (dash_delim) output_list.push(macHyphen);
if (colon_delim) output_list.push(macColon);
if (cisco_style) output_list.push(macCisco);
} else if (output_case === "Upper only") {
if (no_delim) output_list.push(cleanMac.toUpperCase());
if (dash_delim) output_list.push(macHyphen.toUpperCase());
if (colon_delim) output_list.push(macColon.toUpperCase());
if (cisco_style) output_list.push(macCisco.toUpperCase());
if (outputCase === "Lower only") {
if (noDelim) outputList.push(cleanMac);
if (dashDelim) outputList.push(macHyphen);
if (colonDelim) outputList.push(macColon);
if (ciscoStyle) outputList.push(macCisco);
} else if (outputCase === "Upper only") {
if (noDelim) outputList.push(cleanMac.toUpperCase());
if (dashDelim) outputList.push(macHyphen.toUpperCase());
if (colonDelim) outputList.push(macColon.toUpperCase());
if (ciscoStyle) outputList.push(macCisco.toUpperCase());
} else {
if (no_delim) output_list.push(cleanMac, cleanMac.toUpperCase());
if (dash_delim) output_list.push(macHyphen, macHyphen.toUpperCase());
if (colon_delim) output_list.push(macColon, macColon.toUpperCase());
if (cisco_style) output_list.push(macCisco, macCisco.toUpperCase());
if (noDelim) outputList.push(cleanMac, cleanMac.toUpperCase());
if (dashDelim) outputList.push(macHyphen, macHyphen.toUpperCase());
if (colonDelim) outputList.push(macColon, macColon.toUpperCase());
if (ciscoStyle) outputList.push(macCisco, macCisco.toUpperCase());
}
output_list.push(
outputList.push(
"" // Empty line to delimit groups
);
});
// Return the data as a string
return output_list.join("\n");
return outputList.join("\n");
},
};

View file

@ -16,7 +16,7 @@ var OS = {
* @param {Object[]} args
* @returns {string}
*/
run_parse_unix_perms: function(input, args) {
runParseUnixPerms: function(input, args) {
var perms = {
d : false, // directory
sl : false, // symbolic link
@ -158,12 +158,12 @@ var OS = {
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);
output += "Textual representation: " + OS._permsToStr(perms);
output += "\nOctal representation: " + OS._permsToOctal(perms);
// File type
if (textual) {
output += "\nFile type: " + OS._ft_from_perms(perms);
output += "\nFile type: " + OS._ftFromPerms(perms);
}
// setuid, setgid
@ -201,7 +201,7 @@ var OS = {
* @param {Object} perms
* @returns {string}
*/
_perms_to_str: function(perms) {
_permsToStr: function(perms) {
var str = "",
type = "-";
@ -262,7 +262,7 @@ var OS = {
* @param {Object} perms
* @returns {string}
*/
_perms_to_octal: function(perms) {
_permsToOctal: function(perms) {
var d = 0,
u = 0,
g = 0,
@ -295,7 +295,7 @@ var OS = {
* @param {Object} perms
* @returns {string}
*/
_ft_from_perms: function(perms) {
_ftFromPerms: function(perms) {
if (perms.d) return "Directory";
if (perms.sl) return "Symbolic link";
if (perms.np) return "Named pipe";

View file

@ -24,15 +24,15 @@ var PublicKey = {
* @param {Object[]} args
* @returns {string}
*/
run_parse_x509: function (input, args) {
runParseX509: function (input, args) {
var cert = new X509(),
input_format = args[0];
inputFormat = args[0];
if (!input.length) {
return "No input";
}
switch (input_format) {
switch (inputFormat) {
case "DER Hex":
input = input.replace(/\s/g, "");
cert.hex = input;
@ -43,11 +43,11 @@ var PublicKey = {
cert.pem = input;
break;
case "Base64":
cert.hex = Utils.to_hex(Utils.from_base64(input, null, "byte_array"), "");
cert.hex = Utils.toHex(Utils.fromBase64(input, null, "byteArray"), "");
cert.pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(cert.hex, "CERTIFICATE");
break;
case "Raw":
cert.hex = Utils.to_hex(Utils.str_to_byte_array(input), "");
cert.hex = Utils.toHex(Utils.strToByteArray(input), "");
cert.pem = KJUR.asn1.ASN1Util.getPEMStringFromHex(cert.hex, "CERTIFICATE");
break;
default:
@ -58,108 +58,108 @@ var PublicKey = {
sn = cert.getSerialNumberHex(),
algorithm = KJUR.asn1.x509.OID.oid2name(KJUR.asn1.ASN1Util.oidHexToInt(ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [0, 2, 0]))),
issuer = cert.getIssuerString(),
not_before = cert.getNotBefore(),
not_after = cert.getNotAfter(),
notBefore = cert.getNotBefore(),
notAfter = cert.getNotAfter(),
subject = cert.getSubjectString(),
pk_algorithm = KJUR.asn1.x509.OID.oid2name(KJUR.asn1.ASN1Util.oidHexToInt(ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [0, 6, 0, 0]))),
pkAlgorithm = KJUR.asn1.x509.OID.oid2name(KJUR.asn1.ASN1Util.oidHexToInt(ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [0, 6, 0, 0]))),
pk = X509.getPublicKeyFromCertPEM(cert.pem),
pk_fields = [],
pk_str = "",
cert_sig_alg = KJUR.asn1.x509.OID.oid2name(KJUR.asn1.ASN1Util.oidHexToInt(ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [1, 0]))),
cert_sig = ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [2]).substr(2),
sig_str = "",
pkFields = [],
pkStr = "",
certSigAlg = KJUR.asn1.x509.OID.oid2name(KJUR.asn1.ASN1Util.oidHexToInt(ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [1, 0]))),
certSig = ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [2]).substr(2),
sigStr = "",
extensions = ASN1HEX.dump(ASN1HEX.getDecendantHexVByNthList(cert.hex, 0, [0, 7]));
// Public Key fields
if (pk.type === "EC") { // ECDSA
pk_fields.push({
pkFields.push({
key: "Curve Name",
value: pk.curveName
});
pk_fields.push({
pkFields.push({
key: "Length",
value: (((new BigInteger(pk.pubKeyHex, 16)).bitLength()-3) /2) + " bits"
});
pk_fields.push({
pkFields.push({
key: "pub",
value: PublicKey._format_byte_str(pk.pubKeyHex, 16, 18)
value: PublicKey._formatByteStr(pk.pubKeyHex, 16, 18)
});
} else if (pk.type === "DSA") { // DSA
pk_fields.push({
pkFields.push({
key: "pub",
value: PublicKey._format_byte_str(pk.y.toString(16), 16, 18)
value: PublicKey._formatByteStr(pk.y.toString(16), 16, 18)
});
pk_fields.push({
pkFields.push({
key: "P",
value: PublicKey._format_byte_str(pk.p.toString(16), 16, 18)
value: PublicKey._formatByteStr(pk.p.toString(16), 16, 18)
});
pk_fields.push({
pkFields.push({
key: "Q",
value: PublicKey._format_byte_str(pk.q.toString(16), 16, 18)
value: PublicKey._formatByteStr(pk.q.toString(16), 16, 18)
});
pk_fields.push({
pkFields.push({
key: "G",
value: PublicKey._format_byte_str(pk.g.toString(16), 16, 18)
value: PublicKey._formatByteStr(pk.g.toString(16), 16, 18)
});
} else if (pk.e) { // RSA
pk_fields.push({
pkFields.push({
key: "Length",
value: pk.n.bitLength() + " bits"
});
pk_fields.push({
pkFields.push({
key: "Modulus",
value: PublicKey._format_byte_str(pk.n.toString(16), 16, 18)
value: PublicKey._formatByteStr(pk.n.toString(16), 16, 18)
});
pk_fields.push({
pkFields.push({
key: "Exponent",
value: pk.e + " (0x" + pk.e.toString(16) + ")"
});
} else {
pk_fields.push({
pkFields.push({
key: "Error",
value: "Unknown Public Key type"
});
}
// Signature fields
if (ASN1HEX.dump(cert_sig).indexOf("SEQUENCE") === 0) { // DSA or ECDSA
sig_str = " r: " + PublicKey._format_byte_str(ASN1HEX.getDecendantHexVByNthList(cert_sig, 0, [0]), 16, 18) + "\n" +
" s: " + PublicKey._format_byte_str(ASN1HEX.getDecendantHexVByNthList(cert_sig, 0, [1]), 16, 18) + "\n";
if (ASN1HEX.dump(certSig).indexOf("SEQUENCE") === 0) { // DSA or ECDSA
sigStr = " r: " + PublicKey._formatByteStr(ASN1HEX.getDecendantHexVByNthList(certSig, 0, [0]), 16, 18) + "\n" +
" s: " + PublicKey._formatByteStr(ASN1HEX.getDecendantHexVByNthList(certSig, 0, [1]), 16, 18) + "\n";
} else { // RSA
sig_str = " Signature: " + PublicKey._format_byte_str(cert_sig, 16, 18) + "\n";
sigStr = " Signature: " + PublicKey._formatByteStr(certSig, 16, 18) + "\n";
}
// Format Public Key fields
for (var i = 0; i < pk_fields.length; i++) {
pk_str += " " + pk_fields[i].key + ":" +
Utils.pad_left(
pk_fields[i].value + "\n",
18 - (pk_fields[i].key.length + 3) + pk_fields[i].value.length + 1,
for (var i = 0; i < pkFields.length; i++) {
pkStr += " " + pkFields[i].key + ":" +
Utils.padLeft(
pkFields[i].value + "\n",
18 - (pkFields[i].key.length + 3) + pkFields[i].value.length + 1,
" "
);
}
var issuer_str = PublicKey._format_dn_str(issuer, 2),
nb_date = PublicKey._format_date(not_before),
na_date = PublicKey._format_date(not_after),
subject_str = PublicKey._format_dn_str(subject, 2);
var issuerStr = PublicKey._formatDnStr(issuer, 2),
nbDate = PublicKey._formatDate(notBefore),
naDate = PublicKey._formatDate(notAfter),
subjectStr = PublicKey._formatDnStr(subject, 2);
var output = "Version: " + (parseInt(version, 16) + 1) + " (0x" + version + ")\n" +
"Serial number: " + new BigInteger(sn, 16).toString() + " (0x" + sn + ")\n" +
"Algorithm ID: " + algorithm + "\n" +
"Validity\n" +
" Not Before: " + nb_date + " (dd-mm-yy hh:mm:ss) (" + not_before + ")\n" +
" Not After: " + na_date + " (dd-mm-yy hh:mm:ss) (" + not_after + ")\n" +
" Not Before: " + nbDate + " (dd-mm-yy hh:mm:ss) (" + notBefore + ")\n" +
" Not After: " + naDate + " (dd-mm-yy hh:mm:ss) (" + notAfter + ")\n" +
"Issuer\n" +
issuer_str +
issuerStr +
"Subject\n" +
subject_str +
subjectStr +
"Public Key\n" +
" Algorithm: " + pk_algorithm + "\n" +
pk_str +
" Algorithm: " + pkAlgorithm + "\n" +
pkStr +
"Certificate Signature\n" +
" Algorithm: " + cert_sig_alg + "\n" +
sig_str +
" Algorithm: " + certSigAlg + "\n" +
sigStr +
"\nExtensions (parsed ASN.1)\n" +
extensions;
@ -174,7 +174,7 @@ var PublicKey = {
* @param {Object[]} args
* @returns {string}
*/
run_pem_to_hex: function(input, args) {
runPemToHex: function(input, args) {
if (input.indexOf("-----BEGIN") < 0) {
// Add header so that the KEYUTIL function works
input = "-----BEGIN CERTIFICATE-----" + input;
@ -200,7 +200,7 @@ var PublicKey = {
* @param {Object[]} args
* @returns {string}
*/
run_hex_to_pem: function(input, args) {
runHexToPem: function(input, args) {
return KJUR.asn1.ASN1Util.getPEMStringFromHex(input.replace(/\s/g, ""), args[0]);
},
@ -212,7 +212,7 @@ var PublicKey = {
* @param {Object[]} args
* @returns {string}
*/
run_hex_to_object_identifier: function(input, args) {
runHexToObjectIdentifier: function(input, args) {
return KJUR.asn1.ASN1Util.oidHexToInt(input.replace(/\s/g, ""));
},
@ -224,7 +224,7 @@ var PublicKey = {
* @param {Object[]} args
* @returns {string}
*/
run_object_identifier_to_hex: function(input, args) {
runObjectIdentifierToHex: function(input, args) {
return KJUR.asn1.ASN1Util.oidIntToHex(input);
},
@ -242,11 +242,11 @@ var PublicKey = {
* @param {Object[]} args
* @returns {string}
*/
run_parse_asn1_hex_string: function(input, args) {
var truncate_len = args[1],
runParseAsn1HexString: function(input, args) {
var truncateLen = args[1],
index = args[0];
return ASN1HEX.dump(input.replace(/\s/g, ""), {
"ommit_long_octet": truncate_len
"ommitLongOctet": truncateLen
}, index);
},
@ -255,14 +255,14 @@ var PublicKey = {
* Formats Distinguished Name (DN) strings.
*
* @private
* @param {string} dn_str
* @param {string} dnStr
* @param {number} indent
* @returns {string}
*/
_format_dn_str: function(dn_str, indent) {
_formatDnStr: function(dnStr, indent) {
var output = "",
fields = dn_str.split(",/|"),
max_key_len = 0,
fields = dnStr.split(",/|"),
maxKeyLen = 0,
key,
value,
str;
@ -272,7 +272,7 @@ var PublicKey = {
key = fields[i].split("=")[0];
max_key_len = key.length > max_key_len ? key.length : max_key_len;
maxKeyLen = key.length > maxKeyLen ? key.length : maxKeyLen;
}
for (i = 0; i < fields.length; i++) {
@ -280,9 +280,9 @@ var PublicKey = {
key = fields[i].split("=")[0];
value = fields[i].split("=")[1];
str = Utils.pad_right(key, max_key_len) + " = " + value + "\n";
str = Utils.padRight(key, maxKeyLen) + " = " + value + "\n";
output += Utils.pad_left(str, indent + str.length, " ");
output += Utils.padLeft(str, indent + str.length, " ");
}
return output;
@ -293,22 +293,22 @@ var PublicKey = {
* Formats byte strings by adding line breaks and delimiters.
*
* @private
* @param {string} byte_str
* @param {string} byteStr
* @param {number} length - Line width
* @param {number} indent
* @returns {string}
*/
_format_byte_str: function(byte_str, length, indent) {
byte_str = Utils.to_hex(Utils.from_hex(byte_str), ":");
_formatByteStr: function(byteStr, length, indent) {
byteStr = Utils.toHex(Utils.fromHex(byteStr), ":");
length = length * 3;
var output = "";
for (var i = 0; i < byte_str.length; i += length) {
var str = byte_str.slice(i, i + length) + "\n";
for (var i = 0; i < byteStr.length; i += length) {
var str = byteStr.slice(i, i + length) + "\n";
if (i === 0) {
output += str;
} else {
output += Utils.pad_left(str, indent + str.length, " ");
output += Utils.padLeft(str, indent + str.length, " ");
}
}
@ -320,16 +320,16 @@ var PublicKey = {
* Formats dates.
*
* @private
* @param {string} date_str
* @param {string} dateStr
* @returns {string}
*/
_format_date: function(date_str) {
return date_str[4] + date_str[5] + "/" +
date_str[2] + date_str[3] + "/" +
date_str[0] + date_str[1] + " " +
date_str[6] + date_str[7] + ":" +
date_str[8] + date_str[9] + ":" +
date_str[10] + date_str[11];
_formatDate: function(dateStr) {
return dateStr[4] + dateStr[5] + "/" +
dateStr[2] + dateStr[3] + "/" +
dateStr[0] + dateStr[1] + " " +
dateStr[6] + dateStr[7] + ":" +
dateStr[8] + dateStr[9] + ":" +
dateStr[10] + dateStr[11];
},
};
@ -388,9 +388,9 @@ X509.DN_ATTRHEX = {
// "06032a864886f70d010104" : "md5withRSAEncryption",
// "06032a864886f70d010105" : "SHA-1WithRSAEncryption",
// "06032a8648ce380403" : "id-dsa-with-sha-1",
// "06032b06010505070302" : "id_kp_clientAuth",
// "06032b06010505070304" : "id_kp_securityemail",
"06032b06010505070201" : "id_certificatePolicies",
// "06032b06010505070302" : "idKpClientAuth",
// "06032b06010505070304" : "idKpSecurityemail",
"06032b06010505070201" : "idCertificatePolicies",
"06036086480186f8420101" : "netscape-cert-type",
"06036086480186f8420102" : "netscape-base-url",
"06036086480186f8420103" : "netscape-revocation-url",
@ -867,25 +867,25 @@ X509.DN_ATTRHEX = {
"06036086480186f8450107010101" : "Unknown Verisign policy qualifier",
"06036086480186f8450107010102" : "Unknown Verisign policy qualifier",
"0603678105" : "TCPA",
"060367810501" : "tcpa_specVersion",
"060367810502" : "tcpa_attribute",
"06036781050201" : "tcpa_at_tpmManufacturer",
"0603678105020a" : "tcpa_at_securityQualities",
"0603678105020b" : "tcpa_at_tpmProtectionProfile",
"0603678105020c" : "tcpa_at_tpmSecurityTarget",
"0603678105020d" : "tcpa_at_foundationProtectionProfile",
"0603678105020e" : "tcpa_at_foundationSecurityTarget",
"0603678105020f" : "tcpa_at_tpmIdLabel",
"06036781050202" : "tcpa_at_tpmModel",
"06036781050203" : "tcpa_at_tpmVersion",
"06036781050204" : "tcpa_at_platformManufacturer",
"06036781050205" : "tcpa_at_platformModel",
"06036781050206" : "tcpa_at_platformVersion",
"06036781050207" : "tcpa_at_componentManufacturer",
"06036781050208" : "tcpa_at_componentModel",
"06036781050209" : "tcpa_at_componentVersion",
"060367810503" : "tcpa_protocol",
"06036781050301" : "tcpa_prtt_tpmIdProtocol",
"060367810501" : "tcpaSpecVersion",
"060367810502" : "tcpaAttribute",
"06036781050201" : "tcpaAtTpmManufacturer",
"0603678105020a" : "tcpaAtSecurityQualities",
"0603678105020b" : "tcpaAtTpmProtectionProfile",
"0603678105020c" : "tcpaAtTpmSecurityTarget",
"0603678105020d" : "tcpaAtFoundationProtectionProfile",
"0603678105020e" : "tcpaAtFoundationSecurityTarget",
"0603678105020f" : "tcpaAtTpmIdLabel",
"06036781050202" : "tcpaAtTpmModel",
"06036781050203" : "tcpaAtTpmVersion",
"06036781050204" : "tcpaAtPlatformManufacturer",
"06036781050205" : "tcpaAtPlatformModel",
"06036781050206" : "tcpaAtPlatformVersion",
"06036781050207" : "tcpaAtComponentManufacturer",
"06036781050208" : "tcpaAtComponentModel",
"06036781050209" : "tcpaAtComponentVersion",
"060367810503" : "tcpaProtocol",
"06036781050301" : "tcpaPrttTpmIdProtocol",
"0603672a00" : "contentType",
"0603672a0000" : "PANData",
"0603672a0001" : "PANToken",

View file

@ -24,7 +24,7 @@ var Punycode = {
* @param {Object[]} args
* @returns {string}
*/
run_to_ascii: function(input, args) {
runToAscii: function(input, args) {
var idn = args[0];
if (idn) {
@ -42,7 +42,7 @@ var Punycode = {
* @param {Object[]} args
* @returns {string}
*/
run_to_unicode: function(input, args) {
runToUnicode: function(input, args) {
var idn = args[0];
if (idn) {

View file

@ -35,11 +35,11 @@ var QuotedPrintable = {
/**
* To Quoted Printable operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {string}
*/
run_to: function (input, args) {
runTo: function (input, args) {
var mimeEncodedStr = QuotedPrintable.mimeEncode(input);
// fix line breaks
@ -58,9 +58,9 @@ var QuotedPrintable = {
*
* @param {string} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_from: function (input, args) {
runFrom: function (input, args) {
var str = input.replace(/\=(?:\r?\n|$)/g, "");
return QuotedPrintable.mimeDecode(str);
},
@ -70,7 +70,7 @@ var QuotedPrintable = {
* Decodes mime-encoded data.
*
* @param {string} str
* @returns {byte_array}
* @returns {byteArray}
*/
mimeDecode: function(str) {
var encodedBytesCount = (str.match(/\=[\da-fA-F]{2}/g) || []).length,
@ -96,7 +96,7 @@ var QuotedPrintable = {
/**
* Encodes mime data.
*
* @param {byte_array} buffer
* @param {byteArray} buffer
* @returns {string}
*/
mimeEncode: function(buffer) {
@ -130,7 +130,7 @@ var QuotedPrintable = {
*
* @private
* @param {number} nr
* @param {byte_array[]} ranges
* @param {byteArray[]} ranges
* @returns {bolean}
*/
_checkRanges: function(nr, ranges) {

View file

@ -26,10 +26,10 @@ var Rotate = {
* Runs rotation operations across the input data.
*
* @private
* @param {byte_array} data
* @param {byteArray} data
* @param {number} amount
* @param {function} algo - The rotation operation to carry out
* @returns {byte_array}
* @returns {byteArray}
*/
_rot: function(data, amount, algo) {
var result = [];
@ -47,13 +47,13 @@ var Rotate = {
/**
* Rotate right operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_rotr: function(input, args) {
runRotr: function(input, args) {
if (args[1]) {
return Rotate._rotr_whole(input, args[0]);
return Rotate._rotrWhole(input, args[0]);
} else {
return Rotate._rot(input, args[0], Rotate._rotr);
}
@ -63,13 +63,13 @@ var Rotate = {
/**
* Rotate left operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_rotl: function(input, args) {
runRotl: function(input, args) {
if (args[1]) {
return Rotate._rotl_whole(input, args[0]);
return Rotate._rotlWhole(input, args[0]);
} else {
return Rotate._rot(input, args[0], Rotate._rotl);
}
@ -95,16 +95,16 @@ var Rotate = {
/**
* ROT13 operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_rot13: function(input, args) {
runRot13: function(input, args) {
var amount = args[2],
output = input,
chr,
rot13_lowercase = args[0],
rot13_upperacse = args[1];
rot13Lowercase = args[0],
rot13Upperacse = args[1];
if (amount) {
if (amount < 0) {
@ -113,10 +113,10 @@ var Rotate = {
for (var i = 0; i < input.length; i++) {
chr = input[i];
if (rot13_upperacse && chr >= 65 && chr <= 90) { // Upper case
if (rot13Upperacse && chr >= 65 && chr <= 90) { // Upper case
chr = (chr - 65 + amount) % 26;
output[i] = chr + 65;
} else if (rot13_lowercase && chr >= 97 && chr <= 122) { // Lower case
} else if (rot13Lowercase && chr >= 97 && chr <= 122) { // Lower case
chr = (chr - 97 + amount) % 26;
output[i] = chr + 97;
}
@ -136,11 +136,11 @@ var Rotate = {
* ROT47 operation.
*
* @author Matt C [matt@artemisbot.pw]
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_rot47: function(input, args) {
runRot47: function(input, args) {
var amount = args[0],
output = input,
chr;
@ -193,23 +193,23 @@ var Rotate = {
* from the end of the array to the beginning.
*
* @private
* @param {byte_array} data
* @param {byteArray} data
* @param {number} amount
* @returns {byte_array}
* @returns {byteArray}
*/
_rotr_whole: function(data, amount) {
var carry_bits = 0,
new_byte,
_rotrWhole: function(data, amount) {
var carryBits = 0,
newByte,
result = [];
amount = amount % 8;
for (var i = 0; i < data.length; i++) {
var old_byte = data[i] >>> 0;
new_byte = (old_byte >> amount) | carry_bits;
carry_bits = (old_byte & (Math.pow(2, amount)-1)) << (8-amount);
result.push(new_byte);
var oldByte = data[i] >>> 0;
newByte = (oldByte >> amount) | carryBits;
carryBits = (oldByte & (Math.pow(2, amount)-1)) << (8-amount);
result.push(newByte);
}
result[0] |= carry_bits;
result[0] |= carryBits;
return result;
},
@ -219,23 +219,23 @@ var Rotate = {
* from the beginning of the array to the end.
*
* @private
* @param {byte_array} data
* @param {byteArray} data
* @param {number} amount
* @returns {byte_array}
* @returns {byteArray}
*/
_rotl_whole: function(data, amount) {
var carry_bits = 0,
new_byte,
_rotlWhole: function(data, amount) {
var carryBits = 0,
newByte,
result = [];
amount = amount % 8;
for (var i = data.length-1; i >= 0; i--) {
var old_byte = data[i];
new_byte = ((old_byte << amount) | carry_bits) & 0xFF;
carry_bits = (old_byte >> (8-amount)) & (Math.pow(2, amount)-1);
result[i] = (new_byte);
var oldByte = data[i];
newByte = ((oldByte << amount) | carryBits) & 0xFF;
carryBits = (oldByte >> (8-amount)) & (Math.pow(2, amount)-1);
result[i] = (newByte);
}
result[data.length-1] = result[data.length-1] | carry_bits;
result[data.length-1] = result[data.length-1] | carryBits;
return result;
},

View file

@ -32,21 +32,21 @@ var SeqUtils = {
* @param {Object[]} args
* @returns {string}
*/
run_sort: function (input, args) {
var delim = Utils.char_rep[args[0]],
sort_reverse = args[1],
runSort: function (input, args) {
var delim = Utils.charRep[args[0]],
sortReverse = args[1],
order = args[2],
sorted = input.split(delim);
if (order === "Alphabetical (case sensitive)") {
sorted = sorted.sort();
} else if (order === "Alphabetical (case insensitive)") {
sorted = sorted.sort(SeqUtils._case_insensitive_sort);
sorted = sorted.sort(SeqUtils._caseInsensitiveSort);
} else if (order === "IP address") {
sorted = sorted.sort(SeqUtils._ip_sort);
sorted = sorted.sort(SeqUtils._ipSort);
}
if (sort_reverse) sorted.reverse();
if (sortReverse) sorted.reverse();
return sorted.join(delim);
},
@ -58,8 +58,8 @@ var SeqUtils = {
* @param {Object[]} args
* @returns {string}
*/
run_unique: function (input, args) {
var delim = Utils.char_rep[args[0]];
runUnique: function (input, args) {
var delim = Utils.charRep[args[0]];
return input.split(delim).unique().join(delim);
},
@ -77,7 +77,7 @@ var SeqUtils = {
* @param {Object[]} args
* @returns {number}
*/
run_count: function(input, args) {
runCount: function(input, args) {
var search = args[0].string,
type = args[0].option;
@ -91,7 +91,7 @@ var SeqUtils = {
}
} else if (search) {
if (type.indexOf("Extended") === 0) {
search = Utils.parse_escaped_chars(search);
search = Utils.parseEscapedChars(search);
}
return input.count(search);
} else {
@ -109,11 +109,11 @@ var SeqUtils = {
/**
* Reverse operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_reverse: function (input, args) {
runReverse: function (input, args) {
if (args[0] === "Line") {
var lines = [],
line = [],
@ -146,7 +146,7 @@ var SeqUtils = {
* @param {Object[]} args
* @returns {string}
*/
run_add_line_numbers: function(input, args) {
runAddLineNumbers: function(input, args) {
var lines = input.split("\n"),
output = "",
width = lines.length.toString().length;
@ -165,7 +165,7 @@ var SeqUtils = {
* @param {Object[]} args
* @returns {string}
*/
run_remove_line_numbers: function(input, args) {
runRemoveLineNumbers: function(input, args) {
return input.replace(/^[ \t]{0,5}\d+[\s:|\-,.)\]]/gm, "");
},
@ -177,8 +177,8 @@ var SeqUtils = {
* @param {Object[]} args
* @returns {string}
*/
run_expand_alph_range: function(input, args) {
return Utils.expand_alph_range(input).join(args[0]);
runExpandAlphRange: function(input, args) {
return Utils.expandAlphRange(input).join(args[0]);
},
@ -190,7 +190,7 @@ var SeqUtils = {
* @param {string} b
* @returns {number}
*/
_case_insensitive_sort: function(a, b) {
_caseInsensitiveSort: function(a, b) {
return a.toLowerCase().localeCompare(b.toLowerCase());
},
@ -203,7 +203,7 @@ var SeqUtils = {
* @param {string} b
* @returns {number}
*/
_ip_sort: function(a, b) {
_ipSort: function(a, b) {
var a_ = a.split("."),
b_ = b.split(".");

View file

@ -97,30 +97,30 @@ var StrUtils = {
* @param {Object[]} args
* @returns {html}
*/
run_regex: function(input, args) {
var user_regex = args[1],
runRegex: function(input, args) {
var userRegex = args[1],
i = args[2],
m = args[3],
display_total = args[4],
output_format = args[5],
displayTotal = args[4],
outputFormat = args[5],
modifiers = "g";
if (i) modifiers += "i";
if (m) modifiers += "m";
if (user_regex && user_regex !== "^" && user_regex !== "$") {
if (userRegex && userRegex !== "^" && userRegex !== "$") {
try {
var regex = new RegExp(user_regex, modifiers);
var regex = new RegExp(userRegex, modifiers);
switch (output_format) {
switch (outputFormat) {
case "Highlight matches":
return StrUtils._regex_highlight(input, regex, display_total);
return StrUtils._regexHighlight(input, regex, displayTotal);
case "List matches":
return Utils.escape_html(StrUtils._regex_list(input, regex, display_total, true, false));
return Utils.escapeHtml(StrUtils._regexList(input, regex, displayTotal, true, false));
case "List capture groups":
return Utils.escape_html(StrUtils._regex_list(input, regex, display_total, false, true));
return Utils.escapeHtml(StrUtils._regexList(input, regex, displayTotal, false, true));
case "List matches with capture groups":
return Utils.escape_html(StrUtils._regex_list(input, regex, display_total, true, true));
return Utils.escapeHtml(StrUtils._regexList(input, regex, displayTotal, true, true));
default:
return "Error: Invalid output format";
}
@ -128,7 +128,7 @@ var StrUtils = {
return "Invalid regex. Details: " + err.message;
}
} else {
return Utils.escape_html(input);
return Utils.escapeHtml(input);
}
},
@ -146,7 +146,7 @@ var StrUtils = {
* @param {Object[]} args
* @returns {string}
*/
run_upper: function (input, args) {
runUpper: function (input, args) {
var scope = args[0];
switch (scope) {
@ -177,7 +177,7 @@ var StrUtils = {
* @param {Object[]} args
* @returns {string}
*/
run_lower: function (input, args) {
runLower: function (input, args) {
return input.toLowerCase();
},
@ -210,7 +210,7 @@ var StrUtils = {
* @param {Object[]} args
* @returns {string}
*/
run_find_replace: function(input, args) {
runFindReplace: function(input, args) {
var find = args[0].string,
type = args[0].option,
replace = args[1],
@ -226,7 +226,7 @@ var StrUtils = {
if (type === "Regex") {
find = new RegExp(find, modifiers);
} else if (type.indexOf("Extended") === 0) {
find = Utils.parse_escaped_chars(find);
find = Utils.parseEscapedChars(find);
}
return input.replace(find, replace, modifiers);
@ -254,12 +254,12 @@ var StrUtils = {
* @param {Object[]} args
* @returns {string}
*/
run_split: function(input, args) {
var split_delim = args[0] || StrUtils.SPLIT_DELIM,
join_delim = Utils.char_rep[args[1]],
sections = input.split(split_delim);
runSplit: function(input, args) {
var splitDelim = args[0] || StrUtils.SPLIT_DELIM,
joinDelim = Utils.charRep[args[1]],
sections = input.split(splitDelim);
return sections.join(join_delim);
return sections.join(joinDelim);
},
@ -271,8 +271,8 @@ var StrUtils = {
* @param {Object[]} args
* @returns {string}
*/
run_filter: function(input, args) {
var delim = Utils.char_rep[args[0]],
runFilter: function(input, args) {
var delim = Utils.charRep[args[0]],
reverse = args[2];
try {
@ -281,11 +281,11 @@ var StrUtils = {
return "Invalid regex. Details: " + err.message;
}
var regex_filter = function(value) {
var regexFilter = function(value) {
return reverse ^ regex.test(value);
};
return input.split(delim).filter(regex_filter).join(delim);
return input.split(delim).filter(regexFilter).join(delim);
},
@ -307,13 +307,13 @@ var StrUtils = {
* @param {Object[]} args
* @returns {html}
*/
run_diff: function(input, args) {
var sample_delim = args[0],
diff_by = args[1],
show_added = args[2],
show_removed = args[3],
ignore_whitespace = args[4],
samples = input.split(sample_delim),
runDiff: function(input, args) {
var sampleDelim = args[0],
diffBy = args[1],
showAdded = args[2],
showRemoved = args[3],
ignoreWhitespace = args[4],
samples = input.split(sampleDelim),
output = "",
diff;
@ -321,19 +321,19 @@ var StrUtils = {
return "Incorrect number of samples, perhaps you need to modify the sample delimiter or add more samples?";
}
switch (diff_by) {
switch (diffBy) {
case "Character":
diff = JsDiff.diffChars(samples[0], samples[1]);
break;
case "Word":
if (ignore_whitespace) {
if (ignoreWhitespace) {
diff = JsDiff.diffWords(samples[0], samples[1]);
} else {
diff = JsDiff.diffWordsWithSpace(samples[0], samples[1]);
}
break;
case "Line":
if (ignore_whitespace) {
if (ignoreWhitespace) {
diff = JsDiff.diffTrimmedLines(samples[0], samples[1]);
} else {
diff = JsDiff.diffLines(samples[0], samples[1]);
@ -354,11 +354,11 @@ var StrUtils = {
for (var i = 0; i < diff.length; i++) {
if (diff[i].added) {
if (show_added) output += "<span class='hlgreen'>" + Utils.escape_html(diff[i].value) + "</span>";
if (showAdded) output += "<span class='hlgreen'>" + Utils.escapeHtml(diff[i].value) + "</span>";
} else if (diff[i].removed) {
if (show_removed) output += "<span class='hlred'>" + Utils.escape_html(diff[i].value) + "</span>";
if (showRemoved) output += "<span class='hlred'>" + Utils.escapeHtml(diff[i].value) + "</span>";
} else {
output += Utils.escape_html(diff[i].value);
output += Utils.escapeHtml(diff[i].value);
}
}
@ -379,14 +379,14 @@ var StrUtils = {
* @param {Object[]} args
* @returns {html}
*/
run_offset_checker: function(input, args) {
var sample_delim = args[0],
samples = input.split(sample_delim),
runOffsetChecker: function(input, args) {
var sampleDelim = args[0],
samples = input.split(sampleDelim),
outputs = [],
i = 0,
s = 0,
match = false,
in_match = false,
inMatch = false,
chr;
if (!samples || samples.length < 2) {
@ -415,34 +415,34 @@ var StrUtils = {
// Write output for each sample
for (s = 0; s < samples.length; s++) {
if (samples[s].length <= i) {
if (in_match) outputs[s] += "</span>";
if (s === samples.length - 1) in_match = false;
if (inMatch) outputs[s] += "</span>";
if (s === samples.length - 1) inMatch = false;
continue;
}
if (match && !in_match) {
outputs[s] += "<span class='hlgreen'>" + Utils.escape_html(samples[s][i]);
if (match && !inMatch) {
outputs[s] += "<span class='hlgreen'>" + Utils.escapeHtml(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;
if (s === samples.length - 1) inMatch = true;
} else if (!match && inMatch) {
outputs[s] += "</span>" + Utils.escapeHtml(samples[s][i]);
if (s === samples.length - 1) inMatch = false;
} else {
outputs[s] += Utils.escape_html(samples[s][i]);
if (in_match && samples[s].length === i + 1) {
outputs[s] += Utils.escapeHtml(samples[s][i]);
if (inMatch && samples[s].length === i + 1) {
outputs[s] += "</span>";
if (samples[s].length - 1 !== i) in_match = false;
if (samples[s].length - 1 !== i) inMatch = false;
}
}
if (samples[0].length - 1 === i) {
if (in_match) outputs[s] += "</span>";
outputs[s] += Utils.escape_html(samples[s].substring(i + 1));
if (inMatch) outputs[s] += "</span>";
outputs[s] += Utils.escapeHtml(samples[s].substring(i + 1));
}
}
}
return outputs.join(sample_delim);
return outputs.join(sampleDelim);
},
@ -453,8 +453,8 @@ var StrUtils = {
* @param {Object[]} args
* @returns {string}
*/
run_parse_escaped_string: function(input, args) {
return Utils.parse_escaped_chars(input);
runParseEscapedString: function(input, args) {
return Utils.parseEscapedChars(input);
},
@ -464,10 +464,10 @@ var StrUtils = {
* @private
* @param {string} input
* @param {RegExp} regex
* @param {boolean} display_total
* @param {boolean} displayTotal
* @returns {string}
*/
_regex_highlight: function(input, regex, display_total) {
_regexHighlight: function(input, regex, displayTotal) {
var output = "",
m,
hl = 1,
@ -476,10 +476,10 @@ var StrUtils = {
while ((m = regex.exec(input))) {
// Add up to match
output += Utils.escape_html(input.slice(i, m.index));
output += Utils.escapeHtml(input.slice(i, m.index));
// Add match with highlighting
output += "<span class='hl"+hl+"'>" + Utils.escape_html(m[0]) + "</span>";
output += "<span class='hl"+hl+"'>" + Utils.escapeHtml(m[0]) + "</span>";
// Switch highlight
hl = hl === 1 ? 2 : 1;
@ -489,9 +489,9 @@ var StrUtils = {
}
// Add all after final match
output += Utils.escape_html(input.slice(i, input.length));
output += Utils.escapeHtml(input.slice(i, input.length));
if (display_total)
if (displayTotal)
output = "Total found: " + total + "\n\n" + output;
return output;
@ -504,12 +504,12 @@ var StrUtils = {
* @private
* @param {string} input
* @param {RegExp} regex
* @param {boolean} display_total
* @param {boolean} displayTotal
* @param {boolean} matches - Display full match
* @param {boolean} capture_groups - Display each of the capture groups separately
* @param {boolean} captureGroups - Display each of the capture groups separately
* @returns {string}
*/
_regex_list: function(input, regex, display_total, matches, capture_groups) {
_regexList: function(input, regex, displayTotal, matches, captureGroups) {
var output = "",
total = 0,
match;
@ -519,7 +519,7 @@ var StrUtils = {
if (matches) {
output += match[0] + "\n";
}
if (capture_groups) {
if (captureGroups) {
for (var i = 1; i < match.length; i++) {
if (matches) {
output += " Group " + i + ": ";
@ -529,7 +529,7 @@ var StrUtils = {
}
}
if (display_total)
if (displayTotal)
output = "Total found: " + total + "\n\n" + output;
return output;

View file

@ -47,21 +47,21 @@ var Tidy = {
* @param {Object[]} args
* @returns {string}
*/
run_remove_whitespace: function (input, args) {
var remove_spaces = args[0],
remove_cariage_returns = args[1],
remove_line_feeds = args[2],
remove_tabs = args[3],
remove_form_feeds = args[4],
remove_full_stops = args[5],
runRemoveWhitespace: function (input, args) {
var removeSpaces = args[0],
removeCariageReturns = args[1],
removeLineFeeds = args[2],
removeTabs = args[3],
removeFormFeeds = args[4],
removeFullStops = args[5],
data = input;
if (remove_spaces) data = data.replace(/ /g, "");
if (remove_cariage_returns) data = data.replace(/\r/g, "");
if (remove_line_feeds) data = data.replace(/\n/g, "");
if (remove_tabs) data = data.replace(/\t/g, "");
if (remove_form_feeds) data = data.replace(/\f/g, "");
if (remove_full_stops) data = data.replace(/\./g, "");
if (removeSpaces) data = data.replace(/ /g, "");
if (removeCariageReturns) data = data.replace(/\r/g, "");
if (removeLineFeeds) data = data.replace(/\n/g, "");
if (removeTabs) data = data.replace(/\t/g, "");
if (removeFormFeeds) data = data.replace(/\f/g, "");
if (removeFullStops) data = data.replace(/\./g, "");
return data;
},
@ -69,11 +69,11 @@ var Tidy = {
/**
* Remove null bytes operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_remove_nulls: function (input, args) {
runRemoveNulls: function (input, args) {
var output = [];
for (var i = 0; i < input.length; i++) {
if (input[i] !== 0) output.push(input[i]);
@ -101,19 +101,19 @@ var Tidy = {
/**
* Drop bytes operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_drop_bytes: function(input, args) {
runDropBytes: function(input, args) {
var start = args[0],
length = args[1],
apply_to_each_line = args[2];
applyToEachLine = args[2];
if (start < 0 || length < 0)
throw "Error: Invalid value";
if (!apply_to_each_line)
if (!applyToEachLine)
return input.slice(0, start).concat(input.slice(start+length, input.length));
// Split input into lines
@ -153,19 +153,19 @@ var Tidy = {
/**
* Take bytes operation.
*
* @param {byte_array} input
* @param {byteArray} input
* @param {Object[]} args
* @returns {byte_array}
* @returns {byteArray}
*/
run_take_bytes: function(input, args) {
runTakeBytes: function(input, args) {
var start = args[0],
length = args[1],
apply_to_each_line = args[2];
applyToEachLine = args[2];
if (start < 0 || length < 0)
throw "Error: Invalid value";
if (!apply_to_each_line)
if (!applyToEachLine)
return input.slice(start, start+length);
// Split input into lines
@ -214,7 +214,7 @@ var Tidy = {
* @param {Object[]} args
* @returns {string}
*/
run_pad: function(input, args) {
runPad: function(input, args) {
var position = args[0],
len = args[1],
chr = args[2],
@ -224,11 +224,11 @@ var Tidy = {
if (position === "Start") {
for (i = 0; i < lines.length; i++) {
output += Utils.pad_left(lines[i], lines[i].length+len, chr) + "\n";
output += Utils.padLeft(lines[i], lines[i].length+len, chr) + "\n";
}
} else if (position === "End") {
for (i = 0; i < lines.length; i++) {
output += Utils.pad_right(lines[i], lines[i].length+len, chr) + "\n";
output += Utils.padRight(lines[i], lines[i].length+len, chr) + "\n";
}
}

View file

@ -25,9 +25,9 @@ var URL_ = {
* @param {Object[]} args
* @returns {string}
*/
run_to: function(input, args) {
var encode_all = args[0];
return encode_all ? URL_._encode_all_chars(input) : encodeURI(input);
runTo: function(input, args) {
var encodeAll = args[0];
return encodeAll ? URL_._encodeAllChars(input) : encodeURI(input);
},
@ -38,7 +38,7 @@ var URL_ = {
* @param {Object[]} args
* @returns {string}
*/
run_from: function(input, args) {
runFrom: function(input, args) {
var data = input.replace(/\+/g, "%20");
try {
return decodeURIComponent(data);
@ -55,7 +55,7 @@ var URL_ = {
* @param {Object[]} args
* @returns {string}
*/
run_parse: function(input, args) {
runParse: function(input, args) {
var a = document.createElement("a");
// Overwrite base href which will be the current CyberChef URL to reduce confusion.
@ -85,15 +85,15 @@ var URL_ = {
if (a.search && a.search !== window.location.search) {
output += "Arguments:\n";
var args_ = (a.search.slice(1, a.search.length)).split("&");
var split_args = [], padding = 0;
var splitArgs = [], 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;
splitArgs.push(args_[i].split("="));
padding = (splitArgs[i][0].length > padding) ? splitArgs[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";
for (i = 0; i < splitArgs.length; i++) {
output += "\t" + Utils.padRight(splitArgs[i][0], padding);
if (splitArgs[i].length > 1 && splitArgs[i][1].length)
output += " = " + splitArgs[i][1] + "\n";
else output += "\n";
}
}
@ -112,7 +112,7 @@ var URL_ = {
* @param {string} str
* @returns {string}
*/
_encode_all_chars: function(str) {
_encodeAllChars: function(str) {
//TODO Do this programatically
return encodeURIComponent(str)
.replace(/!/g, "%21")

View file

@ -16,7 +16,7 @@ var UUID = {
* @param {Object[]} args
* @returns {string}
*/
run_generate_v4: function(input, args) {
runGenerateV4: function(input, args) {
if (typeof(window.crypto) !== "undefined" && typeof(window.crypto.getRandomValues) !== "undefined") {
var buf = new Uint32Array(4),
i = 0;

View file

@ -22,8 +22,8 @@ var Unicode = {
* @param {Object[]} args
* @returns {string}
*/
run_unescape: function(input, args) {
var prefix = Unicode._prefix_to_regex[args[0]],
runUnescape: function(input, args) {
var prefix = Unicode._prefixToRegex[args[0]],
regex = new RegExp(prefix+"([a-f\\d]{4,6})", "ig"),
output = "",
m,
@ -53,7 +53,7 @@ var Unicode = {
* @private
* @constant
*/
_prefix_to_regex: {
_prefixToRegex: {
"\\u": "\\\\u",
"%u": "%u",
"U+": "U\\+"