When winword process open a file and want to execute “save as” operation ,I want to refuse “save as” operation if the file will be saved to another directory。 i want to use C++ by api hook,how can I do?
It depends, if you want to hook an external process, you need to get into this process's address space first e.g (dll injection). Then you need to know precisely which API function this process uses to perform such task as saving a file to be able to hook a correct one. After all of these steps, I suggest to use detours to hook API functions. for example:
typedef void savefunc_t(const char *fn); // api function prototype
savefunc_t *original_savefunc;
void savefunc_hook(const char *fn)
{
if(strstr(fn, "dir")) // check path and deny if otherwise execute original func
return;
original_savefunc(fn);
}
DetourFunction(DesiredFunctionPointer, savefunc_hook);