#!/usr/bin/perl
#
# AppleSingle/AppleDouble dump
#
# (c) 2009-2010 by HAT <hat@fa2.so-net.ne.jp>
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  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.  See the
#  GNU General Public License for more details.
# 

# 
# References:
# 
# Applesingle and AppleDouble format internals (version 1)
# http://users.phg-online.de/tk/netatalk/doc/Apple/v1/
# 
# AppleSingle/AppleDouble Formats for Foreign Files Developer's Note (version2)
# http://users.phg-online.de/tk/netatalk/doc/Apple/v2/AppleSingle_AppleDouble.pdf
# 
# Inside Macintosh: Macintosh Toolbox Essentials /
# Chapter 7 - Finder Interface / Finder Interface Reference
# http://developer.apple.com/legacy/mac/library/documentation/mac/toolbox/Toolbox-463.html
# 
# Finder Interface Reference
# http://developer.apple.com/legacy/mac/library/documentation/Carbon/Reference/Finder_Interface/Reference/reference.html
# 
# Technical Note TN1150  HFS Plus Volume Format
# http://developer.apple.com/mac/library/technotes/tn/tn1150.html#FinderInfo
# 
# CarbonHeaders source
# http://www.opensource.apple.com/source/CarbonHeaders/CarbonHeaders-8A428/Finder.h
# http://www.opensource.apple.com/source/CarbonHeaders/CarbonHeaders-9A581/Finder.h
# 
# Xcode 3.2.1
# /usr/bin/SetFile
# /usr/bin/GetFileInfo
# 
# Mac OS X 10.6.2 kernel source
# http://www.opensource.apple.com/source/xnu/xnu-1486.2.11/bsd/vfs/vfs_xattr.c
# 

use File::Basename;
use File::Spec;
use bigint; # require perl >= 5.8

# parse command line -----------------------------------------------

$finderinfo = 0;              #  0: unknown   1: file   2: directory
while ($arg = shift @ARGV)
{
    if  ($arg =~ /^(-h|-help|--help)$/ ) {
        printf ("usage: %s [-a] FILE|DIR\n"     ,basename($0));
        printf (" or:   %s -f FILE\n"           ,basename($0));
        printf (" or:   %s -d FILE\n"           ,basename($0));
        printf (" or:   %s -h|-help|--help\n"   ,basename($0));
        printf ("Dump AppleSingle/AppleDouble format file.\n");
        printf ("\n");
        printf ("  -a (default)     Dump a AppleSingle/AppleDouble file for FILE or DIR\n");
        printf ("                   automatically.\n");
        printf ("                   Extrapolate FinderInfo type from absolute path.\n");
        printf ("                   If FILE is not AppleSingle/AppleDouble format,\n");
        printf ("                   look for '.AppleDouble/FILE' and '._FILE'.\n");
        printf ("                   If DIR, look for 'DIR/.AppleDouble/.Parent' and '._DIR'.\n");
        printf ("  -f               Dump FILE. Assume FinderInfo to be FileInfo.\n");
        printf ("  -d               Dump FILE. Assume FinderInfo to be DirInfo.\n");
        printf ("  -h,-help,--help  Display this help and exit\n");
        printf ("\n");
        printf ("There is no way to detect whether FinderInfo is FileInfo or DirInfo.\n");
        printf ("By default, %s examins whether file or directory,\n"   ,basename($0));
        printf ("a parent directory is .AppleDouble, filename is ._*, filename is .Parent,\n");
        printf ("and so on.\n");
        printf ("If setting option -f or -d, %s assume FinderInfo and doesn't look for\n");
        printf ("another file.\n");
        exit 0;
    } elsif ($arg eq "-a") {
        $finderinfo = 0;
    } elsif ($arg eq "-f") {
        $finderinfo = 1;
    } elsif ($arg eq "-d") {
        $finderinfo = 2;
    } elsif ($arg =~ /^-/) {
	printf (STDERR "%s: invalid option %s\n", basename($0), $arg);
	printf (STDERR "Try \`%s\ -h' for more information.\n", basename($0));
	exit 1;
    } else {
        $afile = $arg;
    }
}

if (!($afile)) {
    printf (STDERR "missing file operand.\n");
    exit 1;
}
if (!( -e $afile)) {
    printf (STDERR "\"%s\" not found.\n", $afile);
    exit 1;
}

# detect FinderInfo, and search AppleSingle/AppleDouble file --------------

$abspath = File::Spec->rel2abs($afile);
($basename, $path, $ext) = fileparse($abspath);

if ( $finderinfo != 0 ) {
    ;
} elsif ( -f $afile ) {
    if ( $basename eq ".Parent") {
	$finderinfo = 2;
    } elsif ( $path =~ /\/.AppleDouble\/$/ ) {
	$finderinfo =1;
    } elsif ( $basename =~ /^._/ ) {
	if ( -f $path.substr($basename, 2) ) {
	    $finderinfo =1;
	} elsif ( -d $path.substr($basename, 2) ) {
	    $finderinfo =2;
	}
    }
    if (!open(INFILE, "<$afile")) {
	printf (STDERR "cannot open %s\n",  $afile);
	exit 1;
    }
    read(INFILE,$buf,4);
    $val = unpack("N", $buf );
    close(INFILE);
    if ($val == 0x00051600 || $val == 0x00051607) {
	;
    } else {
	printf ("\"%s\" is not AppleSingle/AppleDouble format.\n", $afile);
	$finderinfo = 1;
	$netatalkfile = $path.".AppleDouble/".$basename;
	$osxfile = $path."._".$basename;

	if (( -e $netatalkfile ) && !( -e $osxfile )) {
	    $afile = $netatalkfile;
	} elsif (!( -e $netatalkfile ) && ( -e $osxfile )) {
	    $afile = $osxfile;
	} elsif (( -e $netatalkfile ) && ( -e $osxfile )) {
	    printf ("\"%s\" found.\n", $netatalkfile);
	    printf ("\"%s\" found.\n", $osxfile);
	    printf ("Specify which of file.\n");
	    exit 1;
	} else {
	    printf ("\"%s\" not found.\n", $netatalkfile);
	    printf ("\"%s\" not found.\n", $osxfile);
	    exit 1;
	}
    }
} elsif ( -d $afile) {
    printf ("\"%s\" is a directory.\n", $afile);
    $finderinfo =2;
    $netatalkfile = $path.$basename."/.AppleDouble/.Parent";
    $osxfile = $path."._".$basename;

    if (( -e $netatalkfile ) && !( -e $osxfile )) {
	$afile = $netatalkfile;
    } elsif (!( -e $netatalkfile ) && ( -e $osxfile )) {
	$afile = $osxfile;
    } elsif (( -e $netatalkfile ) && ( -e $osxfile )) {
	printf ("\"%s\" found.\n", $netatalkfile);
	printf ("\"%s\" found.\n", $osxfile);
	printf ("Specify which of file.\n");
	exit 1;
    } else {
	printf ("\"%s\" not found.\n", $netatalkfile);
	printf ("\"%s\" not found.\n", $osxfile);
	exit 1;
    }
} else {
    printf (STDERR "unknown error: %s\n", $afile);
    exit 1;
}

if (!open(INFILE, "<$afile")) {
    printf (STDERR "cannot open %s\n",  $afile);
    exit 1;
}
printf ("%s:\n\n", $afile);

# Magic Number -----------------------------------------------

print "-------------------------------------------------------------------------------\n";

read(INFILE,$buf,4);
$val = unpack("N", $buf );
printf("MagicNumber: %08X", $val);
if    ( $val == 0x00051600 ) {
    printf("                                        : AppleSingle");
}
elsif ( $val == 0x00051607 ) {
    printf("                                        : AppleDouble");
}
else                         {
    printf("                                        : Unknown"    );
}
print "\n";

# Version Number ---------------------------------------------

read(INFILE,$buf,4);
$version = unpack("N", $buf );
printf("Version    : %08X", $version);
if ( $version == 0x00010000 ) {
    printf("                                        : Version 1");
} elsif ( $version == 0x00020000 ) {
    printf("                                        : Version 2");
} else {
    printf("                                        : Unknown"  );
}
print "\n";

# v1:Home file system / v2:Filler ----------------------------

read(INFILE,$buf,16);
if ( $version == 0x00010000 ) {
    print "HomeFileSys:";
} else {
    print "Filler     :";
}
hexdump($buf, 16, 16, " ");

# Number of entities -----------------------------------------

read(INFILE,$buf,2);
$entnum = unpack("n", $buf );
printf("Num. of ent: %04X    ", $entnum);
printf("                                        : %d", $entnum);
print "\n";

# data -------------------------------------------------------

