-
-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Manual Map issue #173
Comments
As I can see they use DllMain like |
Thank you for responding, I want to elaborate is I may I modified MemoryModulePP library (and others) to supposedly successfully map the dll in memory, namely I removed the dllentry call and commented out this check
` which provided a valid base address/return. Then used their export function "MemoryGetProcAddress" to get the export from the C# dll I want to call, and that's where things crash. The address appears valid, The debugger says it crashes somewhere in mscoree.dll. I also tried the old school method of loading the clr like you mentioned before doing the above
that didn't do much. So my question is what is LoadLibrary doing that these mapping librabries aren't that's making loading the C# dll unsuccessful? They're
and is there a way I can preload the CLR or do anything to avoid having to load from disk first(or use LoadLibrary for that matter) ? Thanks |
Guess not, ok thank you for share and project, have good day. |
Not sure about completeness for the mentioned equivalent to the LoadLibrary(), and unfortunately I don't have time/health to review it today, but first of all, RVAs in export table will point exactly to export stubs --> that points to --> v-table slots ! Each slot contains method token which will be replaced with the address of a marshaling point providing unmanaged entry to managed method. All this must be processed with actual addresses at runtime. What about unmanaged starter for CLR, It must be located in .text section where vtfixup, that is ~
Its RVA should be assigned to PE AddressOfEntryPoint and my highlights above looks correct: ((DllEntryProc)(LPVOID)(code + result->headers->OptionalHeader.AddressOfEntryPoint)) @frostiest, but as I voiced, you need init CLR ~"environment" (I do not mean clr hosting way like from your "old school" example above, it's different to the task) before processing/calculating related to it. Also note v-table should be located in other .sdata section because of RW |
@frostiest I'm not sure what exactly you're doing, but suspect easiest approach would be to make small C# library "loader", which in a turn would use Assembly.Load and perform assembly loading from ram - I guess this is equivalent to C++ MemoryModulePP. This approach however will not work on all assemblies - some assemblies might need to be loaded from disk in order to work. I'm also not sure about debugging of such in-ram loaded dll's, as debugger will not be aware of any newly loaded dll unless you explicitly specify it somehow to debugger. But I'm actually interested on what you want to achieve and what was the last problem. I by myself want to fully release .net framework assembly without any good result. Don't understand why there aren't any FreeLibrary for C#. I've slightly played around with .net core - situation seems to be better, but I haven't yet tried C++ / mixed mode clr dlls. Can you tell me bit more on where you've ended up with your experiments ? |
Btw, MemoryModulePP perform something similar to https://github.com/nickcano/ReloadLibrary One approach is to actually allow PE loader perform what it wants to perform, but intercept windows API calls, like LoadLibrary, GetProcAddress, FreeLibrary to manually control what you do with these dlls, and remove file locking. Using minhook in similar manner to: You can intercept windows api. But main question - is what loader is performing, and how to "reset" loader state back to "not loaded" state. I guess with C++ it's easy - existence of MemoryModulePP and ReloadLibrary tells me that this is something that was already achieved. With .net it's bit more complex, as need to interspect what loader / clr includes. At the moment clrmd - https://github.com/microsoft/clrmd knows everything about state of C# - I was thinking maybe later on try to debug what it knows that I don't know. Either way, please inform me if you know something more that I don't know. |
Here are bit more links on IAT problem, which I have tried to analyze by myself without any good result: To my best understanding IAT table refers to external dll. I'm not sure why which reference is needed, but apparently C++ linker generates it if you have C++/cli in use and you use some sort of global symbols. There are some attempts to make data as appdomain specific (now it's .net framework specific, not necessarily applicable to .net core) using I probably need to try how this works on .net core level, as things are different in there. (.net framework is officially deprecated by Microsoft by now). |
FYI also: https://dev.to/thebuzzsaw/building-a-better-library-loader-in-c-part-1-1446 Interesting reading, but suspect Conary somehow walks in that direction. |
I no find solution but I wanted to link you to similar project that also doesn't fix my issue at all but DOES have the feature of DllEntry so can simply use LoadLibrary("test.dll"); and ability to export other methods. https://github.com/seanrussell2/DotNetExport example use
Tool Test (c++) maybe can copy if care about DllEntry. |
Just curious if you know why all manual map libraries seem to fail and a possible way to make them work? The goal is embed the .net dll inside an unmanaged exe and load the dll from bye array/memory instead of file.
an example library is https://github.com/strivexjun/MemoryModulePP
The text was updated successfully, but these errors were encountered: