mirror of https://github.com/gchq/CyberChef.git
update node api docs
parent
b0c2d95ac1
commit
a6fa501c9e
258
Node-API.md
258
Node-API.md
|
@ -15,7 +15,7 @@ For a taste of what operations are available in CyberChef, check out the [live d
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
```
|
```
|
||||||
npm install --save CyberChef
|
npm install --save cyberchef
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
@ -24,25 +24,26 @@ npm install --save CyberChef
|
||||||
|
|
||||||
### Decode a Base64 encoded-string
|
### Decode a Base64 encoded-string
|
||||||
```javascript
|
```javascript
|
||||||
import chef from "CyberChef";
|
import chef from "cyberchef";
|
||||||
|
|
||||||
chef.fromBase64("U28gbG9uZyBhbmQgdGhhbmtzIGZvciBhbGwgdGhlIGZpc2gu").toString() === "So long and thanks for all the fish."; // true
|
chef.fromBase64("U28gbG9uZyBhbmQgdGhhbmtzIGZvciBhbGwgdGhlIGZpc2gu").toString();
|
||||||
|
// => "So long and thanks for all the fish."
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### Convert a date and time to a different time zone
|
### Convert a date and time to a different time zone
|
||||||
```javascript
|
```javascript
|
||||||
import chef from "CyberChef";
|
import chef from "cyberchef";
|
||||||
|
|
||||||
const aestTime = chef.translateDateTimeFormat("15/06/2015 20:45:00", {
|
const aestTime = chef.translateDateTimeFormat("15/06/2015 20:45:00", {
|
||||||
outputTimezone: "Australia/Queensland"
|
outputTimezone: "Australia/Queensland"
|
||||||
});
|
}).toString();
|
||||||
aestTime.toString() === "Tuesday 16th June 2015 06:45:00 +10:00 AEST"; // true
|
// => "Tuesday 16th June 2015 06:45:00 +10:00 AEST"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Parse a Teredo IPv6 Address
|
### Parse a Teredo IPv6 Address
|
||||||
```javascript
|
```javascript
|
||||||
import { parseIPv6Address } from "CyberChef";
|
import { parseIPv6Address } from "cyberchef";
|
||||||
|
|
||||||
console.log(parseIPv6Address("2001:0000:4136:e378:8000:63bf:3fff:fdd2"));
|
console.log(parseIPv6Address("2001:0000:4136:e378:8000:63bf:3fff:fdd2"));
|
||||||
/** =>
|
/** =>
|
||||||
|
@ -68,51 +69,47 @@ Teredo prefix range: 2001::/32 */
|
||||||
|
|
||||||
### Convert data from a Hexdump, then decompress
|
### Convert data from a Hexdump, then decompress
|
||||||
```javascript
|
```javascript
|
||||||
import { Dish } from "CyberChef";
|
import { Dish, fromHexdump, gunzip } from "cyberchef";
|
||||||
|
|
||||||
const message = new Dish(`00000000 1f 8b 08 00 12 bc f3 57 00 ff 0d c7 c1 09 00 20 |.....¼óW.ÿ.ÇÁ.. |
|
const message = new Dish(`00000000 1f 8b 08 00 12 bc f3 57 00 ff 0d c7 c1 09 00 20 |.....¼óW.ÿ.ÇÁ.. |
|
||||||
00000010 08 05 d0 55 fe 04 2d d3 04 1f ca 8c 44 21 5b ff |..ÐUþ.-Ó..Ê.D![ÿ|
|
00000010 08 05 d0 55 fe 04 2d d3 04 1f ca 8c 44 21 5b ff |..ÐUþ.-Ó..Ê.D![ÿ|
|
||||||
00000020 60 c7 d7 03 16 be 40 1f 78 4a 3f 09 89 0b 9a 7d |\`Ç×..¾@.xJ?....}|
|
00000020 60 c7 d7 03 16 be 40 1f 78 4a 3f 09 89 0b 9a 7d |\`Ç×..¾@.xJ?....}|
|
||||||
00000030 4e c8 4e 6d 05 1e 01 8b 4c 24 00 00 00 |NÈNm....L$...|`)
|
00000030 4e c8 4e 6d 05 1e 01 8b 4c 24 00 00 00 |NÈNm....L$...|`)
|
||||||
.fromHexdump()
|
.apply(fromHexdump)
|
||||||
.gunzip();
|
.apply(gunzip)
|
||||||
message.toString() === "So long and thanks for all the fish." //true
|
.toString();
|
||||||
|
// =>"So long and thanks for all the fish." //true
|
||||||
```
|
```
|
||||||
|
|
||||||
### Interact with files from Node.js `fs` library
|
### Interact with files from Node.js `fs` library
|
||||||
```javascript
|
```javascript
|
||||||
import { Dish, toHex } from "CyberChef";
|
import { Dish, toHex, fromHex } from "cyberchef";
|
||||||
|
|
||||||
fs.writeFileSync("test.txt", toHex("hello"));
|
fs.writeFileSync("test.txt", toHex("hello").toString());
|
||||||
|
|
||||||
const file = new Dish(fs.readFileSync("test.txt"));
|
const file = new Dish(fs.readFileSync("test.txt"));
|
||||||
|
console.log(file) ;
|
||||||
|
// => 68 65 6c 6c 6f
|
||||||
|
|
||||||
console.log(file) // 68 65 6c 6c 6f
|
file.apply(fromHex).toString()
|
||||||
file.fromHex().toString() === "hello"; // true
|
// => hello;
|
||||||
```
|
```
|
||||||
|
|
||||||
## Import with ES6 `import` or CommonJS `require`
|
## Import with ES6 `import` or CommonJS `require`
|
||||||
|
|
||||||
#### ES6 imports
|
### ES6 imports
|
||||||
You can import the default `chef` object:
|
You can import the default `chef` object:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
import chef from "CyberChef";
|
import chef from "cyberchef";
|
||||||
chef.toMorseCode("hello").toString();
|
chef.toMorseCode("hello").toString();
|
||||||
// => .... . .-.. .-.. ---
|
// => .... . .-.. .-.. ---
|
||||||
```
|
```
|
||||||
|
|
||||||
Or you can import individual operations:
|
|
||||||
```javascript
|
|
||||||
import {toMorseCode} from "CyberChef";
|
|
||||||
toMorseCode("goodbye").toString();
|
|
||||||
// => --. --- --- -.. -... -.-- .
|
|
||||||
```
|
|
||||||
|
|
||||||
### CommonJS require
|
### CommonJS require
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const chef = require("CyberChef");
|
const chef = require("cyberchef");
|
||||||
chef.toKebabCase("Large chicken shish, garlic mayo, no salad.").toString();
|
chef.toKebabCase("Large chicken shish, garlic mayo, no salad.").toString();
|
||||||
// => large-chicken-shish-garlic-mayo-no-salad
|
// => large-chicken-shish-garlic-mayo-no-salad
|
||||||
```
|
```
|
||||||
|
@ -127,15 +124,15 @@ chef.toKebabCase("Large chicken shish, garlic mayo, no salad.").toString();
|
||||||
|
|
||||||
You can use operations with default config, or define your own arguments.
|
You can use operations with default config, or define your own arguments.
|
||||||
|
|
||||||
> To see what values an argument accepts, either refer to the UI or use `chef.help(<operation name>)` and inspect the args properties.
|
> To see what values an argument accepts, either refer to the UI or use `chef.help(<operation name>)` and inspect the properties.
|
||||||
|
|
||||||
Operation with default args:
|
Operation with default :
|
||||||
```javascript
|
```javascript
|
||||||
chef.toCharcode("Service!") // Space delimiter, Base 16
|
chef.toCharcode("Service!") // Space delimiter, Base 16
|
||||||
// => 53 65 72 76 69 63 65 21
|
// => 53 65 72 76 69 63 65 21
|
||||||
```
|
```
|
||||||
|
|
||||||
Configure args. Arg keys are camelCase versions of those displayed on the CyberChef UI.
|
Configure . Arg keys are camelCase versions of those displayed on the CyberChef UI.
|
||||||
```javascript
|
```javascript
|
||||||
chef.toCharcode("Service!", {
|
chef.toCharcode("Service!", {
|
||||||
base: 8
|
base: 8
|
||||||
|
@ -144,7 +141,7 @@ chef.toCharcode("Service!", {
|
||||||
// => 123 145 162 166 151 143 145 41
|
// => 123 145 162 166 151 143 145 41
|
||||||
```
|
```
|
||||||
|
|
||||||
Where arguments are options, they are case sensitive. It is recommended to use the argOptions property of the operation. For example:
|
Where arguments are options, they are case sensitive. It is recommended to use the `` property of the operation to access options. For example:
|
||||||
```javascript
|
```javascript
|
||||||
// OK
|
// OK
|
||||||
chef.convertDistance(122, {
|
chef.convertDistance(122, {
|
||||||
|
@ -155,9 +152,9 @@ chef.convertDistance(122, {
|
||||||
|
|
||||||
// Less error-prone
|
// Less error-prone
|
||||||
chef.convertDistance(122, {
|
chef.convertDistance(122, {
|
||||||
inputUnits: chef.convertDistance.argOptions.inputUnits[5],
|
inputUnits: chef.convertDistance..inputUnits.options[5],
|
||||||
outputUnits: chef.convertDistance.argOptions.outputUnits[17]
|
outputUnits: chef.convertDistance..outputUnits.options[17]
|
||||||
});
|
})
|
||||||
// => 30500
|
// => 30500
|
||||||
|
|
||||||
// Invalid outputUnits value
|
// Invalid outputUnits value
|
||||||
|
@ -170,27 +167,28 @@ chef.convertDistance(122, {
|
||||||
|
|
||||||
|
|
||||||
#### Operation input
|
#### Operation input
|
||||||
Operations accept a wide range of input types. For most cases, you can throw any input type at an operation and it will deal with it.
|
Operations accept a wide range of input types, such as strings, numbers and byteArrays. For most cases, you can throw any input type at an operation and it will deal with it.
|
||||||
|
|
||||||
If the given input to an operation is not the operation's input type, it will attempt to convert the input before operating on it. For example, `toBase32`'s input type is `byteArray`, so if you input a string, it converts that string into a byte array before running the operation.
|
If the given input to an operation is not the operation's input type, it will attempt to convert the input before operating on it. For example, `toBase32`'s input type is `byteArray`, so if you input a string, it converts that string into a byte array before running the operation.
|
||||||
|
|
||||||
Files can be read into appropriate functions in chef. They are converted into ArrayBuffers.
|
Files from `fs` can be read into appropriate functions in chef. They are converted into `byteArray`s.
|
||||||
|
|
||||||
JavaScript objects are accepted as input to operations that expect JSON, for example, `JSONBeautify`.
|
JavaScript objects are accepted as input to operations that expect JSON, for example, `JSONBeautify`.
|
||||||
|
|
||||||
#### Operation arguments
|
#### Operation arguments
|
||||||
Operation arguments are the second argument in an operation call. The best way to see an operation's arguments is to use `chef.help(<argument name here>)` or consult the UI.
|
Operation arguments are the second argument in an operation call. The best way to see an operation's arguments is to use `chef.help(<argument name here>)` or consult the UI.
|
||||||
|
|
||||||
Some operation arguments have default values. Some, like `AESEncrypt` for example, will not work without specifying some argument.
|
Some operation arguments have default values. Some, like `AESEncrypt` for example, will not work without specifying some arguments.
|
||||||
|
|
||||||
##### Number, String, binaryString and boolean arguments
|
##### Number, String, binaryString and boolean arguments
|
||||||
Declare these arguments as key value pairs, where the key is the argument name.
|
Declare these arguments as key value pairs, where the key is the argument name.
|
||||||
|
|
||||||
Example: `toGeoHash` (Number)
|
Example: `toBase` (Number)
|
||||||
```javascript
|
```javascript
|
||||||
chef.toGeoHash("37.8324,112.5584", {
|
chef.toBase("45", {
|
||||||
precision: 10,
|
radix: 8
|
||||||
});
|
})
|
||||||
|
// => 55
|
||||||
```
|
```
|
||||||
|
|
||||||
Example: `toBase32` (binaryString)
|
Example: `toBase32` (binaryString)
|
||||||
|
@ -198,21 +196,24 @@ Example: `toBase32` (binaryString)
|
||||||
chef.toBase32("diamond", {
|
chef.toBase32("diamond", {
|
||||||
alphabet: "A-Z",
|
alphabet: "A-Z",
|
||||||
});
|
});
|
||||||
|
// => MRUWCLPNZSA
|
||||||
```
|
```
|
||||||
|
|
||||||
##### Option arguments
|
##### Option arguments
|
||||||
These are arguments represented as dropdowns in the UI. Here the string value must be an exact match for the option string. For convenience, it is recommended to use the `argOptions` property of the operation.
|
These are arguments represented as dropdowns in the UI. Here the string value must be an exact match for the option string. For convenience, it is recommended to use the `` property of the operation.
|
||||||
|
|
||||||
Example: `toDecimal`
|
Example: `toDecimal`
|
||||||
```javascript
|
```javascript
|
||||||
chef.toDecimal("Hello", {
|
chef.toDecimal("Hello", {
|
||||||
delimiter: "Colon", // note case sensitive
|
delimiter: "Colon", // note case sensitive
|
||||||
});
|
});
|
||||||
|
// => 72:101:108:108:111
|
||||||
|
|
||||||
// Equivalent and less error-prone:
|
// Equivalent and less error-prone:
|
||||||
chef.toDecimal("Hello", {
|
chef.toDecimal("Hello", {
|
||||||
delimiter: chef.toDecimal.argOptions.delimiter[3]
|
delimiter: chef.toDecimal..delimiter.options[3],
|
||||||
})
|
});
|
||||||
|
// => 72:101:108:108:111
|
||||||
```
|
```
|
||||||
|
|
||||||
##### toggleString arguments
|
##### toggleString arguments
|
||||||
|
@ -221,16 +222,16 @@ ToggleStrings are arguments where there is a value and an option in one argument
|
||||||
Example: `ADD` with default encoding
|
Example: `ADD` with default encoding
|
||||||
```javascript
|
```javascript
|
||||||
chef.ADD("abc", {
|
chef.ADD("abc", {
|
||||||
key: "abc"
|
key: "123",
|
||||||
})
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
Example: `ADD` with explicit encoding
|
Example: `ADD` with explicit encoding. Note the property `toggleValues` rather than `options` in the `` object.
|
||||||
```javascript
|
```javascript
|
||||||
chef.ADD("abc", {
|
chef.ADD("abc", {
|
||||||
key: {
|
key: {
|
||||||
string: "abc",
|
string: "123",
|
||||||
option: chef.ADD.argOptions.key[4],
|
option: chef.ADD..key.toggleValues[4],
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
@ -242,13 +243,13 @@ Operations return a [`Dish`](#the-dish-type) type. [`Dish`](#the-dish-type) has
|
||||||
Logging to the console, string coercion and number coercion work as you would expect:
|
Logging to the console, string coercion and number coercion work as you would expect:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const result = toBase32(32).fromBase32();
|
const result = chef.toBase32(32).apply(chef.fromBase32);
|
||||||
|
|
||||||
// Logging to console
|
// Logging to console
|
||||||
console.log(result); // => 32
|
console.log(result); // => 32
|
||||||
|
|
||||||
// Number coercion
|
// Number coercion
|
||||||
assert.equal(result + 3, 35); // => true
|
assert.equal(result + 3, 35); // OK
|
||||||
|
|
||||||
// String coercion
|
// String coercion
|
||||||
assert.equal(result.toString(), "32"); // => true;
|
assert.equal(result.toString(), "32"); // => true;
|
||||||
|
@ -257,8 +258,8 @@ assert.equal(result.toString(), "32"); // => true;
|
||||||
The `value` property of an operation result will give the raw result. For example:
|
The `value` property of an operation result will give the raw result. For example:
|
||||||
```javascript
|
```javascript
|
||||||
// dropBytes has output type ArrayBuffer
|
// dropBytes has output type ArrayBuffer
|
||||||
dropBytes("I'd love a byte").value
|
chef.dropBytes("I'd love a byte").value
|
||||||
// => ArrayBuffer { byteLength: 8 }
|
// => ArrayBuffer { byteLength: 10 }
|
||||||
```
|
```
|
||||||
|
|
||||||
Calling `toString` will give a string representation of the result.
|
Calling `toString` will give a string representation of the result.
|
||||||
|
@ -266,9 +267,9 @@ Calling `toString` will give a string representation of the result.
|
||||||
[See more about `Dish` here.](#the-dish-type)
|
[See more about `Dish` here.](#the-dish-type)
|
||||||
|
|
||||||
#### Compose operations
|
#### Compose operations
|
||||||
Operations can be composed. This example performs ROT13 substitution followed by conversion to Hex on some input:
|
Operations can be composed using `apply`. This example performs ROT13 substitution followed by conversion to Hex on some input:
|
||||||
```javascript
|
```javascript
|
||||||
ROT13("Medium rare, please.").toHex().toString();
|
chef.ROT13("Medium rare, please.").apply(chef.toHex).toString();
|
||||||
// => 5a 72 71 76 68 7a 20 65 6e 65 72 2c 20 63 79 72 6e 66 72 2e
|
// => 5a 72 71 76 68 7a 20 65 6e 65 72 2c 20 63 79 72 6e 66 72 2e
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -276,7 +277,7 @@ ROT13("Medium rare, please.").toHex().toString();
|
||||||
#### Excluded operations
|
#### Excluded operations
|
||||||
The best way to browse operations is to run Cyberchef, either locally or via the [demo][1].
|
The best way to browse operations is to run Cyberchef, either locally or via the [demo][1].
|
||||||
|
|
||||||
Most CyberChef operations are inclided in the Node.js API, with the exception of operations that handle the Javascript `File` API and Flow Control operations. Excluded files will throw an ExcludedOperationError if called.
|
Most CyberChef operations are included in the Node.js API, with the exception of Flow Control operations. Excluded operations will throw an ExcludedOperationError if called.
|
||||||
|
|
||||||
For a full list of excluded operations, see the source files under `src/node/config/excludedOperations`.
|
For a full list of excluded operations, see the source files under `src/node/config/excludedOperations`.
|
||||||
|
|
||||||
|
@ -289,19 +290,19 @@ The `chef` object has some other helpful functions.
|
||||||
The `help` function returns the description of an operation. Use this to see what input, output and arguments an operation has.
|
The `help` function returns the description of an operation. Use this to see what input, output and arguments an operation has.
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
chef.help(chef.toBase32)
|
chef.help(chef.toBase32);
|
||||||
/**
|
/**
|
||||||
{ module: 'Default',
|
[{ module: 'Default',
|
||||||
description: 'Base32 is a notation for encoding arbitrary byte data using a restricted set of symbols that can be conveniently used by humans and processed by computers. It uses a smaller set of characters than Base64, usually the uppercase alphabet and the numbers 2 to 7.',
|
description: 'Base32 is a notation for encoding arbitrary byte data using a restricted set of symbols that can be conveniently used by humans and processed by computers. It uses a smaller set of characters than Base64, usually the uppercase alphabet and the numbers 2 to 7.',
|
||||||
inputType: 'byteArray',
|
inputType: 'byteArray',
|
||||||
outputType: 'string',
|
outputType: 'string',
|
||||||
flowControl: false,
|
flowControl: false,
|
||||||
args:
|
:
|
||||||
[ { name: 'Alphabet',
|
[ { name: 'Alphabet',
|
||||||
type: 'binaryString',
|
type: 'binaryString',
|
||||||
value: 'A-Z2-7=',
|
value: 'A-Z2-7=',
|
||||||
toggleValues: [] } ],
|
toggleValues: [] } ],
|
||||||
name: 'To Base32' }
|
name: 'To Base32' }]
|
||||||
*/
|
*/
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -312,10 +313,12 @@ chef.help("tobase32") // OK
|
||||||
chef.help("toBase32") // OK
|
chef.help("toBase32") // OK
|
||||||
```
|
```
|
||||||
|
|
||||||
|
If there is more than one match for the given search term, `help` will return multiple matches. It searches in the operation name and the description field, prioritising matches in the operation name.
|
||||||
|
|
||||||
#### `bake`
|
#### `bake`
|
||||||
`bake` is useful for building "recipes" - chains of operations to apply to some input, in order. `bake` accepts operations in multiple ways. It always returns a `Dish` object.
|
`bake` is useful for building "recipes" - chains of operations to apply to some input, in order. `bake` accepts operations in multiple ways. It always returns a `Dish` object.
|
||||||
|
|
||||||
One operation, no args
|
One operation, no
|
||||||
```javascript
|
```javascript
|
||||||
chef.bake("I'll have the cod.", chef.toBase64);
|
chef.bake("I'll have the cod.", chef.toBase64);
|
||||||
// => SSdsbCBoYXZlIHRoZSBjb2Qu
|
// => SSdsbCBoYXZlIHRoZSBjb2Qu
|
||||||
|
@ -325,35 +328,35 @@ One operation by name
|
||||||
chef.bake("I'll have the cod.", "to base 64");
|
chef.bake("I'll have the cod.", "to base 64");
|
||||||
// => SSdsbCBoYXZlIHRoZSBjb2Qu
|
// => SSdsbCBoYXZlIHRoZSBjb2Qu
|
||||||
```
|
```
|
||||||
Multiple operations, by name or by function (default args)
|
Multiple operations, by name or by function (default )
|
||||||
```javascript
|
```javascript
|
||||||
chef.bake("I'll have the cod", [chef.toBase64, "sha1"]);
|
chef.bake("I'll have the cod", [chef.toBase64, "sha1"]);
|
||||||
// => aef8b5147a4b1a0dafb427bea903af0f3c8ea151
|
// => f20135964d60f5fb66f971f5ee33d8395d1f90bf
|
||||||
```
|
```
|
||||||
|
|
||||||
One operation, with custom args
|
One operation, with custom
|
||||||
```javascript
|
```javascript
|
||||||
chef.bake("I'll have the salmon.", {
|
chef.bake("I'll have the salmon.", {
|
||||||
op: chef.toBase64,
|
op: chef.toBase64,
|
||||||
args: {
|
: {
|
||||||
alphabet: "A-Z",
|
alphabet: "A-Z",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
// => SSCBYXZIHRZSBYW
|
// => SSCBYXZIHRZSBYW
|
||||||
```
|
```
|
||||||
|
|
||||||
Multiple operations with custom args
|
Multiple operations with custom
|
||||||
```javascript
|
```javascript
|
||||||
chef.bake("I'll have the salmon.", [
|
chef.bake("I'll have the salmon.", [
|
||||||
{
|
{
|
||||||
op: chef.toBase64,
|
op: chef.toBase64,
|
||||||
args: {
|
: {
|
||||||
alphabet: "A-Z"
|
alphabet: "A-Z"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
op: chef.sort,
|
op: chef.sort,
|
||||||
args: {
|
: {
|
||||||
delimiter: "Nothing (separate chars)",
|
delimiter: "Nothing (separate chars)",
|
||||||
reverse: true,
|
reverse: true,
|
||||||
}
|
}
|
||||||
|
@ -365,15 +368,30 @@ chef.bake("I'll have the salmon.", [
|
||||||
> ### Using recipes from CyberChef web tool
|
> ### Using recipes from CyberChef web tool
|
||||||
> `chef.bake` is compatible with the JSON format from saved recipes in the CyberChef web UI. Therefore, you can use the UI to figure out your recipe, and then export it to use in the Node.js API.
|
> `chef.bake` is compatible with the JSON format from saved recipes in the CyberChef web UI. Therefore, you can use the UI to figure out your recipe, and then export it to use in the Node.js API.
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
// taken from CyberChef web export
|
||||||
|
const recipe = [
|
||||||
|
{ "op": "To Base64",
|
||||||
|
"": ["A-Z"] },
|
||||||
|
{ "op": "Sort",
|
||||||
|
"": ["Nothing (separate chars)", true, "Alphabetical (case sensitive)"] }
|
||||||
|
];
|
||||||
|
|
||||||
|
chef.bake("I'll have the salmon.", recipe);
|
||||||
|
// => // => ZZYYXWSSSRIHCBB
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## The `Dish` type
|
## The `Dish` type
|
||||||
All operations in CyberChef return the `Dish` type. This allows operations to be composed. You can also create a new `Dish` with some input and then perform operations on it.
|
All operations in CyberChef return the `Dish` type. This allows operations to be composed. You can also create a new `Dish` with some input and then perform operations on it.
|
||||||
|
|
||||||
Example:
|
Example:
|
||||||
```javascript
|
```javascript
|
||||||
import { Dish } from "CyberChef";
|
import chef from "cyberchef";
|
||||||
const dish = new Dish("hello");
|
const dish = new chef.Dish("hello");
|
||||||
dish.toBase32().toString(); // => NBSWY3DP
|
dish.apply(chef.toBase32).toString();
|
||||||
|
// => NBSWY3DP
|
||||||
```
|
```
|
||||||
|
|
||||||
For more information on `Dish`, see the [`Dish` API](#Dish) below
|
For more information on `Dish`, see the [`Dish` API](#Dish) below
|
||||||
|
@ -385,39 +403,48 @@ Dish will coerce to a String or an Number where appropriate.
|
||||||
|
|
||||||
Empty Dish contructor
|
Empty Dish contructor
|
||||||
```javascript
|
```javascript
|
||||||
const dish = new Dish();
|
const dish = new chef.Dish();
|
||||||
dish.value; // => []
|
dish.value; // => []
|
||||||
dish.type; // => 0 (byteArray)
|
dish.type; // => 0 (byteArray)
|
||||||
```
|
```
|
||||||
|
|
||||||
Dish with type implied from input
|
Dish with type implied from input
|
||||||
```javascript
|
```javascript
|
||||||
const dish = new Dish("input");
|
const dish = new chef.Dish("input");
|
||||||
dish.value; // => "input"
|
dish.value; // => "input"
|
||||||
dish.type; // => 1 (string)
|
dish.type; // => 1 (string)
|
||||||
```
|
```
|
||||||
|
|
||||||
Dish with explicit type declaration
|
Dish with explicit type declaration
|
||||||
```javascript
|
```javascript
|
||||||
const dish = new Dish(2, "number");
|
const dish = new chef.Dish(2, "number");
|
||||||
dish.value; // => 2
|
dish.value; // => 2
|
||||||
dish.type; // => 2 (number)
|
dish.type; // => 2 (number)
|
||||||
```
|
```
|
||||||
|
|
||||||
Dish will not perform coercion on construction
|
Dish will not perform coercion on construction
|
||||||
```javascript
|
```javascript
|
||||||
const dish = new Dish("2", "number");
|
const dish = new chef.Dish("2", "number");
|
||||||
// Data is not a valid number: "2"
|
// Data is not a valid number: "2"
|
||||||
```
|
```
|
||||||
|
|
||||||
Coerce dish value to another type
|
Coerce dish value to another type
|
||||||
```javascript
|
```javascript
|
||||||
const dish = new Dish("42");
|
const dish = new chef.Dish("42");
|
||||||
dish.type; // => 1
|
dish.type; // => 1
|
||||||
dish.get("number") // => 42
|
dish.get("number") // => 42
|
||||||
dish.type; // => 2
|
dish.type; // => 2
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Immutably present dish value as another type with `presentAs`
|
||||||
|
```javascript
|
||||||
|
const dish = new chef.Dish("42");
|
||||||
|
dish.type; // => 1
|
||||||
|
dish.presentAs("number") // => 42
|
||||||
|
dish.type; // => 1
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
Dish values get coerced to String on `console.log` or `toString`
|
Dish values get coerced to String on `console.log` or `toString`
|
||||||
```javascript
|
```javascript
|
||||||
const result = chef.ADD("some input", {
|
const result = chef.ADD("some input", {
|
||||||
|
@ -431,7 +458,7 @@ result.toString(); /* => ØÕÔÍ
ÏÕØÚÚ */
|
||||||
|
|
||||||
Perform operations straight off a Dish:
|
Perform operations straight off a Dish:
|
||||||
```javascript
|
```javascript
|
||||||
const result = new Dish("Yum").toBinary();
|
const result = new chef.Dish("Yum").apply(chef.toBinary);
|
||||||
result.value; // => 01011001 01110101 01101101
|
result.value; // => 01011001 01110101 01101101
|
||||||
result.type; // => 1 (string)
|
result.type; // => 1 (string)
|
||||||
```
|
```
|
||||||
|
@ -452,7 +479,7 @@ To see what features and fixes are in the pipeline, refer to the repository [iss
|
||||||
|
|
||||||
# REPL
|
# REPL
|
||||||
|
|
||||||
To run the repl, install CyberChef, run `grunt node` and then run `npm run repl`.
|
To run the repl, install CyberChef, run `npm run repl`.
|
||||||
|
|
||||||
# API
|
# API
|
||||||
|
|
||||||
|
@ -470,17 +497,17 @@ Returns configuration for operations matching the search term.
|
||||||
```javascript
|
```javascript
|
||||||
chef.help("md5")
|
chef.help("md5")
|
||||||
/** =>
|
/** =>
|
||||||
[ { module: 'Hashing',
|
1 result found.
|
||||||
description: 'MD5 (Message-Digest 5) is a widely used hash function. It has been used in a variety of security applications and is also commonly used to check the integrity of files.<br><br>However, MD5 is not collision resistant and it isn\'t suitable for applications like SSL/TLS certificates or digital signatures that rely on this property.',
|
[ { module: 'Crypto',
|
||||||
|
description:
|
||||||
|
'MD5 (Message-Digest 5) is a widely used hash function. It has been used in a variety of security applications and is also commonly used to check the integrity of files.<br><br>However, MD5 is not collision resistant and it isn\'t suitable for applications like SSL/TLS certificates or digital signatures that rely on this property.',
|
||||||
infoURL: 'https://wikipedia.org/wiki/MD5',
|
infoURL: 'https://wikipedia.org/wiki/MD5',
|
||||||
inputType: 'ArrayBuffer',
|
inputType: 'ArrayBuffer',
|
||||||
outputType: 'string',
|
outputType: 'string',
|
||||||
flowControl: false,
|
flowControl: false,
|
||||||
args: [],
|
manualBake: false,
|
||||||
name: 'MD5' },
|
: [],
|
||||||
...
|
name: 'MD5' } ]
|
||||||
]
|
|
||||||
|
|
||||||
*/
|
*/
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -491,8 +518,8 @@ Also exposed as a top level export `Dish`.
|
||||||
#### Arguments:
|
#### Arguments:
|
||||||
|Name|Type|Description|
|
|Name|Type|Description|
|
||||||
|-|-|-|
|
|-|-|-|
|
||||||
|`inputOrDish=null`|ArrayBuffer, String, Number, Object or Dish|The input on which you want to operate, or a Dish instance to clone a dish. If `null`, the dish's `value` and `type` properties are set to `[]` and `0` respectively.|
|
|`inputOrDish=null`|Buffer, ArrayBuffer, String, Number, Object or Dish|The input on which you want to operate, or a Dish instance to clone a dish. If `null`, the dish's `value` and `type` properties are set to `[]` and `0` respectively.|
|
||||||
|`type=null`|`String`|The type that you want the input coerced to.|
|
|`type=null`|`String` or `Dish` enum|The type that you want the input coerced to.|
|
||||||
#### Example:
|
#### Example:
|
||||||
```javascript
|
```javascript
|
||||||
const dish = new chef.Dish("hello");
|
const dish = new chef.Dish("hello");
|
||||||
|
@ -500,9 +527,8 @@ dish.value; // "hello"
|
||||||
dish.type; // 1, signifying string type enum.
|
dish.type; // 1, signifying string type enum.
|
||||||
|
|
||||||
|
|
||||||
// Or as top level export
|
// Explicitly declare type
|
||||||
import { Dish } from "CyberChef"
|
const dish = new chef.Dish(5, "number");
|
||||||
const dish = new Dish("5", "number");
|
|
||||||
dish.value; // 5
|
dish.value; // 5
|
||||||
dish.type; // 2;
|
dish.type; // 2;
|
||||||
```
|
```
|
||||||
|
@ -516,7 +542,7 @@ Useful for consuming recipes saved from the web version of CyberChef.
|
||||||
|Name|Type|Description|
|
|Name|Type|Description|
|
||||||
|-|-|-|
|
|-|-|-|
|
||||||
|input|any|The input for the recipe.|
|
|input|any|The input for the recipe.|
|
||||||
|recipeConfig|`String` or operation or an object with properties `op` and `args` (see CyberChef save recipe JSON format), or an `Array` of one or more of these types.|A description of which operations, with given arguments, to perform on the input.
|
|recipeConfig|`String` or operation or an object with properties `op` and `` (see CyberChef save recipe JSON format), or an `Array` of one or more of these types.|A description of which operations, with given arguments, to perform on the input.
|
||||||
#### Examples:
|
#### Examples:
|
||||||
```javascript
|
```javascript
|
||||||
// Single operation input
|
// Single operation input
|
||||||
|
@ -527,10 +553,10 @@ chef.bake("Apple pie", chef.toBase32).toString();
|
||||||
chef.bake("Apple pie", "to base 32").toString();
|
chef.bake("Apple pie", "to base 32").toString();
|
||||||
// => IFYHA3DFEBYGSZI=
|
// => IFYHA3DFEBYGSZI=
|
||||||
|
|
||||||
// Single operation object with args
|
// Single operation object with
|
||||||
chef.bake("Apple pie", {
|
chef.bake("Apple pie", {
|
||||||
op: chef.toBase32, // string would work here too
|
op: chef.toBase32, // string would work here too
|
||||||
args: {
|
: {
|
||||||
alphabet: "A-Z"
|
alphabet: "A-Z"
|
||||||
}
|
}
|
||||||
}).toString();
|
}).toString();
|
||||||
|
@ -541,7 +567,7 @@ chef.bake("Apple pie", [
|
||||||
chef.toBase32,
|
chef.toBase32,
|
||||||
{
|
{
|
||||||
op: "from base 32",
|
op: "from base 32",
|
||||||
args: {
|
: {
|
||||||
alphabet: "A-Z2-7=",
|
alphabet: "A-Z2-7=",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -567,7 +593,8 @@ Map from string representation of type to the type enum.
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
```javascript
|
```javascript
|
||||||
0 === Dish.typeEnum("bytearray"); // => true
|
chef.Dish.typeEnum("bytearray");
|
||||||
|
// => 0
|
||||||
```
|
```
|
||||||
|
|
||||||
### static `enumLookup`
|
### static `enumLookup`
|
||||||
|
@ -585,7 +612,8 @@ Get string representation of Dish type enum.
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
```javascript
|
```javascript
|
||||||
"JSON" === Dish.enumLookup(Dish.JSON); // => true
|
chef.Dish.enumLookup(Dish.JSON);
|
||||||
|
// => "JSON"
|
||||||
```
|
```
|
||||||
|
|
||||||
### Constructor
|
### Constructor
|
||||||
|
@ -599,20 +627,42 @@ Construct a new Dish.
|
||||||
#### Examples:
|
#### Examples:
|
||||||
```javascript
|
```javascript
|
||||||
// Empty Dish constructor
|
// Empty Dish constructor
|
||||||
const dish = new Dish();
|
const dish = new chef.Dish();
|
||||||
|
|
||||||
// String type dish (implied)
|
// String type dish (implied)
|
||||||
const dish = new Dish("some input");
|
const dish = new chef.Dish("some input");
|
||||||
|
|
||||||
// Number type dish (explicit)
|
// Number type dish (explicit)
|
||||||
const dish = new Dish(460, "number");
|
const dish = new chef.Dish(460, "number");
|
||||||
|
|
||||||
// Dish from another dish. Clones it.
|
// Dish from another dish. Clones it.
|
||||||
const secondDish = new Dish(dish);
|
const secondDish = new chef.Dish(dish);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `dish.apply`
|
||||||
|
A method for chaining operations. Run the given operation with the dish as the input. A new dish is returned and the original is not changed.
|
||||||
|
|
||||||
|
#### Arguments
|
||||||
|
|Name|Type|Description|
|
||||||
|
|-|-|-|
|
||||||
|
|operation|Operation|Operation to run with dish as input|
|
||||||
|
|=null|Object| Operation arguments|
|
||||||
|
|
||||||
|
#### Examples
|
||||||
|
```javascript
|
||||||
|
// Operation with default arguments
|
||||||
|
const dish = new chef.Dish(5, "number");
|
||||||
|
const result = dish.apply(chef.toBase32);
|
||||||
|
|
||||||
|
// Operation with custom arguments
|
||||||
|
const base64 = dish.apply(chef.toBase64, {
|
||||||
|
alphabet: "A-Z",
|
||||||
|
});
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### `dish.get` or `dish.to`
|
### `dish.get` or `dish.to`
|
||||||
Coerce the dish to a different type.
|
Coerce the dish to a different type. Mutable.
|
||||||
|
|
||||||
#### Arguments
|
#### Arguments
|
||||||
|Name|Type|Description|
|
|Name|Type|Description|
|
||||||
|
@ -637,8 +687,14 @@ asNumber; // => 360
|
||||||
dish.type; // => 2 (number)
|
dish.type; // => 2 (number)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `dish.presentAs`
|
||||||
|
return the dish value as another type, without changing the dish.
|
||||||
|
|
||||||
|
Same arguments as `dish.get`.
|
||||||
|
|
||||||
|
|
||||||
### `toString`
|
### `toString`
|
||||||
Coerce the current dish to a string value. Calls `get(1)` on the dish.
|
Get the current dish value as a string. Does not change the dish.
|
||||||
|
|
||||||
|
|
||||||
### `dish.set`
|
### `dish.set`
|
||||||
|
@ -647,7 +703,7 @@ Sets the data value and type and then validates them.
|
||||||
|Name|Type|Description|
|
|Name|Type|Description|
|
||||||
|-|-|-|
|
|-|-|-|
|
||||||
|value|*|new dish value|
|
|value|*|new dish value|
|
||||||
|type|String or Number| The data type of value. See Dish enums.
|
|type|String or `Dish` enum| The data type of value. See Dish enums.
|
||||||
|
|
||||||
#### Example
|
#### Example
|
||||||
```javascript
|
```javascript
|
||||||
|
|
Loading…
Reference in New Issue