Binary Patching via Outgoing Trampolines for Runtime Code Injection
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Existing methods cannot effectively add new functionality to existing object files without rewriting code, as modifications to source code are not applicable in compiled outputs and the structure of object files does not allow for adding new code, especially for position-dependent code to maintain proper operation.
Innovation Solution
The method involves preparing a hook object with machine code snippets, called trampolines, to bridge the original object file's code to the new functionality, allowing the original code to branch to the hook object while maintaining existing functionality, by modifying the original object file with outgoing trampolines and compiling the hook trampolines, implementations, and infrastructure to form a patched binary.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Adaptability or versatility
If new functionality is added to an existing object file by splicing or appending code, then the functionality is enhanced, but position-dependent code (SP, PC) cannot continue operating properly
Solution Approach 1:
The patent segments the code modification process into two distinct parts: (1) patching the original object file with outgoing trampolines that redirect to new functionality, and (2) loading hook objects containing the new functionality into separate memory pages. This segmentation allows position-dependent code in the original file to remain unchanged while new functionality is added through external hook objects, resolving the contradiction between functionality enhancement and position-dependent code reliability.
Solution Approach 2:
The patent introduces outgoing trampolines as intermediary code snippets that act as bridges between the original object file and new hook objects. These trampolines are patched into the original file at specific locations and redirect execution flow to newly added functionality without modifying the original position-dependent code structures, thereby maintaining reliability while enabling functionality enhancement.
2Adaptability or versatility
If modifications are applied to source code, then functionality can be changed, but these modifications are not applicable in the output of a compiler
Solution Approach 1:
The patent replaces the traditional mechanical compilation process with a runtime code injection mechanism. Instead of modifying source code and recompiling (which doesn't work for binary outputs), the system patches machine code directly into the compiled binary and loads additional hook objects at runtime. This substitution enables functionality modification at the binary level, making changes applicable to compiler output without requiring source code access or recompilation.
3Reliability
If the structure of object files is kept intact, then existing code functionality is preserved, but there is no room for adding new code
Solution Approach 1:
The patent adds a new dimension to object file structure by introducing a separate loading mechanism for hook objects. Instead of trying to fit new code into the traditional single-page object file structure, the system loads additional hook objects into separate memory pages that are linked to the original object file through outgoing trampolines. This dimensional expansion allows new code to be added without disrupting the existing object file structure or its position-dependent code.
Data Source
AI summary
It is often desired to add or change the functionality of an existing executable, also known as binary.Simply splicing in new machine code into the binary will not work due to host system-specific and platform-specific limitations.The present invention will enable adding any new code to an existing program while overcoming the aforementioned consistency limitations and maintaining the original functionality.


