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

This commit is contained in:
n1474335 committed 2017-08-04 13:36:03 +00:00
commit 4b87d66131
5 files changed
+6935

No files matched your search

+2
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",
+18
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,
File diff suppressed because it is too large. Load diff
+39
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