-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.cpp
191 lines (152 loc) · 5.07 KB
/
main.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
* main.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 "DFMParser.h"
#include "VmtDir.h"
#include "helpers.h"
#include "obfuscate.h"
#include "write.h"
#include "sync.h"
#include <cstdlib>
#include <iostream>
#include <string>
#include <fstream>
#include <ctime>
#include <map>
#include <iomanip>
#include <PeLib.h>
extern unsigned int g_recognizedVmts;
void printUsage()
{
std::cout << "Usage: pythia.exe [options] file\n\n";
std::cout << "Options:\n";
std::cout << " -i Prints information about the file (does not modify the file)\n";
std::cout << " -c Show changes (Prints the obfuscated strings)\n";
}
void printStats()
{
std::cout << "Recognized VMTs: " << g_recognizedVmts << "\n\n";
}
void printVMT(const VMT* vmt, std::string pad = "")
{
std::cout << pad << "Name: " << *vmt->name << "\n";
std::cout << pad << "Offset: 0x" << std::uppercase << std::hex << vmt->offset << "\n";
std::cout << pad << "Properties: " << std::dec << vmt->typeinfo.size() << "\n";
for (unsigned int i=0;i<vmt->typeinfo.size();i++)
{
std::cout << pad << " " << *vmt->typeinfo[i].type << " " << *vmt->typeinfo[i].name << "\n";
std::cout << pad << " GetProc: " << std::hex << vmt->typeinfo[i].GetProc << "\n";
std::cout << pad << " SetProc: " << std::hex << vmt->typeinfo[i].SetProc << "\n";
std::cout << pad << " StoredProc: " << std::hex << vmt->typeinfo[i].StoredProc << "\n";
}
std::cout << pad << "Methods: " << std::dec << vmt->methods.size() << "\n";
for (unsigned int i=0;i<vmt->methods.size();i++)
{
std::cout << pad << " Name: " << *vmt->methods[i].name << " ( 0x" << std::hex << vmt->methods[i].va << " )\n";
}
std::cout << pad << "Fields: " << std::dec << vmt->fields.size() << "\n";
for (unsigned int i=0;i<vmt->fields.size();i++)
{
std::cout << pad << " Name: " << *vmt->fields[i].name << "\n";
}
std::cout << "\n";
for (unsigned int i=0;i<vmt->children.size();i++)
printVMT(vmt->children[i], pad + " ");
}
void printDfm(DFMResource* dfm, std::string pad = "")
{
std::cout << pad << *dfm->classname << " " << *dfm->name << "\n";
std::cout << pad << "Properties: " << std::dec << dfm->properties.size() << "\n";
for (unsigned int i=0;i<dfm->properties.size();i++)
{
for (unsigned int j=0;j<dfm->properties[i].name.size();j++)
{
std::cout << pad << " " << *dfm->properties[i].name[j] << "\n";
}
// for (unsigned int j=0;j<dfm->properties[i].value.size();j++)
// {
// std::cout << pad << " " << *dfm->properties[i].value[j] << "\n";
// }
}
std::cout << "\n";
for (unsigned int i=0;i<dfm->children.size();i++)
printDfm(dfm->children[i], pad + " ");
}
bool printInformation = false;
bool showChanges = false;
int main(int argc, char *argv[])
{
std::cout << "Pythia 1.1 - Author: Sebastian Porst ([email protected])\n\n";
srand(static_cast<unsigned int>(time(0)));
if (argc < 2)
{
printUsage();
return 1;
}
for (int i=1;i<argc - 1;i++)
{
if (!strcmp(argv[i], "-i"))
printInformation = true;
if (!strcmp(argv[i], "-c"))
showChanges = true;
}
if ( printInformation && showChanges )
{
die("-i and -c are mutually exclusive");
}
std::string filename = argv[argc - 1];
PeLib::PeFile32 pefile(filename);
if (pefile.readMzHeader() == 0 && pefile.readPeHeader() == 0 && pefile.readResourceDirectory() == 0)
{
VMTDir vmtdir;
readVMTs(pefile, vmtdir);
printStats();
if ( printInformation )
{
for (std::vector<VMT*>::iterator Iter = vmtdir.begin(); Iter != vmtdir.end(); ++Iter)
{
printVMT(*Iter);
}
// std::for_each(vmtdir.begin(), vmtdir.end(), printVMT);
}
DFMData dfmresources;
try
{
readDFMResources(pefile, dfmresources);
if ( printInformation )
{
std::cout << "Recognized DFMs\n\n";
for (std::vector<DFMResource*>::iterator Iter = dfmresources.begin(); Iter != dfmresources.end(); ++Iter)
{
printDfm(*Iter);
}
// std::for_each(dfmresources.begin(), dfmresources.end(), printDfm);
}
else
{
synchronize(dfmresources, vmtdir);
obfuscate(dfmresources, vmtdir);
store(filename, dfmresources, vmtdir, pefile);
}
}
catch(const std::string& e)
{
die(e);
}
if ( !printInformation )
{
std::cout << "Everything seems to have worked. Try to start the obfuscated file now." << std::endl;
}
return EXIT_SUCCESS;
}
else
{
die("Error: File does not seem to be a valid Delphi file.");
}
}