Solved

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

Posted on 2004-09-14
3
408 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

708 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now