mirror of
https://github.com/gchq/CyberChef.git
synced 2025-04-20 14:56:19 -04:00
Added big and little endian options for Windows timestamp conversion ops
This commit is contained in:
parent
4bae662357
commit
3df57ba3dd
2 changed files with 24 additions and 15 deletions
|
@ -34,7 +34,7 @@ class UNIXTimestampToWindowsFiletime extends Operation {
|
||||||
{
|
{
|
||||||
"name": "Output format",
|
"name": "Output format",
|
||||||
"type": "option",
|
"type": "option",
|
||||||
"value": ["Decimal", "Hex"]
|
"value": ["Decimal", "Hex (big endian)", "Hex (little endian)"]
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -65,11 +65,24 @@ class UNIXTimestampToWindowsFiletime extends Operation {
|
||||||
|
|
||||||
input = input.plus(new BigNumber("116444736000000000"));
|
input = input.plus(new BigNumber("116444736000000000"));
|
||||||
|
|
||||||
if (format === "Hex") {
|
let result;
|
||||||
return input.toString(16);
|
if (format.startsWith("Hex")) {
|
||||||
|
result = input.toString(16);
|
||||||
} else {
|
} else {
|
||||||
return input.toFixed();
|
result = input.toFixed();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (format === "Hex (little endian)") {
|
||||||
|
// Swap endianness
|
||||||
|
let flipped = "";
|
||||||
|
for (let i = result.length - 2; i >= 0; i -= 2) {
|
||||||
|
flipped += result.charAt(i);
|
||||||
|
flipped += result.charAt(i + 1);
|
||||||
|
}
|
||||||
|
result = flipped;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,12 +34,7 @@ class WindowsFiletimeToUNIXTimestamp extends Operation {
|
||||||
{
|
{
|
||||||
"name": "Input format",
|
"name": "Input format",
|
||||||
"type": "option",
|
"type": "option",
|
||||||
"value": ["Decimal", "Hex"]
|
"value": ["Decimal", "Hex (big endian)", "Hex (little endian)"]
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "Swap Endianness",
|
|
||||||
"type": "boolean",
|
|
||||||
"value": false
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -50,9 +45,12 @@ class WindowsFiletimeToUNIXTimestamp extends Operation {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
run(input, args) {
|
run(input, args) {
|
||||||
const [units, format, swapEndianness] = args;
|
const [units, format] = args;
|
||||||
|
|
||||||
if (swapEndianness) {
|
if (!input) return "";
|
||||||
|
|
||||||
|
if (format === "Hex (little endian)") {
|
||||||
|
// Swap endianness
|
||||||
let result = "";
|
let result = "";
|
||||||
for (let i = input.length - 2; i >= 0; i -= 2) {
|
for (let i = input.length - 2; i >= 0; i -= 2) {
|
||||||
result += input.charAt(i);
|
result += input.charAt(i);
|
||||||
|
@ -61,9 +59,7 @@ class WindowsFiletimeToUNIXTimestamp extends Operation {
|
||||||
input = result;
|
input = result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!input) return "";
|
if (format.startsWith("Hex")) {
|
||||||
|
|
||||||
if (format === "Hex") {
|
|
||||||
input = new BigNumber(input, 16);
|
input = new BigNumber(input, 16);
|
||||||
} else {
|
} else {
|
||||||
input = new BigNumber(input);
|
input = new BigNumber(input);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue