- IPC Uses PID to identify the process

- Exception code now shows in hex capitals
- Fixed version checking and bumped the version support
- Added process blacklist for already injected game detection
- Used std::all_of instead of std::string::find for digit checks
This commit is contained in:
Anonymous275
2022-07-25 17:09:42 +03:00
parent d7d1a550cb
commit 8f53052356
9 changed files with 74 additions and 49 deletions

View File

@@ -8,10 +8,8 @@
#include "Memory/BeamNG.h"
#include "Memory/Memory.h"
//atomic_queue::AtomicQueue2<std::string, 1000> AtomicQueue;
std::unique_ptr<atomic_queue<std::string, 1000>> Queue;
int BeamNG::lua_open_jit_D(lua_State* State) {
Memory::Print("Got lua State");
GELua::State = State;
@@ -21,16 +19,17 @@ int BeamNG::lua_open_jit_D(lua_State* State) {
void BeamNG::EntryPoint() {
Queue = std::make_unique<atomic_queue<std::string, 1000>>();
uint32_t PID = Memory::GetPID();
auto status = MH_Initialize();
if(status != MH_OK)Memory::Print(std::string("MH Error -> ") + MH_StatusToString(status));
Memory::Print("PID : " + std::to_string(Memory::GetPID()));
Memory::Print("PID : " + std::to_string(PID));
GELua::FindAddresses();
/*GameBaseAddr = Memory::GetModuleBase(GameModule);
DllBaseAddr = Memory::GetModuleBase(DllModule);*/
OpenJITDetour = std::make_unique<Hook<def::lua_open_jit>>(GELua::lua_open_jit, lua_open_jit_D);
OpenJITDetour->Enable();
IPCToLauncher = std::make_unique<IPC>("BeamMP_IN", "BeamMP_Sem3", "BeamMP_Sem4", 0x1900000);
IPCFromLauncher = std::make_unique<IPC>("BeamMP_OUT", "BeamMP_Sem1", "BeamMP_Sem2", 0x1900000);
IPCFromLauncher = std::make_unique<IPC>(PID, 0x1900000);
IPCToLauncher = std::make_unique<IPC>(PID+1, 0x1900000);
IPCListener();
}

View File

@@ -7,18 +7,22 @@
#include <windows.h>
#include "Memory/IPC.h"
IPC::IPC(const char* MemID, const char* SemID, const char* SemID2, size_t Size) noexcept : Size_(Size) {
SemHandle_ = OpenSemaphoreA(SYNCHRONIZE | SEMAPHORE_MODIFY_STATE, FALSE, SemID);
IPC::IPC(uint32_t ID, size_t Size) noexcept : Size_(Size) {
std::string Sem{"MP_S" + std::to_string(ID)},
SemConf{"MP_SC" + std::to_string(ID)},
Mem{"MP_IO" + std::to_string(ID)};
SemHandle_ = OpenSemaphoreA(SYNCHRONIZE | SEMAPHORE_MODIFY_STATE, FALSE, Sem.c_str());
if(SemHandle_ == nullptr) {
SemHandle_ = CreateSemaphoreA(nullptr, 0, 1, SemID);
SemHandle_ = CreateSemaphoreA(nullptr, 0, 1, Sem.c_str());
}
SemConfHandle_ = OpenSemaphoreA(SYNCHRONIZE | SEMAPHORE_MODIFY_STATE, FALSE, SemID2);
SemConfHandle_ = OpenSemaphoreA(SYNCHRONIZE | SEMAPHORE_MODIFY_STATE, FALSE, SemConf.c_str());
if(SemConfHandle_ == nullptr) {
SemConfHandle_ = CreateSemaphoreA(nullptr, 0, 1, SemID2);
SemConfHandle_ = CreateSemaphoreA(nullptr, 0, 1, SemConf.c_str());
}
MemoryHandle_ = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, MemID);
MemoryHandle_ = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, Mem.c_str());
if(MemoryHandle_ == nullptr) {
MemoryHandle_ = CreateFileMappingA(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, DWORD(Size), MemID);
MemoryHandle_ = CreateFileMappingA(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, DWORD(Size), Mem.c_str());
}
Data_ = (char*)MapViewOfFile(MemoryHandle_, FILE_MAP_ALL_ACCESS, 0, 0, Size);
}
@@ -77,4 +81,12 @@ IPC::~IPC() noexcept {
CloseHandle(MemoryHandle_);
}
bool IPC::mem_used(uint32_t MemID) noexcept {
std::string Mem{"MP_IO" + std::to_string(MemID)};
HANDLE MEM = OpenFileMappingA(FILE_MAP_ALL_ACCESS, FALSE, Mem.c_str());
bool used = MEM != nullptr;
UnmapViewOfFile(MEM);
return used;
}

View File

@@ -11,8 +11,7 @@
#include <tlhelp32.h>
#include <psapi.h>
uint32_t Memory::GetBeamNGPID() {
uint32_t Memory::GetBeamNGPID(const std::vector<uint32_t>& BL) {
SetLastError(0);
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(PROCESSENTRY32);
@@ -20,7 +19,11 @@ uint32_t Memory::GetBeamNGPID() {
if(Process32First(Snapshot, &pe32)) {
do{
if(std::string("BeamNG.drive.x64.exe") == pe32.szExeFile)break;
if(std::string("BeamNG.drive.x64.exe") == pe32.szExeFile &&
std::find(BL.begin(), BL.end(), pe32.th32ProcessID) == BL.end() &&
std::find(BL.begin(), BL.end(), pe32.th32ParentProcessID) == BL.end()) {
break;
}
}while(Process32Next(Snapshot, &pe32));
}