mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-04-04 06:46:06 +00:00
Reformat to clang-format
This commit is contained in:
@@ -7,9 +7,9 @@
|
||||
#undef UNICODE
|
||||
#include "Memory/Memory.h"
|
||||
#include "Memory/BeamNG.h"
|
||||
#include <psapi.h>
|
||||
#include <string>
|
||||
#include <tlhelp32.h>
|
||||
#include <psapi.h>
|
||||
|
||||
uint32_t Memory::GetBeamNGPID(const std::set<uint32_t>& BL) {
|
||||
SetLastError(0);
|
||||
@@ -17,21 +17,22 @@ uint32_t Memory::GetBeamNGPID(const std::set<uint32_t>& BL) {
|
||||
pe32.dwSize = sizeof(PROCESSENTRY32);
|
||||
HANDLE Snapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
|
||||
|
||||
if(Process32First(Snapshot, &pe32)) {
|
||||
do{
|
||||
if(std::string("BeamNG.drive.x64.exe") == pe32.szExeFile
|
||||
&& BL.find(pe32.th32ProcessID) == BL.end()
|
||||
&& BL.find(pe32.th32ParentProcessID) == BL.end()) {
|
||||
if (Process32First(Snapshot, &pe32)) {
|
||||
do {
|
||||
if (std::string("BeamNG.drive.x64.exe") == pe32.szExeFile
|
||||
&& BL.find(pe32.th32ProcessID) == BL.end()
|
||||
&& BL.find(pe32.th32ParentProcessID) == BL.end()) {
|
||||
break;
|
||||
}
|
||||
}while(Process32Next(Snapshot, &pe32));
|
||||
} while (Process32Next(Snapshot, &pe32));
|
||||
}
|
||||
|
||||
if(Snapshot != INVALID_HANDLE_VALUE) {
|
||||
if (Snapshot != INVALID_HANDLE_VALUE) {
|
||||
CloseHandle(Snapshot);
|
||||
}
|
||||
|
||||
if(GetLastError() != 0)return 0;
|
||||
if (GetLastError() != 0)
|
||||
return 0;
|
||||
return pe32.th32ProcessID;
|
||||
}
|
||||
|
||||
@@ -44,24 +45,23 @@ uint32_t Memory::GetPID() {
|
||||
}
|
||||
|
||||
uint64_t Memory::FindPattern(const char* module, const char* Pattern[]) {
|
||||
MODULEINFO mInfo{nullptr};
|
||||
MODULEINFO mInfo { nullptr };
|
||||
GetModuleInformation(GetCurrentProcess(), GetModuleHandleA(module), &mInfo, sizeof(MODULEINFO));
|
||||
auto base = uint64_t(mInfo.lpBaseOfDll);
|
||||
auto size = uint32_t(mInfo.SizeOfImage);
|
||||
auto len = strlen(Pattern[1]);
|
||||
for(auto i = 0; i < size - len; i++) {
|
||||
for (auto i = 0; i < size - len; i++) {
|
||||
bool found = true;
|
||||
for(auto j = 0; j < len && found; j++) {
|
||||
found &= Pattern[1][j] == '?' || Pattern[0][j] == *(char*)(base+i+j);
|
||||
for (auto j = 0; j < len && found; j++) {
|
||||
found &= Pattern[1][j] == '?' || Pattern[0][j] == *(char*)(base + i + j);
|
||||
}
|
||||
if(found) {
|
||||
return base+i;
|
||||
if (found) {
|
||||
return base + i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void* operator new(size_t size) {
|
||||
return GlobalAlloc(GPTR, size);
|
||||
}
|
||||
@@ -98,11 +98,11 @@ void Memory::Inject(uint32_t PID) {
|
||||
|
||||
auto relocationTable = (PIMAGE_BASE_RELOCATION)((DWORD_PTR)localImage + ntHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress);
|
||||
PDWORD_PTR patchedAddress;
|
||||
while (relocationTable->SizeOfBlock > 0){
|
||||
while (relocationTable->SizeOfBlock > 0) {
|
||||
DWORD relocationEntriesCount = (relocationTable->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) / sizeof(USHORT);
|
||||
auto relocationRVA = (PBASE_RELOCATION_ENTRY)(relocationTable + 1);
|
||||
for (uint32_t i = 0; i < relocationEntriesCount; i++){
|
||||
if (relocationRVA[i].Offset){
|
||||
for (uint32_t i = 0; i < relocationEntriesCount; i++) {
|
||||
if (relocationRVA[i].Offset) {
|
||||
patchedAddress = PDWORD_PTR(DWORD_PTR(localImage) + relocationTable->VirtualAddress + relocationRVA[i].Offset);
|
||||
*patchedAddress += deltaImageBase;
|
||||
}
|
||||
@@ -110,7 +110,7 @@ void Memory::Inject(uint32_t PID) {
|
||||
relocationTable = PIMAGE_BASE_RELOCATION(DWORD_PTR(relocationTable) + relocationTable->SizeOfBlock);
|
||||
}
|
||||
WriteProcessMemory(targetProcess, targetImage, localImage, ntHeader->OptionalHeader.SizeOfImage, nullptr);
|
||||
CreateRemoteThread(targetProcess,nullptr,0,(LPTHREAD_START_ROUTINE)((DWORD_PTR)EntryPoint + deltaImageBase),nullptr,0,nullptr);
|
||||
CreateRemoteThread(targetProcess, nullptr, 0, (LPTHREAD_START_ROUTINE)((DWORD_PTR)EntryPoint + deltaImageBase), nullptr, 0, nullptr);
|
||||
CloseHandle(targetProcess);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user