Want to write a this function,
Has been written to relocation table that place,
Next, if just ready to call a function, only need to access the DLL's exported functions, of course I haven't write here,
But I want to ask the question is not in the application of DLL export tables,
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
But about the DLL import table, namely dependence,
About this problem I wanted to think: loadlibrary when loading program may check the import table, find dependent DLLS and so on, and then one by one all loaded into memory, estimates that in the process of the kernel in the nature of the list of the modules, trying to loadlibrary behind the same module is not repeated load,
But I if their implementation?
if I import the DLL rely on the socket. The DLL, how to determine whether the current application has loaded the socket. The DLL
socket. The DLL is system libraries, and may be high in the address space, you can think of is to call loadlibrary, it feels like the use of A, in the process of creating A
if I import the DLL rely on a. d. ll, how to determine whether the current application has loaded the a. d. ll
a. d. ll obviously is not a system library, I can think of way is to turn the pages of scanning the entire 0 ~ 0 x800000 this memory? There is no more appropriate way?
Thank you
CodePudding user response:
Reference:
PBYTE pb=NULL;
A MEMORY_BASIC_INFORMATION mbi.
While (VirtualQuery (pb, & amp; 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, _countof (szModName));
}
//if (nLen & gt; 0 {
//wsprintfA (STRCHR (szBuf, 0), "\ n % p - % s",
//mbi. AllocationBase szModName);
//}
Pb +=mbi. RegionSize;
}
CodePudding user response:
Can also use GetModuleHandle (dllName) to judge did a DLL is loaded, but it and what is the difference between using loadlibrary,,, but that's just tricky,,Whether it's on the first floor said method or GetModuleHandle traversal to or get module premise is PEB module has been loaded into the correct process list (all HMODULE related API is certainly won't be able to work), and if you write their own loadlibrary that to properly deal with this step I feel quite complicated,,,
I also write their own loadlibrary before, but after the load is at best a memory module, API is unable to work, such as the GetModuleFileName
Since you also want to achieve, meaning also should just want to deepen understanding, it is better not to use other apis, such as recursive call themselves achieve loadlibrary, then their management reference counting (counting their implementation loadlibrary load module) and don't need to go to tube system orthodox load module exactly have been loaded, anyway have reached the purpose of your study,