Sync iPhone and dead mac
Attach your phone to any Mac that you want to use as your new machine. It can be the same machine with a new hard drive, or a completely new Mac altogether.
When prompted to sync, cancel, so that you don't lose the data on your phone.

Now, click File -> Transfer Purchases. You will be prompted to "authorize" your Mac. Log in and then you should be able to transfer your music and apps. 

If you want to save your contacts to your computer, look through the "Info" tab to have iTunes overwrite the contacts on your Mac with those on your phone. There are settings for that there.

You can also use Music Rescue (shareware) to pull off your music.