From ad25daf206d245f65fa986bf956375f0760214e6 Mon Sep 17 00:00:00 2001 From: bwhitn Date: Sun, 2 Jul 2017 20:04:25 -0400 Subject: [PATCH 1/2] Allow hex and decimal format for Windows Filetime format as those are the formats they are typically represented in --- src/core/config/OperationConfig.js | 10 ++++++++++ src/core/operations/DateTime.js | 23 +++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/core/config/OperationConfig.js b/src/core/config/OperationConfig.js index 0397b50e..d5688f28 100755 --- a/src/core/config/OperationConfig.js +++ b/src/core/config/OperationConfig.js @@ -2271,6 +2271,11 @@ const OperationConfig = { name: "Output units", type: "option", value: DateTime.UNITS + }, + { + name: "Input Format", + type: "option", + value: DateTime.FILETIME_FORMATS } ] }, @@ -2284,6 +2289,11 @@ const OperationConfig = { name: "Input units", type: "option", value: DateTime.UNITS + }, + { + name: "Output Format", + type: "option", + value: DateTime.FILETIME_FORMATS } ] }, diff --git a/src/core/operations/DateTime.js b/src/core/operations/DateTime.js index 5262ecc4..dcfa2faf 100755 --- a/src/core/operations/DateTime.js +++ b/src/core/operations/DateTime.js @@ -90,7 +90,13 @@ const DateTime = { */ runFromFiletimeToUnix: function(input, args) { let units = args[0]; - input = new BigInteger(input).subtract(new BigInteger("116444736000000000")); + let format = args[1]; + if (format === "Hex") { + input = new BigInteger(input, 16); + } else { + input = new BigInteger(input); + } + input = input.subtract(new BigInteger("116444736000000000")); if (units === "Seconds (s)"){ input = input.divide(new BigInteger("10000000")); } else if (units === "Milliseconds (ms)") { @@ -116,6 +122,7 @@ const DateTime = { */ runToFiletimeFromUnix: function(input, args) { let units = args[0]; + let format = args[1]; input = new BigInteger(input); if (units === "Seconds (s)"){ input = input.multiply(new BigInteger("10000000")); @@ -128,10 +135,22 @@ const DateTime = { } else { throw "Unrecognised unit"; } - return input.add(new BigInteger("116444736000000000")).toString(); + input = input.add(new BigInteger("116444736000000000")); + if (format === "Hex"){ + return input.toString(16); + } else { + return input.toString(); + } }, + /** + * @constant + * @default + */ + FILETIME_FORMATS: ["Decimal", "Hex"], + + /** * @constant * @default From 183c57643bf401bc7a95ba983b944558bfcf2f29 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Mon, 3 Jul 2017 15:25:14 +0000 Subject: [PATCH 2/2] Tidied up changes to filetime operations and brought tests up to date --- src/core/config/OperationConfig.js | 4 ++-- src/core/operations/DateTime.js | 16 ++++++++++++---- test/tests/operations/DateTime.js | 4 ++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/core/config/OperationConfig.js b/src/core/config/OperationConfig.js index 89cd9e44..f8d9fe6d 100755 --- a/src/core/config/OperationConfig.js +++ b/src/core/config/OperationConfig.js @@ -2303,7 +2303,7 @@ const OperationConfig = { value: DateTime.UNITS }, { - name: "Input Format", + name: "Input format", type: "option", value: DateTime.FILETIME_FORMATS } @@ -2321,7 +2321,7 @@ const OperationConfig = { value: DateTime.UNITS }, { - name: "Output Format", + name: "Output format", type: "option", value: DateTime.FILETIME_FORMATS } diff --git a/src/core/operations/DateTime.js b/src/core/operations/DateTime.js index dcfa2faf..b665a2b5 100755 --- a/src/core/operations/DateTime.js +++ b/src/core/operations/DateTime.js @@ -89,14 +89,17 @@ const DateTime = { * @returns {string} */ runFromFiletimeToUnix: function(input, args) { - let units = args[0]; - let format = args[1]; + let units = args[0], + format = args[1]; + if (format === "Hex") { input = new BigInteger(input, 16); } else { input = new BigInteger(input); } + input = input.subtract(new BigInteger("116444736000000000")); + if (units === "Seconds (s)"){ input = input.divide(new BigInteger("10000000")); } else if (units === "Milliseconds (ms)") { @@ -108,6 +111,7 @@ const DateTime = { } else { throw "Unrecognised unit"; } + return input.toString(); }, @@ -121,9 +125,11 @@ const DateTime = { * @returns {string} */ runToFiletimeFromUnix: function(input, args) { - let units = args[0]; - let format = args[1]; + let units = args[0], + format = args[1]; + input = new BigInteger(input); + if (units === "Seconds (s)"){ input = input.multiply(new BigInteger("10000000")); } else if (units === "Milliseconds (ms)") { @@ -135,7 +141,9 @@ const DateTime = { } else { throw "Unrecognised unit"; } + input = input.add(new BigInteger("116444736000000000")); + if (format === "Hex"){ return input.toString(16); } else { diff --git a/test/tests/operations/DateTime.js b/test/tests/operations/DateTime.js index 7ee445ff..f8226ac6 100644 --- a/test/tests/operations/DateTime.js +++ b/test/tests/operations/DateTime.js @@ -16,7 +16,7 @@ TestRegister.addTests([ recipeConfig: [ { op: "Windows Filetime to UNIX Timestamp", - args: ["Nanoseconds (ns)"], + args: ["Nanoseconds (ns)", "Decimal"], }, ], }, @@ -27,7 +27,7 @@ TestRegister.addTests([ recipeConfig: [ { op: "UNIX Timestamp to Windows Filetime", - args: ["Nanoseconds (ns)"], + args: ["Nanoseconds (ns)", "Decimal"], }, ], },