diff options
Diffstat (limited to '')
| -rw-r--r-- | src/core/memory/cheat_engine.cpp | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/src/core/memory/cheat_engine.cpp b/src/core/memory/cheat_engine.cpp index a06e99166..53a89cc8f 100644 --- a/src/core/memory/cheat_engine.cpp +++ b/src/core/memory/cheat_engine.cpp | |||
| @@ -19,16 +19,23 @@ namespace Core::Memory { | |||
| 19 | namespace { | 19 | namespace { |
| 20 | constexpr auto CHEAT_ENGINE_NS = std::chrono::nanoseconds{1000000000 / 12}; | 20 | constexpr auto CHEAT_ENGINE_NS = std::chrono::nanoseconds{1000000000 / 12}; |
| 21 | 21 | ||
| 22 | std::string_view ExtractName(std::string_view data, std::size_t start_index, char match) { | 22 | std::string_view ExtractName(std::size_t& out_name_size, std::string_view data, |
| 23 | std::size_t start_index, char match) { | ||
| 23 | auto end_index = start_index; | 24 | auto end_index = start_index; |
| 24 | while (data[end_index] != match) { | 25 | while (data[end_index] != match) { |
| 25 | ++end_index; | 26 | ++end_index; |
| 26 | if (end_index > data.size() || | 27 | if (end_index > data.size()) { |
| 27 | (end_index - start_index - 1) > sizeof(CheatDefinition::readable_name)) { | ||
| 28 | return {}; | 28 | return {}; |
| 29 | } | 29 | } |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | out_name_size = end_index - start_index; | ||
| 33 | |||
| 34 | // Clamp name if it's too big | ||
| 35 | if (out_name_size > sizeof(CheatDefinition::readable_name)) { | ||
| 36 | end_index = start_index + sizeof(CheatDefinition::readable_name); | ||
| 37 | } | ||
| 38 | |||
| 32 | return data.substr(start_index, end_index - start_index); | 39 | return data.substr(start_index, end_index - start_index); |
| 33 | } | 40 | } |
| 34 | } // Anonymous namespace | 41 | } // Anonymous namespace |
| @@ -113,7 +120,8 @@ std::vector<CheatEntry> TextCheatParser::Parse(std::string_view data) const { | |||
| 113 | return {}; | 120 | return {}; |
| 114 | } | 121 | } |
| 115 | 122 | ||
| 116 | const auto name = ExtractName(data, i + 1, '}'); | 123 | std::size_t name_size{}; |
| 124 | const auto name = ExtractName(name_size, data, i + 1, '}'); | ||
| 117 | if (name.empty()) { | 125 | if (name.empty()) { |
| 118 | return {}; | 126 | return {}; |
| 119 | } | 127 | } |
| @@ -125,12 +133,13 @@ std::vector<CheatEntry> TextCheatParser::Parse(std::string_view data) const { | |||
| 125 | .definition.readable_name[out[*current_entry].definition.readable_name.size() - 1] = | 133 | .definition.readable_name[out[*current_entry].definition.readable_name.size() - 1] = |
| 126 | '\0'; | 134 | '\0'; |
| 127 | 135 | ||
| 128 | i += name.length() + 1; | 136 | i += name_size + 1; |
| 129 | } else if (data[i] == '[') { | 137 | } else if (data[i] == '[') { |
| 130 | current_entry = out.size(); | 138 | current_entry = out.size(); |
| 131 | out.emplace_back(); | 139 | out.emplace_back(); |
| 132 | 140 | ||
| 133 | const auto name = ExtractName(data, i + 1, ']'); | 141 | std::size_t name_size{}; |
| 142 | const auto name = ExtractName(name_size, data, i + 1, ']'); | ||
| 134 | if (name.empty()) { | 143 | if (name.empty()) { |
| 135 | return {}; | 144 | return {}; |
| 136 | } | 145 | } |
| @@ -142,7 +151,7 @@ std::vector<CheatEntry> TextCheatParser::Parse(std::string_view data) const { | |||
| 142 | .definition.readable_name[out[*current_entry].definition.readable_name.size() - 1] = | 151 | .definition.readable_name[out[*current_entry].definition.readable_name.size() - 1] = |
| 143 | '\0'; | 152 | '\0'; |
| 144 | 153 | ||
| 145 | i += name.length() + 1; | 154 | i += name_size + 1; |
| 146 | } else if (::isxdigit(data[i])) { | 155 | } else if (::isxdigit(data[i])) { |
| 147 | if (!current_entry || out[*current_entry].definition.num_opcodes >= | 156 | if (!current_entry || out[*current_entry].definition.num_opcodes >= |
| 148 | out[*current_entry].definition.opcodes.size()) { | 157 | out[*current_entry].definition.opcodes.size()) { |