Skip to content

Commit

Permalink
make sure random types are never used twice
Browse files Browse the repository at this point in the history
  • Loading branch information
koemeet committed May 3, 2017
1 parent 3b9673e commit ad45866
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
3 changes: 2 additions & 1 deletion RTTIObfuscator.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,10 @@
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="main.cpp" />
<ClCompile Include="src\main.cpp" />
</ItemGroup>
<ItemGroup>
<None Include=".gitignore" />
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
Expand Down
9 changes: 5 additions & 4 deletions RTTIObfuscator.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<None Include="packages.config" />
<None Include=".gitignore" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<ClCompile Include="src\main.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
16 changes: 13 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
#include <random>
#include <time.h>
#include <cstdlib>
#include <unordered_set>

#include <boost/regex.hpp>
#include <boost/filesystem.hpp>

using namespace std;

std::vector<std::string> usedTypeNames;
std::unordered_set<std::string> usedTypeNames;

std::string getRandomString(const int len) {
static const char alpha[] =
Expand Down Expand Up @@ -80,9 +81,18 @@ int main(int argc, char* argv[])
auto prefix = m[1].str();
auto typeName = m[2].str();

reverse(typeName.begin(), typeName.end());
// generate the new type name for the current rtti entry
auto newTypeName = getRandomString(typeName.size());

return "." + prefix + getRandomString(typeName.size()) + "@@";
// get a new random name untill we have one we never used before
while (usedTypeNames.find(newTypeName) != usedTypeNames.end())
{
newTypeName = getRandomString(typeName.size());
}

usedTypeNames.emplace(newTypeName);

return "." + prefix + newTypeName + "@@";
});

// generate output path
Expand Down

0 comments on commit ad45866

Please sign in to comment.