Skip to content

Commit

Permalink
Fixed issue with SetThreadName and C#/Xaml applications
Browse files Browse the repository at this point in the history
  • Loading branch information
Mauro Leggieri committed Aug 21, 2015
1 parent 8f25b1e commit 3b4110c
Show file tree
Hide file tree
Showing 17 changed files with 145 additions and 92 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*.log
*.obj
*.ilk
Bin/*.lib
Libs/*.idb
bin/
Libs/
obj/
extras/
Documentation/bin/*.exe
Expand Down
60 changes: 22 additions & 38 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Known issues:
============
* C# plugins may not work if RegisterClass is hooked because CoInitialize(Ex) calls RegisterClass on STA and, at this
point, COM initialization in not complete yet.
* Plugins may not work in IE8 unless executed with elevated privileges because of COM security model used by the app.
(Resolved in 2.7.2)
* C# plugins may not work if "RegisterClassA" or "RegisterClassW" Apis is hooked because CoInitialize(Ex) calls RegisterClass on STA and, at this point, COM initialization in not complete yet.


Version 2.7.5
=============
-Fixed compatibility issue with Windows 10 Preview
-Fixed compatibility issue with Windows 10 Preview.
-Removed call to SetThreadName because causing issues when Deviare is used while debugging a C#/Xaml application.


Version 2.7.4
=============
Expand Down Expand Up @@ -57,11 +57,9 @@ Version 2.6.8

Version 2.6.7
=============
-BREAKING CHANGE: INktSpyMgr::CreateProcess(WithLogon) will set continueEvent to NULL instead of 0 if 'suspended'
parameter is FALSE or an error occurs.
-BREAKING CHANGE: OnLoadLibraryCall/OnFreeLibraryCall/OnCustomMessage events sends the direct VARIANT value instead
of seding a ByRef/Variant that points to another variant. (Should not affect C# project because its 'object' handling).
-Fixed memory & handle leaks in some functions using the internal process handles manager.
-BREAKING CHANGE: INktSpyMgr::CreateProcess(WithLogon) will set continueEvent to NULL instead of 0 if 'suspended' parameter is FALSE or an error occurs.
-BREAKING CHANGE: OnLoadLibraryCall/OnFreeLibraryCall/OnCustomMessage events sends the direct VARIANT value instead of seding a ByRef/Variant that points to another variant. (Should not affect C# project because its 'object' handling).
-Fixed memory and handle leaks in some functions using the internal process handles manager.
-Fixed messages being sent between server/client before connection tasks were completed.
-Updated to latest SQLite version.
-Added configurable agent load timeout (default is 10 seconds).
Expand Down Expand Up @@ -94,8 +92,7 @@ Version 2.6.5
-Added a new interface INktPdbFunctionSymbol to retrieve function address from pdb's symbols.
-Changed INktSpyMgr::CreateHookForAddress method to mantain concistency with other hook creation methods.
-Now plugins can send a custom message to the server when processing a function call.
-Added optional GetFunctionCallbackName method to plugins in order to reroute OnFunctionCall callback to
different methods.
-Added optional GetFunctionCallbackName method to plugins in order to reroute OnFunctionCall callback to different methods.
-Fixed big packet message handling that caused overflows on certain situations.
-Fixed memory leak on COM objects not being fully released when internal counterpart object is released.
-INktParamsEnum now returns dummy params on invalid index.
Expand All @@ -117,15 +114,12 @@ Version 2.6.4

Version 2.6.3
=============
-Changed COM event firing implementation replacing ATL::IConnectionPointImpl to avoid rare deadlocks
from appearing in STA threads.
-Changed COM event firing implementation replacing ATL::IConnectionPointImpl to avoid rare deadlocks from appearing in STA threads.
-Fixed deadlock on connection being shutdown because of an error.
-Major change: stErrorNotEnoughMemory and stErrorNotFound redefined.
-DeviareCOM & DeviareCOM64 manifest files are now embedded into dlls.
-If LoadLibrary/FreeLibrary ared called while hooking is in progress, notifications will be sent
asynchronously to avoid deadlocks.
-Fixed an issue when a library is loaded/unloaded into the hooked process while a connection is being
established.
-If LoadLibrary/FreeLibrary ared called while hooking is in progress, notifications will be sent asynchronously to avoid deadlocks.
-Fixed an issue when a library is loaded/unloaded into the hooked process while a connection is being established.
-Fixed CreateProcess injection code to allow .NET processes to be hooked upon startup.

Version 2.6.2
Expand All @@ -140,12 +134,10 @@ Version 2.6.2
Version 2.6.1
=============
-Fixed minor issue in native custom plugins.
-Applied free thread marshalling to custom plugins to avoid invocation problems while inside
a SendMessage (RPC_E_CANTCALLOUT_ININPUTSYNCCALL).
-Applied free thread marshalling to custom plugins to avoid invocation problems while inside a SendMessage (RPC_E_CANTCALLOUT_ININPUTSYNCCALL).
-Fixed integer parsing in C sample.
-Added GetFileNameFromHandle to the INktTools interface. Remember INktTools may throw exceptions.
-Now, in custom handlers, the "64" suffix is added/removed from the dll filename if hooks are
propagated from x64 processes to x86 and viceversa.
-Now, in custom handlers, the "64" suffix is added/removed from the dll filename if hooks are propagated from x64 processes to x86 and viceversa.
-Also, if a relative path is specified in custom handler dll, it will use agent dll path as the base.

Version 2.6.0
Expand All @@ -163,10 +155,8 @@ Version 2.6.0
Version 2.5.2
=============
-Memory management module completely rewritten to improve speed and balance comsumption.
-Added FilterSpyMgrEvent method to the INktHookCallInfoPlugin in order to let the plugin filter calls
and prevent them from being sent to the Spy Manager object.
-Change: Hooks that are automatically installed when a dll or child process is loaded now they are
installed synchronously.
-Added FilterSpyMgrEvent method to the INktHookCallInfoPlugin in order to let the plugin filter calls and prevent them from being sent to the Spy Manager object.
-Change: Hooks that are automatically installed when a dll or child process is loaded now they are installed synchronously.
-Fixed PointerVal access in plugins.

Version 2.5.1
Expand All @@ -179,14 +169,11 @@ Version 2.5.0
=============
-Improved message dispatcher (beta). Event delivery should be faster mainly in async ones.
-New hook flags. Now you can specify if a hook/custom handler is called when the loader lock is active.
-Fixed a race condition caused by GetModuleFileName returning ERROR_INVALID_HANDLE if the module is
being unloaded.
-Fixed a race condition caused by GetModuleFileName returning ERROR_INVALID_HANDLE if the module is being unloaded.
-Fixed a bug on exported function enumerator causing a later access fault.
-IEnumVARIANT code rewritten.
-Code that links com objects and internal ones was rewritten to avoid some race conditions and circular
references.
-INktSpy.ProcessHandle and INktProcess.Handle both returns duplicated handles that must be closed in
order to mantain consistency between the two functions.
-Code that links com objects and internal ones was rewritten to avoid some race conditions and circular references.
-INktSpy.ProcessHandle and INktProcess.Handle both returns duplicated handles that must be closed in order to mantain consistency between the two functions.
-Fixed an issue with target process' modules enumeration while the process is still initializing.
-Fixed an issue when agent is loaded while target process is initializing.
-Fixed a deadlock when SpyMgr process is shutting down.
Expand All @@ -199,8 +186,7 @@ Version 2.1.2
=============
-Fixed a security descriptor issue in W2K.
-GetProcessHandle now accepts current ProcessId.
-Packets received by SpyMgr are delivered to a secondary thread pool to improve speed when multiple calls
are made from different threads in hooked applications.
-Packets received by SpyMgr are delivered to a secondary thread pool to improve speed when multiple calls are made from different threads in hooked applications.
-Fixed some bugs in database generator application.
-Fixed read/write of IntPtr/size_t parameters in some routines.

Expand All @@ -220,8 +206,7 @@ Version 2.1.0
-Added interfaces that gives more process information.
-Added full api namespace support. (still BETA)
-Added multi-database merger application.
-Batch hooking and unhooking can be done with INktHooksEnumerator. This should be faster than individual
hook/unhook.
-Batch hooking and unhooking can be done with INktHooksEnumerator. This should be faster than individual hook/unhook.
-Dynamic link libraries loaded as datafile now are listed in the modules enumerator.
-Minor fixes applied.

Expand All @@ -232,8 +217,7 @@ Version 2.0.7
-Added initial namespace support to database.
-Changed internal "insertion point" algorithm.
-Added initial multi-hook-at-once support.
-Added registry key entry to optionally display debug output.
[HKLM\\Software\\Nektra\\Deviare2 => DebugLevelMask (REG_DWORD)]
-Added registry key entry to optionally display debug output. [HKLM\\Software\\Nektra\\Deviare2 => DebugLevelMask (REG_DWORD)]

Version 2.0.6
=============
Expand Down
Binary file modified Database/DbBuilder/bin/DbGenerator.exe
Binary file not shown.
Binary file modified Database/DbBuilder/bin/DbGenerator64.exe
Binary file not shown.
68 changes: 63 additions & 5 deletions Database/HeaderBuilder/Minimal Header Sample/base.h
Original file line number Diff line number Diff line change
@@ -1,33 +1,91 @@
//------------------------------------------------------------------------------
//Basic definitions

typedef signed char SCHAR;
typedef char CHAR;
typedef unsigned char UCHAR;
typedef short int SHORT;
typedef short unsigned int USHORT;

typedef short SHORT;
typedef unsigned short USHORT;
typedef unsigned short WORD;

typedef int INT;
typedef int SDWORD;
typedef int LONG;
typedef unsigned int UINT;
typedef unsigned int DWORD;
typedef unsigned int ULONG;
typedef long long int SQWORD;
typedef long long unsigned int QWORD;

typedef long long int LONGLONG;
typedef long long int SQWORD;
typedef long long unsigned int ULONGLONG;
typedef long long unsigned int QWORD;

typedef float FLOAT;
typedef double DOUBLE;
typedef long double LONG_DOUBLE;

typedef char *LPSTR;
typedef const char *LPCSTR;
typedef wchar_t *LPWSTR;
typedef const wchar_t *LPCWSTR;

typedef void *LPVOID;
typedef unsigned char *LPBYTE;

typedef long BOOL;

#if defined(_M_IX86)

typedef LONG SSIZE_T;
typedef LONG ssize_t;
typedef LONG INT_PTR;
typedef LONG LONG_PTR;

typedef ULONG SIZE_T;
typedef ULONG size_t;
typedef ULONG UINT_PTR;
typedef ULONG ULONG_PTR;

#elif defined(_M_X64)

typedef LONGLONG SSIZE_T;
typedef LONGLONG ssize_t;
typedef LONGLONG INT_PTR;
typedef LONGLONG LONG_PTR;

typedef ULONGLONG SIZE_T;
typedef ULONGLONG size_t;
typedef ULONGLONG UINT_PTR;
typedef ULONGLONG ULONG_PTR;

#endif

int pepe(int a, int b);
//------------------------------------------------------------------------------
//Some Microsoft Windows definitions

#define __in
#define __in_opt
#define __out
#define __out_opt
#define __inout
#define __inout_opt

#define WINAPI __stdcall
#define CONST const

typedef UINT_PTR WPARAM;
typedef LONG_PTR LPARAM;
typedef LONG_PTR LRESULT;

typedef HANDLE HWND;
typedef HANDLE HMENU;
typedef HANDLE HINSTANCE;

typedef LPVOID HANDLE;
typedef HANDLE *PHANDLE;


//------------------------------------------------------------------------------
//A Sample API
int sample_api(int a, int b);
5 changes: 4 additions & 1 deletion Source/Common/DynamicAPIs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1600,8 +1600,11 @@ static HRESULT BuildOriginalNtCalls()
static LPVOID BuildOriginalNtCall(__in LPBYTE lpFileFuncAddr, __in PRTL_OSVERSIONINFOW lpOsVerInfoW,
__in LPBYTE lpData, __in IMAGE_SECTION_HEADER *lpFileImgSect, __in SIZE_T nSecCount)
{
SIZE_T k, nSrcOfs, nInstrLen, nCurrSize, nExtraSize, nDestSize, nMainCodeSize;
SIZE_T k, nSrcOfs, nInstrLen, nCurrSize, nExtraSize, nMainCodeSize;
#if defined _M_IX86
SIZE_T nDestSize;
DWORD dwRawAddr;
#endif //_M_IX86
LPBYTE lpSrc, lpDest, lpStub;

//stage 1: scan for a return
Expand Down
13 changes: 8 additions & 5 deletions Source/Common/Threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,21 +545,24 @@ BOOL CNktThread::MsgCheckForAbort(__in DWORD dwTimeout, __in DWORD dwEventCount,

VOID CNktThread::SetThreadName(__in DWORD dwThreadId, __in_z_opt LPCSTR szName)
{
//NOTE: Temporary commented because registers are not saved correctly when called inside a C#/XAML application
/*
THREADNAME_INFO sInfo;
if (szName == NULL)
szName = "";
::Sleep(10);
sInfo.dwType = 0x1000;
sInfo.szName = szName;
sInfo.szName = (szName != NULL) ? szName : "";
sInfo.dwThreadID = (DWORD)dwThreadId;
sInfo.dwFlags = 0;
#pragma warning(disable: 6312 6322)
__try
{
::RaiseException(MS_VC_EXCEPTION, 0, sizeof(sInfo)/sizeof(ULONG_PTR), (ULONG_PTR*)&sInfo);
::RaiseException(MS_VC_EXCEPTION, 0, sizeof(sInfo)/sizeof(DWORD), (ULONG_PTR*)&sInfo);
}
__except(EXCEPTION_EXECUTE_HANDLER)
__except (EXCEPTION_CONTINUE_EXECUTION)
{ }
#pragma warning(default: 6312 6322)
*/
return;
}

