From 112af3c74be73e61333adf3aad9fc323f6023e1c Mon Sep 17 00:00:00 2001 From: "windhamwong@nva-hk.com" Date: Fri, 24 Mar 2017 11:02:37 +0000 Subject: [PATCH] 0x[Hex] operation added --- README.md | 1 + src/js/config/Categories.js | 1 + src/js/config/OperationConfig.js | 9 +++++++++ src/js/operations/ByteRepr.js | 18 ++++++++++++++++++ 4 files changed, 29 insertions(+) diff --git a/README.md b/README.md index a484bb01..0c831ba2 100755 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ This is a fork of original CyberChef by GCHQ. This project has implemented my ow ## Features - opeartion **nTcpdump**: tcpdump hexdump convert +- operation **From 0x[Hex]**: e.g. 0x217e21 to !~! ## Todo diff --git a/src/js/config/Categories.js b/src/js/config/Categories.js index c92cc4c3..f1d2749c 100755 --- a/src/js/config/Categories.js +++ b/src/js/config/Categories.js @@ -28,6 +28,7 @@ var Categories = [ "To Hexdump", "From Hexdump", "From nTcpdump", + "From 0x[Hex]", "To Hex", "From Hex", "To Charcode", diff --git a/src/js/config/OperationConfig.js b/src/js/config/OperationConfig.js index b6d56c6e..f4bb2ca8 100755 --- a/src/js/config/OperationConfig.js +++ b/src/js/config/OperationConfig.js @@ -391,6 +391,15 @@ var OperationConfig = { } ] }, + "From 0x[Hex]": { + description: "Converts a hexadecimal byte string back into a its raw value.

e.g. 0x217e21 becomes the UTF-8 encoded string !~!", + run: ByteRepr.runFrom0xHex, + highlight: ByteRepr.highlightFrom, + highlightReverse: ByteRepr.highlightTo, + inputType: "string", + outputType: "string", + args: [] + }, "From Hex": { description: "Converts a hexadecimal byte string back into a its raw value.

e.g. ce 93 ce b5 ce b9 ce ac 20 cf 83 ce bf cf 85 0a becomes the UTF-8 encoded string Γειά σου", run: ByteRepr.runFromHex, diff --git a/src/js/operations/ByteRepr.js b/src/js/operations/ByteRepr.js index 2130409d..ebbae924 100755 --- a/src/js/operations/ByteRepr.js +++ b/src/js/operations/ByteRepr.js @@ -51,6 +51,24 @@ var ByteRepr = { var delim = args[0] || "Space"; return Utils.fromHex(input, delim, 2); }, + + + /** + * From 0xHex operation. + * + * @param {string} input (Starting with 0x only in the raw input) + * @param {Object[]} args + * @returns {byteArray} + */ + runFrom0xHex: function(input, args) { + var data = input.replace(/0x([0-9a-f]{2,})/ig, + function(match, p1) { + if (p1) { + return Utils.byteArrayToChars(Utils.fromHex(p1)); + }; + }); + return data; + }, /**