Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-09-14
3
Medium Priority
?
420 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

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…
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 and use structures in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

618 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