aboutsummaryrefslogtreecommitdiff
path: root/src/tools/connection_patcher/Patcher.cpp
diff options
context:
space:
mode:
authorDuarte Duarte <dnpd.dd@gmail.com>2014-11-09 16:52:49 +0000
committerDuarte Duarte <dnpd.dd@gmail.com>2014-11-09 16:52:49 +0000
commit60eaa06d208cad87bd83f2e4932086207456ba22 (patch)
treef876c40dfe1f4c21e627d5dbb2b4b04fd2314a5f /src/tools/connection_patcher/Patcher.cpp
parent543bea32e16bbe317171d24888a5f0c751ea19e8 (diff)
parent20d1d9d99759369c99f6c25d8e3b8300bff2b8c7 (diff)
Merge pull request #13521 from TrinityCore/connection_patcher/fix_osx__document__fix_nonexistant_file_exception
Connection patcher: fix osx, document, fix nonexistant file exception
Diffstat (limited to 'src/tools/connection_patcher/Patcher.cpp')
-rw-r--r--src/tools/connection_patcher/Patcher.cpp28
1 files changed, 16 insertions, 12 deletions
diff --git a/src/tools/connection_patcher/Patcher.cpp b/src/tools/connection_patcher/Patcher.cpp
index 65cf1704472..92d9dacedf3 100644
--- a/src/tools/connection_patcher/Patcher.cpp
+++ b/src/tools/connection_patcher/Patcher.cpp
@@ -24,6 +24,7 @@
#include <fstream>
#include <iostream>
#include <iterator>
+#include <set>
#include <stdexcept>
namespace
@@ -50,17 +51,15 @@ namespace
std::copy(data.begin(), data.end(), std::ostream_iterator<unsigned char>(ofs));
}
- size_t SearchOffset (std::vector<unsigned char> const& binary, std::vector<unsigned char> const& pattern)
+ std::set<size_t> SearchOffset (std::vector<unsigned char> const& binary, std::vector<unsigned char> const& pattern)
{
- for (size_t i = 0; i < binary.size(); i++)
+ std::set<size_t> offsets;
+ for (size_t i = 0; (i + pattern.size()) < binary.size(); i++)
{
size_t matches = 0;
for (size_t j = 0; j < pattern.size(); j++)
{
- if (pattern.size() > (binary.size() - i))
- throw std::runtime_error("unable to find pattern");
-
if (pattern[j] == 0)
{
matches++;
@@ -74,10 +73,13 @@ namespace
}
if (matches == pattern.size())
- return i;
+ {
+ offsets.insert(i);
+ i += matches;
+ }
}
- throw std::runtime_error("unable to find pattern");
+ return offsets.empty() ? throw std::runtime_error("unable to find pattern") : offsets;
}
}
@@ -96,12 +98,14 @@ namespace Connection_Patcher
if (pattern.empty())
return;
- size_t const offset(SearchOffset(binary, pattern));
- std::cout << "Found offset " << offset << std::endl;
+ for (size_t const offset : SearchOffset(binary, pattern))
+ {
+ std::cout << "Found offset " << offset << std::endl;
- if (offset != 0 && binary.size() >= bytes.size())
- for (size_t i = 0; i < bytes.size(); i++)
- binary[offset + i] = bytes[i];
+ if (offset != 0 && binary.size() >= bytes.size())
+ for (size_t i = 0; i < bytes.size(); i++)
+ binary[offset + i] = bytes[i];
+ }
}
void Patcher::Finish(boost::filesystem::path out)