Created
March 11, 2016 04:13
-
-
Save trwyant/5a5e850d2eabe91728c0 to your computer and use it in GitHub Desktop.
Perl script to find installed Perl modules that link to libssl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use 5.010; | |
use strict; | |
use warnings; | |
use File::Find; | |
use File::Spec; | |
use Getopt::Long 2.33 qw{ :config auto_version }; | |
use List::Util qw{ min }; | |
use Pod::Usage; | |
our $VERSION = '0.000_01'; | |
my %opt; | |
GetOptions( \%opt, | |
help => sub { pod2usage( { -verbose => 2 } ) }, | |
) or pod2usage( { -verbose => 0 } ); | |
my $dir = @ARGV ? $ARGV[0] : shortest_prefix( @INC ); | |
my %found; | |
my %searched; | |
say "Searching $dir"; | |
find( \&check, $dir ); | |
foreach my $bundle ( sort keys %found ) { | |
say $bundle; | |
say " $found{$bundle}"; | |
} | |
sub check { | |
-f $_ | |
and -B _ | |
or return; | |
`file '$File::Find::name'` =~ m/ \b Mach-O \b /smx | |
or return; | |
foreach ( `otool -L '$File::Find::name'` ) { | |
m/ \b libssl \b /smx | |
or next; | |
s/ \s+ \z //smx; | |
s/ \A \s+ //smx; | |
$found{ $File::Find::name } = $_; | |
last; | |
} | |
return; | |
} | |
sub shortest_prefix { | |
my @arg = @_; | |
@arg = sort { length $a <=> length $b || $a cmp $b } | |
grep { m / \b lib \b /smx } @arg; | |
my $std = shift @arg; | |
my $lim = length $std; | |
foreach my $loc ( 1 .. $lim ) { | |
my $sub = substr $std, 0, $loc; | |
foreach my $str ( @arg ) { | |
$sub eq substr $str, 0, $loc | |
and next; | |
return substr $std, 0, $loc - 1; | |
} | |
} | |
return $std; | |
} | |
__END__ | |
=head1 TITLE | |
find-libssl - Find Perl Mach-O files that link to libssl | |
=head1 SYNOPSIS | |
find-libssl | |
find-libssl ~/.perl/lib | |
find-libssl -help | |
find-libssl -version | |
=head1 OPTIONS | |
=head2 -help | |
This option displays the documentation for this script. The script then | |
exits. | |
=head2 -version | |
This option displays the version of this script. The script then exits. | |
=head1 DETAILS | |
This Perl script attempts to find all Mach-O files generated by Perl | |
modules that link to C<libssl>. The argument is the Perl F<lib/> | |
directory to search. If no argument is specified, we attempt to figure | |
out which directory to search from the contents of C<@INC>. This attempt | |
may well fail. | |
For each binary normal file found, the C<file> command is run to | |
determine if it is a Mach-O file. If this check succeeds, the C<otool | |
-L> command is run to determine what that file links to. If C<'libssl'> | |
is found in the output, the Perl file and the OpenSSL library linked to | |
are written to standard out. | |
=head1 AUTHOR | |
Thomas R. Wyant, III F<wyant at cpan dot org> | |
=head1 COPYRIGHT AND LICENSE | |
Copyright (C) 2016 by Thomas R. Wyant, III | |
This program is free software; you can redistribute it and/or modify it | |
under the same terms as Perl 5.10.0. For more details, see the Artistic | |
License 1.0 at | |
L<http://www.perlfoundation.org/artistic_license_1_0>, and/or the Gnu | |
GPL at L<http://www.gnu.org/licenses/old-licenses/gpl-1.0.txt>. | |
This program is distributed in the hope that it will be useful, but | |
without any warranty; without even the implied warranty of | |
merchantability or fitness for a particular purpose. | |
=cut | |
# ex: set textwidth=72 : |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment