Skip to content

Commit

Permalink
windows fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Yangff committed Feb 21, 2024
1 parent 20624d0 commit 268e7fa
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 58 deletions.
2 changes: 1 addition & 1 deletion UE4SS/src/UE4SSProgram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ namespace RC
SYSSTR(""));
m_load_library_ex_w_hook->hook();
#endif
Unreal::UnrealInitializer::SetupUnrealModules();
Unreal::UnrealInitializer::Platform::SetupUnrealModules();

setup_mods();
install_cpp_mods();
Expand Down
12 changes: 6 additions & 6 deletions deps/first/Helpers/include/Helpers/String.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,12 @@ namespace RC

template <typename T>
auto stringviewify(T&& tp) {
if constexpr (std::is_same_v<std::decay_t<T>, UECharType*> || std::is_same_v<std::decay_t<T>, const UECharType*>) {
return UEStringViewType{tp};
} else if constexpr (std::is_same_v<std::decay_t<T>, SystemCharType*> || std::is_same_v<std::decay_t<T>, const SystemCharType*>) {
return SystemStringViewType{tp};
} else if constexpr (std::is_same_v<std::decay_t<T>, File::CharType*> || std::is_same_v<std::decay_t<T>, const File::CharType*>) {
return File::StringViewType{tp};
if constexpr (std::is_same_v<std::decay_t<T>, char*> || std::is_same_v<std::decay_t<T>, const char*>) {
return std::string_view{tp};
} else if constexpr (std::is_same_v<std::decay_t<T>, wchar_t*> || std::is_same_v<std::decay_t<T>, const wchar_t*>) {
return std::wstring_view{tp};
} else if constexpr (std::is_same_v<std::decay_t<T>, char16_t*> || std::is_same_v<std::decay_t<T>, const char16_t*>) {
return std::u16string_view{tp};
} else {
return std::forward<T>(tp);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,20 +312,18 @@ namespace RC
RC_SPSS_API auto static string_to_vector(const std::vector<SignatureData>& signatures) -> std::vector<std::vector<int>>;
RC_SPSS_API auto static format_aob_strings(std::vector<SignatureContainer>& signature_containers) -> void;

RC_SPSS_API auto static get_system_info() -> SystemInfo;

public:
RC_SPSS_API auto static scanner_work_thread(uint8_t* start_address,
uint8_t* end_address,
SystemInfo& info,
SystemInfo* info,
std::vector<SignatureContainer>& signature_containers) -> void;
RC_SPSS_API auto static scanner_work_thread_scalar(uint8_t* start_address,
uint8_t* end_address,
SystemInfo& info,
SystemInfo* info,
std::vector<SignatureContainer>& signature_containers) -> void;
RC_SPSS_API auto static scanner_work_thread_stdfind(uint8_t* start_address,
uint8_t* end_address,
SystemInfo& info,
SystemInfo* info,
std::vector<SignatureContainer>& signature_containers) -> void;

using SignatureContainerMap = std::unordered_map<ScanTarget, std::vector<SignatureContainer>>;
Expand All @@ -335,17 +333,20 @@ namespace RC


namespace Platform {
// Get the system info
auto get_system_info() -> SystemInfo*;

// Get the start address of the system
auto get_start_address(SystemInfo &info) -> uint8_t*;
auto get_start_address(SystemInfo *info) -> uint8_t*;

// Get the end address of the system
auto get_end_address(SystemInfo &info) -> uint8_t*;
auto get_end_address(SystemInfo *info) -> uint8_t*;

// Get the size of the module
auto get_module_size(ModuleOS &info) -> uint32_t;
auto get_module_size(ModuleOS *info) -> uint32_t;

// Get the base address of the module
auto get_module_base(ModuleOS &info) -> uint8_t*;
auto get_module_base(ModuleOS *info) -> uint8_t*;
}; // namespace Platform

}; // namespace RC
25 changes: 10 additions & 15 deletions deps/first/SinglePassSigScanner/src/SinglePassSigScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ namespace RC
SinglePassScanner::ScanMethod SinglePassScanner::m_scan_method = ScanMethod::Scalar;
uint32_t SinglePassScanner::m_multithreading_module_size_threshold = 0x1000000;
std::mutex SinglePassScanner::m_scanner_mutex{};

auto ScanTargetArray::operator[](ScanTarget index) -> ModuleOS&
{
return array[static_cast<size_t>(index)];
}

auto ScanTargetToString(ScanTarget scan_target) -> std::string
{
Expand Down Expand Up @@ -429,7 +424,7 @@ namespace RC
return pattern_data;
}

auto SinglePassScanner::scanner_work_thread(uint8_t* start_address, uint8_t* end_address, SystemInfo& info, std::vector<SignatureContainer>& signature_containers)
auto SinglePassScanner::scanner_work_thread(uint8_t* start_address, uint8_t* end_address, SystemInfo *info, std::vector<SignatureContainer>& signature_containers)
-> void
{
ProfilerSetThreadName("UE4SS-ScannerWorkThread");
Expand Down Expand Up @@ -480,7 +475,7 @@ namespace RC

auto SinglePassScanner::scanner_work_thread_stdfind(uint8_t* start_address,
uint8_t* end_address,
SystemInfo& info,
SystemInfo* info,
std::vector<SignatureContainer>& signature_containers) -> void
{
ProfilerScope();
Expand Down Expand Up @@ -581,20 +576,20 @@ namespace RC

auto SinglePassScanner::start_scan(SignatureContainerMap& signature_containers) -> void
{
SystemInfo info = get_system_info();
SystemInfo* info = Platform::get_system_info();

// If not modular then the containers get merged into one scan target
// That way there are no extra scans
// If modular then loop the containers and retrieve the scan target for each and pass everything to the do_scan() lambda
fprintf(stderr, "signature_containers.size() = %d\n", signature_containers.size());
if (!SigScannerStaticData::m_is_modular)
{
ModuleOS merged_module_info{};
ModuleOS* merged_module_info{};
std::vector<SignatureContainer> merged_containers;

for (const auto& [scan_target, outer_container] : signature_containers)
{
merged_module_info = *std::bit_cast<ModuleOS*>(&SigScannerStaticData::m_modules_info[scan_target]);
merged_module_info = std::bit_cast<ModuleOS*>(&SigScannerStaticData::m_modules_info[scan_target]);
fprintf(stderr, "outer_container len = %d\n", outer_container.size());
for (const auto& signature_container : outer_container)
{
Expand Down Expand Up @@ -629,7 +624,7 @@ namespace RC
&scanner_work_thread,
module_start_address + last_range,
module_start_address + last_range + range,
std::ref(info),
info,
std::ref(merged_containers)));

last_range += range;
Expand All @@ -644,7 +639,7 @@ namespace RC
{
// Module is too small to make it overall faster to scan with multiple threads
uint8_t* module_end_address = static_cast<uint8_t*>(module_start_address + Platform::get_module_size(merged_module_info));
scanner_work_thread(module_start_address, module_end_address, merged_module_info, merged_containers);
scanner_work_thread(module_start_address, module_end_address, info, merged_containers);
}

for (auto& container : merged_containers)
Expand All @@ -657,11 +652,11 @@ namespace RC
// This ranged for loop is performing a copy of unordered_map<ScanTarget, vector<SignatureContainer>>
// Is this required ? Would it be worth trying to avoid copying here ?
// Right now it can't be auto& or const auto& because the do_scan function takes a non-const since it needs to mutate the values inside the vector
auto info = SigScannerStaticData::m_modules_info[ScanTarget::MainExe];
auto info = Platform::get_system_info();
for (auto& [scan_target, signature_container] : signature_containers)
{
uint8_t* module_start_address = static_cast<uint8_t*>(Platform::get_module_base(SigScannerStaticData::m_modules_info[scan_target]));
uint8_t* module_end_address = static_cast<uint8_t*>(module_start_address + Platform::get_module_size(SigScannerStaticData::m_modules_info[scan_target]));
uint8_t* module_start_address = static_cast<uint8_t*>(Platform::get_module_base(&SigScannerStaticData::m_modules_info[scan_target]));
uint8_t* module_end_address = static_cast<uint8_t*>(module_start_address + Platform::get_module_size(&SigScannerStaticData::m_modules_info[scan_target]));

scanner_work_thread(module_start_address, module_end_address, info, signature_container);

Expand Down
25 changes: 15 additions & 10 deletions deps/first/SinglePassSigScanner/src/SinglePassSigScannerLinux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,32 @@
namespace RC
{

auto SinglePassScanner::get_system_info() -> SystemInfo
auto ScanTargetArray::operator[](ScanTarget index) -> ModuleOS&
{
return SigScannerStaticData::m_modules_info[ScanTarget::MainExe];
return array[static_cast<size_t>(index)];
}

namespace Platform
{
auto SinglePassScanner::get_system_info() -> SystemInfo*
{
return &SigScannerStaticData::m_modules_info[ScanTarget::MainExe];
}

namespace Platform {
auto get_start_address(DLData &info) -> uint8_t* {
return info.base_address;
auto get_start_address(DLData *info) -> uint8_t* {
return info->base_address;
}

auto get_end_address(DLData &info) -> uint8_t* {
return info.base_address + info.size;
auto get_end_address(DLData *info) -> uint8_t* {
return info->base_address + info.size;
}

auto get_module_size(DLData &info) -> uint32_t {
return info.size;
auto get_module_size(DLData *info) -> uint32_t {
return info->size;
}

auto get_module_base(DLData &info) -> uint8_t* {
return info.base_address;
return info->base_address;
}
}; // namespace Platform

Expand Down
39 changes: 23 additions & 16 deletions deps/first/SinglePassSigScanner/src/SinglePassSigScannerWin32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,39 @@
namespace RC
{

auto SinglePassScanner::get_system_info() -> SystemInfo
auto ScanTargetArray::operator[](ScanTarget index) -> ModuleOS&
{
SYSTEM_INFO info{};
GetSystemInfo(&info);
return info;
return *std::bit_cast<MODULEINFO*>(&array[static_cast<size_t>(index)]);
}

namespace Platform {

namespace Platform
{
auto get_system_info() -> SystemInfo*
{
static SYSTEM_INFO info{};
GetSystemInfo(&info);
return &info;
}

// Get the start address of the system
auto get_start_address(SystemInfo &info) -> uint8_t* {
return static_cast<uint8_t*>(info.lpMinimumApplicationAddress);
auto get_start_address(SystemInfo *info) -> uint8_t* {
return static_cast<uint8_t*>(info->lpMinimumApplicationAddress);
}

// Get the end address of the system
auto get_end_address(SystemInfo &info) -> uint8_t* {
return static_cast<uint8_t*>(info.lpMaximumApplicationAddress);
auto get_end_address(SystemInfo *info) -> uint8_t* {
return static_cast<uint8_t*>(info->lpMaximumApplicationAddress);
}

// Get the size of the module
auto get_module_size(ModuleOS &info) -> size_t {
return info.SizeOfImage;
auto get_module_size(ModuleOS *info) -> uint32_t {
return info->SizeOfImage;
}

// Get the base address of the module
auto get_module_base(ModuleOS &info) -> uint8_t* {
return static_cast<uint8_t*>(info.lpBaseOfDll);
auto get_module_base(ModuleOS *info) -> uint8_t* {
return static_cast<uint8_t*>(info->lpBaseOfDll);
}
}; // namespace Platform

Expand Down Expand Up @@ -106,17 +113,17 @@ namespace RC

auto SinglePassScanner::scanner_work_thread_scalar(uint8_t* start_address,
uint8_t* end_address,
SYSTEM_INFO& info,
SYSTEM_INFO* info,
std::vector<SignatureContainer>& signature_containers) -> void
{
ProfilerScope();
if (!start_address)
{
start_address = static_cast<uint8_t*>(info.lpMinimumApplicationAddress);
start_address = static_cast<uint8_t*>(info->lpMinimumApplicationAddress);
}
if (!end_address)
{
start_address = static_cast<uint8_t*>(info.lpMaximumApplicationAddress);
start_address = static_cast<uint8_t*>(info->lpMaximumApplicationAddress);
}

MEMORY_BASIC_INFORMATION memory_info{};
Expand Down
2 changes: 1 addition & 1 deletion deps/first/Unreal

0 comments on commit 268e7fa

Please sign in to comment.