0

I've read and tried every answer here, yet they seem to only apply to strings in non-binary formats. I'm trying to compare differences in binary files and return those in format such as this:

[file1]

-0001010: ac 0f 00 00 01 00 00 00 48 65 6c 6c 6f 2c 20 77  ........Hello, w

[file2]

+0001010: ac 0f 00 00 01 00 00 00 48 75 6c 6c 6f 2c 20 77  ........Hullo, w

xdiff works fine for creating bdiff patches and patching file - I'm looking too illustrate the differences.

$one = 'one'; // original file
$two = 'two'; // updated file
$pat = 'dif'; // bdiff patch
$new = 'new'; // new destfile

xdiff_file_diff_binary($one, $two, $pat);
xdiff_file_patch_binary($one, $pat, $new);

$diff = xdiff_file_diff($one, $two, 1);
if (is_file($diff)) {
    echo "Differences:\n"; // result = 1 
    echo $diff;
}

Maybe xdiff isn't the right extension to be using for this? I'm not sure.

Community
  • 1
  • 1
Devon
  • 127
  • 1
  • 1
  • 7

1 Answers1

0

Sound like a big pain in the butt to do in PHP, might I suggest the following bash one-liner?

diff <(hexdump -C file1) <(hexdump -C file2)

Output:

10c10
< 00000090  35 35 61 34 32 62 62 31  30 33 31 62 38 38 39 34  |55a42bb1031b8894|
---
> 00000090  35 35 61 34 32 62 62 31  30 33 31 61 38 38 39 34  |55a42bb1031a8894|

And you can always mess with the options for diff and hexdump.

Sammitch
  • 30,782
  • 7
  • 50
  • 77
  • Nice idea, but when I try to use it with `exec()` for example I get an error: `sh: -c: line 0: syntax error near unexpected token` `(' – Devon Oct 07 '14 at 01:25
  • @Devon Because it's a *bash* one-liner, and your system is defaulting to `sh` for `exec()`. – Sammitch Oct 07 '14 at 16:40