Merge pull request #5 from Artikash/cleanup

Cleanup
This commit is contained in:
Akash Mozumdar 2018-07-20 15:15:03 -04:00 committed by GitHub
commit 9407c96be3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
58 changed files with 70 additions and 149 deletions

View File

@ -47,8 +47,8 @@ add_definitions(
include_directories( include_directories(
. .
vnr
vnr/texthook texthook
${CMAKE_BINARY_DIR}/gui ${CMAKE_BINARY_DIR}/gui
) )
@ -76,6 +76,13 @@ set(nexthooker_src
gui/window.h gui/window.h
gui/TextBuffer.cpp gui/TextBuffer.cpp
gui/TextBuffer.h gui/TextBuffer.h
gui/profile/Profile.h
gui/profile/Profile.cpp
gui/profile/pugiconfig.h
gui/profile/pugixml.cpp
gui/profile/pugixml.h
gui/profile/misc.h
gui/profile/misc.cpp
${resource_src} ${resource_src}
) )
@ -83,7 +90,8 @@ source_group("Resource Files" FILES ${resource_src})
add_executable(${PROJECT_NAME} ${nexthooker_src}) add_executable(${PROJECT_NAME} ${nexthooker_src})
add_subdirectory(vnr) add_subdirectory(texthook)
add_subdirectory(vnrhook)
# add_subdirectory(profile) # add_subdirectory(profile)
set_target_properties(${PROJECT_NAME} PROPERTIES set_target_properties(${PROJECT_NAME} PROPERTIES
@ -97,7 +105,7 @@ target_compile_definitions(${PROJECT_NAME}
) )
target_link_libraries(${PROJECT_NAME} target_link_libraries(${PROJECT_NAME}
profile #profile
vnrhost vnrhost
#ithsys #ithsys
#${WDK_HOME}/lib/wxp/i386/ntdll.lib #${WDK_HOME}/lib/wxp/i386/ntdll.lib

View File

@ -347,9 +347,10 @@ void ClickButton(HWND hWnd, HWND h)
} }
} }
void ThreadOutput(TextThread* thread, std::wstring output) std::wstring ThreadOutput(TextThread* thread, std::wstring output)
{ {
if (thread->Status() & CURRENT_SELECT) texts->AddText(output, false); if (thread->Status() & CURRENT_SELECT) texts->AddText(output, false);
return output;
} }
bool GetHookParam(DWORD pid, DWORD hook_addr, HookParam& hp) bool GetHookParam(DWORD pid, DWORD hook_addr, HookParam& hp)

View File

@ -6,20 +6,22 @@
# # TODO: Get rid of dependence on msvc's swprintf # # TODO: Get rid of dependence on msvc's swprintf
# DEFINES += _CRT_NON_CONFORMING_SWPRINTFS # DEFINES += _CRT_NON_CONFORMING_SWPRINTFS
project(host)
set(vnrhost_src set(vnrhost_src
hookman.h hookman.h
host.h host.h
pipe.h pipe.h
textthread.h textthread.h
winmutex.h
hookman.cc hookman.cc
host.cc host.cc
pipe.cc pipe.cc
textthread.cc textthread.cc
${PROJECT_SOURCE_DIR}/winmutex/winmutex.h
${PROJECT_SOURCE_DIR}/extensions/Extensions.cpp
${PROJECT_SOURCE_DIR}/extensions/Extensions.h
) )
include_directories(../)
add_library(vnrhost SHARED ${vnrhost_src}) add_library(vnrhost SHARED ${vnrhost_src})
set_target_properties(vnrhost PROPERTIES LINK_FLAGS /SUBSYSTEM:WINDOWS) set_target_properties(vnrhost PROPERTIES LINK_FLAGS /SUBSYSTEM:WINDOWS)

View File

@ -12,7 +12,7 @@
#include "vnrhook/include/const.h" #include "vnrhook/include/const.h"
#include "vnrhook/include/defs.h" #include "vnrhook/include/defs.h"
#include "vnrhook/include/types.h" #include "vnrhook/include/types.h"
#include "winmutex/winmutex.h" #include "winmutex.h"
#include <atlbase.h> #include <atlbase.h>
#define HM_LOCK CriticalSectionLocker hmLocker(hmCs) // Synchronized scope for accessing private data #define HM_LOCK CriticalSectionLocker hmLocker(hmCs) // Synchronized scope for accessing private data

View File

