How To Determine Dynamic Library Dependencies For An Executable or Library File in OS X

This script uses otool -L to determine and print all dynamic library dependencies of a given executable or library file recursively and you use it like this:

$ checklibs.pl /bin/ls
   /bin/ls:
            /usr/lib/libgcc_s.1.dylib
            /usr/lib/libncurses.5.4.dylib
            /usr/lib/libSystem.B.dylib
   /usr/lib/libgcc_s.1.dylib:
            /usr/lib/libSystem.B.dylib
   /usr/lib/libncurses.5.4.dylib:
            /usr/lib/libgcc_s.1.dylib
            /usr/lib/libSystem.B.dylib
   /usr/lib/libSystem.B.dylib:
            /usr/lib/system/libmathCommon.A.dylib

Here’s the script which was written by Marc Liyanage:

#!/usr/bin/perl
#
# Written by Marc Liyanage <http://www.entropy.ch>
# use strict;
use warnings; 

my ($file) = @ARGV;
die $! unless (-f $file); 

my $libs = {};
check_libs(file => $file, libs => $libs); 

print
	map {("\n$_:\n", map {"\t$_\n"} sort {lc($a) cmp lc($b)} @{$libs->{$_}})}
	sort {lc($a) cmp lc($b)}
	grep {@{$libs->{$_}}}
	keys(%$libs);
sub check_libs {
	my (%args) = @_;
	my $libs = $args{libs};
	my @file_libs = grep {$_ ne $args{file}} grep {$_} map {/^\s+(\S+)/} qx(otool -L $args{file});
	$libs->{$args{file}} = \@file_libs;
	foreach my $lib (grep {!$libs->{$_}} @file_libs) {
		unless (-f $lib) {
			$libs->{$lib} = ['(missing)'];
			next;
		}
		check_libs(%args, file => $lib);
	}
}

In case my blog software mangles the code above, you can download the script in a plain text file by clicking here: checklibs.zip

Code

How to Determine What Program Is Listening on a Port in OS X or Linux

To determine what daemon or program is listening on a port in Linux or OS X you can use the lsof command. You need to run the command while logged in as root or if your operating system supports sudo like OS X, you can use that.

Command to run in Linux:

lsof -i -nP

Command to run in OS X:

sudo lsof -i -nP

Terminal

Installing Windows XP x64 with AHCI Enabled on a Gigabyte GA-P35-DS3R Motherboard

There are two SATA controllers on the motherboard. The Intel SATA interface and the Gigabyte (JMicron) SATA interface. In order for AHCI to work with the Intel SATA interface, you must install the drivers at Windows install time or you can perform a hack after Windows is installed. Here is what you need to do for a clean install of Windows XP x64:

  1. Make the Windows x64 “pre-installation” driver floppy disk for the Intel SATA controller. You can get this off the Gigabyte website with the other motherboard drivers.
  2. In the BIOS enable AHCI for the Intel interface but set the Gigabyte SATA interface to “IDE” mode. If you don’t set the Gigabyte interface to “IDE” mode then the Windows setup program will not see drives connected to that interface.
  3. Boot off the Windows XP x64 installation CD and press “F6” when the installation program prompts to do so in order to install the Intel SATA interface drivers off the driver floppy disk you made in step one.
  4. Complete the installation of Windows XP x64.
  5. Download the Gigabyte SATA interface driver from the Gigabyte website and install it in Windows. Then reboot the computer.
  6. When the computer reboots, enter the BIOS
  7. Enable AHCI for the Gigabyte SATA interface and then save the change.
  8. When Windows XP x64 boot, it should recognize the AHCI mode of the Gigabyte SATA interface and install the drivers. Then it will prompt you to reboot.
  9. After Windows XP x64 reboots, the Gigabyte SATA interface will now be in AHCI mode.

Gigabyte GA-P35-DS3R Motherboard