Reverse Engineering for Beginners

(avery) #1

CHAPTER 31. ENDIANNESS CHAPTER 31. ENDIANNESS


Chapter 31


Endianness


The endianness is a way of representing values in memory.


31.1 Big-endian.


The0x12345678value is represented in memory as:


address in memory byte value
+0 0x12
+1 0x34
+2 0x56
+3 0x78

Big-endian CPUs include Motorola 68k, IBM POWER.


31.2 Little-endian


The0x12345678value is represented in memory as:


address in memory byte value
+0 0x78
+1 0x56
+2 0x34
+3 0x12

Little-endian CPUs include Intel x86.


31.3 Example


Let’s take big-endian MIPS Linux installed and ready in QEMU^1.


And let’s compile this simple example:


#include <stdio.h>


int main()
{
int v, i;


v=123;

printf ("%02X %02X %02X %02X\n",
(char)&v,
(((char)&v)+1),
(((char)&v)+2),
(((char)&v)+3));
};


(^1) Available for download here:http://go.yurichev.com/17008

Free download pdf