【发布时间】:2015-11-04 01:54:05
【问题描述】:
我正在构建一个工具来帮助我对数据库文件进行逆向工程。我将我的工具定位于固定记录长度的平面文件。
我知道的: 1)每条记录都有一个索引(ID)。 2) 每条记录由分隔符分隔。 3) 每条记录都是固定宽度。 4) 每条记录中的每一列至少由一个 x00 字节分隔。 5)文件头在开头(我这么说是因为头不包含分隔符..)
我在其他文件中找到的分隔符是:( xFAxFA, xFExFE, xFDxFD ) 但考虑到我将来可能会在不同的数据库上使用该工具,这有点无关紧要。所以我需要一些能够挑选出“模式”的东西,尽管它是由多少字节组成的。大概不超过6个字节?如果它更多,它可能会吃掉太多的数据。但是,我这样做的经验是有限的。
所以我想我的问题是,如何在大文件中找到 UNKNOWN 分隔符?我觉得,“我所知道的”我应该能够编程一些东西,我只是不知道从哪里开始......
# Really loose pseudo code
def begin_some_how
# THIS IS THE PART I NEED HELP WITH...
# find all non-zero non-ascii sets of 2 or more bytes that repeat more than twice.
end
def check_possible_record_lengths
possible_delimiter = begin_some_how
# test if any of the above are always the same number of bytes apart from each other(except one instance, the header...)
possible_records = file.split(possible_delimiter)
rec_length_count = possible_records.map{ |record| record.length}.uniq.count
if rec_length_count == 2 # The header will most likely not be the same size.
puts "Success! We found the fixed record delimiter: #{possible_delimiter}
else
puts "Wrong delimiter found"
end
end
【问题讨论】:
标签: ruby database reverse-engineering