[Source Code] โค้ด Inject C++










#include <windows.h>
#include <tlhelp32.h>
#include <shlwapi.h>
#include <conio.h>
#include <stdio.h>


#define WIN32_LEAN_AND_MEAN
#define CREATE_THREAD_ACCESS (PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_OPERATION | PROCESS_VM_WRITE | PROCESS_VM_READ

BOOL CreateRemoteThreadInject(DWORD ID, const char * dll);


DWORD GetProcessId(IN PCHAR szExeName);


int main()

{

char dll[10];

//ชื่อไฟล์ .dll
GetFullPathName("D3D9_Logger.dll", MAX_PATH, dll, NULL);

// Show the .DLL Path.
//printf("DLL : ");
//printf(dll);
//printf("\n\n\n");

// Proecss Name
DWORD ID = GetProcessId("D3D9_test.exe");
if (!CreateRemoteThreadInject(ID, dll))
{

printf("Injection failed!");
Sleep(3000);
exit(1);


}
else
{

printf("Injection Successful!");
Sleep(3000);
exit(1);


}
return 0;
}

DWORD GetProcessId(IN PCHAR szExeName)

{
DWORD dwRet = 0;
DWORD dwCount = 0;

HANDLE hSnapshot = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);

if (hSnapshot != INVALID_HANDLE_VALUE)
{
PROCESSENTRY32 pe = { 0 };
pe.dwSize = sizeof(PROCESSENTRY32);

BOOL bRet = Process32First(hSnapshot, &pe);

while (bRet)
{
if (!_stricmp(pe.szExeFile, szExeName))
{
dwCount++;
dwRet = pe.th32ProcessID;
}
bRet = Process32Next(hSnapshot, &pe);
}

if (dwCount > 1)
dwRet = 0xFFFFFFFF;

CloseHandle(hSnapshot);
}

return dwRet;
}


BOOL CreateRemoteThreadInject(DWORD ID, const char * dll)

{

HANDLE Process;


LPVOID Memory;


LPVOID LoadLibrary;


if (!ID)
return false;


Process = OpenProcess(PROCESS_CREATE_THREAD | PROCESS_QUERY_INFORMATION | PROCESS_VM_READ | PROCESS_VM_WRITE | PROCESS_VM_OPERATION, FALSE, ID);


LoadLibrary = (LPVOID)GetProcAddress(GetModuleHandle("kernel32.dll"), "LoadLibraryA");


Memory = (LPVOID)VirtualAllocEx(Process, NULL, strlen(dll), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);


WriteProcessMemory(Process, (LPVOID)Memory, dll, strlen(dll), NULL);


CreateRemoteThread(Process, NULL, NULL, (LPTHREAD_START_ROUTINE)LoadLibrary, (LPVOID)Memory, NULL, NULL);


CloseHandle(Process);

VirtualFree((LPVOID)Memory, strlen(dll), NULL);

return true;
}

ความคิดเห็น

โพสต์ยอดนิยมจากบล็อกนี้

Naruto Shippuden: Ultimate Ninja Storm 3