Network, bug fixes, more patters, GELua and a lot more

This commit is contained in:
Anonymous275
2022-01-31 23:39:42 +02:00
parent 6c11de2708
commit 6dfeba1e49
21 changed files with 1130 additions and 54 deletions

View File

@@ -5,26 +5,23 @@
#pragma once
#include "Memory/Detours.h"
#include "Definitions.h"
#include <cstdint>
#include "Memory/GELua.h"
#include "Memory/IPC.h"
#include <memory>
#include <string>
class BeamNG {
public:
static void EntryPoint();
static void SendIPC(const std::string& Data);
private:
static std::unique_ptr<Detours> TickCountDetour;
static std::unique_ptr<Detours> OpenJITDetour;
static std::unique_ptr<IPC> IPCFromLauncher;
static std::unique_ptr<IPC> IPCToLauncher;
static int lua_open_jit_D(lua_State* State);
static void RegisterGEFunctions();
static uint32_t GetTickCount_D();
static uint64_t GameBaseAddr;
static uint64_t DllBaseAddr;
static def::GetTickCount GetTickCount;
static def::lua_open_jit lua_open_jit;
static def::lua_push_fstring lua_push_fstring;
static def::lua_get_field lua_get_field;
static def::lua_p_call lua_p_call;
static const char* GameModule;
static const char* DllModule;
static lua_State* GEState;
};

View File

@@ -4,12 +4,20 @@
///
#pragma once
typedef struct lua_State lua_State;
#include <cstdint>
typedef struct lua_State lua_State;
typedef int (*lua_CFunction)(lua_State*);
extern int lua_gettop(lua_State *L);
namespace def {
typedef unsigned long (*GetTickCount)();
typedef int (*lua_open_jit)(lua_State* L);
typedef void (*lua_get_field)(lua_State* L, int idx, const char* k);
typedef const char* (*lua_push_fstring)(lua_State* L, const char* fmt, ...);
typedef int(*lua_p_call)(lua_State* L, int arg, int res, int err);
typedef int (*lua_p_call)(lua_State* L, int arg, int res, int err);
typedef void (*lua_pushcclosure)(lua_State* L, lua_CFunction fn, int n);
typedef void (*lua_settable)(lua_State* L, int idx);
typedef void (*lua_createtable)(lua_State* L, int narray, int nrec);
typedef void (*lua_setfield)(lua_State* L, int idx, const char* k);
typedef const char* (*lua_tolstring)(lua_State* L, int idx, size_t* len);
}

43
include/Memory/GELua.h Normal file
View File

@@ -0,0 +1,43 @@
///
/// Created by Anonymous275 on 1/30/22
/// Copyright (c) 2021-present Anonymous275 read the LICENSE file for more info.
///
#pragma once
#include "Definitions.h"
class GELua {
public:
static void FindAddresses();
static def::GetTickCount GetTickCount;
static def::lua_open_jit lua_open_jit;
static def::lua_push_fstring lua_push_fstring;
static def::lua_get_field lua_get_field;
static def::lua_p_call lua_p_call;
static def::lua_createtable lua_createtable;
static def::lua_pushcclosure lua_pushcclosure;
static def::lua_setfield lua_setfield;
static def::lua_settable lua_settable;
static def::lua_tolstring lua_tolstring;
static lua_State* State;
};
namespace GELuaTable {
inline void Begin(lua_State* L) {
GELua::lua_createtable(L, 0, 0);
}
inline void End(lua_State* L, const char* name) {
GELua::lua_setfield(L, -10002, name);
}
inline void BeginEntry(lua_State* L, const char* name) {
GELua::lua_push_fstring(L, "%s", name);
}
inline void EndEntry(lua_State* L) {
GELua::lua_settable(L, -3);
}
inline void InsertFunction(lua_State* L, const char* name, lua_CFunction func) {
BeginEntry(L, name);
GELua::lua_pushcclosure(L, func, 0);
EndEntry(L);
}
}

View File

@@ -14,15 +14,20 @@ public:
[[nodiscard]] char* c_str() const noexcept;
void send(const std::string& msg) noexcept;
[[nodiscard]] void* raw() const noexcept;
[[nodiscard]] bool receive_timed_out() const noexcept;
[[nodiscard]] bool send_timed_out() const noexcept;
const std::string& msg() noexcept;
void confirm_receive() noexcept;
void receive();
void try_receive() noexcept;
void receive() noexcept;
~IPC() noexcept;
private:
void* SemConfHandle_;
void* MemoryHandle_;
void* SemHandle_;
std::string Msg_;
bool SendTimeout;
bool RcvTimeout;
size_t Size_;
char* Data_;
};

View File

@@ -8,7 +8,7 @@
class Memory{
public:
static uint64_t FindPattern(const char* module, const char* Pattern, const char* Mask);
static uint64_t FindPattern(const char* module, const char* Pattern[]);
static uint64_t GetModuleBase(const char* Name);
static void Print(const std::string& msg);
static void Inject(uint32_t PID);

View File

@@ -25,4 +25,24 @@ namespace Patterns {
"\x48\x89\x5c\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xec\x00\x48\x8b\x59\x00\x41\x8b\xf0\x4c\x63\xda",
"xxxx?xxxx?xxxx?xxx?xxxxxx"
};
const char* lua_setfield[2] {
"\x48\x89\x5c\x24\x00\x57\x48\x83\xec\x00\x4d\x8b\xd0\x48\x8b\xd9\xe8\x00\x00\x00\x00\x48\x8b\xf8\x49\xc7\xc0\x00\x00\x00\x00\x90\x49\xff\xc0\x43\x80\x3c\x02\x00\x75\x00\x49\x8b\xd2\x48\x8b\xcb\xe8\x00\x00\x00\x00\x48\xb9\x00\x00\x00\x00\x00\x00\x00\x00\x4c\x8d\x44\x24\x00\x48\x0b\xc1\x48\x8b\xd7\x48\x8b\xcb\x48\x89\x44\x24\x00\xe8\x00\x00\x00\x00\x48\x8b\x53",
"xxxx?xxxx?xxxxxxx????xxxxxx????xxxxxxxx?x?xxxxxxx????xx????????xxxx?xxxxxxxxxxxxx?x????xxx"
};
const char* lua_createtable[2] {
"\x48\x89\x5c\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xec\x00\x4c\x8b\x49\x00\x41\x8b\xf8",
"xxxx?xxxx?xxxx?xxx?xxx"
};
const char* lua_settable[2] {
"\x40\x53\x48\x83\xec\x00\x48\x8b\xd9\xe8\x00\x00\x00\x00\x4c\x8b\x43\x00\x48\x8b\xd0\x49\x83\xe8\x00\x48\x8b\xcb\xe8\x00\x00\x00\x00\x48\x8b\x53",
"xxxxx?xxxx????xxx?xxxxxx?xxxx????xxx"
};
const char* lua_pushcclosure[2] {
"\x48\x89\x5c\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xec\x00\x48\x8b\xd9\x49\x63\xf8\x48\x8b\x49\x00\x48\x8b\xf2",
"xxxx?xxxx?xxxx?xxxxxxxxx?xxx"
};
const char* lua_tolstring[2] {
"\x48\x89\x5c\x24\x00\x48\x89\x74\x24\x00\x57\x48\x83\xec\x00\x49\x8b\xf8\x8b\xda\x48\x8b\xf1\xe8",
"xxxx?xxxx?xxxx?xxxxxxxxx"
};
}