diff options
author | jbzdarkid <jbzdarkid@gmail.com> | 2018-12-09 11:48:17 -0800 |
---|---|---|
committer | jbzdarkid <jbzdarkid@gmail.com> | 2018-12-09 11:48:17 -0800 |
commit | 4ad724eaae7be3780b5fb891b391bbf4ef26f410 (patch) | |
tree | d4daf1c5a8036098ee7dd4a52690802dbacaf3c3 /Source/Memory.cpp | |
parent | f485927337c329a4a691500a1b6c18c763863bb4 (diff) | |
download | witness-tutorializer-4ad724eaae7be3780b5fb891b391bbf4ef26f410.tar.gz witness-tutorializer-4ad724eaae7be3780b5fb891b391bbf4ef26f410.tar.bz2 witness-tutorializer-4ad724eaae7be3780b5fb891b391bbf4ef26f410.zip |
Improve internals of sigscanning, fix a small overwrite bug
Diffstat (limited to 'Source/Memory.cpp')
-rw-r--r-- | Source/Memory.cpp | 37 |
1 files changed, 35 insertions, 2 deletions
diff --git a/Source/Memory.cpp b/Source/Memory.cpp index 43cb9b3..2d0d4a9 100644 --- a/Source/Memory.cpp +++ b/Source/Memory.cpp | |||
@@ -63,12 +63,45 @@ int Memory::GetCurrentFrame() | |||
63 | return ReadData<int>({SCRIPT_FRAMES}, 1)[0]; | 63 | return ReadData<int>({SCRIPT_FRAMES}, 1)[0]; |
64 | } | 64 | } |
65 | 65 | ||
66 | void Memory::SigScan(std::function<void(int offset, const std::vector<byte>& data)> scanFunc) | 66 | void Memory::AddSigScan(const std::vector<byte>& scanBytes, const std::function<void(int index)>& scanFunc) |
67 | { | ||
68 | _sigScans[scanBytes] = {scanFunc, false}; | ||
69 | } | ||
70 | |||
71 | int find(const std::vector<byte> &data, const std::vector<byte>& search, size_t startIndex = 0) { | ||
72 | for (size_t i=startIndex; i<data.size() - search.size(); i++) { | ||
73 | bool match = true; | ||
74 | for (size_t j=0; j<search.size(); j++) { | ||
75 | if (data[i+j] == search[j]) { | ||
76 | continue; | ||
77 | } | ||
78 | match = false; | ||
79 | break; | ||
80 | } | ||
81 | if (match) return static_cast<int>(i); | ||
82 | } | ||
83 | return -1; | ||
84 | } | ||
85 | |||
86 | int Memory::ExecuteSigScans() | ||
67 | { | 87 | { |
68 | for (int i=0; i<0x200000; i+=0x1000) { | 88 | for (int i=0; i<0x200000; i+=0x1000) { |
69 | std::vector<byte> data = ReadData<byte>({i}, 0x1100); | 89 | std::vector<byte> data = ReadData<byte>({i}, 0x1100); |
70 | scanFunc(i, data); | 90 | |
91 | for (auto& [scanBytes, sigScan] : _sigScans) { | ||
92 | if (sigScan.found) continue; | ||
93 | int index = find(data, scanBytes); | ||
94 | if (index == -1) continue; | ||
95 | sigScan.scanFunc(i + index); | ||
96 | sigScan.found = true; | ||
97 | } | ||
98 | } | ||
99 | |||
100 | int notFound = 0; | ||
101 | for (auto it : _sigScans) { | ||
102 | if (it.second.found == false) notFound++; | ||
71 | } | 103 | } |
104 | return notFound; | ||
72 | } | 105 | } |
73 | 106 | ||
74 | void Memory::ThrowError() { | 107 | void Memory::ThrowError() { |