Giter VIP home page Giter VIP logo

Comments (4)

thiekus avatar thiekus commented on July 25, 2024 2

@tommy8421 @mw7536 I have been successfully load MFC dll library just like lynnux pointed. Basically you just hook GetModuleFileNameA or GetModuleFileNameW for the Unicode one to use main module path instead. Here's my example:

static HMODULE kernelHModule = 0;

static DWORD WINAPI HookGetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize) {
	DWORD result = GetModuleFileNameA(hModule, lpFilename, nSize);
	if (result == 0)
		result = GetModuleFileNameA(0, lpFilename, nSize);
	return result;
}

static FARPROC CustomGetProcAddress(HCUSTOMMODULE module, LPCSTR name, void *userdata) {
	UNREFERENCED_PARAMETER(userdata);
	FARPROC proc;
	if ((module == kernelHModule) && ((DWORD)name > 0xffff) && (strcmp(name, "GetModuleFileNameA") == 0)) {
		proc = (FARPROC)HookGetModuleFileNameA;
	}
	else {
		proc = (FARPROC)GetProcAddress((HMODULE)module, name);
	}
	return proc;
}

This one if your MFC dll is Ansi, for Unicode, you can replace GetModuleFileNameA with GetModuleFileNameW and LPSTR lpFilename with LPWSTR lpFilename. Then you just load with MemoryLoadLibraryEx with custom CustomGetProcAddress like this:

kernelHModule = GetModuleHandle("kernel32.dll");
hinstDll = MemoryLoadLibraryEx(dllData, dllSize, MemoryDefaultAlloc, MemoryDefaultFree, MemoryDefaultLoadLibrary, CustomGetProcAddress, MemoryDefaultFreeLibrary, NULL);

from memorymodule.

lynnux avatar lynnux commented on July 25, 2024

just hook GetModuleFileName to get this work.

from memorymodule.

mw7536 avatar mw7536 commented on July 25, 2024

Hooked GetModuleFileName, and see that an empty string is being returned for my MFC dll loaded by MemoryLoadFile, but I don't see what to do in my hooking function. I also suspect additional problems with this Unicode MFC dll due to Unicode. Anybody tried that?

from memorymodule.

Elmue avatar Elmue commented on July 25, 2024

May be your code solves the problem. But it is a drity workaround.
It is wrong to return the path to the EXE file when the caller wants the path to the DLL.
There will be cases where this does not work.

from memorymodule.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.