亚洲视频二区_亚洲欧洲日本天天堂在线观看_日韩一区二区在线观看_中文字幕不卡一区

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.430618.com 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

1linux環境xxd命令如何編輯/修改二進制文件

xxd工具雖然不能直接修改二進制文件,但xxd -r參數可把Hexdump文本轉成二進制內容。convert (or patch) hexdump into binary.

因此,對于要修改的二進制文件,可以先轉為Hexdump文本,再通過xxd -r命令把Hexdump文本轉為二進制文件。

[mycc@wen*z:~]$ xxd file1.binary
0000000: 1234 0001 0000 0000 2022 0103 9900 000c  .4...... "......
0000010: 22f9 0100 0041 3106 1992 6741 3106 1992  "....A1...gA1...
0000020: 6700 00f7 0100 001f 0933 0900 0000 0310  g........3......
0000030: 4800 0000 7156 0559 71fb 0102 2c01 0130  H...qV.Yq...,..0
[mycc@wen*z:~]$ xxd file1.binary > file1.txt 
[mycc@wen*z:~]$ vi file1.txt 
[mycc@wen*z:~]$ cat file1.txt 
0000000: abcd 0001 0000 0000 2022 0103 9900 000c  .4...... "......
0000010: 22f9 0100 0041 3106 1992 6741 3106 1992  "....A1...gA1...
0000020: 6700 00f7 0100 001f 0933 0900 0000 0310  g........3......
0000030: 4800 0000 7156 0559 71fb 0102 2c01 0130  H...qV.Yq...,..0
[mycc@wen*z:~]$ xxd -r file1.txt  file1.binary
[mycc@wen*z:~]$ xxd file1.binary
0000000: abcd 0001 0000 0000 2022 0103 9900 000c  ........ "......
0000010: 22f9 0100 0041 3106 1992 6741 3106 1992  "....A1...gA1...
0000020: 6700 00f7 0100 001f 0933 0900 0000 0310  g........3......
0000030: 4800 0000 7156 0559 71fb 0102 2c01 0130  H...qV.Yq...,..0
xxd命令修改和查看二進制文件

xxd修改二進制文件示例

2用xxd查看二進制文件

2.1查看二進制文件

[mycc@wen*z:~]$ xxd file1.binary
0000000: 1234 0001 0000 0000 2022 0103 9900 000c  .4...... "......
0000010: 22f9 0100 0041 3106 1992 6741 3106 1992  "....A1...gA1...
0000020: 6700 00f7 0100 001f 0933 0900 0000 0310  g........3......
0000030: 4800 0000 7156 0559 71fb 0102 2c01 0130  H...qV.Yq...,..0

2.2.查看指定字節數量內容:-l參數表示長度

xxd -l 32 file1.binary 查看前32個字節

[mycc@wen*z:~]$ xxd -l 32 file1.binary 
0000000: 1234 0001 0000 0000 2022 0103 9900 000c  .4...... "......
0000010: 22f9 0100 0041 3106 1992 6741 3106 1992  "....A1...gA1...

2.3查看指定偏移位置后的內容:-s參數表示偏移位置(從0開始),當值為負數時為從尾向前數偏移

xxd -s 16 file1.binary 查看從16字節開始的內容

[mycc@wen*z:~]$ xxd -s 16  file1.binary 
0000010: 22f9 0100 0041 3106 1992 6741 3106 1992  "....A1...gA1...
0000020: 6700 00f7 0100 001f 0933 0900 0000 0310  g........3......
0000030: 4800 0000 7156 0559 71fb 0102 2c01 0130  H...qV.Yq...,..0

xxd -s -16查看最后16字節內容

[mycc@wen*z:~]$ xxd -s -16 file1.binary 
0000030: 4800 0000 7156 0559 71fb 0102 2c01 0130  H...qV.Yq...,..0

2.4 限定每行輸出的字節數:-c 參數,限定每行字節數量

xxd -c 8 file1.binary查看內容,每行8字節

