hexdump related.
hexdump format strings
Tue 13 December 2005
In tips.
Ian WienandMore from the "things you'd learn if you read the manual" department, although the manual as currently written is a little esoteric on this feature of hexdump.
$ hexdump -e ' [iterations]/[byte_count] "[format string]" '
As you might guess, this means apply format string to groups of byte_count bytes, iterations times. Format string is likeprintf.
You can of course chain multiple formats together, or put them in a file. So say you needed to clag some binary data into a C array, a-la firmware for loading into a driver. You could use
$ hexdump -v -e '6/4 "0x%08x, "' -e '"\n"' ./dump
to get something that fits in 80 columns and is almost ready to go.
Manual on How to Use the Hexdump Unix Utility
Every time I go to use hexdump I find myself stumbling over it's bizarre argument format and ineffectual manual. Because I look at binary files often I decided to work up this page more for myself than anyone else.
Here is a sample usage of hexdump:
cat file | hexdump -v -e '"\\\x" 1/1 "%02x" " "'
And here is some sample output from it:
\x97\x6d\xea\xd1\x21\x02\x12\x80\x01\x9d...
Argument Description
The -v argument is needed to not print duplicate chars as a *. The -e argument has 5 parts separated by whitespace. I'm not sure how multiple format entries interact.
- An optional starting string (in quotes) which is printed before each conversion. In the first example below we are printing x before each hex character ("x").
- An interation count which defaults to 1 if not supplied but has to be supplied if you want a byte count. This tells how many times to do the conversion before we print the end string. So if you were decoding 4 things, each of 1 byte, you'd say 4/1.
- A byte count which is separated from the interation count by a /. I don't think there is a way to specify a byte count without an interation count. This specifies how many bytes are in each item that is being decoded.
- A sprintf format. The manual is somewhat useful here. Some standard ones apply and there are _ extensions. In the first example below this is "%02X" which prints each byte as a 2 character, 0 prefixed capital hex number.
- An optional ending string (in quotes) which is printed after the conversion. A space in the first example below (" ").
Format Examples
Print an "x" to start, take 1 item / 1 byte, print it as a 2 digit 0 prefixed hex value ("%02X"), and end with a space.
echo "hello there" | hexdump -v -e '"x" 1/1 "%02X" " "'
Outputs something like:
x68 x65 x6C x6C x6F x20 x74 x68 x65 x72 x65 x0A
Print an "[" to start, take 2 items / each 1 byte, print them as a 3 digit 0 prefixed octal value followed by a space ("%03o "), and end with "]\n".
echo "hello there" | hexdump -v -e '"[" 2/1 "%03o " "]\n"'
Outputs something like:
[150 145]
[154 154]
[157 040]
[164 150]
[145 162]
[145 012]
NOTE: the trailing space in "%03o " format will not be printed at the end of each interation.
hexdump related.的更多相关文章
- MS SQL错误:SQL Server failed with error code 0xc0000000 to spawn a thread to process a new login or connection. Check the SQL Server error log and the Windows event logs for information about possible related problems
早晨宁波那边的IT人员打电话告知数据库无法访问了.其实我在早晨也发现Ignite监控下的宁波的数据库服务器出现了异常,但是当时正在检查查看其它服务器发过来的各类邮件,还没等到我去确认具体情 ...
- Linux命令学习总结:hexdump
命令简介: hexdump是Linux下的一个二进制文件查看工具,它可以将二进制文件转换为ASCII.八进制.十进制.十六进制格式进行查看. 指令所在路径:/usr/bin/hexdump 命令语法: ...
- 用hexdump获取event的输出信息
当我们在调试输入设备时,如:键盘,触摸屏 会使用到hexdump工具.其内容如下: 1. 键盘: # cat /dev/input/event0 | hexdump 0000000 f6a6 4e15 ...
- 使用 hexdump dump 文件内容
名词解释 [dump] dump 是指把文件的内容,每个字节用2位十六进制数来表示的方式. 缘由 最近看矢泽久雄的<How Program Works>,了解到 dump “exe文件”( ...
- How to remove a batch of VMs and related Disks
Foreword Need to remove a batch of VMs, which named with same prefix or belong to same Cloud Service ...
- hexdump—Linux系统的二进制文件查看工具
hexdump 无参: 相当于 hexdump -x 0000000 457f 464c 0102 0001 0000 0000 0000 0000 0000010 0002 003e 0001 00 ...
- SharePoint Server 2010 & WorkFlow related Limits
Today, I have come across different workflow related limits for SharePoint Server 2010. Limit Maximu ...
- HexDump.java解析
从包名我们可以看出该类并没有对应用开发者开放,也就是说在google开放的Android API文档中并没有该类的相关介绍:好在Android系统源码是开源的,因此我在解决framework中问题的时 ...
- PeopleSoft Related Language Records
As we all know, PeopleSoft is capable of maintaining application data in multiple languages within t ...
随机推荐
- 洛谷P1273 有线电视网 【树上分组背包】
题目描述 某收费有线电视网计划转播一场重要的足球比赛.他们的转播网和用户终端构成一棵树状结构,这棵树的根结点位于足球比赛的现场,树叶为各个用户终端,其他中转站为该树的内部节点. 从转播站到转播站以及从 ...
- POJ.3087 Shuffle'm Up (模拟)
POJ.3087 Shuffle'm Up (模拟) 题意分析 给定两个长度为len的字符串s1和s2, 接着给出一个长度为len*2的字符串s12. 将字符串s1和s2通过一定的变换变成s12,找到 ...
- python基础----函数的定义和调用、return语句、变量作用域、传参、函数嵌套、函数对象、闭包、递归函数
1.函数的定义: 函数是组织好的,可重复使用的,用来实现单一,或相关联功能的代码段. 函数能提高应用的模块性,和代码的重复利用率.你已经知道Python提供了许多内建函数,比如print().但你也可 ...
- json数据的格式
JSON的具体形式 1.对象是一个无序的“‘名称/值’对”集合.一个对象以“{”开始,以“}”结束.每个“名称”后跟一个“:”,“‘名称/值’对”之间使用“,”分隔. 举个例子: { name:&qu ...
- sloop公共程序之总体描述
1:功能需求 开发一个公共库文件sloop.c,实现三个常用功能以供其它模块调用.三个功能如下: 功能一:实现一般的信号监听,调用模块只需传入要监听的信号和相应的回调函数就可以在信号到时调用回调函数处 ...
- nova-conductor与AMQP(一)
源码版本:H版 一.AMQP基础 1. 什么是AMQP 可以参考如下文章: http://blog.csdn.net/linvo/article/details/5750987 http://blog ...
- CSS选择器-常用搜集
标签选择器: div{ font-size=10px; color=red; background-color=yello; width=200px; height=200px; } <div& ...
- hdu4699-Editor
Sample Input 8 I 2 I -1 I 1 Q 3 L D R Q 2 Sample Output 2 3 发现IDLR四种操作都在光标处发生,且操作完成后光标至多移动1个位置,根据这种“ ...
- UVA 11982 Fantasy Cricket
https://vjudge.net/problem/UVA-11982 题意: 给出一个包含’U’, ‘D’, ‘E’的字符串, ’U’ 表示需要把这个字符向后移动, ’D’表示需要把这个字符向前移 ...
- HTML 5 Web 存储:localStorage和sessionStorage
本文内容摘自http://www.w3school.com.cn/ 在客户端存储数据 HTML5 提供了两种在客户端存储数据的新方法: localStorage - 没有时间限制的数据存储 sessi ...