douxie3625 2014-10-06 23:14
浏览 40

使用PHP返回二进制文件中的十六进制差异

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:
"; // result = 1 
    echo $diff;
}

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

  • 写回答

1条回答 默认 最新

  • dongqi4085 2014-10-07 00:52
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥15 正弦信号发生器串并联电路电阻无法保持同步怎么办
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序