[mycc@wen*z:~]$ xxd -c 8 file1.binary 
0000000: 1234 0001 0000 0000  .4......
0000008: 2022 0103 9900 000c   "......
0000010: 22f9 0100 0041 3106  "....A1.
0000018: 1992 6741 3106 1992  ..gA1...
0000020: 6700 00f7 0100 001f  g.......
0000028: 0933 0900 0000 0310  .3......
0000030: 4800 0000 7156 0559  H...qV.Y
0000038: 71fb 0102 2c01 0130  q...,..0

2.5以純Hex字符輸出:-p參數表示無空格,無序號,無ascii格式部分

xxd -p file.binary

[mycc@wen*z:~]$ xxd -p file1.binary 
1234000100000000202201039900000c22f9010000413106199267413106
1992670000f70100001f0933090000000310480000007156055971fb0102
2c010130

 

2.6將二進制文件內容轉為C語言內容:-i參數

xxd -i file1.binary將二進制文件內容轉為c數組,這在某些測試過程中是有用的

[mycc@wen*z:~]$ xxd -i file1.binary
unsigned char file1_binary[] = {
  0x12, 0x34, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x20, 0x22, 0x01, 0x03,
  0x99, 0x00, 0x00, 0x0c, 0x22, 0xf9, 0x01, 0x00, 0x00, 0x41, 0x31, 0x06,
  0x19, 0x92, 0x67, 0x41, 0x31, 0x06, 0x19, 0x92, 0x67, 0x00, 0x00, 0xf7,
  0x01, 0x00, 0x00, 0x1f, 0x09, 0x33, 0x09, 0x00, 0x00, 0x00, 0x03, 0x10,
  0x48, 0x00, 0x00, 0x00, 0x71, 0x56, 0x05, 0x59, 0x71, 0xfb, 0x01, 0x02,
  0x2c, 0x01, 0x01, 0x30
};
unsigned int file1_binary_len = 64;

2.7綜合利用上面參數示例

xxd -p -s 16 -l 32 -c 8 file1.binary 偏移16字節,輸出32個字節內容,每行輸出8字節,以純Hex方式顯示

[mycc@wen*z:~]$ xxd -p -s 16 -l 32 -c 8 file1.binary
22f9010000413106
1992674131061992
670000f70100001f
0933090000000310

xxd --help
[mycc@wen*z:~]$ xxd --help
Usage:
       xxd [options] [infile [outfile]]
    or
       xxd -r [-s [-]offset] [-c cols] [-ps] [infile [outfile]]
Options:
    -a          toggle autoskip: A single '*' replaces nul-lines. Default off.
    -b          binary digit dump (incompatible with -ps,-i,-r). Default hex.
    -c cols     format <cols> octets per line. Default 16 (-i: 12, -ps: 30).
    -E          show characters in EBCDIC. Default ASCII.
    -g          number of octets per group in normal output. Default 2.
    -h          print this summary.
    -i          output in C include file style.
    -l len      stop after <len> octets.
    -ps         output in postscript plain hexdump style.
    -r          reverse operation: convert (or patch) hexdump into binary.
    -r -s off   revert with <off> added to file positions found in hexdump.
    -s [+][-]seek  start at <seek> bytes abs. (or +: rel.) infile offset.
    -u          use upper case hex letters.
    -v          show version: "xxd V1.10 27oct98 by Juergen Weigert".

分享到:
標簽:命令 xxd
用戶無頭像

網友整理

注冊時間:

網站:5 個   小程序:0 個  文章:12 篇

  • 51998

    網站

  • 12

    小程序

  • 1030137

    文章

  • 747

    會員

趕快注冊賬號,推廣您的網站吧!
最新入駐小程序

數獨大挑戰2018-06-03

數獨一種數學游戲,玩家需要根據9

答題星2018-06-03

您可以通過答題星輕松地創建試卷

全階人生考試2018-06-03

各種考試題,題庫,初中,高中,大學四六

運動步數有氧達人2018-06-03

記錄運動步數,積累氧氣值。還可偷

每日養生app2018-06-03

每日養生,天天健康

體育訓練成績評定2018-06-03

通用課目體育訓練成績評定