mirror of
https://github.com/gchq/CyberChef
synced 2024-11-15 09:07:06 +00: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",
|
||||
"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"));
|
||||
|
||||
if (format === "Hex") {
|
||||
return input.toString(16);
|
||||
let result;
|
||||
if (format.startsWith("Hex")) {
|
||||
result = input.toString(16);
|
||||
} 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",
|
||||
"type": "option",
|
||||
"value": ["Decimal", "Hex"]
|
||||
},
|
||||
{
|
||||
"name": "Swap Endianness",
|
||||
"type": "boolean",
|
||||
"value": false
|
||||
"value": ["Decimal", "Hex (big endian)", "Hex (little endian)"]
|
||||
}
|
||||
];
|
||||
}
|
||||
|
@ -50,9 +45,12 @@ class WindowsFiletimeToUNIXTimestamp extends Operation {
|
|||
* @returns {string}
|
||||
*/
|
||||
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 = "";
|
||||
for (let i = input.length - 2; i >= 0; i -= 2) {
|
||||
result += input.charAt(i);
|
||||
|
@ -61,9 +59,7 @@ class WindowsFiletimeToUNIXTimestamp extends Operation {
|
|||
input = result;
|
||||
}
|
||||
|
||||
if (!input) return "";
|
||||
|
||||
if (format === "Hex") {
|
||||
if (format.startsWith("Hex")) {
|
||||
input = new BigNumber(input, 16);
|
||||
} else {
|
||||
input = new BigNumber(input);
|
||||
|
|
Loading…
Reference in a new issue