
Limitations of BinDiffīinDiff cannot compare files larger than 2GB.

Now both files have been processed completely. This is also done with calls to WriteBlockAdded, beginning with nPos2, which is 1 byte after the last found block. When all blocks of File 1 have been searched, the remaining bytes of File 2 must be written. If more than 16 bytes have been added, WriteBlockAdded will be called more than once. If the block has been found, the position nPos2 will be moved to 1 byte after the found block, so no block will be found twice.ĭepending on the results of FindBlock, the functions WriteBlockRemoved, WriteBlockEqual and WriteBlockAdded will be called. Each block is searched with a call to FindBlock. The function DiffWriter.WriteDiffThread loops through File 1 in steps of 16 bytes, and always reads 1 block of maximum 16 bytes. This way, it does not declare a very large amount of bytes as "added" ("+") if the block being searched for is found very much later in File 2. This means: After the first block has been found, the program will only search 1KB in advance for the next block, and declare the block as "not found" ("-") if it appears later than 1KB after the previous found block. If the flag bFoundFirstEqual is set, the loop will end as soon as more than 1KB data have been searched and no equal block was found. In this case, the loop ends, and the position is returned. If all nBytesToCompare bytes are equal, the block has been found at position i. The function loops through File 2 in steps of 1 byte, and compares nBytesToCompare bytes, starting at the loop counter i. A flag that specifies whether at least 1 equal block has already been found in an earlier call of The number of bytes contained in the block that shall be compared (must be > 0). A byte array that contains all bytes of File 2.

A byte array that contains all bytes of File 1. The position in File 2 where the search for an equal block shall begin. The position in File 1 where the block that shall be compared begins. Private static Int32 FindBlock( Int32 nPos1,Īs you can see, this function takes six parameters: This is where the function FindBlock is needed: The important question is: How does the function DiffWriter.WriteDiffThread decide whether a block was found in File 2? These sub routines are so simple that I will not explain them in detail. WriteBlockAdded (if there are some bytes between two found blocks, marked with a "+").WriteBlockRemoved (if a block is not found, marked with a.Three sub routines, each of which can write a block of 16 bytes (or smaller) to the text file: The same will happen for bytes before the first found block and after the last found block.Īs a result of these requirements, the function DiffWriter.WriteDiffThread needs If there are some bytes between the previous found block and this found block, they are marked with a "+", and written on the right side. If a block is found, it is not marked, and written on both sides, with respect to the different file positions. If a block is not found, it is marked with a "-", and written on the left side.

+ 00000024 AA BB CC DD EE Compare Algorithm Two found blocks, or after the last found block). Additionally, the resulting text file will contain lines that show bytes that were added in File 2 (either before the first found block, or between The idea of this procedure is that the bytes of File 1 will be displayed like in a normal hex editor, with 16 bytes per line, whereas the bytes of File 2 will be moved in a way so the user can easily compare File 1 and File 2. For each block, the resulting text file will contain a line that shows whether these 16 bytes were found, and if so, where they were found. What it doesīinDiff reads File 1 in blocks of 16 bytes, and tries to find each block in File 2. Furthermore, I wanted to save the results of each comparison in a separate text file, for later analysis. Most binary file comparison tools (like for example "BinCoMerge") are very slow when it's about comparing large files that have many small differences where bytes are added or removed. The main purpose was to detect changes in an audio transmission, resulting from the clock drift of several gateways the audio stream was passed through. I needed a simple tool to compare two binary files, especially focusing on small sequences of added or removed bytes.
