All pastes #87403 Raw Edit

Cody Brocious

public text v1 · immutable
#87403 ·published 2006-07-13 22:48 UTC
rendered paste body
void hotfixer(void *caller,
              void *callee,
              void *new_func) {
  /*                                                                                                               
   * Get the true address of the callee                                                                            
   */

  callee -= 8; // XXX: Validate this!                                                                              
               // Should be equal to pop eax+call                                                                  

  /*                                                                                                               
   * Check various call instructions                                                                               
   */
  if(*((void **) ((char *) caller) - 4) == callee) {
    /*                                                                                                             
     * Patch new function into place                                                                               
     */
    *((void **) ((char *) caller) - 4) = new_func;
  }
}