Tutorial: Reverse debugging with GDB 7 (转载)
Porting of cURL to Android OS using NDK (from The Software Rogue)

hexdump related.

tubo posted @ 2014年9月03日 00:09 in 未分类 , 574 阅读

hexdump format strings

Tue 13 December 2005

In tips.

 

Ian Wienand

 

More 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.

  1. 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").
  2. 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.
  3. 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.
  4. 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.
  5. 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.

meidir 说:
2023年2月09日 02:18

Just to follow up on the up-date of this subject on your web page and wish to let you know just how much I prized the time you took to publish this beneficial post. Within the post, you actually spoke regarding how to truly handle this challenge with all comfort. It would be my own pleasure to collect some more thoughts from your web-site and come up to offer other folks what I have benefited from you. Thanks for your usual good effort. Software Contract Attorney

meidir 说:
2023年6月04日 02:43

very nice post, i definitely enjoy this amazing site, persist with it iPad回收

 

 

====================

 

 

Thanks for the post, was an interesting read. Curious as to how you came about that solution… Macbook tradein

 

 

====================

 

 

inspiring insights you are sharing. I love the way you are sharing it. Is there any way I could get updated for more? 電競電腦

 

 

====================

 

 

This website is my inhalation, really fantastic layout and Perfect written content. 魔術表演

meidir 说:
2023年6月20日 02:48

I am also commenting to let you understand of the fantastic encounter my friend’s child experienced using your web site. She picked up too many pieces, which included what it is like to possess an incredible coaching style to let certain people without difficulty gain knowledge of some tricky subject matter. You really exceeded visitors’ desires. I appreciate you for offering those informative, healthy, edifying and unique tips about the topic to Ethel. 花藝學校

meidir 说:
2023年6月23日 22:06

I am impressed with this internet site , real I am a big fan . technology lawyer new jersey

meidir 说:
2023年7月16日 06:37 Regards for all your efforts that you have put in this. Very interesting information. 강남안마 가이드
meidir 说:
2023年10月28日 20:42

I have been absent for some time, but now I remember why I used to love this site. Thank you, I’ll try and check back more often. How frequently do you update your web site? mpo100

 

========================

 

Whoa that guideline is astonishing it truly helped me and my family, thanks a lot! mpo100

 

========================

 

very good post, i definitely really like this website, continue it link mpo100

meidir 说:
2023年11月12日 07:33

Hello this is amazing site! really cool and it will be a new inspirations for me online memorial

meidir 说:
2023年12月10日 07:37

This is such an informationrmative story and very clearly written. Every single thought and idea is direct to the point. Perfectly laid out. cheers for taking your time sharing this to you readers. Débouchage lavano every

meidir 说:
2023年12月21日 07:06

I am not sure if you mean that you want to write a weblog but don’t want the templates that come supplied with places like Doodlekit… or if you mean you would like to use the content material from another blog - not written by you - in your web site. black dollar

meidir 说:
2023年12月23日 20:35

Outstanding post, I conceive blog owners should acquire a lot from this blog its very user pleasant. 手機回收

 

 

===================

 

 

Naturally I like your web site, however you have to check the spelling on quite a few of your posts. A number of them are rife with spelling problems and I find it very bothersome to tell you. Nevertheless I will surely come again again! 手機回收

 

 

===================

 

 

I’d must verify with you here. Which isn’t something I often do! I take pleasure in reading a post that may make people think. Additionally, thanks for allowing me to comment! iphone回收價格表

 

 

===================

 

 

I admire the useful facts you offer inside your articles. I will bookmark your weblog and also have my children verify up here often. I’m very sure they’ll learn a lot of new things right here than anybody else! iphone 回收

meidir 说:
2023年12月27日 03:25

Hello! I just wanted to ask if you ever have any issues with hackers? My last blog (wordpress) was hacked and I ended up losing several weeks of hard work due to no back up. Do you have any methods to stop hackers? Black money cleaning chemicals Qatar

meidir 说:
2024年1月10日 05:59

produce,Underneath the celestial satellite of affection remedy blokes sensible sweetheart is aware of two of the more poor on the opportunity to begin, and that is your boyfriend’s beloved duration of the guiltiness, impressive perfect spare time on her. IOP drug rehabs West Palm Beach

 

 

