Results 1 to 3 of 3

Thread: How to store files inside executables - Revised Version

  1. #1

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    How to store files inside executables - Revised Version

    ** Updated 30/August/2002
    Code now uses a faster String Append Method
    This code is on average a little over ten times faster
    than VB's own string append operation
    This is accomplished through use of CopyMemory()
    **


    There are a few methods of bundling files with your application.

    The easiest is to use your Setup application to bundle the files.
    Things like InnoSetup can do this easily.
    Another method is to include files inside resource files.

    One method that I am quite fond of however is to compress and then
    base 64 encode the file(s) and then have the file(s) decoded and
    decompressed at load time for the application.

    One huge advantage of this is if you want to give out a full version
    of your application, but people must enter a code to enable it.
    Well what you could do then is instead of just compressing and
    encoding the full version into a wrapper application, you could also
    encrypt the data using (for example) RSA encryption.
    This would mean that if the person enters the wrong password then a
    load of gunk will come out the other end, but if they enter the right
    password, then the proper application will come out.

    There would be no way of cracking this approach.
    The only way to get the application out without having the password
    would be to try and brute force decrypt the data, and if you know
    anything about encryption (especially RSA), you'll know that that
    is not a viable option.


    To date I have always coded all this manually and written little
    applications to test if the encoding is working and all that.
    But as a number of people have requested it so far I have written
    an application to get any file into the source code for your app.


    I would suggest that you follow the instructions exactly, and then
    once you are confident of what is happening and that the application
    is working, then possibly modify the code.


    Instructions for use :
    1 ) Extract the application attached to this post to some folder
    2 ) Open the application
    3 ) Run it, and select a source file to encode
    4 ) Then select a destaination .bas file for the app to create
    5 ) Press Go
    6 ) A destination .bas module will be created then
    7 ) Open the created .bas module in Visual Basic
    8 ) Add a form to this new project
    9 ) Add the two class modules clsB64.cls and clsHuffman.cls
    10) Make the form the startup object for the project
    11) Enter the following code for the form ;
    VB Code:
    1. Private Sub Form_Load()
    2.           MsgBox getFile()
    3.       End Sub
    12) That will display the *original* data that was encoded
    13) You can then change that to put the data elsewhere if needs be


    If you follow those instructions, you will be presented with the
    data you originally encoded, ie. the original file.
    So then you can have that data put into a public variable,
    written to a file, presented in a text box ... etc.


    I would very much so like to get feedback on this as I have never
    seen this being done before, so I'd like to know if anyone else
    has done this kind of thing, or has any better alternatives.



    After you have attached your files to your project, and compile,
    you may find that your executable has grown considerably
    ( or at least grown by the size of those attached files )
    Anyway, once you have compiled your application, I would suggest
    that you then run the Universal Packer for eXecutables (UPX) on
    the executable. (http://upx.sourceforge.net)




    note: I did not write the Base64 or Huffman encoding class modules.
    I found these on the net, but no longer have any author information etc.

    Also, I did not write UPX.
    That project is Copyright (c) 1996-2002 Markus Oberhumer & Laszlo Molnar
    Attached Files Attached Files
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  2. #2

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    Also from what I remember, there are much better implimentations of Base64 encoding and compression that the two that I had found and bundled in this sample.
    For example, one could use a C/C++ DLL to Base64 encode the data and the zlib library for compression. You can do anything you want really.

    We're Base64 encoding so that the original file will be in a format that the VB6 IDE and compiler will be okay with.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

  3. #3

    Thread Starter
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    * 21-October-2004 - Moved to CodeBank *
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width