<commit_before>// EasyHook (File: EasyHookDll\debug.cpp)
//
// Copyright (c) 2009 <NAME> & Copyright (c) 2015 <NAME>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// Please visit https://easyhook.github.io for more information
// about the project and latest updates.

#include "stdafx.h"

#include <dbgeng.h>

#ifdef __cplusplus
extern "C"{
#endif

typedef HRESULT __stdcall DebugCreate_PROC(
	        __in REFIID InterfaceId,
	        __out PVOID* Interface
	        );

typedef LONG NTAPI ZwQueryInformationProcess_PROC(
            IN HANDLE ProcessHandle,
            IN ULONG ProcessInformationClass,
            OUT PVOID ProcessInformation,
            IN ULONG ProcessInformationLength,
            OUT PULONG ReturnLength OPTIONAL
            );

typedef DWORD WINAPI ZwGetProcessId_PROC(
            IN HANDLE Process
            );

typedef LONG NTAPI ZwQueryInformationThread_PROC(
            IN HANDLE ThreadHandle,
            IN ULONG ThreadInformationClass,
            OUT PVOID ThreadInformation,
            IN ULONG ThreadInformationLength,
            OUT PULONG ReturnLength OPTIONAL
            );

typedef DWORD WINAPI ZwGetThreadId_PROC(
            IN HANDLE Thread
            );

#define ObjectNameInformation           1

typedef LONG ZwQueryObject_PROC(
            HANDLE InHandle,
            ULONG InInfoClass,
            PVOID OutInfo,
            ULONG InInfoSize,
            PULONG OutRequiredSize);

typedef struct _CLIENT_ID
{
    DWORD	    UniqueProcess;
    DWORD	    UniqueThread;
}CLIENT_ID, * PCLIENT_ID;

typedef struct _THREAD_BASIC_INFORMATION
{
    LONG ExitStatus;
    PNT_TIB TebBaseAddress;
    CLIENT_ID ClientId;
    DWORD AffinityMask;
    LONG Priority;
    LONG BasePriority;
}THREAD_BASIC_INFORMATION, *PTHREAD_BASIC_INFORMATION;

static HMODULE                          hDbgEng = NULL;
static IDebugClient*			        DebugClient = NULL;
static IDebugControl*			        DebugControl = NULL;
static DebugCreate_PROC*                CreateDebugEngine = NULL;
static ZwGetThreadId_PROC*              ZwGetThreadId = NULL;
static ZwGetProcessId_PROC*             ZwGetProcessId = NULL;
static ZwQueryInformationThread_PROC*   ZwQueryInformationThread = NULL;
static ZwQueryInformationProcess_PROC*  ZwQueryInformationProcess = NULL;
static ZwQueryObject_PROC*              ZwQueryObject = NULL;

EASYHOOK_NT_EXPORT DbgAttachDebugger()
{
/*
Description:

    Attaches a debugger to the current process (64-bit only). This is no 
	longer necessary for RIP-relocation and disassembling. Multiple
    calls will do nothing.

*/<commit_msg>Rename CLIENT_ID struct to DBG_CLIENT_ID (Fixes #225)<commit_after>// EasyHook (File: EasyHookDll\debug.cpp)
//
// Copyright (c) 2009 <NAME> & Copyright (c) 2015 <NAME>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// Please visit https://easyhook.github.io for more information
// about the project and latest updates.

#include "stdafx.h"

#include <dbgeng.h>

#ifdef __cplusplus
extern "C"{
#endif

typedef HRESULT __stdcall DebugCreate_PROC(
	        __in REFIID InterfaceId,
	        __out PVOID* Interface
	        );

typedef LONG NTAPI ZwQueryInformationProcess_PROC(
            IN HANDLE ProcessHandle,
            IN ULONG ProcessInformationClass,
            OUT PVOID ProcessInformation,
            IN ULONG ProcessInformationLength,
            OUT PULONG ReturnLength OPTIONAL
            );

typedef DWORD WINAPI ZwGetProcessId_PROC(
            IN HANDLE Process
            );

typedef LONG NTAPI ZwQueryInformationThread_PROC(
            IN HANDLE ThreadHandle,
            IN ULONG ThreadInformationClass,
            OUT PVOID ThreadInformation,
            IN ULONG ThreadInformationLength,
            OUT PULONG ReturnLength OPTIONAL
            );

typedef DWORD WINAPI ZwGetThreadId_PROC(
            IN HANDLE Thread
            );

#define ObjectNameInformation           1

typedef LONG ZwQueryObject_PROC(
            HANDLE InHandle,
            ULONG InInfoClass,
            PVOID OutInfo,
            ULONG InInfoSize,
            PULONG OutRequiredSize);

typedef struct _DBG_CLIENT_ID
{
    DWORD	    UniqueProcess;
    DWORD	    UniqueThread;
}DBG_CLIENT_ID, * PDBG_CLIENT_ID;

typedef struct _THREAD_BASIC_INFORMATION
{
    LONG ExitStatus;
    PNT_TIB TebBaseAddress;
	DBG_CLIENT_ID ClientId;
    DWORD AffinityMask;
    LONG Priority;
    LONG BasePriority;
}THREAD_BASIC_INFORMATION, *PTHREAD_BASIC_INFORMATION;

static HMODULE                          hDbgEng = NULL;
static IDebugClient*			        DebugClient = NULL;
static IDebugControl*			        DebugControl = NULL;
static DebugCreate_PROC*                CreateDebugEngine = NULL;
static ZwGetThreadId_PROC*              ZwGetThreadId = NULL;
static ZwGetProcessId_PROC*             ZwGetProcessId = NULL;
static ZwQueryInformationThread_PROC*   ZwQueryInformationThread = NULL;
static ZwQueryInformationProcess_PROC*  ZwQueryInformationProcess = NULL;
static ZwQueryObject_PROC*              ZwQueryObject = NULL;

EASYHOOK_NT_EXPORT DbgAttachDebugger()
{
/*
Description:

    Attaches a debugger to the current process (64-bit only). This is no 
	longer necessary for RIP-relocation and disassembling. Multiple
    calls will do nothing.

*/
{'fraction_non_alphanumeric': 0.05764754210598384, 'fraction_numerical': 0.003423250718882651, 'mean_word_length': 2.910064239828694, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4506237', 'n_tokens_mistral': 2065, 'n_tokens_neox': 1933, 'n_words': 732}