Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Rereading your code, I have some more observations:</p> <ol> <li><p>It is apparent you are not passing the correct parameters to <code>fwrite</code>. The first parameter is a pointer to a buffer of memory, not another <code>FILE*</code>. In this case you're copying bizarre memory into the new executable, which is why it cannot be executed.</p> <p>If you have a block of memory you would like to copy to an executable, simply <code>fwrite</code> that block of memory:</p> <pre><code>FILE* fp_out = fopen("testing.exe", "wb"); /* ... */ fwrite(value, sizeof(value), 1, fp_out); </code></pre> <p>However, this assumes <code>value</code> is a full and complete executable image suitable for execution (you probably need a <code>chmod +x testing.exe</code>). I'm left to wonder, given an extension of <code>.exe</code>, if this binary image even contains a valid executable for your platform.</p></li> <li><p>You do not want to use <code>strlen</code> when dealing with a supposed executable image, even if it is "stored" in a <code>char*</code>. Executables contain byte values of 0, which are the C-string delimiter character NUL (e.g. <code>'\0'</code>). This will cause <code>strlen</code> to fumble. You'll need to use <code>sizeof</code> or keep track of the size of the executable image.</p></li> <li><p>It would be best to use <code>"wb"</code> in your call to <code>fopen</code> if you made the effort to use <code>"rb"</code> in your call to <code>fmemopen</code>. This way you do not receive newline translation on systems which do this (<a href="http://msdn.microsoft.com/en-us/library/yeby3zcb.aspx" rel="nofollow">Windows</a>). If you're on a platform which does not make this requirement, either remove the <code>b</code> from the calls or keep it. Whatever you choose, be consistent.</p></li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload