#!/usr/bin/perl -w
use strict;
############################################################
#  usage:  ./OS_X_Lion_JimF.pl < file.plist >> shadowfile.in
############################################################

my $hexfile; my $hash; my $user;

read(STDIN, $_, 1000000) || die;
$hexfile = unpack('H*', $_); $_ = $hexfile;

# list00\xd1\x01\x02]SALTED-SHA512\xf4\x10\x44 followed by pass hash

($hash)=/6c6973743030d101025d53414c5445442d5348413531324f1044(.{136})/;
if (!$hash) {
   print "Could not find a Mac OS X 10.7 Lion salted SHA-512 hash\n";
   exit 1;
}

#  hex string below:  :SHA1.hex(40)user_name\xa1\x35\x4f\x10
($user) = /3a534841312e.{80}(.{2,64})a1354f10/;

if (!$user) { $user = "unk_username"; }
else        { $user =~ s/([a-f0-9][a-f0-9])/chr(hex($1))/eg; }

print $user, ":", $hash, "\n";

