W
Ws
Ok, so I have a question reguarding compilers and placing strings into
the .rdata section of the PE.
I was working on a program and couldn't figure out why I was getting a
0xc0000005 error message (memory access violation) while trying to
alter a (char *) data type'd variable. Proper size, pointers all
accurate and verified. I finally got frustrated enough and tried
something else, built it as a Release application (using Microsoft
Visual Studio 2005 Professional -- it is a legitimate copy, believe it
or not), and took it into OllyDbg.
My finding in OllyDbg was that it was storing the string in the .rdata
section of the PE, and that this section of the file was Read-Only
access. Ok, that answers why it was erroring.
== But more to the point, why did the compiler place the string in
the .rdata section?! I have prepared a short sample code that
duplicates the same problem. (merged stdafx.h into the source inline
to show the concept.)
Anyone have any pointers as to why VC++ placed the my_data string into
the .rdata section of the file?
Thanks in advance for any pointers on this query
-Wes
the .rdata section of the PE.
I was working on a program and couldn't figure out why I was getting a
0xc0000005 error message (memory access violation) while trying to
alter a (char *) data type'd variable. Proper size, pointers all
accurate and verified. I finally got frustrated enough and tried
something else, built it as a Release application (using Microsoft
Visual Studio 2005 Professional -- it is a legitimate copy, believe it
or not), and took it into OllyDbg.
My finding in OllyDbg was that it was storing the string in the .rdata
section of the PE, and that this section of the file was Read-Only
access. Ok, that answers why it was erroring.
== But more to the point, why did the compiler place the string in
the .rdata section?! I have prepared a short sample code that
duplicates the same problem. (merged stdafx.h into the source inline
to show the concept.)
Code:
#ifndef _WIN32_WINNT
#define _WIN32_WINNT 0x0501
#endif
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
void alter_data( char * data )
{
// simply sets the first byte to be 'b' instead
data[0] ^= 'b';
}
int main ( int argc, char ** argv )
{
char *my_data = "Hello, world!";
printf( "%s\n", my_data );
alter_data( my_data );
printf( "%s\n", my_data );
// pause
_getch();
return 0;
}
Anyone have any pointers as to why VC++ placed the my_data string into
the .rdata section of the file?
Thanks in advance for any pointers on this query
-Wes