The elements of interest are VirtualSize
and the SizeOfRawData
. According to the Windows PE specification, VirtualSize
should contain the total size of the section when loaded into memory, and SizeOfRawData
should contain the size of data on disk. The Windows loader uses the smaller of VirtualSize
and SizeOfRawData
to map the section data into memory. If the SizeOfRawData
is larger than VirtualSize
, only VirtualSize
data is copied into memory; the rest is ignored. Because OllyDbg uses only the SizeOfRawData
, setting the SizeofRawData
to something large like 0x77777777
, will cause OllyDbg to crash.
The easiest way to overcome this anti-debugging technique is to manually modify the PE header and set the SizeOfRawData
using a hex editor to change the value to be close to VirtualSize
. (Note that, according to the specification, this value must be a multiple of the FileAlignment
value from the IMAGE_OPTIONAL_HEADER
). PE Explorer is a great program to use for this purpose because it is not fooled by a large value for SizeofRawData
.
Malware often attempts to exploit a format string vulnerability in version 1.1 of OllyDbg, by providing a string of %s
as a parameter to OutputDebugString
to cause OllyDbg to crash. Beware of suspicious calls like OutputDebugString ("%s%s%s%s%s%s%s%s%s%s%s%s%s%s")
. If this call executes, your debugger will crash.