edit: I can't seem to find it at the moment, but it was fairly simple. Intercept all mouse events, determine the clicked element, record the initial position, start dragging, etc. I think it did some fanciness for non-absolutely positioned or non-block elements too.
Though theoretically it could be used to steal designs also... I mean that already happens today but it'd be easier.
If you take a screen shot then load it into photoshop and move around a window, you'll get a big white box where the window was, because the screenshot app didn't record any information 'underneath' the window.
None of the big graphics libraries (GD, Image Magick, etc) support writing of layered PSD files (Imagick can read them, and export non-layered's, but that's it as far as I can tell.), and the format specs require you to sign an NDA/non-compete with Adobe.
Taking the screenshots is doable if a bit of a pain, but short of reverse engineering the psd format, the second part seems to be a roadblock. Shame, i'd use this too =P.
While you are at it, why not just save the file in Gimp format and be done with it? :-)