title: PE: Adding code at the end of .txt section
body: <p>As I understand in <code>PE</code> file Virtual Size shows how much space it allocates for section during loading and Raw Size shows how big the section is on disk.</p>
  
  <p>I came across to this executable which did the following:</p>
  
  <p>It subtracted the virtual size (<code>offset 0x8</code>) from the raw data size (<code>offset 0x10</code>) and made sure there was some space(for example 100 bytes). At offset <code>0x14</code> from the text section header it found the offset in the file for the section itself. It added to this the virtual size, finding right where the section ends in the file. it copied some shellcode(which at the end eventually jumped to the original entry point of an executable to make sure original executable ran) to the end of the text section of the binary.</p>
  
  <p>Now I'm little confused here, if the Virtual Size shows the exact space which will be allocated for executable, would not adding code at the end of <code>.txt</code> section overwrite some other data of executable and make it crash? thanks.</p>