Skip to content

Commit

Permalink
fix system dll enforcement
Browse files Browse the repository at this point in the history
  • Loading branch information
SayakaIsBaka committed Nov 14, 2024
1 parent 718c3f1 commit 48d46d4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions LR2ArenaEx/src/overlay/dx9hook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ int __cdecl hkShowCursor(int enabled) {

void overlay::dx9hook::HookDX9() {
char* d3dPointer = mem::ScanModIn(d3dPattern, d3dMask, d3dName, true);
if (!d3dPointer) {
std::cout << "[!] d3d9.dll not found, aborting..." << std::endl;
return;
}
std::cout << "[i] D3D pointer: " << (int*)d3dPointer << std::endl;

uintptr_t d3dDeviceAddr = mem::FindDMAAddy((uintptr_t)d3dPointer + 0x4, { 0x0 });
Expand Down
14 changes: 13 additions & 1 deletion LR2ArenaEx/src/utils/mem.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <vector>
#include <iostream>
#include <cstring>
#include <filesystem>

#include <framework.h>
#include <ntdll.h>
Expand Down Expand Up @@ -226,7 +227,16 @@ LDR_DATA_TABLE_ENTRY* GetLDREntry(std::string name, bool forceSystem)

if (_stricmp(cName, name.c_str()) == 0)
{
if (!forceSystem || (forceSystem && std::wstring(mod->FullDllName.Buffer).rfind(system_dir, 0) == 0)) {
if (forceSystem) {
auto dllPath = std::filesystem::path(mod->FullDllName.Buffer);
auto systemPath = std::filesystem::path(system_dir);
auto rel = std::filesystem::relative(dllPath, systemPath);
if (!rel.empty() && rel.native()[0] != '.') { // If subpath
ldr = mod;
break;
}
}
else {
ldr = mod;
break;
}
Expand All @@ -241,6 +251,8 @@ LDR_DATA_TABLE_ENTRY* GetLDREntry(std::string name, bool forceSystem)
char* mem::ScanModIn(char* pattern, char* mask, std::string modName, bool forceSystem)
{
LDR_DATA_TABLE_ENTRY* ldr = GetLDREntry(modName, forceSystem);
if (!ldr)
return nullptr;
std::cout << "[i] DLL base for " << modName << ": " << ldr->DllBase << std::endl;
std::cout << "[i] Size of image: " << ldr->SizeOfImage << std::endl;
char* match = mem::ScanInternal(pattern, mask, (char*)ldr->DllBase, ldr->SizeOfImage);
Expand Down

0 comments on commit 48d46d4

Please sign in to comment.