Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Include data in compiled perl .exe

by dree (Monsignor)
on Mar 15, 2003 at 02:47 UTC ( #243237=note: print w/ replies, xml ) Need Help??


in reply to Include data in compiled perl .exe

First of all you need to encode the exe:

use strict; use warnings; use MIME::Base64 qw(encode_base64); my $buf; open(FILE, "$ARGV[0]") or die "$!"; binmode FILE; while (read(FILE, $buf, 60*57)) { print encode_base64($buf); } close FILE;
so you can use it (encode.pl) in this way:
c:\>perl encode.pl myexe.exe > mybase64.txt
Now, you need the script (second_exe.pl) that encapsulates and extracts this exe:
use strict; use warnings; use Win32::API; use MIME::Base64 qw(decode_base64); my $exe_name="myexe.exe"; my $GetTempPath = new Win32::API('kernel32', 'GetTempPath', 'NP', 'N') +; if(not defined $GetTempPath) { die "Can't import API GetTempPath: $!\n"; } my $lpBuffer = " " x 80; my $return = $GetTempPath->Call(80, $lpBuffer); my $TempPath = substr($lpBuffer, 0, $return); my $exe_full_path=$TempPath."\\".$exe_name; print $exe_full_path.$/; open (FILE , ">$exe_full_path") or die "$!"; binmode FILE; print FILE decode_base64($_) while (<DATA>); close FILE; system("$exe_full_path"); unlink $exe_full_path; __END__ TVqQAAMAAAQAAAAAAAAAAAAAA etc. (the content of mybase64.txt)
this works for me on Windows XP and perl2exe 7:
c:\>perl2exe second_exe.pl
that produces an exe. If you run it you run the first exe incapsulated in.
If you add a line like this:
system("$exe_full_path -$ARGV[0]");
you can run the first encapsulated exe with additional parmeteres passed by command line (of the first second exe).


Comment on Re: Include data in compiled perl .exe
Select or Download Code
Re: Re: Include data in compiled perl .exe
by Anonymous Monk on Jun 07, 2003 at 18:43 UTC
    eh, think I forgot something: Thanks jand and special Thanks! dree for your code (it works).. Regards.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://243237]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (2)
As of 2014-09-18 01:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (104 votes), past polls