* hookapi.cc (putmem): Remove query of previous memory protection since we get
that for free the first time we call VirtualProtect.
This commit is contained in:
parent
f5778dc7f4
commit
fd01d14ab1
@ -1,3 +1,8 @@
|
|||||||
|
2005-12-16 Christopher Faylor <cgf@timesys.com>
|
||||||
|
|
||||||
|
* hookapi.cc (putmem): Remove query of previous memory protection since
|
||||||
|
we get that for free the first time we call VirtualProtect.
|
||||||
|
|
||||||
2005-12-15 Corinna Vinschen <corinna@vinschen.de>
|
2005-12-15 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* mmap.cc (fhandler_dev_zero::fixup_mmap_after_fork): Use
|
* mmap.cc (fhandler_dev_zero::fixup_mmap_after_fork): Use
|
||||||
|
@ -53,25 +53,14 @@ rvadelta (PIMAGE_NT_HEADERS pnt, DWORD import_rva)
|
|||||||
void *
|
void *
|
||||||
putmem (PIMAGE_THUNK_DATA pi, const void *hookfn)
|
putmem (PIMAGE_THUNK_DATA pi, const void *hookfn)
|
||||||
{
|
{
|
||||||
|
DWORD ofl;
|
||||||
DWORD flOldProtect, flNewProtect, flDontCare;
|
if (!VirtualProtect (pi, sizeof (PVOID), PAGE_READWRITE, &ofl) )
|
||||||
MEMORY_BASIC_INFORMATION mbi;
|
|
||||||
|
|
||||||
/* Get the current protection attributes */
|
|
||||||
VirtualQuery (pi, &mbi, sizeof (mbi));
|
|
||||||
|
|
||||||
/* Remove ReadOnly and ExecuteRead attributes, add on ReadWrite flag */
|
|
||||||
flNewProtect = mbi.Protect;
|
|
||||||
flNewProtect &= ~(PAGE_READONLY | PAGE_EXECUTE_READ);
|
|
||||||
flNewProtect |= PAGE_READWRITE;
|
|
||||||
|
|
||||||
if (!VirtualProtect (pi, sizeof (PVOID), flNewProtect, &flOldProtect) )
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
void *origfn = (void *) pi->u1.Function;
|
void *origfn = (void *) pi->u1.Function;
|
||||||
pi->u1.Function = (DWORD) hookfn;
|
pi->u1.Function = (DWORD) hookfn;
|
||||||
|
|
||||||
VirtualProtect (pi, sizeof (PVOID), flOldProtect, &flDontCare);
|
VirtualProtect (pi, sizeof (PVOID), ofl, &ofl);
|
||||||
return origfn;
|
return origfn;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user