-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
3,009 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
#pragma once | ||
#include "stdafx.h" | ||
#include <Windows.h> | ||
#pragma comment(linker, "/EXPORT:GetFileVersionInfoA=_AheadLib_GetFileVersionInfoA,@1") | ||
#pragma comment(linker, "/EXPORT:GetFileVersionInfoByHandle=_AheadLib_GetFileVersionInfoByHandle,@2") | ||
#pragma comment(linker, "/EXPORT:GetFileVersionInfoExA=_AheadLib_GetFileVersionInfoExA,@3") | ||
#pragma comment(linker, "/EXPORT:GetFileVersionInfoExW=_AheadLib_GetFileVersionInfoExW,@4") | ||
#pragma comment(linker, "/EXPORT:GetFileVersionInfoSizeA=_AheadLib_GetFileVersionInfoSizeA,@5") | ||
#pragma comment(linker, "/EXPORT:GetFileVersionInfoSizeExA=_AheadLib_GetFileVersionInfoSizeExA,@6") | ||
#pragma comment(linker, "/EXPORT:GetFileVersionInfoSizeExW=_AheadLib_GetFileVersionInfoSizeExW,@7") | ||
#pragma comment(linker, "/EXPORT:GetFileVersionInfoSizeW=_AheadLib_GetFileVersionInfoSizeW,@8") | ||
#pragma comment(linker, "/EXPORT:GetFileVersionInfoW=_AheadLib_GetFileVersionInfoW,@9") | ||
#pragma comment(linker, "/EXPORT:VerFindFileA=_AheadLib_VerFindFileA,@10") | ||
#pragma comment(linker, "/EXPORT:VerFindFileW=_AheadLib_VerFindFileW,@11") | ||
#pragma comment(linker, "/EXPORT:VerInstallFileA=_AheadLib_VerInstallFileA,@12") | ||
#pragma comment(linker, "/EXPORT:VerInstallFileW=_AheadLib_VerInstallFileW,@13") | ||
#pragma comment(linker, "/EXPORT:VerLanguageNameA=_AheadLib_VerLanguageNameA,@14") | ||
#pragma comment(linker, "/EXPORT:VerLanguageNameW=_AheadLib_VerLanguageNameW,@15") | ||
#pragma comment(linker, "/EXPORT:VerQueryValueA=_AheadLib_VerQueryValueA,@16") | ||
#pragma comment(linker, "/EXPORT:VerQueryValueW=_AheadLib_VerQueryValueW,@17") | ||
|
||
#define EXTERNC extern "C" | ||
#define NAKED __declspec(naked) | ||
#define EXPORT __declspec(dllexport) | ||
|
||
#define ALCPP EXPORT NAKED | ||
#define ALSTD EXTERNC EXPORT NAKED void __stdcall | ||
#define ALCFAST EXTERNC EXPORT NAKED void __fastcall | ||
#define ALCDECL EXTERNC NAKED void __cdecl | ||
|
||
namespace AheadLib | ||
{ | ||
HMODULE m_hModule = NULL; | ||
DWORD m_dwReturn[17] = { 0 }; | ||
|
||
inline BOOL WINAPI Load() | ||
{ | ||
TCHAR tzPath[MAX_PATH]; | ||
TCHAR tzTemp[MAX_PATH * 2]; | ||
|
||
GetSystemDirectory(tzPath, MAX_PATH); | ||
lstrcat(tzPath, TEXT("\\version")); | ||
m_hModule = LoadLibrary(tzPath); | ||
if (m_hModule == NULL) | ||
{ | ||
wsprintf(tzTemp, TEXT("No Original Version.dll"), tzPath); | ||
MessageBox(NULL, tzTemp, TEXT("AheadLib"), MB_ICONSTOP); | ||
} | ||
|
||
return (m_hModule != NULL); | ||
} | ||
|
||
inline VOID WINAPI Free() | ||
{ | ||
if (m_hModule) | ||
{ | ||
FreeLibrary(m_hModule); | ||
} | ||
} | ||
|
||
FARPROC WINAPI GetAddress(PCSTR pszProcName) | ||
{ | ||
FARPROC fpAddress; | ||
CHAR szProcName[16]; | ||
TCHAR tzTemp[MAX_PATH]; | ||
|
||
if (m_hModule == NULL) | ||
{ | ||
if (Load() == FALSE) | ||
{ | ||
ExitProcess(-1); | ||
} | ||
} | ||
|
||
fpAddress = GetProcAddress(m_hModule, pszProcName); | ||
if (fpAddress == NULL) | ||
{ | ||
if (HIWORD(pszProcName) == 0) | ||
{ | ||
wsprintf(szProcName, "%d", pszProcName); | ||
pszProcName = szProcName; | ||
} | ||
|
||
wsprintf(tzTemp, TEXT("No Such Function %s"), pszProcName); | ||
MessageBox(NULL, tzTemp, TEXT("AheadLib"), MB_ICONSTOP); | ||
ExitProcess(-2); | ||
} | ||
|
||
return fpAddress; | ||
} | ||
} | ||
using namespace AheadLib; | ||
void Hijack(); | ||
|
||
BOOL WINAPI DllMain(HMODULE hModule, DWORD dwReason, PVOID pvReserved) | ||
{ | ||
if (dwReason == DLL_PROCESS_ATTACH) | ||
{ | ||
DisableThreadLibraryCalls(hModule); | ||
Hijack(); | ||
} | ||
else if (dwReason == DLL_PROCESS_DETACH) | ||
{ | ||
Free(); | ||
} | ||
|
||
return TRUE; | ||
} | ||
|
||
|
||
ALCDECL AheadLib_GetFileVersionInfoA(void) | ||
{ | ||
GetAddress("GetFileVersionInfoA"); | ||
__asm JMP EAX; | ||
} | ||
|
||
ALCDECL AheadLib_GetFileVersionInfoByHandle(void) | ||
{ | ||
GetAddress("GetFileVersionInfoByHandle"); | ||
__asm JMP EAX; | ||
} | ||
|
||
|
||
ALCDECL AheadLib_GetFileVersionInfoExA(void) | ||
{ | ||
GetAddress("GetFileVersionInfoExA"); | ||
__asm JMP EAX; | ||
} | ||
|
||
ALCDECL AheadLib_GetFileVersionInfoExW(void) | ||
{ | ||
GetAddress("GetFileVersionInfoExW"); | ||
__asm JMP EAX; | ||
} | ||
|
||
ALCDECL AheadLib_GetFileVersionInfoSizeA(void) | ||
{ | ||
GetAddress("GetFileVersionInfoSizeA"); | ||
__asm JMP EAX; | ||
} | ||
|
||
ALCDECL AheadLib_GetFileVersionInfoSizeExA(void) | ||
{ | ||
GetAddress("GetFileVersionInfoSizeExA"); | ||
__asm JMP EAX; | ||
} | ||
|
||
ALCDECL AheadLib_GetFileVersionInfoSizeExW(void) | ||
{ | ||
GetAddress("GetFileVersionInfoSizeExW"); | ||
__asm JMP EAX; | ||
} | ||
|
||
ALCDECL AheadLib_GetFileVersionInfoSizeW(void) | ||
{ | ||
GetAddress("GetFileVersionInfoSizeW"); | ||
__asm JMP EAX; | ||
} | ||
|
||
ALCDECL AheadLib_GetFileVersionInfoW(void) | ||
{ | ||
GetAddress("GetFileVersionInfoW"); | ||
__asm JMP EAX; | ||
} | ||
|
||
ALCDECL AheadLib_VerFindFileA(void) | ||
{ | ||
GetAddress("VerFindFileA"); | ||
__asm JMP EAX; | ||
} | ||
|
||
ALCDECL AheadLib_VerFindFileW(void) | ||
{ | ||
GetAddress("VerFindFileW"); | ||
__asm JMP EAX; | ||
} | ||
|
||
ALCDECL AheadLib_VerInstallFileA(void) | ||
{ | ||
GetAddress("VerInstallFileA"); | ||
__asm JMP EAX; | ||
} | ||
|
||
ALCDECL AheadLib_VerInstallFileW(void) | ||
{ | ||
GetAddress("VerInstallFileW"); | ||
__asm JMP EAX; | ||
} | ||
|
||
ALCDECL AheadLib_VerLanguageNameA(void) | ||
{ | ||
GetAddress("VerLanguageNameA"); | ||
__asm JMP EAX; | ||
} | ||
|
||
ALCDECL AheadLib_VerLanguageNameW(void) | ||
{ | ||
GetAddress("VerLanguageNameW"); | ||
__asm JMP EAX; | ||
} | ||
|
||
ALCDECL AheadLib_VerQueryValueA(void) | ||
{ | ||
GetAddress("VerQueryValueA"); | ||
__asm JMP EAX; | ||
} | ||
|
||
ALCDECL AheadLib_VerQueryValueW(void) | ||
{ | ||
GetAddress("VerQueryValueW"); | ||
__asm JMP EAX; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
#include "stdafx.h" | ||
#include "EventEmitter.h" | ||
|
||
// | ||
// Copyright (c) 2014 Sean Farrell | ||
// | ||
// 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. | ||
// | ||
|
||
#include "EventEmitter.h" | ||
|
||
#include <stdexcept> | ||
|
||
EventEmitter::EventEmitter() {} | ||
|
||
EventEmitter::~EventEmitter() {} | ||
|
||
unsigned int EventEmitter::add_listener(unsigned int event_id, std::function<void()> cb) | ||
{ | ||
if (!cb) | ||
{ | ||
throw std::invalid_argument("EventEmitter::add_listener: No callbak provided."); | ||
} | ||
|
||
std::lock_guard<std::mutex> lock(mutex); | ||
|
||
unsigned int listener_id = ++last_listener; | ||
listeners.insert(std::make_pair(event_id, std::make_shared<Listener<>>(listener_id, cb))); | ||
|
||
return listener_id; | ||
} | ||
|
||
unsigned int EventEmitter::on(unsigned int event_id, std::function<void()> cb) | ||
{ | ||
return add_listener(event_id, cb); | ||
} | ||
|
||
void EventEmitter::remove_listener(unsigned int listener_id) | ||
{ | ||
std::lock_guard<std::mutex> lock(mutex); | ||
|
||
auto i = std::find_if(listeners.begin(), listeners.end(), [&](std::pair<const unsigned int, std::shared_ptr<ListenerBase>> p) { | ||
return p.second->id == listener_id; | ||
}); | ||
if (i != listeners.end()) | ||
{ | ||
listeners.erase(i); | ||
} | ||
else | ||
{ | ||
throw std::invalid_argument("EventEmitter::remove_listener: Invalid listener id."); | ||
} | ||
} |
Oops, something went wrong.