Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Windows.h>
- #include <iostream>
- int main() {
- const char* processPath = "C:\\Path\\To\\Your\\Process.exe";
- STARTUPINFOA startupInfo;
- PROCESS_INFORMATION processInfo;
- ZeroMemory(&startupInfo, sizeof(startupInfo));
- startupInfo.cb = sizeof(startupInfo);
- ZeroMemory(&processInfo, sizeof(processInfo));
- // Create the suspended process
- if (!CreateProcessA(
- NULL,
- (LPSTR)processPath,
- NULL,
- NULL,
- FALSE,
- CREATE_SUSPENDED,
- NULL,
- NULL,
- &startupInfo,
- &processInfo
- ))
- {
- std::cerr << "Failed to create the process: " << GetLastError() << std::endl;
- return 1;
- }
- // Process handle
- HANDLE hProcess = processInfo.hProcess;
- // Get the base address of the main module (executable) of the process
- HMODULE hModule = NULL;
- if (!EnumProcessModules(hProcess, &hModule, sizeof(hModule), NULL)) {
- std::cerr << "Failed to get the process module: " << GetLastError() << std::endl;
- return 1;
- }
- // Calculate the memory address to modify (example: modify the first integer in the process's memory)
- uintptr_t baseAddress = (uintptr_t)hModule;
- int newValue = 999;
- // Write the new value to the process's memory
- if (!WriteProcessMemory(hProcess, (LPVOID)baseAddress, &newValue, sizeof(newValue), NULL)) {
- std::cerr << "Failed to write to process memory: " << GetLastError() << std::endl;
- return 1;
- }
- // Resume the process and allow it to run
- if (ResumeThread(processInfo.hThread) == -1) {
- std::cerr << "Failed to resume the process: " << GetLastError() << std::endl;
- return 1;
- }
- // Close process and thread handles
- CloseHandle(processInfo.hThread);
- CloseHandle(processInfo.hProcess);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement