Dll Eject Help

  • Thread starter Thread starter Yordy Corrales
  • Start date Start date
Y

Yordy Corrales

Guest
Hi,

Hi have this code in c++:

//Open the process with read , write and execute priviledges
auto Process = OpenProcess(PROCESS_ALL_ACCESS, FALSE, ID);
auto hh = GetModuleHandle(L"kernel32.dll");
//Get the address of LoadLibraryA
auto LoadLibraryx = GetProcAddress(hh, "LoadLibraryA");

// Allocate space in the process for our DLL
auto Memory = VirtualAllocEx(Process, nullptr, strlen(dll), MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);

// Write the string name of our DLL in the memory allocated
auto y=WriteProcessMemory(Process, Memory, dll, strlen(dll), nullptr);

// Load our DLL
auto hThreadId =CreateRemoteThread(Process, nullptr, 0, reinterpret_cast<LPTHREAD_START_ROUTINE>(LoadLibraryx), Memory, NULL, nullptr);
auto z = GetLastError();
WaitForSingleObject(hThreadId, INFINITE);

auto b = FreeLibrary(GetModuleHandleA((const char*)Memory));

CloseHandle(Process);

//auto u = FreeLibrary();

//Lets free the memory we are not using anymore.
VirtualFreeEx(Process, (LPVOID)Memory, 0, MEM_RELEASE);


but it fails in the line "auto b = FreeLibrary(GetModuleHandleA((const char*)Memory));" it says: "Unhandled exception at 0x00007FFAA032DC26 (ntdll.dll) in app.exe: 0xC0000005: Access violation reading location 0x000002E55ED80000."

Please, Someone can help me to know how can I eject a DLL with an example?

Best Regards,


Yordy Corrales

Continue reading...
 
Back
Top