Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!ncar!gatech!purdue!haven!ni.umd.edu!sayshell.umd.edu!louie From: louie@sayshell.umd.edu (Louis A. Mamakos) Newsgroups: comp.sys.next Subject: Re: Ripping apart NIBS Summary: perl version of extract and combine with new features Message-ID: <1991Feb22.054549.15205@ni.umd.edu> Date: 22 Feb 91 05:45:49 GMT References: <5288@media-lab.MEDIA.MIT.EDU> Sender: usenet@ni.umd.edu (USENET News System) Organization: University of Maryland, College Park Lines: 155 The NIB extrator is really neat! Not willing to leave well enough alone, here's a version in Perl which a bit smaller on the disk assuming, of course, that you already have Perl installed on your machine as all right-thinking folks do! It also extracts other "interesting" parts of the NIB file including .tiff files, .snd files, etc. Enjoy! My thanks to Simson for thinking up this wonderful idea.. My thanks to Larry Wall for Perl, a wonderful tool for hacking up stuff like this. louie #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # extract # combine # This archive created: Fri Feb 22 00:37:28 1991 export PATH; PATH=/bin:$PATH if test -f 'extract' then echo shar: will not over-write existing file "'extract'" else sed 's/^X//' << \SHAR_EOF > 'extract' X#!/usr/local/bin/perl -s X# X# extract.pl 0.1 X# Louis Mamakos X# X# Quick and dirty hack. Used to extract various interesting X# piece of NeXT .nib files for examination, modification and X# possible replacement. Inspired by the pair of C programs X# written by simsong@daily-bugle.media.mit.edu (Simson L. Garfinkel), X# usage is pretty much the same. This version also extracts stuff X# from the __TIFF, __ICON and __SND segments as well as the original X# doing the __NIB segment. X# X# TODO: X# - Need to be a bit more clever to fix up truncated names. If part of X# required extension is there, we should complete it rather than just X# append the whole thing. X# X X($prog = $ARGV[0]) || die "No arg specified,"; X Xopen(OTOOL, "otool -l $prog |"); Xopen(FILES, ">NIBFILES"); X X@NIBFILES = (); @TIFFFILES = (); @ICONFILES = (); @SNDFILES = (); X Xwhile() { X chop; X next unless /^Section$/; X $_ = ; chop; X next unless /^ sectname (.*)$/; X $sectname = $1; X $_ = ; chop; X /^ segname __NIB$/ && push(@NIBFILES, $sectname); X /^ segname __TIFF$/ && push(@TIFFFILES, $sectname); X /^ segname __ICON$/ && push(@ICONFILES, $sectname); X /^ segname __SND$/ && push(@SNDFILES, $sectname); X} Xclose(OTOOL); X Xformat FILES = X@<<<<<< @<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<< X$type $sect $filename $time X. X X&nibsegment("__NIB", ".nib", @NIBFILES); X&nibsegment("__TIFF", ".tiff", @TIFFFILES); X&nibsegment("__ICON", ".icon.tiff", @ICONFILES); # need to use a different extension for __ICON files X&nibsegment("__SND", ".snd", @SNDFILES); Xclose(FILES); X Xsub nibsegment { X @files = @_; X $type = shift(@files); X $ext = shift(@files); X X foreach $sect (@files) { X $filename = $sect; X $filename .= $ext unless ($filename =~ m/$ext$/); X X if (-e $filename) { X print "$filename already exists; skipping...\n"; X next; X } X print "Extracting $sect -> $filename\n"; X print "segedit -extract $type $sect $filename $prog\n" if $debug; X # X # Probably should extract multiple sections at a time... X # X system "segedit -extract $type $sect $filename $prog"; X @a = stat($filename); X $time = $a[$[ + 9]; X write FILES; X } X} X X X SHAR_EOF fi # end of overwriting check if test -f 'combine' then echo shar: will not over-write existing file "'combine'" else sed 's/^X//' << \SHAR_EOF > 'combine' X#!/usr/local/bin/perl -s X# combine.pl 0.1 X# Louis Mamakos X# X# quick and dirty hack, use with "extract" perl script. X# This version, unlike the C version, will replace all of the X# modified files in one fell swoop. The thing to worry about here is X# if the command line grows too large; this is unlikely to be a X# real problem. Hey, its just a quick hack.. X# X($prog = $ARGV[0]) || die "No source program specified.\n"; X($new = $ARGV[1]) || die "No new program specified.\n"; X Xopen(NIBFILES, "< NIBFILES"); X X$command = ''; X Xwhile() { X ($type, $nib, $file, $mtime) = split; X X next if (! -e $file); X @a = stat($file); X $time = $a[$[ + 9]; X if ($time > $mtime) { X $command .= " -replace $type $nib $file"; X print X "File $file [sect name $nib seg name $type] has been modified\n"; X print "New file is ", $time - $mtime, X " seconds newer\n" if $debug; X } X} Xclose(NIBFILES); Xif ($command ne '') { X print "segedit $command $prog -output $new\n" if $debug; X system "segedit $command $prog -output $new"; X} else { X print "No modified files\n"; X} X X SHAR_EOF fi # end of overwriting check # End of shell archive exit 0 Brought to you by Super Global Mega Corp .com