Better unpack hook

This commit is contained in:
momo5502 2022-05-30 20:37:58 +02:00
parent 4097ed37d5
commit d9b834bede
5 changed files with 35 additions and 13 deletions

View File

@ -1,5 +1,4 @@
#include <std_include.hpp>
#include "console.hpp"
#include "loader/component_loader.hpp"
#include <utils/thread.hpp>
@ -9,10 +8,32 @@ namespace console
{
namespace
{
volatile bool g_started = false;
void create_game_console()
{
reinterpret_cast<void(*)()>(0x142333F80_g)();
}
void print_message(const char* message)
{
if (g_started)
{
reinterpret_cast<void(*)(int, int, const char*, ...)>(0x1421499C0_g)(0, 0, "%s", message);
}
}
void print_stub(const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
char buffer[1024]{0};
const int res = vsnprintf_s(buffer, sizeof(buffer), _TRUNCATE, fmt, ap);
print_message(buffer);
va_end(ap);
}
}
class component final : public component_interface
@ -20,6 +41,8 @@ namespace console
public:
void post_unpack() override
{
utils::hook::jump(printf, print_stub);
this->terminate_runner_ = false;
this->console_runner_ = utils::thread::create_named_thread("Console IO", [this]
@ -33,8 +56,8 @@ namespace console
a.sub(eax, edx);
a.jmp(0x142333B4F_g);
}));
create_game_console();
g_started = true;
}
MSG msg{};

View File

@ -1,6 +0,0 @@
#pragma once
namespace console
{
void print(int type, const char* fmt, ...);
}

View File

@ -58,7 +58,7 @@ namespace
patch_steam_import("SteamAPI_Init");
patch_steam_import("SteamAPI_RestartAppIfNecessary");
utils::hook::set(game.get_iat_entry("kernel32.dll", "InitializeCriticalSection"), initialize_critical_section);
//utils::hook::set(game.get_iat_entry("kernel32.dll", "InitializeCriticalSection"), initialize_critical_section);
utils::hook::set(game.get_iat_entry("kernel32.dll", "ExitProcess"), exit_hook);
}

View File

@ -4,6 +4,8 @@
#include <utils/nt.hpp>
#include <utils/io.hpp>
#include "loader/component_loader.hpp"
namespace steam
{
uint64_t callbacks::call_id_ = 0;
@ -109,6 +111,7 @@ namespace steam
const std::string steam_path = SteamAPI_GetSteamInstallPath();
if (!steam_path.empty() && ::utils::io::file_exists(steam_path + "/steam.exe"))
{
component_loader::post_unpack();
return false;
}

View File

@ -45,6 +45,8 @@ namespace utils::string
class entry final
{
public:
entry() = default;
explicit entry(const size_t _size = MinBufferSize) : size(_size), buffer(nullptr)
{
if (this->size < MinBufferSize) this->size = MinBufferSize;
@ -70,12 +72,12 @@ namespace utils::string
this->allocate();
}
size_t size;
char* buffer;
size_t size{};
char* buffer{nullptr};
};
size_t current_buffer_;
entry string_pool_[Buffers];
size_t current_buffer_{};
entry string_pool_[Buffers]{};
};
const char* va(const char* fmt, ...);