ExeCreator Utility

Environment: VC6

ExeCreator is a small utility to enwrap any number of files into a single exe. This new enwrapped exe when executed spits all the files to a desired folder.

It consists of two applications: ExeCreator and ExeExtractor.

ExeCreator:
It is the main application which provides GUI for receiving file names to be added, creates a new ExeExtractor.exe from one present in its resources, and adds all the files as resources to this new ExeExtractor.exe. It uses UpdateResource() to dynamically add files (converted to specified format known to ExeExtractor.exe) into resource in Extractor.exe.

ExeExtractor:
It extracts the files added as resource by ExeCreator into a folder.

In next version of this program I'll try to add compression in file data stored and an encryption option. But presently also it provides a useful tool for self-extracting exe's especially used in installations.

// Create a buffer which will be added as resource to 
// the ExeExtractor exe
// First byte in buffer is set to number of files in list
LPSTR buff = (LPSTR)new DWORD(m_InList.GetCount());
UINT nSize = sizeof(DWORD);
// Add each file
for(DWORD i = 0;i < *(DWORD *)buff;++i)
{
  CString inFName;
  m_InList.GetText(i,inFName);

  // Open i file 
  FILE* fpIn = fopen(inFName,"rb");
  if(fpIn == NULL)
  {
    CString errMsg;
    errMsg.Format( "Could not open %d file : %s",
                   i + 1,
                   (LPCSTR)inFName);
    AfxMessageBox(errMsg);
    delete buff;
    return;
  }

  // Retieve file size file 
  fseek(fpIn,0,SEEK_END);
  UINT nFSize = ftell(fpIn);
  fseek(fpIn,0,SEEK_SET);

  // Extract just file name from full pathname of file
  for(int nCtr = 0,nMid = 0;nCtr < inFName.GetLength();++nCtr)
    if(inFName[nCtr] == '\\' || inFName[nCtr] == ':')
      nMid = nCtr + 1;
  CString onlyFName = inFName.Mid(nMid);

  // Realloc previous buffer to accomodate this file's info
  LPSTR newbuff = new char[nSize +
                           (onlyFName.GetLength() + 1) +
                           sizeof(UINT) + nFSize];
  memcpy(newbuff,buff,nSize);
  delete buff;
  buff = newbuff;

  // Copy file name with null character
  memcpy( buff + nSize,
          (LPCSTR)onlyFName,
          onlyFName.GetLength() + 1);
  // Copy file size
  *(UINT *)(buff + nSize + onlyFName.GetLength() + 1) = 
                                                    nFSize;
  // Copy file data
  VERIFY(fread( buff + nSize + 
                sizeof(UINT) + 
                (onlyFName.GetLength() + 1),
         1,nFSize,fpIn) == nFSize);

  nSize += sizeof(UINT) + 
           (onlyFName.GetLength() + 1) +
           nFSize;
  fclose(fpIn);
}

// Create a dummy EXE from ExeExtractor
FILE* fpOut = fopen(m_outFName,"wb");
if(fpOut == NULL)
{
  AfxMessageBox("Could not create output file" +
                m_outFName);
  delete buff;
  return;
}

// Find Load and Lock resource
HRSRC hResLoad = FindResource(NULL,
           MAKEINTRESOURCE(IDR_IDR_EXE_EXEEXTRACTOR),
           "IDR_EXE");
HGLOBAL hResData = LoadResource(NULL,hResLoad);
LPCSTR data = (LPCSTR)LockResource(hResData);

// Write the ExeCreator binary data to this file
ASSERT(hResLoad != NULL && hResData != NULL && data != NULL);
fwrite(data,1,SizeofResource(NULL,hResLoad),fpOut);
fclose(fpOut);
FreeResource(hResData);

// Open the file for addition of file data in resource
HANDLE hUpdateRes = BeginUpdateResource(m_outFName, FALSE);
ASSERT(hUpdateRes != NULL);

// Add the file data to the update list.
VERIFY(UpdateResource(hUpdateRes,
    "IDR_EXE",MAKEINTRESOURCE(IDR_IDR_EXE_EXEEXTRACTOR),
    MAKELANGID(LANG_NEUTRAL, SUBLANG_NEUTRAL),
    buff,nSize));
delete buff;

// Write changes and then close it. 
VERIFY(EndUpdateResource(hUpdateRes, FALSE));

Downloads

Download demo project - 24 Kb
Download source - 7 Kb


Comments

  • Request!

    Posted by kannan23in on 09/17/2005 07:03am

    Attn: Kaushal Malhotra Is there any posiblities of ... 1) add y.exe and create z.exe (self-extracter created thru our ExeCreator) 2) when running the z.exe .. the y.exe will be we are getting now. (Fine) the posibilty... 3) without extracting the y.exe to the harddisk is there any chance to run the y.exe from z.exe? This logic is most-important one in protection-purpose we can use. by extending.. this project.. thanks. Kannan (Chennai-India)

    Reply
  • Great! Reading files without extracting?

    Posted by Legacy on 08/08/2002 12:00am

    Originally posted by: Lea Hayes

    Great work!

    Is it possible to read and open the files which are contained within the executable without extracting them. This would be great for storing textures for a game with some modification. Like a WAD file.

    Yours Sincerely,
    Lea Hayes

    Reply
  • Excellent Code! Good Job!

    Posted by Legacy on 12/28/2001 12:00am

    Originally posted by: Ram Sharma

    Point is not only getting the software which can do this but the code which can perform this sort of function so it can be integrated with other softwares.

    This has helped me a great deal in packaging up files which are downloaded and expanded for online software updates.

    Thank you very much for your contribution!

    Ram

    Reply
  • Will it beat WinZip???

    Posted by Legacy on 12/22/2001 12:00am

    Originally posted by: Saurabh Agrawal

    A great job indeed...

    Will it beat WinZip in compression and other stuff...

    Reply
  • Windows 95/98?

    Posted by Legacy on 12/21/2001 12:00am

    Originally posted by: Gene

    What would you propose for Win 95/98?

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Remember getting your first box of LEGOS as a kid? How fun it was putting the pieces together, collaborating with your friends to create something new? Now, as an IT professional, assembling and maintaining a Lego-like collaboration infrastructure isn't what you signed up for. Piecing together disparate systems of record for email, web meetings and other applications is about as painful as stepping on a pile of Legos. Download the e-book to learn how implementing a collaboration system connects systems of …

  • Finance leaders have been talking about expanding the value-added role of their teams for a long time. The debate is no longer whether the finance and accounting function needs to become a more strategic partner to the rest of the business but rather how to get there. Technology innovation has caught up to this ambition, and what was once aspiration can be a reality – and the choice is now yours. Read this research report to learn how to make the most of information tools to enable innovation and growth.

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date