chester has asked for the wisdom of the Perl Monks concerning the following question:
I am charged with the unpleasant task of "password-protecting" a windows .exe file, or otherwise stopping a user from running this executable unless authorized. Search didn't turn up much that's similar to my problem. The complications:
use warnings; use strict; use Convert::UU qw(uudecode); use Digest::MD5 qw(md5_hex); use Win32::Process; use Win32; use File::MkTemp; print "Password: "; chomp( $_ = <STDIN> ); my $dep; if(md5_hex($_) eq '207f499c334c2a3199f748a327b1b515') { # For added "security" (I use the term lightly) we're going to use + a random filename. $dep = mktemp('XXXXXXXX', $ENV{'TEMP'}) . '.exe'; print "Password OK. One moment please.\n\n"; open OUT, '>', $dep or die $!; my $uu; { local $/; $uu = <DATA>; } binmode OUT; print OUT uudecode($uu); close OUT; # We need to pass along the command line arguments my $com = join ' ', ($dep, @ARGV); # And the current directory; this script is always called via .bat +files, # so the current working directory should always be set; we don't c +are what it is, # but we need to let the process know below chomp(my $curr_dir = `cd`); my $proc; Win32::Process::Create( $proc, # Process object $dep, # Filename $com, # Command line args 0, # Should the process inherit fileh +andles? (No.) NORMAL_PRIORITY_CLASS, # Priority (normal) $curr_dir # Process' working directory ) or die $!; $proc->Wait(INFINITE); print "Please don't close this window. It will close itself automa +tically in a few seconds.\n"; } END { # Delete the temp file. This won't be run if the script doesn't ex +it normally! unlink $dep if $dep; } __DATA__ # long uuencoded string of the original .exe goes here
I then take this script and run it through PAR to create a standalone .exe, and then I will distribute this wrapper exe as a drop-in replacement for the original .exe.
Can you think of anything else I could do here, or anything I'm overlooking? I particularly don't like the END block. (This is my first post. Thanks in advance.)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Password-protect an arbitrary windows executable?
by 5mi11er (Deacon) on Aug 05, 2005 at 18:43 UTC | |
by chester (Hermit) on Aug 05, 2005 at 18:58 UTC | |
by 5mi11er (Deacon) on Aug 05, 2005 at 19:07 UTC | |
|
Re: Password-protect an arbitrary windows executable?
by jfroebe (Parson) on Aug 05, 2005 at 19:12 UTC | |
by chester (Hermit) on Aug 05, 2005 at 19:25 UTC |