impacket
impacket copied to clipboard
Improve file timestamp resolution
Currently, file timestamps returned by the SMBServer are obtained by unpacking the 10-tuple returned by os.stat(some_path). However, accessing the timestamp fields in that manner returns an integer Unix timestamp, providing 1-second resolution.
This PR changes such occurences to use named access instead (using the field st_{a/c/m}time ), which returns a float value with improved resolution.
Testing with one of my projects that uses the SMB client's listPath method:
Before
>>> c.retrieve_latest_file()
2025-01-29 09:43:25.717 | INFO | controller:retrieve_file:39 - Retrieving latest file
2025-01-29 09:43:26.750 | INFO | driver:retrieve_file:47 - Found new result file test.csv created at 133826174050000000
After
>>> c.retrieve_latest_file()
2025-01-29 09:44:53.474 | INFO | controller:retrieve_file:39 - Retrieving latest file
2025-01-29 09:44:54.516 | DEBUG | driver:retrieve_file:47 - Found new result file test.csv created at 133826174934897888
I'd love these changes as well!
Please notice the getFileTime method was moved from smbserver.py to smb.py and was renamed as well.