Linux: View and Edit Binary Files

from: https://blog.youkuaiyun.com/wangxiaoqin00007/article/details/6618003

一、在Linux下查看二进制文件的软件:

xxd (2进制)

hexdump  (16进制)

 

二、编辑:

1、biew

2、hexedit

3、vim

Vim 来编辑二进制文件。Vim 本非为此而设计的,因而有若干局限。但你能读
取一个文件,改动一个字符,然后把它存盘。结果是你的文件就只有那一个字符给改了,
其它的就跟原来那个一模一样。
   要保证 Vim 别把它那些聪明的窍门用错地方,启动 Vim 时加上 "-b" 参数:
        vim -b datafile
这个参数设定了 'binary' 选项。其作用是排除所有的意外副作用。例如,'textwidth'
设为零,免得文本行给擅自排版了。并且,文件一律以 Unix 文件格式读取。
二进制模式可以用来修改某程序的消息报文。小心别插入或删除任何字符,那会让程序运
行出问题。用 "R" 命令进入替换模式。
文件里的很多字符都是不可显示的。用 Hex 格式来显示它们的值:
        :set display=uhex
另外,也可以用命令 "ga"  来显示光标下的字符值。当光标位于一个  字符上时,
该命令的输出看起来就像这样:
          27, Hex 1b,  Octal 033
文件中也许没那么多换行符。你可以关闭 'wrap' 选项来获得总览的效果:
        :set nowrap
字 节 位 置
要发现你在文件中的当前字节位置,请用这个命令:
        g CTRL-G
其输出十分冗长:
    Col 9-16 of 9-16; Line 277 of 330; Word 1806 of 2058; Byte 10580 of 12206
最后两个数字就是文件中的当前字节位置和文件字节总数。这已经考虑了 'fileformat'
选项导致换行符字节不同的影响。
    要移到文件中某个指定的字节,请用 "go" 命令。例如,要移到字节 2345:
        2345go
使 用 XXD
一个真正的二进制编辑器用两种方式来显示文本: 二进制和十六进制格式。你可以在 Vim
里通过转换程序 "xxd" 来达到这效果。该程序是随 Vim 一起发布的。
   首先以二进制方式编辑这个文件:
        vim -b datafile
现在用 xxd 把这个文件转换成十六进制:
        :%!xxd
文本看起来像这样:
        0000000: 1f8b 0808 39d7 173b 0203 7474 002b 4e49  ....9..;..tt.+NI
        0000010: 4b2c 8660 eb9c ecac c462 eb94 345e 2e30  K,.`.....b..4^.0
        0000020: 373b 2731 0b22 0ca6 c1a2 d669 1035 39d9  7;'1.".....i.59.
现在你可以随心所欲地阅读和编辑这些文本了。 Vim 把这些信息当作普通文本来对待。
修改了十六进制部分并不导致可显示字符部分的改变,反之亦然。
   最后,用下面的命令把它转换回来:
        :%!xxd -r
只有十六进制部分的修改才会被采用。右边可显示文本部分的修改忽略不计。

 

Linux: (od)查看二进制文件

from: https://www.cnblogs.com/yongdaimi/p/12326496.html

查看二进制文件,用od或hexdump命令。

复制代码

$ od -tx1 -tc -Ax binFile
000000  61  62  63  64  65  31  32  33  34  35  61  62  63  64  65  31
         a   b   c   d   e   1   2   3   4   5   a   b   c   d   e   1
000010  32  33  34  35  61  62  63  64  65  31  32  33  34  35  61  62
         2   3   4   5   a   b   c   d   e   1   2   3   4   5   a   b
000020  63  64  65  31  32  33  34  35  0a
         c   d   e   1   2   3   4   5  \n
000029

复制代码

-tx1选项表示将文件中的字节以十六进制的形式列出来,每组一个字节(类似hexdump的-c选项)

-tc选项表示将文件中的ASCII码以字符形式列出来(和hexdump类似,输出结果最左边的一列是文件中的地址,默认以八进制显示)

-Ax选项要求以十六进制显示文件中的地址

===> this function can automatically pick out the heading null/'0' bytes

e.g.

//under less

==> use :gg to jump to the beginning of the file, use :G to jump to the end;

Key Features Grasp the intricacies of the ELF binary format of UNIX and Linux Design tools for reverse engineering and binary forensic analysis Insights into UNIX and Linux memory infections, ELF viruses, and binary protection schemes Book Description Learning Linux Binary Analysis is packed with knowledge and code that will teach you the inner workings of the ELF format, and the methods used by hackers and security analysts for virus analysis, binary patching, software protection and more. This book will start by taking you through UNIX/Linux object utilities, and will move on to teaching you all about the ELF specimen. You will learn about process tracing, and will explore the different types of Linux and UNIX viruses, and how you can make use of ELF Virus Technology to deal with them. The latter half of the book discusses the usage of Kprobe instrumentation for kernel hacking, code patching, and debugging. You will discover how to detect and disinfect kernel-mode rootkits, and move on to analyze static code. Finally, you will be walked through complex userspace memory infection analysis. This book will lead you into territory that is uncharted even by some experts; right into the world of the computer hacker. Table of Contents Chapter 1. The Linux Environment and Its Tools Chapter 2. The ELF Binary Format Chapter 3. Linux Process Tracing Chapter 4. ELF Virus Technology – Linux/Unix Viruses Chapter 5. Linux Binary Protection Chapter 6. ELF Binary Forensics in Linux Chapter 7. Process Memory Forensics Chapter 8. ECFS – Extended Core File Snapshot Technology Chapter 9. Linux /proc/kcore Analysis
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值