Expand Down
Binary file modified Source/Engine/DeviareCOM/BuildPrimaryInterop/DeviareCOM.tlb
Binary file not shown.
2 changes: 1 addition & 1 deletion Source/Engine/DeviareCOM/DeviareCOM64_i.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


/* File created by MIDL compiler version 7.00.0555 */
/* at Thu Jul 09 14:35:24 2015
/* at Fri Aug 21 10:18:52 2015
*/
/* Compiler settings for DeviareCOM.idl:
Os, W1, Zp8, env=Win64 (32b run), target_arch=AMD64 7.00.0555
Expand Down
2 changes: 1 addition & 1 deletion Source/Engine/DeviareCOM/DeviareCOM64_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


/* File created by MIDL compiler version 7.00.0555 */
/* at Thu Jul 09 14:35:24 2015
/* at Fri Aug 21 10:18:52 2015
*/
/* Compiler settings for DeviareCOM.idl:
Os, W1, Zp8, env=Win64 (32b run), target_arch=AMD64 7.00.0555
Expand Down
2 changes: 1 addition & 1 deletion Source/Engine/DeviareCOM/DeviareCOM64_p.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


/* File created by MIDL compiler version 7.00.0555 */
/* at Thu Jul 09 14:35:24 2015
/* at Fri Aug 21 10:18:52 2015
*/
/* Compiler settings for DeviareCOM.idl:
Os, W1, Zp8, env=Win64 (32b run), target_arch=AMD64 7.00.0555
Expand Down
2 changes: 1 addition & 1 deletion Source/Engine/DeviareCOM/DeviareCOM_i.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


/* File created by MIDL compiler version 7.00.0555 */
/* at Thu Jul 09 14:33:25 2015
/* at Fri Aug 21 10:16:51 2015
*/
/* Compiler settings for DeviareCOM.idl:
Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 7.00.0555
Expand Down
2 changes: 1 addition & 1 deletion Source/Engine/DeviareCOM/DeviareCOM_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


/* File created by MIDL compiler version 7.00.0555 */
/* at Thu Jul 09 14:33:25 2015
/* at Fri Aug 21 10:16:51 2015
*/
/* Compiler settings for DeviareCOM.idl:
Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 7.00.0555
Expand Down
2 changes: 1 addition & 1 deletion Source/Engine/DeviareCOM/DeviareCOM_p.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


/* File created by MIDL compiler version 7.00.0555 */
/* at Thu Jul 09 14:33:25 2015
/* at Fri Aug 21 10:16:51 2015
*/
/* Compiler settings for DeviareCOM.idl:
Oicf, W1, Zp8, env=Win32 (32b run), target_arch=X86 7.00.0555
Expand Down
Binary file modified Source/MiscUtils/File2Inc/bin/File2Inc.exe
Binary file not shown.
Loading

0 comments on commit 3b4110c

Please sign in to comment.