jmpews / Dobby

a lightweight, multi-platform, multi-architecture hook framework.
Apache License 2.0
3.98k stars 822 forks source link

(Question) Are multiple hooks at the same address allowed? #26

Closed chayleaf closed 6 years ago

chayleaf commented 6 years ago

something like

void log(const char *text);
void hooked();
typedef void(*hooked_t)(void);

hooked_t origin1;
void replacement1() {
   log("hook 1 works");
   origin1();
}

hooked_t origin2;
void replacement2() {
   log("hook 2 works");
   origin2();
}

ZzHookReplace(
    &hooked,
    &replacement2,
    &origin2
);

ZzHookReplace(
    &hooked,
    &replacement1,
    &origin1
);

hooked();

/* 
 * log now contains:
 * hook 1 works
 * hook 2 works
 */
jmpews commented 6 years ago

sorry, No. but you can call replacement2 in replacement1

chayleaf commented 6 years ago

Ok, thanks for the answer. I'm making a modification api for a C++ game, and I want multiple mods that hook the same function to be compatible. In this case I will write my own wrapper that will use updated addresses (I suppose you can do

void log(const char *text);
void hooked();
typedef void(*hooked_t)(void);

hooked_t origin1;
void replacement1() {
   log("hook 1 works");
   origin1();
}

hooked_t origin2;
void replacement2() {
   log("hook 2 works");
   origin2();
}

ZzHookReplace(
    &hooked,
    &replacement2,
    &origin2
);

ZzHookReplace(
    &replacement2,
    &replacement1,
    &origin1
);

hooked();

/* 
 * log now contains:
 * hook 1 works
 * hook 2 works
 */

)