https://stackoverflow.com/questions/38063529/x86-32-x86-64-p...
...and if you want to expand it to run on a SPARC or MIPS or something else...
https://hackaday.io/project/18614-polyglot-one-binary-multip...
The general idea is to find a set of bytes which can be interpreted in different (and valid) ways by all the architectures you want to support, and using those differences, jump to architecture-specific code.
https://stackoverflow.com/questions/38063529/x86-32-x86-64-p...
...and if you want to expand it to run on a SPARC or MIPS or something else...
https://hackaday.io/project/18614-polyglot-one-binary-multip...
The general idea is to find a set of bytes which can be interpreted in different (and valid) ways by all the architectures you want to support, and using those differences, jump to architecture-specific code.