Patent attributes
During execution of a program, a code patching component may insert a redirection patch into a native-code representation of the program. The code patching component may identify a patch area in the native-code representation, copy existing code from the patch area to another location for subsequent emulation by a trap handler, determine the number of instructions and type of native-code elements within the patch area, and replace native-code elements in the patch area with native-code elements representing a jump type instruction and a target address argument for the jump type instruction (directly or indirectly indicating the location of new code that replaces the code in the patch area). The target address argument may be determined by the code patching component based on the program's characteristics, and may include a collection of elements representing existing code, trap type instructions, NOP type instructions, or arbitrary values.