As part of my PhD research, I developed a tool which inverts the computational steps of the Independent JPEG Group's JPEG decompressor version 6b. The tool maps an input image onto the set of bitstreams that produce it on decompression. If the set is empty, it indicates regions that are inconsistent with JPEG decompression.
Source code for the exact recompressor is available on my web page on exact JPEG recompression.