for ( $num = 0 ; $num < $entnum ; $num++) {

    seek(INFILE, ($num * 12 + 26), 0);

#    Entry ---------------------------------------------------

    read(INFILE,$buf,4);
    $entid = unpack("N", $buf );
    print "\n-------------------------------------------------------------------------------\n";
    printf("Entry ID   : %08X", $entid);
    if    ( $entid ==  1 )         { printf(" : Data Fork"); }
    elsif ( $entid ==  2 )         { printf(" : Resource Fork"); }
    elsif ( $entid ==  3 )         { printf(" : Real Name"); }
    elsif ( $entid ==  4 )         { printf(" : Comment"); }
    elsif ( $entid ==  5 )         { printf(" : Icon, B&W"); }
    elsif ( $entid ==  6 )         { printf(" : Icon Color"); }
    elsif ( $entid ==  7 )         { printf(" : File Info"); }
    elsif ( $entid ==  8 )         { printf(" : File Dates Info"); }
    elsif ( $entid ==  9 )         { printf(" : Finder Info"); }
    elsif ( $entid == 10 )         { printf(" : Macintosh File Info"); }
    elsif ( $entid == 11 )         { printf(" : ProDOS File Info"); }
    elsif ( $entid == 12 )         { printf(" : MS-DOS File Info"); }
    elsif ( $entid == 13 )         { printf(" : Short Name"); }
    elsif ( $entid == 14 )         { printf(" : AFP File Info"); }
    elsif ( $entid == 15 )         { printf(" : Directory ID"); }
    elsif ( $entid == 0x8053567E ) { printf(" : CNID (Netatalk Extended)"); }
    elsif ( $entid == 0x8053594E ) { printf(" : DB stamp (Netatalk Extended)"); }
    elsif ( $entid == 0x80444556 ) { printf(" : dev (Netatalk Extended)"); }
    elsif ( $entid == 0x80494E4F ) { printf(" : inode (Netatalk Extended)"); }
    else                           { printf(" : Unknown"); }
    print "\n";

#    Offset -------------------------------------------------

    read(INFILE,$buf,4);
    $ofst = unpack("N", $buf );
    printf("Offset     : %08X", $ofst);
    printf(" : %d ", $ofst);

#    Length -------------------------------------------------

    read(INFILE,$buf,4);
    $len = unpack("N", $buf );
    printf("\nLength     : %08X", $len);
    printf(" : %d", $len);
    $quo = $len >> 4;
    $rem = $len & 0xF;
    print "\n";

#     Dump for each Entry ID --------------------------------

#    if ( $entid ==  1 ) { ; } # Data Fork
#    if ( $entid ==  2 ) { ; } # Resource Fork
#    if ( $entid ==  3 ) { ; } # Real Name
#    if ( $entid ==  4 ) { ; } # Comment
#    if ( $entid ==  5 ) { ; } # Icon, B&W
#    if ( $entid ==  6 ) { ; } # Icon Color
#    if ( $entid ==  7 ) { ; } # File Info
    if ( $entid ==  8 ) { filedatesdump($ofst,$len); }
    elsif ( $entid ==  9 ) { finderinfodump($ofst,$len); }
#    if ( $entid == 10 ) { ; } # Macintosh File Info
#    if ( $entid == 11 ) { ; } # ProDOS File Info
#    if ( $entid == 12 ) { ; } # MS-DOS File Info
#    if ( $entid == 13 ) { ; } # Short Name
#    if ( $entid == 14 ) { ; } # AFP File Info 
    elsif ( $entid == 15 ) { print "\n"; bedump($ofst,$len); } # Directory ID
    elsif ( $entid == 0x8053567E  ) { print "\n"; bedump($ofst,$len); } # CNID (Netatalk Extended)
    elsif ( $entid == 0x8053594E  ) { print "\n"; bedump($ofst,$len); ledump($ofst,$len); } # DB stamp (Netatalk Extended)
    elsif ( $entid == 0x80444556  ) { print "\n"; bedump($ofst,$len); ledump($ofst,$len); } # dev (Netatalk Extended)
    elsif ( $entid == 0x80494E4F  ) { print "\n"; bedump($ofst,$len); ledump($ofst,$len); } # inode (Netatalk Extended)

#    RAW Dump ---------------------------------------------------

    if ( ($quo > 0) || ($rem > 0)) {
	print "\n";
	print "-RAW DUMP--:  0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F : (ASCII)\n";
    }

    seek(INFILE, $ofst, 0);
    rawdump($quo, $rem);

}

close(INFILE);
exit 0;

#sub -----------------------------------------------------------

sub filedatesdump {
    my ($ofst, $len) = @_;
    my ($datedata);
    my ($i);
    my ($datestr);

    @datetype =('create    ', 'modify    ', 'backup    ', 'access    ');

    seek(INFILE, $ofst, 0);

    print "\n";
    printf ("-DATE------:          : (GMT)                    : (Local)\n");

    for ( $i = 0 ; $i < 4 ; $i++) {
        read(INFILE,$buf,4);
        $datedata = unpack("N", $buf );
        if ($datedata < 0x80000000) {
            $datestr = gmtime( $datedata + 946684800)
                ." : "
                .localtime( $datedata + 946684800);
        } elsif ($datedata == 0x80000000) {
            $datestr = "Unknown or Initial";
        } else {
            $datestr = gmtime( $datedata - 3348282496)
                ." : "
                .localtime( $datedata - 3348282496);
        }
        printf ("%s : %08X : %s\n",$datetype[$i], $datedata, $datestr);
    }
}

sub finderinfodump {
    my ($ofst, $len) = @_;

    seek(INFILE, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0);

    if ($finderinfo == 0--------------------------E, $ofst, 0)