Install first hook and do cleanup

This commit is contained in:
momo5502 2022-05-27 19:08:39 +02:00
parent 60915bd335
commit 47d6d960d8
7 changed files with 40 additions and 18 deletions

View File

@ -13,7 +13,7 @@ namespace arxan
{
namespace
{
const auto pseudo_steam_id = 0x1337;
constexpr auto pseudo_steam_id = 0x1337;
const auto pseudo_steam_handle = reinterpret_cast<HANDLE>(reinterpret_cast<uint64_t>(INVALID_HANDLE_VALUE) -
pseudo_steam_id);
@ -28,16 +28,6 @@ namespace arxan
return reinterpret_cast<HANDLE>(static_cast<DWORD64>(pid));
}
void check_steam_install()
{
if (!*steam::SteamAPI_GetSteamInstallPath())
{
MessageBoxA(nullptr, "Steam must be installed for the game to run. Please install steam!", "Error",
MB_ICONERROR);
TerminateProcess(GetCurrentProcess(), 1);
}
}
HANDLE WINAPI open_process_stub(const DWORD access, const BOOL inherit, const DWORD pid)
{
if (pid == pseudo_steam_id)
@ -372,8 +362,6 @@ namespace arxan
public:
void post_load() override
{
check_steam_install();
hide_being_debugged();
scheduler::loop(hide_being_debugged, scheduler::pipeline::async);

View File

@ -11,7 +11,7 @@ namespace console
{
void create_game_console()
{
reinterpret_cast<void(*)()>(utils::nt::library{}.get_ptr() + 0x2333F80)();
reinterpret_cast<void(*)()>(0x142333F80_g)();
}
}
@ -20,11 +20,23 @@ namespace console
public:
void post_unpack() override
{
this->terminate_runner_ = false;
this->console_runner_ = utils::thread::create_named_thread("Console IO", [this]
{
create_game_console();
{
utils::hook::detour d;
d.create(0x142333B40_g, utils::hook::assemble([](utils::hook::assembler& a)
{
a.mov(r8, "BOIII Console");
a.mov(r9d, 0x80CA0000);
a.sub(eax, edx);
a.jmp(0x142333B4F_g);
}));
create_game_console();
}
MSG msg{};
while (!this->terminate_runner_)

View File

@ -1,6 +1,8 @@
#include <std_include.hpp>
#include "component_loader.hpp"
#include <utils/nt.hpp>
void component_loader::register_component(std::unique_ptr<component_interface>&& component_)
{
get_components().push_back(std::move(component_));
@ -88,3 +90,10 @@ std::vector<std::unique_ptr<component_interface>>& component_loader::get_compone
return *components;
}
size_t operator"" _g(const size_t val)
{
static auto base = size_t(utils::nt::library{}.get_ptr());
assert(base && "Failed to resolve base");
return base + (val - 0x140000000);
}

View File

@ -56,3 +56,5 @@ namespace \
{ \
static component_loader::installer<name> __component; \
}
size_t operator"" _g(const size_t val);

View File

@ -77,7 +77,7 @@ namespace
bool run()
{
srand(uint32_t(time(nullptr)) ^ (~GetTickCount()));
srand(uint32_t(time(nullptr)) ^ ~(GetTickCount() * GetCurrentProcessId()));
{
auto premature_shutdown = true;

View File

@ -76,6 +76,7 @@
#include <optional>
#include <unordered_set>
#include <variant>
#include <cassert>
#include <MinHook.h>
#include <asmjit/core/jitruntime.h>

View File

@ -2,6 +2,7 @@
#include "steam.hpp"
#include <utils/nt.hpp>
#include <utils/io.hpp>
namespace steam
{
@ -105,12 +106,21 @@ namespace steam
bool SteamAPI_RestartAppIfNecessary()
{
return false;
const std::string steam_path = SteamAPI_GetSteamInstallPath();
if (!steam_path.empty() && ::utils::io::file_exists(steam_path + "/steam.exe"))
{
return false;
}
MessageBoxA(nullptr, "Steam must be installed for the game to run. Please install steam!", "Error", MB_ICONERROR);
ShellExecuteA(nullptr, "open", "https://store.steampowered.com/about/", nullptr, nullptr, SW_SHOWNORMAL);
TerminateProcess(GetCurrentProcess(), 1);
return true;
}
bool SteamAPI_Init()
{
const std::filesystem::path steam_path = steam::SteamAPI_GetSteamInstallPath();
const std::filesystem::path steam_path = SteamAPI_GetSteamInstallPath();
if (steam_path.empty()) return true;
::utils::nt::library::load(steam_path / "tier0_s64.dll");