[英]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.