#include <windows.h>
#include <iostream>
#include <unordered_map>
#include <fstream>
#include <string>
// Function to inject DLL
bool InjectDLL(DWORD processID, const std::string& dllPath) {
// Open the target process
HANDLE hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, processID);
if (hProcess == NULL) {
std::cerr << "Failed to open target process." << std::endl;
return false;
}
// Allocate memory in the target process for the DLL path
void* pRemoteDllPath = VirtualAllocEx(hProcess, NULL, dllPath.size() + 1, MEM_COMMIT, PAGE_READWRITE);
if (pRemoteDllPath == NULL) {
std::cerr << "Failed to allocate memory in target process." << std::endl;
CloseHandle(hProcess);
return false;
}
// Write the DLL path into the allocated memory
if (!WriteProcessMemory(hProcess, pRemoteDllPath, dllPath.c_str(), dllPath.size() + 1, NULL)) {
std::cerr << "Failed to write DLL path into target process memory." << std::endl;
VirtualFreeEx(hProcess, pRemoteDllPath, 0, MEM_RELEASE);
CloseHandle(hProcess);
return false;
}
// Get the address of LoadLibraryA in kernel32.dll
HMODULE hKernel32 = GetModuleHandle(L"kernel32.dll");
if (hKernel32 == NULL) {
std::cerr << "Failed to get handle of kernel32.dll." << std::endl;
VirtualFreeEx(hProcess, pRemoteDllPath, 0, MEM_RELEASE);
CloseHandle(hProcess);
return false;
}
FARPROC pLoadLibraryA = GetProcAddress(hKernel32, "LoadLibraryA");
if (pLoadLibraryA == NULL) {
std::cerr << "Failed to get address of LoadLibraryA." << std::endl;
VirtualFreeEx(hProcess, pRemoteDllPath, 0, MEM_RELEASE);
CloseHandle(hProcess);
return false;
}
// Create a remote thread in the target process to call LoadLibraryA with the DLL path as an argument
HANDLE hRemoteThread = CreateRemoteThread(hProcess, NULL, 0, (LPTHREAD_START_ROUTINE)pLoadLibraryA, pRemoteDllPath, 0, NULL);
if (hRemoteThread == NULL) {
std::cerr << "Failed to create remote thread in target process." << std::endl;
VirtualFreeEx(hProcess, pRemoteDllPath, 0, MEM_RELEASE);
CloseHandle(hProcess);
return false;
}
// Wait for the remote thread to finish
WaitForSingleObject(hRemoteThread, INFINITE);
// Cleanup
VirtualFreeEx(hProcess, pRemoteDllPath, 0, MEM_RELEASE);
CloseHandle(hRemoteThread);
CloseHandle(hProcess);
return true;
}
std::unordered_map<std::string, int> loadConfig(const std::string& filename) {
std::unordered_map<std::string, int> config;
std::ifstream file(filename);
std::string line;
if (!file) {
std::cerr << "Error: Cannot open config file!\n";
return config;
}
while (std::getline(file, line)) {
size_t pos = line.find('=');
if (pos != std::string::npos) {
std::string key = line.substr(0, pos);
int value = std::stoi(line.substr(pos + 1));
config[key] = value;
}
}
return config;
}
int main() {
// Sleep(200);
std::cout << "Preparing process for injection can take a while please be patient and do not touch anything!!" << std::endl;
// Start the target process
STARTUPINFO si = { sizeof(si) };
PROCESS_INFORMATION pi;
if (!CreateProcess(L"FurryVNE.exe", NULL, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) {
std::cerr << "Failed to start target process." << std::endl;
return 1;
}
auto config = loadConfig("VNEConfig.txt");
// Inject the DLL
int sleeptime = 4000;
if (config.find("timming-adjust") != config.end()) {
sleeptime = config["timming-adjust"];
std::cout << "timming-adjust: " << sleeptime << "ms\n";
}
else {
std::cerr << "Key 'timming-adjust' not found in config!\n";
}
Sleep(sleeptime);
std::cout << "injecting Black magic into process please wait !!" << std::endl;
while (!InjectDLL(pi.dwProcessId, "VNEDLL.dll")) {
std::cerr << "DLL injection failed retry in 500ms." << std::endl;
return 1;
}
std::cout << "DLL injection successful." << std::endl;
// Cleanup
CloseHandle(pi.hThread);
CloseHandle(pi.hProcess);
return 0;
}