bool Simulator::load(memory_t &image, bool allow_resize, addr_t load_offset) { size_t required_size = image.size() + load_offset; size_t available_size = state.mem.size(); if(required_size > available_size) { if(!allow_resize) return false; state.mem.resize(required_size); } std::copy(image.begin(), image.end(), state.mem.data() + load_offset); status.image_loaded = true; return true; }
#include "../../src/CheatEngine.h" #include "FakeProcess.h" #include "catch.hpp" #include <string> TEST_CASE("CheatEngine can search for matches") { FakeProcess process; CheatEngine engine{process}; const std::string str = "this is a test."; memory_t memory{std::begin(str), std::end(str)}; process.pages = { MemoryPage(memory.data(), memory.size()) }; process.reads = { memory }; SECTION("does not find a match when the value is missing") { const auto matches = engine.search({ 't', 'e', 's', 's' }); REQUIRE(matches.getPageMatches().empty()); } SECTION("does find a match when the value present") { const auto matches = engine.search({ 'i', 's' }); REQUIRE(matches.getPageMatches().size() == 1); const auto match = matches.getPageMatches().front(); const offsets_t offsets = {2, 5}; REQUIRE(match.getOffsets() == offsets); }