mirror of
https://github.com/a2x/cs2-dumper.git
synced 2025-12-21 11:00:01 +08:00
Refactored code
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
namespace builder {
|
||||
class CppFileBuilder : public IFileBuilder {
|
||||
public:
|
||||
std::string get_extension() noexcept override {
|
||||
std::string extension() noexcept override {
|
||||
return "hpp";
|
||||
}
|
||||
|
||||
@@ -12,12 +12,12 @@ namespace builder {
|
||||
output << "#include <cstddef>\n\n";
|
||||
}
|
||||
|
||||
void write_namespace(std::ofstream& output, const std::string& namespace_name) noexcept override {
|
||||
output << "namespace " << namespace_name << " {\n";
|
||||
void write_namespace(std::ofstream& output, const std::string& name) noexcept override {
|
||||
output << "namespace " << name << " {\n";
|
||||
}
|
||||
|
||||
void write_variable(std::ofstream& output, const std::string& variable_name, const std::uint64_t variable_value) noexcept override {
|
||||
output << " constexpr std::ptrdiff_t " << variable_name << " = 0x" << std::hex << variable_value << ";\n";
|
||||
void write_variable(std::ofstream& output, const std::string& name, const std::uintptr_t value) noexcept override {
|
||||
output << " constexpr std::ptrdiff_t " << name << " = 0x" << std::hex << value << ";\n";
|
||||
}
|
||||
|
||||
void write_closure(std::ofstream& output, const bool eof) noexcept override {
|
||||
|
||||
@@ -3,20 +3,18 @@
|
||||
namespace builder {
|
||||
class CSharpFileBuilder : public IFileBuilder {
|
||||
public:
|
||||
std::string get_extension() noexcept override {
|
||||
std::string extension() noexcept override {
|
||||
return "cs";
|
||||
}
|
||||
|
||||
void write_top_level(std::ofstream& output) noexcept override {
|
||||
// Nothing needed here.
|
||||
void write_top_level(std::ofstream& output) noexcept override {}
|
||||
|
||||
void write_namespace(std::ofstream& output, const std::string& name) noexcept override {
|
||||
output << "public static class " << name << " {\n";
|
||||
}
|
||||
|
||||
void write_namespace(std::ofstream& output, const std::string& namespace_name) noexcept override {
|
||||
output << "public static class " << namespace_name << " {\n";
|
||||
}
|
||||
|
||||
void write_variable(std::ofstream& output, const std::string& variable_name, const std::uint64_t variable_value) noexcept override {
|
||||
output << " public const ulong " << variable_name << " = 0x" << std::hex << variable_value << ";\n";
|
||||
void write_variable(std::ofstream& output, const std::string& name, const std::uintptr_t value) noexcept override {
|
||||
output << " public const ulong " << name << " = 0x" << std::hex << value << ";\n";
|
||||
}
|
||||
|
||||
void write_closure(std::ofstream& output, const bool eof) noexcept override {
|
||||
|
||||
@@ -7,10 +7,10 @@ namespace builder {
|
||||
class IFileBuilder {
|
||||
public:
|
||||
virtual ~IFileBuilder() noexcept = default;
|
||||
virtual std::string get_extension() noexcept = 0;
|
||||
virtual std::string extension() noexcept = 0;
|
||||
virtual void write_top_level(std::ofstream& output) noexcept = 0;
|
||||
virtual void write_namespace(std::ofstream& output, const std::string& namespace_name) noexcept = 0;
|
||||
virtual void write_variable(std::ofstream& output, const std::string& variable_name, std::uint64_t variable_value) noexcept = 0;
|
||||
virtual void write_namespace(std::ofstream& output, const std::string& name) noexcept = 0;
|
||||
virtual void write_variable(std::ofstream& output, const std::string& name, std::uintptr_t value) noexcept = 0;
|
||||
virtual void write_closure(std::ofstream& output, bool eof) noexcept = 0;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -5,20 +5,18 @@
|
||||
namespace builder {
|
||||
class JsonFileBuilder : public IFileBuilder {
|
||||
public:
|
||||
std::string get_extension() noexcept override {
|
||||
std::string extension() noexcept override {
|
||||
return "json";
|
||||
}
|
||||
|
||||
void write_top_level(std::ofstream& output) noexcept override {
|
||||
// Nothing needed here.
|
||||
void write_top_level(std::ofstream& output) noexcept override {}
|
||||
|
||||
void write_namespace(std::ofstream& output, const std::string& name) noexcept override {
|
||||
namespace_name_ = name;
|
||||
}
|
||||
|
||||
void write_namespace(std::ofstream& output, const std::string& namespace_name) noexcept override {
|
||||
current_namespace_name_ = namespace_name;
|
||||
}
|
||||
|
||||
void write_variable(std::ofstream& output, const std::string& variable_name, const std::uint64_t variable_value) noexcept override {
|
||||
json[current_namespace_name_][variable_name] = variable_value;
|
||||
void write_variable(std::ofstream& output, const std::string& name, const std::uintptr_t value) noexcept override {
|
||||
json[namespace_name_][name] = value;
|
||||
}
|
||||
|
||||
void write_closure(std::ofstream& output, const bool eof) noexcept override {
|
||||
@@ -33,6 +31,6 @@ namespace builder {
|
||||
nlohmann::json json;
|
||||
|
||||
private:
|
||||
std::string current_namespace_name_;
|
||||
std::string namespace_name_;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
namespace builder {
|
||||
class RustFileBuilder : public IFileBuilder {
|
||||
public:
|
||||
std::string get_extension() noexcept override {
|
||||
std::string extension() noexcept override {
|
||||
return "rs";
|
||||
}
|
||||
|
||||
@@ -11,12 +11,12 @@ namespace builder {
|
||||
output << "#![allow(non_snake_case, non_upper_case_globals)]\n\n";
|
||||
}
|
||||
|
||||
void write_namespace(std::ofstream& output, const std::string& namespace_name) noexcept override {
|
||||
output << "pub mod " << namespace_name << " {\n";
|
||||
void write_namespace(std::ofstream& output, const std::string& name) noexcept override {
|
||||
output << "pub mod " << name << " {\n";
|
||||
}
|
||||
|
||||
void write_variable(std::ofstream& output, const std::string& variable_name, const std::uint64_t variable_value) noexcept override {
|
||||
output << " pub const " << variable_name << ": usize = 0x" << std::hex << variable_value << ";\n";
|
||||
void write_variable(std::ofstream& output, const std::string& name, const std::uintptr_t value) noexcept override {
|
||||
output << " pub const " << name << ": usize = 0x" << std::hex << value << ";\n";
|
||||
}
|
||||
|
||||
void write_closure(std::ofstream& output, const bool eof) noexcept override {
|
||||
|
||||
@@ -1,36 +1,31 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include "utility/address.hpp"
|
||||
|
||||
#include <optional>
|
||||
#include <string_view>
|
||||
#include <vector>
|
||||
|
||||
namespace process {
|
||||
bool attach(std::string_view process_name);
|
||||
bool attach(std::string_view process_name) noexcept;
|
||||
|
||||
[[nodiscard]] std::optional<std::uintptr_t> find_pattern(std::string_view module_name, std::string_view pattern) noexcept;
|
||||
[[nodiscard]] std::optional<utility::Address> find_pattern(std::string_view module_name, std::string_view pattern) noexcept;
|
||||
|
||||
[[nodiscard]] std::optional<std::uintptr_t> get_export(std::uintptr_t module_base, std::string_view function_name) noexcept;
|
||||
[[nodiscard]] std::optional<std::uintptr_t> get_module_base_by_name(std::string_view module_name) noexcept;
|
||||
|
||||
[[nodiscard]] std::optional<std::uintptr_t> get_export(std::string_view module_name, std::string_view function_name) noexcept;
|
||||
std::optional<std::uintptr_t> get_module_export_by_name(std::uintptr_t module_base, std::string_view function_name) noexcept;
|
||||
|
||||
[[nodiscard]] std::optional<std::vector<std::string>> get_loaded_modules() noexcept;
|
||||
|
||||
[[nodiscard]] std::optional<std::uintptr_t> get_module_base(std::string_view module_name) noexcept;
|
||||
|
||||
[[nodiscard]] std::optional<std::uintptr_t> resolve_jmp(std::uintptr_t address) noexcept;
|
||||
|
||||
[[nodiscard]] std::optional<std::uintptr_t> resolve_rip_relative_address(std::uintptr_t address) noexcept;
|
||||
[[nodiscard]] std::optional<std::vector<std::string>> loaded_modules() noexcept;
|
||||
|
||||
bool read_memory(std::uintptr_t address, void* buffer, std::size_t size) noexcept;
|
||||
|
||||
bool write_memory(std::uintptr_t address, const void* buffer, std::size_t size) noexcept;
|
||||
|
||||
std::string read_string(std::uintptr_t address, std::size_t length) noexcept;
|
||||
[[nodiscard]] std::string read_string(std::uintptr_t address, std::size_t length) noexcept;
|
||||
|
||||
template <typename T>
|
||||
T read_memory(const std::uintptr_t address) noexcept {
|
||||
T buffer = {};
|
||||
T buffer{};
|
||||
|
||||
read_memory(address, &buffer, sizeof(T));
|
||||
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace sdk {
|
||||
class SchemaClassFieldData_t {
|
||||
public:
|
||||
[[nodiscard]] std::string get_name() const noexcept;
|
||||
|
||||
[[nodiscard]] std::uint16_t get_offset() const noexcept;
|
||||
};
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace sdk {
|
||||
class SchemaClassFieldData_t;
|
||||
|
||||
class CSchemaClassInfo {
|
||||
public:
|
||||
[[nodiscard]] std::uint16_t get_fields_count() const noexcept;
|
||||
|
||||
[[nodiscard]] std::vector<SchemaClassFieldData_t*> get_fields() const noexcept;
|
||||
};
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace sdk {
|
||||
class CSchemaSystemTypeScope;
|
||||
|
||||
class CSchemaSystem {
|
||||
public:
|
||||
static CSchemaSystem* get() noexcept;
|
||||
|
||||
[[nodiscard]] std::vector<CSchemaSystemTypeScope*> get_type_scopes() const noexcept;
|
||||
};
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace sdk {
|
||||
class CSchemaClassInfo;
|
||||
class CSchemaType_DeclaredClass;
|
||||
|
||||
class CSchemaSystemTypeScope {
|
||||
public:
|
||||
[[nodiscard]] CSchemaClassInfo* find_declared_class(std::string_view class_name) const noexcept;
|
||||
|
||||
[[nodiscard]] std::vector<CSchemaType_DeclaredClass*> get_declared_classes() const noexcept;
|
||||
|
||||
[[nodiscard]] std::string get_module_name() const noexcept;
|
||||
};
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
namespace sdk {
|
||||
class CSchemaType_DeclaredClass {
|
||||
public:
|
||||
[[nodiscard]] std::string get_class_name() const noexcept;
|
||||
};
|
||||
}
|
||||
10
include/sdk/schema_class_field_data.hpp
Normal file
10
include/sdk/schema_class_field_data.hpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
namespace sdk {
|
||||
class SchemaClassFieldData {
|
||||
public:
|
||||
[[nodiscard]] std::string name() const noexcept;
|
||||
|
||||
[[nodiscard]] std::uint16_t offset() const noexcept;
|
||||
};
|
||||
}
|
||||
10
include/sdk/schema_class_info.hpp
Normal file
10
include/sdk/schema_class_info.hpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
namespace sdk {
|
||||
class SchemaClassInfo {
|
||||
public:
|
||||
[[nodiscard]] std::uint16_t fields_count() const noexcept;
|
||||
|
||||
void for_each_field(const std::function<void(SchemaClassFieldData*)>& callback) const noexcept;
|
||||
};
|
||||
}
|
||||
10
include/sdk/schema_system.hpp
Normal file
10
include/sdk/schema_system.hpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
namespace sdk {
|
||||
class SchemaSystem {
|
||||
public:
|
||||
static SchemaSystem* get() noexcept;
|
||||
|
||||
[[nodiscard]] std::vector<SchemaSystemTypeScope*> type_scopes() const noexcept;
|
||||
};
|
||||
}
|
||||
10
include/sdk/schema_system_type_scope.hpp
Normal file
10
include/sdk/schema_system_type_scope.hpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
namespace sdk {
|
||||
class SchemaSystemTypeScope {
|
||||
public:
|
||||
void for_each_class(const std::function<void(std::pair<std::string, SchemaClassInfo*>)>& callback) const noexcept;
|
||||
|
||||
[[nodiscard]] std::string module_name() const noexcept;
|
||||
};
|
||||
}
|
||||
10
include/sdk/schema_type_declared_class.hpp
Normal file
10
include/sdk/schema_type_declared_class.hpp
Normal file
@@ -0,0 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
namespace sdk {
|
||||
class SchemaTypeDeclaredClass {
|
||||
public:
|
||||
[[nodiscard]] std::string binary_name() const noexcept;
|
||||
|
||||
[[nodiscard]] std::string module_name() const noexcept;
|
||||
};
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
#include "process.hpp"
|
||||
|
||||
#include "c_schema_class_field_data.hpp"
|
||||
#include "c_schema_class_info.hpp"
|
||||
#include "c_schema_system.hpp"
|
||||
#include "c_schema_system_type_scope.hpp"
|
||||
#include "c_schema_type_declared_class.hpp"
|
||||
#include "schema_class_field_data.hpp"
|
||||
#include "schema_class_info.hpp"
|
||||
#include "schema_type_declared_class.hpp"
|
||||
#include "schema_system_type_scope.hpp"
|
||||
#include "schema_system.hpp"
|
||||
#include "utl_ts_hash.hpp"
|
||||
|
||||
119
include/sdk/utl_ts_hash.hpp
Normal file
119
include/sdk/utl_ts_hash.hpp
Normal file
@@ -0,0 +1,119 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace sdk {
|
||||
template <class T, typename K>
|
||||
class HashBucketDataInternal {
|
||||
public:
|
||||
HashBucketDataInternal<T, K>* next() const noexcept {
|
||||
return process::read_memory<HashBucketDataInternal<T, K>*>(reinterpret_cast<std::uint64_t>(this) + 0x8);
|
||||
}
|
||||
|
||||
public:
|
||||
T data; // 0x0
|
||||
std::byte pad_0[0x8]; // 0x8
|
||||
K ui_key; // 0x10
|
||||
};
|
||||
|
||||
template <class T, typename K>
|
||||
class HashFixedDataInternal {
|
||||
public:
|
||||
HashFixedDataInternal<T, K>* next() const noexcept {
|
||||
return process::read_memory<HashFixedDataInternal<T, K>*>(reinterpret_cast<std::uint64_t>(this) + 0x8);
|
||||
}
|
||||
|
||||
public:
|
||||
K ui_key; // 0x0
|
||||
std::byte pad_0[0x8]; // 0x8
|
||||
T data; // 0x10
|
||||
};
|
||||
|
||||
template <class T, typename K>
|
||||
struct HashAllocatedData {
|
||||
std::array<HashFixedDataInternal<T, K>, 128> list() const noexcept {
|
||||
return process::read_memory<std::array<HashFixedDataInternal<T, K>, 128>>(reinterpret_cast<std::uint64_t>(this) + 0x18);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, typename K>
|
||||
class HashUnallocatedData {
|
||||
public:
|
||||
HashUnallocatedData<T, K>* next() const noexcept {
|
||||
return process::read_memory<HashUnallocatedData<T, K>*>(reinterpret_cast<std::uint64_t>(this));
|
||||
}
|
||||
|
||||
K ui_key() const noexcept {
|
||||
return process::read_memory<K>(reinterpret_cast<std::uint64_t>(this) + 0x10);
|
||||
}
|
||||
|
||||
std::array<HashBucketDataInternal<T, K>, 256> block_list() const noexcept {
|
||||
return process::read_memory<std::array<HashBucketDataInternal<T, K>, 256>>(reinterpret_cast<std::uint64_t>(this) + 0x20);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, typename K>
|
||||
struct HashBucket {
|
||||
std::byte pad_0[0x10]; // 0x0
|
||||
HashAllocatedData<T, K>* allocated_data; // 0x10
|
||||
HashUnallocatedData<T, K>* unallocated_data; // 0x18
|
||||
};
|
||||
|
||||
class UtlMemoryPool {
|
||||
public:
|
||||
[[nodiscard]] std::int32_t block_size() const noexcept {
|
||||
return blocks_per_blob_;
|
||||
}
|
||||
|
||||
[[nodiscard]] std::int32_t count() const noexcept {
|
||||
return block_allocated_size_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::int32_t block_size_; // 0x0
|
||||
std::int32_t blocks_per_blob_; // 0x4
|
||||
std::int32_t grow_mode_; // 0x8
|
||||
std::int32_t blocks_allocated_; // 0xC
|
||||
std::int32_t block_allocated_size_; // 0x10
|
||||
std::int32_t peak_alloc_; // 0x14
|
||||
};
|
||||
|
||||
template <class T, typename K = std::uint64_t>
|
||||
class UtlTsHash {
|
||||
public:
|
||||
[[nodiscard]] std::int32_t block_size() const noexcept {
|
||||
return entry_memory.block_size();
|
||||
}
|
||||
|
||||
[[nodiscard]] std::int32_t count() const noexcept {
|
||||
return entry_memory.count();
|
||||
}
|
||||
|
||||
std::vector<T> elements() const noexcept {
|
||||
std::vector<T> list;
|
||||
|
||||
const auto& unallocated_data = buckets.unallocated_data;
|
||||
|
||||
std::int32_t index = 0;
|
||||
|
||||
for (auto element = unallocated_data; element != nullptr; element = element->next()) {
|
||||
const auto block_list = element->block_list();
|
||||
|
||||
for (std::int32_t i = 0; i < block_size() && i != count(); ++i) {
|
||||
list.emplace_back(block_list[i].data);
|
||||
|
||||
++index;
|
||||
|
||||
if (index >= count())
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
private:
|
||||
UtlMemoryPool entry_memory; // 0x0
|
||||
HashBucket<T, K> buckets; // 0x18
|
||||
};
|
||||
}
|
||||
33
include/utility/address.hpp
Normal file
33
include/utility/address.hpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace utility {
|
||||
class Address {
|
||||
public:
|
||||
Address() noexcept = default;
|
||||
|
||||
explicit Address(const std::uintptr_t address) noexcept : address_(address) {}
|
||||
|
||||
[[nodiscard]] Address add(std::ptrdiff_t offset) const noexcept;
|
||||
|
||||
[[nodiscard]] std::uintptr_t address() const noexcept;
|
||||
|
||||
[[nodiscard]] Address get(std::size_t times = 1) const noexcept;
|
||||
|
||||
[[nodiscard]] bool is_valid() const noexcept;
|
||||
|
||||
[[nodiscard]] Address jmp(std::ptrdiff_t offset = 0x1) const noexcept;
|
||||
|
||||
[[nodiscard]] Address rip(std::ptrdiff_t offset = 0x3, std::size_t length = 7) const noexcept;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] T as() const noexcept {
|
||||
return reinterpret_cast<T>(address_);
|
||||
}
|
||||
|
||||
private:
|
||||
std::uintptr_t address_;
|
||||
};
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace utility {
|
||||
std::uint32_t murmur_hash2(const void* key, std::uint32_t length, std::uint32_t seed);
|
||||
}
|
||||
@@ -6,7 +6,7 @@
|
||||
|
||||
#include <handleapi.h>
|
||||
|
||||
namespace base {
|
||||
namespace utility {
|
||||
namespace detail {
|
||||
struct HandleDisposer {
|
||||
using pointer = HANDLE;
|
||||
12
include/utility/string.hpp
Normal file
12
include/utility/string.hpp
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <cctype>
|
||||
#include <string_view>
|
||||
|
||||
namespace utility::string {
|
||||
inline bool equals_ignore_case(const std::string_view str_1, const std::string_view str_2) noexcept {
|
||||
return (str_1.size() == str_2.size()) && std::equal(str_1.begin(), str_1.end(), str_2.begin(), [](const char a, const char b) {
|
||||
return std::tolower(a) == std::tolower(b);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user