Do routers and switches generally have the same hardware? That is to say, if one flashed the firmware of a router on a switch, would it effectively be a router?
Mike Pennington already said that the answer was generally "no", and that's a good answer as far as it goes.
The answer really comes down to definitional questions. The term "switch" is really pretty poorly defined and used in a lot of contexts, so its almost impossible to give an absolute answer.
"Layer 3 switching" was originally a (very marketingish) term for a router that forwards packets based on inspection of layer 3 header information using "hardware" such as an ASIC to do the forwarding, rather than using software running on a general purpose CPU.
Nowadays, most routers of any significant scale use ASICs (or FPGAs) in the data plane to forward packets. Hardware based routers turn out to be able to do switching at Layer 2 or routing at Layer 3 with essentially no performance differences, so the definition between "switch" and "router" has really become very blurry with modern gear.
Whether traffic if forwarded based on layer 2 header information or layer 3 information has become a matter of configuration on modern high end gear rather than hardware.
To pick one example, with the right set of blades, you could take every blade out of a Cisco 6500 "Switch" (as they label it on their website) and slide them into a 7600 "Router" (again, as they label it on their website), and the behavior essentially doesn't change at all.
That having been said, you can still get gear that only does layer 2 switching and isn't capable of doing layer 3 switching based on the capabilities of the ASICs included in the equipment. You'll also could find examples where a device is released with a certain set of capabilities (say layer 2 switching only), but the hardware is capable of more and the software to control it just hasn't been written, yet. Later releases of the firmware/software for the device can then enable those capabilities that had been physically available, just not turned on by software.
So...the answer can really only be, "it depends." Sorry, I know that's typically an unsatisfying answer, but its the best that can really be done without narrowing down the scope a bit.