fix: consolidate FILETIME conversions into wintime.py and fix qwinsta crash on Windows - #2215
Open
n3rada wants to merge 3 commits into
Open
fix: consolidate FILETIME conversions into wintime.py and fix qwinsta crash on Windows#2215n3rada wants to merge 3 commits into
n3rada wants to merge 3 commits into
Conversation
This was referenced Jun 23, 2026
n3rada
force-pushed
the
fix/getunixtime-dedup
branch
from
June 24, 2026 12:18
9ad3caa to
caf247a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Hello maintainers 👋
Picking up on #2022 (and also fixing #1374 along the way).
The
getUnixTimefunction was copy-pasted across 11 files with no single authoritative definition. Two of those copies used/=instead of//=, silently producing floats. The one insmbserver.pywas a dead wrapper aroundsmb.FTtoPOSIXthat was never called. The same problem exists on the inverse side:POSIXtoFTandFTtoPOSIXlived insmb.pyand were re-imported everywhere.What this PR does:
Introduces
impacket/wintime.pyas the single home for Windows FILETIME conversions. It exposes three functions:filetime_to_datetime(t): converts a FILETIME value to a naive UTCdatetimeobject by computingdatetime(1601, 1, 1) + timedelta(microseconds=t // 10). Avoidsfromtimestamp()entirely, so it never crashes on Windows for any input value. Fort=0(uninitialised/never-set fields) it returnsdatetime(1601, 1, 1)rather than lying with the Unix epoch.filetime_to_posix(t): converts to a POSIX integer for callers that genuinely need one (e.g.os.utime). Includes a zero-guard for values below the FILETIME epoch.posix_to_filetime(t): replacesPOSIXtoFT.All callers that previously did
datetime.fromtimestamp(getUnixTime(t))ordatetime.fromtimestamp(filetime_to_posix(t))now usefiletime_to_datetime(t)directly. No legacy aliases remain anywhere.smb.pystill imports fromwintimefor its own internal use but no longer re-exports the functions.I chose a dedicated
wintime.pyrather than dropping this intosmb.pyor a genericutils.py— the SMB module is already large and these conversions are used byese,nspi,tsts,dpapi, and several examples that have nothing to do with SMB.Closes #2022
Closes #1374
Best regards