免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: 把握今天
打印 上一主题 下一主题

怎样分离一个二进制文件? [复制链接]

论坛徽章:
5
2015年辞旧岁徽章
日期:2015-03-03 16:54:152015年迎新春徽章
日期:2015-03-04 09:50:282015年亚洲杯之朝鲜
日期:2015-03-13 22:47:33IT运维版块每日发帖之星
日期:2016-01-09 06:20:00IT运维版块每周发帖之星
日期:2016-03-07 16:27:44
11 [报告]
发表于 2011-03-21 13:28 |只看该作者
回复 10# Shell_HAT


    可以按字节来分啊。

论坛徽章:
0
12 [报告]
发表于 2011-03-21 16:46 |只看该作者
加入分割符吧。

论坛徽章:
3
天秤座
日期:2013-12-27 13:44:58射手座
日期:2014-05-22 16:52:43天蝎座
日期:2014-08-13 16:03:21
13 [报告]
发表于 2011-03-21 16:57 |只看该作者
在此,我想问个问题:
读取二进制文件的内容,并且能够正确的显示。请问各位,用什么命令,3Q!!!!

论坛徽章:
33
ChinaUnix元老
日期:2015-02-02 08:55:39CU十四周年纪念徽章
日期:2019-08-20 08:30:3720周年集字徽章-周	
日期:2020-10-28 14:13:3020周年集字徽章-20	
日期:2020-10-28 14:04:3019周年集字徽章-CU
日期:2019-09-08 23:26:2519周年集字徽章-19
日期:2019-08-27 13:31:262016科比退役纪念章
日期:2022-04-24 14:33:24
14 [报告]
发表于 2011-03-21 20:57 |只看该作者
回复 11# blackold


我就是想看看楼主有没有找到啥通用的方法

论坛徽章:
0
15 [报告]
发表于 2011-03-21 23:07 |只看该作者
可以用tail分离, 很多shell写的安装脚本就是把二进制的压缩包附在shell脚本后面. 比如java的安装包.

论坛徽章:
0
16 [报告]
发表于 2011-03-22 01:52 |只看该作者
是不是可以这样:dd命令分割二进制文件:

  1. [root@linux split]# cp /bin/ls ./
  2. [root@linux split]# cp /bin/echo ./
  3. [root@linux split]# ls
  4. echo  ls
  5. [root@linux split]# cat echo ls >sum
  6. [root@linux split]# ls
  7. echo  ls  sum
  8. [root@linux split]# ll
  9. total 252
  10. -rwxr-xr-x 1 root root  19852 Mar 20 18:47 echo
  11. -rwxr-xr-x 1 root root  95116 Mar 20 18:47 ls
  12. -rw-r--r-- 1 root root 114968 Mar 20 18:47 sum
  13. [root@linux split]# dd if=sum of=echo2 bs=1 count=19852
  14. 19852+0 records in
  15. 19852+0 records out
  16. 19852 bytes (20 kB) copied, 0.431886 seconds, 46.0 kB/s
  17. [root@linux split]# chmod u+x echo2
  18. [root@linux split]# ./echo2 chinaunix
  19. chinaunix
  20. [root@linux split]# dd if=sum of=ls2 ibs=1 skip=19852 bs=1 count=95116
  21. 95116+0 records in
  22. 95116+0 records out
  23. 95116 bytes (95 kB) copied, 2.1091 seconds, 45.1 kB/s
  24. [root@linux split]# chmod u+x ls2
  25. [root@linux split]# ./ls2 -l
  26. total 380
  27. -rwxr-xr-x 1 root root  19852 Mar 20 18:47 echo
  28. -rwxr--r-- 1 root root  19852 Mar 20 18:48 echo2
  29. -rwxr-xr-x 1 root root  95116 Mar 20 18:47 ls
  30. -rwxr--r-- 1 root root  95116 Mar 20 18:49 ls2
  31. -rw-r--r-- 1 root root 114968 Mar 20 18:47 sum
  32. [root@linux split]#
复制代码

论坛徽章:
0
17 [报告]
发表于 2011-03-22 02:04 |只看该作者
然后dd命令分割普通文本文件:

  1. [root@linux split]# cat 1.txt
  2. this is the 1.txt content
  3. first line
  4. second line
  5. [root@linux split]# cat 2.txt
  6. this is the 2.txt content
  7. first line
  8. second line
  9. third line
  10. [root@linux split]# cat 1.txt 2.txt >sum.txt
  11. [root@linux split]# cat sum.txt
  12. this is the 1.txt content
  13. first line
  14. second line
  15. this is the 2.txt content
  16. first line
  17. second line
  18. third line
  19. [root@linux split]# ll
  20. total 24
  21. -rw-r--r-- 1 root root  49 Mar 20 18:55 1.txt
  22. -rw-r--r-- 1 root root  60 Mar 20 18:56 2.txt
  23. -rw-r--r-- 1 root root 109 Mar 20 19:01 sum.txt
  24. [root@linux split]# dd if=sum.txt of=1.2.txt bs=1 count=49
  25. 49+0 records in
  26. 49+0 records out
  27. 49 bytes (49 B) copied, 0.00130533 seconds, 37.5 kB/s
  28. [root@linux split]# diff 1.txt 1.2.txt
  29. [root@linux split]# cat 1.2.txt
  30. this is the 1.txt content
  31. first line
  32. second line
  33. [root@linux split]# dd if=sum.txt of=2.2.txt ibs=1 skip=49  bs=1 count=60
  34. 60+0 records in
  35. 60+0 records out
  36. 60 bytes (60 B) copied, 0.00153774 seconds, 39.0 kB/s
  37. [root@linux split]# diff 2.txt 2.2.txt
  38. [root@linux split]# cat 2.2.txt
  39. this is the 2.txt content
  40. first line
  41. second line
  42. third line
  43. [root@linux split]# ll
  44. total 40
  45. -rw-r--r-- 1 root root  49 Mar 20 19:01 1.2.txt
  46. -rw-r--r-- 1 root root  49 Mar 20 18:55 1.txt
  47. -rw-r--r-- 1 root root  60 Mar 20 19:02 2.2.txt
  48. -rw-r--r-- 1 root root  60 Mar 20 18:56 2.txt
  49. -rw-r--r-- 1 root root 109 Mar 20 19:01 sum.txt
  50. [root@linux split]#
复制代码
测试没有问题!

论坛徽章:
1
2015年迎新春徽章
日期:2015-03-04 09:56:11
18 [报告]
发表于 2011-03-22 06:30 |只看该作者
回复 13# compare2000

hexdump
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP