mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-22 15:56:16 -04:00
Merge branch 'master' of https://github.com/gchq/CyberChef into feature/advanced-entropy
This commit is contained in:
commit
802493fec4
20 changed files with 1130 additions and 443 deletions
46
src/core/operations/ProtobufDecode.mjs
Normal file
46
src/core/operations/ProtobufDecode.mjs
Normal file
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* @author GCHQ Contributor [3]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import OperationError from "../errors/OperationError";
|
||||
import Protobuf from "../lib/Protobuf";
|
||||
|
||||
/**
|
||||
* Protobuf Decode operation
|
||||
*/
|
||||
class ProtobufDecode extends Operation {
|
||||
|
||||
/**
|
||||
* ProtobufDecode constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "Protobuf Decode";
|
||||
this.module = "Default";
|
||||
this.description = "Decodes any Protobuf encoded data to a JSON representation of the data using the field number as the field key.";
|
||||
this.infoURL = "https://wikipedia.org/wiki/Protocol_Buffers";
|
||||
this.inputType = "byteArray";
|
||||
this.outputType = "JSON";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {byteArray} input
|
||||
* @param {Object[]} args
|
||||
* @returns {JSON}
|
||||
*/
|
||||
run(input, args) {
|
||||
try {
|
||||
return Protobuf.decode(input);
|
||||
} catch (err) {
|
||||
throw new OperationError(err);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default ProtobufDecode;
|
|
@ -230,6 +230,7 @@ function regexHighlight (input, regex, displayTotal) {
|
|||
title = "",
|
||||
hl = 1,
|
||||
total = 0;
|
||||
const captureGroups = [];
|
||||
|
||||
output = input.replace(regex, (match, ...args) => {
|
||||
args.pop(); // Throw away full string
|
||||
|
@ -247,9 +248,15 @@ function regexHighlight (input, regex, displayTotal) {
|
|||
// Switch highlight
|
||||
hl = hl === 1 ? 2 : 1;
|
||||
|
||||
total++;
|
||||
// Store highlighted match and replace with a placeholder
|
||||
captureGroups.push(`<span class='hl${hl}' title='${title}'>${Utils.escapeHtml(match)}</span>`);
|
||||
return `[cc_capture_group_${total++}]`;
|
||||
});
|
||||
|
||||
return `<span class='hl${hl}' title='${title}'>${Utils.escapeHtml(match)}</span>`;
|
||||
// Safely escape all remaining text, then replace placeholders
|
||||
output = Utils.escapeHtml(output);
|
||||
output = output.replace(/\[cc_capture_group_(\d+)\]/g, (_, i) => {
|
||||
return captureGroups[i];
|
||||
});
|
||||
|
||||
if (displayTotal)
|
||||
|
|
|
@ -79,7 +79,7 @@ class TextEncodingBruteForce extends Operation {
|
|||
let table = "<table class='table table-hover table-sm table-bordered table-nonfluid'><tr><th>Encoding</th><th>Value</th></tr>";
|
||||
|
||||
for (const enc in encodings) {
|
||||
const value = Utils.printable(encodings[enc], true);
|
||||
const value = Utils.escapeHtml(Utils.printable(encodings[enc], true));
|
||||
table += `<tr><td>${enc}</td><td>${value}</td></tr>`;
|
||||
}
|
||||
|
||||
|
|
46
src/core/operations/VarIntDecode.mjs
Normal file
46
src/core/operations/VarIntDecode.mjs
Normal file
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* @author GCHQ Contributor [3]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import OperationError from "../errors/OperationError";
|
||||
import Protobuf from "../lib/Protobuf";
|
||||
|
||||
/**
|
||||
* VarInt Decode operation
|
||||
*/
|
||||
class VarIntDecode extends Operation {
|
||||
|
||||
/**
|
||||
* VarIntDecode constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "VarInt Decode";
|
||||
this.module = "Default";
|
||||
this.description = "Decodes a VarInt encoded integer. VarInt is an efficient way of encoding variable length integers and is commonly used with Protobuf.";
|
||||
this.infoURL = "https://developers.google.com/protocol-buffers/docs/encoding#varints";
|
||||
this.inputType = "byteArray";
|
||||
this.outputType = "number";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {byteArray} input
|
||||
* @param {Object[]} args
|
||||
* @returns {number}
|
||||
*/
|
||||
run(input, args) {
|
||||
try {
|
||||
return Protobuf.varIntDecode(input);
|
||||
} catch (err) {
|
||||
throw new OperationError(err);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default VarIntDecode;
|
46
src/core/operations/VarIntEncode.mjs
Normal file
46
src/core/operations/VarIntEncode.mjs
Normal file
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* @author GCHQ Contributor [3]
|
||||
* @copyright Crown Copyright 2019
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import OperationError from "../errors/OperationError";
|
||||
import Protobuf from "../lib/Protobuf";
|
||||
|
||||
/**
|
||||
* VarInt Encode operation
|
||||
*/
|
||||
class VarIntEncode extends Operation {
|
||||
|
||||
/**
|
||||
* VarIntEncode constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "VarInt Encode";
|
||||
this.module = "Default";
|
||||
this.description = "Encodes a Vn integer as a VarInt. VarInt is an efficient way of encoding variable length integers and is commonly used with Protobuf.";
|
||||
this.infoURL = "https://developers.google.com/protocol-buffers/docs/encoding#varints";
|
||||
this.inputType = "number";
|
||||
this.outputType = "byteArray";
|
||||
this.args = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} input
|
||||
* @param {Object[]} args
|
||||
* @returns {byteArray}
|
||||
*/
|
||||
run(input, args) {
|
||||
try {
|
||||
return Protobuf.varIntEncode(input);
|
||||
} catch (err) {
|
||||
throw new OperationError(err);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default VarIntEncode;
|
Loading…
Add table
Add a link
Reference in a new issue