mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-21 23:36:16 -04:00
Remove tickbox and make 0x comma an option
This commit is contained in:
parent
9a3464a5ec
commit
293a95e938
2 changed files with 36 additions and 30 deletions
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import Operation from "../Operation.mjs";
|
import Operation from "../Operation.mjs";
|
||||||
import {toHex, TO_HEX_DELIM_OPTIONS} from "../lib/Hex.mjs";
|
import {toHex} from "../lib/Hex.mjs";
|
||||||
import Utils from "../Utils.mjs";
|
import Utils from "../Utils.mjs";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,17 +29,12 @@ class ToHex extends Operation {
|
||||||
{
|
{
|
||||||
name: "Delimiter",
|
name: "Delimiter",
|
||||||
type: "option",
|
type: "option",
|
||||||
value: TO_HEX_DELIM_OPTIONS
|
value: ["Space", "Percent", "Comma", "Semi-colon", "Colon", "Line feed", "CRLF", "0x", "0x with comma", "\\x", "None"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Bytes per line",
|
name: "Bytes per line",
|
||||||
type: "number",
|
type: "number",
|
||||||
value: 0
|
value: 0
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Comma separated",
|
|
||||||
type: "boolean",
|
|
||||||
value: false
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -50,9 +45,14 @@ class ToHex extends Operation {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const delim = Utils.charRep(args[0] || "Space");
|
let delim, comma;
|
||||||
|
if (args[0] === "0x with comma") {
|
||||||
|
delim = "0x";
|
||||||
|
comma = ",";
|
||||||
|
} else {
|
||||||
|
delim = Utils.charRep(args[0] || "Space");
|
||||||
|
}
|
||||||
const lineSize = args[1];
|
const lineSize = args[1];
|
||||||
const comma = args[2] ? "," : "";
|
|
||||||
|
|
||||||
return toHex(new Uint8Array(input), delim, 2, comma, lineSize);
|
return toHex(new Uint8Array(input), delim, 2, comma, lineSize);
|
||||||
}
|
}
|
||||||
|
@ -67,10 +67,16 @@ class ToHex extends Operation {
|
||||||
* @returns {Object[]} pos
|
* @returns {Object[]} pos
|
||||||
*/
|
*/
|
||||||
highlight(pos, args) {
|
highlight(pos, args) {
|
||||||
const delim = Utils.charRep(args[0] || "Space"),
|
let delim, commaLen;
|
||||||
lineSize = args[1],
|
if (args[0] === "0x with comma") {
|
||||||
comma = args[2],
|
delim = "0x";
|
||||||
len = (delim === "\r\n" ? 1 : delim.length) + (comma ? 1 : 0);
|
commaLen = 1;
|
||||||
|
} else {
|
||||||
|
delim = Utils.charRep(args[0] || "Space");
|
||||||
|
}
|
||||||
|
|
||||||
|
const lineSize = args[1],
|
||||||
|
len = (delim === "\r\n" ? 1 : delim.length) + commaLen;
|
||||||
|
|
||||||
const countLF = function(p) {
|
const countLF = function(p) {
|
||||||
// Count the number of LFs from 0 upto p
|
// Count the number of LFs from 0 upto p
|
||||||
|
@ -85,9 +91,7 @@ class ToHex extends Operation {
|
||||||
pos[0].end -= delim.length;
|
pos[0].end -= delim.length;
|
||||||
}
|
}
|
||||||
// if there is comma, trim the trailing comma
|
// if there is comma, trim the trailing comma
|
||||||
if (comma) {
|
pos[0].end -= commaLen;
|
||||||
pos[0].end--;
|
|
||||||
}
|
|
||||||
return pos;
|
return pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,10 +105,16 @@ class ToHex extends Operation {
|
||||||
* @returns {Object[]} pos
|
* @returns {Object[]} pos
|
||||||
*/
|
*/
|
||||||
highlightReverse(pos, args) {
|
highlightReverse(pos, args) {
|
||||||
const delim = Utils.charRep(args[0] || "Space"),
|
let delim, commaLen;
|
||||||
lineSize = args[1],
|
if (args[0] === "0x with comma") {
|
||||||
comma = args[2],
|
delim = "0x";
|
||||||
len = (delim === "\r\n" ? 1 : delim.length) + (comma ? 1 : 0),
|
commaLen = 1;
|
||||||
|
} else {
|
||||||
|
delim = Utils.charRep(args[0] || "Space");
|
||||||
|
}
|
||||||
|
|
||||||
|
const lineSize = args[1],
|
||||||
|
len = (delim === "\r\n" ? 1 : delim.length) + commaLen,
|
||||||
width = len + 2;
|
width = len + 2;
|
||||||
|
|
||||||
const countLF = function(p) {
|
const countLF = function(p) {
|
||||||
|
|
|
@ -10,8 +10,7 @@ TestRegister.addTests([
|
||||||
"op": "To Hex",
|
"op": "To Hex",
|
||||||
"args": [
|
"args": [
|
||||||
"None",
|
"None",
|
||||||
0,
|
0
|
||||||
false
|
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -25,8 +24,7 @@ TestRegister.addTests([
|
||||||
"op": "To Hex",
|
"op": "To Hex",
|
||||||
"args": [
|
"args": [
|
||||||
"Colon",
|
"Colon",
|
||||||
0,
|
0
|
||||||
false
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -39,9 +37,8 @@ TestRegister.addTests([
|
||||||
{
|
{
|
||||||
"op": "To Hex",
|
"op": "To Hex",
|
||||||
"args": [
|
"args": [
|
||||||
"0x",
|
"0x with comma",
|
||||||
0,
|
0
|
||||||
true
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -54,9 +51,8 @@ TestRegister.addTests([
|
||||||
{
|
{
|
||||||
"op": "To Hex",
|
"op": "To Hex",
|
||||||
"args": [
|
"args": [
|
||||||
"0x",
|
"0x with comma",
|
||||||
4,
|
4
|
||||||
true
|
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue