-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
70 lines (53 loc) · 1.95 KB
/
main.cpp
File metadata and controls
70 lines (53 loc) · 1.95 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
#include <filesystem>
#include <fstream>
#include <iostream>
#include "src/misc/misc.h"
int main(int argc, char* argv[]) {
char full_dll_path[MAX_PATH];
std::string dll_path = argv[1];
std::string process_name = argv[2];
if (!std::filesystem::exists(dll_path)) {
std::cout << dll_path << " does not exist" << std::endl;
}
GetFullPathNameA(dll_path.c_str(), MAX_PATH, full_dll_path, nullptr);
auto proc_id = misc::get_process_id(process_name);
if (!proc_id.has_value()) {
std::cout << "Notepad is not open." << std::endl;
return 1;
}
HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, false, proc_id.value());
if (handle == nullptr) {
std::cout << "Failed to open a Handle." << std::endl;
return 1;
}
auto alloced_mem = VirtualAllocEx(handle, nullptr, strlen(full_dll_path), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
if (alloced_mem == nullptr) {
std::cout << "Failed to allocate memory." << std::endl;
CloseHandle(handle);
return 1;
}
if (!WriteProcessMemory(handle, alloced_mem, full_dll_path, strlen(full_dll_path), nullptr)) {
std::cout << "Failed to Write dll path." << std::endl;
CloseHandle(handle);
return 1;
}
auto kernel32 = GetModuleHandleA("kernel32.dll");
if (kernel32 == nullptr) {
std::cout << "Failed to get kernel32.dll" << std::endl;
CloseHandle(handle);
return 1;
}
auto loadlibrarya = GetProcAddress(kernel32, "LoadLibraryA");
if (loadlibrarya == nullptr) {
std::cout << "Failed to Write dll path." << std::endl;
CloseHandle(handle);
return 1;
}
if (CreateRemoteThread(handle,nullptr, 0, (LPTHREAD_START_ROUTINE)loadlibrarya, alloced_mem, 0, nullptr) == nullptr) {
std::cout << "Failed to create remote thread." << std::endl;
CloseHandle(handle);
return 1;
}
CloseHandle(handle);
return 0;
}