Delphi threading problem
I have a executable that was written in Delphi 2007.
My DLL is written in Delphi 10.2 I'm using Delphi Detours Library to hook some functions. Everything was fine when a old DLL is used. But, I don't know why, now the target is throwing Access Violations when it try to create a thread. After some deep digging, I found that any call from BeginThread to windows CreateThread is throwing Access Violation. Is something about SysInit ThreadWrapper. Anyone can give me some light? |
Make sure you are using the correct calling convention for your thread function. If you are using BeginThread, you cannot define the function as a STDCALL. BeginThread is basically a workaround for your thread function to use the delphi calling convention. My personal suggestion and preference for x86 is to use the standard WinAPI CreateThread and define your thread function as follows.
Function MyThreadFunction(p:Pointer):Cardinal; STDCALL; Begin //dostuff Result:=0; End; |
More I program in Delphi, less I know. :o
My DLL uses the code below to hook the target .EXE functions: Code:
library blablabla; A crash is throw inside ntdll.dll code callstack: Code:
:8d575653 But in a blind shot, I commented out the DLLProc line and voilá Code:
begin DLLInit: 0x00000001 => DLL_PROCESS_ATTACH DLLInit: 0x6CBE2728 DLLInit: 0x6D992728 DLLInit: 0x064DBC38 By the way, it solves my problem. Thanks Sir. |
Yes, confict/bug in DllEntryPoint function of your Delphi code.
When a thread created, system will call DllEntryPoint function with param DLL_THREAD_ATTACHED |
That's the point.
I always thought it worked like this. But unknown code are sent Code:
DLLInit: 0x00000001 => DLL_PROCESS_ATTACH Code:
DLL_PROCESS_ATTACH = 1; Code:
begin Like you said, probably a DLLProc erratic behavior. Thanks |
You can refer two documents:
1. http://docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/delphivclwin32/System_DLLProc.html 2. https://www.delphipraxis.net/47406-dll-entry-function.html Best regards, |
All times are GMT +8. The time now is 17:42. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Always Your Best Friend: Aaron, JMI, ahmadmansoor, ZeNiX