如何通过构造解析bin文件?

时间:2019-01-12 01:57:08

标签: python parsing construct

文件格式为:

from construct import *    

file_format=Struct(
        'n_links'/ Int32ul, # number of links
        'links'/ Array(this.n_links, Int32ul), # links
        'n_Items' / ???  # how to do here ? 
     )

02000000  0C000000  10000000  55000000          AA000000
n_links    link_0    link_1   value_of_link_0    value_of_link_1

如何解析“ n_Items”?

1 个答案:

答案 0 :(得分:0)

我解决了:

file_format=Struct(
        'n_links'/ Int32ul, # number of links
        'links'/ Array(this.n_links, Int32ul), # links
        'n_Items' / Pointer(this.links[0], Int32ul[this.n_links])
     )
t=file_format.parse('\x02\x00\x00\x00\x04\x00\x00\x00\x08\x00\x00\x00') #ok parse