解码二进制数据序列中的日期和时间(来自LG手机短信)



INTRO

我正在尝试对一个包含短信消息的二进制数据文件进行逆向工程
该文件名为ems.idx4,大约5年前使用名为LG PhoneManager的软件创建,作为LG手机短信的备份档案
我不知道LG PhoneManager是用哪种语言编写的,但在二进制文件中,我读到了"CObTree"、"CFolder"、"CMessage"等字符串:也许这条线索毫无意义,也许它表明使用了Cobol/.net/任何语言

问题

我解码了二进制文件的整个结构,这很简单
我唯一无法解码的部分是单个消息的日期和时间
我确定了日期和时间编码的二进制部分,并得到了一些解码的示例(感谢消息的内容(
十六进制二进制数据:

[0x10] D0 74 C4 FE 3F 42 E3 40 F1 64 [0x7] 2 [0x13] 1 [0x6] 6C [0x2] is 2007/12/25 some time after 23:58 GMT+1
[0x10] 2B 25 CA 19 2F 43 E3 40 F1 64 [0x7] 2 [0x13] 1 [0x6] 6C [0x2] is 2008/01/02 some time after 10:48 GMT+1
[0x10] AA C0 2C 6E 35 43 E3 40 F1 64 [0x7] 2 [0x13] 1 [0x6] 6C [0x2] is 2008/01/02 some time after 16:03 GMT+1
[0x10] EE 04 71 F2 B6 43 E3 40 F1 64 [0x7] 2 [0x13] 1 [0x6] 6C [0x2] is 2008/01/06 some time after 14:31 GMT+1
[0x10] 60 2C F9 45 4E 4F E3 40 F1 64 [0x7] 2 [0x13] 1 [0x6] 6C [0x2] is 2008/04/08 some time after 10:32 GMT+1
[0x10] 5D 84 01 14 74 64 E3 40 F1 64 [0x7] 2 [0x13] 1 [0x6] 6C [0x2] is 2008/11/11 some time after 14:53 GMT+1

其中[0xN]表示N个零的序列。

知道吗?

更新

使用此工具:http://www.digital-detective.co.uk/freetools/decode.asp
我意识到它是Windows 64位OLE日期/时间格式
根据该工具:

D0 74 C4 FE 3F 42 E3 40 means exactly 26/12/2007 00:59

知道这种Windows 64位OLE日期/时间格式背后的数学原理吗?

这是一个双精度浮点数,表示自1899年12月30日以来的天数(以及小数天数(。

如果你在Windows上,你可以使用VariantTimeToSystemTime函数将其转换为更可用的格式:

unsigned char timeBytes[] = {0xD0,0x74,0xC4,0xFE,0x3F,0x42,0xE3,0x40};
double timeDouble = *(double*)&timeBytes;
SYSTEMTIME systemTime;
VariantTimeToSystemTime(timeDouble, &systemTime);

如果你不使用Windows,我怀疑你需要手动进行转换。如果你需要任何帮助,请在评论中告诉我。

好吧,我找到路了
[0x10]之后的前8个字节是以小端十六进制表示的OLE日期
我用将它们转换为python中的常规日期时间

import datetime
import math
from struct import unpack

def ole_date_bin_to_datetime(ole_date_bin):
    """
        Converts a OLE date from a binary 8 bytes little endian hex form to a datetime
    """
    #Conversion to OLE date float, where:
    # - integer part: days from epoch (1899/12/30 00:00) 
    # - decimal part: percentage of the day, where 0,5 is midday
    date_float = unpack('<d', ole_date_bin)[0]
    date_decimal, date_integer = math.modf(date_float)
    date_decimal = abs(date_decimal)
    date_integer = int(date_integer)
    #Calculate the result
    res = datetime.datetime(1899, 12, 30) + datetime.timedelta(days=date_integer) #adding days to epoch
    res = res + datetime.timedelta(seconds = 86400*date_decimal) #adding percentage of the day
    return res

if __name__ == "__main__":
    print ole_date_bin_to_datetime('xd0x74xc4xfex3fx42xe3x40')

最新更新