Solved

EXE File Self-Extract

Posted on 2000-03-15
6
430 Views
Last Modified: 2010-04-10
Hi...
I need a source code in Visual C++ or Borland C++ for make one EXE file with many files inside (self-extract).

thanks for all

If do you want, please, send the source code to me.. thanks

masvmasv@hotmail.com
0
Comment
Question by:masvmasv
  • 2
  • 2
  • 2
6 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 2621276
There are commercial programs for doing this.  Its probably not worth writting this yourself.  Check out pklite at

http://www.pkware.com/pklite.html

i
0
 
LVL 22

Expert Comment

by:nietod
ID: 2621290
That link only has the 16 bit version.  try

http://www.pkware.com/catalog/pklite.html

instead.
0
 
LVL 32

Accepted Solution

by:
jhance earned 350 total points
ID: 2621551
I dug this out of my PAQ (previously asked questions) at:

http://www.experts-exchange.com/jsp/qShow.jsp?ta=mfc&qid=10220405

Here is the essential code from that previous posting:

After giving this a little thought, I decided that I did have a pretty good idea on how to do it.  It seems you know how to create the DIFF file so I'll just show you how I created a small app that extracts the last part of itself into another file at run time.

First, the code:

#include "stdafx.h"
#include "PatchTest.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// The one and only application object

CWinApp theApp;

using namespace std;

int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
// TODO: change error code to suit your needs
cerr << _T("Fatal Error: MFC initialization failed") << endl;
nRetCode = 1;
}
else
{
// TODO: code your application's behavior here.
const TCHAR *lpszDataMarker = _T("***BEGINNING-OF-DATA***");

// Get this executable file's name
LPBYTE pbBuffer;

TCHAR lpszExeName[_MAX_PATH+1];
::GetModuleFileName(NULL, lpszExeName, _MAX_PATH);

CFile mFile;
if(!mFile.Open(lpszExeName, CFile::modeRead | CFile::shareDenyNone | CFile::typeBinary)){
cerr << _T("Error opening EXE file: ") << lpszExeName << endl;
return 0;
}
cout << _T("EXE File opened OK") << endl;

// Allocate space for it
DWORD dwLength = mFile.GetLength();
pbBuffer = new BYTE[dwLength];

mFile.Read(pbBuffer, dwLength);

mFile.Close();

// Find the 1st occurrence of the lpszDataMarker
BOOL bFlag = FALSE;
LPBYTE p;
for(p=pbBuffer; p<(pbBuffer+dwLength)-_tcslen(lpszDataMarker); p++){
if(memcmp((LPVOID)lpszDataMarker, (LPVOID)p, _tcslen(lpszDataMarker)) == 0){
bFlag = TRUE;
break;
}
}

if(bFlag){
cout << _T("Found 1st at offset ") << (p - pbBuffer) << endl;
}
else{
cout << _T("Error marker not found...") << endl;
delete pbBuffer;
return 0;
}

// Now the 2nd one, the one we want
bFlag = FALSE;
for(p += _tcslen(lpszDataMarker);p<(pbBuffer+dwLength)-_tcslen(lpszDataMarker); p++){
if(memcmp((LPVOID)lpszDataMarker, (LPVOID)p, _tcslen(lpszDataMarker)) == 0){
bFlag = TRUE;
break;
}
}

if(bFlag){
cout << _T("Found 2nd at offset ") << (p - pbBuffer) << endl;

// Now extract everything after the marker to a file
p += _tcslen(lpszDataMarker);
CFile mFileNew;
mFileNew.Open(_T("EXTRACTED"), CFile::modeWrite | CFile::modeCreate);
mFileNew.Write(p, dwLength-(p-pbBuffer));
mFileNew.Close();
//
}
else{
cout << _T("Error 2nd marker not found.") << endl;
}

delete pbBuffer;
}

return nRetCode;
}


Then there is a text file with just a single line in it called MARKER.TXT.  It has in it:

***BEGINNING-OF-DATA***

Then use the DOS COPY command like this to append 3 files together into the EXE you are going to distribute:


C:\VCProjects\PatchTest\Debug>copy /B patchtest.exe /b + marker.txt /b + ..\Patchtest.cpp patch.exe /b

This appends the patchtest.exe, the marker.txt file, and the file to be extracted, in this case, the source code to the project and copies them into patch.exe

Now when you run patch.exe, you will get the contents of patchtest.cpp extracted into a file called EXTRACTED.

Enjoy....



0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:masvmasv
ID: 2625035
Thanks

One more question...
Your program need any DLL file or only a unique EXE File?

Excuse me for my bad english

Thanks...
0
 
LVL 32

Expert Comment

by:jhance
ID: 2625456
No DLLs (other than the standard Windows DLLs) are used in this program.  What I've posted here is complete.  It does use MFC (which I think is available on your Borland C++ but if not, it should be straightforward to remove all the MFC references.

I wanted to show you how this works in concept.  
0
 

Author Comment

by:masvmasv
ID: 2625964
Thanks...
I dont test it...
But I send the points to you...


thanks
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now