.exe crated using Par::Packer with script containing Net::SSH2 is not working

621 views Asked by At

Am using Net::SSH2 module in my Perl script and trying to make an executable (.exe for windows) using Par::Packer. The script need to ssh to a linux box from a windows box using public keys and don't want to input password.

Am facing the below error while running the .exe

Can't load 'C:\Users...\AppData\Local\Temp\par-73656172756d7567616d\cache-a6d57d5a234829aae84d08c4a78a09ad307ea8d3\a9057da2.xs.dll' for module Net::SSH2: load_file:The specified module could not be found at C:/Strawberry/perl/lib/DynaLoader.pm line 193. at C:/Strawberry/perl/vendor/lib/PAR/Heavy.pm line 123.

Tried to workaround with the below methods but none of them worked

  1. Tried to pack from a portable version of Strawberry Perl
  2. Tried to link a9057da2.xs.dll while packing using Par::Packer

Is there any workaround or fix for packing the perl scrip to .exe with Net:SSH2. Or are there alternatives to Net::SSH2 for ssh from windows to Linux using public keys (not passing passwords)?

2

There are 2 answers

0
Markus Wawersich On

If you get something like:

Can't load D:\TEMP\par-76696b616d7768\cache-48ca417d0c47dd7f7245a1218d8d6614470afa93\7c34139c.xs.dll' for module XML::LibXML: load_file:The specified module could not be found at <embedded>/DynaLoader.pm line 193.
at <embedded>/PAR/Heavy.pm line 140.
BEGIN failed--compilation aborted at D:\TEMP\par-76696b616d7768\cache-48ca417d0c47dd7f7245a1218d8d6614470afa93\inc\lib/XML/LibXML.pm line 156.
Compilation failed in require at script/test.pl line 3.
BEGIN failed--compilation aborted at script/test.pl line 3.

then add the following test code
(check your path to Listdlls.exe and fix the below as needed)

#This is the code causing the issue
use XML::LibXML;
my $x = XML::LibXML->new();

ListPerlDLLs();

sub ListPerlDLLs
{
  my @ret =  `C:\\"Program Files"\\Sysinternals\\Listdlls.exe  $$`; # $$ : current PID

  foreach my $line (@ret)
  {
    $line =~ s/\s$//;
    next if $line !~ /^0x\w+\s+\w+\s+(.+)/;
    my $dll = $1;
    next if $dll =~ /^c:\\windows\\/i;
    print "$dll\n";
  }
}

The Listdlls.exe is from Microsoft - see SysInternals \

First, double-click Listdlls.exe to accept the disclaimer
(will ask for approval on first launch).

When you run the Perl script, you will get something like this:

D:/strawberry-perl/perl/bin/perl.exe
D:/strawberry-perl/perl/bin/perl532.dll
D:/strawberry-perl/perl/bin/libgcc_s_seh-1.dll
D:/strawberry-perl/perl/bin/libwinpthread-1.dll
D:/strawberry-perl/perl/bin/libstdc++-6.dll
D:/strawberry-perl/perl/lib/auto/Encode/Encode.xs.dll
D:/strawberry-perl/perl/lib/auto/Fcntl/Fcntl.xs.dll
D:/strawberry-perl/perl/lib/auto/Storable/Storable.xs.dll
D:/strawberry-perl/perl/lib/auto/Data/Dumper/Dumper.xs.dll
D:/strawberry-perl/perl/lib/auto/IO/IO.xs.dll
D:/strawberry-perl/perl/vendor/lib/auto/XML/LibXML/LibXML.xs.dll
D:/strawberry-perl/c/bin/libxml2-2__.dll
D:/strawberry-perl/c/bin/libiconv-2__.dll
D:/strawberry-perl/c/bin/liblzma-5__.dll
D:/strawberry-perl/c/bin/zlib1__.dll
D:/strawberry-perl/perl/lib/auto/List/Util/Util.xs.dll

if you build your EXE and run it, you will get something like:

D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/test.exe
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/perl532.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/libgcc_s_seh-1.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/libwinpthread-1.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/libstdc++-6.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/5461bd7b.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/1ed3ae5b.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/89b9c18b.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/18f23f26.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/0e796a00.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/5d0ea4ea.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/d3d27bc6.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/d8bcc032.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/64916f0f.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/76c6a0cc.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/6b1ff21f.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/4eceebd6.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/ebaed210.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/831f407e.xs.dll
D:/TEMP/par-76696b616d7768/cache-48ca417d0c47dd7f7245a1218d8d6614470afa93/7c34139c.xs.dll
D:/strawberry-perl/c/bin/libxml2-2__.dll
D:/strawberry-perl/c/bin/liblzma-5__.dll
D:/strawberry-perl/c/bin/zlib1__.dll
D:/strawberry-perl/c/bin/libiconv-2__.dll

The last four are the missing DLLs -
add them with --link parameters:

call pp test.pl -o test.exe --link D:/strawberry-perl/c/bin/libxml2-2__.dll --link D:/strawberry-perl/c/bin/liblzma-5__.dll --link D:/strawberry-perl/c/bin/zlib1__.dll --link D:/strawberry-perl/c/bin/libiconv-2__.dll
0
salva On

Probably you are not packing the libssh2 and openssl DLLs inside the executable.

Par::Packer does not detect DLL dependencies automatically, you need to tell it explicitly which ones your program needs (a simple way to discover which DLLs your program needs is to use Process Monitor, an utility which allows one to monitor process activity).

Another option is to use my module Win32::Packer to pack the application which does find DLL dependencies automatically.