Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

EXE file packing and encryption.. help.

Status
Not open for further replies.

rpk2006

Technical User
Apr 24, 2002
225
IN
Hi,

I want to develop a program in VB 6 to compress and EXE file and encrypt it, maintaining its executability. Though there are many good programs available for this, but I want to make a one of my own.

Please help me and suggest some good links from where I can get related matter. There is always a new solution for the same problem.

Anonymous
 
In a limited way, this can be accomplish with relative ease.

One way to do it would be to create a stub program and then encrypt and attach your application EXE to it. (See thread222-103449.)

The stub program is responsible for accepting a password, extracting and decrypting the application in a temporary folder, executing and monitoring the app and then wiping it after it terminates.

The setup package must include all the dependency files for both the app and the stub program (these would be hard to encrypt unless the stub was written as a stand-alone in something other than VB).

It sounds like an interesting project. Perhaps one of the users in this forum will show a way to execute the app from the stub program's memory space without creating a page fault (it would eliminate the need to write a temporary, unencrypted copy of the program to disk).
VCA.gif
 
Alt25,

Amazing Answers. Hats Off to you.

I hope you will be able to guide me better in "EXE file Packing and Encryption".

Please suggest me some sites which will be helpful in learning about DOS and Windows EXE files. There is always a new solution for the same problem.

Anonymous
 
You can get the EXE file specifications at and some additional information at
You will, without doubt, find tons of information about encryption and various file formats by searching the Internet. Finding information specific to your application might be a bit harder... so I would recommend a visit to your public or local university library. Don't be ashamed to resort to this archaic method of information retrieval: wading through the stacks isn't as easy as clicking in a browser but the results can be more satisfying.

The problem with information on the Internet is that most of it is relatively new. If I were interested in finding a way to create self-extracting EXEs I would dig out a dusty old DOS programming manual, learn everything I could about the way things used to work and then extend my research into the present day while maintaining a grasp of the original notions (trust me, they haven't changed very much).

And don't discount the benefits of pure dumb experimentation. While looking for a way to prevent users from altering or copying company documents I discovered that I could encrypt them and append them to an executable file. This didn't require a PHD in Rocket Science or 10,000 hours of research. I just did it.
VCA.gif
 
Alt255,

I tried the code given at the thread you suggested, but it is not working. It is giving errors in File Open and Close statements. There is always a new solution for the same problem.

Anonymous
 
Please post the section of code that generates the errors.
VCA.gif
 
Alt255,

I received errors at the File Open and Close statements in your following code:

----------------------------------------------
' This is the name of your program.
MyExe$ = "PigiBack.exe"
' You would probably use...
' App.ExeName & ".EXE" instead.
F1 = FreeFile
Open MyExe$ For Binary As #F1
Get #F1, LOF(F1) - 3, Test&
' Check to see if the last 4 bytes of the EXE
' contain a file size.
If Test& > 0 Then
Close #F1
MsgBox "File has already been piggybacked."
Exit Sub
End If
' Read the contents of the program files
' and appendf them to your app EXE.
For Rep = 0 To UBound(EXEinfo)
With EXEinfo(Rep)
f2 = FreeFile
Open .EXEname For Binary As #f2
G$ = String$(LOF(f2), 0)
.FileSize = Len(G$)
Get #f2, 1, G$
Close #f2
.StartByte = LOF(F1) + 1
Put #F1, , G$
End With
Next
' Write the file information
' records at the end of the EXE.
For Rep = 0 To UBound(EXEinfo)
Put #F1, , EXEinfo(Rep)
Next
Close #F1
End Sub

Private Sub ExtractExes_Click()
' This sub just retrieves the stored
' program names and places them in
' a list box.
MyExe$ = "PigiBack.exe"
F1 = FreeFile
Open MyExe$ For Binary As #F1
Get #F1, LOF(F1) - 3, Test&
' Check to see if the last 4 bytes of the EXE
' contain a file size.
If Test& = 0 Then
Close #F1
MsgBox "File has not been piggybacked yet."
Exit Sub
End If
RecSize = Len(EXEinfo(0))
' Get the file information records.
For Rep = 0 To UBound(EXEinfo)
Get #F1, LOF(F1) - (RecSize * (Rep + 1)) + 1, EXEinfo(Rep)
List1.AddItem EXEinfo(Rep).EXEname
Next
Close #F1
End Sub
----------------------------------------------

How can I contact you via email to proceed with this program. There is always a new solution for the same problem.

Anonymous
 
Rpk2006, we try to keep our messages visible to all Tek-Tips users. At this point, I think it advisable to move this discussion back to the Visual Basic - version 5 & 6 forum. Click thread222-103449 and respond to the original thread, noting the actual error message you are receiving... I'll try to help you resolve your problems with opening and closing the file.
VCA.gif
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top