〖Linux〗使用sed命令修改小端(little endian)存储的数据

 1 #!/bin/bash - 
 2 #===============================================================================
 3 #
 4 #          FILE: hex_change.sh
 5 # 
 6 #         USAGE: ./hex_change.sh 
 7 # 
 8 #   DESCRIPTION: 
 9 # 
10 #       OPTIONS: ---
11 #  REQUIREMENTS: ---
12 #          BUGS: ---
13 #         NOTES: ---
14 #        AUTHOR: linkscue (scue), linkscue@gmail.com
15 #  ORGANIZATION: 
16 #       CREATED: 2014年08月07日 00时05分55秒 CST
17 #      REVISION:  ---
18 #===============================================================================
19 
20 # hex_change 修改二进制文件
21 # 语法:hex_change 00ABCDEF 00ABCDEF file
22 #       hex_change [0x]00ABCDEF [0x]00ABCDEF file
23 hex_change(){
24     local hex=${1#0x}
25     local hexnew=${2#0x}
26     local bin=$3
27     hex=$(echo $hex|tr a-z A-Z)                 # 小写转大写
28     hexnew=$(echo $hexnew|tr a-z A-Z)           # 小写转大写
29     echo "convert hex: 0x$hex 0x$hexnew"
30     p1="\x${hex:6:2}"
31     p2="\x${hex:4:2}"
32     p3="\x${hex:2:2}"
33     p4="\x${hex:0:2}"
34     pn1="\x${hexnew:6:2}"
35     pn2="\x${hexnew:4:2}"
36     pn3="\x${hexnew:2:2}"
37     pn4="\x${hexnew:0:2}"
38     echo sed -i "s/$p1$p2$p3$p4/$pn1$pn2$pn3$pn4/g" $bin
39     sed -i "s/$p1$p2$p3$p4/$pn1$pn2$pn3$pn4/g" $bin
40 }
41 
42 hex_change ABCDEF55 DDCCBBAA ./1.bin

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值