@ -7,7 +7,6 @@
#include "vnrhook/include/const.h" #include "vnrhook/include/const.h"
#include "vnrhook/include/defs.h" #include "vnrhook/include/defs.h"
#include "vnrhook/include/types.h" #include "vnrhook/include/types.h"
#include "extensions/Extensions.h"
HANDLE preventDuplicationMutex; HANDLE preventDuplicationMutex;
@ -58,7 +57,6 @@ DLLEXPORT bool StartHost()
} }
else else
{ {
LoadExtensions();
::running = true; ::running = true;
::man = new HookManager; ::man = new HookManager;
return true; return true;

View File

@ -8,8 +8,7 @@
#include "host.h" #include "host.h"
#include "textthread.h" #include "textthread.h"
#include "vnrhook/include/const.h" #include "vnrhook/include/const.h"
#include "extensions/Extensions.h" #include "winmutex.h"
#include "winmutex/winmutex.h"
extern HookManager* man; extern HookManager* man;
extern HWND dummyWindow; extern HWND dummyWindow;
@ -54,7 +53,7 @@ void TextThread::AddSentence()
sentence = std::wstring(converted, MultiByteToWideChar(932, 0, sentenceBuffer.data(), sentenceBuffer.size(), converted, sentenceBuffer.size())); sentence = std::wstring(converted, MultiByteToWideChar(932, 0, sentenceBuffer.data(), sentenceBuffer.size(), converted, sentenceBuffer.size()));
delete[] converted; delete[] converted;
} }
AddSentence(DispatchSentenceToExtensions(sentence, status)); AddSentence(sentence);
sentenceBuffer.clear(); sentenceBuffer.clear();
} }
@ -62,7 +61,7 @@ void TextThread::AddSentence(std::wstring sentence)
{ {
TT_LOCK; TT_LOCK;
sentence.append(L"\r\n"); sentence.append(L"\r\n");
if (output) output(this, sentence); if (output) sentence = output(this, sentence);
storage.append(sentence); storage.append(sentence);
} }

View File

@ -25,7 +25,7 @@ struct ThreadParameter
#define CURRENT_SELECT 0x1000 #define CURRENT_SELECT 0x1000
class TextThread; class TextThread;
typedef void(*ThreadOutputCallback)(TextThread*, std::wstring data); typedef std::wstring(*ThreadOutputCallback)(TextThread*, std::wstring data);
//extern DWORD split_time,repeat_count,global_filter,cyclic_remove; //extern DWORD split_time,repeat_count,global_filter,cyclic_remove;

35
texthook/winmutex.h Normal file
View File

@ -0,0 +1,35 @@
#pragma once
// winmutex.h
// 12/11/2011 jichi
#include <windows.h>
#ifdef _MSC_VER
# pragma warning(disable:4800) // C4800: forcing value to bool
#endif // _MSC_VER
// Artikash 7/20/2018: these are similar to std::lock guard but use Winapi objects
class MutexLocker
{
HANDLE m;
public:
explicit MutexLocker(HANDLE mutex) : m(mutex)
{
WaitForSingleObject(m, 0);
}
~MutexLocker() { if (m != INVALID_HANDLE_VALUE && m != nullptr) ReleaseMutex(m); }
};
class CriticalSectionLocker
{
CRITICAL_SECTION cs;
public:
explicit CriticalSectionLocker(CRITICAL_SECTION cs) : cs(cs)
{
EnterCriticalSection(&cs);
}
~CriticalSectionLocker() { LeaveCriticalSection(&cs); }
};
// EOF

View File

@ -1,28 +0,0 @@
# config.pri
# DEFINES += _SECURE_SCL=0 _SCL_SECURE_NO_WARNINGS
# DEFINES += _CRT_SECURE_NO_WARNINGS
cmake_minimum_required(VERSION 2.8)
set(CMAKE_CONFIGURATION_TYPES Debug Release)
project(vnr)
set(WDK_HOME "C:\\WinDDK\\7600.16385.1" CACHE FILEPATH "Windows Driver Kit path")
add_definitions(
/DUNICODE
/D_UNICODE
/D_SECURE_SCL=0
/D_SCL_SECURE_NO_WARNINGS
/D_CRT_SECURE_NO_WARNINGS
)
include_directories(
${PROJECT_SOURCE_DIR}
${PROJECT_SOURCE_DIR}/texthook
)
add_subdirectory(vnrhook)
add_subdirectory(texthook)
add_subdirectory(profile)

