Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
148 changes: 75 additions & 73 deletions copying.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1199,85 +1199,87 @@ e) modify or distribute the source code of any Distributable Code so that any pa
This applies to MinHook, available from http://github.com/RaMMicHaeL/minhook

```
/*
* MinHook - The Minimalistic API Hooking Library for x64/x86
* Copyright (c) 2009 Tsuda Kageyu.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
MinHook - The Minimalistic API Hooking Library for x64/x86
Copyright (C) 2009-2017 Tsuda Kageyu.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER
OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

================================================================================
Portions of this software are Copyright (c) 2008-2009, Vyacheslav Patkov.
================================================================================
/*
* Hacker Disassembler Engine 32 C
* Copyright (c) 2008-2009, Vyacheslav Patkov.
* All rights reserved.
*
*/
Hacker Disassembler Engine 32 C
Copyright (c) 2008-2009, Vyacheslav Patkov.
All rights reserved.

/*
* Hacker Disassembler Engine 64 C
* Copyright (c) 2008-2009, Vyacheslav Patkov.
* All rights reserved.
*
*/
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

================================================================================
Portions of this software are Copyright (c) 2005-2007 Paul Hsieh.
================================================================================
/* A portable stdint.h
****************************************************************************
* BSD License:
****************************************************************************
*
* Copyright (c) 2005-2007 Paul Hsieh
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

-------------------------------------------------------------------------------
Hacker Disassembler Engine 64 C
Copyright (c) 2008-2009, Vyacheslav Patkov.
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:

1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
```

= The MIT License =
Expand Down
2 changes: 1 addition & 1 deletion include/minhook
10 changes: 4 additions & 6 deletions nvdaHelper/minHook/sconscript
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,13 @@ env=env.Clone(CPPPATH=minhookPath.Dir('include'))
if 'analyze' in env['nvdaHelperDebugFlags']:
env.Append(CCFLAGS='/analyze-')

HDESourceFile='HDE64/src/HDE64.c' if env['TARGET_ARCH']=='x86_64' else 'HDE32/HDE32.c'
HDESourceFile='HDE/HDE64.c' if env['TARGET_ARCH']=='x86_64' else 'HDE/HDE32.c'

sourceFiles=[
HDESourceFile,
'buffer.cpp',
'export.cpp',
'hook.cpp',
'thread.cpp',
'trampoline.cpp',
'buffer.c',
'hook.c',
'trampoline.c',
]

objFiles=[env.Object('_minHook_%s.obj'%x.replace('/','_'),minhookPath.File('src/%s'%x)) for x in sourceFiles]
Expand Down
24 changes: 11 additions & 13 deletions nvdaHelper/remote/apiHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ bool error_setNHFP=false;
//function pointer typedefs for all minHook functions for use with getProcAddress
typedef MH_STATUS(WINAPI *MH_Initialize_funcType)();
typedef MH_STATUS(WINAPI *MH_Uninitialize_funcType)();
typedef MH_STATUS(WINAPI *MH_CreateHook_funcType)(void*,void*,void**);
typedef MH_STATUS(WINAPI *MH_EnableHook_funcType)(void*);
typedef MH_STATUS(WINAPI *MH_DisableHook_funcType)(void*);
typedef MH_STATUS(WINAPI *MH_CreateHook_funcType)(LPVOID,LPVOID,LPVOID*);
typedef MH_STATUS(WINAPI *MH_EnableHook_funcType)(LPVOID);
typedef MH_STATUS(WINAPI *MH_DisableHook_funcType)(LPVOID);

#define defMHFP(funcName) funcName##_funcType funcName##_fp=NULL

Expand All @@ -58,7 +58,6 @@ defMHFP(MH_DisableHook);

bool apiHook_initialize() {
LOG_DEBUG("calling MH_Initialize");
int res;
wstring dllPath=dllDirectory;
dllPath+=L"\\minhook.dll";
if((minhookLibHandle=LoadLibrary(dllPath.c_str()))==NULL) {
Expand All @@ -77,8 +76,9 @@ defMHFP(MH_DisableHook);
minhookLibHandle=NULL;
return false;
}
if ((res=MH_Initialize_fp())!=MH_OK) {
LOG_ERROR("MH_CreateHook failed with " << res);
MH_STATUS res = MH_Initialize_fp();
if (res!=MH_OK) {
LOG_ERROR("MH_Initialize failed with " << res);
FreeLibrary(minhookLibHandle);
minhookLibHandle=NULL;
return false;
Expand All @@ -104,9 +104,9 @@ void* apiHook_hookFunction(const char* moduleName, const char* functionName, voi
}
LOG_DEBUG("requesting to hook function " << functionName << " at address 0X" << std::hex << realFunc << " in module " << moduleName << " at address 0X" << moduleHandle << " with new function at address 0X" << newHookProc);
void* origFunc;
int res;
if((res=MH_CreateHook_fp(realFunc,newHookProc,&origFunc))!=MH_OK) {
LOG_ERROR("MH_CreateHook failed with " << res);
MH_STATUS res = MH_CreateHook_fp(realFunc,newHookProc,&origFunc);
if(res!=MH_OK) {
LOG_ERROR("MH_CreateHook for function " << functionName << " in module " << moduleName << " failed with " << res);
FreeLibrary(moduleHandle);
return NULL;
}
Expand All @@ -117,25 +117,23 @@ void* apiHook_hookFunction(const char* moduleName, const char* functionName, voi
}

bool apiHook_enableHooks() {
int res;
if(!minhookLibHandle) {
LOG_ERROR(L"apiHooks not initialized");
return false;
}
res=MH_EnableHook_fp(MH_ALL_HOOKS);
MH_STATUS res=MH_EnableHook_fp(MH_ALL_HOOKS);
nhAssert(res==MH_OK);
return TRUE;
}

bool apiHook_terminate() {
int res;
//If the process is exiting then minHook will have already removed all hooks and unloaded
if(isProcessExiting) return true;
if(!minhookLibHandle) {
LOG_ERROR(L"apiHooks not initialized");
return false;
}
res=MH_DisableHook_fp(MH_ALL_HOOKS);
MH_STATUS res=MH_DisableHook_fp(MH_ALL_HOOKS);
nhAssert(res==MH_OK);
g_hookedFunctions.clear();
//Give enough time for all hook functions to complete.
Expand Down