| 1 |
#!/bin/env perl -lw |
| 2 |
# |
| 3 |
# $Id: stripbin 19324 2012-09-29 14:38:11Z chninkel $ |
| 4 |
# |
| 5 |
# Copyright 2006 Cory Omand <comand@blastwave.org> |
| 6 |
# All rights reserved. Use is subject to license terms. |
| 7 |
# |
| 8 |
# Redistribution and/or use, with or without modification, is |
| 9 |
# permitted. This software is without warranty of any kind. The |
| 10 |
# author(s) shall not be liable in the event that use of the |
| 11 |
# software causes damage. |
| 12 |
# |
| 13 |
# stripbin - strip binaries found in the target directory |
| 14 |
# |
| 15 |
|
| 16 |
use strict; |
| 17 |
|
| 18 |
my $bindir = $ARGV[0] || die "Usage: $0 <binary dir>"; |
| 19 |
|
| 20 |
foreach my $file (glob "$bindir/*") { |
| 21 |
my ($filechar) = `file $file`; |
| 22 |
die "Failed to get characteristics for file $file" unless (($? >> 8) == 0); |
| 23 |
|
| 24 |
if ($filechar =~ /ELF/ && $filechar =~ /not stripped/) { |
| 25 |
print "Stripping $file ... "; |
| 26 |
|
| 27 |
# Make sure we can write to the file |
| 28 |
my $perm = (stat $file)[2] & 07777; |
| 29 |
print "making file temporarily writable ... " unless( $perm & 0200 ); |
| 30 |
chmod($perm | 0200, $file); |
| 31 |
system "/usr/ccs/bin/strip", $file and die "Failed."; |
| 32 |
chmod($perm, $file); |
| 33 |
print "Done.\n"; |
| 34 |
} |
| 35 |
} |