How does the Put Back feature of the Trash work? This question is really more for my fellow computer scientists: how does the Put Back feature of the Trash directory work? I'm guessing the OS maintains some sort of index file which stores the path to the current location of the file before moving it to the Trash? Of course, this would be a bit more nuanced with non-empty directories...

Everything that was returned in an admittedly brief Web search had to do with end-user interaction with the Trash. I would like to know how OS X is doing this "under the hood" so that I can emulate the same handling in a script that I am writing.
According to https://superuser.com/questions/59376/how-to-tell-where-an-item-in-the-trash-came-from, "I know the original locations are stored in ~/.Trash/.DS_Store". .DS_Store is the name of the file that stores various Finder-related information.

Following that question, there is also How do I check where the file in .Trash was removed from? and How to determine original location of file that is currently in the Trash?, which don't quite look like duplicates but talk about some of the details a bit more.