As long as the tailpipe is clean, they won't notice the ECU being reprogrammed (although it's still illegal).
They do tend to spot things like having a V8 in a 4-cylinder car, though. The swap could be done legally, but you'd have to tell them what car the engine came from (which has to be the same year or newer), and show that you moved over whatever emission control devices the donor car had on it (cat, carbon canister, EGR, etc). Then you have to meet the tailpipe standards for the donor car.
I didn't say it was impossible, just difficult.
Another possibility might be re-registering it as a kit car, but I believe that involves significant hassles as well. Only 500 per year allowed and the result still has to meet the smog standards for the engine's model year (or use an engine old enough to not have any smog equipment). Again it could be done (the Buick 215 was introduced in 1965 as I recall and I think the cutoff year was 1968), but not easily.
On the subject of changing ECU programming; it should actually be easy to come up with a program that would pass the test without hindering performance (if just reprogramming the ECU would pass to begin with). The test only includes idle and low speed cruise, they don't look at WOT at all. But ECU programming won't make up for a lumpy cam, or lack of a cat.