HelpDll whichs inject a Dll.

Posts 1–5 of 5 · Page 1 of 1
Dll whichs inject a Dll.
Hello.

I try with this to create a dll which should inject another dll:

Code:
#include "windows.h"
#include <iostream>

using namespace std;

char const Path[]="blah.dll";

int main(int argc, char* argv)
{
    HANDLE hWnd, hProcess, AllocAdresse, hRemoteThread;
    DWORD PID;

    hWnd = FindWindow(0,"nnjij");
    GetWindowThreadProcessId((HWND)hWnd, &PID);
    
    hProcess = OpenProcess(PROCESS_ALL_ACCESS, false, PID);

    AllocAdresse = VirtualAllocEx(hProcess, 0, sizeof(Path), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
    WriteProcessMemory(hProcess, (void*)AllocAdresse, (void*)Path, sizeof(Path), 0);
    hRemoteThread=CreateRemoteThread(hProcess, 0, 0, (LPTHREAD_START_ROUTINE) GetProcAddress(GetModuleHandle("kernel32.dll"),"LoadLibraryA"), AllocAdresse, 0, 0);
    
    WaitForSingleObject(hRemoteThread, INFINITE);

    VirtualFreeEx(hProcess, AllocAdresse, sizeof(Path), MEM_DECOMMIT);
    CloseHandle(hProcess);
}
But i just got some errors on compiling:



I am not good at c++ so i dont know whats wrong with it :/
Project -> Properties -> Configuration Properties -> Character set -> Change it to Multibyte

Do you want to load it into the same process?
Quote Originally Posted by Biesi View Post
Project -> Properties -> Configuration Properties -> Character set -> Change it to Multibyte

Do you want to load it into the same process?

Yes.

Cause when i load the dll direct on startup, it crash. But when i inject the dll with a Injector it works fine. But i want it automatically, so i need a dll which injects another dll.

But don't work with this Code..
In which case no need to inject, just load the image.
irrelevant, but I think the compiler error would be fixed with a cast?

(LPCWSTR) yourVariable

ie.
SomeFunction( , (LPCWSTR)yourVariable, , );
or
*** = (LPCWSTR)yourVariable;


"lpcw" stands for "Long Pointer [to] Const Wide-string" (ie. const * to unicode string) and should be castable from a char *, I think.


 
text version of above

Code:
#include <Windows.h>
#include <iostream>

    int main()
    {
		//Convert a const char* into a LPCWSTR
		const char *p = "hello world";
		LPCWSTR str = (LPCWSTR)p;

		std::cout << "  p: " << (void*)p << "\n"
			  << "str: " << str << "\n" << std::endl;
		//Convert a LPCWSTR into a const char*
		LPCWSTR x = L"hello world";
		const char *y = (char*)x;

		std::cout <<"  x: " << x << "\n"
		          <<"  y: " << (void*)y << std::endl;
	

      return 0;
    }
Posts 1–5 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Talk with us