Hack Forums
[C] Manual DLL mapping. Crash on load a system DLL. - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C] Manual DLL mapping. Crash on load a system DLL. (/showthread.php?tid=6040904)



Manual DLL mapping. Crash on load a system DLL. - Securifier - Jan 14, 2020

Hello Hackforums.

I'm coding in C++ a manual DLL mapper with a custom GetProcAddress.

I tried to load a DLL I created, and all works fine. I can resolve an exported function, and call it.
But when I try with user32.dll to call MessageBoxW, it crashes.


To manual map, I follow these steps :

Reading file and putting in memory
Find and check headers
Allocate memory for mapping DLL (virtual alloc)
Copy headers and sections
Fix relocations
Fix imports
Call entry point


Even on user32, everything works fine, and I'm able to get a handle that looks valid, i can even find a valid address for my function from GetProcAddress, but when I call it, I get a crash.


Is there something to do in addition on Windows DLL ? It works perfectly on my owns dlls.


Thank you very much :)


RE: Manual DLL mapping. Crash on load a system DLL. - SIM-3602340 - Jan 14, 2020

Can you provide more info on the crash?


RE: Manual DLL mapping. Crash on load a system DLL. - Securifier - Jan 14, 2020

[Image: Annotation-2020-01-14-124512.png]


RE: Manual DLL mapping. Crash on load a system DLL. - HFDone - Jan 14, 2020

you get access violation error cuz the dll is in system dir
copy it to your exe path and try it


RE: Manual DLL mapping. Crash on load a system DLL. - Securifier - Jan 15, 2020

I copied the DLL to my working directory, and i get the same error.

Here a screenshot of the formats of all the executables I use

[Image: Annotation-2020-01-15-105647.png]


RE: Manual DLL mapping. Crash on load a system DLL. - HFDone - Jan 15, 2020

seems you have other problem with your mapping code
also check you are using the right code for your os 32 \ 64 and dll also can be problem using debug option over release ...


RE: Manual DLL mapping. Crash on load a system DLL. - Securifier - Jan 15, 2020

I just tried with OutputDebugStringA from kernel32, and it works great.....

I don't know why my User32 is broken....


RE: Manual DLL mapping. Crash on load a system DLL. - SIM-3602340 - Jan 15, 2020

The memory address that visual studio debugger is giving to you is f*d up, like it is supposed to be a valid memory address and obviously it isnt. This means that you are passing a value instead of a pointer somewhere or your relocation is incorrect. That's why we have an access violation error, a function is trying to read memory from that address and it's invalid. Can you dive deeper and show us where the error is occuring? I think that would help


RE: Manual DLL mapping. Crash on load a system DLL. - Securifier - Jan 16, 2020

The address of my resolved function looks valid: MessageBoxA 0x013C0CD0


RE: Manual DLL mapping. Crash on load a system DLL. - LivelyToerag - Jan 16, 2020

(Jan 14, 2020 05:54 AM)HFDone Wrote:  you get access violationerror cuz the dll is in system dir
copy it to your exe path and try it

Shut up you don't know what you are talking about.

For the user having problems:
1. Is this for 64 it or 32?
2. Show the prototype for MessageBoxAPI
3. Show disassembly of where it crashes.
4. Show callstack where it crashes.

If you don't know how to do the last 2 things use Google.


RE: Manual DLL mapping. Crash on load a system DLL. - HFDone - Jan 16, 2020

(Jan 16, 2020 05:04 AM)LivelyToerag Wrote:  Shut up you don't know what you are talking about.

For the user having problems:
1. Is this for 64 it or 32?
2. Show the prototype for MessageBoxAPI
3. Show disassembly of where it crashes.
4. Show callstack where it crashes.

If you don't know how to do the last 2 things use Google.

(Jan 15, 2020 06:19 AM)HFDone Wrote:  seems you have other problem with your mapping code
also check you are using the right code for your os 32 \ 64 and dll also can be problem using debug option over release ...



RE: Manual DLL mapping. Crash on load a system DLL. - LivelyToerag - Jan 16, 2020

the way you asked that in the first place shows that you have no reason to be trying to help others when you can't tell the difference between a memory access and opening a file.

skids gonna skid, asking more stupid questions doesn't make you look smart


RE: Manual DLL mapping. Crash on load a system DLL. - SIM-3602340 - Jan 17, 2020

Yes it's definitly very hard to understand what is going on without a detailed crash report. Maybe you should provide the full source to someone, so he can run it and see what's going on..