More fixes

This commit is contained in:
momo5502 2019-09-24 11:46:47 +02:00
parent 91aa9cc0b8
commit 84cba76ae3
37 changed files with 3327 additions and 3280 deletions

View File

@ -18,6 +18,7 @@ function libtommath.includes()
defines {
"LTM_DESC",
"__STDC_IEC_559__",
"MP_NO_DEV_URANDOM",
}
end

View File

@ -46,7 +46,7 @@ namespace demonware
return this->write_bytes(bytes, reinterpret_cast<const unsigned char*>(data));
}
bool bit_buffer::write_bytes(unsigned int bytes, const unsigned char* data)
bool bit_buffer::write_bytes(const unsigned int bytes, const unsigned char* data)
{
return this->write(bytes * 8, data);
}

View File

@ -254,7 +254,7 @@ namespace demonware
return result;
}
bool byte_buffer::read(int bytes, void* output)
bool byte_buffer::read(const int bytes, void* output)
{
if (bytes + this->current_byte_ > this->buffer_.size()) return false;
@ -276,9 +276,9 @@ namespace demonware
return this->write(data.size(), data.data());
}
void byte_buffer::set_use_data_types(bool _useDataTypes)
void byte_buffer::set_use_data_types(const bool use_data_types)
{
this->use_data_types_ = _useDataTypes;
this->use_data_types_ = use_data_types;
}
size_t byte_buffer::size() const

View File

