Показать сообщение отдельно

  #7  
Старый 02.02.2008, 16:00
criz
Постоянный
Регистрация: 04.11.2007
Сообщений: 303
С нами: 9746420

Репутация: 119
По умолчанию

Товарищи, поможите мну =)
Я делаю инжект в чужой процесс. Длл-ка не хочет выполнять работу =(
Код взял у Рихтера(немного изменил):
sh.dll:
Код:
#include <windows.h>
#include <tchar.h>

void chMB(PCSTR s);

#define chDIMOF(Array) (sizeof(Array) / sizeof(Array[0]))



BOOL WINAPI DllMain(HINSTANCE hinstDll, DWORD fdwReason, PVOID fImpLoad) {

   if (fdwReason == DLL_PROCESS_ATTACH) {
      char szBuf[MAX_PATH * 100] = { 0 };

      PBYTE pb = NULL;
      MEMORY_BASIC_INFORMATION mbi;
      while (VirtualQuery(pb, &mbi, sizeof(mbi)) == sizeof(mbi)) {

         int nLen;
         char szModName[MAX_PATH];

         if (mbi.State == MEM_FREE)
            mbi.AllocationBase = mbi.BaseAddress;

         if ((mbi.AllocationBase == hinstDll) ||
             (mbi.AllocationBase != mbi.BaseAddress) ||
             (mbi.AllocationBase == NULL)) {
            // Do not add the module name to the list
            // if any of the following is true:
            // 1. If this region contains this DLL
            // 2. If this block is NOT the beginning of a region
            // 3. If the address is NULL
            nLen = 0;
         } else {
            nLen = GetModuleFileNameA((HINSTANCE) mbi.AllocationBase, 
               szModName, chDIMOF(szModName));
         }

         if (nLen > 0) {
            wsprintfA(strchr(szBuf, 0), "\n%p-%s", 
               mbi.AllocationBase, szModName);
         }

         pb += mbi.RegionSize;
      }

      chMB(&szBuf[1]);
   }

   return(TRUE);
}


void chMB(PCSTR s) {
   char szTMP[128];
   GetModuleFileNameA(NULL, szTMP, chDIMOF(szTMP));
   MessageBoxA(GetActiveWindow(), s, szTMP, MB_OK);
}
inj.c:
Код:
BOOL inj(DWORD dwProcId)
{
	BOOL res = FALSE;
	HANDLE hProcess, hThread;
	PWSTR psRemFile;
	PTHREAD_START_ROUTINE pThRtn;
	int len;
	char lbFileName[] = "sh.dll";

	//FreeConsole();

	hProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwProcId);
	if(!hProcess)
	{
		MessageBox(NULL, "Sorry, I can't open process", "Error", 0);
		return 0;
	}
	
	len = (strlen(lbFileName) + 1) * sizeof(WCHAR);

	psRemFile = (PWSTR) VirtualAllocEx(hProcess, NULL, len, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
	if(psRemFile == NULL)
	{
		MessageBox(NULL, "Sorry, I can't allocating memory", "Error", 0);
		return 0;
	}
	if(!WriteProcessMemory(hProcess, psRemFile, (PVOID) lbFileName, len, NULL))
	{
		MessageBox(NULL, "Sorry, I can't write in memory", "Error", 0);
		return 0;
	}
	
	pThRtn = (PTHREAD_START_ROUTINE) GetProcAddress(GetModuleHandle(TEXT("Kernel32")), "LoadLibraryW");
	if(!pThRtn)
	{
		MessageBox(NULL, "Sorry, I can't find process", "Error", 0);
		return 0;
	}

	hThread = CreateRemoteThread(hProcess, NULL, 0, pThRtn, psRemFile, 0, NULL);
	if(!hThread)
	{
		MessageBox(NULL, "Sorry, I can't create thread", "Error", 0);
		return 0;
	}
	
	WaitForSingleObject(hThread, INFINITE);
	res = TRUE;

	/*--------------------------------*/
	return res;
}
После инжекта должно вываливаться окошко со списком длл-ок процесса, в который инжектимся.
 
Ответить с цитированием