LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-20-2019, 01:57 AM   #1
Chris_M
LQ Newbie
 
Registered: Jul 2018
Posts: 5

Rep: Reputation: Disabled
hexdump returning varying results


I have been playing with hex dump to look at binary files compiled with GCC, I am specifically looking at the structure of ELF files. I created a C program and compiled it and ran

Code:
hexdump temp
then ran
Code:
hexdump -C temp
where temp is the output from gcc.

In the attached images you can see the hex results are not the same for each run, temp was not recompiled in between each run of hexdump. Is anyone able to explain why I am getting different results?
Attached Thumbnails
Click image for larger version

Name:	Untitled.png
Views:	17
Size:	28.8 KB
ID:	30150   Click image for larger version

Name:	Untitled1.png
Views:	22
Size:	30.5 KB
ID:	30151  

Last edited by Chris_M; 03-20-2019 at 01:59 AM.
 
Old 03-20-2019, 02:24 AM   #2
allend
LQ 5k Club
 
Registered: Oct 2003
Location: Melbourne
Distribution: Slackware64-15.0
Posts: 6,377

Rep: Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757Reputation: 2757
Welcome to the joys of Endianness and whether hexdump is reading bytes or words.
 
Old 03-20-2019, 02:57 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,140

Rep: Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123Reputation: 4123
Coming from big-endian, I find the x86 little endian format arcane beyond words.
 
Old 03-20-2019, 03:55 AM   #4
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
Quote:
Originally Posted by Chris_M View Post
Is anyone able to explain why I am getting different results?
Code:
$ hexdump /bin/bash | head -n1
0000000 457f 464c 0101 0001 0000 0000 0000 0000
$ hexdump -d /bin/bash|head -n1
0000000   17791   17996   00257   00001   00000   00000   00000   00000
$ hexdump -C /bin/bash | head
00000000  7f 45 4c 46 01 01 01 00  00 00 00 00 00 00 00 00  |.ELF............|
Without options, hexdump outputs two-byte numbers. So, the first value is the number 0x457f, or decimal 17791.

However, byte 7f is located at position 0, byte 45 is located at position 1. This is so because Intel CPUs (and the ARM CPU in my tiny server, as I just confirmed) are little-endian: numbers are stored so that the lower bytes come first.

hexdump -C shows each byte as it is positioned: First 7f, then 45 and so on. This works for strings and, in general, one-byte values.

Quote:
Coming from big-endian, I find the x86 little endian format arcane beyond words.
Finally somebody who shares my pain. It was much more intuitive when UNIX ran on 68000 processors.
 
Old 03-20-2019, 03:30 PM   #5
Chris_M
LQ Newbie
 
Registered: Jul 2018
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thanks. Make sense now, just couldn't figure out what was happening
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Picard lookups producing varying results, finds more the more you run it anon091 Linux - Software 2 03-28-2018 07:59 AM
Redirecting ports with netfilter: unexpected varying results alpha645 Linux - Networking 3 11-19-2011 09:53 AM
[SOLVED] Hexdump: inaccurate output? mattseanbachman Linux - Newbie 1 04-21-2010 06:19 PM
How can I use hexdump to display ASCII control codes? Akabaka Linux - Software 2 09-19-2009 06:52 PM
hexdump vs od sulekha Linux - General 1 01-12-2009 03:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 09:48 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration