22858 total geeks with 3297 solutions
Recent challengers:
sharepoint how to
 Welcome, you are an anonymous user! [register] [login] Get a yourname@osix.net email address 

Articles

GEEK

User's box
Username:
Password:

Forgot password?
New account

Shoutbox
innocentius
I win at OSIX, I guess. Onward to the other challenges!
sefo
anilg, new comments are deleted automaticall y because of some abuse recently
anilg
this is plain wierd. I submitted comments twice to article 950, and they dont seem to be there. Something wrong with the comment code?
CodeX
shout-boxes in general are old + the staff thing happened to everyone after an issue 2 months ago
anilg
/me is no longer staff :(

Donate
Donate and help us fund new challenges
Donate!
Due Date: Sep 30
September Goal: $40.00
Gross: $0.00
Net Balance: $0.00
Left to go: $40.00
Contributors


News Feeds
The Register
Email worm wants to
party like it"s
1999 (almost)
Oracle sneaks out
Solaris 10 refresh
Firefox 4 preview
knocks back Jäger
shot
Google search index
splits with
MapReduce
Steve Jobs lectures
devs, dodges
antitrust action
Ex-Sun CEO sees
rosy future in
health
Opensourcers get
personal over
Ellison"s Google
fight
Apple issues
moral
regulations> apps dev guide
Dell launches
Opteron 4100s into
Boxes-o-Cloud
Clegg"s taking away
Your Freedom
Slashdot
Swedish Police Shoe
Database May Tread
On Copyright
Australia"s
National Broadband
Network To Go Ahead
Robots Taught to
Deceive
Apple Relaxes iOS
Development Tool
Restrictions
HDR Video a Reality
Swedish Police Shoe
Database May Tread
on Copyright
New Email Worm
Squirming Through
Windows Users"
Inboxes
Researchers Create
Real Tractor Beams
Broadcom Releases
Source Code For
Drivers
Mozilla Unleashes
JaegerMonkey
Enabled Firefox 4
Article viewer

VB: Self extracting executable



Written by:MaxMouse
Published by:Nightscript
Published on:2006-08-12 05:15:53
Topic:Visual Basic
Search OSI about Visual Basic.More articles by MaxMouse.
 viewed 9947 times send this article printer friendly

Digg this!
    Rate this article :
How to extract files from inside running executable at runtime.

The basis of this article is to demonstrate a way of including other files within you're executable without corruption (too much anyway ;).

The basics:
The reason this is so simple is you can append data to the end of you're executable file, along with delimiters you could append files, their privilages, even an entire directory tree with compression and encryption.

Some code:
to add a file to you're executable

public function AddFile(ExecPath as string, FileToAdd_Path as string, Result as string)
dim TMP as string

open execpath for binary access read as #1
tmp = input(lof(1),1)
close #1

tmp = tmp & "[START]"

open filetoadd_path for binary access read as #1
tmp = tmp & input(lof(1),1)
close #1

open Result for binary access write as #1
put #1,1, tmp
close #1

end function


Code to put inside you're executable to enable extraction of the file.

public function ExtractFile()
dim TMP as string

open app.path & "\" & app.exename & ".exe" for binary access read as #1
tmp = input(lof(1),1)
close #1

tmp = mid(tmp, instr(tmp, "[START]") + 7, len(tmp))

open app.path & "\" & app.exename & "-Extracted.exe" for binary access write as #1
put #1,1, tmp
close #1
end function


This will cause the executable to open and read its contents into the TMP variable, it will then parse all data after the string "[START]" and output that to a file, this is our extracted data, ofcourse its only one file with no compression/encryption and the extraction could be improved by only reading the data from the end of the executable and not the entire thing, but im sure you grasp the idea.

Executable Map:
[Extractor]
[Extractor's Code]
[End of Extractor]

[COMPRESSION + ENCRYPTION START]
[START1]
[Test.TXT]
[Test.TXT's contents]
[PRIVS]
[777]
[START2]
[Whatever.exe]
[Whatever.exe's Contents]
[PRIVS]
[755]

Did you like this article? There are hundreds more.

Comments:
anilg
2006-08-12 05:46:19
Hmm.. Wont work in cases where the exe has say a label or button with the words '[START]' ..

You can hardcode the exe size and read from there onwards.. or there are resource API's you can use to add or read stuff to/from the exe's
MaxMouse
2006-08-16 02:17:35
Yes, good point if something contains the label [start] at compile time then it'll mess the parse up, i was trying to demonstrate the idea, obviously hard-coding the executable size and reading backwards would be far better/reliable.
MaxMouse
2008-07-05 18:15:15
Most higher level languages now require runtimes... the .NET library is a bloody runtime, Java has what could be deemed a runtime, what about the MFC library for C? why are people so wrapped up in the runtime debate, who cares, windows is a friggin runtime!
Domuk
2008-07-05 22:11:45
They're not, they're spamming - don't get so worked up!
MaxMouse
2008-07-06 07:01:05
lol, I'm not... i just jumped on my soap box for a couple of seconds... I'm fine now :)
Anonymous
2010-01-20 00:29:09
http://www.bagscabin.com/mulberry bags
Anonymous
2010-02-27 17:06:09
All the world's latest and most authoritative website with all kinds of uniforms. We are recognized worldwide network of sales jersey website. Here you can choose a variety of uniforms such as MLB jerseys, NFL jerseys, NHL jerseys and NBA jerseys. Professional security identification products with credit guarantee, first-class quality and reasonable prices!
--Lin Guowang
Anonymously add a comment: (or register here)
(registration is really fast and we send you no spam)
BB Code is enabled.
Captcha Number:


Test Yourself: (why not try testing your skill on this subject? Clicking the link will start the test.)
VB Potpourri: Programming, History And Syntax by batterseapower

A nice little collection of the basics of Visual Basic.
Advanced Programming Techniques by batterseapower

A fiendish test covering some of the more obscure elements of Visual Basic 6.


     
Your Ad Here
 
Copyright Open Source Institute, 2006