US 12,271,748 B2
Changing program behavior at runtime
Jingyu Ma, Chong Qing (CN); and Yong Liu, Redmond, WA (US)
Assigned to Microsoft Technology Licensing, LLC, Redmond, WA (US)
Filed by Microsoft Technology Licensing, LLC, Redmond, WA (US)
Filed on Mar. 23, 2022, as Appl. No. 17/702,647.
Prior Publication US 2023/0305868 A1, Sep. 28, 2023
Int. Cl. G06F 9/44 (2018.01); G06F 9/32 (2018.01); G06F 9/38 (2018.01); G06F 9/455 (2018.01)
CPC G06F 9/45516 (2013.01) [G06F 9/328 (2013.01); G06F 9/3806 (2013.01)] 20 Claims
OG exemplary drawing
 
1. A computer system comprising:
one or more processors; and
one or more computer-readable hardware storage devices having stored thereon computer-executable instructions that configure the computer system to override an original behavior of a function at runtime without changing source code of the function, overriding the original behavior of the function at runtime comprising:
identifying an override behavior for overriding the original behavior of the function, the override behavior including at least one of (1) overriding a return value of the function with a predetermined return value, or (2) overriding the function with a second function;
encoding replacement code based on the override behavior;
identifying a size of the replacement code;
identifying a first memory address of the function where code of the function is stored;
copying a block of code having the size of the replacement code from the first memory address to a second memory address;
copying the replacement code to the first memory address; and
after the replacement code is executed, copying the block of code stored at the second memory address back to the first memory address, restoring the code of the function, wherein:
when the override behavior includes overriding the return value of the function with the predetermined return value, encoding the replacement code comprises:
identifying a particular register that stores a return value of the function; and
encoding the replacement code configured to move the predetermined return value into the particular register.