title: Generating a PE format executable
body: <p>I'm trying to generate a PE format executable; I'm at the stage where I have something that dumpbin is happy with, and as far as I can tell is not materially different from an empty program linked with Microsoft's linker, but Windows still rejects it: <a href="https://stackoverflow.com/questions/21585549/pe-file-whats-missing">PE file - what&#39;s missing?</a></p>
  
  <p>If I had some algorithm for generating a valid PE file, maybe I could hill climb from there. Here's what I've found so far:</p>
  
  <ul>
  <li><p>There's plenty of documentation, sample code and tools for <em>reading</em> PE files, as opposed to generating them from scratch.</p></li>
  <li><p>PE Bliss lists generation among its features, but won't compile.</p></li>
  <li><p>Sample assembly language templates for PE file generation concentrate on minimizing size. The most promising looking one generates a file that Windows rejects even though as far as I can see it should be accepted; the one I found that did work, ironically, generates a file that Windows accepts even though as far as I can see it should be rejected, since almost every nominally essential component is missing or malformed.</p></li>
  </ul>
  
  <p>Is there any sample code available that generates a correct PE file?</p>