=================

 

 

when i was a kid, i really enjoyed going up and down on water slides, it is a very enjoyable experience.. alcohol detox centers San Diego

 

 

=================

 

 

You should participate in a contest for among the best blogs on the web. I will advocate this website! drug rehab SEO

 

 

==================

 

 

Thanks for any other magnificent article. Where else may just anybody get that kind of information in such a perfect method of writing? I have a presentation next week, and I’m on the look for such information. drug rehabs Encinitas

meidir 说:
2024年1月14日 10:56

very good post, i surely adore this fabulous website, persist in it social networking

meidir 说:
2024年1月19日 10:52

I conceive other website proprietors should take this web site as an example , very clean and wonderful user pleasant pattern . housing

meidir 说:
2024年2月03日 08:55

Hey, I just started reading your blog – thank you for writing. As an FYI that it’s not displaying properly on the BlackBerry Browser (I have a Pearl). Anyway, I’m now subscribed to your RSS feed on my laptop, so thanks again! plombier tours

meidir 说:
2024年2月05日 08:20

The next time I read a blog, I hope that it doesnt disappoint me as much as this one. I imply, I know it was my option to learn, however I actually thought youd have something fascinating to say. All I hear is a bunch of whining about something that you might repair in case you werent too busy searching for attention. iphone 回收

 

================

 

Hi! I just wanted to ask if you ever have any problems with hackers? My last blog (wordpress) was hacked and I ended up losing months of hard work due to no backup. Do you have any methods to protect against hackers? 回收iphone

 

================

 

This web site is really a walk-through you discover the knowledge it suited you about this and didn’t know who to inquire about. Glimpse here, and you’ll undoubtedly discover it. tradein iPhone

 

================

 

An fascinating discussion may be worth comment. I think that you should write regarding this topic, it will not often be a taboo subject but generally persons are inadequate to talk on such topics. To another. Cheers ipad 回收

meidir 说:
2024年2月23日 14:17

I can’t really help but admire your blog. your blog is so adorable and nice .   Agencja Eventowa Warszawa

 

=================

 

I’m not sure why but this site is loading very slow for me. Is anyone else having this problem or is it a problem on my end? I’ll check back later on and see if the problem still exists. Global Marketing Agency

 

=================

 

Hello! I recently would want to provide a enormous thumbs up for that excellent information you’ve got here about this post. I’ll be coming back to your website to get more soon. Ośrodek terapii uzależnień

 

================

 

You should take part in a contest for one of the best blogs on the web. I will recommend this page! sklep kawiory

 

================

 

Lebron James Is A Clown You Know White Face Paint Red Nose Floppy Shoes ranking kancelarii prawnych

 

================

 

Is There A Way A Minor Can Make Money Online For Free?: I am looking for any legitimate sites that i can make a li najlepsze ośrodki terapii

 

================

 

Hey, just looking around some blogs, seems a pretty nice platform you are using and the theme as well. I’m currently using WordPress for a few of my sites but looking to change one of them over to a platform similar to yours as a trial run. Anything in particular you would recommend about it? Have a nice day! HoReCa

 

================

 

Spot on with this write-up, I truly think this web site needs much more consideration. I’ll probably be once more to read rather more, thanks for that info. Najlepsza Agencja SEO

 

================

 

I’m not sure exactly why but this weblog is loading incredibly slow for me. Is anyone else having this problem or is it a problem on my end? I’ll check back later and see if the problem still exists. Nakatomi

 

================

 

Thankyou for this post, I am a big fan of this website would like to keep updated. doors producer

 

================

 

Aw, this is an extremely good post. In notion I would like to place in writing such as this additionally – taking time and actual effort to create a great article… but exactly what can I say… I procrastinate alot and also by no means appear to get something completed. Życie w Norwegii

 

================

 

Hello! I want to give you a enormous thumbs up for that fantastic information you might have here on this post. We are coming back to your blog for much more soon. pożyczki w Norwegii

Meidir 说:
2024年4月17日 07:51

Ta very much for the update, extremely useful. Do you thoughts If I can I use an extract or two on my web page? https://betonred.one/


登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter