• C

complicated pointer *(long*)&stuffing[i]=0x80484bb

Hi,
I am studying assembly, and have the shellcoder's handbook, where there is the following example on page 21 of how to make an array of 44 bytes, where each byte is filled with "something" (think it's 0x80484bb) but given the following code for this

int i = 0;
char stuffing[44];
for (i=0; i<=40; i+=4)
*(long *) &stuffing[i] = 0x80484bb;

okay, i know that he is putting the address value of 0x80484bb somewhere .... but how can he magically cast a char to a long?  the question is, "what is going on here?" is he changing the char * stuffing into (char *)(Long *) stuffing, meaning making the &stuffing ...  can somebody break down for me *(long *) &stuffing[i]?
LVL 1
joespAsked:
Who is Participating?
 
sunnycoderConnect With a Mentor Commented:
He is stuffing your char array like this

08   04   84    bb  08   04   84    bb  08   04   84    bb  08   04   84    bb  ....

He is filling in 4 bytes at a time by casting char * to long *

C is very flexible and allows you explicit casts of pointers. But you should be very careful while using this feature

*(long *) &stuffing[i] = 0x80484bb;
               ^
               address of ith element ... this should be a char *
      ^
      cast that address to a long *
^
dereference the long * ... this specifies the value of long at the specified address ... since this is LHS of assigment, the value on the right will be stuffed in 4 bytes starting at this address
0
 
joespAuthor Commented:
thank you sir.
"C is very flexible and allows you explicit casts of pointers. "..... to hear this when i often get "incompatible types in assignment" type errors... and you are write one has to count every byte and know where it goes, and that a long is size 4 .... etc.
0
 
sunnycoderCommented:
>to hear this when i often get "incompatible types in assignment" type errors
That is why I said you need to be careful ... it can be tricky ... This kind of juggling should be avoided as far as possible

>and you are write one has to count every byte and know where it goes, and that a long is size 4 .... etc.
It is always good to know your bits and bytes. And be cautioned .. long is not 4 bytes on all platforms ... so do not depend in ... Size of data types vary with platform :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.