View File

@ -1,36 +0,0 @@
#include "Extensions.h"
#include <Windows.h>
#include <map>
#include <vector>
std::map<DWORD, ExtensionFunction> extensionFunctions;
void LoadExtensions()
{
wchar_t path[MAX_PATH];
wchar_t* end = path + GetModuleFileNameW(nullptr, path, MAX_PATH);
while (*(--end) != L'\\');
*(end + 1) = L'*';
*(end + 2) = L'\0';
WIN32_FIND_DATAW fileData;
HANDLE file = FindFirstFileW(path, &fileData);
do
{
if (!(fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
if (wcsstr(fileData.cFileName, L"_nexthooker_extension.dll"))
{
extensionFunctions[wcstoul(fileData.cFileName, nullptr, 10)] = (ExtensionFunction)GetProcAddress(LoadLibraryW(fileData.cFileName), "NewSentence");
}
}
} while (FindNextFileW(file, &fileData) != 0);
}
std::wstring DispatchSentenceToExtensions(std::wstring sentence, DWORD64 info)
{
for (auto extension : extensionFunctions)
{
sentence = extension.second(sentence, info);
}
return sentence;
}

View File

@ -1,6 +0,0 @@
#include <Windows.h>
#include <string>
typedef std::wstring (*ExtensionFunction)(std::wstring, DWORD64);
void LoadExtensions();
std::wstring DispatchSentenceToExtensions(std::wstring sentence, DWORD64 info);

View File

@ -1,23 +0,0 @@
set(profile_src
Profile.h
Profile.cpp
pugiconfig.h
pugixml.cpp
pugixml.h
misc.h
misc.cpp
)
add_library(profile STATIC ${profile_src})
target_compile_options(profile PRIVATE
$<$<CONFIG:Release>:>
$<$<CONFIG:Debug>:>
)
#target_link_libraries(profile comctl32.lib)
#target_compile_definitions(profile
# PRIVATE
# _CRT_NON_CONFORMING_SWPRINTFS
#)

View File

@ -1,33 +0,0 @@
#pragma once
// winmutex.h
// 12/11/2011 jichi
#include <windows.h>
#ifdef _MSC_VER
# pragma warning(disable:4800) // C4800: forcing value to bool
#endif // _MSC_VER
class MutexLocker
{
HANDLE m;
public:
explicit MutexLocker(HANDLE mutex) : m(mutex)
{
WaitForSingleObject(m, 0);
}
~MutexLocker() { if (m != INVALID_HANDLE_VALUE && m != nullptr) ReleaseMutex(m); }
};
class CriticalSectionLocker
{
CRITICAL_SECTION cs;
public:
explicit CriticalSectionLocker(CRITICAL_SECTION cs) : cs(cs)
{
EnterCriticalSection(&cs);
}
~CriticalSectionLocker() { LeaveCriticalSection(&cs); }
};
// EOF

View File

@ -17,6 +17,8 @@
# QMAKE_CXXFLAGS_EXCEPTIONS_ON += /EHa # QMAKE_CXXFLAGS_EXCEPTIONS_ON += /EHa
# } # }
project(engine)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR})
set(vnrhook_src set(vnrhook_src
@ -42,15 +44,17 @@ set(vnrhook_src
src/util/growl.h src/util/growl.h
src/util/util.cc src/util/util.cc
src/util/util.h src/util/util.h
${PROJECT_SOURCE_DIR}/ithsys/ithsys.cc src/util/ithsys/ithsys.cc
${PROJECT_SOURCE_DIR}/disasm/disasm.cc src/util/disasm/disasm.cc
${PROJECT_SOURCE_DIR}/memdbg/memdbg.h src/util/memdbg/memdbg.h
${PROJECT_SOURCE_DIR}/memdbg/memsearch.cc src/util/memdbg/memsearch.cc
${PROJECT_SOURCE_DIR}/memdbg/memsearch.h src/util/memdbg/memsearch.h
${PROJECT_SOURCE_DIR}/mono/monoobject.h src/util/mono/monoobject.h
${PROJECT_SOURCE_DIR}/mono/monotype.h src/util/mono/monotype.h
) )
include_directories(src/util)
add_library(vnrhook SHARED ${vnrhook_src}) add_library(vnrhook SHARED ${vnrhook_src})
enable_language(ASM_MASM) enable_language(ASM_MASM)