Solved

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

Posted on 2004-09-14
3
412 Views
Last Modified: 2012-06-27
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]?
0
Comment
Question by:joesp
  • 2
3 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 200 total points
ID: 12061829
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
 
LVL 1

Author Comment

by:joesp
ID: 12061919
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
 
LVL 45

Expert Comment

by:sunnycoder
ID: 12061956
>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

Featured Post

Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question