mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
clean up code formatting and fix missing entries
This commit is contained in:
parent
bf1e708a4c
commit
15b426ebb6
3 changed files with 35 additions and 41 deletions
|
@ -418,6 +418,7 @@
|
||||||
"JPath expression",
|
"JPath expression",
|
||||||
"CSS selector",
|
"CSS selector",
|
||||||
"PHP Deserialize",
|
"PHP Deserialize",
|
||||||
|
"PHP Serialize",
|
||||||
"Microsoft Script Decoder",
|
"Microsoft Script Decoder",
|
||||||
"Strip HTML tags",
|
"Strip HTML tags",
|
||||||
"Diff",
|
"Diff",
|
||||||
|
|
|
@ -35,7 +35,7 @@ class PHPSerialize extends Operation {
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
/**
|
/**
|
||||||
* Determines if a number is an integer
|
* Determines if a number is an integer
|
||||||
* @param {number} value
|
* @param {number} value
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
function isInteger(value) {
|
function isInteger(value) {
|
||||||
|
@ -44,7 +44,7 @@ class PHPSerialize extends Operation {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Serialize basic types
|
* Serialize basic types
|
||||||
* @param {string | number | boolean} content
|
* @param {string | number | boolean} content
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function serializeBasicTypes(content) {
|
function serializeBasicTypes(content) {
|
||||||
|
@ -54,40 +54,36 @@ class PHPSerialize extends Operation {
|
||||||
"float": "d",
|
"float": "d",
|
||||||
"boolean": "b"
|
"boolean": "b"
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Booleans
|
* Booleans
|
||||||
* cast to 0 or 1
|
* cast to 0 or 1
|
||||||
*/
|
*/
|
||||||
if (typeof content === "boolean"){
|
if (typeof content === "boolean") {
|
||||||
return `${basicTypes["boolean"]}:${content ? 1 : 0}`;
|
return `${basicTypes.boolean}:${content ? 1 : 0}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Numbers
|
* Numbers
|
||||||
*/
|
*/
|
||||||
if (typeof content === "number"){
|
if (typeof content === "number") {
|
||||||
if (isInteger(content)){
|
if (isInteger(content)) {
|
||||||
return `${basicTypes["integer"]}:${content.toString()}`
|
return `${basicTypes.integer}:${content.toString()}`;
|
||||||
}
|
} else {
|
||||||
else {
|
return `${basicTypes.float}:${content.toString()}`;
|
||||||
return `${basicTypes["float"]}:${content.toString()}`
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strings
|
* Strings
|
||||||
*/
|
*/
|
||||||
if (typeof content === "string")
|
if (typeof content === "string")
|
||||||
return `${basicTypes["string"]}:${content.length}:"${content}"`;
|
return `${basicTypes.string}:${content.length}:"${content}"`;
|
||||||
|
|
||||||
/** This should be unreachable */
|
/** This should be unreachable */
|
||||||
throw new OperationError(`Encountered a non-implemented type: ${typeof content}`);
|
throw new OperationError(`Encountered a non-implemented type: ${typeof content}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Recursively serialize
|
* Recursively serialize
|
||||||
* @param {*} object
|
* @param {*} object
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
function serialize(object) {
|
function serialize(object) {
|
||||||
|
@ -95,42 +91,38 @@ class PHPSerialize extends Operation {
|
||||||
* Null
|
* Null
|
||||||
*/
|
*/
|
||||||
if (object == null) {
|
if (object == null) {
|
||||||
return `N;`
|
return `N;`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
if (typeof object !== "object") {
|
||||||
* Basic types
|
/**
|
||||||
*/
|
* Basic types
|
||||||
if (typeof object !== "object"){
|
*/
|
||||||
return `${serializeBasicTypes(object)};`;
|
return `${serializeBasicTypes(object)};`;
|
||||||
}
|
} else if (object instanceof Array) {
|
||||||
|
/**
|
||||||
/**
|
* Arrays
|
||||||
* Arrays
|
*/
|
||||||
*/
|
|
||||||
else if (object instanceof Array) {
|
|
||||||
const serializedElements = [];
|
const serializedElements = [];
|
||||||
|
|
||||||
for (let i = 0; i < object.length; i++) {
|
for (let i = 0; i < object.length; i++) {
|
||||||
serializedElements.push(`${serialize(i)}${serialize(object[i])}`);
|
serializedElements.push(`${serialize(i)}${serialize(object[i])}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return `a:${object.length}:{${serializedElements.join("")}}`
|
return `a:${object.length}:{${serializedElements.join("")}}`;
|
||||||
}
|
} else if (object instanceof Object) {
|
||||||
|
/**
|
||||||
/**
|
* Objects
|
||||||
* Objects
|
* Note: the output cannot be guaranteed to be in the same order as the input
|
||||||
* Note: the output cannot be guaranteed to be in the same order as the input
|
*/
|
||||||
*/
|
|
||||||
else if (object instanceof Object) {
|
|
||||||
const serializedElements = [];
|
const serializedElements = [];
|
||||||
const keys = Object.keys(object);
|
const keys = Object.keys(object);
|
||||||
|
|
||||||
for (const key of keys) {
|
for (const key of keys) {
|
||||||
serializedElements.push(`${serialize(key)}${serialize(object[key])}`);
|
serializedElements.push(`${serialize(key)}${serialize(object[key])}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
return `a:${keys.length}:{${serializedElements.join("")}}`
|
return `a:${keys.length}:{${serializedElements.join("")}}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This should be unreachable */
|
/** This should be unreachable */
|
||||||
|
|
|
@ -70,6 +70,7 @@ import "./tests/NormaliseUnicode.mjs";
|
||||||
import "./tests/OTP.mjs";
|
import "./tests/OTP.mjs";
|
||||||
import "./tests/PGP.mjs";
|
import "./tests/PGP.mjs";
|
||||||
import "./tests/PHP.mjs";
|
import "./tests/PHP.mjs";
|
||||||
|
import "./tests/PHPSerialize.mjs";
|
||||||
import "./tests/ParseIPRange.mjs";
|
import "./tests/ParseIPRange.mjs";
|
||||||
import "./tests/ParseQRCode.mjs";
|
import "./tests/ParseQRCode.mjs";
|
||||||
import "./tests/PEMtoHex.mjs";
|
import "./tests/PEMtoHex.mjs";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue