i'm currently learning from the book "the shellcoder's handbook", I have a strong understanding of c but recently I came across a piece of code that I can't grasp.
Here is the piece of code:
char a[4];
unsigned int addr = 0x0806d3b0;
a[0] = addr & 0xff;
a[1] = (addr & 0xff00) >> 8;
a[2] = (addr & 0xff0000) >> 16;
a[3] = (addr) >> 24;
So the question is what does this, what is addr & 0xff (and the three lines below it) and what makes >> 8 to it (I know that it divides it 8 times by 2)? Ps: don't hesitate to tell me if you have ideas for the tags that I should use.
Zero-address instruction is a format of machine instruction. It has one opcode and no address fields.
Some people may even try to argue that it is an invalid IP address because there is a 0 in third octet. However, today, this IP address is perfectly legal when it comes to subnetting.
0 or . 255 are not usable… in most cases! The reason for this is because we tend to allocate full Class C type addresses to our networks, making it obviously very simple for us to administer. A standard Class C network consists of 256 addresses (0 to 255 inclusive), of which one is the network address (.
In the Internet Protocol Version 4, the address 0.0.0.0 is a non-routable meta-address used to designate an invalid, unknown or non-applicable target. It may also be used for when the client is offline. This address is assigned specific meanings in a number of contexts, such as on clients or on servers.
The variable addr
is 32 bits of data, while each element in the array a
is 8 bits. What the code does is copy the 32 bits of addr
into the array a
, one byte at a time.
Lets take this line:
a[1] = (addr & 0xff00) >> 8;
And then do it step by step.
addr & 0xff00
This gets the bits 8 to 15 of the value in addr
, the result after the operation is 0x0000d300
.>> 8
This shifts the bits to the right, so 0x0000d300
becomes 0x000000d3
.a[1]
.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With