It would be easier to replace the first few bytes of f1 with jump by the beginning of f2 . This way, you wonβt have to deal with any possible code porting issues.
Also, information about how many bytes a function takes ( FUN_LENGTH in your question) is usually not available at runtime. Using jump will also avoid this problem.
X86 requires the operation code of the relative transition command E9 (as per here ). This is a 32-bit relative jump, which means you need to calculate the relative offset between f2 and f1 . This code can do this:
int offset = (int)f2 - ((int)f1 + 5);
The offset is executed from the end of the JMP instruction, so if 5 is added to the offset calculation, add the address f1 .
It is a good idea to execute the result using an assembly-level debugger to make sure you puncture the correct bytes. Of course, all this does not meet the standards, so if it breaks, you can save both parts.
source share