@ -15,7 +15,10 @@ namespace demonware
{
public:
raw_reply() = default;
explicit raw_reply(std::string data) : buffer_(std::move(data)) {}
explicit raw_reply(std::string data) : buffer_(std::move(data))
{
}
virtual std::string get_data() override
{
@ -29,7 +32,9 @@ namespace demonware
class typed_reply : public raw_reply
{
public:
typed_reply(uint8_t _type) : type_(_type) {}
typed_reply(uint8_t _type) : type_(_type)
{
}
protected:
uint8_t get_type() const { return this->type_; }
@ -45,6 +50,7 @@ namespace demonware
{
this->buffer_.append(bbuffer->get_buffer());
}
encrypted_reply(const uint8_t type, byte_buffer* bbuffer) : typed_reply(type)
{
this->buffer_.append(bbuffer->get_buffer());
@ -60,6 +66,7 @@ namespace demonware
{
this->buffer_.append(bbuffer->get_buffer());
}
unencrypted_reply(uint8_t _type, byte_buffer* bbuffer) : typed_reply(_type)
{
this->buffer_.append(bbuffer->get_buffer());
@ -86,7 +93,8 @@ namespace demonware
return reply;
}
virtual std::shared_ptr<service_reply> create_reply(uint8_t type, uint32_t error = 0 /*Game::bdLobbyErrorCode::BD_NO_ERROR*/)
virtual std::shared_ptr<service_reply> create_reply(uint8_t type,
uint32_t error = 0 /*Game::bdLobbyErrorCode::BD_NO_ERROR*/)
{
auto reply = std::make_shared<service_reply>(this, type, error);
return reply;
@ -96,7 +104,9 @@ namespace demonware
class remote_reply final
{
public:
remote_reply(i_server* server, uint8_t _type) : type_(_type), server_(server) {}
remote_reply(i_server* server, uint8_t _type) : type_(_type), server_(server)
{
}
template <typename BufferType>
void send(BufferType* buffer, const bool encrypted)
@ -119,14 +129,23 @@ namespace demonware
{
public:
virtual ~i_serializable() = default;
virtual void serialize(byte_buffer* /*buffer*/) {}
virtual void deserialize(byte_buffer* /*buffer*/) {}
virtual void serialize(byte_buffer* /*buffer*/)
{
}
virtual void deserialize(byte_buffer* /*buffer*/)
{
}
};
class service_reply final
{
public:
service_reply(i_server* _server, uint8_t _type, uint32_t _error) : type_(_type), error_(_error), reply_(_server, 1) {}
service_reply(i_server* _server, uint8_t _type, uint32_t _error) : type_(_type), error_(_error),
reply_(_server, 1)
{
}
uint64_t send()
{

View File

@ -16,7 +16,7 @@ namespace demonware
return this->address_;
}
void stun_server::ip_discovery(SOCKET s, const sockaddr* to, int tolen) const
void stun_server::ip_discovery(SOCKET s, const sockaddr* to, const int tolen) const
{
const uint32_t ip = 0x0100007f;
@ -31,7 +31,7 @@ namespace demonware
dw::send_datagram_packet(s, buffer.get_buffer(), to, tolen);
}
void stun_server::nat_discovery(SOCKET s, const sockaddr* to, int tolen) const
void stun_server::nat_discovery(SOCKET s, const sockaddr* to, const int tolen) const
{
const uint32_t ip = 0x0100007f;
@ -48,7 +48,7 @@ namespace demonware
dw::send_datagram_packet(s, buffer.get_buffer(), to, tolen);
}
int stun_server::send(const SOCKET s, const char* buf, int len, const sockaddr* to, int tolen) const
int stun_server::send(const SOCKET s, const char* buf, const int len, const sockaddr* to, const int tolen) const
{
uint8_t type, version, padding;

View File

@ -85,7 +85,7 @@ namespace game
void Conbuf_AppendText(const char* message)
{
if(is_dedi())
if (is_dedi())
{
conbuf_append_text_dedicated(message);
}
@ -247,7 +247,8 @@ namespace game
}
else
{
return reinterpret_cast<void(*)(unsigned int, unsigned int, unsigned int)>(0x4EFAA0)(id, stringValue, paramcount);
return reinterpret_cast<void(*)(unsigned int, unsigned int, unsigned int)>(0x4EFAA0)(
id, stringValue, paramcount);
}
}
@ -297,7 +298,7 @@ namespace game
launcher::mode get_mode()
{
if(mode == launcher::mode::none)
if (mode == launcher::mode::none)
{
throw std::runtime_error("Launcher mode not valid. Something must be wrong.");
}
@ -330,7 +331,8 @@ namespace game
native::DB_LoadXAssets = native::DB_LoadXAssets_t(SELECT_VALUE(0x48A8E0, 0x4CD020, 0x44F770));
native::Dvar_SetFromStringByName = native::Dvar_SetFromStringByName_t(SELECT_VALUE(0x4DD090, 0x5BF740, 0x518DF0));
native::Dvar_SetFromStringByName = native::Dvar_SetFromStringByName_t(
SELECT_VALUE(0x4DD090, 0x5BF740, 0x518DF0));
native::G_RunFrame = native::G_RunFrame_t(SELECT_VALUE(0x52EAA0, 0x50CB70, 0x48AD60));
@ -358,11 +360,11 @@ namespace game
native::scr_VmPub = reinterpret_cast<native::scrVmPub_t*>(SELECT_VALUE(0x1BF2580, 0x20B4A80, 0x1F5B080));
native::scr_instanceFunctions = reinterpret_cast<native::scr_call_t*>( SELECT_VALUE(0x184CDB0, 0x1D4F258,
native::scr_instanceFunctions = reinterpret_cast<native::scr_call_t*>(SELECT_VALUE(0x184CDB0, 0x1D4F258,
0x1BF59C8));
native::scr_globalFunctions = reinterpret_cast<native::scr_call_t*>( SELECT_VALUE(0x186C68C, 0x1D6EB34,
native::scr_globalFunctions = reinterpret_cast<native::scr_call_t*>(SELECT_VALUE(0x186C68C, 0x1D6EB34,
0x1C152A4
));
));
native::g_script_error_level = reinterpret_cast<int*>(SELECT_VALUE(0x1BEFCFC, 0x20B21FC, 0x1F5B058));
native::g_script_error = reinterpret_cast<jmp_buf*>(SELECT_VALUE(0x1BF1D18, 0x20B4218, 0x1F5A818));

View File

@ -20,7 +20,7 @@ namespace game
typedef void (*DB_LoadXAssets_t)(XZoneInfo* zoneInfo, unsigned int zoneCount, int sync);
extern DB_LoadXAssets_t DB_LoadXAssets;
typedef void (*Dvar_SetFromStringByName_t)(const char *dvarName, const char *string);
typedef void (*Dvar_SetFromStringByName_t)(const char* dvarName, const char* string);
extern Dvar_SetFromStringByName_t Dvar_SetFromStringByName;
typedef int (*G_RunFrame_t)(int, int);

View File

@ -116,7 +116,7 @@ namespace game
{
if (this->entity_id_)
{
native::VariableValue value{};
native::VariableValue value;
value.type = native::SCRIPT_OBJECT;
value.u.entityId = this->entity_id_;
native::AddRefToValue(&value);

View File

@ -102,7 +102,7 @@ namespace game
void event_handler::remove(const event_listener_handle& handle)
{
for (auto task : this->event_listeners_)
for (const auto task : this->event_listeners_)
{
if (task->id == handle.id)
{
@ -111,7 +111,7 @@ namespace game
}
}
for (auto task : this->generic_event_listeners_)
for (const auto task : this->generic_event_listeners_)
{
if (task->id == handle.id)
{

View File

@ -1,3 +1,5 @@
#pragma once
namespace game
{
namespace scripting

View File

@ -100,7 +100,8 @@ namespace game
else if (value.get_type_info() == typeid(std::vector<chaiscript::Boxed_Value>))
{
float values[3];
const auto real_value = this->context_->get_chai()->boxed_cast<std::vector<chaiscript::Boxed_Value>>(value);
const auto real_value = this->context_->get_chai()->boxed_cast<std::vector<chaiscript::Boxed_Value>
>(value);
if (real_value.size() != 3)
{
throw std::runtime_error("Invalid vector length. Size must be exactly 3");

View File

@ -18,12 +18,14 @@ namespace game
return lhs = rhs;
}), "=");
chai->add(chaiscript::fun([this](const std::function<void()>& callback, const long long milliseconds) -> task_handle
chai->add(chaiscript::fun(
[this](const std::function<void()>& callback, const long long milliseconds) -> task_handle
{
return this->add(callback, milliseconds, true);
}), "setTimeout");
chai->add(chaiscript::fun([this](const std::function<void()>& callback, const long long milliseconds) -> task_handle
chai->add(chaiscript::fun(
[this](const std::function<void()>& callback, const long long milliseconds) -> task_handle
{
return this->add(callback, milliseconds, false);
}), "setInterval");
@ -79,14 +81,14 @@ namespace game
this->tasks_.add(task);
return { task.id };
return {task.id};
}
void scheduler::remove(const task_handle& handle)
{
for (auto task : this->tasks_)
{
if(task->id == handle.id)
if (task->id == handle.id)
{
this->tasks_.remove(task);
break;

View File

@ -43,6 +43,6 @@ int html_argument::get_number() const
bool html_argument::get_bool() const
{
if(!this->is_bool()) return false;
if (!this->is_bool()) return false;
return this->value_->boolVal != FALSE;
}

View File

@ -12,7 +12,7 @@ FARPROC loader::load(const utils::nt::module& module) const
const auto buffer = binary_loader::load(this->mode_);
if (buffer.empty()) return nullptr;
utils::nt::module source(HMODULE(buffer.data()));
const utils::nt::module source(HMODULE(buffer.data()));
if (!source) return nullptr;
this->load_sections(module, source);
@ -58,8 +58,8 @@ FARPROC loader::load(const utils::nt::module& module) const
.get_optional_header()->DataDirectory[
IMAGE_DIRECTORY_ENTRY_IMPORT];
std::memmove(module.get_nt_headers(), source.get_nt_headers(),
sizeof(IMAGE_NT_HEADERS) + (source.get_nt_headers()->FileHeader.NumberOfSections * (sizeof(
IMAGE_SECTION_HEADER))));
sizeof(IMAGE_NT_HEADERS) + source.get_nt_headers()->FileHeader.NumberOfSections * sizeof(
IMAGE_SECTION_HEADER));
return FARPROC(module.get_ptr() + source.get_relative_entry_point());
}

View File

@ -27,7 +27,7 @@ bool module_loader::post_start()
module_->post_start();
}
}
catch(premature_shutdown_trigger&)
catch (premature_shutdown_trigger&)
{
return false;
}
@ -75,7 +75,7 @@ void* module_loader::load_import(const std::string& module, const std::string& f
for (const auto& module_ : *modules_)
{
const auto module_function_ptr = module_->load_import(module, function);
if(module_function_ptr)
if (module_function_ptr)
{
function_ptr = module_function_ptr;
}

View File

@ -24,12 +24,12 @@ public:
}
};
template<typename T>
template <typename T>
static T* get()
{
for(const auto& module_ : *modules_)
for (const auto& module_ : *modules_)
{
if(typeid(*module_.get()) == typeid(T))
if (typeid(*module_.get()) == typeid(T))
{
return reinterpret_cast<T*>(module_.get());
}

View File

@ -105,7 +105,7 @@ int main()
auto mode = detect_mode_from_arguments();
if (mode == launcher::mode::none)
{
launcher launcher;
const launcher launcher;
mode = launcher.run();
if (mode == launcher::mode::none) return 0;
}

View File

@ -63,7 +63,7 @@ void scheduler::execute_error()
const char* message;
int level;
if(get_next_error(&message, &level) && message)
if (get_next_error(&message, &level) && message)
{
game::native::Com_Error(level, "%s", message);
}
@ -72,7 +72,7 @@ void scheduler::execute_error()
bool scheduler::get_next_error(const char** error_message, int* error_level)
{
std::lock_guard _(mutex_);
if(errors_.empty())
if (errors_.empty())
{
*error_message = nullptr;
return false;

View File

@ -19,7 +19,8 @@ public:
->quick();
utils::hook(SELECT_VALUE(0x4F9706, 0x5772A0, 0x4FAB88), &frame_stub, HOOK_CALL).install()->quick();
utils::hook(SELECT_VALUE(0x4FFA48, 0x5774AB, 0x4FEFD7), &frame_stub, HOOK_CALL).install()->quick(); // Only relevant one?
utils::hook(SELECT_VALUE(0x4FFA48, 0x5774AB, 0x4FEFD7), &frame_stub, HOOK_CALL).install()->quick();
// Only relevant one?
utils::hook(SELECT_VALUE(0x6109F3, 0x56B637, 0x4EDFF7), &vm_notify_stub, HOOK_CALL).install()->quick();
utils::hook(SELECT_VALUE(0x6128BE, 0x56D541, 0x4EFAF9), &vm_notify_stub, HOOK_CALL).install()->quick();
@ -149,7 +150,7 @@ private:
game::native::VM_Notify(notify_id, type, stack);
}
static int frame_stub(int a1, int a2)
static int frame_stub(const int a1, const int a2)
{
module_loader::get<scripting>()->run_frame();
return game::native::G_RunFrame(a1, a2);

View File

@ -8,7 +8,7 @@ class security final : public module
public:
void post_load() override
{
if(game::is_mp())
if (game::is_mp())
{
utils::hook(0x4AECD4, read_p2p_auth_ticket_stub, HOOK_JUMP).install()->quick();
}

View File

@ -133,7 +133,7 @@ private:
this->client_utils_.invoke<void>("SetAppIDForCurrentPipe", app_id, false);
utils::nt::module self;
const utils::nt::module self;
const auto path = self.get_path();
char our_directory[MAX_PATH] = {0};

View File

@ -14,3 +14,25 @@ char payload_data[BINARY_PAYLOAD_SIZE];
#pragma data_seg(".main")
char main_data[200] = {1};
extern "C" {
int s_read_arc4random(void*, size_t)
{
return -1;
}
int s_read_getrandom(void*, size_t)
{
return -1;
}
int s_read_urandom(void*, size_t)
{
return -1;
}
int s_read_ltm_rng(void*, size_t)
{
return -1;
}
}

View File

@ -2,7 +2,6 @@
#include "interface.hpp"
#include "utils/memory.hpp"
#include "utils/nt.hpp"
#include <minwinbase.h>
namespace steam
{

View File

@ -1,6 +1,5 @@
#include <std_include.hpp>
#include "steam/steam.hpp"
#include "module/scheduler.hpp"
namespace steam
{
@ -37,8 +36,7 @@ namespace steam
{
std::lock_guard _(mutex_);
result result{};
result result;
result.call = call;
result.data = data;
result.size = size;

View File

@ -9,7 +9,8 @@ namespace utils
class element final
{
public:
explicit element(std::recursive_mutex* mutex, std::shared_ptr<T> entry = {}, std::shared_ptr<element> next = {}) :
explicit element(std::recursive_mutex* mutex, std::shared_ptr<T> entry = {},
std::shared_ptr<element> next = {}) :
mutex_(mutex),
entry_(std::move(entry)),
next_(std::move(next))

View File

@ -123,8 +123,9 @@ namespace utils
ltc_mp = ltm_desc;
auto result = 0;
return ( ecc_verify_hash(reinterpret_cast<const uint8_t*>(signature.data()), signature.size(),
reinterpret_cast<const uint8_t*>(message.data()), message.size(), &result, key.get()) == CRYPT_OK && result != 0);
return (ecc_verify_hash(reinterpret_cast<const uint8_t*>(signature.data()), signature.size(),
reinterpret_cast<const uint8_t*>(message.data()), message.size(), &result,
key.get()) == CRYPT_OK && result != 0);
}
std::string rsa::encrypt(const std::string& data, const std::string& hash, const std::string& key)
@ -247,7 +248,7 @@ namespace utils
return compute(reinterpret_cast<const uint8_t*>(data.data()), data.size(), hex);
}
std::string sha1::compute(const uint8_t* data, size_t length, const bool hex)
std::string sha1::compute(const uint8_t* data, const size_t length, const bool hex)
{
uint8_t buffer[20] = {0};
@ -262,12 +263,12 @@ namespace utils
return string::dump_hex(hash, "");
}
std::string sha256::compute(const std::string& data, bool hex)
std::string sha256::compute(const std::string& data, const bool hex)
{
return compute(reinterpret_cast<const uint8_t*>(data.data()), data.size(), hex);
}
std::string sha256::compute(const uint8_t* data, size_t length, bool hex)
std::string sha256::compute(const uint8_t* data, const size_t length, const bool hex)
{
uint8_t buffer[32] = {0};
@ -282,12 +283,12 @@ namespace utils
return string::dump_hex(hash, "");
}
std::string sha512::compute(const std::string& data, bool hex)
std::string sha512::compute(const std::string& data, const bool hex)
{
return compute(reinterpret_cast<const uint8_t*>(data.data()), data.size(), hex);
}
std::string sha512::compute(const uint8_t* data, size_t length, bool hex)
std::string sha512::compute(const uint8_t* data, const size_t length, const bool hex)
{
uint8_t buffer[64] = {0};

View File

@ -1,5 +1,4 @@
#pragma once
#include "memory.hpp"
namespace utils
{
@ -24,7 +23,7 @@ namespace utils
void deserialize(const std::string& key);
std::string serialize(const int type = PK_PRIVATE) const;
std::string serialize(int type = PK_PRIVATE) const;
void free();

View File

@ -1,5 +1,4 @@
#pragma once
#include "memory.hpp"
namespace utils
{

View File

@ -113,7 +113,7 @@ namespace utils
}
}
bool hook::iat(nt::module module, const std::string& target_module, const std::string& process, void* stub)
bool hook::iat(const nt::module module, const std::string& target_module, const std::string& process, void* stub)
{
if (!module.is_valid()) return false;

View File

@ -150,7 +150,7 @@ namespace utils
{
if (!this->is_valid()) return nullptr;
module other_module(module_name);
const module other_module(module_name);
if (!other_module.is_valid()) return nullptr;
const auto target_function = other_module.get_proc<void*>(proc_name);
@ -199,7 +199,7 @@ namespace utils
void raise_hard_exception()
{
int data = false;
utils::nt::module ntdll("ntdll.dll");
const module ntdll("ntdll.dll");
ntdll.invoke_pascal<void>("RtlAdjustPrivilege", 19, true, false, &data);
ntdll.invoke_pascal<void>("NtRaiseHardError", 0xC000007B, 0, nullptr, nullptr, 6, &data);
}