I think you are debugging in assembly calling C functions and trying to trace that with ollydbg (I just looked up what it is and based this assumption on their feature list). This is very difficult to do.
I suggest that you do:
...
void print_ptr(void * p) {
fprintf(stderr, "%p\n", p);
}
...
IMAGE_DOS_HEADER iDOSh;
print_ptr(lpBuffer);
memcpy(&iDOSh,lpBuffer,sizeof(iDOSh));
print_ptr(lpBuffer);
If you aren't actually able to print things that will be ok. Just make the functions extern
to the file with the memcpy
in question and it will force the compiler to load the value into the location which holds the first parameter. You should be able to observe this in your debugger.
The likelihood the memcpy
(from any reasonable C library) is actually doing something wrong is very very low.
If I had to guess what is going wrong it would be that lpBuffer
is not actually supposed to be a void *
but a linker label for a memory location. In that case you might should try declaring it as:
extern char lpBuffer[];
and do your memcpy as
memcpy(&iDOSh,lpBuffer,sizeof(iDOSh));
or
extern IMAGE_DOS_HEADER lpBuffer;
and do your memcpy as
memcpy(&iDOSh,&lpBuffer,sizeof(iDOSh));