-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathobfuscate.cpp
72 lines (57 loc) · 1.74 KB
/
obfuscate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* obfuscate.cpp - Proof of concept for a Delphi Obfuscator
*
* Copyright (c) 2005 Sebastian Porst ([email protected])
* All rights reserved.
*
* This software is licensed under the zlib/libpng License.
* For more details see http://www.opensource.org/licenses/zlib-license.php
*/
#include "obfuscate.h"
#include "helpers.h"
#include <algorithm>
/**
* Replaces the name element of object x with a random string.
* @param x The object with the name element.
**/
template<typename T>
void obfuscate(T& x)
{
extern bool showChanges;
std::string newvalue = uniqueString<RandomCharacterGenerator>(static_cast<unsigned int>(x.name->length()));
if ( showChanges )
{
std::cout << *x.name << " -> " << newvalue << "\n";
}
*x.name = newvalue;
}
/**
* Obfuscates the DFM and VMT data of a Delphi file.
* @param dfmres The DFM data of an entire Delphi file.
* @param vmtdir The VMT data of an entire Delphi file.
**/
void obfuscate(DFMData& dfmres, VMTDir& vmtdir)
{
std::deque<VMT*> vmts;
fill(vmtdir, vmts);
extern bool showChanges;
if ( showChanges )
{
std::cout << "Obfuscated strings: \n\n";
}
for (std::deque<VMT*>::iterator Iter = vmts.begin(); Iter != vmts.end(); ++Iter)
{
if (!isTopElement(dfmres, *(*Iter)->name)) obfuscate<VMT>(**Iter);
std::for_each((*Iter)->typeinfo.begin(), (*Iter)->typeinfo.end(), obfuscate<PropInfo>);
std::for_each((*Iter)->fields.begin(), (*Iter)->fields.end(), obfuscate<FieldInfo>);
std::for_each((*Iter)->methods.begin(), (*Iter)->methods.end(), obfuscate<MethodInfo>);
}
for (unsigned int i=0;i<dfmres.size();++i)
{
obfuscate<DFMResource>(*dfmres[i]);
}
if ( showChanges )
{
std::cout << "\n";
}
}