-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
46 lines (39 loc) · 1 KB
/
Copy pathtest.cpp
File metadata and controls
46 lines (39 loc) · 1 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
#include "peImage.h"
#include <iostream>
#include <memory>
int main()
{
_getFilePath:
std::string filePath;
std::cout << "[+] File Path: ";
std::cin >> filePath;
if (!FileManager::IsExist(filePath))
{
std::cout << "[-] File does not exist." << std::endl;
goto _getFilePath;
}
auto fileBuffer = FileManager::ReadBuffer(filePath);
if (fileBuffer.empty())
{
std::cout << "[-] The size of file is 0." << std::endl;
goto _getFilePath;
}
auto pe = std::make_shared<PEImage>(fileBuffer);
if (!pe->IsValid())
{
std::cout << "[-] The PE of file is invalid." << std::endl;
goto _getFilePath;
}
std::vector<std::uint8_t> testSection(0x1000, 0x00);
pe->AddSection(".test1", testSection);
auto newFilePath = filePath;
size_t pos = newFilePath.rfind(".exe");
if (pos != std::string::npos)
{
newFilePath.replace(pos, 4, "_new.exe");
}
pe->CompileTo(newFilePath);
std::cout << "[+] Build: " << newFilePath << std::endl;
system("pause");
return 0;
}