фыв
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
|
||||
#include "sigscan.hpp"
|
||||
#include "../../utilities/log.h"
|
||||
#include "../memory/memadd.h"
|
||||
CSigScan::CSigScan(const char* name, const char* libraryName, const std::initializer_list<SigData_t>& data) {
|
||||
#ifdef SDK_ENABLE_LOGGING
|
||||
m_Name = name;
|
||||
#else
|
||||
m_Name = "";
|
||||
#endif
|
||||
|
||||
m_LibraryName = libraryName;
|
||||
|
||||
m_Data.reserve(data.size());
|
||||
m_Data.insert(m_Data.end(), data.begin(), data.end());
|
||||
|
||||
CSigScanManager::Get().ScheduleScan(this);
|
||||
}
|
||||
|
||||
void CSigScan::FindSignature() {
|
||||
auto& library = CMemory::GetModule(m_LibraryName);
|
||||
if (!library) {
|
||||
L_PRINT(LOG_WARNING) << CS_XOR("\"signature\" Couldn't find {} because {} was not loaded.");
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < m_Data.size(); ++i) {
|
||||
// Faster than m_Data[] in debug builds because of _STL_VERIFY.
|
||||
const auto& data = m_Data.data()[i];
|
||||
|
||||
m_Value = library->FindPattern(data.m_Signature);
|
||||
if (m_Value.IsValid()) {
|
||||
if (data.m_Procedure) {
|
||||
data.m_Procedure(m_Value);
|
||||
}
|
||||
|
||||
L_PRINT(LOG_INFO) << CS_XOR("\"signature\" Couldn't find " << m_Name << " because{} " << m_Value.Get<void*>() << "was not loaded " << i << " | index.");
|
||||
}
|
||||
}
|
||||
|
||||
L_PRINT(LOG_ERROR) << CS_XOR("\"signature\" Couldn't find ");
|
||||
|
||||
}
|
||||
|
||||
void CSigScanManager::ScheduleScan(CSigScan* sigScan) { m_ScheduledScans.emplace_back(sigScan); }
|
||||
|
||||
void CSigScanManager::ProcessScans() {
|
||||
for (size_t i = 0; i < m_ScheduledScans.size(); ++i) {
|
||||
// Faster than m_ScheduledScans[] in debug builds because of _STL_VERIFY.
|
||||
const auto& scheduledScan = m_ScheduledScans.data()[i];
|
||||
|
||||
scheduledScan->FindSignature();
|
||||
scheduledScan->FreeData();
|
||||
}
|
||||
|
||||
// No need to keep the scans in memory if we're done with them.
|
||||
std::vector<CSigScan*>().swap(m_ScheduledScans);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include "../pointer/pointer.hpp"
|
||||
#include <span>
|
||||
#include <functional>
|
||||
|
||||
class CSigScan {
|
||||
public:
|
||||
using ProcedureFn = std::function<void(CPointer&)>;
|
||||
|
||||
struct SigData_t {
|
||||
std::span<const int> m_Signature;
|
||||
ProcedureFn m_Procedure;
|
||||
};
|
||||
|
||||
CSigScan(const char* name, const char* libraryName, const std::initializer_list<SigData_t>& data);
|
||||
|
||||
void FindSignature();
|
||||
auto FreeData() { std::vector<SigData_t>().swap(m_Data); }
|
||||
|
||||
auto GetPtr() const { return m_Value; }
|
||||
|
||||
template <typename T>
|
||||
auto GetPtrAs() const {
|
||||
return m_Value.Get<T>();
|
||||
}
|
||||
|
||||
CSigScan(const CSigScan&) = delete;
|
||||
CSigScan& operator=(const CSigScan&) = delete;
|
||||
|
||||
private:
|
||||
const char* m_Name;
|
||||
const char* m_LibraryName;
|
||||
|
||||
std::vector<SigData_t> m_Data;
|
||||
|
||||
CPointer m_Value;
|
||||
};
|
||||
|
||||
class CSigScanManager {
|
||||
public:
|
||||
static CSigScanManager& Get() {
|
||||
static CSigScanManager inst;
|
||||
return inst;
|
||||
}
|
||||
|
||||
void ScheduleScan(CSigScan* sigScan);
|
||||
void ProcessScans();
|
||||
|
||||
private:
|
||||
std::vector<CSigScan*> m_ScheduledScans;
|
||||
};
|
||||
Reference in New Issue
Block a user