Skip to content

Commit

Permalink
added loadlibraryhook
Browse files Browse the repository at this point in the history
  • Loading branch information
moccajoghurt committed Aug 23, 2018
1 parent 6897f06 commit a645dc6
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 0 deletions.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#include <windows.h>
#include <iostream>
#include "../../../libs/PolyHook/PolyHook.hpp"

using namespace std;

typedef HMODULE(__stdcall* tLoadLibraryA)(LPCTSTR lpFileName);
tLoadLibraryA oLoadLibraryA;

typedef HMODULE(__stdcall* tLoadLibraryW)(LPWSTR lpFileName);
tLoadLibraryW oLoadLibraryW;

HMODULE __stdcall hLoadLibraryA(LPCTSTR lpFileName) {
cout << "got called" << endl;
if (strcmp(lpFileName, "allowed.dll") == 0) {
return oLoadLibraryA(lpFileName);
} else {
cout << "invalid DLL detected" << endl;
SetLastError(ERROR_ACCESS_DENIED);
return NULL;
}
}

HMODULE __stdcall hLoadLibraryW(LPWSTR lpFileName) {
cout << "got called" << endl;
if (wcscmp(lpFileName, L"allowed.dll") == 0) {
return oLoadLibraryW(lpFileName);
} else {
cout << "invalid DLL detected" << endl;
SetLastError(ERROR_ACCESS_DENIED);
return NULL;
}
}


int main() {
shared_ptr<PLH::Detour> Detour_Ex(new PLH::Detour);
Detour_Ex->SetupHook((BYTE*)&LoadLibraryA,(BYTE*) &hLoadLibraryA);
Detour_Ex->Hook();
oLoadLibraryA = Detour_Ex->GetOriginal<tLoadLibraryA>();

Detour_Ex->SetupHook((BYTE*)&LoadLibraryW,(BYTE*) &hLoadLibraryW);
Detour_Ex->Hook();
oLoadLibraryW = Detour_Ex->GetOriginal<tLoadLibraryW>();

// LoadLibraryA("InjectedDLL.dll");
// LoadLibraryW(L"InjectedDLL.dll");
for (;;) {
// try to inject me
TlsGetValue(0);
Sleep(10);
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@ECHO OFF
cl.exe /EHsc LoadLibraryHook.cpp ../../../Core/MemWarsServicesCore.cpp ../../../Core/MemWarsCore.c /link /LTCG /LIBPATH:"C:\Users\marius\git\MemWars\libs\Capstone\msvc\x64\Release" user32.lib ntdll.lib Advapi32.lib Shlwapi.lib

0 comments on commit a645dc6

Please sign in to comment.