Window Goo

I need to know what to buy to replace the failing 'black goo' that surrounds the rear window.

Picture:
IMG_2910.jpg The left side, top, and right side are a deep black and still pliable.
The entire width of the bottom is a light gray and crumbles. The area just above the blue tape actually has a gap all the way to the car body. No doubt that is why all the rivets are rusting across the bottom.

What do I get at the hardware store or autoparts store to replace the black goo across the bottom?

Is this the same stuff that I put the bonnet back on with?

IMG_2879.jpg The irregular line of stuff across the top of the roof. Is it the same as the window goo?
Attached Images