?
Solved

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

Posted on 2004-09-14
3
Medium Priority
?
418 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 45

Accepted Solution

by:
sunnycoder earned 800 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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…
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.
Suggested Courses

765 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