views:

41

answers:

2

For some reasons, i'm using the method described here: http://geekswithblogs.net/TechTwaddle/archive/2009/10/16/how-to-embed-an-exe-inside-another-exe-as-a.aspx

It starts off from the first byte of the embedded file and goes through 4.234.925 bytes one by one! It takes approximately 40 seconds to finish.

Is there any other methods for copying an embedded file to the hard-disk? (I maybe wrong here but i think the embedded file is read from the memory)

Thanks.

+1  A: 

As the man says, write more of the file (or the whole thing) per WriteFile call. A WriteFile call per byte is going to be ridiculously slow yes.

Logan Capaldo
+2  A: 

Once you know the location and size of the embedded exe , then you can do it in one write.

LPBYTE pbExtract; // the pointer to the data to extract
UINT   cbExtract; // the size of the data to extract.

HANDLE hf;
hf = CreateFile("filename.exe",          // file name
                GENERIC_WRITE,           // open for writing 
                0,                       // no share
                NULL,                    // no security 
                CREATE_ALWAYS,           // overwrite existing
                FILE_ATTRIBUTE_NORMAL,   // normal file 
                NULL);                   // no template 

if (INVALID_HANDLE_VALUE != hf)
{
   DWORD cbWrote;
   WriteFile(hf, pbExtract, cbExtract, &cbWrote, NULL);
   CloseHandle(hf);
}
John Knoeller