Comments (4)
@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.
just hook GetModuleFileName
to get this work.
from memorymodule.
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.
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)
- Create Activation Context Implementation (with code)
- Bug results in crash when loading some DLLs. (with code fix!) HOT 4
- Starting Calc.exe fails (partial fix with code) HOT 2
- PDB Files Not Loaded for DLL's
- running the FARPROC type function fails
- Memory on kernel
- can MemoryCallEntryPoint accept parameters? just like a command line with parameters?
- c# compiled exe load supported ? HOT 1
- 64-bit DLL compiled by G++ failed to load. HOT 1
- cannot load DLL that use OpenSSL? HOT 2
- Link with dllloader
- new failed to allocate memory
- BUG in FinalizeSection
- .pyd files from Python - MemoryModule HOT 5
- Use Unicode version of LoadLibrary HOT 2
- Support for VirtualMachine Libraries
- Can not use CString in vs2015 and newer version , it seems like dynamiclly load Thread Local Storage can not be supported in MemmoryModule??
- Creation of Rust bindings
- MemoryGetProcAddress fails to import a function by ordinal number if dll has no exported names HOT 1
- Need to use it in C# with and unmanaged dll HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from memorymodule.