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 { defines {
"LTM_DESC", "LTM_DESC",
"__STDC_IEC_559__", "__STDC_IEC_559__",
"MP_NO_DEV_URANDOM",
} }
end end

View File

@ -46,7 +46,7 @@ namespace demonware
return this->write_bytes(bytes, reinterpret_cast<const unsigned char*>(data)); 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); return this->write(bytes * 8, data);
} }

View File

@ -254,7 +254,7 @@ namespace demonware
return result; 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; if (bytes + this->current_byte_ > this->buffer_.size()) return false;
@ -276,9 +276,9 @@ namespace demonware
return this->write(data.size(), data.data()); 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 size_t byte_buffer::size() const

View File

@ -15,7 +15,10 @@ namespace demonware
{ {
public: public:
raw_reply() = default; 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 virtual std::string get_data() override
{ {
@ -29,7 +32,9 @@ namespace demonware
class typed_reply : public raw_reply class typed_reply : public raw_reply
{ {
public: public:
typed_reply(uint8_t _type) : type_(_type) {} typed_reply(uint8_t _type) : type_(_type)
{
}
protected: protected:
uint8_t get_type() const { return this->type_; } uint8_t get_type() const { return this->type_; }
@ -45,6 +50,7 @@ namespace demonware
{ {
this->buffer_.append(bbuffer->get_buffer()); this->buffer_.append(bbuffer->get_buffer());
} }
encrypted_reply(const uint8_t type, byte_buffer* bbuffer) : typed_reply(type) encrypted_reply(const uint8_t type, byte_buffer* bbuffer) : typed_reply(type)
{ {
this->buffer_.append(bbuffer->get_buffer()); this->buffer_.append(bbuffer->get_buffer());
@ -60,6 +66,7 @@ namespace demonware
{ {
this->buffer_.append(bbuffer->get_buffer()); this->buffer_.append(bbuffer->get_buffer());
} }
unencrypted_reply(uint8_t _type, byte_buffer* bbuffer) : typed_reply(_type) unencrypted_reply(uint8_t _type, byte_buffer* bbuffer) : typed_reply(_type)
{ {
this->buffer_.append(bbuffer->get_buffer()); this->buffer_.append(bbuffer->get_buffer());
@ -86,7 +93,8 @@ namespace demonware
return reply; 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); auto reply = std::make_shared<service_reply>(this, type, error);
return reply; return reply;
@ -96,7 +104,9 @@ namespace demonware
class remote_reply final class remote_reply final
{ {
public: 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> template <typename BufferType>
void send(BufferType* buffer, const bool encrypted) void send(BufferType* buffer, const bool encrypted)
@ -119,14 +129,23 @@ namespace demonware
{ {
public: public:
virtual ~i_serializable() = default; 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 class service_reply final
{ {
public: 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() uint64_t send()
{ {

View File

@ -16,7 +16,7 @@ namespace demonware
return this->address_; 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; const uint32_t ip = 0x0100007f;
@ -31,7 +31,7 @@ namespace demonware
dw::send_datagram_packet(s, buffer.get_buffer(), to, tolen); 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; const uint32_t ip = 0x0100007f;
@ -48,7 +48,7 @@ namespace demonware
dw::send_datagram_packet(s, buffer.get_buffer(), to, tolen); 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; uint8_t type, version, padding;

View File

@ -247,7 +247,8 @@ namespace game
} }
else 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);
} }
} }
@ -330,7 +331,8 @@ namespace game
native::DB_LoadXAssets = native::DB_LoadXAssets_t(SELECT_VALUE(0x48A8E0, 0x4CD020, 0x44F770)); 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)); native::G_RunFrame = native::G_RunFrame_t(SELECT_VALUE(0x52EAA0, 0x50CB70, 0x48AD60));

View File

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

View File

@ -102,7 +102,7 @@ namespace game
void event_handler::remove(const event_listener_handle& handle) 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) 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) if (task->id == handle.id)
{ {

View File

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

View File

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

View File

@ -18,12 +18,14 @@ namespace game
return lhs = rhs; 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); return this->add(callback, milliseconds, true);
}), "setTimeout"); }), "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); return this->add(callback, milliseconds, false);
}), "setInterval"); }), "setInterval");

View File

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

View File

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

View File

@ -19,7 +19,8 @@ public:
->quick(); ->quick();
utils::hook(SELECT_VALUE(0x4F9706, 0x5772A0, 0x4FAB88), &frame_stub, HOOK_CALL).install()->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(0x6109F3, 0x56B637, 0x4EDFF7), &vm_notify_stub, HOOK_CALL).install()->quick();
utils::hook(SELECT_VALUE(0x6128BE, 0x56D541, 0x4EFAF9), &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); 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(); module_loader::get<scripting>()->run_frame();
return game::native::G_RunFrame(a1, a2); return game::native::G_RunFrame(a1, a2);

View File

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

View File

@ -14,3 +14,25 @@ char payload_data[BINARY_PAYLOAD_SIZE];
#pragma data_seg(".main") #pragma data_seg(".main")
char main_data[200] = {1}; 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 "interface.hpp"
#include "utils/memory.hpp" #include "utils/memory.hpp"
#include "utils/nt.hpp" #include "utils/nt.hpp"
#include <minwinbase.h>
namespace steam namespace steam
{ {

View File

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

View File

@ -9,7 +9,8 @@ namespace utils
class element final class element final
{ {
public: 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), mutex_(mutex),
entry_(std::move(entry)), entry_(std::move(entry)),
next_(std::move(next)) next_(std::move(next))

View File

@ -124,7 +124,8 @@ namespace utils
auto result = 0; auto result = 0;
return (ecc_verify_hash(reinterpret_cast<const uint8_t*>(signature.data()), signature.size(), 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); 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) 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); 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}; uint8_t buffer[20] = {0};
@ -262,12 +263,12 @@ namespace utils
return string::dump_hex(hash, ""); 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); 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}; uint8_t buffer[32] = {0};
@ -282,12 +283,12 @@ namespace utils
return string::dump_hex(hash, ""); 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); 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}; uint8_t buffer[64] = {0};

View File

@ -1,5 +1,4 @@
#pragma once #pragma once
#include "memory.hpp"
namespace utils namespace utils
{ {
@ -24,7 +23,7 @@ namespace utils
void deserialize(const std::string& key); 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(); void free();

View File

@ -1,5 +1,4 @@
#pragma once #pragma once
#include "memory.hpp"
namespace utils 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; if (!module.is_valid()) return false;

View File

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