mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
ESM: Ported BSON, ToTable, Filetime and XKCD operations
This commit is contained in:
parent
eed28f67d5
commit
749b0510e7
7 changed files with 483 additions and 2 deletions
76
src/core/operations/UNIXTimestampToWindowsFiletime.mjs
Normal file
76
src/core/operations/UNIXTimestampToWindowsFiletime.mjs
Normal file
|
@ -0,0 +1,76 @@
|
|||
/**
|
||||
* @author n1474335 [n1474335@gmail.com]
|
||||
* @copyright Crown Copyright 2017
|
||||
* @license Apache-2.0
|
||||
*/
|
||||
|
||||
import Operation from "../Operation";
|
||||
import BigNumber from "bignumber.js";
|
||||
import OperationError from "../errors/OperationError";
|
||||
|
||||
/**
|
||||
* UNIX Timestamp to Windows Filetime operation
|
||||
*/
|
||||
class UNIXTimestampToWindowsFiletime extends Operation {
|
||||
|
||||
/**
|
||||
* UNIXTimestampToWindowsFiletime constructor
|
||||
*/
|
||||
constructor() {
|
||||
super();
|
||||
|
||||
this.name = "UNIX Timestamp to Windows Filetime";
|
||||
this.module = "Default";
|
||||
this.description = "Converts a UNIX timestamp to a Windows Filetime value.<br><br>A Windows Filetime is a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 UTC.<br><br>A UNIX timestamp is a 32-bit value representing the number of seconds since January 1, 1970 UTC (the UNIX epoch).<br><br>This operation also supports UNIX timestamps in milliseconds, microseconds and nanoseconds.";
|
||||
this.inputType = "string";
|
||||
this.outputType = "string";
|
||||
this.args = [
|
||||
{
|
||||
"name": "Input units",
|
||||
"type": "option",
|
||||
"value": ["Seconds (s)", "Milliseconds (ms)", "Microseconds (μs)", "Nanoseconds (ns)"]
|
||||
},
|
||||
{
|
||||
"name": "Output format",
|
||||
"type": "option",
|
||||
"value": ["Decimal", "Hex"]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} input
|
||||
* @param {Object[]} args
|
||||
* @returns {string}
|
||||
*/
|
||||
run(input, args) {
|
||||
const [units, format] = args;
|
||||
|
||||
if (!input) return "";
|
||||
|
||||
input = new BigNumber(input);
|
||||
|
||||
if (units === "Seconds (s)"){
|
||||
input = input.multipliedBy(new BigNumber("10000000"));
|
||||
} else if (units === "Milliseconds (ms)") {
|
||||
input = input.multipliedBy(new BigNumber("10000"));
|
||||
} else if (units === "Microseconds (μs)") {
|
||||
input = input.multiplyiedBy(new BigNumber("10"));
|
||||
} else if (units === "Nanoseconds (ns)") {
|
||||
input = input.dividedBy(new BigNumber("100"));
|
||||
} else {
|
||||
throw new OperationError("Unrecognised unit");
|
||||
}
|
||||
|
||||
input = input.plus(new BigNumber("116444736000000000"));
|
||||
|
||||
if (format === "Hex"){
|
||||
return input.toString(16);
|
||||
} else {
|
||||
return input.toFixed();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default UNIXTimestampToWindowsFiletime;
|
Loading…
Add table
Add a link
Reference in a new issue