A method is provided for safely editing a binary code to be executed on a
computer system. The method allows the binary code to be directly edited
without compromising its integrity. More specifically, a larger binary
code is transformed into a number of smaller binary code segments having
sizes within a reference range of a control transfer function such as a
branch instruction. A branch slamming operation can then used to displace
a binary instruction contained within a smaller binary code segment with
a branch instruction referring to a binary patch that is appended to the
smaller binary code segment. The binary instruction displaced by the
branch instruction is preserved in the binary patch. Upon completion of
the binary patch execution, the smaller binary code segment continues
executing with a binary instruction immediately following the branch
instruction. The method for safely editing the binary code is
particularly useful with large binary codes having sizes greater than the
reference range of the control transfer function.