openbcm

Git mirror of https://github.com/Broadcom-Network-Switching-Software/OpenBCM
git clone git://git.finwo.net/mirror/broadcom/openbcm
Log | Files | Refs | README

stripfix.pl (2095B)


      1 #!/usr/bin/perl
      2 #
      3 # 
      4 #
      5 # This license is set out in https://raw.githubusercontent.com/Broadcom-Network-Switching-Software/OpenBCM/master/Legal/LICENSE file.
      6 # 
      7 # Copyright 2007-2019 Broadcom Inc. All rights reserved.
      8 #
      9 # Perl version of the "stripfix.c" program
     10 #
     11 # In Tornado tools, stripppc and objcopyppc corrupt the ELF program header
     12 # and require the use of the "stripfix" kludge.  Alternately, Solaris'
     13 # strip works on PPC binaries also (/usr/ccs/bin/strip).
     14 #
     15 
     16 use Fcntl;
     17 
     18 ($prog = $0) =~ s,.*/,,;
     19 
     20 ($#ARGV == 3) ||
     21     die "Usage: $prog <unstripped-file> <stripped-file> <byte-offset> <word-count>\n" .
     22         "\tThis utility extracts <word-count> words from <unstripped-file>\n" .
     23         "\tstarting at offset <byte-offset>, and pastes them into the same\n" .
     24         "\tlocation in <stripped-file>.\n";
     25 
     26 ($unstripped, $stripped, $offset, $words) =
     27     ($ARGV[0], $ARGV[1], $ARGV[2], $ARGV[3]);
     28 
     29 #
     30 # Read the interesting bytes from the unstripped input file
     31 #
     32 sysopen(INFILE, $unstripped, O_RDONLY, 0) ||
     33     die "$prog: input file $unstripped: cannot open: $!\n";
     34 binmode INFILE;
     35 sysseek(INFILE, $offset, SEEK_SET) ||
     36     die "$prog: input file $unstripped: seek failed: $!\n";
     37 $len = sysread(INFILE, $data, $words * 4);
     38 defined($len) ||
     39     die "$prog: input file $unstripped: read failed: $!\n";
     40 ($len == $words * 4) ||
     41     die "$prog: input file $unstripped: read failed: returned $len bytes\n";
     42 close(INFILE) ||
     43     die "$prog: input file $unstripped: close failed: $!\n";
     44 
     45 #
     46 # Now overwite the corresponding bytes in the stripped output file
     47 #
     48 sysopen(OUTFILE, $stripped, O_WRONLY, 0) ||
     49     die "$prog: output file $stripped: cannot open: $!\n";
     50 binmode OUTFILE;
     51 sysseek(OUTFILE, $offset, SEEK_SET) ||
     52     die "$prog: output file $stripped: seek failed: $!\n";
     53 $len = syswrite(OUTFILE, $data, $words * 4);
     54 defined($len) ||
     55     die "$prog: output file $stripped: write failed: $!\n";
     56 ($len == $words * 4) ||
     57     die "$prog: output file $stripped: write failed: only $len bytes written\n";
     58 close(OUTFILE) ||
     59     die "$prog: output file $stripped: close failed: $!\n";
     60 
     61 exit 0;