Tested on 10.7.3 & 10.7.4
To turn rounded corners off for all windows use the following command in Terminal.
defaults write -g AppleUseCoreUI -bool false ; killall Finder
To restore the rounded corners for all windows use the following command in Terminal.
defaults write -g AppleUseCoreUI -bool true ; killall Finder
NOTE: For this to take effect on already open applications those applications must be closed and reopened (this is why the commands above include killall Finder). Some Applications may interact differently once CoreUI is turned off.
ALSO: This does not affect the corners at the bottom of the window. They will still appear rounded. (As noted in comments by Daniel Lawson)
If you are not comfortable with the killall Finder being used in your command the steps can be taken to ensure the same result.
Step 1. (Turn off rounded corners)
Run the following Command
defaults write -g AppleUseCoreUI -bool false
Remember to close and reopen any Applications that were open when prior to this command being run.
Step 2. (Turn off rounded corners)
To restore the original rounded corners, simply use the same 2 Steps and replace the false found at the end of the command with true as shown in the following command.
defaults write -g AppleUseCoreUI -bool true
Remember: It is very likely that as you update your OS the rounded corners will reappear. However, even after your next OS update, the same steps listed above are likely to function the same. :–)
From Apple KB Article HT5369:
If the detect displays option is not available, hold down the ⌥ alt/option key while you are in the Display pane.
It should morph the "Gather Windows" button into the "Detect Displays" button.
Stupid change, isn't it?
I figured it out, I used ThemeEngine to edit the appropriate theme in SystemAppearance.bundle.
I made a repo with the changes here: https://github.com/tsujp/custom-macos-gui
I know StackExchange hate linking answers so here is a summary for my case: