Merge branch 'features/jpath' of https://github.com/artemisbot/CyberChef into artemisbot-features/jpath

This commit is contained in:
n1474335 2017-08-04 13:36:03 +00:00
commit 4b87d66131
5 changed files with 6935 additions and 0 deletions

View file

@ -215,6 +215,7 @@ const Categories = [
"Extract dates",
"Regular expression",
"XPath expression",
"JPath expression",
"CSS selector",
"Extract EXIF",
]
@ -278,6 +279,7 @@ const Categories = [
"CSS Beautify",
"CSS Minify",
"XPath expression",
"JPath expression",
"CSS selector",
"Strip HTML tags",
"Diff",

View file

@ -2243,6 +2243,24 @@ const OperationConfig = {
}
]
},
"JPath expression": {
description: "Extract information from a JSON object with a JPath query.",
run: Code.runJpath,
inputType: "string",
outputType: "string",
args: [
{
name: "JPath",
type: "string",
value: Code.JPATH_INITIAL
},
{
name: "Result delimiter",
type: "binaryShortString",
value: Code.JPATH_DELIMITER
}
]
},
"CSS selector": {
description: "Extract information from an HTML document with a CSS selector",
run: Code.runCSSQuery,

6695
src/core/lib/jsonpath.js Normal file

File diff suppressed because one or more lines are too long

View file

@ -4,6 +4,7 @@ import Utils from "../Utils.js";
import vkbeautify from "vkbeautify";
import {DOMParser as dom} from "xmldom";
import xpath from "xpath";
import jpath from "../lib/jsonpath.js";
import prettyPrintOne from "imports-loader?window=>global!exports-loader?prettyPrintOne!google-code-prettify/bin/prettify.min.js";
@ -354,6 +355,44 @@ const Code = {
return nodes.map(nodeToString).join(delimiter);
},
/**
* @constant
* @default
*/
JPATH_INITIAL: "",
/**
* @constant
* @default
*/
JPATH_DELIMITER: "\\n",
/**
* XPath expression operation.
*
* @author Matt C (matt@artemisbot.uk)
* @param {string} input
* @param {Object[]} args
* @returns {string}
*/
runJpath: function(input, args) {
let query = args[0],
delimiter = args[1],
results,
obj;
try {
obj = JSON.parse(input);
} catch (err) {
return "Invalid input JSON.";
}
try {
results = jpath.query(obj, query);
} catch (e) {
return "Invalid JPath expression.";
}
return results.map(result => JSON.stringify(result)).join(delimiter);
},
/**
* @constant