[英]Cast uint64_t to FILETIME
我正在嘗試從文件中獲取字節數組,像uint64_t
一樣解釋它,然后將此uint FILETIME
為FILETIME
在四處搜尋和調試之后,我一直堅持遵循錯誤的工作代碼。
uint64_t win_filetime = *(uint64_t*)(&(((char*)buf)[(int)FILETIME_OFFSET]));
//at this moment win_filetime = 0x01cb3f90e7b52500
其中buf
在FILETIME_OFFSET
處包含所需的字節
然后嘗試t1 = *(FILETIME *)(&win_filetime);
要么
t1.dwLowDateTime = (DWORD)win_filetime;
t1.dwHighDateTime = (DWORD)(win_filetime >> 32);
傳遞給函數
tm FILETIME_to_time_t(const FILETIME *lpFileTime) {
time_t result;
SYSTEMTIME st;
struct tm tmp;
FileTimeToSystemTime(lpFileTime,&st);
memset(&tmp,0,sizeof(struct tm));
tmp.tm_mday = st.wDay;
tmp.tm_mon = st.wMonth - 1;
tmp.tm_year = st.wYear - 1900;
tmp.tm_sec = st.wSecond;
tmp.tm_min = st.wMinute;
tmp.tm_hour = st.wHour;
return tmp;
}
函數FILETIME_to_time_t()
返回垃圾(即年= 110)
來自文件: 0025B5E7903FCB0100
樣本值, HexWorkshop正確將其解析為11:23:10 19.08.2010
也許缺少字節序轉換或我現在無法發現的另一件事?
看來您的代碼還可以,只是年份顯示為110,因為在填充struct tm
時您在代碼中減去了1900。 不過,這是標准的-struct struct tm
應該包含減去1900的年份。在打印值時,請務必小心。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.