title: How can I use memfrob() to encrypt an entire file?
body: <pre><code>#include &lt;Windows.h&gt;
  
  void memfrob(void * s, size_t n)
  {
   char *p = (char *) s;
  
   while (n-- &gt; 0)
    *p++ ^= 42;
  }
  
  int main()
  {
   memfrob("C:\\Program Files\\***\***\\***\***\\***", 30344);
  }
  </code></pre>
  
  <p>There's my code.  If you can't tell, I'm not sure what I'm doing.  I've Googled for about an hour and I haven't seen an example of how to use memfrob(), which is probably why I'm so lost.  I'm trying to pass it the name of the file and then the size of the file in bytes, but my program just crashes.</p>
  
  <p>Alright, this is what I have right now:</p>
  
  <pre><code>#include &lt;Windows.h&gt;
  #include &lt;stdio.h&gt;
  
  int count = 0;
  FILE* pFile = 0;
  long Size = 0;
  
  void *memfrob(void * s, size_t n)
  {
      char *p = (char *) s;
  
      while (n-- &gt; 0)
          *p++ ^= 42;
      return s;
  }
  
  int main()
  {
      fopen_s(&amp;pFile, "C:\\Program Files\\CCP\\EVE\\lib\\corelib\\nasty.pyj", "r+");
      fseek(pFile, 0, SEEK_END);
      Size = ftell(pFile);
      char *buffer = (char*)malloc(Size);
      memset(buffer, 0, Size);
      fread(buffer, Size, 1, pFile);
      fclose(pFile);
      memfrob(buffer, Size);
      fopen_s(&amp;pFile, "C:\\Program Files\\CCP\\EVE\\lib\\corelib\\nasty.pyj", "w+");
      fwrite(buffer, Size, 1, pFile);
      fclose(pFile);
  }
  </code></pre>
  
  <p>In my debugger, it seems that fread is not writing anything to buffer, and my ending file is just 2A over and over, which is 00 xor'd with 42.  So can I get another hint?</p>