Claims
- 1. A method for transforming a binary code, comprising:
identifying a function body in the binary code; copying the function body from the binary code to a shared object; and modifying a call instruction in the binary code to refer to the shared object, the call instruction previously referring to the function body in the binary code.
- 2. A method for transforming a binary code as recited in claim 1, wherein the binary code occupies a memory of a computer system.
- 3. A method for transforming a binary code as recited in claim 1, wherein the function body comprises a sequence of instructions extending from an initial memory address to a final memory address, wherein the initial memory address and the final memory address reside in a memory of a computer system.
- 4. A method for transforming a binary code as recited in claim 3, wherein copying the function body from the binary code to the shared object comprises copying the function body comprising the sequence of instructions extending from the initial memory address to the final memory address such that the sequence of instructions extend from a new initial memory address to a new final memory address, the new initial memory address and the new final memory address being located outside a memory of the computer system occupied by the binary code.
- 5. A method for transforming a binary code as recited in claim 4, wherein the call instruction is configured to direct a program control to the new initial memory address corresponding to the function body copied from the binary code to the shared object, the call instruction being further configured to direct the program control from the shared object back to the binary code upon completion of an execution of the function body copied from the binary code.
- 6. A method for transforming a binary code as recited in claim 1, wherein the binary code comprises a plurality of binary instructions, the plurality of binary instructions being executable by computer system circuitry.
- 7. A method for editing a binary code, comprising:
transforming the binary code into a plurality of binary code segments; inserting a branch instruction into at least one of the plurality of binary code segments; creating a binary patch to correspond to the branch instruction; and appending the binary patch to the at least one of the plurality of binary code segments.
- 8. A method for editing a binary code as recited in claim 7, wherein transforming the binary code into the plurality of binary code segments comprises:
identifying one or more function bodies in the binary code; copying each of the one or more function bodies from the binary code to a shared object; and modifying one or more call instructions in the binary code to refer to the shared object, the one or more call instructions previously referring to the one or more function bodies in the binary code.
- 9. A method for editing a binary code as recited in claim 7, wherein the binary code occupies a memory of a computer system.
- 10. A method for editing a binary code as recited in claim 8, wherein each of the one or more function bodies comprise a separate sequence of instructions extending from a corresponding initial memory address to a corresponding final memory address, wherein the corresponding initial memory address and the corresponding final memory address reside in a memory of a computer system.
- 11. A method for editing a binary code as recited in claim 10, wherein copying each of the one or more function bodies from the binary code to the shared object comprises copying each of the one or more function bodies comprising the separate sequence of instructions extending from the corresponding initial memory address to the corresponding final memory address such that the separate sequence of instructions extend from a new corresponding initial memory address to a new corresponding final memory address, the new corresponding initial memory address and the new corresponding final memory address being located outside a memory of the computer system occupied by the binary code.
- 12. A method for editing a binary code as recited in claim 8, wherein each of the one or more call instructions are configured to direct a program control from the binary code to one of the one or more function bodies copied from the binary code to the shared object, each of the one or more call instructions being further configured to direct the program control from the shared object back to the binary code upon completion of an execution of the one of the one or more function bodies copied from the binary code.
- 13. A method for editing a binary code as recited in claim 7, wherein inserting the branch instruction into at least one of the plurality of binary code segments comprises:
identifying an instruction in the at least one of the plurality of binary code segments; and replacing the instruction in the at least one of the plurality of binary code segments with the branch instruction, the branch instruction directing a program control to the binary patch.
- 14. A method for editing a binary code as recited in claim 13, wherein replacing the instruction in the at least one of the plurality of binary code segments with the branch instruction is performed without recompiling an original source code, the original source code having been used to create the at least one of the plurality of binary code segments.
- 15. A method for editing a binary code as recited in claim 13, wherein replacing the instruction in the at least one of the plurality of binary code segments with the branch instruction is performed such that a machine state is preserved, the machine state comprising a plurality of register values and data existing immediately prior to an execution of the branch instruction.
- 16. A method for editing a binary code as recited in claim 13, wherein creating the binary patch to correspond to the branch instruction comprises:
defining a first instruction in the binary patch to be the instruction in the at least one of the plurality of binary code segments replaced with the branch instruction; and defining a last instruction in the binary patch to direct the program control to a subsequent instruction in the at least one of the plurality of binary code segments, the subsequent instruction immediately following the instruction in the at least one of the plurality of binary code segments replaced with the branch instruction.
- 17. A method for editing a binary code as recited in claim 7, wherein the binary code comprises a plurality of binary instructions, the plurality of binary instructions being executable by computer system circuitry.
- 18. A method for performing a combined transformation and branch slamming operation on a binary code, comprising:
identifying a function body in the binary code; copying the function body from the binary code to a shared object; modifying one or more call instructions in the binary code to refer to the shared object, the one or more call instructions previously referring to the function body in the binary code; identifying an instruction in the function body copied from the binary code to the shared object, the instruction to be replaced by a branch instruction; preparing a binary patch to correspond to the branch instruction; replacing the instruction in the function body copied from the binary code to the shared object with the branch instruction; and appending the binary patch to the shared object.
- 19. A method for performing a combined transformation and branch slamming operation on a binary code as recited in claim 18, wherein the function body comprises a sequence of instructions extending from an initial memory address to a final memory address, wherein the initial memory address and the final memory address reside in a memory of a computer system.
- 20. A method for performing a combined transformation and branch slamming operation on a binary code as recited in claim 19, wherein copying the function body from the binary code to the shared object comprises copying the function body comprising the sequence of instructions extending from the initial memory address to the final memory address such that the sequence of instructions extend from a new initial memory address to a new final memory address, the new initial memory address and the new final memory address being located outside a memory of the computer system occupied by the binary code.
- 21. A method for performing a combined transformation and branch slamming operation on a binary code as recited in claim 20, wherein the one or more call instructions are configured to direct a program control to the new initial memory address corresponding to the function body copied from the binary code.
- 22. A method for performing a combined transformation and branch slamming operation on a binary code as recited in claim 18, wherein the branch instruction directs a program control to the binary patch.
- 23. A method for performing a combined transformation and branch slamming operation on a binary code as recited in claim 18, wherein preparing the binary patch to correspond to the branch instruction comprises:
defining a first instruction in the binary patch to be the instruction in the function body copied from the binary code to the shared object to be replaced by the branch instruction; and defining a last instruction in the binary patch to direct a program control to a subsequent instruction in the function body copied from the binary code to the shared object, the subsequent instruction immediately following the instruction replaced with the branch instruction.
- 24. A method for performing a combined transformation and branch slamming operation on a binary code as recited in claim 18, wherein replacing the instruction in the function body copied from the binary code to the shared object with the branch instruction is performed without recompiling an original source code, the original source code having been used to create the function body copied from the binary code to the shared object.
- 25. A method for performing a combined transformation and branch slamming operation on a binary code as recited in claim 18, wherein replacing the instruction in the function body copied from the binary code to the shared object with the branch instruction is performed such that a machine state is preserved, the machine state comprising a plurality of register values and data existing immediately prior to an execution of the branch instruction.
- 26. A computer program embodied on a computer readable medium for editing a binary code, comprising:
program instructions for transforming the binary code into a plurality of binary code segments; program instructions for inserting a branch instruction into at least one of the plurality of binary code segments; program instructions for creating a binary patch to correspond to the branch instruction; and program instructions for appending the binary patch to the at least one of the plurality of binary code segments.
- 27. A computer program embodied on a computer readable medium for editing a binary code as recited in claim 26, wherein program instructions for transforming the binary code into the plurality of binary code segments comprises:
program instructions for identifying one or more function bodies in the binary code; program instructions for copying each of the one or more function bodies from the binary code to a shared object; and program instructions for modifying one or more call instructions in the binary code to refer to the shared object, the one or more call instructions previously referring to the one or more function bodies moved out of the binary code.
- 28. A computer program embodied on a computer readable medium for editing a binary code as recited in claim 26, wherein the binary code occupies a memory of a computer system.
- 29. A computer program embodied on a computer readable medium for editing a binary code as recited in claim 27, wherein each of the one or more function bodies comprise a separate sequence of instructions extending from a corresponding initial memory address to a corresponding final memory address, wherein the corresponding initial memory address and the corresponding final memory address reside in a memory of a computer system.
- 30. A computer program embodied on a computer readable medium for editing a binary code as recited in claim 29, wherein program instructions for copying each of the one or more function bodies from the binary code to the shared object comprise program instructions for copying each of the one or more function bodies comprising the separate sequence of instructions extending from the corresponding initial memory address to the corresponding final memory address such that the separate sequence of instructions extend from a new corresponding initial memory address to a new corresponding final memory address, the new corresponding initial memory address and the new corresponding final memory address being located outside a memory of the computer system occupied by the binary code.
- 31. A computer program embodied on a computer readable medium for editing a binary code as recited in claim 27, wherein each of the one or more call instructions are configured to direct a program control from the binary code to one of the one or more function bodies copied from the binary code to the shared object, each of the one or more call instructions being further configured to direct the program control from the shared object back to the binary code upon completion of an execution of the one of the one or more function bodies copied from the binary code.
- 32. A computer program embodied on a computer readable medium for editing a binary code as recited in claim 26, wherein program instructions for inserting the branch instruction into at least one of the plurality of binary code segments comprises:
program instructions for identifying an instruction in the at least one of the plurality of binary code segments; and program instructions for replacing the instruction in the at least one of the plurality of binary code segments with the branch instruction, the branch instruction directing a program control to the binary patch.
- 33. A computer program embodied on a computer readable medium for editing a binary code as recited in claim 32, wherein replacing the instruction in the at least one of the plurality of binary code segments with the branch instruction is performed without recompiling an original source code, the original source code having been used to create the at least one of the plurality of binary code segments.
- 34. A computer program embodied on a computer readable medium for editing a binary code as recited in claim 32, wherein replacing the instruction in the at least one of the plurality of binary code segments with the branch instruction is performed such that a machine state is preserved, the machine state comprising a plurality of register values and data existing immediately prior to an execution of the branch instruction.
- 35. A computer program embodied on a computer readable medium for editing a binary code as recited in claim 32, wherein program instructions for creating the binary patch to correspond to the branch instruction comprises:
program instructions for defining a first instruction in the binary patch to be the instruction in the at least one of the plurality of binary code segments replaced with the branch instruction; and program instructions for defining a last instruction in the binary patch to direct the program control to a subsequent instruction in the at least one of the plurality of binary code segments, the subsequent instruction immediately following the instruction in the at least one of the plurality of binary code segments replaced with the branch instruction.
- 36. A computer program embodied on a computer readable medium for editing a binary code as recited in claim 26, wherein the binary code comprises a plurality of binary instructions, the plurality of binary instructions being executable by computer system circuitry.
CROSS REFERENCE TO RELATED APPLICATIONS
[0001] This application is related to U.S. patent application Ser. No. ______ (Attorney Docket No. SUNMP135), filed Dec. 9, 2002, and entitled “Method for Branch Slamming as a Safe Mechanism for Binary Code Editing,” which is incorporated herein by reference.