How to efficiently identify a binary file

后端 未结 4 1948
醉梦人生
醉梦人生 2021-02-10 19:36

What\'s the most efficient way to identify a binary file? I would like to extract some kind of signature from a binary file and use it to compare it with others.

The bru

4条回答
  •  迷失自我
    2021-02-10 19:57

    An approach I found effective for this sort of thing was to calculate two SHA-1 hashes. One for the first block in a file (I arbitrarily picked 512 bytes as a block size) and one for the whole file. I then stored the two hashes along with a file size. When I needed to identify a file I would first compare the file length. If the lengths matched then I would compare the hash of the first block and if that matched I compared the hash of the entire file. The first two tests quickly weeded out a lot of non-matching files.

提交回复
热议问题